diff --git a/.ci/AppImageBuilder.yml b/.ci/AppImageBuilder.yml index 3d83e2851..86184518c 100644 --- a/.ci/AppImageBuilder.yml +++ b/.ci/AppImageBuilder.yml @@ -57,9 +57,9 @@ AppDir: - libqt5gui5 # if QT:BOOL=ON - libqt5widgets5 # if QT:BOOL=ON - libsixel1 # if CLI:BOOL=ON - - libslirp0 # if SLIRP_EXTERNAL:BOOL=ON + - libslirp0 - libsndio7.0 # if OPENAL:BOOL=ON - - libwayland-client0 # if QT:BOOL=ON + - libvdeplug-dev # -dev also pulls in libvdeplug2. -dev is required to get the proper .so symlink to the library - libx11-6 # if QT:BOOL=ON - libx11-xcb1 # if QT:BOOL=ON - libxcb1 # if QT:BOOL=ON @@ -67,10 +67,13 @@ AppDir: - libxcb-shape0 # if QT:BOOL=ON - libxcb-shm0 # if QT:BOOL=ON - libxcb-xfixes0 # if QT:BOOL=ON + - libxkbcommon-x11-0 # if QT:BOOL=ON + - qtwayland5 # if QT:BOOL=ON - zlib1g files: exclude: - etc + - lib/udev - usr/[!ls]* # * except lib, local, share - usr/lib/*/libasound.so.* # using our own ALSA can cause issues, and the API is pretty stable anyway - usr/lib/*.a # produced by library compilation diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 6ab63ea30..a57d3c715 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -78,8 +78,7 @@ def dynarecSlugs = [ ] def presets = [ - 'Regular', - 'Debug' + 'Regular' ] def presetSlugs = [ @@ -284,13 +283,19 @@ pipeline { def archName = archNames[archSlug] if (os == 'macOS') archName = archNamesMac[archSlug] - dir("${dynarecNames[dynarec]}/$os - $archName") { - ret = runBuild("-b \"$packageName\" \"$arch\" ${presetFlags[preset]} ${dynarecFlags[dynarec]} ${osFlags[os]} $buildFlags") + dir(dynarecNames[dynarec]) { + dir("$os - $archName") { + ret = runBuild("-b \"$packageName\" \"$arch\" ${presetFlags[preset]} ${dynarecFlags[dynarec]} ${osFlags[os]} $buildFlags") + if (presets.size() == 1) + writeFile file: '.forcedir', text: '' + } + if ((osArchs.size() == 1) && (thisOsArchs.size() == 1)) + writeFile file: '.forcedir', text: '' } if (ret == 0) { /* Archive resulting artifacts. */ - archiveArtifacts artifacts: "**/**/$packageName*" + archiveArtifacts artifacts: "**/$packageName*, **/.forcedir", defaultExcludes: false } else { /* Fail this stage. */ failStage() diff --git a/.ci/build.sh b/.ci/build.sh old mode 100644 new mode 100755 index 56199d3e6..0aa6a499d --- a/.ci/build.sh +++ b/.ci/build.sh @@ -24,8 +24,8 @@ # - For Windows (MSYS MinGW) builds: # - Packaging requires 7-Zip on Program Files # - Packaging the Ghostscript DLL requires 32-bit and/or 64-bit Ghostscript on Program Files -# - Packaging the FluidSynth DLL requires it to be at /home/86Box/dll32/libfluidsynth.dll -# and/or /home/86Box/dll64/libfluidsynth64.dll (for 32-bit and 64-bit builds respectively) +# - Packaging the XAudio2 DLL for FAudio requires it to be at /home/86Box/dll32/xaudio2*.dll +# and/or /home/86Box/dll64/xaudio2*.dll (for 32-bit and 64-bit builds respectively) # - For Linux builds: # - Only Debian and derivatives are supported # - dpkg and apt-get are called through sudo to manage dependencies; make sure those @@ -156,7 +156,18 @@ do -p) shift - dep_report=1 + + # Check for lddtree and install it if required. + which lddtree > /dev/null || DEBIAN_FRONTEND=noninteractive sudo apt-get -y install pax-utils + + # Default to main binary. + binary="$1" + [ -z "$binary" ] && binary="archive_tmp/usr/local/bin/$project" + + # Run lddtree with AppImage lib directories included in the search path. + LD_LIBRARY_PATH=$(find "$(pwd)/archive_tmp" -type d -name lib -o -name lib64 | while read dir; do find "$dir" -type d; done | tr '\n' ':') \ + lddtree "$binary" + exit $? ;; -s) @@ -198,6 +209,7 @@ if [ -z "$package_name" -a -z "$tarball_name" ] || [ -n "$package_name" -a -z "$ then echo '[!] Usage: build.sh -b {package_name} {architecture} [-t] [cmake_flags...]' echo ' build.sh -s {source_tarball_name}' + echo 'Dep. tree: build.sh -p [archive_tmp/path/to/binary]' exit 100 fi @@ -247,6 +259,7 @@ case $arch in esac [ ! -e "cmake/$toolchain.cmake" ] && toolchain=flags-gcc toolchain_file="cmake/$toolchain.cmake" +toolchain_file_libs= # Perform platform-specific setup. strip_binary=strip @@ -275,7 +288,6 @@ then echo [-] Using MSYSTEM [$MSYSTEM] # Install dependencies only if we're in a new build and/or architecture. - freetype_dll="$cache_dir/freetype.$MSYSTEM.dll" if check_buildtag "$MSYSTEM" then # Update databases and keyring only if we're in a new build. @@ -317,8 +329,8 @@ then done fi - # Generate a new freetype DLL for this architecture. - rm -f "$freetype_dll" + # Clean pacman cache when running under Jenkins to save disk space. + [ "$CI" = "true" ] && rm -rf /var/cache/pacman/pkg # Save build tag to skip this later. Doing it here (once everything is # in place) is important to avoid potential issues with retried builds. @@ -345,10 +357,6 @@ then # Run build for the architecture. args= [ $strip -ne 0 ] && args="-t $args" - case $arch_universal in # workaround: force new dynarec on for ARM - arm*) cmake_flags_extra="-D NEW_DYNAREC=ON";; - *) cmake_flags_extra=;; - esac zsh -lc 'exec "'"$0"'" -n -b "universal slice" "'"$arch_universal"'" '"$args""$cmake_flags"' '"$cmake_flags_extra" status=$? @@ -561,16 +569,15 @@ else # Establish general dependencies. pkgs="cmake ninja-build pkg-config git wget p7zip-full extra-cmake-modules wayland-protocols tar gzip file appstream" - [ $dep_report -ne 0 ] && pkgs="$pkgs pax-utils" if [ "$(dpkg --print-architecture)" = "$arch_deb" ] then pkgs="$pkgs build-essential" else # Add foreign architecture if required. - if ! dpkg --print-foreign-architectures | grep -qE '^'"$arch_deb"'$' + if ! dpkg --print-foreign-architectures | grep -Fqx "$arch_deb" then sudo dpkg --add-architecture "$arch_deb" - + # Force an apt-get update. save_buildtag aptupdate "arch_$arch_deb" fi @@ -584,7 +591,7 @@ else # ...and the ones we do want listed. Non-dev packages fill missing spots on the list. libpkgs="" longest_libpkg=0 - for pkg in libc6-dev libstdc++6 libopenal-dev libfreetype6-dev libx11-dev libsdl2-dev libpng-dev librtmidi-dev qtdeclarative5-dev libwayland-dev libevdev-dev libglib2.0-dev libslirp-dev libfaudio-dev libaudio-dev libjack-jackd2-dev libpipewire-0.3-dev libsamplerate0-dev libsndio-dev + for pkg in libc6-dev libstdc++6 libopenal-dev libfreetype6-dev libx11-dev libsdl2-dev libpng-dev librtmidi-dev qtdeclarative5-dev libwayland-dev libevdev-dev libxkbcommon-x11-dev libglib2.0-dev libslirp-dev libfaudio-dev libaudio-dev libjack-jackd2-dev libpipewire-0.3-dev libsamplerate0-dev libsndio-dev libvdeplug-dev libfluidsynth-dev do libpkgs="$libpkgs $pkg:$arch_deb" length=$(echo -n $pkg | sed 's/-dev$//' | sed "s/qtdeclarative/qt/" | wc -c) @@ -605,10 +612,7 @@ else *) libdir="$arch_triplet";; esac - # Create CMake cross toolchain file. The file is saved on a fixed location for - # the library builds we do later, since running CMake again on a library we've - # already built before will *not* update its toolchain file path; therefore, we - # cannot point them to our working directory, which may change across builds. + # Create CMake cross toolchain file. toolchain_file_new="$cache_dir/toolchain.$arch_deb.cmake" cat << EOF > "$toolchain_file_new" set(CMAKE_SYSTEM_NAME Linux) @@ -629,13 +633,21 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(ENV{PKG_CONFIG_PATH} "") -set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/$libdir/pkgconfig:/usr/share/$libdir/pkgconfig") +set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/$libdir/pkgconfig:/usr/share/$libdir/pkgconfig:/usr/share/pkgconfig") include("$(realpath "$toolchain_file")") EOF toolchain_file="$toolchain_file_new" strip_binary="$arch_triplet-strip" + # Create a separate toolchain file for library compilation without including + # our own toolchain files, letting libraries set their own C(XX)FLAGS instead. + # The file is saved on a fixed location, since running CMake again on a library + # we've already built before will *not* update its toolchain file path; therefore, + # we cannot point them to our working directory, which may change across builds. + toolchain_file_libs="$cache_dir/toolchain.$arch_deb.libs.cmake" + grep -Ev "^include\(" "$toolchain_file" > "$toolchain_file_libs" + # Install dependencies only if we're in a new build and/or architecture. if check_buildtag "$arch_deb" then @@ -658,9 +670,6 @@ EOF else echo [-] Not installing dependencies again fi - - # Link against the system libslirp instead of compiling ours. - cmake_flags_extra="$cmake_flags_extra -D SLIRP_EXTERNAL=ON" fi # Point CMake to the toolchain file. @@ -674,8 +683,8 @@ rm -rf build case $arch in 32 | x86) cmake_flags_extra="$cmake_flags_extra -D ARCH=i386";; 64 | x86_64*) cmake_flags_extra="$cmake_flags_extra -D ARCH=x86_64";; - ARM32 | arm32) cmake_flags_extra="$cmake_flags_extra -D ARCH=arm";; - ARM64 | arm64) cmake_flags_extra="$cmake_flags_extra -D ARCH=arm64";; + ARM32 | arm32) cmake_flags_extra="$cmake_flags_extra -D ARCH=arm -D NEW_DYNAREC=ON";; + ARM64 | arm64) cmake_flags_extra="$cmake_flags_extra -D ARCH=arm64 -D NEW_DYNAREC=ON";; *) cmake_flags_extra="$cmake_flags_extra -D \"ARCH=$arch\"";; esac @@ -780,10 +789,6 @@ then sevenzip="$pf/7-Zip/7z.exe" [ "$arch" = "32" -a -d "/c/Program Files (x86)" ] && pf="/c/Program Files (x86)" - # Archive freetype from cache or generate it from local MSYS installation. - [ ! -e "$freetype_dll" ] && .ci/static2dll.sh -p freetype2 /$MSYSTEM/lib/libfreetype.a "$freetype_dll" - cp -p "$freetype_dll" archive_tmp/freetype.dll - # Archive Ghostscript DLL from local official distribution installation. for gs in "$pf"/gs/gs*.*.* do @@ -794,8 +799,8 @@ then "$sevenzip" e -y -o"archive_tmp" "$discord_zip" "lib/$arch_discord/discord_game_sdk.dll" [ ! -e "archive_tmp/discord_game_sdk.dll" ] && echo [!] No Discord Game SDK for architecture [$arch_discord] - # Archive other DLLs from local directory. - cp -p "/home/$project/dll$arch/"* archive_tmp/ + # Archive XAudio2 DLL if required. + grep -q "OPENAL:BOOL=ON" build/CMakeCache.txt || cp -p "/home/$project/dll$arch/xaudio2"* archive_tmp/ # Archive executable, while also stripping it if requested. if [ $strip -ne 0 ] @@ -877,13 +882,13 @@ else if grep -q "OPENAL:BOOL=ON" build/CMakeCache.txt then - # Build openal-soft 1.22.2 manually to fix audio issues. This is a temporary + # Build openal-soft 1.23.1 manually to fix audio issues. This is a temporary # workaround until a newer version of openal-soft trickles down to Debian repos. - prefix="$cache_dir/openal-soft-1.22.2" + prefix="$cache_dir/openal-soft-1.23.1" if [ ! -d "$prefix" ] then rm -rf "$cache_dir/openal-soft-"* # remove old versions - wget -qO - https://github.com/kcat/openal-soft/archive/refs/tags/1.22.2.tar.gz | tar zxf - -C "$cache_dir" || rm -rf "$prefix" + wget -qO - https://github.com/kcat/openal-soft/archive/refs/tags/1.23.1.tar.gz | tar zxf - -C "$cache_dir" || rm -rf "$prefix" fi # Patches to build with the old PipeWire version in Debian. @@ -891,7 +896,7 @@ else sed -i -e 's/PW_KEY_CONFIG_NAME/"config.name"/g' "$prefix/alc/backends/pipewire.cpp" prefix_build="$prefix/build-$arch_deb" - cmake -G Ninja -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" -S "$prefix" -B "$prefix_build" || exit 99 + cmake -G Ninja -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file_libs" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" -S "$prefix" -B "$prefix_build" || exit 99 cmake --build "$prefix_build" -j$(nproc) || exit 99 cmake --install "$prefix_build" || exit 99 @@ -907,7 +912,7 @@ else wget -qO - https://github.com/FNA-XNA/FAudio/archive/refs/tags/22.03.tar.gz | tar zxf - -C "$cache_dir" || rm -rf "$prefix" fi prefix_build="$prefix/build-$arch_deb" - cmake -G Ninja -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" -S "$prefix" -B "$prefix_build" || exit 99 + cmake -G Ninja -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file_libs" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" -S "$prefix" -B "$prefix_build" || exit 99 cmake --build "$prefix_build" -j$(nproc) || exit 99 cmake --install "$prefix_build" || exit 99 @@ -928,7 +933,7 @@ else wget -qO - https://github.com/thestk/rtmidi/archive/refs/tags/4.0.0.tar.gz | tar zxf - -C "$cache_dir" || rm -rf "$prefix" fi prefix_build="$prefix/build-$arch_deb" - cmake -G Ninja -D RTMIDI_API_JACK=OFF -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" -S "$prefix" -B "$prefix_build" || exit 99 + cmake -G Ninja -D RTMIDI_API_JACK=OFF -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file_libs" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" -S "$prefix" -B "$prefix_build" || exit 99 cmake --build "$prefix_build" -j$(nproc) || exit 99 cmake --install "$prefix_build" || exit 99 @@ -940,15 +945,12 @@ else rm -rf "$cache_dir/fluidsynth-"* # remove old versions wget -qO - https://github.com/FluidSynth/fluidsynth/archive/refs/tags/v2.3.0.tar.gz | tar zxf - -C "$cache_dir" || rm -rf "$prefix" fi - cp cmake/flags-gcc.cmake cmake/flags-gcc.cmake.old - sed -i -e 's/ -Werror=.*\([" ]\)/\1/g' cmake/flags-gcc.cmake # temporary hack for -Werror=old-style-definition non-compliance on FluidSynth and SDL2 prefix_build="$prefix/build-$arch_deb" cmake -G Ninja -D enable-dbus=OFF -D enable-jack=OFF -D enable-oss=OFF -D enable-sdl2=OFF -D enable-pulseaudio=OFF -D enable-pipewire=OFF -D enable-alsa=OFF \ - -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" \ + -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file_libs" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" \ -S "$prefix" -B "$prefix_build" || exit 99 cmake --build "$prefix_build" -j$(nproc) || exit 99 cmake --install "$prefix_build" || exit 99 - cp -p "$cwd_root/archive_tmp/usr/bin/fluidsynth" fluidsynth # Build SDL2 for joystick and FAudio support, with most components # disabled to remove the dependencies on PulseAudio and libdrm. @@ -976,11 +978,24 @@ else -D SDL_ATOMIC=OFF -D SDL_EVENTS=ON -D SDL_HAPTIC=OFF -D SDL_POWER=OFF -D SDL_THREADS=ON -D SDL_TIMERS=ON -D SDL_FILE=OFF \ -D SDL_LOADSO=ON -D SDL_CPUINFO=ON -D SDL_FILESYSTEM=$sdl_ui -D SDL_DLOPEN=OFF -D SDL_SENSOR=OFF -D SDL_LOCALE=OFF \ \ - -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" \ + -D "CMAKE_TOOLCHAIN_FILE=$toolchain_file_libs" -D "CMAKE_INSTALL_PREFIX=$cwd_root/archive_tmp/usr" \ -S "$prefix" -B "$prefix_build" || exit 99 cmake --build "$prefix_build" -j$(nproc) || exit 99 cmake --install "$prefix_build" || exit 99 - mv cmake/flags-gcc.cmake.old cmake/flags-gcc.cmake + + # We rely on the host to provide Vulkan libs to sidestep any potential + # dependency issues. While Qt expects libvulkan.so, at least Debian only + # ships libvulkan.so.1 without a symlink, so make our own as a workaround. + # The relative paths prevent appimage-builder from flattening the links. + mkdir -p "archive_tmp/usr/lib/$libdir" + relroot="../../../../../../../../../../../../../../../../../../../../../../../../../../../../.." + ln -s "$relroot/usr/lib/libvulkan.so.1" "archive_tmp/usr/lib/libvulkan.so" + ln -s "$relroot/usr/lib/$libdir/libvulkan.so.1" "archive_tmp/usr/lib/$libdir/libvulkan.so" + + # The FluidSynth packaged by Debian bullseye is ABI incompatible with + # the newer version we compile, despite sharing a major version. Since we + # don't run into the one breaking ABI change they made, just symlink it. + ln -s "$(readlink "archive_tmp/usr/lib/libfluidsynth.so.3")" "archive_tmp/usr/lib/libfluidsynth.so.2" # Archive Discord Game SDK library. 7z e -y -o"archive_tmp/usr/lib" "$discord_zip" "lib/$arch_discord/discord_game_sdk.so" @@ -1014,7 +1029,7 @@ else mkdir -p "$icon_dir" cp -rp "$icon_size" "$icon_dir/apps" done - project_icon=$(ls "$icon_base/"[0-9]*x[0-9]*/* | head -1 | grep -oP '/\K([^/]+)(?=\.[^\.]+$)') + project_icon=$(find "$icon_base/"[0-9]*x[0-9]*/* -type f -name '*.png' -o -name '*.svg' | head -1 | grep -oP '/\K([^/]+)(?=\.[^\.]+$)') # Archive executable, while also stripping it if requested. mkdir -p archive_tmp/usr/local/bin @@ -1139,20 +1154,11 @@ EOF --recipe AppImageBuilder-generated.yml --appdir "$(grep -oP '^\s+path: \K(.+)' AppImageBuilder-generated.yml)" status=$? [ $status -eq 0 ] && break + [ $status -eq 127 ] && rm -rf /tmp/appimage_extracted_* done # Remove appimage-builder binary on failure, just in case it's corrupted. [ $status -ne 0 ] && rm -f "$appimage_builder_binary" - - # Generate library dependency report if requested. - if [ $dep_report -ne 0 ] - then - echo '[-] Library dependency report:' - - # Run lddtree with AppImage lib directories included in the search path. - LD_LIBRARY_PATH=$(find "$(pwd)/archive_tmp" -type d -name lib -o -name lib64 | while read dir; do find "$dir" -type d; done | tr '\n' ':') \ - lddtree "archive_tmp/usr/local/bin/$project" 2>&1 | tee depreport.txt - fi fi # Check if the archival succeeded. diff --git a/.ci/dependencies_macports.txt b/.ci/dependencies_macports.txt index b78331f9e..5ec71d07c 100644 --- a/.ci/dependencies_macports.txt +++ b/.ci/dependencies_macports.txt @@ -11,3 +11,7 @@ vulkan-headers MoltenVK qt5 wget +fluidsynth +ghostscript +libslirp +vde2 diff --git a/.ci/dependencies_msys.txt b/.ci/dependencies_msys.txt index df4932352..1b9ccdcc8 100644 --- a/.ci/dependencies_msys.txt +++ b/.ci/dependencies_msys.txt @@ -8,5 +8,6 @@ SDL2 zlib libpng rtmidi +libslirp qt5-static qt5-translations diff --git a/.ci/static2dll.sh b/.ci/static2dll.sh deleted file mode 100644 index 030898752..000000000 --- a/.ci/static2dll.sh +++ /dev/null @@ -1,160 +0,0 @@ -#!/bin/sh -# -# 86Box A hypervisor and IBM PC system emulator that specializes in -# running old operating systems and software designed for IBM -# PC systems and compatibles from 1981 through fairly recent -# system designs based on the PCI bus. -# -# This file is part of the 86Box distribution. -# -# Script for converting MinGW static libraries into a DLL. -# -# -# Authors: RichardG, -# -# Copyright 2021 RichardG. -# - -def_file="static2dll.def" -seen_file="static2dll.seen" -libs_file="static2dll.libs" - -find_lib() { - # Try to find a static library's file. - local msystem_lib="/$(echo $MSYSTEM | tr '[:upper:]' '[:lower:]')/lib/lib" - if [ -e "$msystem_lib$1.a" ] - then - echo "$msystem_lib$1.a" - elif [ -e "$msystem_lib$1.dll.a" ] - then - echo "$msystem_lib$1.dll.a" - else - # Return dynamic reference to the library. - echo "-l$1" - return 1 - fi -} - -add_lib() { - # Always make sure this lib is listed after the last lib that depends on it. - old_libs=$(cat "$libs_file") - rm -f "$libs_file" - for lib in $old_libs - do - [ "$lib" != "$*" ] && echo "$lib" >> "$libs_file" - done - echo "$*" >> "$libs_file" - - # Add libstdc++ in the end if required. - if echo "$*" | grep -q "/" - then - grep -Eq -- "__cxa_|__gxx_" "$1" 2> /dev/null && add_lib -static -lstdc++ - fi - - # Add libiconv for libintl. - if echo "$*" | grep -q "libintl" - then - add_lib $(find_lib iconv) - fi - - # Add libuuid for glib. - if echo "$*" | grep -q "libglib" - then - add_lib $(find_lib uuid) - fi -} - -run_pkgconfig() { - local cache_file="static2dll.$1.cache" - if [ -e "$cache_file" ] - then - cat "$cache_file" - else - pkg-config --static --libs "$1" 2> /dev/null | tee "$cache_file" - fi -} - -parse_pkgconfig() { - # Parse arguments. - local layers=$1 - shift - local input_lib_name=$1 - shift - - # Don't process the same file again. - grep -q '^'$input_lib_name'$' "$seen_file" && return - echo $input_lib_name >> "$seen_file" - - echo "$layers" parse_pkgconfig $input_lib_name - - # Parse pkg-config arguments. - for arg in $* - do - local arg_base="$(echo $arg | cut -c1-2)" - if [ "x$arg_base" = "x-l" ] - then - # Don't process the same lib again. - local lib_name="$(echo $arg | cut -c3-)" - [ "x$lib_name" == "x$input_lib_name" ] && continue - - # Add lib path. - add_lib "$(find_lib $lib_name)" - - # Get this lib's dependencies through pkg-config. - local pkgconfig="$(run_pkgconfig "$lib_name")" - [ $? -eq 0 ] && parse_pkgconfig "$layers"'>' "$lib_name" $pkgconfig || echo $lib_name >> "$seen_file" - elif [ "x$(echo $arg_base | cut -c1)" = "x-" ] - then - # Ignore other arguments. - continue - else - # Add lib path. - add_lib "$arg" - fi - done -} - -# Parse arguments. -case $1 in - -p) # -p pkg_config_name static_lib_path out_dll - shift - base_pkgconfig=$(run_pkgconfig "$1") - base_path="$2" - base_name="$1" - ;; - - *) # pc_path static_lib_path out_dll - base_pkgconfig="$(grep ^Libs.private: $1 | cut -d: -f2-)" - base_path="$2" - base_name="$2" - ;; -esac - -# Check arguments. -if [ -z "$base_pkgconfig" -o -z "$base_path" -o -z "$base_name" ] -then - echo Usage: - echo static2dll.sh -p {pkgconfig_package_name} {static_lib_path} {out_dll_name} - echo static2dll.sh {pc_file_path} {static_lib_path} {out_dll_name} - exit 1 -fi - -# Produce .def file. -echo LIBRARY $(basename "$3") > "$def_file" -echo EXPORTS >> "$def_file" -nm "$base_path" | grep " [TC] " | sed "/ _/s// /" | awk '{ print $3 }' >> "$def_file" - -# Parse dependencies recursively. -rm -f "$seen_file" "$libs_file" "$libs_file.tmp" -touch "$seen_file" "$libs_file" -parse_pkgconfig '>' $base_name $base_pkgconfig - -# Produce final DLL. -dllwrap --def "$def_file" -o "$3" -Wl,--allow-multiple-definition "$base_path" $(cat "$libs_file") -status=$? -[ $status -eq 0 ] && rm -f "$def_file" "$seen_file" "$libs_file" "static2dll.*.cache" - -# Update final DLL timestamp. -touch -r "$base_path" "$3" - -exit $status diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml new file mode 100644 index 000000000..53e8ec316 --- /dev/null +++ b/.github/codeql/codeql-config.yml @@ -0,0 +1,5 @@ +name: "86Box CodeQL config" + +queries: + - uses: security-extended +# - uses: security-and-quality diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index e91259189..7b8b6eeb4 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -90,8 +90,13 @@ jobs: libpng:p openal:p rtmidi:p + libslirp:p + fluidsynth:p libvncserver:p - - uses: actions/checkout@v3 + + - name: Checkout repository + uses: actions/checkout@v3 + - name: make run: >- make -fwin/Makefile.mingw -j @@ -101,7 +106,9 @@ jobs: CLANG=${{ matrix.environment.clang }} X64=${{ matrix.environment.x64 }} working-directory: ./src - - uses: actions/upload-artifact@v3 + + - name: Upload artifact + uses: actions/upload-artifact@v3 with: name: '86Box${{ matrix.dynarec.slug }}${{ matrix.build.slug }}-Windows-${{ matrix.environment.msystem }}-gha${{ github.run_number }}' path: src/86Box.exe diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index be42cbae6..12d278e8f 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -24,11 +24,15 @@ on: - "!**/Makefile*" jobs: + msys2: name: "Windows MSYS2 (${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, ${{ matrix.environment.msystem }})" runs-on: windows-2022 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + defaults: run: shell: msys2 {0} @@ -100,9 +104,19 @@ jobs: libpng:p openal:p rtmidi:p + libslirp:p + fluidsynth:p libvncserver:p ${{ matrix.ui.packages }} - - uses: actions/checkout@v3 + + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 + - name: Configure CMake run: >- cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} @@ -111,21 +125,36 @@ jobs: -D CMAKE_INSTALL_PREFIX=./build/artifacts -D QT=${{ matrix.ui.qt }} -D STATIC_BUILD=${{ matrix.ui.static }} + - name: Build - run: cmake --build build + run: | + cmake --build build + + - name: Run sonar-scanner + if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" + - name: Generate package run: cmake --install build - - uses: actions/upload-artifact@v3 + + - name: Upload artifact + uses: actions/upload-artifact@v3 with: name: '86Box${{ matrix.ui.slug }}${{ matrix.dynarec.slug }}${{ matrix.build.slug }}-Windows-${{ matrix.environment.msystem }}-gha${{ github.run_number }}' path: build/artifacts/** llvm-windows: name: "Windows vcpkg/LLVM (${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, ${{ matrix.target.name }})" + if: 0 runs-on: windows-2022 env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite' strategy: @@ -177,12 +206,15 @@ jobs: uses: ilammy/msvc-dev-cmd@v1 with: arch: ${{ matrix.target.vcvars }} + - name: Add LLVM to path run: echo "C:/Program Files/LLVM/bin" >> $env:GITHUB_PATH + - name: Download Ninja run: > Invoke-WebRequest https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip -OutFile ninja-win.zip && Expand-Archive ninja-win.zip -DestinationPath . + - name: Setup NuGet Credentials run: > & (C:/vcpkg/vcpkg fetch nuget | tail -n 2) @@ -192,9 +224,18 @@ jobs: -name "GitHub" -username "86Box" -password "${{ secrets.GITHUB_TOKEN }}" + - name: Fix MSVC atomic headers run: dir "C:/Program Files/Microsoft Visual Studio/2022/*/VC/Tools/MSVC/*/include" -include stdatomic.h -recurse | del - - uses: actions/checkout@v3 + + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 + - name: Configure CMake run: > cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} @@ -205,19 +246,36 @@ jobs: -D VCPKG_TARGET_TRIPLET=${{ matrix.target.triplet }} -D VCPKG_HOST_TRIPLET=x64-windows -D VCPKG_USE_HOST_TOOLS=ON + - name: Fix Qt if: matrix.ui.qt == 'on' run: | $qtTargetsPath = "${{ github.workspace }}/build/vcpkg_installed/${{ matrix.target.triplet }}/share/Qt6/Qt6Targets.cmake" (Get-Content $qtTargetsPath) -replace "^.*-Zc:__cplusplus;-permissive-.*$","#$&" | Set-Content $qtTargetsPath + - name: Reconfigure CMake if: matrix.ui.qt == 'on' - run: cmake clean build + run: | + cmake clean build + - name: Build - run: cmake --build build + run: | + build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner + if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" + - name: Generate package - run: cmake --install build - - uses: actions/upload-artifact@v3 + run: | + cmake --install build + + - name: Upload artifact + uses: actions/upload-artifact@v3 with: name: '86Box${{ matrix.ui.slug }}${{ matrix.dynarec.slug }}${{ matrix.build.slug }}-Windows-LLVM-${{ matrix.target.name }}-gha${{ github.run_number }}' path: build/artifacts/** @@ -227,6 +285,9 @@ jobs: runs-on: ubuntu-22.04 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + strategy: fail-fast: true matrix: @@ -252,7 +313,10 @@ jobs: slug: -Qt packages: >- qtbase5-dev + qtbase5-private-dev qttools5-dev + libevdev-dev + libxkbcommon-x11-dev steps: - name: Install dependencies @@ -266,9 +330,19 @@ jobs: libc6-dev librtmidi-dev libopenal-dev + libslirp-dev + libfluidsynth-dev libvncserver-dev ${{ matrix.ui.packages }} - - uses: actions/checkout@v3 + + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 + - name: Configure CMake run: >- cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} @@ -276,11 +350,25 @@ jobs: -D NEW_DYNAREC=${{ matrix.dynarec.new }} -D CMAKE_INSTALL_PREFIX=./build/artifacts -D QT=${{ matrix.ui.qt }} + - name: Build - run: cmake --build build + run: | + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner +# if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" + - name: Generate package - run: cmake --install build - - uses: actions/upload-artifact@v3 + run: | + cmake --install build + + - name: Upload artifact + uses: actions/upload-artifact@v3 with: name: '86Box${{ matrix.ui.slug }}${{ matrix.dynarec.slug }}${{ matrix.build.slug }}-UbuntuJammy-x86_64-gha${{ github.run_number }}' path: build/artifacts/** @@ -290,6 +378,9 @@ jobs: runs-on: macos-11 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + strategy: fail-fast: true matrix: @@ -326,9 +417,18 @@ jobs: libpng rtmidi openal-soft + fluidsynth libvncserver ${{ matrix.ui.packages }} - - uses: actions/checkout@v3 + + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 + - name: Configure CMake run: >- cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} @@ -339,11 +439,25 @@ jobs: -D Qt5_ROOT=$(brew --prefix qt@5) -D Qt5LinguistTools_ROOT=$(brew --prefix qt@5) -D OpenAL_ROOT=$(brew --prefix openal-soft) + - name: Build - run: cmake --build build + run: | + build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner + if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" + - name: Generate package - run: cmake --install build - - uses: actions/upload-artifact@v3 + run: | + cmake --install build + + - name: Upload artifact + uses: actions/upload-artifact@v3 with: name: '86Box${{ matrix.ui.slug }}${{ matrix.dynarec.slug }}${{ matrix.build.slug }}-macOS-x86_64-gha${{ github.run_number }}' path: build/artifacts/** diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 2cc36c6a6..fcfb16341 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,12 +1,149 @@ -name: "CodeQL" +name: CodeQL -on: [ push, pull_request] +on: + + push: + paths: + - src/** + - cmake/** + - "**/CMakeLists.txt" + - "CMakePresets.json" + - .github/workflows/codeql.yml + - vcpkg.json + - "!**/Makefile*" + + pull_request: + paths: + - src/** + - cmake/** + - "**/CMakeLists.txt" + - "CMakePresets.json" + - .github/workflows/** + - .github/workflows/codeql.yml + - vcpkg.json + - "!**/Makefile*" jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest + analyze-msys2: + name: "Analyze Windows MSYS2 (${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, ${{ matrix.environment.msystem }})" + + runs-on: windows-2022 + + permissions: + actions: read + contents: read + security-events: write + + defaults: + run: + shell: msys2 {0} + + strategy: + fail-fast: true + matrix: + language: [ 'cpp' ] + build: +# - name: Regular +# preset: regular +# - name: Debug +# preset: debug +# slug: -Debug + - name: Dev + preset: experimental + slug: -Dev + dynarec: + - name: ODR + new: off + slug: -ODR + - name: NDR + new: on + slug: -NDR + ui: + - name: Win32 GUI + qt: off + static: on + - name: Qt GUI + qt: on + static: off + slug: -Qt + packages: >- + qt5-base:p + qt5-tools:p + environment: +# - msystem: MSYS +# toolchain: ./cmake/flags-gcc-x86_64.cmake + - msystem: MINGW32 + prefix: mingw-w64-i686 + toolchain: ./cmake/flags-gcc-i686.cmake + - msystem: MINGW64 + prefix: mingw-w64-x86_64 + toolchain: ./cmake/flags-gcc-x86_64.cmake +# - msystem: CLANG32 +# prefix: mingw-w64-clang-i686 +# toolchain: ./cmake/llvm-win32-i686.cmake +# - msystem: CLANG64 +# prefix: mingw-w64-clang-x86_64 +# toolchain: ./cmake/llvm-win32-x86_64.cmake + - msystem: UCRT64 + prefix: mingw-w64-ucrt-x86_64 + toolchain: ./cmake/flags-gcc-x86_64.cmake + + steps: + - name: Prepare MSYS2 environment + uses: msys2/setup-msys2@v2 + with: + release: false + update: true + msystem: ${{ matrix.environment.msystem }} + pacboy: >- + ninja:p + cmake:p + gcc:p + pkgconf:p + freetype:p + SDL2:p + zlib:p + libpng:p + openal:p + rtmidi:p + libslirp:p + fluidsynth:p + libvncserver:p + ${{ matrix.ui.packages }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + config-file: ./.github/codeql/codeql-config.yml + + - name: Configure CMake + run: >- + cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} + --toolchain ${{ matrix.environment.toolchain }} + -D NEW_DYNAREC=${{ matrix.dynarec.new }} + -D CMAKE_INSTALL_PREFIX=./build/artifacts + -D QT=${{ matrix.ui.qt }} + -D STATIC_BUILD=${{ matrix.ui.static }} + + - name: Build + run: cmake --build build + + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" + + analyze-linux: + + name: "Analyze Linux GCC 11 (${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, x86_64)" + + runs-on: ubuntu-22.04 permissions: actions: read @@ -14,9 +151,35 @@ jobs: security-events: write strategy: - fail-fast: false + fail-fast: true matrix: language: [ 'cpp' ] + build: +# - name: Regular +# preset: regular +# - name: Debug +# preset: debug +# slug: -Debug + - name: Dev + preset: experimental + slug: -Dev + dynarec: + - name: ODR + new: off + slug: -ODR + - name: NDR + new: on + slug: -NDR + ui: + - name: Qt GUI + qt: on + slug: -Qt + packages: >- + qtbase5-dev + qtbase5-private-dev + qttools5-dev + libevdev-dev + libxkbcommon-x11-dev steps: - name: Install dependencies @@ -29,10 +192,11 @@ jobs: libpng-dev libc6-dev librtmidi-dev - qtbase5-dev - qttools5-dev libopenal-dev + libslirp-dev + libfluidsynth-dev libvncserver-dev + ${{ matrix.ui.packages }} - name: Checkout repository uses: actions/checkout@v3 @@ -41,9 +205,97 @@ jobs: uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} + config-file: ./.github/codeql/codeql-config.yml - - name: Autobuild - uses: github/codeql-action/autobuild@v2 + - name: Configure CMake + run: >- + cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} + --toolchain ./cmake/flags-gcc-x86_64.cmake + -D NEW_DYNAREC=${{ matrix.dynarec.new }} + -D CMAKE_INSTALL_PREFIX=./build/artifacts + -D QT=${{ matrix.ui.qt }} + + - name: Build + run: cmake --build build + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" + + analyze-macos11: + name: "Analyze macOS 11 (${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, x86_64)" + + runs-on: macos-11 + + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: true + matrix: + language: [ 'cpp' ] + build: +# - name: Regular +# preset: regular +# - name: Debug +# preset: debug +# slug: -Debug + - name: Dev + preset: experimental + slug: -Dev + dynarec: + - name: ODR + new: off + slug: -ODR + - name: NDR + new: on + slug: -NDR + ui: + - name: Qt GUI + qt: on + slug: -Qt + packages: >- + qt@5 + + steps: + - name: Install dependencies + run: >- + brew install + ninja + freetype + sdl2 + libpng + rtmidi + openal-soft + fluidsynth + libvncserver + ${{ matrix.ui.packages }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + config-file: ./.github/codeql/codeql-config.yml + + - name: Configure CMake + run: >- + cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} + --toolchain ./cmake/flags-gcc-x86_64.cmake + -D NEW_DYNAREC=${{ matrix.dynarec.new }} + -D CMAKE_INSTALL_PREFIX=./build/artifacts + -D QT=${{ matrix.ui.qt }} + -D Qt5_ROOT=$(brew --prefix qt@5) + -D Qt5LinguistTools_ROOT=$(brew --prefix qt@5) + -D OpenAL_ROOT=$(brew --prefix openal-soft) + + - name: Build + run: cmake --build build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.gitignore b/.gitignore index 0a21bf105..48a5950b9 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,8 @@ Makefile *.tar.* *.AppImage /appimage-builder-cache +/appimage-build +/AppImageBuilder-generated.yml # Visual Studio Code /.vs @@ -54,3 +56,6 @@ CMakeLists.txt.user /debian/debhelper-build-stamp /debian/files /obj-*-linux-gnu + +# MacOS Finder stuff +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index 8070ff263..8af57ca9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,10 +30,6 @@ if(NOT DEFINED OPENAL OR OPENAL) list(APPEND VCPKG_MANIFEST_FEATURES "openal") endif() -if(SLIRP_EXTERNAL) - list(APPEND VCPKG_MANIFEST_FEATURES "slirp") -endif() - if(MUNT_EXTERNAL) list(APPEND VCPKG_MANIFEST_FEATURES "munt") endif() diff --git a/CMakePresets.json b/CMakePresets.json index d2980ed87..0dbaf1988 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -56,6 +56,72 @@ "NEW_DYNAREC": "ON" }, "inherits": "base" + }, + { + "name": "llvm-macos-aarch64.cmake", + "displayName": "MacOS clang regular", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "cmake/llvm-macos-aarch64.cmake", + "NEW_DYNAREC": "ON", + "QT": "ON", + "USE_QT6": "OFF", + "Qt5_DIR": "/opt/homebrew/opt/qt@5/lib/cmake/Qt5", + "MOLTENVK_DIR": "/opt/homebrew/opt/molten-vk", + "Qt5LinguistTools_DIR": "/opt/homebrew/opt/qt@5/lib/cmake/Qt5LinguistTools", + "OpenAL_ROOT": "/opt/homebrew/opt/openal-soft" + }, + "inherits": "regular" + }, + { + "name": "llvm-macos-aarch64-debug", + "displayName": "MacOS clang debug", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "cmake/llvm-macos-aarch64.cmake", + "NEW_DYNAREC": "ON", + "QT": "ON", + "USE_QT6": "OFF", + "Qt5_DIR": "/opt/homebrew/opt/qt@5/lib/cmake/Qt5", + "MOLTENVK_DIR": "/opt/homebrew/opt/molten-vk", + "Qt5LinguistTools_DIR": "/opt/homebrew/opt/qt@5/lib/cmake/Qt5LinguistTools", + "OpenAL_ROOT": "/opt/homebrew/opt/openal-soft", + "CMAKE_CXX_FLAGS_DEBUG": "-g -O0 -DENABLE_VDE_LOG", + "CMAKE_C_FLAGS_DEBUG": "-g -O0 -DENABLE_VDE_LOG" + }, + "inherits": "debug" + }, + { + "name": "flags-gcc-aarch64-debug", + "displayName": "Linux ARM 64 - Debug", + "description": "Linux ARM64 - Debug build", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "cacheVariables": { + "NEW_DYNAREC": "ON", + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_TOOLCHAIN_FILE": "cmake/flags-gcc-aarch64.cmake", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_CXX_FLAGS_DEBUG": "-g -O0 -DENABLE_VDE_LOG", + "CMAKE_C_FLAGS_DEBUG": "-g -O0 -DENABLE_VDE_LOG" + }, + "inherits": "debug" + }, + { + "name": "flags-gcc-aarch64-regular", + "displayName": "Linux ARM 64 - Regular", + "description": "Linux ARM64 - Release build", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "cacheVariables": { + "NEW_DYNAREC": "ON", + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_TOOLCHAIN_FILE": "cmake/flags-gcc-aarch64.cmake", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" + }, + "inherits": "regular" } ], "buildPresets": [], diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..4f4f32b2e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# Contribution guidelines +The 86Box project welcomes contributions from anyone, as long as some basic guidelines are followed. + +## Emulated hardware +In order to accept new emulated hardware, the following criteria must be met: + +* A ROM must be available and be added to [our ROM repository](https://github.com/86Box/roms) +* Documentation must be available or it must be feasible to reverse engineer with a reasonable amount of time and effort +* It must be feasible to implement with a reasonable amount of time and effort +* It has to fall inside the project's scope + +## Questions +If you're unsure about any aspect of contributing, don't hesitate to get in touch via any of our official communities linked in our [readme](README.md#community) or [GitHub Discussions](https://github.com/86Box/86Box/discussions). diff --git a/README.md b/README.md index a1e3985e1..a1e1b4432 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ 86Box ===== + [![Build Status](https://ci.86box.net/job/86Box/badge/icon)](https://ci.86box.net/job/86Box/) **86Box** is a low level x86 emulator that runs older operating systems and software designed for IBM PC systems and compatibles from 1981 through fairly recent system designs based on the PCI bus. Features -------- + * Easy to use interface inspired by mainstream hypervisor software -* Low level emulation of 8086-based processors up to the Pentium with focus on accuracy +* Low level emulation of 8086-based processors up to the Mendocino-era Celeron with focus on accuracy * Great range of customizability of virtual machines * Many available systems, such as the very first IBM PC 5150 from 1981, or the more obscure IBM PS/2 line of systems based on the Micro Channel Architecture * Lots of supported peripherals including video adapters, sound cards, network adapters, hard disk controllers, and SCSI adapters @@ -16,51 +18,54 @@ Features Minimum system requirements and recommendations ----------------------------------------------- -* Intel Core 2 or AMD Athlon 64 processor -* Windows version: Windows 7 Service Pack 1, Windows 8.1 or Windows 10 + +* Intel Core 2 or AMD Athlon 64 processor or newer +* Windows version: Windows 7 Service Pack 1 or later * Linux version: Ubuntu 16.04, Debian 9.0 or other distributions from 2016 onwards -* macOS version: macOS High Sierra 10.13 -* 4 GB of RAM +* macOS version: macOS High Sierra 10.13 or newer +* 4 GB of RAM or higher Performance may vary depending on both host and guest configuration. Most emulation logic is executed in a single thread; therefore, systems with better IPC (instructions per clock) generally should be able to emulate higher clock speeds. It is also recommended to use a manager application with 86Box for easier handling of multiple virtual machines. + * [86Box Manager](https://github.com/86Box/86BoxManager) by [Overdoze](https://github.com/daviunic) (Windows only) * [86Box Manager Lite](https://github.com/insanemal/86box_manager_py) by [Insanemal](https://github.com/insanemal) * [WinBox for 86Box](https://github.com/86Box/WinBox-for-86Box) by Laci bá' (Windows only) +* [Linbox-qt5](https://github.com/Dungeonseeker/linbox-qt5) by Dungeonseeker (Linux focused, should work on Windows though untested) +* [MacBox for 86Box](https://github.com/Moonif/MacBox) by [Moonif](https://github.com/Moonif) (MacOS only) It is also possible to use 86Box on its own with the `--vmpath`/`-P` command line option. Getting started --------------- + See [our documentation](https://86box.readthedocs.io/en/latest/index.html) for an overview of the emulator's features and user interface. Community --------- + We operate an IRC channel and a Discord server for discussing 86Box, its development and anything related to retro computing. We look forward to hearing from you! [![Visit our IRC channel](https://kiwiirc.com/buttons/irc.ringoflightning.net/86Box.png)](https://kiwiirc.com/client/irc.ringoflightning.net/?nick=86box|?#86Box) [![Visit our Discord server](https://discordapp.com/api/guilds/262614059009048590/embed.png)](https://discord.gg/QXK9XTv) +Contributions +--------- + +We welcome all contributions to the project, as long as the [contribution guidelines](CONTRIBUTING.md) are followed. + Licensing --------- + 86Box is released under the [GNU General Public License, version 2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) or later. For more information, see the `COPYING` file in the root of the repository. The emulator can also optionally make use of [munt](https://github.com/munt/munt), [FluidSynth](https://www.fluidsynth.org/), [Ghostscript](https://www.ghostscript.com/) and [Discord Game SDK](https://discord.com/developers/docs/game-sdk/sdk-starter-guide), which are distributed under their respective licenses. -Contribution requirements -------------------------- - Formal codification of the project's emulated hardware contribution requirements, which all have to be met to accept an addition: -* A ROM must be available; -* Documentation must be available or it must be feasible to reverse engineer with a reasonable amount of time and effort; -* It must be feasible to implement with a reasonable amount of time and effort; -* It has to fall inside the project's scope. - -Where unsure or for more details about the project's emulated hardware contribution requirements, contact a Contributor or higher. - Donations --------- + We do not charge you for the emulator but donations are still welcome: https://paypal.me/86Box. diff --git a/bumpversion.sh b/bumpversion.sh index 87728603c..4681e72be 100644 --- a/bumpversion.sh +++ b/bumpversion.sh @@ -36,7 +36,7 @@ if [ -z "${romversion}" ]; then # Get the latest ROM release from the GitHub API. romversion=$(curl --silent "https://api.github.com/repos/86Box/roms/releases/latest" | grep '"tag_name":' | - sed -E 's/.*"([^"]+)".*/\1/') + sed -E 's/.*"v([^"]+)".*/\1/') fi # Switch to the repository root directory. diff --git a/debian/rules b/debian/rules index f01d81dcd..7b0605e72 100644 --- a/debian/rules +++ b/debian/rules @@ -25,7 +25,7 @@ endif dh $@ --buildsystem cmake+ninja override_dh_auto_configure: - dh_auto_configure --buildsystem cmake+ninja -- --preset regular --toolchain $(TOOLCHAIN) -DNEW_DYNAREC=$(NDR) -DSLIRP_EXTERNAL=on + dh_auto_configure --buildsystem cmake+ninja -- --preset regular --toolchain $(TOOLCHAIN) -DNEW_DYNAREC=$(NDR) override_dh_auto_test: diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 000000000..781fad035 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=86Box_86Box +sonar.organization=86box + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=86Box +#sonar.projectVersion=1.0 + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 diff --git a/src/86box.c b/src/86box.c index 1c020c32e..3a1ad179b 100644 --- a/src/86box.c +++ b/src/86box.c @@ -8,8 +8,6 @@ * * Main emulator module where most things are controlled. * - * - * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, @@ -182,6 +180,7 @@ uint32_t isa_mem_size = 0; /* (C) memory int cpu_use_dynarec = 0; /* (C) cpu uses/needs Dyna */ int cpu = 0; /* (C) cpu type */ int fpu_type = 0; /* (C) fpu type */ +int fpu_softfloat = 0; /* (C) fpu uses softfloat */ int time_sync = 0; /* (C) enable time sync */ int confirm_reset = 1; /* (C) enable reset confirmation */ int confirm_exit = 1; /* (C) enable exit confirmation */ @@ -209,16 +208,20 @@ char exe_path[2048]; /* path (dir) of executable */ char usr_path[1024]; /* path (dir) of user data */ char cfg_path[1024]; /* full path of config file */ FILE *stdlog = NULL; /* file to log output to */ -// int scrnsz_x = SCREEN_RES_X; /* current screen size, X */ -// int scrnsz_y = SCREEN_RES_Y; /* current screen size, Y */ +#if 0 +int scrnsz_x = SCREEN_RES_X; /* current screen size, X */ +int scrnsz_y = SCREEN_RES_Y; /* current screen size, Y */ +#endif int config_changed; /* config has changed */ int title_update; int framecountx = 0; int hard_reset_pending = 0; -// int unscaled_size_x = SCREEN_RES_X; /* current unscaled size X */ -// int unscaled_size_y = SCREEN_RES_Y; /* current unscaled size Y */ -// int efscrnsz_y = SCREEN_RES_Y; +#if 0 +int unscaled_size_x = SCREEN_RES_X; /* current unscaled size X */ +int unscaled_size_y = SCREEN_RES_Y; /* current unscaled size Y */ +int efscrnsz_y = SCREEN_RES_Y; +#endif static wchar_t mouse_msg[3][200]; @@ -405,19 +408,24 @@ pc_log(const char *fmt, ...) int pc_init(int argc, char *argv[]) { - char *ppath = NULL, *rpath = NULL; - char *cfg = NULL, *p; - char temp[2048], *fn[FDD_NUM] = { NULL }; - char drive = 0, *temp2 = NULL; - struct tm *info; - time_t now; - int c, lvmp = 0; - int i; + char *ppath = NULL; + char *rpath = NULL; + char *cfg = NULL; + char *p; + char temp[2048]; + char *fn[FDD_NUM] = { NULL }; + char drive = 0; + char *temp2 = NULL; + const struct tm *info; + time_t now; + int c; + int lvmp = 0; #ifdef ENABLE_NG int ng = 0; #endif #ifdef _WIN32 - uint32_t *uid, *shwnd; + uint32_t *uid; + uint32_t *shwnd; #endif uint32_t lang_init = 0; @@ -434,7 +442,7 @@ pc_init(int argc, char *argv[]) } if (!strncmp(exe_path, "/private/var/folders/", 21)) { ui_msgbox_header(MBX_FATAL, L"App Translocation", EMU_NAME_W L" cannot determine the emulated machine's location due to a macOS security feature. Please move the " EMU_NAME_W L" app to another folder (not /Applications), or make a copy of it and open that copy instead."); - return (0); + return 0; } #elif !defined(_WIN32) /* Grab the actual path if we are an AppImage. */ @@ -462,7 +470,7 @@ pc_init(int argc, char *argv[]) if (!strcasecmp(argv[c], "--help") || !strcasecmp(argv[c], "-?")) { usage: - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fn[i] != NULL) { free(fn[i]); fn[i] = NULL; @@ -494,7 +502,7 @@ usage: printf("-V or --vmname name - overrides the name of the running VM\n"); printf("-Z or --lastvmpath - the last parameter is VM path rather than config\n"); printf("\nA config file can be specified. If none is, the default file will be used.\n"); - return (0); + return 0; } else if (!strcasecmp(argv[c], "--lastvmpath") || !strcasecmp(argv[c], "-Z")) { lvmp = 1; } else if (!strcasecmp(argv[c], "--dumpcfg") || !strcasecmp(argv[c], "-O")) { @@ -586,7 +594,7 @@ usage: /* some (undocumented) test function here.. */ /* .. and then exit. */ - return (0); + return 0; #ifdef USE_INSTRUMENT } else if (!strcasecmp(argv[c], "--instrument")) { if ((c + 1) == argc) @@ -771,7 +779,7 @@ usage: /* Load the configuration file. */ config_load(); - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fn[i] != NULL) { if (strlen(fn[i]) <= 511) strncpy(floppyfns[i], fn[i], 511); @@ -787,7 +795,7 @@ usage: gdbstub_init(); /* All good! */ - return (1); + return 1; } void @@ -813,7 +821,8 @@ pc_full_speed(void) int pc_init_modules(void) { - int c, m; + int c; + int m; wchar_t temp[512]; char tempc[512]; @@ -847,7 +856,7 @@ pc_init_modules(void) } if (c == 0) { /* No usable ROMs found, aborting. */ - return (0); + return 0; } pc_log("A total of %d ROM sets have been loaded.\n", c); @@ -868,7 +877,6 @@ pc_init_modules(void) if (machine == -1) { fatal("No available machines\n"); exit(-1); - return (0); } } @@ -891,7 +899,6 @@ pc_init_modules(void) if (gfxcard[0] == -1) { fatal("No available video cards\n"); exit(-1); - return (0); } } @@ -934,7 +941,7 @@ pc_init_modules(void) machine_status_init(); - return (1); + return 1; } void @@ -1137,7 +1144,10 @@ pc_reset_hard_init(void) void update_mouse_msg(void) { - wchar_t wcpufamily[2048], wcpu[2048], wmachine[2048], *wcp; + wchar_t wcpufamily[2048]; + wchar_t wcpu[2048]; + wchar_t wmachine[2048]; + wchar_t *wcp; mbstowcs(wmachine, machine_getname(), strlen(machine_getname()) + 1); @@ -1175,10 +1185,8 @@ pc_reset_hard(void) } void -pc_close(thread_t *ptr) +pc_close(UNUSED(thread_t *ptr)) { - int i; - /* Wait a while so things can shut down. */ plat_delay_ms(200); @@ -1206,7 +1214,7 @@ pc_close(thread_t *ptr) lpt_devices_close(); - for (i = 0; i < FDD_NUM; i++) + for (uint8_t i = 0; i < FDD_NUM; i++) fdd_close(i); #ifdef ENABLE_808X_LOG @@ -1265,9 +1273,11 @@ pc_run(void) startblit(); cpu_exec(cpu_s->rspeed / 100); #ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */ - if (gdbstub_step == GDBSTUB_EXEC) + // if (gdbstub_step == GDBSTUB_EXEC) #endif +#if 0 mouse_process(); +#endif joystick_process(); endblit(); @@ -1306,7 +1316,10 @@ set_screen_size_monitor(int x, int y, int monitor_index) { int temp_overscan_x = monitors[monitor_index].mon_overscan_x; int temp_overscan_y = monitors[monitor_index].mon_overscan_y; - double dx, dy, dtx, dty; + double dx; + double dy; + double dtx; + double dty; /* Make sure we keep usable values. */ #if 0 @@ -1405,6 +1418,9 @@ set_screen_size_monitor(int x, int y, int monitor_index) monitors[monitor_index].mon_scrnsz_x = (monitors[monitor_index].mon_unscaled_size_x << 3); monitors[monitor_index].mon_scrnsz_y = (monitors[monitor_index].mon_unscaled_size_y << 3); break; + + default: + break; } plat_resize_request(monitors[monitor_index].mon_scrnsz_x, monitors[monitor_index].mon_scrnsz_y, monitor_index); @@ -1425,14 +1441,14 @@ reset_screen_size_monitor(int monitor_index) void reset_screen_size(void) { - for (int i = 0; i < MONITORS_NUM; i++) + for (uint8_t i = 0; i < MONITORS_NUM; i++) set_screen_size(monitors[i].mon_unscaled_size_x, monitors[i].mon_efscrnsz_y); } void set_screen_size_natural(void) { - for (int i = 0; i < MONITORS_NUM; i++) + for (uint8_t i = 0; i < MONITORS_NUM; i++) set_screen_size(monitors[i].mon_unscaled_size_x, monitors[i].mon_unscaled_size_y); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77de8aad9..3809ead73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -109,6 +109,9 @@ endif() find_package(Freetype REQUIRED) include_directories(${FREETYPE_INCLUDE_DIRS}) +if(FREETYPE_INCLUDE_DIR_ft2build) + include_directories(${FREETYPE_INCLUDE_DIR_ft2build}) +endif() if(APPLE) # Freetype is dynamically loaded by the emulator, however, we link it # on macOS so it gets copied to the bundle by the installation process diff --git a/src/acpi.c b/src/acpi.c index cafa06229..157e3cadd 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -148,7 +148,7 @@ acpi_raise_smi(void *priv, int do_smi) if (dev->regs.glbctl & 0x01) { if ((dev->vendor == VEN_VIA) || (dev->vendor == VEN_VIA_596B)) { - if ((!dev->regs.smi_lock || !dev->regs.smi_active)) { + if (!dev->regs.smi_lock || !dev->regs.smi_active) { if (do_smi) smi_raise(); dev->regs.smi_active = 1; @@ -169,11 +169,12 @@ acpi_raise_smi(void *priv, int do_smi) } static uint32_t -acpi_reg_read_common_regs(int size, uint16_t addr, void *p) +acpi_reg_read_common_regs(UNUSED(int size), uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; + acpi_t *dev = (acpi_t *) priv; uint32_t ret = 0x00000000; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -210,6 +211,9 @@ acpi_reg_read_common_regs(int size, uint16_t addr, void *p) update_tsc(); #endif break; + + default: + break; } #ifdef ENABLE_ACPI_LOG @@ -220,11 +224,12 @@ acpi_reg_read_common_regs(int size, uint16_t addr, void *p) } static uint32_t -acpi_reg_read_ali(int size, uint16_t addr, void *p) +acpi_reg_read_ali(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; - uint32_t ret = 0x00000000; - int shift16, shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -275,7 +280,7 @@ acpi_reg_read_ali(int size, uint16_t addr, void *p) ret = dev->regs.pmcntrl; break; default: - ret = acpi_reg_read_common_regs(size, addr, p); + ret = acpi_reg_read_common_regs(size, addr, priv); break; } @@ -287,11 +292,12 @@ acpi_reg_read_ali(int size, uint16_t addr, void *p) } static uint32_t -acpi_reg_read_intel(int size, uint16_t addr, void *p) +acpi_reg_read_intel(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; - uint32_t ret = 0x00000000; - int shift16, shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -371,7 +377,7 @@ acpi_reg_read_intel(int size, uint16_t addr, void *p) ret = dev->regs.gporeg[addr & 3]; break; default: - ret = acpi_reg_read_common_regs(size, addr, p); + ret = acpi_reg_read_common_regs(size, addr, priv); break; } @@ -383,11 +389,12 @@ acpi_reg_read_intel(int size, uint16_t addr, void *p) } static uint32_t -acpi_reg_read_via_common(int size, uint16_t addr, void *p) +acpi_reg_read_via_common(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; - uint32_t ret = 0x00000000; - int shift16, shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0xff; shift16 = (addr & 1) << 3; @@ -466,7 +473,7 @@ acpi_reg_read_via_common(int size, uint16_t addr, void *p) ret = (dev->regs.gptren >> shift32) & 0xff; break; default: - ret = acpi_reg_read_common_regs(size, addr, p); + ret = acpi_reg_read_common_regs(size, addr, priv); break; } @@ -478,9 +485,9 @@ acpi_reg_read_via_common(int size, uint16_t addr, void *p) } static uint32_t -acpi_reg_read_via(int size, uint16_t addr, void *p) +acpi_reg_read_via(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; + acpi_t *dev = (acpi_t *) priv; uint32_t ret = 0x00000000; int shift16; @@ -523,7 +530,7 @@ acpi_reg_read_via(int size, uint16_t addr, void *p) ret = (dev->regs.gpi_val >> shift16) & 0xff; break; default: - ret = acpi_reg_read_via_common(size, addr, p); + ret = acpi_reg_read_via_common(size, addr, priv); break; } @@ -535,11 +542,12 @@ acpi_reg_read_via(int size, uint16_t addr, void *p) } static uint32_t -acpi_reg_read_via_596b(int size, uint16_t addr, void *p) +acpi_reg_read_via_596b(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; - uint32_t ret = 0x00000000; - int shift16, shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0x7f; shift16 = (addr & 1) << 3; @@ -572,7 +580,7 @@ acpi_reg_read_via_596b(int size, uint16_t addr, void *p) ret = (dev->regs.gpo_val >> shift32) & 0xff; break; default: - ret = acpi_reg_read_via_common(size, addr, p); + ret = acpi_reg_read_via_common(size, addr, priv); break; } @@ -584,13 +592,13 @@ acpi_reg_read_via_596b(int size, uint16_t addr, void *p) } static uint32_t -acpi_reg_read_smc(int size, uint16_t addr, void *p) +acpi_reg_read_smc(int size, uint16_t addr, void *priv) { uint32_t ret = 0x00000000; addr &= 0x0f; - ret = acpi_reg_read_common_regs(size, addr, p); + ret = acpi_reg_read_common_regs(size, addr, priv); #ifdef ENABLE_ACPI_LOG if (size != 1) @@ -600,11 +608,11 @@ acpi_reg_read_smc(int size, uint16_t addr, void *p) } static uint32_t -acpi_aux_reg_read_smc(int size, uint16_t addr, void *p) +acpi_aux_reg_read_smc(UNUSED(int size), uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; - uint32_t ret = 0x00000000; - int shift16; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; addr &= 0x07; shift16 = (addr & 1) << 3; @@ -633,6 +641,9 @@ acpi_aux_reg_read_smc(int size, uint16_t addr, void *p) /* Miscellaneous Control Register */ ret = dev->regs.glbctl & 0xff; break; + + default: + break; } acpi_log("(%i) ACPI Read (%i) %02X: %02X\n", in_smm, size, addr, ret); @@ -640,10 +651,11 @@ acpi_aux_reg_read_smc(int size, uint16_t addr, void *p) } static void -acpi_reg_write_common_regs(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_common_regs(UNUSED(int size), uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; - int shift16, sus_typ; + acpi_t *dev = (acpi_t *) priv; + int shift16; + int sus_typ; addr &= 0x3f; #ifdef ENABLE_ACPI_LOG @@ -687,14 +699,13 @@ acpi_reg_write_common_regs(int size, uint16_t addr, uint8_t val, void *p) } if (sus_typ & SUS_RESET_PCI) - device_reset_all_pci(); + device_reset_all(DEVICE_PCI); if (sus_typ & SUS_RESET_CPU) cpu_alt_reset = 0; if (sus_typ & SUS_RESET_PCI) { pci_reset(); - keyboard_at_reset(); mem_a20_alt = 0; mem_a20_recalc(); @@ -714,14 +725,18 @@ acpi_reg_write_common_regs(int size, uint16_t addr, uint8_t val, void *p) } dev->regs.pmcntrl = ((dev->regs.pmcntrl & ~(0xff << shift16)) | (val << shift16)) & 0x3f07 /* 0x3c07 */; break; + + default: + break; } } static void -acpi_reg_write_ali(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_ali(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + acpi_t *dev = (acpi_t *) priv; + int shift16; + int shift32; addr &= 0x3f; #ifdef ENABLE_ACPI_LOG @@ -776,7 +791,7 @@ acpi_reg_write_ali(int size, uint16_t addr, uint8_t val, void *p) dev->regs.pmcntrl = val & 1; break; default: - acpi_reg_write_common_regs(size, addr, val, p); + acpi_reg_write_common_regs(size, addr, val, priv); /* Setting GBL_RLS also sets BIOS_STS and generates SMI. */ if ((addr == 0x00) && !(dev->regs.pmsts & 0x20)) dev->regs.gpcntrl &= ~0x0002; @@ -789,10 +804,11 @@ acpi_reg_write_ali(int size, uint16_t addr, uint8_t val, void *p) } static void -acpi_reg_write_intel(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_intel(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + acpi_t *dev = (acpi_t *) priv; + int shift16; + int shift32; addr &= 0x3f; #ifdef ENABLE_ACPI_LOG @@ -871,7 +887,7 @@ acpi_reg_write_intel(int size, uint16_t addr, uint8_t val, void *p) dev->regs.gporeg[addr & 3] = val; break; default: - acpi_reg_write_common_regs(size, addr, val, p); + acpi_reg_write_common_regs(size, addr, val, priv); /* Setting GBL_RLS also sets BIOS_STS and generates SMI. */ if ((addr == 0x00) && !(dev->regs.pmsts & 0x20)) dev->regs.glbctl &= ~0x0002; @@ -885,10 +901,11 @@ acpi_reg_write_intel(int size, uint16_t addr, uint8_t val, void *p) } static void -acpi_reg_write_via_common(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_via_common(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + acpi_t *dev = (acpi_t *) priv; + int shift16; + int shift32; addr &= 0xff; acpi_log("(%i) ACPI Write (%i) %02X: %02X\n", in_smm, size, addr, val); @@ -957,7 +974,7 @@ acpi_reg_write_via_common(int size, uint16_t addr, uint8_t val, void *p) dev->regs.gptren = ((dev->regs.gptren & ~(0xff << shift32)) | (val << shift32)) & 0x000000d9; break; default: - acpi_reg_write_common_regs(size, addr, val, p); + acpi_reg_write_common_regs(size, addr, val, priv); /* Setting GBL_RLS also sets BIOS_STS and generates SMI. */ if ((addr == 0x00) && !(dev->regs.pmsts & 0x20)) dev->regs.glbctl &= ~0x0002; @@ -978,10 +995,11 @@ acpi_i2c_set(acpi_t *dev) } static void -acpi_reg_write_via(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_via(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + acpi_t *dev = (acpi_t *) priv; + int shift16; + int shift32; addr &= 0xff; acpi_log("(%i) ACPI Write (%i) %02X: %02X\n", in_smm, size, addr, val); @@ -1035,16 +1053,17 @@ acpi_reg_write_via(int size, uint16_t addr, uint8_t val, void *p) dev->regs.gpo_val = ((dev->regs.gpo_val & ~(0xff << shift16)) | (val << shift16)) & 0xffff; break; default: - acpi_reg_write_via_common(size, addr, val, p); + acpi_reg_write_via_common(size, addr, val, priv); break; } } static void -acpi_reg_write_via_596b(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_via_596b(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + acpi_t *dev = (acpi_t *) priv; + int shift16; + int shift32; addr &= 0x7f; acpi_log("(%i) ACPI Write (%i) %02X: %02X\n", in_smm, size, addr, val); @@ -1092,20 +1111,20 @@ acpi_reg_write_via_596b(int size, uint16_t addr, uint8_t val, void *p) dev->regs.gpo_val = ((dev->regs.gpo_val & ~(0xff << shift32)) | (val << shift32)) & 0x7fffffff; break; default: - acpi_reg_write_via_common(size, addr, val, p); + acpi_reg_write_via_common(size, addr, val, priv); break; } } static void -acpi_reg_write_smc(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_smc(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; + acpi_t *dev = (acpi_t *) priv; addr &= 0x0f; acpi_log("(%i) ACPI Write (%i) %02X: %02X\n", in_smm, size, addr, val); - acpi_reg_write_common_regs(size, addr, val, p); + acpi_reg_write_common_regs(size, addr, val, priv); /* Setting GBL_RLS also sets BIOS_STS and generates SMI. */ if ((addr == 0x00) && !(dev->regs.pmsts & 0x20)) dev->regs.glbctl &= ~0x0001; @@ -1117,9 +1136,9 @@ acpi_reg_write_smc(int size, uint16_t addr, uint8_t val, void *p) } static void -acpi_aux_reg_write_smc(int size, uint16_t addr, uint8_t val, void *p) +acpi_aux_reg_write_smc(UNUSED(int size), uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; + acpi_t *dev = (acpi_t *) priv; int shift16; addr &= 0x07; @@ -1161,76 +1180,79 @@ acpi_aux_reg_write_smc(int size, uint16_t addr, uint8_t val, void *p) acpi_update_irq(dev); } break; + + default: + break; } } static uint32_t -acpi_reg_read_common(int size, uint16_t addr, void *p) +acpi_reg_read_common(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; + const acpi_t *dev = (acpi_t *) priv; uint8_t ret = 0xff; if (dev->vendor == VEN_ALI) - ret = acpi_reg_read_ali(size, addr, p); + ret = acpi_reg_read_ali(size, addr, priv); else if (dev->vendor == VEN_VIA) - ret = acpi_reg_read_via(size, addr, p); + ret = acpi_reg_read_via(size, addr, priv); else if (dev->vendor == VEN_VIA_596B) - ret = acpi_reg_read_via_596b(size, addr, p); + ret = acpi_reg_read_via_596b(size, addr, priv); else if (dev->vendor == VEN_INTEL) - ret = acpi_reg_read_intel(size, addr, p); + ret = acpi_reg_read_intel(size, addr, priv); else if (dev->vendor == VEN_SMC) - ret = acpi_reg_read_smc(size, addr, p); + ret = acpi_reg_read_smc(size, addr, priv); return ret; } static void -acpi_reg_write_common(int size, uint16_t addr, uint8_t val, void *p) +acpi_reg_write_common(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; + const acpi_t *dev = (acpi_t *) priv; if (dev->vendor == VEN_ALI) - acpi_reg_write_ali(size, addr, val, p); + acpi_reg_write_ali(size, addr, val, priv); else if (dev->vendor == VEN_VIA) - acpi_reg_write_via(size, addr, val, p); + acpi_reg_write_via(size, addr, val, priv); else if (dev->vendor == VEN_VIA_596B) - acpi_reg_write_via_596b(size, addr, val, p); + acpi_reg_write_via_596b(size, addr, val, priv); else if (dev->vendor == VEN_INTEL) - acpi_reg_write_intel(size, addr, val, p); + acpi_reg_write_intel(size, addr, val, priv); else if (dev->vendor == VEN_SMC) - acpi_reg_write_smc(size, addr, val, p); + acpi_reg_write_smc(size, addr, val, priv); } static uint32_t -acpi_aux_reg_read_common(int size, uint16_t addr, void *p) +acpi_aux_reg_read_common(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) p; + const acpi_t *dev = (acpi_t *) priv; uint8_t ret = 0xff; if (dev->vendor == VEN_SMC) - ret = acpi_aux_reg_read_smc(size, addr, p); + ret = acpi_aux_reg_read_smc(size, addr, priv); return ret; } static void -acpi_aux_reg_write_common(int size, uint16_t addr, uint8_t val, void *p) +acpi_aux_reg_write_common(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; + const acpi_t *dev = (acpi_t *) priv; if (dev->vendor == VEN_SMC) - acpi_aux_reg_write_smc(size, addr, val, p); + acpi_aux_reg_write_smc(size, addr, val, priv); } static uint32_t -acpi_reg_readl(uint16_t addr, void *p) +acpi_reg_readl(uint16_t addr, void *priv) { uint32_t ret = 0x00000000; - ret = acpi_reg_read_common(4, addr, p); - ret |= (acpi_reg_read_common(4, addr + 1, p) << 8); - ret |= (acpi_reg_read_common(4, addr + 2, p) << 16); - ret |= (acpi_reg_read_common(4, addr + 3, p) << 24); + ret = acpi_reg_read_common(4, addr, priv); + ret |= (acpi_reg_read_common(4, addr + 1, priv) << 8); + ret |= (acpi_reg_read_common(4, addr + 2, priv) << 16); + ret |= (acpi_reg_read_common(4, addr + 3, priv) << 24); acpi_log("ACPI: Read L %08X from %04X\n", ret, addr); @@ -1238,12 +1260,12 @@ acpi_reg_readl(uint16_t addr, void *p) } static uint16_t -acpi_reg_readw(uint16_t addr, void *p) +acpi_reg_readw(uint16_t addr, void *priv) { uint16_t ret = 0x0000; - ret = acpi_reg_read_common(2, addr, p); - ret |= (acpi_reg_read_common(2, addr + 1, p) << 8); + ret = acpi_reg_read_common(2, addr, priv); + ret |= (acpi_reg_read_common(2, addr + 1, priv) << 8); acpi_log("ACPI: Read W %08X from %04X\n", ret, addr); @@ -1251,11 +1273,11 @@ acpi_reg_readw(uint16_t addr, void *p) } static uint8_t -acpi_reg_read(uint16_t addr, void *p) +acpi_reg_read(uint16_t addr, void *priv) { uint8_t ret = 0x00; - ret = acpi_reg_read_common(1, addr, p); + ret = acpi_reg_read_common(1, addr, priv); acpi_log("ACPI: Read B %02X from %04X\n", ret, addr); @@ -1263,14 +1285,14 @@ acpi_reg_read(uint16_t addr, void *p) } static uint32_t -acpi_aux_reg_readl(uint16_t addr, void *p) +acpi_aux_reg_readl(uint16_t addr, void *priv) { uint32_t ret = 0x00000000; - ret = acpi_aux_reg_read_common(4, addr, p); - ret |= (acpi_aux_reg_read_common(4, addr + 1, p) << 8); - ret |= (acpi_aux_reg_read_common(4, addr + 2, p) << 16); - ret |= (acpi_aux_reg_read_common(4, addr + 3, p) << 24); + ret = acpi_aux_reg_read_common(4, addr, priv); + ret |= (acpi_aux_reg_read_common(4, addr + 1, priv) << 8); + ret |= (acpi_aux_reg_read_common(4, addr + 2, priv) << 16); + ret |= (acpi_aux_reg_read_common(4, addr + 3, priv) << 24); acpi_log("ACPI: Read Aux L %08X from %04X\n", ret, addr); @@ -1278,12 +1300,12 @@ acpi_aux_reg_readl(uint16_t addr, void *p) } static uint16_t -acpi_aux_reg_readw(uint16_t addr, void *p) +acpi_aux_reg_readw(uint16_t addr, void *priv) { uint16_t ret = 0x0000; - ret = acpi_aux_reg_read_common(2, addr, p); - ret |= (acpi_aux_reg_read_common(2, addr + 1, p) << 8); + ret = acpi_aux_reg_read_common(2, addr, priv); + ret |= (acpi_aux_reg_read_common(2, addr + 1, priv) << 8); acpi_log("ACPI: Read Aux W %04X from %04X\n", ret, addr); @@ -1291,11 +1313,11 @@ acpi_aux_reg_readw(uint16_t addr, void *p) } static uint8_t -acpi_aux_reg_read(uint16_t addr, void *p) +acpi_aux_reg_read(uint16_t addr, void *priv) { uint8_t ret = 0x00; - ret = acpi_aux_reg_read_common(1, addr, p); + ret = acpi_aux_reg_read_common(1, addr, priv); acpi_log("ACPI: Read Aux B %02X from %04X\n", ret, addr); @@ -1303,59 +1325,59 @@ acpi_aux_reg_read(uint16_t addr, void *p) } static void -acpi_reg_writel(uint16_t addr, uint32_t val, void *p) +acpi_reg_writel(uint16_t addr, uint32_t val, void *priv) { acpi_log("ACPI: Write L %08X to %04X\n", val, addr); - acpi_reg_write_common(4, addr, val & 0xff, p); - acpi_reg_write_common(4, addr + 1, (val >> 8) & 0xff, p); - acpi_reg_write_common(4, addr + 2, (val >> 16) & 0xff, p); - acpi_reg_write_common(4, addr + 3, (val >> 24) & 0xff, p); + acpi_reg_write_common(4, addr, val & 0xff, priv); + acpi_reg_write_common(4, addr + 1, (val >> 8) & 0xff, priv); + acpi_reg_write_common(4, addr + 2, (val >> 16) & 0xff, priv); + acpi_reg_write_common(4, addr + 3, (val >> 24) & 0xff, priv); } static void -acpi_reg_writew(uint16_t addr, uint16_t val, void *p) +acpi_reg_writew(uint16_t addr, uint16_t val, void *priv) { acpi_log("ACPI: Write W %04X to %04X\n", val, addr); - acpi_reg_write_common(2, addr, val & 0xff, p); - acpi_reg_write_common(2, addr + 1, (val >> 8) & 0xff, p); + acpi_reg_write_common(2, addr, val & 0xff, priv); + acpi_reg_write_common(2, addr + 1, (val >> 8) & 0xff, priv); } static void -acpi_reg_write(uint16_t addr, uint8_t val, void *p) +acpi_reg_write(uint16_t addr, uint8_t val, void *priv) { acpi_log("ACPI: Write B %02X to %04X\n", val, addr); - acpi_reg_write_common(1, addr, val, p); + acpi_reg_write_common(1, addr, val, priv); } static void -acpi_aux_reg_writel(uint16_t addr, uint32_t val, void *p) +acpi_aux_reg_writel(uint16_t addr, uint32_t val, void *priv) { acpi_log("ACPI: Write Aux L %08X to %04X\n", val, addr); - acpi_aux_reg_write_common(4, addr, val & 0xff, p); - acpi_aux_reg_write_common(4, addr + 1, (val >> 8) & 0xff, p); - acpi_aux_reg_write_common(4, addr + 2, (val >> 16) & 0xff, p); - acpi_aux_reg_write_common(4, addr + 3, (val >> 24) & 0xff, p); + acpi_aux_reg_write_common(4, addr, val & 0xff, priv); + acpi_aux_reg_write_common(4, addr + 1, (val >> 8) & 0xff, priv); + acpi_aux_reg_write_common(4, addr + 2, (val >> 16) & 0xff, priv); + acpi_aux_reg_write_common(4, addr + 3, (val >> 24) & 0xff, priv); } static void -acpi_aux_reg_writew(uint16_t addr, uint16_t val, void *p) +acpi_aux_reg_writew(uint16_t addr, uint16_t val, void *priv) { acpi_log("ACPI: Write Aux W %04X to %04X\n", val, addr); - acpi_aux_reg_write_common(2, addr, val & 0xff, p); - acpi_aux_reg_write_common(2, addr + 1, (val >> 8) & 0xff, p); + acpi_aux_reg_write_common(2, addr, val & 0xff, priv); + acpi_aux_reg_write_common(2, addr + 1, (val >> 8) & 0xff, priv); } static void -acpi_aux_reg_write(uint16_t addr, uint8_t val, void *p) +acpi_aux_reg_write(uint16_t addr, uint8_t val, void *priv) { acpi_log("ACPI: Write Aux B %02X to %04X\n", val, addr); - acpi_aux_reg_write_common(1, addr, val, p); + acpi_aux_reg_write_common(1, addr, val, priv); } void @@ -1364,9 +1386,9 @@ acpi_update_io_mapping(acpi_t *dev, uint32_t base, int chipset_en) int size; switch (dev->vendor) { + default: case VEN_ALI: case VEN_INTEL: - default: size = 0x040; break; case VEN_SMC: @@ -1535,9 +1557,9 @@ acpi_pwrbtn_timer(void *priv) } static void -acpi_apm_out(uint16_t port, uint8_t val, void *p) +acpi_apm_out(uint16_t port, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) p; + acpi_t *dev = (acpi_t *) priv; acpi_log("[%04X:%08X] APM write: %04X = %02X (AX = %04X, BX = %04X, CX = %04X)\n", CS, cpu_state.pc, port, val, AX, BX, CX); @@ -1547,7 +1569,9 @@ acpi_apm_out(uint16_t port, uint8_t val, void *p) if (port == 0x0001) { acpi_log("ALi SOFT SMI# status set (%i)\n", dev->apm->do_smi); dev->apm->cmd = val; - // acpi_raise_smi(dev, dev->apm->do_smi); +#if 0 + acpi_raise_smi(dev, dev->apm->do_smi); +#endif if (dev->apm->do_smi) smi_raise(); dev->regs.ali_soft_smi = 1; @@ -1565,10 +1589,10 @@ acpi_apm_out(uint16_t port, uint8_t val, void *p) } static uint8_t -acpi_apm_in(uint16_t port, void *p) +acpi_apm_in(uint16_t port, void *priv) { - acpi_t *dev = (acpi_t *) p; - uint8_t ret = 0xff; + const acpi_t *dev = (acpi_t *) priv; + uint8_t ret = 0xff; port &= 0x0001; @@ -1593,7 +1617,6 @@ static void acpi_reset(void *priv) { acpi_t *dev = (acpi_t *) priv; - int i; memset(&dev->regs, 0x00, sizeof(acpi_regs_t)); dev->regs.gpireg[0] = 0xff; @@ -1604,7 +1627,7 @@ acpi_reset(void *priv) Gigabyte GA-686BX: - Bit 1: CMOS battery low (active high) */ dev->regs.gpireg[2] = dev->gpireg2_default; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) dev->regs.gporeg[i] = dev->gporeg_default[i]; if (dev->vendor == VEN_VIA_596B) { dev->regs.gpo_val = 0x7fffffff; @@ -1671,7 +1694,7 @@ acpi_init(const device_t *info) dev = (acpi_t *) malloc(sizeof(acpi_t)); if (dev == NULL) - return (NULL); + return NULL; memset(dev, 0x00, sizeof(acpi_t)); cpu_to_acpi = ACPI_TIMER_FREQ / cpuclock; @@ -1700,6 +1723,7 @@ acpi_init(const device_t *info) dev->suspend_types[2] = SUS_SUSPEND | SUS_NVR | SUS_RESET_CPU | SUS_RESET_PCI; dev->suspend_types[3] = SUS_SUSPEND; dev->suspend_types[5] = SUS_POWER_OFF; /* undocumented, used for S4/S5 by ASUS P5A ACPI table */ + dev->suspend_types[7] = SUS_POWER_OFF; /* undocumented, used for S5 by Gigabyte GA-5AX ACPI table */ break; case VEN_VIA: @@ -1722,6 +1746,9 @@ acpi_init(const device_t *info) dev->suspend_types[3] = SUS_SUSPEND | SUS_RESET_CACHE; dev->suspend_types[4] = SUS_SUSPEND; break; + + default: + break; } timer_add(&dev->timer, acpi_timer_overflow, dev, 0); diff --git a/src/apm.c b/src/apm.c index 76fc24257..d7ce262a3 100644 --- a/src/apm.c +++ b/src/apm.c @@ -52,9 +52,9 @@ apm_set_do_smi(apm_t *dev, uint8_t do_smi) } static void -apm_out(uint16_t port, uint8_t val, void *p) +apm_out(uint16_t port, uint8_t val, void *priv) { - apm_t *dev = (apm_t *) p; + apm_t *dev = (apm_t *) priv; apm_log("[%04X:%08X] APM write: %04X = %02X (BX = %04X, CX = %04X)\n", CS, cpu_state.pc, port, val, BX, CX); @@ -69,10 +69,10 @@ apm_out(uint16_t port, uint8_t val, void *p) } static uint8_t -apm_in(uint16_t port, void *p) +apm_in(uint16_t port, void *priv) { - apm_t *dev = (apm_t *) p; - uint8_t ret = 0xff; + const apm_t *dev = (apm_t *) priv; + uint8_t ret = 0xff; port &= 0x0001; @@ -87,24 +87,23 @@ apm_in(uint16_t port, void *p) } static void -apm_reset(void *p) +apm_reset(void *priv) { - apm_t *dev = (apm_t *) p; + apm_t *dev = (apm_t *) priv; dev->cmd = dev->stat = 0x00; } static void -apm_close(void *p) +apm_close(void *priv) { - apm_t *dev = (apm_t *) p; + apm_t *dev = (apm_t *) priv; free(dev); } -static void - * - apm_init(const device_t *info) +static void * +apm_init(const device_t *info) { apm_t *dev = (apm_t *) malloc(sizeof(apm_t)); memset(dev, 0, sizeof(apm_t)); diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 31c5d2165..3ca7e6885 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -163,7 +163,7 @@ cdrom_interface_get_from_internal_name(char *s) int c = 0; while (controllers[c].device != NULL) { - if (!strcmp((char *) controllers[c].device->internal_name, s)) + if (!strcmp(controllers[c].device->internal_name, s)) return c; c++; } @@ -183,12 +183,12 @@ cdrom_interface_has_config(int cdinterface) const device_t *dev = cdrom_interface_get_device(cdinterface); if (dev == NULL) - return (0); + return 0; if (!device_has_config(dev)) - return (0); + return 0; - return (1); + return 1; } int @@ -257,7 +257,9 @@ int cdrom_lba_to_msf_accurate(int lba) { int pos; - int m, s, f; + int m; + int s; + int f; pos = lba + 150; f = pos % 75; @@ -401,7 +403,9 @@ cdrom_stop(cdrom_t *dev) void cdrom_seek(cdrom_t *dev, uint32_t pos, uint8_t vendor_type) { - int m, s, f; + int m; + int s; + int f; if (!dev) return; @@ -418,6 +422,8 @@ cdrom_seek(cdrom_t *dev, uint32_t pos, uint8_t vendor_type) case 0x80: pos = bcd2bin((pos >> 24) & 0xff); break; + default: + break; } dev->seek_pos = pos; @@ -498,7 +504,9 @@ uint8_t cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf) { track_info_t ti; - int m = 0, s = 0, f = 0; + int m = 0; + int s = 0; + int f = 0; if (dev->cd_status == CD_STATUS_DATA_ONLY) return 0; @@ -570,7 +578,9 @@ cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf) uint8_t cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit) { - int m = 0, s = 0, f = 0; + int m = 0; + int s = 0; + int f = 0; if (dev->cd_status == CD_STATUS_DATA_ONLY) return 0; @@ -603,6 +613,8 @@ cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit) } dev->seek_pos = (pos >> 24) & 0xff; break; + default: + break; } /* Unlike standard commands, if there's a data track on an Audio CD (mixed mode) @@ -615,7 +627,9 @@ cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit) uint8_t cdrom_audio_play_toshiba(cdrom_t *dev, uint32_t pos, int type) { - int m = 0, s = 0, f = 0; + int m = 0; + int s = 0; + int f = 0; if (dev->cd_status == CD_STATUS_DATA_ONLY) return 0; @@ -642,6 +656,8 @@ cdrom_audio_play_toshiba(cdrom_t *dev, uint32_t pos, int type) } dev->cd_end = pos; break; + default: + break; } cdrom_log("Toshiba/NEC Play Audio: MSF = %06x, type = %02x, cdstatus = %02x\n", pos, type, dev->cd_status); @@ -657,7 +673,9 @@ cdrom_audio_play_toshiba(cdrom_t *dev, uint32_t pos, int type) uint8_t cdrom_audio_scan(cdrom_t *dev, uint32_t pos, int type) { - int m = 0, s = 0, f = 0; + int m = 0; + int s = 0; + int f = 0; if (dev->cd_status == CD_STATUS_DATA_ONLY) return 0; @@ -686,6 +704,8 @@ cdrom_audio_scan(cdrom_t *dev, uint32_t pos, int type) case 0x80: dev->seek_pos = (pos >> 24) & 0xff; break; + default: + break; } /* Do this at this point, since it's at this point that we know the @@ -712,7 +732,10 @@ cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) { uint8_t ret; subchannel_t subc; - int pos = 1, m, s, f; + int pos = 1; + int m; + int s; + int f; uint32_t dat; dev->ops->get_subchannel(dev, dev->seek_pos, &subc); @@ -895,9 +918,13 @@ static int read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf) { track_info_t ti; - int i, len = 4; - int m, s, f; - int first_track, last_track; + int i; + int len = 4; + int m; + int s; + int f; + int first_track; + int last_track; uint32_t temp; cdrom_log("read_toc_normal(%08X, %08X, %02X, %i)\n", dev, b, start_track, msf); @@ -978,7 +1005,10 @@ static int read_toc_session(cdrom_t *dev, unsigned char *b, int msf) { track_info_t ti; - int len = 4, m, s, f; + int len = 4; + int m; + int s; + int f; uint32_t temp; cdrom_log("read_toc_session(%08X, %08X, %i)\n", dev, b, msf); @@ -1027,8 +1057,9 @@ static int read_toc_raw(cdrom_t *dev, unsigned char *b) { track_info_t ti; - int i, len = 4; - int first_track, last_track; + int len = 4; + int first_track; + int last_track; cdrom_log("read_toc_raw(%08X, %08X)\n", dev, b); @@ -1037,7 +1068,7 @@ read_toc_raw(cdrom_t *dev, unsigned char *b) /* Bytes 2 and 3 = Number of first and last sessions */ b[2] = b[3] = 1; - for (i = 0; i <= last_track; i++) { + for (int i = 0; i <= last_track; i++) { dev->ops->get_track_info(dev, i + 1, 0, &ti); cdrom_log(" tracks(%i) = %02X, %02X, %i:%02i.%02i\n", i, ti.attr, ti.number, ti.m, ti.s, ti.f); @@ -1061,8 +1092,10 @@ static int read_toc_sony(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf) { track_info_t ti; - int i, len = 4; - int first_track, last_track; + int i; + int len = 4; + int first_track; + int last_track; uint32_t temp; cdrom_log("read_toc_sony(%08X, %08X, %02X, %i)\n", dev, b, start_track, msf); @@ -1173,7 +1206,8 @@ void cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf) { track_info_t ti; - int first_track, last_track; + int first_track; + int last_track; if (dev != NULL) { dev->ops->get_tracks(dev, &first_track, &last_track); @@ -1196,7 +1230,8 @@ void cdrom_get_q(cdrom_t *dev, uint8_t *buf, int *curtoctrk, uint8_t mode) { track_info_t ti; - int first_track, last_track; + int first_track; + int last_track; if (dev != NULL) { dev->ops->get_tracks(dev, &first_track, &last_track); @@ -1254,8 +1289,11 @@ uint8_t cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, int type) { track_info_t ti; - int first_track, last_track; - int m = 0, s = 0, f = 0; + int first_track; + int last_track; + int m = 0; + int s = 0; + int f = 0; dev->ops->get_tracks(dev, &first_track, &last_track); @@ -1301,13 +1339,15 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in b[2] = 0; b[3] = 0; break; + default: + break; } return 1; } static int -track_type_is_valid(uint8_t id, int type, int flags, int audio, int mode2) +track_type_is_valid(UNUSED(uint8_t id), int type, int flags, int audio, int mode2) { if (!(flags & 0x70) && (flags & 0xf8)) { /* 0x08/0x80/0x88 are illegal modes */ cdrom_log("CD-ROM %i: [Any Mode] 0x08/0x80/0x88 are illegal modes\n", id); @@ -1583,10 +1623,15 @@ int cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, int cdrom_sector_flags, int *len, uint8_t vendor_type) { - uint8_t *b, *temp_b; - uint32_t msf, lba; - int audio = 0, mode2 = 0; - int m, s, f; + uint8_t *b; + uint8_t *temp_b; + uint32_t msf; + uint32_t lba; + int audio = 0; + int mode2 = 0; + int m; + int s; + int f; if (dev->cd_status == CD_STATUS_EMPTY) return 0; @@ -1763,9 +1808,8 @@ void cdrom_hard_reset(void) { cdrom_t *dev; - int i; - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { dev = &cdrom[i]; if (dev->bus_type) { cdrom_log("CD-ROM %i: Hard reset\n", i); @@ -1798,9 +1842,8 @@ void cdrom_close(void) { cdrom_t *dev; - int i; - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { dev = &cdrom[i]; if (dev->bus_type == CDROM_BUS_SCSI) diff --git a/src/cdrom/cdrom_image.c b/src/cdrom/cdrom_image.c index 2742d0e80..0c7ee03a0 100644 --- a/src/cdrom/cdrom_image.c +++ b/src/cdrom/cdrom_image.c @@ -84,7 +84,8 @@ static void image_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc) { cd_img_t *img = (cd_img_t *) dev->image; - TMSF rel_pos, abs_pos; + TMSF rel_pos; + TMSF abs_pos; cdi_get_audio_sub(img, lba, &subc->attr, &subc->track, &subc->index, &rel_pos, &abs_pos); @@ -102,17 +103,19 @@ static int image_get_capacity(cdrom_t *dev) { cd_img_t *img = (cd_img_t *) dev->image; - int first_track, last_track; - int number, c; + int first_track; + int last_track; + int number; unsigned char attr; - uint32_t address = 0, lb = 0; + uint32_t address = 0; + uint32_t lb = 0; if (!img) return 0; cdi_get_audio_tracks_lba(img, &first_track, &last_track, &lb); - for (c = 0; c <= last_track; c++) { + for (int c = 0; c <= last_track; c++) { cdi_get_audio_track_info_lba(img, 0, c + 1, &number, &address, &attr); if (address > lb) lb = address; @@ -127,8 +130,11 @@ image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf) cd_img_t *img = (cd_img_t *) dev->image; uint8_t attr; TMSF tmsf; - int m, s, f; - int number, track; + int m; + int s; + int f; + int number; + int track; if (!img || (dev->cd_status == CD_STATUS_DATA_ONLY)) return 0; diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c index d3f48578d..e94668d75 100644 --- a/src/cdrom/cdrom_image_backend.c +++ b/src/cdrom/cdrom_image_backend.c @@ -159,7 +159,15 @@ bin_init(const char *filename, int *error) tf->get_length = bin_get_length; tf->close = bin_close; } else { - free(tf); + /* From the check above, error may still be non-zero if opening a directory. + * The error is set for viso to try and open the directory following this function. + * However, we need to make sure the descriptor is closed. */ + if ((tf->file != NULL) && ((stats.st_mode & S_IFMT) == S_IFDIR)) { + /* tf is freed by bin_close */ + bin_close(tf); + } else { + free(tf); + } tf = NULL; } @@ -194,14 +202,13 @@ track_file_close(track_t *trk) static void cdi_clear_tracks(cd_img_t *cdi) { - int i; - track_file_t *last = NULL; + const track_file_t *last = NULL; track_t *cur = NULL; if ((cdi->tracks == NULL) || (cdi->tracks_num == 0)) return; - for (i = 0; i < cdi->tracks_num; i++) { + for (int i = 0; i < cdi->tracks_num; i++) { cur = &cdi->tracks[i]; /* Make sure we do not attempt to close a NULL file. */ @@ -266,7 +273,7 @@ cdi_get_audio_tracks_lba(cd_img_t *cdi, int *st_track, int *end, uint32_t *lead_ int cdi_get_audio_track_pre(cd_img_t *cdi, int track) { - track_t *trk = &cdi->tracks[track - 1]; + const track_t *trk = &cdi->tracks[track - 1]; if ((track < 1) || (track > cdi->tracks_num)) return 0; @@ -276,9 +283,9 @@ cdi_get_audio_track_pre(cd_img_t *cdi, int track) /* This replaces both Info and EndInfo, they are specified by a variable. */ int -cdi_get_audio_track_info(cd_img_t *cdi, int end, int track, int *track_num, TMSF *start, uint8_t *attr) +cdi_get_audio_track_info(cd_img_t *cdi, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) { - track_t *trk = &cdi->tracks[track - 1]; + const track_t *trk = &cdi->tracks[track - 1]; int pos = trk->start + 150; if ((track < 1) || (track > cdi->tracks_num)) @@ -295,9 +302,9 @@ cdi_get_audio_track_info(cd_img_t *cdi, int end, int track, int *track_num, TMSF } int -cdi_get_audio_track_info_lba(cd_img_t *cdi, int end, int track, int *track_num, uint32_t *start, uint8_t *attr) +cdi_get_audio_track_info_lba(cd_img_t *cdi, UNUSED(int end), int track, int *track_num, uint32_t *start, uint8_t *attr) { - track_t *trk = &cdi->tracks[track - 1]; + const track_t *trk = &cdi->tracks[track - 1]; if ((track < 1) || (track > cdi->tracks_num)) return 0; @@ -313,8 +320,8 @@ cdi_get_audio_track_info_lba(cd_img_t *cdi, int end, int track, int *track_num, int cdi_get_track(cd_img_t *cdi, uint32_t sector) { - int i; - track_t *cur, *next; + const track_t *cur; + const track_t *next; /* There must be at least two tracks - data and lead out. */ if (cdi->tracks_num < 2) @@ -322,7 +329,7 @@ cdi_get_track(cd_img_t *cdi, uint32_t sector) /* This has a problem - the code skips the last track, which is lead out - is that correct? */ - for (i = 0; i < (cdi->tracks_num - 1); i++) { + for (int i = 0; i < (cdi->tracks_num - 1); i++) { cur = &cdi->tracks[i]; next = &cdi->tracks[i + 1]; if ((cur->start <= sector) && (sector < next->start)) @@ -336,8 +343,8 @@ cdi_get_track(cd_img_t *cdi, uint32_t sector) int cdi_get_audio_sub(cd_img_t *cdi, uint32_t sector, uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos) { - int cur_track = cdi_get_track(cdi, sector); - track_t *trk; + int cur_track = cdi_get_track(cdi, sector); + const track_t *trk; if (cur_track < 1) return 0; @@ -360,12 +367,17 @@ cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector) { size_t length; int track = cdi_get_track(cdi, sector) - 1; - uint64_t sect = (uint64_t) sector, seek; + uint64_t sect = (uint64_t) sector; + uint64_t seek; track_t *trk; - int track_is_raw, ret; - int raw_size, cooked_size; + int track_is_raw; + int ret; + int raw_size; + int cooked_size; uint64_t offset = 0ULL; - int m = 0, s = 0, f = 0; + int m = 0; + int s = 0; + int f = 0; if (track < 0) return 0; @@ -420,9 +432,10 @@ cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector) int cdi_read_sectors(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector, uint32_t num) { - int sector_size, success = 1; + int sector_size; + int success = 1; uint8_t *buf; - uint32_t buf_len, i; + uint32_t buf_len; /* TODO: This fails to account for Mode 2. Shouldn't we have a function to get sector size? */ @@ -430,7 +443,7 @@ cdi_read_sectors(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector, uint3 buf_len = num * sector_size; buf = (uint8_t *) malloc(buf_len * sizeof(uint8_t)); - for (i = 0; i < num; i++) { + for (uint32_t i = 0; i < num; i++) { success = cdi_read_sector(cdi, &buf[i * sector_size], raw, sector + i); if (!success) break; @@ -453,7 +466,8 @@ cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector) { int track = cdi_get_track(cdi, sector) - 1; track_t *trk; - uint64_t s = (uint64_t) sector, seek; + uint64_t s = (uint64_t) sector; + uint64_t seek; if (track < 0) return 0; @@ -469,8 +483,8 @@ cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector) int cdi_get_sector_size(cd_img_t *cdi, uint32_t sector) { - int track = cdi_get_track(cdi, sector) - 1; - track_t *trk; + int track = cdi_get_track(cdi, sector) - 1; + const track_t *trk; if (track < 0) return 0; @@ -482,8 +496,8 @@ cdi_get_sector_size(cd_img_t *cdi, uint32_t sector) int cdi_is_mode2(cd_img_t *cdi, uint32_t sector) { - int track = cdi_get_track(cdi, sector) - 1; - track_t *trk; + int track = cdi_get_track(cdi, sector) - 1; + const track_t *trk; if (track < 0) return 0; @@ -496,8 +510,8 @@ cdi_is_mode2(cd_img_t *cdi, uint32_t sector) int cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector) { - int track = cdi_get_track(cdi, sector) - 1; - track_t *trk; + int track = cdi_get_track(cdi, sector) - 1; + const track_t *trk; if (track < 0) return 0; @@ -542,7 +556,8 @@ cdi_track_push_back(cd_img_t *cdi, track_t *trk) int cdi_load_iso(cd_img_t *cdi, const char *filename) { - int error, ret = 2; + int error; + int ret = 2; track_t trk; cdi->tracks = NULL; @@ -637,7 +652,9 @@ cdi_cue_get_buffer(char *str, char **line, int up) done = 1; break; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: if (up && islower((int) *s)) @@ -690,7 +707,9 @@ static int cdi_cue_get_frame(uint64_t *frames, char **line) { char temp[128]; - int min, sec, fr; + int min; + int sec; + int fr; int success; success = cdi_cue_get_buffer(temp, line, 0); @@ -709,7 +728,8 @@ cdi_cue_get_frame(uint64_t *frames, char **line) static int cdi_cue_get_flags(track_t *cur, char **line) { - char temp[128], temp2[128]; + char temp[128]; + char temp2[128]; int success; success = cdi_cue_get_buffer(temp, line, 0); @@ -730,7 +750,8 @@ static int cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, uint64_t *total_pregap, uint64_t cur_pregap) { /* Frames between index 0 (prestart) and 1 (current track start) must be skipped. */ - uint64_t skip, temp; + uint64_t skip; + uint64_t temp; track_t *prev = NULL; /* Skip *MUST* be calculated even if prestart is 0. */ @@ -749,7 +770,7 @@ cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, u } /* First track (track number must be 1). */ - if (cdi->tracks_num == 0) { + if ((prev == NULL) || (cdi->tracks_num == 0)) { /* I guess this makes sure the structure is not filled with invalid data. */ if (cur->number != 1) return 0; @@ -768,7 +789,7 @@ cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, u *total_pregap += cur_pregap; cur->start += *total_pregap; } else { - temp = prev->file->get_length(prev->file) - ((uint64_t) prev->skip); + temp = prev->file->get_length(prev->file) - (prev->skip); prev->length = temp / ((uint64_t) prev->sector_size); if ((temp % prev->sector_size) != 0) prev->length++; @@ -797,16 +818,23 @@ int cdi_load_cue(cd_img_t *cdi, const char *cuefile) { track_t trk; - char pathname[MAX_FILENAME_LENGTH], filename[MAX_FILENAME_LENGTH]; + char pathname[MAX_FILENAME_LENGTH]; + char filename[MAX_FILENAME_LENGTH]; char temp[MAX_FILENAME_LENGTH]; - uint64_t shift = 0ULL, prestart = 0ULL; - uint64_t cur_pregap = 0ULL, total_pregap = 0ULL; - uint64_t frame = 0ULL, index; - int i, success; - int error, can_add_track = 0; + uint64_t shift = 0ULL; + uint64_t prestart = 0ULL; + uint64_t cur_pregap = 0ULL; + uint64_t total_pregap = 0ULL; + uint64_t frame = 0ULL; + uint64_t index; + int success; + int error; + int can_add_track = 0; FILE *fp; - char buf[MAX_LINE_LENGTH], ansi[MAX_FILENAME_LENGTH]; - char *line, *command; + char buf[MAX_LINE_LENGTH]; + char ansi[MAX_FILENAME_LENGTH]; + char *line; + char *command; char *type; cdi->tracks = NULL; @@ -834,7 +862,7 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile) /* Do two iterations to make sure to nuke even if it's \r\n or \n\r, but do checks to make sure we're not nuking other bytes. */ - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { if (strlen(buf) > 0) { if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; @@ -1027,13 +1055,11 @@ cdi_load_cue(cd_img_t *cdi, const char *cuefile) int cdi_has_data_track(cd_img_t *cdi) { - int i; - if ((cdi == NULL) || (cdi->tracks == NULL)) return 0; /* Data track has attribute 0x14. */ - for (i = 0; i < cdi->tracks_num; i++) { + for (int i = 0; i < cdi->tracks_num; i++) { if (cdi->tracks[i].attr == DATA_TRACK) return 1; } @@ -1044,13 +1070,11 @@ cdi_has_data_track(cd_img_t *cdi) int cdi_has_audio_track(cd_img_t *cdi) { - int i; - if ((cdi == NULL) || (cdi->tracks == NULL)) return 0; /* Audio track has attribute 0x14. */ - for (i = 0; i < cdi->tracks_num; i++) { + for (int i = 0; i < cdi->tracks_num; i++) { if (cdi->tracks[i].attr == AUDIO_TRACK) return 1; } diff --git a/src/cdrom/cdrom_image_viso.c b/src/cdrom/cdrom_image_viso.c index d4fc2b2a9..45182481d 100644 --- a/src/cdrom/cdrom_image_viso.c +++ b/src/cdrom/cdrom_image_viso.c @@ -114,8 +114,10 @@ typedef struct _viso_entry_ { } viso_entry_t; typedef struct { - uint64_t vol_size_offsets[2], pt_meta_offsets[2]; - int format, use_version_suffix : 1; + uint64_t vol_size_offsets[2]; + uint64_t pt_meta_offsets[2]; + int format; + uint8_t use_version_suffix : 1; size_t metadata_sectors, all_sectors, entry_map_size, sector_size, file_fifo_pos; uint8_t *metadata; @@ -218,7 +220,7 @@ viso_convert_utf8(wchar_t *dest, const char *src, ssize_t buf_size) return p - dest; } -#define VISO_WRITE_STR_FUNC(func, dst_type, src_type, converter) \ +#define VISO_WRITE_STR_FUNC(func, dst_type, src_type, converter, bounds_chk) \ static void \ func(dst_type *dest, const src_type *src, ssize_t buf_size, int charset) \ { \ @@ -284,7 +286,7 @@ viso_convert_utf8(wchar_t *dest, const char *src, ssize_t buf_size) \ default: \ /* Not valid for D or A, but valid for filenames. */ \ - if ((charset < VISO_CHARSET_FN) || (c > 0xffff)) \ + if ((charset < VISO_CHARSET_FN) || (bounds_chk)) \ c = '_'; \ break; \ } \ @@ -293,15 +295,16 @@ viso_convert_utf8(wchar_t *dest, const char *src, ssize_t buf_size) *dest++ = converter(c); \ } \ } -VISO_WRITE_STR_FUNC(viso_write_string, uint8_t, char, ) -VISO_WRITE_STR_FUNC(viso_write_wstring, uint16_t, wchar_t, cpu_to_be16) +VISO_WRITE_STR_FUNC(viso_write_string, uint8_t, char, , 0) +VISO_WRITE_STR_FUNC(viso_write_wstring, uint16_t, wchar_t, cpu_to_be16, c > 0xffff) static int viso_fill_fn_short(char *data, const viso_entry_t *entry, viso_entry_t **entries) { /* Get name and extension length. */ const char *ext_pos = strrchr(entry->basename, '.'); - int name_len, ext_len; + int name_len; + int ext_len; if (ext_pos) { name_len = ext_pos - entry->basename; ext_len = strlen(ext_pos); @@ -367,7 +370,7 @@ viso_fill_fn_rr(uint8_t *data, const viso_entry_t *entry, size_t max_len) /* Relocate extension if the original name exceeds the maximum length. */ if (!S_ISDIR(entry->stats.st_mode)) { /* do this on files only */ - char *ext = strrchr(entry->basename, '.'); + const char *ext = strrchr(entry->basename, '.'); if (ext > entry->basename) { len = strlen(ext); if (len >= max_len) @@ -398,7 +401,7 @@ viso_fill_fn_joliet(uint8_t *data, const viso_entry_t *entry, size_t max_len) /* /* Relocate extension if the original name exceeds the maximum length. */ if (!S_ISDIR(entry->stats.st_mode)) { /* do this on files only */ - wchar_t *ext = wcsrchr(utf8dec, L'.'); + const wchar_t *ext = wcsrchr(utf8dec, L'.'); if (ext > utf8dec) { len = wcslen(ext); if (len > max_len) @@ -472,7 +475,9 @@ viso_fill_time(uint8_t *data, time_t time, int format, int longform) static int viso_fill_dir_record(uint8_t *data, viso_entry_t *entry, viso_t *viso, int type) { - uint8_t *p = data, *q, *r; + uint8_t *p = data; + uint8_t *q; + uint8_t *r; *p++ = 0; /* size (filled in later) */ *p++ = 0; /* extended attribute length */ @@ -626,10 +631,17 @@ pad_susp: if (!(*q & 1)) /* padding for even file ID lengths */ *p++ = 0; break; + + default: + break; } if ((p - data) > 255) - fatal("VISO: Directory record overflow (%d) on entry %08X\n", p - data, entry); +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + fatal("VISO: Directory record overflow (%d) on entry %016" PRIX64 "\n", (uint32_t) (uintptr_t) (p - data), (uint64_t) (uintptr_t) entry); +#else + fatal("VISO: Directory record overflow (%d) on entry %08X\n", (uint32_t) (uintptr_t) (p - data), (uint32_t) (uintptr_t) entry); +#endif data[0] = p - data; /* length */ return data[0]; @@ -650,9 +662,9 @@ viso_read(void *p, uint8_t *buffer, uint64_t seek, size_t count) /* Handle reads in a sector by sector basis. */ while (count > 0) { /* Determine the current sector, offset and remainder. */ - uint32_t sector = seek / viso->sector_size, - sector_offset = seek % viso->sector_size, - sector_remain = MIN(count, viso->sector_size - sector_offset); + uint32_t sector = seek / viso->sector_size; + uint32_t sector_offset = seek % viso->sector_size; + uint32_t sector_remain = MIN(count, viso->sector_size - sector_offset); /* Handle sector. */ if (sector < viso->metadata_sectors) { @@ -713,8 +725,9 @@ viso_read(void *p, uint8_t *buffer, uint64_t seek, size_t count) uint64_t viso_get_length(void *p) { - track_file_t *tf = (track_file_t *) p; - viso_t *viso = (viso_t *) tf->priv; + track_file_t *tf = (track_file_t *) p; + const viso_t *viso = (viso_t *) tf->priv; + return ((uint64_t) viso->all_sectors) * viso->sector_size; } @@ -736,7 +749,8 @@ viso_close(void *p) remove(nvr_path(viso->tf.fn)); #endif - viso_entry_t *entry = viso->root_dir, *next_entry; + viso_entry_t *entry = viso->root_dir; + viso_entry_t *next_entry; while (entry) { if (entry->file) fclose(entry->file); @@ -760,7 +774,8 @@ viso_init(const char *dirname, int *error) /* Initialize our data structure. */ viso_t *viso = (viso_t *) calloc(1, sizeof(viso_t)); - uint8_t *data = NULL, *p; + uint8_t *data = NULL; + uint8_t *p; *error = 1; if (viso == NULL) goto end; @@ -785,12 +800,18 @@ viso_init(const char *dirname, int *error) /* Set up directory traversal. */ cdrom_image_viso_log("VISO: Traversing directories:\n"); - viso_entry_t *entry, *last_entry, *dir, *last_dir, *eltorito_dir = NULL, *eltorito_entry = NULL; - struct dirent *readdir_entry; - int len, eltorito_others_present = 0; - size_t dir_path_len; - uint64_t eltorito_offset = 0; - uint8_t eltorito_type = 0; + viso_entry_t *entry; + viso_entry_t *last_entry; + viso_entry_t *dir; + viso_entry_t *last_dir; + const viso_entry_t *eltorito_dir = NULL; + const viso_entry_t *eltorito_entry = NULL; + struct dirent *readdir_entry; + int len; + int eltorito_others_present = 0; + size_t dir_path_len; + uint64_t eltorito_offset = 0; + uint8_t eltorito_type = 0; /* Fill root directory entry. */ dir_path_len = strlen(dirname); @@ -1445,8 +1466,8 @@ next_entry: /* Go through files, assigning sectors to them. */ cdrom_image_viso_log("VISO: Assigning sectors to files:\n"); size_t base_factor = viso->sector_size / orig_sector_size; - viso_entry_t *prev_entry = viso->root_dir, - **entry_map_p = viso->entry_map; + viso_entry_t *prev_entry = viso->root_dir; + viso_entry_t **entry_map_p = viso->entry_map; entry = prev_entry->next; while (entry) { /* Skip this entry if it corresponds to a directory. */ @@ -1512,7 +1533,8 @@ next_entry: if (!viso->metadata) goto end; fseeko64(viso->tf.file, 0, SEEK_SET); - uint64_t metadata_size = viso->metadata_sectors * viso->sector_size, metadata_remain = metadata_size; + uint64_t metadata_size = viso->metadata_sectors * viso->sector_size; + uint64_t metadata_remain = metadata_size; while (metadata_remain > 0) metadata_remain -= fread(viso->metadata + (metadata_size - metadata_remain), 1, MIN(metadata_remain, viso->sector_size), viso->tf.file); diff --git a/src/cdrom/cdrom_mitsumi.c b/src/cdrom/cdrom_mitsumi.c index e7e12bb94..6c015fa9d 100644 --- a/src/cdrom/cdrom_mitsumi.c +++ b/src/cdrom/cdrom_mitsumi.c @@ -116,7 +116,9 @@ typedef struct { /* The addresses sent from the guest are absolute, ie. a LBA of 0 corresponds to a MSF of 00:00:00. Otherwise, the counter displayed by the guest is wrong: there is a seeming 2 seconds in which audio plays but counter does not move, while a data track before audio jumps to 2 seconds before the actual start of the audio while audio still plays. With an absolute conversion, the counter is fine. */ +#ifdef MSFtoLBA #undef MSFtoLBA +#endif #define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) #define CD_BCD(x) (((x) % 10) | (((x) / 10) << 4)) @@ -242,9 +244,11 @@ mitsumi_cdrom_in(uint16_t port, void *priv) ret |= FLAG_NOSTAT; pclog("Read port 1: ret = %02x\n", ret | FLAG_UNK); return ret | FLAG_UNK; + default: + break; } - return (0xff); + return 0xff; } static void @@ -283,6 +287,8 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) case 0x10: dev->enable_irq = val; break; + default: + break; } dev->cmdbuf[1] = 0; dev->cmdbuf_count = 2; @@ -297,6 +303,8 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) if (dev->conf == 1) dev->cmdrd_count++; break; + default: + break; } break; case CMD_READ1X: @@ -316,12 +324,19 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) break; case 5: dev->readmsf = 0; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 4: case 3: dev->readmsf |= CD_DCB(val) << ((dev->cmdrd_count - 3) << 3); break; + default: + break; } break; + default: + break; } if (!dev->cmdrd_count) dev->stat = cdrom.host_drive ? (STAT_READY | (dev->change ? STAT_CHANGE : 0)) : 0; @@ -406,11 +421,13 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) case 1: mitsumi_cdrom_reset(dev); break; + default: + break; } } static void * -mitsumi_cdrom_init(const device_t *info) +mitsumi_cdrom_init(UNUSED(const device_t *info)) { mcd_t *dev; diff --git a/src/chipset/82c100.c b/src/chipset/82c100.c index 516768742..689234ebb 100644 --- a/src/chipset/82c100.c +++ b/src/chipset/82c100.c @@ -28,23 +28,24 @@ #include <86box/io.h> #include <86box/mem.h> #include <86box/nmi.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/rom.h> #include <86box/chipset.h> -typedef struct -{ +typedef struct ems_page_t { int enabled; - uint32_t virt, phys; + uint32_t virt; + uint32_t phys; } ems_page_t; -typedef struct -{ - uint8_t index, access; - uint16_t ems_io_base; - uint32_t ems_window_base; - uint8_t ems_page_regs[4], - regs[256]; +typedef struct ct_82c100_t { + uint8_t index; + uint8_t access; + uint16_t ems_io_base; + uint32_t ems_window_base; + uint8_t ems_page_regs[4]; + uint8_t regs[256]; ems_page_t ems_pages[4]; mem_mapping_t ems_mappings[4]; } ct_82c100_t; @@ -70,10 +71,9 @@ ct_82c100_log(const char *fmt, ...) static void ct_82c100_ems_pages_recalc(ct_82c100_t *dev) { - int i; uint32_t page_base; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { page_base = dev->ems_window_base + (i << 14); if ((i == 1) || (i == 2)) page_base ^= 0xc000; @@ -109,7 +109,7 @@ ct_82c100_ems_out(uint16_t port, uint8_t val, void *priv) static uint8_t ct_82c100_ems_in(uint16_t port, void *priv) { - ct_82c100_t *dev = (ct_82c100_t *) priv; + const ct_82c100_t *dev = (ct_82c100_t *) priv; uint8_t ret = 0xff; ret = dev->ems_page_regs[port >> 14]; @@ -120,9 +120,7 @@ ct_82c100_ems_in(uint16_t port, void *priv) static void ct_82c100_ems_update(ct_82c100_t *dev) { - int i; - - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { ct_82c100_log("Disabling EMS I/O handler %i at %04X\n", i, dev->ems_io_base + (i << 14)); io_handler(0, dev->ems_io_base + (i << 14), 1, ct_82c100_ems_in, NULL, NULL, ct_82c100_ems_out, NULL, NULL, dev); @@ -130,7 +128,7 @@ ct_82c100_ems_update(ct_82c100_t *dev) dev->ems_io_base = 0x0208 + (dev->regs[0x4c] & 0xf0); - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { ct_82c100_log("Enabling EMS I/O handler %i at %04X\n", i, dev->ems_io_base + (i << 14)); io_handler(1, dev->ems_io_base + (i << 14), 1, ct_82c100_ems_in, NULL, NULL, ct_82c100_ems_out, NULL, NULL, dev); @@ -222,6 +220,9 @@ ct_82c100_out(uint16_t port, uint8_t val, void *priv) dev->regs[0x4c] = val; ct_82c100_ems_update(dev); break; + + default: + break; } dev->access = 0; } @@ -258,6 +259,9 @@ ct_82c100_in(uint16_t port, void *priv) case 0x4c: ret = dev->regs[dev->index]; break; + + default: + break; } dev->access = 0; } @@ -274,15 +278,15 @@ ct_82c100_in(uint16_t port, void *priv) static uint8_t mem_read_emsb(uint32_t addr, void *priv) { - ems_page_t *page = (ems_page_t *) priv; - uint8_t ret = 0xff; + const ems_page_t *page = (ems_page_t *) priv; + uint8_t ret = 0xff; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; #endif addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = ram[addr]; ct_82c100_log("mem_read_emsb(%08X = %08X): %02X\n", old_addr, addr, ret); @@ -293,7 +297,7 @@ mem_read_emsb(uint32_t addr, void *priv) static uint16_t mem_read_emsw(uint32_t addr, void *priv) { - ems_page_t *page = (ems_page_t *) priv; + const ems_page_t *page = (ems_page_t *) priv; uint16_t ret = 0xffff; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; @@ -301,7 +305,7 @@ mem_read_emsw(uint32_t addr, void *priv) addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = *(uint16_t *) &ram[addr]; ct_82c100_log("mem_read_emsw(%08X = %08X): %04X\n", old_addr, addr, ret); @@ -312,14 +316,14 @@ mem_read_emsw(uint32_t addr, void *priv) static void mem_write_emsb(uint32_t addr, uint8_t val, void *priv) { - ems_page_t *page = (ems_page_t *) priv; + const ems_page_t *page = (ems_page_t *) priv; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; #endif addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ram[addr] = val; ct_82c100_log("mem_write_emsb(%08X = %08X, %02X)\n", old_addr, addr, val); @@ -328,14 +332,14 @@ mem_write_emsb(uint32_t addr, uint8_t val, void *priv) static void mem_write_emsw(uint32_t addr, uint16_t val, void *priv) { - ems_page_t *page = (ems_page_t *) priv; + const ems_page_t *page = (ems_page_t *) priv; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; #endif addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) *(uint16_t *) &ram[addr] = val; ct_82c100_log("mem_write_emsw(%08X = %08X, %04X)\n", old_addr, addr, val); @@ -350,10 +354,9 @@ ct_82c100_close(void *priv) } static void * -ct_82c100_init(const device_t *info) +ct_82c100_init(UNUSED(const device_t *info)) { ct_82c100_t *dev; - uint32_t i; dev = (ct_82c100_t *) malloc(sizeof(ct_82c100_t)); memset(dev, 0x00, sizeof(ct_82c100_t)); @@ -367,7 +370,7 @@ ct_82c100_init(const device_t *info) io_sethandler(0x007e, 2, ct_82c100_in, NULL, NULL, ct_82c100_out, NULL, NULL, dev); - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { mem_mapping_add(&(dev->ems_mappings[i]), (i + 28) << 14, 0x04000, mem_read_emsb, mem_read_emsw, NULL, mem_write_emsb, mem_write_emsw, NULL, @@ -379,7 +382,7 @@ ct_82c100_init(const device_t *info) device_add(&port_92_device); - return (dev); + return dev; } const device_t ct_82c100_device = { diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 765913672..9ce29bdff 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -30,6 +30,7 @@ #include <86box/io.h> #include <86box/mem.h> #include <86box/port_92.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> #define ENABLED_SHADOW (MEM_READ_INTERNAL | ((dev->regs[0x02] & 0x20) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL)) @@ -57,20 +58,21 @@ acc2168_log(const char *fmt, ...) #endif typedef struct acc2168_t { - uint8_t reg_idx, regs[256]; + uint8_t reg_idx; + uint8_t regs[256]; } acc2168_t; static void acc2168_shadow_recalc(acc2168_t *dev) { - for (uint32_t i = 0; i < 5; i++) + for (uint8_t i = 0; i < 5; i++) mem_set_mem_state_both(SHADOW_ADDR, SHADOW_SIZE, SHADOW_RECALC); } static void -acc2168_write(uint16_t addr, uint8_t val, void *p) +acc2168_write(uint16_t addr, uint8_t val, void *priv) { - acc2168_t *dev = (acc2168_t *) p; + acc2168_t *dev = (acc2168_t *) priv; switch (addr) { case 0xf2: @@ -158,13 +160,15 @@ acc2168_write(uint16_t addr, uint8_t val, void *p) break; } break; + default: + break; } } static uint8_t -acc2168_read(uint16_t addr, void *p) +acc2168_read(uint16_t addr, void *priv) { - acc2168_t *dev = (acc2168_t *) p; + const acc2168_t *dev = (acc2168_t *) priv; return (addr == 0xf3) ? dev->regs[dev->reg_idx] : dev->reg_idx; } @@ -178,7 +182,7 @@ acc2168_close(void *priv) } static void * -acc2168_init(const device_t *info) +acc2168_init(UNUSED(const device_t *info)) { acc2168_t *dev = (acc2168_t *) malloc(sizeof(acc2168_t)); memset(dev, 0, sizeof(acc2168_t)); diff --git a/src/chipset/ali1429.c b/src/chipset/ali1429.c index 02034e481..34c3e18c2 100644 --- a/src/chipset/ali1429.c +++ b/src/chipset/ali1429.c @@ -115,16 +115,20 @@ ali1429_log(const char *fmt, ...) # define ali1429_log(fmt, ...) #endif -typedef struct -{ - uint8_t is_g, index, cfg_locked, reg_57h, - regs[90]; +typedef struct ali_1429_t { + uint8_t is_g; + uint8_t index; + uint8_t cfg_locked; + uint8_t reg_57h; + uint8_t regs[90]; } ali1429_t; static void ali1429_shadow_recalc(ali1429_t *dev) { - uint32_t base, i, can_write, can_read; + uint32_t base; + uint32_t can_write; + uint32_t can_read; shadowbios = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x01); shadowbios_write = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x02); @@ -132,7 +136,7 @@ ali1429_shadow_recalc(ali1429_t *dev) can_write = (dev->regs[0x14] & 0x02) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; can_read = (dev->regs[0x14] & 0x01) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); if (dev->regs[0x13] & (1 << i)) @@ -164,7 +168,7 @@ ali1429_write(uint16_t addr, uint8_t val, void *priv) dev->cfg_locked = (val != 0xc5); if (!dev->cfg_locked) { - pclog("M1429: dev->regs[%02x] = %02x\n", dev->index, val); + ali1429_log("M1429: dev->regs[%02x] = %02x\n", dev->index, val); /* Common M1429 Registers */ switch (dev->index) { @@ -237,12 +241,16 @@ ali1429_write(uint16_t addr, uint8_t val, void *priv) case 6: cpu_set_isa_speed(cpu_busspeed / 12); break; + default: + break; } break; case 0x21 ... 0x27: dev->regs[dev->index] = val; break; + default: + break; } /* M1429G Only Registers */ @@ -258,18 +266,22 @@ ali1429_write(uint16_t addr, uint8_t val, void *priv) case 0x57: dev->reg_57h = val; break; + default: + break; } } } break; + default: + break; } } static uint8_t ali1429_read(uint16_t addr, void *priv) { - ali1429_t *dev = (ali1429_t *) priv; - uint8_t ret = 0xff; + const ali1429_t *dev = (ali1429_t *) priv; + uint8_t ret = 0xff; if ((addr == 0x23) && (dev->index >= 0x10) && (dev->index <= 0x4a)) ret = dev->regs[dev->index]; diff --git a/src/chipset/ali1435.c b/src/chipset/ali1435.c index 2909a48b9..72595cf84 100644 --- a/src/chipset/ali1435.c +++ b/src/chipset/ali1435.c @@ -1,315 +1,327 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * Emulation of ALi M1435 chipset that acts as both the - * southbridge. - * - * - * - * Authors: Miran Grca, - * - * Copyright 2020 Miran Grca. - */ -#include -#include -#include -#include -#include -#include -#define HAVE_STDARG_H -#include <86box/86box.h> -#include <86box/device.h> -#include <86box/io.h> -#include <86box/apm.h> -#include <86box/dma.h> -#include <86box/mem.h> -#include <86box/smram.h> -#include <86box/pci.h> -#include <86box/timer.h> -#include <86box/pic.h> -#include <86box/pit.h> -#include <86box/port_92.h> -#include <86box/hdc_ide.h> -#include <86box/hdc.h> -#include <86box/machine.h> -#include <86box/chipset.h> -#include <86box/spd.h> - -#define MEM_STATE_SHADOW_R 0x01 -#define MEM_STATE_SHADOW_W 0x02 -#define MEM_STATE_SMRAM 0x04 - -typedef struct -{ - uint8_t index, cfg_locked, - regs[16], pci_regs[256]; -} ali1435_t; - -#define ENABLE_ALI1435_LOG 1 -#ifdef ENABLE_ALI1435_LOG -int ali1435_do_log = ENABLE_ALI1435_LOG; - -static void -ali1435_log(const char *fmt, ...) -{ - va_list ap; - - if (ali1435_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define ali1435_log(fmt, ...) -#endif - -/* NOTE: We cheat here. The real ALi M1435 uses a level to edge triggered IRQ converter - when the most siginificant bit is set. We work around that by manipulating the - emulated PIC's ELCR register. */ -static void -ali1435_update_irqs(ali1435_t *dev, int set) -{ - uint8_t val; - int i, reg; - int shift, irq; - int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; - pic_t *temp_pic; - - for (i = 0; i < 4; i++) { - reg = 0x80 + (i >> 1); - shift = (i & 1) << 2; - val = (dev->pci_regs[reg] >> shift) & 0x0f; - irq = irq_map[val & 0x07]; - if (irq == -1) - continue; - temp_pic = (irq >= 8) ? &pic2 : &pic; - irq &= 7; - if (set && (val & 0x08)) - temp_pic->elcr |= (1 << irq); - else - temp_pic->elcr &= ~(1 << irq); - } -} - -static void -ali1435_pci_write(int func, int addr, uint8_t val, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - int irq, irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; - - ali1435_log("ali1435_write(%02X, %02X, %02X)\n", func, addr, val); - - if (func > 0) - return; - - if ((addr < 0x04) || (addr == 0x06) || ((addr >= 0x08) && (addr <= 0x0b))) - return; - - if ((addr >= 0x0f) && (addr < 0x30)) - return; - - if ((addr >= 0x34) && (addr < 0x40)) - return; - - switch (addr) { - /* Dummy PCI Config */ - case 0x04: - dev->pci_regs[addr] = (val & 0x7f) | 0x07; - break; - - case 0x05: - dev->pci_regs[addr] = (val & 0x01); - break; - - /* Dummy PCI Status */ - case 0x07: - dev->pci_regs[addr] &= ~(val & 0xb8); - break; - - case 0x80: - case 0x81: - dev->pci_regs[addr] = val; - ali1435_update_irqs(dev, 0); - irq = irq_map[val & 0x07]; - if (irq >= 0) { - ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x41 + ((addr & 0x01) << 1), irq); - pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), irq); - } else { - ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x41 + ((addr & 0x01) << 1)); - pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); - } - irq = irq_map[(val >> 4) & 0x07]; - if (irq >= 0) { - ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x42 + ((addr & 0x01) << 1), irq); - pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), irq); - } else { - ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x42 + ((addr & 0x01) << 1)); - pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); - } - ali1435_update_irqs(dev, 1); - break; - - default: - dev->pci_regs[addr] = val; - break; - } -} - -static uint8_t -ali1435_pci_read(int func, int addr, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - uint8_t ret; - - ret = 0xff; - - if (func == 0) - ret = dev->pci_regs[addr]; - - ali1435_log("ali1435_read(%02X, %02X) = %02X\n", func, addr, ret); - - return ret; -} - -static void -ali1435_write(uint16_t addr, uint8_t val, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - - switch (addr) { - case 0x22: - dev->index = val; - break; - - case 0x23: - /* #ifdef ENABLE_ALI1435_LOG - if (dev->index != 0x03) - ali1435_log("M1435: dev->regs[%02x] = %02x\n", dev->index, val); - #endif */ - - if (dev->index == 0x03) - dev->cfg_locked = (val != 0x69); - - if (!dev->cfg_locked) { - pclog("M1435: dev->regs[%02x] = %02x\n", dev->index, val); - - switch (dev->index) { - /* PCI Mechanism select? */ - case 0x00: - dev->regs[dev->index] = val; - pclog("PMC = %i\n", val != 0xc8); - pci_set_pmc(val != 0xc8); - break; - - /* ???? */ - case 0x06: - dev->regs[dev->index] = val; - break; - - /* ???? */ - case 0x07: - dev->regs[dev->index] = val; - break; - } - } - break; - } -} - -static uint8_t -ali1435_read(uint16_t addr, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - uint8_t ret = 0xff; - - if ((addr == 0x23) && (dev->index < 0x10)) - ret = dev->regs[dev->index]; - else if (addr == 0x22) - ret = dev->index; - - return ret; -} - -static void -ali1435_reset(void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - - memset(dev->regs, 0, 16); - - dev->regs[0x00] = 0xff; - - pci_set_pmc(0); - - dev->cfg_locked = 1; - - memset(dev->pci_regs, 0, 256); - - dev->pci_regs[0x00] = 0x25; - dev->pci_regs[0x01] = 0x10; /*ALi*/ - dev->pci_regs[0x02] = 0x35; - dev->pci_regs[0x03] = 0x14; /*M1435*/ - dev->pci_regs[0x04] = 0x07; - dev->pci_regs[0x07] = 0x04; - dev->pci_regs[0x0b] = 0x06; - - dev->pci_regs[0x80] = 0x80; - dev->pci_regs[0x81] = 0x00; - - pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED); - pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED); - pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED); - pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED); -} - -static void -ali1435_close(void *p) -{ - ali1435_t *dev = (ali1435_t *) p; - - free(dev); -} - -static void * -ali1435_init(const device_t *info) -{ - ali1435_t *dev = (ali1435_t *) malloc(sizeof(ali1435_t)); - memset(dev, 0, sizeof(ali1435_t)); - - dev->cfg_locked = 1; - - /* M1435 Ports: - 22h Index Port - 23h Data Port - */ - io_sethandler(0x0022, 0x0002, ali1435_read, NULL, NULL, ali1435_write, NULL, NULL, dev); - - pci_add_card(PCI_ADD_NORTHBRIDGE, ali1435_pci_read, ali1435_pci_write, dev); - - ali1435_reset(dev); - - /* pci_set_irq_level(PCI_INTA, 0); - pci_set_irq_level(PCI_INTB, 0); - pci_set_irq_level(PCI_INTC, 0); - pci_set_irq_level(PCI_INTD, 0); */ - - return dev; -} - -const device_t ali1435_device = { - .name = "Intel ALi M1435", - .internal_name = "ali1435", - .flags = DEVICE_PCI, - .local = 0x00, - .init = ali1435_init, - .close = ali1435_close, - .reset = ali1435_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * Emulation of ALi M1435 chipset that acts as both the + * southbridge. + * + * + * + * Authors: Miran Grca, + * + * Copyright 2020 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/apm.h> +#include <86box/dma.h> +#include <86box/mem.h> +#include <86box/smram.h> +#include <86box/pci.h> +#include <86box/timer.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/plat_unused.h> +#include <86box/port_92.h> +#include <86box/hdc_ide.h> +#include <86box/hdc.h> +#include <86box/machine.h> +#include <86box/chipset.h> +#include <86box/spd.h> + +#define MEM_STATE_SHADOW_R 0x01 +#define MEM_STATE_SHADOW_W 0x02 +#define MEM_STATE_SMRAM 0x04 + +typedef struct ali_1435_t { + uint8_t index; + uint8_t cfg_locked; + uint8_t regs[16]; + uint8_t pci_regs[256]; +} ali1435_t; + +#define ENABLE_ALI1435_LOG 1 +#ifdef ENABLE_ALI1435_LOG +int ali1435_do_log = ENABLE_ALI1435_LOG; + +static void +ali1435_log(const char *fmt, ...) +{ + va_list ap; + + if (ali1435_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define ali1435_log(fmt, ...) +#endif + +/* NOTE: We cheat here. The real ALi M1435 uses a level to edge triggered IRQ converter + when the most siginificant bit is set. We work around that by manipulating the + emulated PIC's ELCR register. */ +static void +ali1435_update_irqs(ali1435_t *dev, int set) +{ + uint8_t val; + int reg; + int shift; + int irq; + int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; + pic_t *temp_pic; + + for (uint8_t i = 0; i < 4; i++) { + reg = 0x80 + (i >> 1); + shift = (i & 1) << 2; + val = (dev->pci_regs[reg] >> shift) & 0x0f; + irq = irq_map[val & 0x07]; + if (irq == -1) + continue; + temp_pic = (irq >= 8) ? &pic2 : &pic; + irq &= 7; + if (set && (val & 0x08)) + temp_pic->elcr |= (1 << irq); + else + temp_pic->elcr &= ~(1 << irq); + } +} + +static void +ali1435_pci_write(int func, int addr, uint8_t val, void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + int irq; + int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; + + ali1435_log("ali1435_write(%02X, %02X, %02X)\n", func, addr, val); + + if (func > 0) + return; + + if ((addr < 0x04) || (addr == 0x06) || ((addr >= 0x08) && (addr <= 0x0b))) + return; + + if ((addr >= 0x0f) && (addr < 0x30)) + return; + + if ((addr >= 0x34) && (addr < 0x40)) + return; + + switch (addr) { + /* Dummy PCI Config */ + case 0x04: + dev->pci_regs[addr] = (val & 0x7f) | 0x07; + break; + + case 0x05: + dev->pci_regs[addr] = (val & 0x01); + break; + + /* Dummy PCI Status */ + case 0x07: + dev->pci_regs[addr] &= ~(val & 0xb8); + break; + + case 0x80: + case 0x81: + dev->pci_regs[addr] = val; + ali1435_update_irqs(dev, 0); + irq = irq_map[val & 0x07]; + if (irq >= 0) { + ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x41 + ((addr & 0x01) << 1), irq); + pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), irq); + } else { + ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x41 + ((addr & 0x01) << 1)); + pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); + } + irq = irq_map[(val >> 4) & 0x07]; + if (irq >= 0) { + ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x42 + ((addr & 0x01) << 1), irq); + pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), irq); + } else { + ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x42 + ((addr & 0x01) << 1)); + pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); + } + ali1435_update_irqs(dev, 1); + break; + + default: + dev->pci_regs[addr] = val; + break; + } +} + +static uint8_t +ali1435_pci_read(int func, int addr, void *priv) +{ + const ali1435_t *dev = (ali1435_t *) priv; + uint8_t ret; + + ret = 0xff; + + if (func == 0) + ret = dev->pci_regs[addr]; + + ali1435_log("ali1435_read(%02X, %02X) = %02X\n", func, addr, ret); + + return ret; +} + +static void +ali1435_write(uint16_t addr, uint8_t val, void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + + switch (addr) { + case 0x22: + dev->index = val; + break; + + case 0x23: +#if 0 +#ifdef ENABLE_ALI1435_LOG + if (dev->index != 0x03) + ali1435_log("M1435: dev->regs[%02x] = %02x\n", dev->index, val); +#endif +#endif + if (dev->index == 0x03) + dev->cfg_locked = (val != 0x69); + + if (!dev->cfg_locked) { + pclog("M1435: dev->regs[%02x] = %02x\n", dev->index, val); + + switch (dev->index) { + /* PCI Mechanism select? */ + case 0x00: + dev->regs[dev->index] = val; + pclog("PMC = %i\n", val != 0xc8); + pci_set_pmc(val != 0xc8); + break; + + /* ???? */ + case 0x06: + dev->regs[dev->index] = val; + break; + + /* ???? */ + case 0x07: + dev->regs[dev->index] = val; + break; + + default: + break; + } + } + break; + default: + break; + } +} + +static uint8_t +ali1435_read(uint16_t addr, void *priv) +{ + const ali1435_t *dev = (ali1435_t *) priv; + uint8_t ret = 0xff; + + if ((addr == 0x23) && (dev->index < 0x10)) + ret = dev->regs[dev->index]; + else if (addr == 0x22) + ret = dev->index; + + return ret; +} + +static void +ali1435_reset(void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + + memset(dev->regs, 0, 16); + + dev->regs[0x00] = 0xff; + + pci_set_pmc(0); + + dev->cfg_locked = 1; + + memset(dev->pci_regs, 0, 256); + + dev->pci_regs[0x00] = 0x25; + dev->pci_regs[0x01] = 0x10; /*ALi*/ + dev->pci_regs[0x02] = 0x35; + dev->pci_regs[0x03] = 0x14; /*M1435*/ + dev->pci_regs[0x04] = 0x07; + dev->pci_regs[0x07] = 0x04; + dev->pci_regs[0x0b] = 0x06; + + dev->pci_regs[0x80] = 0x80; + dev->pci_regs[0x81] = 0x00; + + pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED); + pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED); + pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED); + pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED); +} + +static void +ali1435_close(void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + + free(dev); +} + +static void * +ali1435_init(UNUSED(const device_t *info)) +{ + ali1435_t *dev = (ali1435_t *) malloc(sizeof(ali1435_t)); + memset(dev, 0, sizeof(ali1435_t)); + + dev->cfg_locked = 1; + + /* M1435 Ports: + 22h Index Port + 23h Data Port + */ + io_sethandler(0x0022, 0x0002, ali1435_read, NULL, NULL, ali1435_write, NULL, NULL, dev); + + pci_add_card(PCI_ADD_NORTHBRIDGE, ali1435_pci_read, ali1435_pci_write, dev); + + ali1435_reset(dev); + +#if 0 + pci_set_irq_level(PCI_INTA, 0); + pci_set_irq_level(PCI_INTB, 0); + pci_set_irq_level(PCI_INTC, 0); + pci_set_irq_level(PCI_INTD, 0); +#endif + + return dev; +} + +const device_t ali1435_device = { + .name = "Intel ALi M1435", + .internal_name = "ali1435", + .flags = DEVICE_PCI, + .local = 0x00, + .init = ali1435_init, + .close = ali1435_close, + .reset = ali1435_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 70ff509ab..1b2087e4d 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -35,6 +35,7 @@ #include <86box/nmi.h> #include <86box/pic.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/smram.h> @@ -61,10 +62,14 @@ ali1489_log(const char *fmt, ...) # define ali1489_log(fmt, ...) #endif -typedef struct -{ - uint8_t index, ide_index, ide_chip_id, pci_slot, - regs[256], pci_conf[256], ide_regs[256]; +typedef struct ali1489_t { + uint8_t index; + uint8_t ide_index; + uint8_t ide_chip_id; + uint8_t pci_slot; + uint8_t regs[256]; + uint8_t pci_conf[256]; + uint8_t ide_regs[256]; port_92_t *port_92; smram_t *smram; @@ -75,11 +80,9 @@ static void ali1489_ide_handler(ali1489_t *dev); static void ali1489_shadow_recalc(ali1489_t *dev) { - uint32_t i; - shadowbios = shadowbios_write = 0; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { if (dev->regs[0x13] & (1 << i)) { ali1489_log("%06Xh-%06Xh region shadow enabled: read = %i, write = %i\n", 0xc0000 + (i << 14), 0xc3fff + (i << 14), !!(dev->regs[0x14] & 0x10), !!(dev->regs[0x14] & 0x20)); @@ -90,7 +93,7 @@ ali1489_shadow_recalc(ali1489_t *dev) } } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { if (dev->regs[0x14] & (1 << i)) { ali1489_log("%06Xh-%06Xh region shadow enabled: read = %i, write = %i\n", 0xe0000 + (i << 15), 0xe7fff + (i << 15), !!(dev->regs[0x14] & 0x10), !!(dev->regs[0x14] & 0x20)); @@ -126,6 +129,8 @@ ali1489_smram_recalc(ali1489_t *dev) else smram_enable(dev->smram, 0x38000, 0xa8000, 0x08000, (dev->regs[0x19] & 0x08), 1); break; + default: + break; } if ((dev->regs[0x19] & 0x31) == 0x11) { @@ -206,8 +211,9 @@ static void ali1489_write(uint16_t addr, uint8_t val, void *priv) { ali1489_t *dev = (ali1489_t *) priv; - uint8_t old, irq; - const uint8_t irq_array[16] = { 0, 3, 4, 7, 0, 0, 0, 0, 9, 10, 5, 6, 11, 12, 14, 15 }; + uint8_t old; + uint8_t irq; + const uint8_t irq_array[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 0, 11, 0, 12, 0, 14, 0, 15 }; switch (addr) { case 0x22: @@ -319,6 +325,8 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) case 0x30: picint(1 << 10); break; + default: + break; } dev->regs[0x35] |= 0x0e; } else if (!(val & 0x10)) @@ -380,6 +388,8 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) /* TODO: When doing the IRQ and PCI IRQ rewrite, bits 0 to 3 toggle edge/level output. */ dev->regs[dev->index] = val; break; + default: + break; } if (dev->index != 0x03) { @@ -389,14 +399,17 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) dev->regs[dev->index] = val; break; + + default: + break; } } static uint8_t ali1489_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - ali1489_t *dev = (ali1489_t *) priv; + uint8_t ret = 0xff; + const ali1489_t *dev = (ali1489_t *) priv; switch (addr) { case 0x23: @@ -408,6 +421,8 @@ ali1489_read(uint16_t addr, void *priv) else ret = dev->regs[dev->index]; break; + default: + break; } ali1489_log("M1489: dev->regs[%02x] (%02x)\n", dev->index, ret); @@ -416,7 +431,7 @@ ali1489_read(uint16_t addr, void *priv) } static void -ali1489_pci_write(int func, int addr, uint8_t val, void *priv) +ali1489_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { ali1489_t *dev = (ali1489_t *) priv; @@ -432,14 +447,17 @@ ali1489_pci_write(int func, int addr, uint8_t val, void *priv) case 0x07: dev->pci_conf[0x07] &= ~(val & 0xb8); break; + + default: + break; } } static uint8_t -ali1489_pci_read(int func, int addr, void *priv) +ali1489_pci_read(UNUSED(int func), int addr, void *priv) { - ali1489_t *dev = (ali1489_t *) priv; - uint8_t ret = 0xff; + const ali1489_t *dev = (ali1489_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; ali1489_log("M1489-PCI: dev->pci_conf[%02x] (%02x)\n", addr, ret); @@ -528,16 +546,22 @@ ali1489_ide_write(uint16_t addr, uint8_t val, void *priv) dev->ide_regs[dev->ide_index] = val; ali1489_ide_handler(dev); break; + + default: + break; } break; + + default: + break; } } static uint8_t ali1489_ide_read(uint16_t addr, void *priv) { - ali1489_t *dev = (ali1489_t *) priv; - uint8_t ret = 0xff; + const ali1489_t *dev = (ali1489_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0xf4: @@ -547,6 +571,9 @@ ali1489_ide_read(uint16_t addr, void *priv) ret = dev->ide_regs[dev->ide_index]; ali1489_log("M1489-IDE: dev->regs[%02x] (%02x)\n", dev->ide_index, ret); break; + + default: + break; } return ret; @@ -575,7 +602,7 @@ ali1489_close(void *priv) } static void * -ali1489_init(const device_t *info) +ali1489_init(UNUSED(const device_t *info)) { ali1489_t *dev = (ali1489_t *) malloc(sizeof(ali1489_t)); memset(dev, 0, sizeof(ali1489_t)); diff --git a/src/chipset/ali1531.c b/src/chipset/ali1531.c index b92421e31..3812e4ca4 100644 --- a/src/chipset/ali1531.c +++ b/src/chipset/ali1531.c @@ -28,6 +28,7 @@ #include <86box/io.h> #include <86box/mem.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/smram.h> #include <86box/spd.h> @@ -82,6 +83,9 @@ ali1531_smram_recalc(uint8_t val, ali1531_t *dev) if (val & 0x10) mem_set_mem_state_smram_ex(1, 0x30000, 0x10000, 0x02); break; + + default: + break; } } @@ -89,14 +93,17 @@ ali1531_smram_recalc(uint8_t val, ali1531_t *dev) } static void -ali1531_shadow_recalc(int cur_reg, ali1531_t *dev) +ali1531_shadow_recalc(UNUSED(int cur_reg), ali1531_t *dev) { - int i, bit, r_reg, w_reg; - uint32_t base, flags = 0; + int bit; + int r_reg; + int w_reg; + uint32_t base; + uint32_t flags = 0; shadowbios = shadowbios_write = 0; - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { base = 0x000c0000 + (i << 14); bit = i & 7; r_reg = 0x4c + (i >> 3); @@ -121,7 +128,7 @@ ali1531_shadow_recalc(int cur_reg, ali1531_t *dev) } static void -ali1531_write(int func, int addr, uint8_t val, void *priv) +ali1531_write(UNUSED(int func), int addr, uint8_t val, void *priv) { ali1531_t *dev = (ali1531_t *) priv; @@ -225,8 +232,10 @@ ali1531_write(int func, int addr, uint8_t val, void *priv) case 0x57: /* H2PO */ dev->pci_conf[addr] = val & 0x60; /* Find where the Shut-down Special cycle is initiated. */ - // if (!(val & 0x20)) - // outb(0x92, 0x01); +#if 0 + if (!(val & 0x20)) + outb(0x92, 0x01); +#endif break; case 0x58: @@ -285,14 +294,17 @@ ali1531_write(int func, int addr, uint8_t val, void *priv) case 0x83: dev->pci_conf[addr] = val & 0x10; break; + + default: + break; } } static uint8_t -ali1531_read(int func, int addr, void *priv) +ali1531_read(UNUSED(int func), int addr, void *priv) { - ali1531_t *dev = (ali1531_t *) priv; - uint8_t ret = 0xff; + const ali1531_t *dev = (ali1531_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; @@ -303,7 +315,6 @@ static void ali1531_reset(void *priv) { ali1531_t *dev = (ali1531_t *) priv; - int i; /* Default Registers */ dev->pci_conf[0x00] = 0xb9; @@ -339,10 +350,10 @@ ali1531_reset(void *priv) ali1531_write(0, 0x47, 0x00, dev); ali1531_write(0, 0x48, 0x00, dev); - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) ali1531_write(0, 0x4c + i, 0x00, dev); - for (i = 0; i < 16; i += 2) { + for (uint8_t i = 0; i < 16; i += 2) { ali1531_write(0, 0x60 + i, 0x08, dev); ali1531_write(0, 0x61 + i, 0x40, dev); } @@ -358,7 +369,7 @@ ali1531_close(void *priv) } static void * -ali1531_init(const device_t *info) +ali1531_init(UNUSED(const device_t *info)) { ali1531_t *dev = (ali1531_t *) malloc(sizeof(ali1531_t)); memset(dev, 0, sizeof(ali1531_t)); diff --git a/src/chipset/ali1541.c b/src/chipset/ali1541.c index 37dd7c809..55cf5d25d 100644 --- a/src/chipset/ali1541.c +++ b/src/chipset/ali1541.c @@ -28,6 +28,7 @@ #include <86box/io.h> #include <86box/mem.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/smram.h> #include <86box/spd.h> @@ -83,6 +84,8 @@ ali1541_smram_recalc(uint8_t val, ali1541_t *dev) if (val & 0x10) mem_set_mem_state_smram_ex(1, 0x30000, 0x10000, 0x02); break; + default: + break; } } @@ -90,14 +93,17 @@ ali1541_smram_recalc(uint8_t val, ali1541_t *dev) } static void -ali1541_shadow_recalc(int cur_reg, ali1541_t *dev) +ali1541_shadow_recalc(UNUSED(int cur_reg), ali1541_t *dev) { - int i, bit, r_reg, w_reg; - uint32_t base, flags = 0; + int bit; + int r_reg; + int w_reg; + uint32_t base; + uint32_t flags = 0; shadowbios = shadowbios_write = 0; - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { base = 0x000c0000 + (i << 14); bit = i & 7; r_reg = 0x56 + (i >> 3); @@ -124,11 +130,12 @@ ali1541_shadow_recalc(int cur_reg, ali1541_t *dev) static void ali1541_mask_bar(ali1541_t *dev) { - uint32_t bar, mask; + uint32_t bar; + uint32_t mask; switch (dev->pci_conf[0xbc] & 0x0f) { - case 0x00: default: + case 0x00: mask = 0x00000000; break; case 0x01: @@ -166,7 +173,7 @@ ali1541_mask_bar(ali1541_t *dev) } static void -ali1541_write(int func, int addr, uint8_t val, void *priv) +ali1541_write(UNUSED(int func), int addr, uint8_t val, void *priv) { ali1541_t *dev = (ali1541_t *) priv; @@ -363,8 +370,10 @@ ali1541_write(int func, int addr, uint8_t val, void *priv) case 0x87: /* H2PO */ dev->pci_conf[addr] = val; /* Find where the Shut-down Special cycle is initiated. */ - // if (!(val & 0x20)) - // outb(0x92, 0x01); +#if 0 + if (!(val & 0x20)) + outb(0x92, 0x01); +#endif break; case 0x88: @@ -542,14 +551,17 @@ ali1541_write(int func, int addr, uint8_t val, void *priv) case 0xf7: dev->pci_conf[addr] = val & 0x43; break; + + default: + break; } } static uint8_t -ali1541_read(int func, int addr, void *priv) +ali1541_read(UNUSED(int func), int addr, void *priv) { - ali1541_t *dev = (ali1541_t *) priv; - uint8_t ret = 0xff; + const ali1541_t *dev = (ali1541_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; @@ -560,7 +572,6 @@ static void ali1541_reset(void *priv) { ali1541_t *dev = (ali1541_t *) priv; - int i; /* Default Registers */ dev->pci_conf[0x00] = 0xb9; @@ -603,12 +614,13 @@ ali1541_reset(void *priv) ali1541_write(0, 0x54, 0x00, dev); ali1541_write(0, 0x55, 0x00, dev); - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) ali1541_write(0, 0x56 + i, 0x00, dev); - ali1541_write(0, 0x60 + i, 0x07, dev); - ali1541_write(0, 0x61 + i, 0x40, dev); - for (i = 0; i < 14; i += 2) { + ali1541_write(0, 0x60, 0x07, dev); + ali1541_write(0, 0x61, 0x40, dev); + + for (uint8_t i = 0; i < 14; i += 2) { ali1541_write(0, 0x62 + i, 0x00, dev); ali1541_write(0, 0x63 + i, 0x00, dev); } @@ -624,7 +636,7 @@ ali1541_close(void *priv) } static void * -ali1541_init(const device_t *info) +ali1541_init(UNUSED(const device_t *info)) { ali1541_t *dev = (ali1541_t *) malloc(sizeof(ali1541_t)); memset(dev, 0, sizeof(ali1541_t)); diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index 150e54468..cefaa4f0d 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -36,6 +36,7 @@ #include <86box/nvr.h> #include <86box/pci.h> #include <86box/pic.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/sio.h> #include <86box/smbus.h> @@ -46,10 +47,19 @@ #include <86box/chipset.h> typedef struct ali1543_t { - uint8_t pci_conf[256], pmu_conf[256], usb_conf[256], ide_conf[256], - pci_slot, ide_slot, usb_slot, pmu_slot, usb_dev_enable, ide_dev_enable, - pmu_dev_enable, type; - int offset; + uint8_t pci_conf[256]; + uint8_t pmu_conf[256]; + uint8_t usb_conf[256]; + uint8_t ide_conf[256]; + uint8_t pci_slot; + uint8_t ide_slot; + uint8_t usb_slot; + uint8_t pmu_slot; + uint8_t usb_dev_enable; + uint8_t ide_dev_enable; + uint8_t pmu_dev_enable; + uint8_t type; + int offset; apm_t *apm; acpi_t *acpi; @@ -59,6 +69,7 @@ typedef struct ali1543_t { sff8038i_t *ide_controller[2]; smbus_ali7101_t *smbus; usb_t *usb; + usb_params_t usb_params; } ali1543_t; @@ -94,7 +105,7 @@ ali1543_log(const char *fmt, ...) #endif static void -ali1533_ddma_handler(ali1543_t *dev) +ali1533_ddma_handler(UNUSED(ali1543_t *dev)) { /* TODO: Find any documentation that actually explains the ALi southbridge DDMA mapping. */ } @@ -111,7 +122,6 @@ static void ali1533_write(int func, int addr, uint8_t val, void *priv) { ali1543_t *dev = (ali1543_t *) priv; - int irq; ali1543_log("M1533: dev->pci_conf[%02x] = %02x\n", addr, val); if (func > 0) @@ -151,10 +161,7 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) break; case 0x41: - /* TODO: Bit 7 selects keyboard controller type: - 0 = AT, 1 = PS/2 */ - keyboard_at_set_mouse_scan((val & 0x40) ? 1 : 0); - dev->pci_conf[addr] = val & 0xbf; + dev->pci_conf[addr] = val; break; case 0x42: /* ISA Bus Speed */ @@ -171,6 +178,8 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) case 6: cpu_set_isa_pci_div((val & 7) + 1); break; + default: + break; } break; @@ -221,7 +230,7 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) case 0x4c: /* PCI INT to ISA Level to Edge transfer */ dev->pci_conf[addr] = val; - for (irq = 1; irq < 9; irq++) + for (uint8_t irq = 1; irq < 9; irq++) pci_set_irq_level(irq, !(val & (1 << (irq - 1)))); break; @@ -230,8 +239,10 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) dev->pci_conf[addr] = val; ali1543_log("SIRQI = IRQ %i; SIRQII = IRQ %i\n", ali1533_irq_routing[(val >> 4) & 0x0f], ali1533_irq_routing[val & 0x0f]); - // pci_set_mirq_routing(PCI_MIRQ0, ali1533_irq_routing[(val >> 4) & 0x0f]); - // pci_set_mirq_routing(PCI_MIRQ1, ali1533_irq_routing[val & 0x0f]); +#if 0 + pci_set_mirq_routing(PCI_MIRQ0, ali1533_irq_routing[(val >> 4) & 0x0f]); + pci_set_mirq_routing(PCI_MIRQ1, ali1533_irq_routing[val & 0x0f]); +#endif } break; @@ -296,6 +307,8 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) case 0x30: dev->ide_slot = 0x0d; /* A24 = slot 13 */ break; + default: + break; } pci_relocate_slot(PCI_CARD_SOUTHBRIDGE_IDE, ((int) dev->ide_slot) + dev->offset); ali1543_log("IDE slot = %02X (A%0i)\n", ((int) dev->ide_slot) + dev->offset, dev->ide_slot + 11); @@ -367,6 +380,8 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) case 0x0c: dev->pmu_slot = 0x04; /* A15 = slot 04 */ break; + default: + break; } pci_relocate_slot(PCI_CARD_SOUTHBRIDGE_PMU, ((int) dev->pmu_slot) + dev->offset); ali1543_log("PMU slot = %02X (A%0i)\n", ((int) dev->pmu_slot) + dev->offset, dev->pmu_slot + 11); @@ -383,6 +398,8 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) case 0x03: dev->usb_slot = 0x01; /* A12 = slot 01 */ break; + default: + break; } pci_relocate_slot(PCI_CARD_SOUTHBRIDGE_USB, ((int) dev->usb_slot) + dev->offset); ali1543_log("USB slot = %02X (A%0i)\n", ((int) dev->usb_slot) + dev->offset, dev->usb_slot + 11); @@ -440,6 +457,9 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) dev->pmu_dev_enable = 0; } break; + + default: + break; } } @@ -454,9 +474,7 @@ ali1533_read(int func, int addr, void *priv) ret = 0x00; else { ret = dev->pci_conf[addr]; - if (addr == 0x41) - ret |= (keyboard_at_get_mouse_scan() << 2); - else if (addr == 0x58) + if (addr == 0x58) ret = (ret & 0xbf) | (dev->ide_dev_enable ? 0x40 : 0x00); else if ((dev->type == 1) && ((addr >= 0x7c) && (addr <= 0xff)) && !dev->pmu_dev_enable) { dev->pmu_dev_enable = 1; @@ -472,7 +490,8 @@ ali1533_read(int func, int addr, void *priv) static void ali5229_ide_irq_handler(ali1543_t *dev) { - int ctl = 0, ch = 0; + int ctl = 0; + int ch = 0; int bit = 0; if (dev->ide_conf[0x52] & 0x10) { @@ -513,6 +532,9 @@ ali5229_ide_irq_handler(ali1543_t *dev) sff_set_irq_mode(dev->ide_controller[ctl], 0 ^ ch, 0); sff_set_irq_mode(dev->ide_controller[ctl], 1 ^ ch, 2); break; + + default: + break; } } @@ -550,6 +572,9 @@ ali5229_ide_irq_handler(ali1543_t *dev) sff_set_irq_mode(dev->ide_controller[ctl], 0 ^ ch, 0); sff_set_irq_mode(dev->ide_controller[ctl], 1 ^ ch, 2); break; + + default: + break; } } } @@ -559,17 +584,20 @@ ali5229_ide_handler(ali1543_t *dev) { uint32_t ch = 0; - uint16_t native_base_pri_addr = ((dev->ide_conf[0x11] | dev->ide_conf[0x10] << 8)) & 0xfffe; - uint16_t native_side_pri_addr = ((dev->ide_conf[0x15] | dev->ide_conf[0x14] << 8)) & 0xfffe; - uint16_t native_base_sec_addr = ((dev->ide_conf[0x19] | dev->ide_conf[0x18] << 8)) & 0xfffe; - uint16_t native_side_sec_addr = ((dev->ide_conf[0x1c] | dev->ide_conf[0x1b] << 8)) & 0xfffe; + uint16_t native_base_pri_addr = (dev->ide_conf[0x11] | dev->ide_conf[0x10] << 8) & 0xfffe; + uint16_t native_side_pri_addr = (dev->ide_conf[0x15] | dev->ide_conf[0x14] << 8) & 0xfffe; + uint16_t native_base_sec_addr = (dev->ide_conf[0x19] | dev->ide_conf[0x18] << 8) & 0xfffe; + uint16_t native_side_sec_addr = (dev->ide_conf[0x1c] | dev->ide_conf[0x1b] << 8) & 0xfffe; uint16_t comp_base_pri_addr = 0x01f0; uint16_t comp_side_pri_addr = 0x03f6; uint16_t comp_base_sec_addr = 0x0170; uint16_t comp_side_sec_addr = 0x0376; - uint16_t current_pri_base, current_pri_side, current_sec_base, current_sec_side; + uint16_t current_pri_base; + uint16_t current_pri_side; + uint16_t current_sec_base; + uint16_t current_sec_side; /* Primary Channel Programming */ if (dev->ide_conf[0x52] & 0x10) { @@ -622,7 +650,7 @@ ali5229_ide_handler(ali1543_t *dev) ali1543_log("ali5229_ide_handler(): Enabling secondary IDE...\n"); ide_sec_enable(); - sff_bus_master_handler(dev->ide_controller[1], dev->ide_conf[0x04] & 0x01, (((dev->ide_conf[0x20] & 0xf0) | (dev->ide_conf[0x21] << 8))) + (8 ^ ch)); + sff_bus_master_handler(dev->ide_controller[1], dev->ide_conf[0x04] & 0x01, ((dev->ide_conf[0x20] & 0xf0) | (dev->ide_conf[0x21] << 8)) + (8 ^ ch)); ali1543_log("M5229 SEC: BASE %04x SIDE %04x\n", current_sec_base, current_sec_side); } } else { @@ -858,13 +886,16 @@ ali5229_write(int func, int addr, uint8_t val, void *priv) case 0x5f: dev->ide_conf[addr] = val & 0x7f; break; + + default: + break; } } static uint8_t ali5229_read(int func, int addr, void *priv) { - ali1543_t *dev = (ali1543_t *) priv; + const ali1543_t *dev = (ali1543_t *) priv; uint8_t ret = 0xff; if (dev->ide_dev_enable && (func == 0)) { @@ -910,7 +941,12 @@ ali5237_write(int func, int addr, uint8_t val, void *priv) case 0x0c: /* Cache Line Size */ case 0x0d: /* Latency Timer */ + dev->usb_conf[addr] = val; + break; + case 0x3c: /* Interrupt Line Register */ + dev->usb_conf[addr] = val; + break; case 0x42: /* Test Mode Register */ dev->usb_conf[addr] = val & 0x10; @@ -938,13 +974,16 @@ ali5237_write(int func, int addr, uint8_t val, void *priv) if (!(dev->usb_conf[0x42] & 0x10)) dev->usb_conf[addr] = val; break; + + default: + break; } } static uint8_t ali5237_read(int func, int addr, void *priv) { - ali1543_t *dev = (ali1543_t *) priv; + const ali1543_t *dev = (ali1543_t *) priv; uint8_t ret = 0xff; if (dev->usb_dev_enable && (func == 0)) @@ -1422,6 +1461,9 @@ ali7101_read(int func, int addr, void *priv) case 0x74: dev->pmu_conf[addr] &= 0xcc; break; + + default: + break; } } } @@ -1429,6 +1471,17 @@ ali7101_read(int func, int addr, void *priv) return ret; } +static void +ali5237_usb_update_interrupt(usb_t* usb, void *priv) +{ + const ali1543_t *dev = (ali1543_t *) priv; + + if (usb->irq_level) + pci_set_mirq(4, !!(dev->pci_conf[0x74] & 0x10)); + else + pci_clear_mirq(4, !!(dev->pci_conf[0x74] & 0x10)); +} + static void ali1543_reset(void *priv) { @@ -1510,7 +1563,8 @@ ali1543_reset(void *priv) dev->pci_conf[0x0a] = 0x01; dev->pci_conf[0x0b] = 0x06; - ali1533_write(0, 0x48, 0x00, dev); // Disables all IRQ's + ali1533_write(0, 0x41, 0x00, dev); /* Disables the keyboard and mouse IRQ latch. */ + ali1533_write(0, 0x48, 0x00, dev); /* Disables all IRQ's. */ ali1533_write(0, 0x44, 0x00, dev); ali1533_write(0, 0x4d, 0x00, dev); ali1533_write(0, 0x53, 0x00, dev); @@ -1520,6 +1574,8 @@ ali1543_reset(void *priv) ali1533_write(0, 0x74, 0x00, dev); ali1533_write(0, 0x75, 0x00, dev); ali1533_write(0, 0x76, 0x00, dev); + if (dev->type == 1) + ali1533_write(0, 0x78, 0x00, dev); unmask_a20_in_smm = 1; } @@ -1576,7 +1632,10 @@ ali1543_init(const device_t *info) dev->smbus = device_add(&ali7101_smbus_device); /* USB */ - dev->usb = device_add(&usb_device); + dev->usb_params.parent_priv = dev; + dev->usb_params.smi_handle = NULL; + dev->usb_params.update_interrupt = ali5237_usb_update_interrupt; + dev->usb = device_add_parameters(&usb_device, &dev->usb_params); dev->type = info->local & 0xff; dev->offset = (info->local >> 8) & 0x7f; diff --git a/src/chipset/ali1621.c b/src/chipset/ali1621.c index 7db437b24..b927d3e34 100644 --- a/src/chipset/ali1621.c +++ b/src/chipset/ali1621.c @@ -28,6 +28,8 @@ #include <86box/io.h> #include <86box/mem.h> #include <86box/pci.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/smram.h> #include <86box/spd.h> @@ -94,7 +96,8 @@ ali1621_log(const char *fmt, ...) static void ali1621_smram_recalc(uint8_t val, ali1621_t *dev) { - uint16_t access_smm = 0x0000, access_normal = 0x0000; + uint16_t access_smm = 0x0000; + uint16_t access_normal = 0x0000; smram_disable_all(); @@ -106,10 +109,14 @@ ali1621_smram_recalc(uint8_t val, ali1621_t *dev) switch (val & 0x30) { case 0x10: /* Open. */ access_normal = ACCESS_SMRAM_RX; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x30: /* Protect. */ access_smm |= ACCESS_SMRAM_R; break; + default: + break; } } @@ -117,10 +124,14 @@ ali1621_smram_recalc(uint8_t val, ali1621_t *dev) switch (val & 0x30) { case 0x10: /* Open. */ access_normal |= ACCESS_SMRAM_W; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x30: /* Protect. */ access_smm |= ACCESS_SMRAM_W; break; + default: + break; } smram_enable(dev->smram[0], 0xa0000, 0xa0000, 0x20000, ((val & 0x30) == 0x10), (val & 0x30)); @@ -136,15 +147,18 @@ ali1621_smram_recalc(uint8_t val, ali1621_t *dev) } static void -ali1621_shadow_recalc(int cur_reg, ali1621_t *dev) +ali1621_shadow_recalc(UNUSED(int cur_reg), ali1621_t *dev) { - int i, r_bit, w_bit, reg; - uint32_t base, flags = 0; + int r_bit; + int w_bit; + int reg; + uint32_t base; + uint32_t flags = 0; shadowbios = shadowbios_write = 0; /* C0000-EFFFF */ - for (i = 0; i < 12; i++) { + for (uint8_t i = 0; i < 12; i++) { base = 0x000c0000 + (i << 14); r_bit = (i << 1) + 4; reg = 0x84; @@ -199,11 +213,12 @@ ali1621_shadow_recalc(int cur_reg, ali1621_t *dev) static void ali1621_mask_bar(ali1621_t *dev) { - uint32_t bar, mask; + uint32_t bar; + uint32_t mask; switch (dev->pci_conf[0xbc] & 0x0f) { - case 0x00: default: + case 0x00: mask = 0x00000000; break; case 0x01: @@ -241,7 +256,7 @@ ali1621_mask_bar(ali1621_t *dev) } static void -ali1621_write(int func, int addr, uint8_t val, void *priv) +ali1621_write(UNUSED(int func), int addr, uint8_t val, void *priv) { ali1621_t *dev = (ali1621_t *) priv; @@ -560,14 +575,17 @@ ali1621_write(int func, int addr, uint8_t val, void *priv) case 0xf0 ... 0xff: dev->pci_conf[addr] = val; break; + + default: + break; } } static uint8_t -ali1621_read(int func, int addr, void *priv) +ali1621_read(UNUSED(int func), int addr, void *priv) { - ali1621_t *dev = (ali1621_t *) priv; - uint8_t ret = 0xff; + const ali1621_t *dev = (ali1621_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; @@ -578,7 +596,6 @@ static void ali1621_reset(void *priv) { ali1621_t *dev = (ali1621_t *) priv; - int i; /* Default Registers */ dev->pci_conf[0x00] = 0xb9; @@ -633,7 +650,7 @@ ali1621_reset(void *priv) ali1621_write(0, 0x83, 0x08, dev); - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) ali1621_write(0, 0x84 + i, 0x00, dev); } @@ -649,7 +666,7 @@ ali1621_close(void *priv) } static void * -ali1621_init(const device_t *info) +ali1621_init(UNUSED(const device_t *info)) { ali1621_t *dev = (ali1621_t *) malloc(sizeof(ali1621_t)); memset(dev, 0, sizeof(ali1621_t)); diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index 98451067a..78705ee26 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -30,16 +30,17 @@ #include <86box/pit.h> #include <86box/device.h> #include <86box/port_92.h> -#include <86box/usb.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/chipset.h> +#include <86box/plat_fallthrough.h> typedef struct ali6117_t { uint32_t local; /* Main registers (port 22h/23h) */ - uint8_t unlocked, mode; + uint8_t unlocked; + uint8_t mode; uint8_t reg_offset; uint8_t regs[256]; } ali6117_t; @@ -103,8 +104,8 @@ ali6117_log(const char *fmt, ...) static void ali6117_recalcmapping(ali6117_t *dev) { - uint8_t reg, bitpair; - uint32_t base, size; + uint32_t base; + uint32_t size; int state; shadowbios = 0; @@ -113,8 +114,8 @@ ali6117_recalcmapping(ali6117_t *dev) ali6117_log("ALI6117: Shadowing for A0000-BFFFF (reg 12 bit 1) = %s\n", (dev->regs[0x12] & 0x02) ? "on" : "off"); mem_set_mem_state(0xa0000, 0x20000, (dev->regs[0x12] & 0x02) ? (MEM_WRITE_INTERNAL | MEM_READ_INTERNAL) : (MEM_WRITE_EXTANY | MEM_READ_EXTANY)); - for (reg = 0; reg <= 1; reg++) { - for (bitpair = 0; bitpair <= 3; bitpair++) { + for (uint8_t reg = 0; reg <= 1; reg++) { + for (uint8_t bitpair = 0; bitpair <= 3; bitpair++) { size = 0x8000; base = 0xc0000 + (size * ((reg * 4) + bitpair)); ali6117_log("ALI6117: Shadowing for %05X-%05X (reg %02X bp %d wmask %02X rmask %02X) =", base, base + size - 1, 0x14 + reg, bitpair, 1 << ((bitpair * 2) + 1), 1 << (bitpair * 2)); @@ -149,10 +150,10 @@ ali6117_recalcmapping(ali6117_t *dev) static void ali6117_bank_recalc(ali6117_t *dev) { - int i; - uint32_t bank, addr; + uint32_t bank; + uint32_t addr; - for (i = 0x00000000; i < (mem_size << 10); i += 4096) { + for (uint32_t i = 0x00000000; i < (mem_size << 10); i += 4096) { if ((i >= 0x000a0000) && (i < 0x00100000)) continue; @@ -233,7 +234,9 @@ ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) case 0x12: val &= 0xf7; - /* FALL-THROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x14: case 0x15: @@ -278,6 +281,9 @@ ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) case 0x7: cpu_set_isa_speed(cpu_busspeed / 6); break; + + default: + break; } break; @@ -373,6 +379,9 @@ ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) case 0x71: val &= 0x1f; break; + + default: + break; } dev->regs[dev->reg_offset] = val; @@ -382,7 +391,7 @@ ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) static uint8_t ali6117_reg_read(uint16_t addr, void *priv) { - ali6117_t *dev = (ali6117_t *) priv; + const ali6117_t *dev = (ali6117_t *) priv; uint8_t ret; if (addr == 0x22) @@ -455,7 +464,7 @@ ali6117_close(void *priv) static void * ali6117_init(const device_t *info) { - int i, last_match = 0; + int last_match = 0; ali6117_log("ALI6117: init()\n"); @@ -468,7 +477,7 @@ ali6117_init(const device_t *info) ali6117_setup(dev); - for (i = 31; i >= 0; i--) { + for (int8_t i = 31; i >= 0; i--) { if ((mem_size >= ali6117_modes[i][0]) && (ali6117_modes[i][0] > last_match)) { last_match = ali6117_modes[i][0]; dev->mode = i; diff --git a/src/chipset/contaq_82c59x.c b/src/chipset/contaq_82c59x.c index 951a86b0a..ec7050b1e 100644 --- a/src/chipset/contaq_82c59x.c +++ b/src/chipset/contaq_82c59x.c @@ -48,16 +48,17 @@ contaq_82c59x_log(const char *fmt, ...) # define contaq_82c59x_log(fmt, ...) #endif -typedef struct -{ - uint32_t phys, virt; +typedef struct mem_remapping_t { + uint32_t phys; + uint32_t virt; } mem_remapping_t; -typedef struct -{ - uint8_t index, green, - smi_status_set, - regs[256], smi_status[2]; +typedef struct contaq_82c59x_t { + uint8_t index; + uint8_t green; + uint8_t smi_status_set; + uint8_t regs[256]; + uint8_t smi_status[2]; smram_t *smram[2]; } contaq_82c59x_t; @@ -82,6 +83,8 @@ contaq_82c59x_isa_speed_recalc(contaq_82c59x_t *dev) case 0x03: cpu_set_isa_speed(cpu_busspeed / 5); break; + default: + break; } } } @@ -89,7 +92,8 @@ contaq_82c59x_isa_speed_recalc(contaq_82c59x_t *dev) static void contaq_82c59x_shadow_recalc(contaq_82c59x_t *dev) { - uint32_t i, base; + uint32_t i; + uint32_t base; uint8_t bit; shadowbios = shadowbios_write = 0; @@ -273,8 +277,14 @@ contaq_82c59x_write(uint16_t addr, uint8_t val, void *priv) case 0x7c: dev->regs[dev->index] = val; break; + + default: + break; } break; + + default: + break; } } diff --git a/src/chipset/cs4031.c b/src/chipset/cs4031.c index a2cef50b9..fb439ec3a 100644 --- a/src/chipset/cs4031.c +++ b/src/chipset/cs4031.c @@ -27,13 +27,13 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/chipset.h> -typedef struct -{ - uint8_t index, - regs[256]; +typedef struct cs4031_t { + uint8_t index; + uint8_t regs[256]; port_92_t *port_92; } cs4031_t; @@ -134,15 +134,21 @@ cs4031_write(uint16_t addr, uint8_t val, void *priv) dev->regs[dev->index] = val & 0xb3; port_92_set_features(dev->port_92, val & 0x10, val & 0x20); break; + + default: + break; } break; + + default: + break; } } static uint8_t cs4031_read(uint16_t addr, void *priv) { - cs4031_t *dev = (cs4031_t *) priv; + const cs4031_t *dev = (cs4031_t *) priv; return (addr == 0x23) ? dev->regs[dev->index] : 0xff; } @@ -156,7 +162,7 @@ cs4031_close(void *priv) } static void * -cs4031_init(const device_t *info) +cs4031_init(UNUSED(const device_t *info)) { cs4031_t *dev = (cs4031_t *) malloc(sizeof(cs4031_t)); memset(dev, 0, sizeof(cs4031_t)); diff --git a/src/chipset/cs8230.c b/src/chipset/cs8230.c index edf4ac8c2..93a7f1bba 100644 --- a/src/chipset/cs8230.c +++ b/src/chipset/cs8230.c @@ -25,12 +25,12 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_unused.h> #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/chipset.h> -typedef struct -{ +typedef struct cs8230_t { int idx; uint8_t regs[256]; } cs8230_t; @@ -51,6 +51,8 @@ shadow_control(uint32_t addr, uint32_t size, int state) case 0x11: mem_set_mem_state(addr, size, MEM_READ_EXTANY | MEM_WRITE_EXTANY); break; + default: + break; } flushmmucache_nopc(); @@ -59,9 +61,7 @@ shadow_control(uint32_t addr, uint32_t size, int state) static void rethink_shadow_mappings(cs8230_t *cs8230) { - int c; - - for (c = 0; c < 32; c++) { + for (uint8_t c = 0; c < 32; c++) { /* Addresses 40000-bffff in 16k blocks */ if (cs8230->regs[0xa + (c >> 3)] & (1 << (c & 7))) mem_set_mem_state(0x40000 + (c << 14), 0x4000, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); /* I/O channel */ @@ -69,7 +69,7 @@ rethink_shadow_mappings(cs8230_t *cs8230) mem_set_mem_state(0x40000 + (c << 14), 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); /* System board */ } - for (c = 0; c < 16; c++) { + for (uint8_t c = 0; c < 16; c++) { /* Addresses c0000-fffff in 16k blocks. System board ROM can be mapped here */ if (cs8230->regs[0xe + (c >> 3)] & (1 << (c & 7))) mem_set_mem_state(0xc0000 + (c << 14), 0x4000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); /* I/O channel */ @@ -79,10 +79,10 @@ rethink_shadow_mappings(cs8230_t *cs8230) } static uint8_t -cs8230_read(uint16_t port, void *p) +cs8230_read(uint16_t port, void *priv) { - cs8230_t *cs8230 = (cs8230_t *) p; - uint8_t ret = 0xff; + const cs8230_t *cs8230 = (cs8230_t *) priv; + uint8_t ret = 0xff; if (port & 1) { switch (cs8230->idx) { @@ -112,6 +112,9 @@ cs8230_read(uint16_t port, void *p) case 0x2a: ret = cs8230->regs[cs8230->idx]; break; + + default: + break; } } @@ -119,9 +122,9 @@ cs8230_read(uint16_t port, void *p) } static void -cs8230_write(uint16_t port, uint8_t val, void *p) +cs8230_write(uint16_t port, uint8_t val, void *priv) { - cs8230_t *cs8230 = (cs8230_t *) p; + cs8230_t *cs8230 = (cs8230_t *) priv; if (!(port & 1)) cs8230->idx = val; @@ -137,6 +140,8 @@ cs8230_write(uint16_t port, uint8_t val, void *p) case 0x0f: /* Address maps */ rethink_shadow_mappings(cs8230); break; + default: + break; } } } @@ -149,9 +154,8 @@ cs8230_close(void *priv) free(cs8230); } -static void - * - cs8230_init(const device_t *info) +static void * +cs8230_init(UNUSED(const device_t *info)) { cs8230_t *cs8230 = (cs8230_t *) malloc(sizeof(cs8230_t)); memset(cs8230, 0, sizeof(cs8230_t)); diff --git a/src/chipset/et6000.c b/src/chipset/et6000.c index eb42ac7cb..f2cffd7f7 100644 --- a/src/chipset/et6000.c +++ b/src/chipset/et6000.c @@ -28,14 +28,15 @@ #include <86box/device.h> #include <86box/mem.h> #include <86box/pit.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/chipset.h> #define INDEX (dev->index - 0x10) -typedef struct -{ - uint8_t index, regs[6]; +typedef struct et6000_t { + uint8_t index; + uint8_t regs[256]; } et6000_t; #ifdef ENABLE_ET6000_LOG @@ -105,16 +106,22 @@ et6000_write(uint16_t addr, uint8_t val, void *priv) et6000_shadow_control(0xe0000, 0x10000, val & 0x20, (val & 0x20) && (val & 0x10)); et6000_shadow_control(0xf0000, 0x10000, val & 0x40, !(val & 0x40)); break; + + default: + break; } et6000_log("ET6000: dev->regs[%02x] = %02x\n", dev->index, dev->regs[dev->index]); break; + + default: + break; } } static uint8_t et6000_read(uint16_t addr, void *priv) { - et6000_t *dev = (et6000_t *) priv; + const et6000_t *dev = (et6000_t *) priv; return ((addr == 0x23) && (INDEX >= 0) && (INDEX <= 5)) ? dev->regs[INDEX] : 0xff; } @@ -128,7 +135,7 @@ et6000_close(void *priv) } static void * -et6000_init(const device_t *info) +et6000_init(UNUSED(const device_t *info)) { et6000_t *dev = (et6000_t *) malloc(sizeof(et6000_t)); memset(dev, 0, sizeof(et6000_t)); diff --git a/src/chipset/gc100.c b/src/chipset/gc100.c index 2aba21350..0b4717903 100644 --- a/src/chipset/gc100.c +++ b/src/chipset/gc100.c @@ -44,8 +44,7 @@ #include <86box/io.h> #include <86box/video.h> -typedef struct -{ +typedef struct gc100_t { uint8_t reg[0x10]; } gc100_t; @@ -70,9 +69,9 @@ gc100_log(const char *fmt, ...) static uint8_t get_fdd_switch_settings(void) { - int i, fdd_count = 0; + uint8_t fdd_count = 0; - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -135,6 +134,9 @@ gc100_write(uint16_t port, uint8_t val, void *priv) /* addr 0x6 */ /* addr 0x7 */ + + default: + break; } gc100_log("GC100: Write %02x at %02x\n", val, port); @@ -143,9 +145,9 @@ gc100_write(uint16_t port, uint8_t val, void *priv) static uint8_t gc100_read(uint16_t port, void *priv) { - gc100_t *dev = (gc100_t *) priv; - uint8_t ret = 0xff; - uint16_t addr = port & 0xf; + const gc100_t *dev = (gc100_t *) priv; + uint8_t ret = 0xff; + uint16_t addr = port & 0xf; ret = dev->reg[addr]; @@ -187,6 +189,9 @@ gc100_read(uint16_t port, void *priv) /* addr 0x6 */ /* addr 0x7 */ + + default: + break; } return ret; diff --git a/src/chipset/headland.c b/src/chipset/headland.c index 8b8ee1562..db5922470 100644 --- a/src/chipset/headland.c +++ b/src/chipset/headland.c @@ -34,6 +34,7 @@ #include <86box/device.h> #include <86box/fdd.h> #include <86box/fdc.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/chipset.h> @@ -52,8 +53,9 @@ enum { #define HEADLAND_HAS_CRI 0x10 #define HEADLAND_HAS_SLEEP 0x20 -typedef struct { - uint8_t valid, enabled; +typedef struct headland_mr_t { + uint8_t valid; + uint8_t enabled; uint16_t mr; uint32_t virt_base; @@ -62,7 +64,8 @@ typedef struct { typedef struct headland_t { uint8_t revision; - uint8_t has_cri, has_sleep; + uint8_t has_cri; + uint8_t has_sleep; uint8_t cri; uint8_t cr[7]; @@ -72,8 +75,8 @@ typedef struct headland_t { uint8_t ems_mar; - headland_mr_t null_mr, - ems_mr[64]; + headland_mr_t null_mr; + headland_mr_t ems_mr[64]; mem_mapping_t low_mapping; mem_mapping_t ems_mapping[64]; @@ -105,7 +108,11 @@ static const int mem_conf_cr1[41] = { static uint32_t get_addr(headland_t *dev, uint32_t addr, headland_mr_t *mr) { - uint32_t bank_base[4], bank_shift[4], shift, other_shift, bank; + uint32_t bank_base[4]; + uint32_t bank_shift[4]; + uint32_t shift; + uint32_t other_shift; + uint32_t bank; if ((addr >= 0x0e0000) && (addr <= 0x0fffff)) return addr; @@ -158,7 +165,7 @@ get_addr(headland_t *dev, uint32_t addr, headland_mr_t *mr) static void hl_ems_disable(headland_t *dev, uint8_t mar, uint32_t base_addr, uint8_t indx) { - if (base_addr < ((uint32_t) mem_size << 10)) + if (base_addr < (mem_size << 10)) mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], ram + base_addr); else mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], NULL); @@ -173,7 +180,8 @@ hl_ems_disable(headland_t *dev, uint8_t mar, uint32_t base_addr, uint8_t indx) static void hl_ems_update(headland_t *dev, uint8_t mar) { - uint32_t base_addr, virt_addr; + uint32_t base_addr; + uint32_t virt_addr; uint8_t indx = mar & 0x1f; base_addr = (indx + 16) << 14; @@ -189,7 +197,7 @@ hl_ems_update(headland_t *dev, uint8_t mar) dev->ems_mr[mar & 0x3f].virt_base = virt_addr; if (indx < 24) mem_mapping_disable(&dev->upper_mapping[indx]); - if (virt_addr < ((uint32_t) mem_size << 10)) + if (virt_addr < (mem_size << 10)) mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], ram + virt_addr); else mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], NULL); @@ -200,11 +208,9 @@ hl_ems_update(headland_t *dev, uint8_t mar) } static void -set_global_EMS_state(headland_t *dev, int state) +set_global_EMS_state(headland_t *dev, UNUSED(int state)) { - int i; - - for (i = 0; i < 32; i++) { + for (uint8_t i = 0; i < 32; i++) { hl_ems_update(dev, i | (((dev->cr[0] & 0x01) << 5) ^ 0x20)); hl_ems_update(dev, i | ((dev->cr[0] & 0x01) << 5)); } @@ -229,7 +235,6 @@ static void memmap_state_update(headland_t *dev) { uint32_t addr; - int i; uint8_t ht_cr0 = dev->cr[0]; uint8_t ht_romcs = !(dev->cr[4] & 0x01); if (dev->revision <= 1) @@ -237,9 +242,9 @@ memmap_state_update(headland_t *dev) if (!(dev->cr[0] & 0x04)) ht_cr0 &= ~0x18; - for (i = 0; i < 24; i++) { + for (uint8_t i = 0; i < 24; i++) { addr = get_addr(dev, 0x40000 + (i << 14), NULL); - mem_mapping_set_exec(&dev->upper_mapping[i], addr < ((uint32_t) mem_size << 10) ? ram + addr : NULL); + mem_mapping_set_exec(&dev->upper_mapping[i], addr < (mem_size << 10) ? ram + addr : NULL); } memmap_state_default(dev, ht_romcs); @@ -508,7 +513,7 @@ mem_read_b(uint32_t addr, void *priv) uint8_t ret = 0xff; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = ram[addr]; return ret; @@ -522,7 +527,7 @@ mem_read_w(uint32_t addr, void *priv) uint16_t ret = 0xffff; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = *(uint16_t *) &ram[addr]; return ret; @@ -536,7 +541,7 @@ mem_read_l(uint32_t addr, void *priv) uint32_t ret = 0xffffffff; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = *(uint32_t *) &ram[addr]; return ret; @@ -549,7 +554,7 @@ mem_write_b(uint32_t addr, uint8_t val, void *priv) headland_t *dev = mr->headland; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ram[addr] = val; } @@ -560,7 +565,7 @@ mem_write_w(uint32_t addr, uint16_t val, void *priv) headland_t *dev = mr->headland; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) *(uint16_t *) &ram[addr] = val; } @@ -571,7 +576,7 @@ mem_write_l(uint32_t addr, uint32_t val, void *priv) headland_t *dev = mr->headland; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) *(uint32_t *) &ram[addr] = val; } @@ -588,7 +593,6 @@ headland_init(const device_t *info) { headland_t *dev; int ht386 = 0; - uint32_t i; dev = (headland_t *) malloc(sizeof(headland_t)); memset(dev, 0x00, sizeof(headland_t)); @@ -613,7 +617,7 @@ headland_init(const device_t *info) dev->null_mr.mr = 0xff; dev->null_mr.headland = dev; - for (i = 0; i < 64; i++) { + for (uint8_t i = 0; i < 64; i++) { dev->ems_mr[i].valid = 1; dev->ems_mr[i].mr = 0x00; dev->ems_mr[i].headland = dev; @@ -645,7 +649,7 @@ headland_init(const device_t *info) mem_mapping_enable(&dev->high_mapping); } - for (i = 0; i < 24; i++) { + for (uint8_t i = 0; i < 24; i++) { mem_mapping_add(&dev->upper_mapping[i], 0x40000 + (i << 14), 0x4000, mem_read_b, mem_read_w, mem_read_l, @@ -671,7 +675,7 @@ headland_init(const device_t *info) MEM_MAPPING_INTERNAL, &dev->null_mr); mem_mapping_disable(&dev->shadow_mapping[1]); - for (i = 0; i < 64; i++) { + for (uint8_t i = 0; i < 64; i++) { dev->ems_mr[i].mr = 0x00; mem_mapping_add(&dev->ems_mapping[i], ((i & 31) + ((i & 31) >= 24 ? 24 : 16)) << 14, 0x04000, @@ -684,7 +688,7 @@ headland_init(const device_t *info) memmap_state_update(dev); - return (dev); + return dev; } const device_t headland_gc10x_device = { diff --git a/src/chipset/ims8848.c b/src/chipset/ims8848.c index 0cdc833b5..f84eb5706 100644 --- a/src/chipset/ims8848.c +++ b/src/chipset/ims8848.c @@ -30,6 +30,8 @@ #include <86box/mem.h> #include <86box/smram.h> #include <86box/pci.h> +#include <86box/pic.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/chipset.h> @@ -117,10 +119,11 @@ Bit 0: HADS# Delay After LB. Cycle (1: Enabled / 0: Disable) */ -typedef struct -{ - uint8_t idx, access_data, - regs[256], pci_conf[256]; +typedef struct ims8848_t { + uint8_t idx; + uint8_t access_data; + uint8_t regs[256]; + uint8_t pci_conf[256]; smram_t *smram; } ims8848_t; @@ -147,7 +150,7 @@ ims8848_log(const char *fmt, ...) static void ims8848_recalc(ims8848_t *dev) { - int i, state_on; + int state_on; uint32_t base; ims8848_log("SHADOW: 00 = %02X, 08 = %02X, 1B = %02X, 1C = %02X\n", dev->regs[0x00], dev->regs[0x08], dev->regs[0x1b], dev->regs[0x1c]); @@ -155,7 +158,7 @@ ims8848_recalc(ims8848_t *dev) state_on = MEM_READ_INTERNAL; state_on |= (dev->regs[0x08] & 0x04) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { base = 0xe0000 + (i << 16); if (dev->regs[0x00] & (1 << (i + 2))) mem_set_mem_state_both(base, 0x10000, state_on); @@ -163,7 +166,7 @@ ims8848_recalc(ims8848_t *dev) mem_set_mem_state_both(base, 0x10000, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xc0000 + (i << 14); if (dev->regs[0x1c] & (1 << i)) mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); @@ -242,10 +245,16 @@ ims8848_write(uint16_t addr, uint8_t val, void *priv) /* Base Memory */ ims8848_base_memory(dev); break; + + default: + break; } dev->access_data = 0; } break; + + default: + break; } } @@ -274,6 +283,8 @@ ims8848_read(uint16_t addr, void *priv) } ims8848_log("[R] [%i] REG %02X = %02X\n", old_ad, dev->idx, ret); break; + default: + break; } return ret; @@ -307,14 +318,17 @@ ims8849_pci_write(int func, int addr, uint8_t val, void *priv) case 0x52 ... 0x55: dev->pci_conf[addr] = val; break; + + default: + break; } } static uint8_t ims8849_pci_read(int func, int addr, void *priv) { - ims8848_t *dev = (ims8848_t *) priv; - uint8_t ret = 0xff; + const ims8848_t *dev = (ims8848_t *) priv; + uint8_t ret = 0xff; if (func == 0) ret = dev->pci_conf[addr]; @@ -362,7 +376,7 @@ ims8848_close(void *priv) } static void * -ims8848_init(const device_t *info) +ims8848_init(UNUSED(const device_t *info)) { ims8848_t *dev = (ims8848_t *) malloc(sizeof(ims8848_t)); memset(dev, 0, sizeof(ims8848_t)); diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 98c2d0386..5200d8834 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -31,32 +31,38 @@ #include <86box/mem.h> #include <86box/smram.h> #include <86box/pci.h> +#include <86box/pic.h> #include <86box/timer.h> #include <86box/pit.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/hdc_ide.h> #include <86box/hdc.h> #include <86box/machine.h> #include <86box/chipset.h> #include <86box/spd.h> +#ifndef USE_DRB_HACK +#include <86box/row.h> +#endif #define MEM_STATE_SHADOW_R 0x01 #define MEM_STATE_SHADOW_W 0x02 #define MEM_STATE_SMRAM 0x04 -typedef struct -{ - uint8_t has_ide, smram_locked, - regs[256]; +typedef struct i420ex_t { + uint8_t has_ide; + uint8_t smram_locked; + uint8_t regs[256]; - uint16_t timer_base, - timer_latch; + uint16_t timer_base; + uint16_t timer_latch; smram_t *smram; double fast_off_period; - pc_timer_t timer, fast_off_timer; + pc_timer_t timer; + pc_timer_t fast_off_timer; apm_t *apm; port_92_t *port_92; @@ -96,6 +102,8 @@ i420ex_map(uint32_t addr, uint32_t size, int state) case 3: mem_set_mem_state_both(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); break; + default: + break; } flushmmucache_nopc(); } @@ -110,15 +118,16 @@ i420ex_smram_handler_phase0(void) static void i420ex_smram_handler_phase1(i420ex_t *dev) { - uint8_t *regs = (uint8_t *) dev->regs; + const uint8_t *regs = (uint8_t *) dev->regs; - uint32_t host_base = 0x000a0000, ram_base = 0x000a0000; - uint32_t size = 0x00010000; + uint32_t host_base = 0x000a0000; + uint32_t ram_base = 0x000a0000; + uint32_t size = 0x00010000; switch (regs[0x70] & 0x07) { + default: case 0: case 1: - default: host_base = ram_base = 0x00000000; size = 0x00000000; break; @@ -152,6 +161,25 @@ i420ex_smram_handler_phase1(i420ex_t *dev) (regs[0x70] & 0x70) == 0x40, !(regs[0x70] & 0x20)); } +#ifndef USE_DRB_HACK +static void +i420ex_drb_recalc(i420ex_t *dev) +{ + uint32_t boundary; + + for (int8_t i = 4; i >= 0; i--) + row_disable(i); + + for (uint8_t i = 0; i <= 4; i++) { + boundary = ((uint32_t) dev->regs[0x60 + i]) & 0xff; + row_set_boundary(i, boundary); + } + + flushmmucache(); +} +#endif + + static void i420ex_write(int func, int addr, uint8_t val, void *priv) { @@ -193,6 +221,8 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) ide_set_side(0, 0x0376); ide_pri_enable(); break; + default: + break; } } break; @@ -281,7 +311,12 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) case 0x62: case 0x63: case 0x64: +#ifdef USE_DRB_HACK spd_write_drbs(dev->regs, 0x60, 0x64, 1); +#else + dev->regs[addr] = val; + i420ex_drb_recalc(dev); +#endif break; case 0x66: case 0x67: @@ -354,14 +389,16 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) cpu_fast_off_count = val + 1; cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); break; + default: + break; } } static uint8_t i420ex_read(int func, int addr, void *priv) { - i420ex_t *dev = (i420ex_t *) priv; - uint8_t ret; + const i420ex_t *dev = (i420ex_t *) priv; + uint8_t ret; ret = 0xff; @@ -387,7 +424,7 @@ i420ex_reset_hard(void *priv) dev->regs[0x4c] = 0x4d; dev->regs[0x4e] = 0x03; - /* Bits 2:1 of register 50h are 00 is 25 MHz, and 01 if 33 MHz, 10 and 11 are reserved. */ + /* Bits 2:1 of register 50h are 00 is 25 MHz, and 01 if 33 MHz, 10 and 11 are reserved. */ if (cpu_busspeed >= 33333333) dev->regs[0x50] |= 0x02; dev->regs[0x51] = 0x80; @@ -409,9 +446,9 @@ i420ex_reset_hard(void *priv) } static void -i420ex_apm_out(uint16_t port, uint8_t val, void *p) +i420ex_apm_out(UNUSED(uint16_t port), UNUSED(uint8_t val), void *priv) { - i420ex_t *dev = (i420ex_t *) p; + i420ex_t *dev = (i420ex_t *) priv; if (dev->apm->do_smi) dev->regs[0xaa] |= 0x80; @@ -429,39 +466,41 @@ i420ex_fast_off_count(void *priv) } static void -i420ex_reset(void *p) +i420ex_reset(void *priv) { - i420ex_t *dev = (i420ex_t *) p; - int i; + i420ex_t *dev = (i420ex_t *) priv; - i420ex_write(0, 0x48, 0x00, p); + i420ex_write(0, 0x48, 0x00, priv); - for (i = 0; i < 7; i++) - i420ex_write(0, 0x59 + i, 0x00, p); + /* Disable the PIC mouse latch. */ + i420ex_write(0, 0x4e, 0x03, priv); - for (i = 0; i <= 4; i++) - i420ex_write(0, 0x60 + i, 0x01, p); + for (uint8_t i = 0; i < 7; i++) + i420ex_write(0, 0x59 + i, 0x00, priv); + + for (uint8_t i = 0; i <= 4; i++) + dev->regs[0x60 + i] = 0x01; dev->regs[0x70] &= 0xef; /* Forcibly unlock the SMRAM register. */ dev->smram_locked = 0; - i420ex_write(0, 0x70, 0x00, p); + i420ex_write(0, 0x70, 0x00, priv); mem_set_mem_state(0x000a0000, 0x00060000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); mem_set_mem_state_smm(0x000a0000, 0x00060000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - i420ex_write(0, 0xa0, 0x08, p); - i420ex_write(0, 0xa2, 0x00, p); - i420ex_write(0, 0xa4, 0x00, p); - i420ex_write(0, 0xa5, 0x00, p); - i420ex_write(0, 0xa6, 0x00, p); - i420ex_write(0, 0xa7, 0x00, p); - i420ex_write(0, 0xa8, 0x0f, p); + i420ex_write(0, 0xa0, 0x08, priv); + i420ex_write(0, 0xa2, 0x00, priv); + i420ex_write(0, 0xa4, 0x00, priv); + i420ex_write(0, 0xa5, 0x00, priv); + i420ex_write(0, 0xa6, 0x00, priv); + i420ex_write(0, 0xa7, 0x00, priv); + i420ex_write(0, 0xa8, 0x0f, priv); } static void -i420ex_close(void *p) +i420ex_close(void *priv) { - i420ex_t *dev = (i420ex_t *) p; + i420ex_t *dev = (i420ex_t *) priv; smram_del(dev->smram); @@ -518,6 +557,11 @@ i420ex_init(const device_t *info) device_add(&ide_pci_2ch_device); +#ifndef USE_DRB_HACK + row_device.local = 4 | (1 << 8) | (0x01 << 16) | (8 << 24); + device_add((const device_t *) &row_device); +#endif + i420ex_reset_hard(dev); return dev; diff --git a/src/chipset/intel_4x0.c b/src/chipset/intel_4x0.c index 8f74c79d9..c68f6218c 100644 --- a/src/chipset/intel_4x0.c +++ b/src/chipset/intel_4x0.c @@ -28,6 +28,7 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> #include <86box/spd.h> #include <86box/machine.h> @@ -50,17 +51,20 @@ enum { INTEL_440ZX }; -typedef struct -{ - uint8_t pm2_cntrl, - smram_locked, max_drb, - drb_unit, drb_default; - uint8_t regs[256], regs_locked[256]; +typedef struct i4x0_t { + uint8_t pm2_cntrl; + uint8_t smram_locked; + uint8_t max_drb; + uint8_t drb_unit; + uint8_t drb_default; + uint8_t regs[256]; + uint8_t regs_locked[256]; uint8_t mem_state[256]; int type; - smram_t *smram_low, *smram_high; + smram_t *smram_low; + smram_t *smram_high; agpgart_t *agpgart; - void (*write_drbs)(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit); + void (*write_drbs)(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit); } i4x0_t; #ifdef ENABLE_I4X0_LOG @@ -114,12 +118,13 @@ static void i4x0_smram_handler_phase1(i4x0_t *dev) { - uint8_t *regs = (uint8_t *) dev->regs; - uint32_t tom = (mem_size << 10); - uint8_t *reg = (dev->type >= INTEL_430LX) ? &(regs[0x72]) : &(regs[0x57]); - uint8_t *ext_reg = (dev->type >= INTEL_440BX) ? &(regs[0x73]) : &(regs[0x71]); + const uint8_t *regs = (uint8_t *) dev->regs; + uint32_t tom = (mem_size << 10); + const uint8_t *reg = (dev->type >= INTEL_430LX) ? &(regs[0x72]) : &(regs[0x57]); + const uint8_t *ext_reg = (dev->type >= INTEL_440BX) ? &(regs[0x73]) : &(regs[0x71]); - uint32_t s, base[2] = { 0x000a0000, 0x00000000 }; + uint32_t s; + uint32_t base[2] = { 0x000a0000, 0x00000000 }; uint32_t size[2] = { 0x00010000, 0x00000000 }; if ((dev->type <= INTEL_420ZX) || (dev->type >= INTEL_430FX)) { @@ -164,8 +169,8 @@ i4x0_smram_handler_phase1(i4x0_t *dev) } else { size[0] = 0x00010000; switch (*reg & 0x03) { - case 0: default: + case 0: base[0] = (mem_size << 10) - size[0]; s = 1; break; @@ -221,17 +226,17 @@ i4x0_mask_bar(uint8_t *regs, void *agpgart) } static uint8_t -pm2_cntrl_read(uint16_t addr, void *p) +pm2_cntrl_read(UNUSED(uint16_t addr), void *priv) { - i4x0_t *dev = (i4x0_t *) p; + const i4x0_t *dev = (i4x0_t *) priv; return dev->pm2_cntrl & 0x01; } static void -pm2_cntrl_write(uint16_t addr, uint8_t val, void *p) +pm2_cntrl_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { - i4x0_t *dev = (i4x0_t *) p; + i4x0_t *dev = (i4x0_t *) priv; dev->pm2_cntrl = val & 0x01; } @@ -242,7 +247,6 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) i4x0_t *dev = (i4x0_t *) priv; uint8_t *regs = (uint8_t *) dev->regs; uint8_t *regs_l = (uint8_t *) dev->regs_locked; - int i; if (func > 0) return; @@ -251,6 +255,7 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) switch (addr) { case 0x04: /*Command register*/ switch (dev->type) { + default: case INTEL_420TX: case INTEL_420ZX: case INTEL_430LX: @@ -258,7 +263,6 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440BX: case INTEL_440GX: case INTEL_440ZX: - default: regs[0x04] = (regs[0x04] & ~0x42) | (val & 0x42); break; case INTEL_430FX: @@ -291,16 +295,18 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[0x05] = val & 0x01; break; + default: + break; } break; case 0x07: switch (dev->type) { + default: case INTEL_420TX: case INTEL_420ZX: case INTEL_430LX: case INTEL_430NX: case INTEL_430HX: - default: regs[0x07] &= ~(val & 0x70); break; case INTEL_430FX: @@ -343,6 +349,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_430TX: regs[0x0f] = (val & 0x40); break; + default: + break; } break; case 0x12: @@ -355,6 +363,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[0x12] = (val & 0xc0); i4x0_mask_bar(regs, dev->agpgart); break; + default: + break; } break; case 0x13: @@ -367,6 +377,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[0x13] = val; i4x0_mask_bar(regs, dev->agpgart); break; + default: + break; } break; case 0x2c: @@ -382,6 +394,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs_l[addr] = 1; } break; + default: + break; } break; @@ -396,14 +410,16 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_430TX: regs[0x4f] = (val & 0x80); break; + default: + break; } break; case 0x50: switch (dev->type) { + default: case INTEL_420TX: case INTEL_420ZX: case INTEL_430LX: - default: regs[0x50] = (val & 0xe5); break; case INTEL_430NX: @@ -467,17 +483,19 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[0x51] = (regs[0x51] & 0xb0) | (val & 0x4f); i4x0_mask_bar(regs, dev->agpgart); break; + default: + break; } break; case 0x52: /* Cache Control Register */ switch (dev->type) { + default: case INTEL_420TX: case INTEL_420ZX: case INTEL_430LX: case INTEL_430FX: case INTEL_430VX: case INTEL_430TX: - default: regs[0x52] = (val & 0xfb); break; case INTEL_430NX: @@ -515,6 +533,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) /* Not applicable to 440ZX as that does not support ECC. */ regs[0x53] = val; break; + default: + break; } break; case 0x54: @@ -534,6 +554,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440FX: regs[0x54] = val & 0x82; break; + default: + break; } break; case 0x55: @@ -553,6 +575,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[0x55] = val; break; + default: + break; } break; case 0x56: @@ -577,6 +601,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[0x56] = val; break; + default: + break; } break; case 0x57: @@ -628,10 +654,10 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) break; case 0x58: switch (dev->type) { + default: case INTEL_420TX: case INTEL_420ZX: case INTEL_430LX: - default: regs[0x58] = val & 0x01; break; case INTEL_430NX: @@ -720,6 +746,7 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) break; } switch (dev->type) { + default: case INTEL_420TX: case INTEL_420ZX: case INTEL_430LX: @@ -731,7 +758,6 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440BX: case INTEL_440ZX: case INTEL_440GX: - default: regs[addr] = val; break; case INTEL_430FX: @@ -768,6 +794,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_430TX: regs[addr] = val & 0x7f; break; + default: + break; } break; case 0x66: @@ -786,6 +814,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: regs[addr] = val; break; + default: + break; } break; case 0x67: @@ -810,6 +840,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_430TX: regs[addr] = val & 0xb7; break; + default: + break; } break; case 0x68: @@ -838,6 +870,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: regs[0x68] = (regs[0x68] & 0x3f) | (val & 0xc0); break; + default: + break; } break; case 0x69: @@ -856,6 +890,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: regs[0x69] = val & 0x3f; break; + default: + break; } break; case 0x6a: @@ -880,6 +916,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) else regs[addr] = val & 0x33; break; + default: + break; } break; case 0x6c: @@ -899,6 +937,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) else if (addr == 0x6d) regs[addr] = val & 0xcf; break; + default: + break; } break; case 0x6f: @@ -909,6 +949,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[addr] = val & 0xcf; break; + default: + break; } break; case 0x70: @@ -930,6 +972,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[addr] = val & 0xf8; break; + default: + break; } break; case 0x71: @@ -953,6 +997,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440LX: regs[addr] = val & 0x1f; break; + default: + break; } break; case 0x72: /* SMRAM */ @@ -998,6 +1044,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) i4x0_smram_handler_phase1(dev); } break; + default: + break; } break; case 0x74: @@ -1008,6 +1056,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0x74] = val; break; + default: + break; } break; case 0x75: @@ -1018,6 +1068,10 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: case INTEL_440GX: regs[addr] = val; + break; + + default: + break; } break; case 0x77: @@ -1025,6 +1079,10 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440BX: case INTEL_440ZX: regs[0x77] = val & 0x03; + break; + + default: + break; } break; case 0x78: @@ -1039,6 +1097,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0x78] = val & 0x1f; break; + default: + break; } break; case 0x79: @@ -1054,6 +1114,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0x79] = val; break; + default: + break; } break; case 0x7a: @@ -1066,6 +1128,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) if (val & 0x40) io_sethandler(0x0022, 0x01, pm2_cntrl_read, NULL, NULL, pm2_cntrl_write, NULL, NULL, dev); break; + default: + break; } break; case 0x7c: @@ -1081,6 +1145,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: regs[0x7c] = val & 0x1f; break; + default: + break; } break; case 0x7d: @@ -1091,6 +1157,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_430NX: regs[0x7d] = val & 0x32; break; + default: + break; } break; case 0x7e: @@ -1102,6 +1170,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_430NX: regs[addr] = val; break; + default: + break; } break; case 0x80: @@ -1111,6 +1181,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0x80] &= ~(val & 0x03); break; + default: + break; } break; case 0x90: @@ -1132,6 +1204,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0x90] = val; break; + default: + break; } break; case 0x91: @@ -1144,6 +1218,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) /* Not applicable on 82443EX and 82443ZX. */ regs[0x91] &= ~(val & 0x11); break; + default: + break; } break; case 0x92: @@ -1157,6 +1233,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0x92] &= ~(val & 0x1f); break; + default: + break; } break; case 0x93: @@ -1170,6 +1248,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[0x93] = (val & 0x0e); trc_write(0x0093, val & 0x06, NULL); break; + default: + break; } break; case 0xa7: @@ -1178,6 +1258,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[0xa7] = val & 0x1f; break; + default: + break; } break; case 0xa8: @@ -1190,6 +1272,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[addr] = (val & 0x03); break; + default: + break; } break; case 0xb0: @@ -1201,6 +1285,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0xb0] = (val & 0x80); break; + default: + break; } break; case 0xb1: @@ -1214,6 +1300,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0xb1] = (val & 0xa0); break; + default: + break; } break; case 0xb4: @@ -1226,6 +1314,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[0xb4] = (val & 0x3f); i4x0_mask_bar(regs, dev->agpgart); break; + default: + break; } break; case 0xb9: @@ -1238,6 +1328,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[0xb9] = (val & 0xf0); i4x0_mask_bar(regs, dev->agpgart); break; + default: + break; } break; @@ -1252,6 +1344,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[addr] = val; i4x0_mask_bar(regs, dev->agpgart); break; + default: + break; } break; @@ -1261,6 +1355,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[addr] = (val & 0xf8); break; + default: + break; } break; @@ -1270,6 +1366,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440EX: regs[addr] = (val & 0xf8); break; + default: + break; } break; @@ -1287,6 +1385,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[addr] = val; break; + default: + break; } break; case 0xca: @@ -1298,6 +1398,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: regs[addr] = val & 0xe7; break; + default: + break; } break; case 0xcb: @@ -1309,6 +1411,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: regs[addr] = val & 0xa7; break; + default: + break; } break; case 0xcc: @@ -1320,6 +1424,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: regs[0xcc] = (val & 0x58); break; + default: + break; } break; case 0xe0: @@ -1339,6 +1445,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) if (!regs_l[addr]) regs[addr] = val; break; + default: + break; } break; case 0xe5: @@ -1350,6 +1458,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) if (!regs_l[addr]) regs[addr] = (val & 0x3f); break; + default: + break; } break; case 0xe7: @@ -1358,12 +1468,14 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: case INTEL_440GX: regs[0xe7] = 0x80; - for (i = 0; i < 16; i++) + for (uint8_t i = 0; i < 16; i++) regs_l[0xe0 + i] = !!(val & 0x80); if (!regs_l[0xe7]) { regs[0xe7] |= (val & 0x7f); } break; + default: + break; } break; case 0xf0: @@ -1373,6 +1485,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0xf0] = (val & 0xc0); break; + default: + break; } break; case 0xf1: @@ -1382,17 +1496,22 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440GX: regs[0xf1] = (val & 0x03); break; + default: + break; } break; + + default: + break; } } static uint8_t i4x0_read(int func, int addr, void *priv) { - i4x0_t *dev = (i4x0_t *) priv; - uint8_t ret = 0xff; - uint8_t *regs = (uint8_t *) dev->regs; + i4x0_t *dev = (i4x0_t *) priv; + uint8_t ret = 0xff; + const uint8_t *regs = (uint8_t *) dev->regs; if (func == 0) { ret = regs[addr]; @@ -1409,7 +1528,6 @@ static void i4x0_reset(void *priv) { i4x0_t *dev = (i4x0_t *) priv; - int i; if ((dev->type == INTEL_440LX) || (dev->type == INTEL_440BX) || (dev->type == INTEL_440ZX)) memset(dev->regs_locked, 0x00, 256 * sizeof(uint8_t)); @@ -1419,11 +1537,16 @@ i4x0_reset(void *priv) else i4x0_write(0, 0x59, 0x0f, priv); - for (i = 0; i < 6; i++) + for (uint8_t i = 0; i < 6; i++) i4x0_write(0, 0x5a + i, 0x00, priv); - for (i = 0; i <= dev->max_drb; i++) - i4x0_write(0, 0x60 + i, dev->drb_default, priv); + for (uint8_t i = 0; i <= dev->max_drb; i++) + dev->regs[0x60 + i] = dev->drb_default; + + if (dev->type >= INTEL_430NX) { + for (uint8_t i = 0; i < 4; i++) + dev->regs[0x68 + i] = 0x00; + } if (dev->type >= INTEL_430FX) { dev->regs[0x72] &= 0xef; /* Forcibly unlock the SMRAM register. */ @@ -1443,9 +1566,9 @@ i4x0_reset(void *priv) } static void -i4x0_close(void *p) +i4x0_close(void *priv) { - i4x0_t *dev = (i4x0_t *) p; + i4x0_t *dev = (i4x0_t *) priv; smram_del(dev->smram_high); smram_del(dev->smram_low); @@ -1453,9 +1576,8 @@ i4x0_close(void *p) free(dev); } -static void - * - i4x0_init(const device_t *info) +static void * +i4x0_init(const device_t *info) { i4x0_t *dev = (i4x0_t *) malloc(sizeof(i4x0_t)); uint8_t *regs; @@ -1484,9 +1606,9 @@ static void regs[0x0d] = 0x20; /* According to information from FreeBSD 3.x source code: 0x00 = 486DX, 0x20 = 486SX, 0x40 = 486DX2 or 486DX4, 0x80 = Pentium OverDrive. */ - if (!(hasfpu) && (cpu_multi == 1)) + if (!hasfpu && (cpu_multi == 1)) regs[0x50] = 0x20; - else if (!(hasfpu) && (cpu_multi == 2)) + else if (!hasfpu && (cpu_multi == 2)) regs[0x50] = 0x60; /* Guess based on the SX, DX, and DX2 values. */ else if (hasfpu && (cpu_multi == 1)) regs[0x50] = 0x00; @@ -1508,7 +1630,7 @@ static void regs[0x59] = 0x0f; regs[0x60] = regs[0x61] = regs[0x62] = regs[0x63] = 0x02; dev->max_drb = 3; - dev->drb_unit = 4; + dev->drb_unit = 1; dev->drb_default = 0x02; break; case INTEL_430LX: @@ -1746,6 +1868,8 @@ static void dev->drb_unit = 8; dev->drb_default = 0x01; break; + default: + break; } regs[0x04] = 0x06; diff --git a/src/chipset/intel_82335.c b/src/chipset/intel_82335.c index e945f35d1..da0cc30f6 100644 --- a/src/chipset/intel_82335.c +++ b/src/chipset/intel_82335.c @@ -28,6 +28,7 @@ #include <86box/device.h> #include <86box/mem.h> #include <86box/chipset.h> +#include <86box/plat_unused.h> /* Shadow capabilities */ #define DISABLED_SHADOW (MEM_READ_EXTANY | MEM_WRITE_EXTANY) @@ -56,12 +57,10 @@ #define DEFINE_RC1_REMAP_SIZE ((dev->regs[0x24] & 0x02) ? 128 : 256) #define DEFINE_RC2_REMAP_SIZE ((dev->regs[0x26] & 0x02) ? 128 : 256) -typedef struct -{ +typedef struct intel_82335_t { + uint16_t regs[256]; - uint16_t regs[256], - - cfg_locked; + uint16_t cfg_locked; } intel_82335_t; @@ -86,8 +85,11 @@ intel_82335_log(const char *fmt, ...) static void intel_82335_write(uint16_t addr, uint16_t val, void *priv) { - intel_82335_t *dev = (intel_82335_t *) priv; - uint32_t romsize = 0, base = 0, i = 0, rc1_remap = 0, rc2_remap = 0; + intel_82335_t *dev = (intel_82335_t *) priv; + uint32_t romsize = 0; + uint32_t base = 0; + uint32_t rc1_remap = 0; + uint32_t rc2_remap = 0; dev->regs[addr] = val; @@ -106,7 +108,9 @@ intel_82335_write(uint16_t addr, uint16_t val, void *priv) shadowbios_write = !!(dev->regs[0x22] & 0x01); /* Base System 512/640KB set */ - // mem_set_mem_state_both(0x80000, 0x20000, (dev->regs[0x22] & 0x08) ? ENABLE_TOP_128KB : DISABLE_TOP_128KB); +#if 0 + mem_set_mem_state_both(0x80000, 0x20000, (dev->regs[0x22] & 0x08) ? ENABLE_TOP_128KB : DISABLE_TOP_128KB); +#endif /* Video RAM shadow*/ mem_set_mem_state_both(0xa0000, 0x20000, (dev->regs[0x22] & (0x04 << 8)) ? DETERMINE_VIDEO_RAM_WRITE_ACCESS : DISABLED_SHADOW); @@ -128,14 +132,17 @@ intel_82335_write(uint16_t addr, uint16_t val, void *priv) case 0x2e: /* Extended Granularity (Enabled if Bit 0 in Register 2Ch is set) */ if (EXTENDED_GRANULARITY_ENABLED) { - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); shadowbios = (dev->regs[0x2e] & (1 << (i + 8))) && (base == romsize); shadowbios_write = (dev->regs[0x2e] & (1 << i)) && (base == romsize); mem_set_mem_state_both(base, 0x8000, GRANULARITY_RECALC); } - break; } + break; + + default: + break; } } @@ -146,7 +153,7 @@ intel_82335_write(uint16_t addr, uint16_t val, void *priv) static uint16_t intel_82335_read(uint16_t addr, void *priv) { - intel_82335_t *dev = (intel_82335_t *) priv; + const intel_82335_t *dev = (intel_82335_t *) priv; intel_82335_log("Register %02x: Read %04x\n", addr, dev->regs[addr]); @@ -162,7 +169,7 @@ intel_82335_close(void *priv) } static void * -intel_82335_init(const device_t *info) +intel_82335_init(UNUSED(const device_t *info)) { intel_82335_t *dev = (intel_82335_t *) malloc(sizeof(intel_82335_t)); memset(dev, 0, sizeof(intel_82335_t)); diff --git a/src/chipset/intel_i450kx.c b/src/chipset/intel_i450kx.c index ac3746492..b81c3dde4 100644 --- a/src/chipset/intel_i450kx.c +++ b/src/chipset/intel_i450kx.c @@ -35,6 +35,7 @@ i450GX is way more popular of an option but needs more stuff. #include <86box/device.h> #include <86box/mem.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/smram.h> #include <86box/spd.h> #include <86box/chipset.h> @@ -61,7 +62,8 @@ i450kx_log(const char *fmt, ...) typedef struct i450kx_t { smram_t *smram[2]; - uint8_t pb_pci_conf[256], mc_pci_conf[256]; + uint8_t pb_pci_conf[256]; + uint8_t mc_pci_conf[256]; uint8_t mem_state[2][256]; uint8_t bus_index; @@ -88,8 +90,9 @@ i450kx_map(i450kx_t *dev, int bus, uint32_t addr, uint32_t size, int state) static void i450kx_smram_recalc(i450kx_t *dev, int bus) { - uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; - uint32_t addr, size; + const uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; + uint32_t addr; + uint32_t size; smram_disable(dev->smram[bus]); @@ -109,9 +112,11 @@ i450kx_smram_recalc(i450kx_t *dev, int bus) static void i450kx_vid_buf_recalc(i450kx_t *dev, int bus) { - uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; + const uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; +#if 0 // int state = (regs[0x58] & 0x02) ? (MEM_READ_EXTANY | MEM_WRITE_EXTANY) : (MEM_READ_DISABLED | MEM_WRITE_DISABLED); +#endif int state = (regs[0x58] & 0x02) ? (MEM_READ_INTERNAL | MEM_WRITE_INTERNAL) : (MEM_READ_EXTANY | MEM_WRITE_EXTANY); if (bus) @@ -166,8 +171,10 @@ pb_write(int func, int addr, uint8_t val, void *priv) case 0x4a: case 0x4b: dev->pb_pci_conf[addr] = val; - // if (addr == 0x4a) - // pci_remap_bus(dev->bus_index, val); +#if 0 + if (addr == 0x4a) + pci_remap_bus(dev->bus_index, val); +#endif break; case 0x4c: @@ -319,13 +326,6 @@ pb_write(int func, int addr, uint8_t val, void *priv) dev->pb_pci_conf[addr] = val & /*0x1a*/ 0x1f; break; - case 0xb4: - dev->pb_pci_conf[addr] = val & 0xe0; - break; - case 0xb5: - dev->pb_pci_conf[addr] = val & 0x1f; - break; - case 0xb8: case 0xb9: dev->pb_pci_conf[addr] = val; @@ -365,13 +365,16 @@ pb_write(int func, int addr, uint8_t val, void *priv) case 0xcb: dev->pb_pci_conf[addr] = val; break; + + default: + break; } } static uint8_t pb_read(int func, int addr, void *priv) { - i450kx_t *dev = (i450kx_t *) priv; + const i450kx_t *dev = (i450kx_t *) priv; uint8_t ret = 0xff; if (func == 0) @@ -386,10 +389,8 @@ pb_read(int func, int addr, void *priv) static void mc_fill_drbs(i450kx_t *dev) { - int i; - spd_write_drbs_interleaved(dev->mc_pci_conf, 0x60, 0x6f, 4); - for (i = 0x60; i <= 0x6f; i++) { + for (uint8_t i = 0x60; i <= 0x6f; i++) { if (i & 0x01) dev->mc_pci_conf[i] = 0x00; else @@ -591,13 +592,16 @@ mc_write(int func, int addr, uint8_t val, void *priv) case 0xcb: dev->mc_pci_conf[addr] = val; break; + + default: + break; } } static uint8_t mc_read(int func, int addr, void *priv) { - i450kx_t *dev = (i450kx_t *) priv; + const i450kx_t *dev = (i450kx_t *) priv; uint8_t ret = 0xff; if (func == 0) @@ -614,7 +618,9 @@ i450kx_reset(void *priv) i450kx_t *dev = (i450kx_t *) priv; uint32_t i; +#if 0 // pclog("i450KX: i450kx_reset()\n"); +#endif /* Defaults PB */ dev->pb_pci_conf[0x00] = 0x86; @@ -672,9 +678,11 @@ i450kx_reset(void *priv) dev->pb_pci_conf[0xa6] = 0xfe; dev->pb_pci_conf[0xa7] = 0x00; /* Note: Do NOT reset these two registers on programmed (TRC) hard reset! */ - // dev->pb_pci_conf[0xb0] = 0x00; - // dev->pb_pci_conf[0xb1] = 0x00; - dev->pb_pci_conf[0xb4] = 0x00; +#if 0 + dev->pb_pci_conf[0xb0] = 0x00; + dev->pb_pci_conf[0xb1] = 0x00; +#endif + dev->pb_pci_conf[0xb4] = 0xff; dev->pb_pci_conf[0xb5] = 0x00; dev->pb_pci_conf[0xb8] = 0x05; dev->pb_pci_conf[0xb9] = 0x00; @@ -694,7 +702,9 @@ i450kx_reset(void *priv) dev->pb_pci_conf[0xca] = 0x00; dev->pb_pci_conf[0xcb] = 0x00; - // pci_remap_bus(dev->bus_index, 0x00); +#if 0 + pci_remap_bus(dev->bus_index, 0x00); +#endif i450kx_smram_recalc(dev, 1); i450kx_vid_buf_recalc(dev, 1); pb_write(0, 0x59, 0x30, dev); @@ -787,7 +797,7 @@ i450kx_close(void *priv) } static void * -i450kx_init(const device_t *info) +i450kx_init(UNUSED(const device_t *info)) { i450kx_t *dev = (i450kx_t *) malloc(sizeof(i450kx_t)); memset(dev, 0, sizeof(i450kx_t)); diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 180940e26..038f35f97 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -40,6 +40,7 @@ #include <86box/pci.h> #include <86box/pic.h> #include <86box/pit.h> +#include <86box/plat.h> #include <86box/port_92.h> #include <86box/scsi_device.h> #include <86box/hdc.h> @@ -50,7 +51,7 @@ #include <86box/smbus.h> #include <86box/chipset.h> -typedef struct { +typedef struct piix_io_trap_t { struct _piix_ *dev; void *trap; uint8_t dev_id; @@ -58,14 +59,20 @@ typedef struct { } piix_io_trap_t; typedef struct _piix_ { - uint8_t cur_readout_reg, rev, - type, func_shift, - max_func, pci_slot, - no_mirq0, pad, - regs[4][256], - readout_regs[256], board_config[2]; - uint16_t func0_id, nvr_io_base, - acpi_io_base; + uint8_t cur_readout_reg; + uint8_t rev; + uint8_t type; + uint8_t func_shift; + uint8_t max_func; + uint8_t pci_slot; + uint8_t no_mirq0; + uint8_t pad; + uint8_t regs[4][256]; + uint8_t readout_regs[256]; + uint8_t board_config[2]; + uint16_t func0_id; + uint16_t nvr_io_base; + uint16_t acpi_io_base; double fast_off_period; sff8038i_t *bm[2]; smbus_piix4_t *smbus; @@ -77,6 +84,7 @@ typedef struct _piix_ { piix_io_trap_t io_traps[26]; port_92_t *port_92; pc_timer_t fast_off_timer; + usb_params_t usb_params; } piix_t; #ifdef ENABLE_PIIX_LOG @@ -100,7 +108,8 @@ piix_log(const char *fmt, ...) static void smsc_ide_irqs(piix_t *dev) { - int irq_line = 3, irq_mode[2] = { 0, 0 }; + int irq_line = 3; + uint8_t irq_mode[2] = { 0, 0 }; if (dev->regs[1][0x09] & 0x01) irq_mode[0] = (dev->regs[0][0xe1] & 0x01) ? 3 : 1; @@ -133,6 +142,8 @@ smsc_ide_irqs(piix_t *dev) case 0x07: irq_line = 15; break; + default: + break; } sff_set_irq_line(dev->bm[0], irq_line); @@ -147,7 +158,8 @@ smsc_ide_irqs(piix_t *dev) static void piix_ide_handlers(piix_t *dev, int bus) { - uint16_t main, side; + uint16_t main; + uint16_t side; if (bus & 0x01) { ide_pri_disable(); @@ -200,7 +212,7 @@ piix_ide_bm_handlers(piix_t *dev) } static uint8_t -kbc_alias_reg_read(uint16_t addr, void *p) +kbc_alias_reg_read(UNUSED(uint16_t addr), UNUSED(void *priv)) { uint8_t ret = inb(0x61); @@ -208,7 +220,7 @@ kbc_alias_reg_read(uint16_t addr, void *p) } static void -kbc_alias_reg_write(uint16_t addr, uint8_t val, void *p) +kbc_alias_reg_write(UNUSED(uint16_t addr), uint8_t val, UNUSED(void *priv)) { outb(0x61, val); } @@ -264,7 +276,7 @@ nvr_update_io_mapping(piix_t *dev) } static void -piix_trap_io(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) +piix_trap_io(UNUSED(int size), UNUSED(uint16_t addr), UNUSED(uint8_t write), UNUSED(uint8_t val), void *priv) { piix_io_trap_t *trap = (piix_io_trap_t *) priv; @@ -277,7 +289,7 @@ piix_trap_io(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) static void piix_trap_io_ide(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) { - piix_io_trap_t *trap = (piix_io_trap_t *) priv; + const piix_io_trap_t *trap = (piix_io_trap_t *) priv; /* IDE traps are per drive, not per channel. */ if (ide_drives[trap->dev_id]->selected) @@ -315,9 +327,10 @@ piix_trap_update_devctl(piix_t *dev, uint8_t trap_id, uint8_t dev_id, static void piix_trap_update(void *priv) { - piix_t *dev = (piix_t *) priv; - uint8_t trap_id = 0, *fregs = dev->regs[3]; - uint16_t temp; + piix_t *dev = (piix_t *) priv; + uint8_t trap_id = 0; + const uint8_t *fregs = dev->regs[3]; + uint16_t temp; piix_trap_update_devctl(dev, trap_id++, 0, 0x00000002, 1, 0x1f0, 8); piix_trap_update_devctl(dev, trap_id++, 0, 0x00000002, 1, 0x3f6, 1); @@ -458,7 +471,6 @@ piix_write(int func, int addr, uint8_t val, void *priv) piix_t *dev = (piix_t *) priv; uint8_t *fregs; uint16_t base; - int i; /* Return on unsupported function. */ if (dev->max_func > 0) { @@ -512,7 +524,6 @@ piix_write(int func, int addr, uint8_t val, void *priv) break; case 0x4e: fregs[0x4e] = val; - keyboard_at_set_mouse_scan((val & 0x10) ? 1 : 0); if (dev->type >= 4) kbc_alias_update_io_mapping(dev); break; @@ -553,8 +564,8 @@ piix_write(int func, int addr, uint8_t val, void *priv) break; case 0x6a: switch (dev->type) { - case 1: default: + case 1: fregs[0x6a] = (fregs[0x6a] & 0xfb) | (val & 0x04); fregs[0x0e] = (val & 0x04) ? 0x80 : 0x00; piix_log("PIIX: Write %02X\n", val); @@ -639,7 +650,7 @@ piix_write(int func, int addr, uint8_t val, void *priv) base = fregs[addr | 0x01] << 8; base |= fregs[addr & 0xfe]; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) ddma_update_io_mapping(dev->ddma, (addr & 4) + i, fregs[addr & 0xfe] + (i << 4), fregs[addr | 0x01], (base != 0x0000)); } break; @@ -789,6 +800,8 @@ piix_write(int func, int addr, uint8_t val, void *priv) } } break; + default: + break; } else if (func == 1) switch (addr) { /* IDE */ @@ -1010,6 +1023,8 @@ piix_write(int func, int addr, uint8_t val, void *priv) nvr_read_addr_set(!!(val & 0x10), dev->nvr); } break; + default: + break; } else if (func == 3) switch (addr) { /* Power Management */ @@ -1143,14 +1158,17 @@ piix_write(int func, int addr, uint8_t val, void *priv) fregs[0x91] = val; smbus_update_io_mapping(dev); break; + default: + break; } } static uint8_t piix_read(int func, int addr, void *priv) { - piix_t *dev = (piix_t *) priv; - uint8_t ret = 0xff, *fregs; + piix_t *dev = (piix_t *) priv; + uint8_t ret = 0xff; + const uint8_t *fregs; if ((dev->type == 3) && (func == 2) && (dev->max_func == 1) && (addr >= 0x40)) ret = 0x00; @@ -1159,9 +1177,7 @@ piix_read(int func, int addr, void *priv) if ((func <= dev->max_func) || ((func == 1) && (dev->max_func == 0))) { fregs = (uint8_t *) dev->regs[func]; ret = fregs[addr]; - if ((func == 0) && (addr == 0x4e)) - ret |= keyboard_at_get_mouse_scan(); - else if ((func == 2) && (addr == 0xff)) + if ((func == 2) && (addr == 0xff)) ret |= 0xef; piix_log("PIIX function %i read: %02X from %02X\n", func, ret, addr); @@ -1186,8 +1202,8 @@ board_write(uint16_t port, uint8_t val, void *priv) static uint8_t board_read(uint16_t port, void *priv) { - piix_t *dev = (piix_t *) priv; - uint8_t ret = 0x64; + const piix_t *dev = (piix_t *) priv; + uint8_t ret = 0x64; if (port == 0x0078) ret = dev->board_config[0]; @@ -1204,7 +1220,6 @@ board_read(uint16_t port, void *priv) static void piix_reset_hard(piix_t *dev) { - int i; uint8_t *fregs; uint16_t old_base = (dev->regs[1][0x20] & 0xf0) | (dev->regs[1][0x21] << 8); @@ -1241,7 +1256,7 @@ piix_reset_hard(piix_t *dev) } /* Clear all 4 functions' arrays and set their vendor and device ID's. */ - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { memset(dev->regs[i], 0, 256); if (dev->type == 5) { dev->regs[i][0x00] = 0x55; @@ -1293,7 +1308,7 @@ piix_reset_hard(piix_t *dev) fregs[0xa0] = (dev->type < 4) ? 0x08 : 0x00; fregs[0xa8] = (dev->type < 4) ? 0x0f : 0x00; if (dev->type > 3) - fregs[0xb0] = (is_pentium) ? 0x00 : 0x04; + fregs[0xb0] = is_pentium ? 0x00 : 0x04; fregs[0xcb] = (dev->type > 3) ? 0x21 : 0x00; if (dev->type > 4) { fregs[0xd4] = 0x70; @@ -1409,9 +1424,9 @@ piix_reset_hard(piix_t *dev) } static void -piix_apm_out(uint16_t port, uint8_t val, void *p) +piix_apm_out(UNUSED(uint16_t port), UNUSED(uint8_t val), void *priv) { - piix_t *dev = (piix_t *) p; + piix_t *dev = (piix_t *) priv; if (dev->apm->do_smi) { if (dev->type < 4) @@ -1429,70 +1444,84 @@ piix_fast_off_count(void *priv) } static void -piix_reset(void *p) +piix_usb_update_interrupt(usb_t* usb, void *priv) { - piix_t *dev = (piix_t *) p; + const piix_t *dev = (piix_t *) priv; + + if (usb->irq_level) + pci_set_irq(dev->pci_slot, PCI_INTD); + else + pci_clear_irq(dev->pci_slot, PCI_INTD); +} + +static void +piix_reset(void *priv) +{ + const piix_t *dev = (piix_t *) priv; if (dev->type > 3) { - piix_write(3, 0x04, 0x00, p); - piix_write(3, 0x5b, 0x00, p); + piix_write(3, 0x04, 0x00, priv); + piix_write(3, 0x5b, 0x00, priv); } else { - piix_write(0, 0xa0, 0x08, p); - piix_write(0, 0xa2, 0x00, p); - piix_write(0, 0xa4, 0x00, p); - piix_write(0, 0xa5, 0x00, p); - piix_write(0, 0xa6, 0x00, p); - piix_write(0, 0xa7, 0x00, p); - piix_write(0, 0xa8, 0x0f, p); + piix_write(0, 0xa0, 0x08, priv); + piix_write(0, 0xa2, 0x00, priv); + piix_write(0, 0xa4, 0x00, priv); + piix_write(0, 0xa5, 0x00, priv); + piix_write(0, 0xa6, 0x00, priv); + piix_write(0, 0xa7, 0x00, priv); + piix_write(0, 0xa8, 0x0f, priv); } + /* Disable the PIC mouse latch. */ + piix_write(0, 0x4e, 0x03, priv); + if (dev->type == 5) - piix_write(0, 0xe1, 0x40, p); - piix_write(1, 0x04, 0x00, p); + piix_write(0, 0xe1, 0x40, priv); + piix_write(1, 0x04, 0x00, priv); if (dev->type == 5) { - piix_write(1, 0x09, 0x8a, p); - piix_write(1, 0x10, 0xf1, p); - piix_write(1, 0x11, 0x01, p); - piix_write(1, 0x14, 0xf5, p); - piix_write(1, 0x15, 0x03, p); - piix_write(1, 0x18, 0x71, p); - piix_write(1, 0x19, 0x01, p); - piix_write(1, 0x1c, 0x75, p); - piix_write(1, 0x1d, 0x03, p); + piix_write(1, 0x09, 0x8a, priv); + piix_write(1, 0x10, 0xf1, priv); + piix_write(1, 0x11, 0x01, priv); + piix_write(1, 0x14, 0xf5, priv); + piix_write(1, 0x15, 0x03, priv); + piix_write(1, 0x18, 0x71, priv); + piix_write(1, 0x19, 0x01, priv); + piix_write(1, 0x1c, 0x75, priv); + piix_write(1, 0x1d, 0x03, priv); } else - piix_write(1, 0x09, 0x80, p); - piix_write(1, 0x20, 0x01, p); - piix_write(1, 0x21, 0x00, p); - piix_write(1, 0x41, 0x00, p); - piix_write(1, 0x43, 0x00, p); + piix_write(1, 0x09, 0x80, priv); + piix_write(1, 0x20, 0x01, priv); + piix_write(1, 0x21, 0x00, priv); + piix_write(1, 0x41, 0x00, priv); + piix_write(1, 0x43, 0x00, priv); ide_pri_disable(); ide_sec_disable(); if (dev->type >= 3) { - piix_write(2, 0x04, 0x00, p); + piix_write(2, 0x04, 0x00, priv); if (dev->type == 5) { - piix_write(2, 0x10, 0x00, p); - piix_write(2, 0x11, 0x00, p); - piix_write(2, 0x12, 0x00, p); - piix_write(2, 0x13, 0x00, p); + piix_write(2, 0x10, 0x00, priv); + piix_write(2, 0x11, 0x00, priv); + piix_write(2, 0x12, 0x00, priv); + piix_write(2, 0x13, 0x00, priv); } else { - piix_write(2, 0x20, 0x01, p); - piix_write(2, 0x21, 0x00, p); - piix_write(2, 0x22, 0x00, p); - piix_write(2, 0x23, 0x00, p); + piix_write(2, 0x20, 0x01, priv); + piix_write(2, 0x21, 0x00, priv); + piix_write(2, 0x22, 0x00, priv); + piix_write(2, 0x23, 0x00, priv); } } if (dev->type >= 4) { - piix_write(0, 0xb0, (is_pentium) ? 0x00 : 0x04, p); - piix_write(3, 0x40, 0x01, p); - piix_write(3, 0x41, 0x00, p); - piix_write(3, 0x5b, 0x00, p); - piix_write(3, 0x80, 0x00, p); - piix_write(3, 0x90, 0x01, p); - piix_write(3, 0x91, 0x00, p); - piix_write(3, 0xd2, 0x00, p); + piix_write(0, 0xb0, is_pentium ? 0x00 : 0x04, priv); + piix_write(3, 0x40, 0x01, priv); + piix_write(3, 0x41, 0x00, priv); + piix_write(3, 0x5b, 0x00, priv); + piix_write(3, 0x80, 0x00, priv); + piix_write(3, 0x90, 0x01, priv); + piix_write(3, 0x91, 0x00, priv); + piix_write(3, 0xd2, 0x00, priv); } sff_set_irq_mode(dev->bm[0], 0, 0); @@ -1532,9 +1561,8 @@ piix_speed_changed(void *priv) timer_on_auto(&dev->fast_off_timer, ((double) cpu_fast_off_val + 1) * dev->fast_off_period); } -static void - * - piix_init(const device_t *info) +static void * +piix_init(const device_t *info) { piix_t *dev = (piix_t *) malloc(sizeof(piix_t)); memset(dev, 0, sizeof(piix_t)); @@ -1570,8 +1598,12 @@ static void sff_set_irq_mode(dev->bm[1], 1, 2); } - if (dev->type >= 3) - dev->usb = device_add(&usb_device); + if (dev->type >= 3) { + dev->usb_params.parent_priv = dev; + dev->usb_params.smi_handle = NULL; + dev->usb_params.update_interrupt = piix_usb_update_interrupt; + dev->usb = device_add_parameters(&usb_device, &dev->usb_params); + } if (dev->type > 3) { dev->nvr = device_add(&piix4_nvr_device); @@ -1678,7 +1710,9 @@ static void else dev->board_config[1] |= 0x00; - // device_add(&i8254_sec_device); +#if 0 + device_add(&i8254_sec_device); +#endif return dev; } diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index d94cac04a..1dcbafe5a 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -27,23 +27,25 @@ #include <86box/dma.h> #include <86box/mem.h> #include <86box/pci.h> +#include <86box/pic.h> #include <86box/timer.h> #include <86box/pit.h> #include <86box/port_92.h> #include <86box/machine.h> #include <86box/chipset.h> +#include <86box/plat_unused.h> -typedef struct -{ - uint8_t id, - regs[256]; +typedef struct sio_t { + uint8_t id; + uint8_t regs[256]; - uint16_t timer_base, - timer_latch; + uint16_t timer_base; + uint16_t timer_latch; double fast_off_period; - pc_timer_t timer, fast_off_timer; + pc_timer_t timer; + pc_timer_t fast_off_timer; apm_t *apm; port_92_t *port_92; @@ -199,6 +201,8 @@ sio_write(int func, int addr, uint8_t val, void *priv) dev->regs[addr] = val; break; case 0x4c: + dev->regs[addr] = (val & 0x7f); + break; case 0x4d: dev->regs[addr] = (val & 0x7f); break; @@ -312,14 +316,16 @@ sio_write(int func, int addr, uint8_t val, void *priv) cpu_fast_off_count = val + 1; cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); break; + default: + break; } } static uint8_t sio_read(int func, int addr, void *priv) { - sio_t *dev = (sio_t *) priv; - uint8_t ret; + const sio_t *dev = (sio_t *) priv; + uint8_t ret; ret = 0xff; @@ -330,12 +336,13 @@ sio_read(int func, int addr, void *priv) } static void -sio_config_write(uint16_t addr, uint8_t val, void *priv) +sio_config_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), UNUSED(void *priv)) { + // } static uint8_t -sio_config_read(uint16_t port, void *priv) +sio_config_read(uint16_t port, UNUSED(void *priv)) { uint8_t ret = 0x00; @@ -362,6 +369,9 @@ sio_config_read(uint16_t port, void *priv) break; } break; + + default: + break; } return ret; @@ -422,9 +432,9 @@ sio_reset_hard(void *priv) } static void -sio_apm_out(uint16_t port, uint8_t val, void *p) +sio_apm_out(UNUSED(uint16_t port), UNUSED(uint8_t val), void *priv) { - sio_t *dev = (sio_t *) p; + sio_t *dev = (sio_t *) priv; if (dev->apm->do_smi) dev->regs[0xaa] |= 0x80; @@ -440,29 +450,32 @@ sio_fast_off_count(void *priv) } static void -sio_reset(void *p) +sio_reset(void *priv) { - sio_t *dev = (sio_t *) p; + const sio_t *dev = (sio_t *) priv; - sio_write(0, 0x57, 0x04, p); + /* Disable the PIC mouse latch. */ + sio_write(0, 0x4d, 0x40, priv); + + sio_write(0, 0x57, 0x04, priv); dma_set_params(1, 0xffffffff); if (dev->id == 0x03) { - sio_write(0, 0xa0, 0x08, p); - sio_write(0, 0xa2, 0x00, p); - sio_write(0, 0xa4, 0x00, p); - sio_write(0, 0xa5, 0x00, p); - sio_write(0, 0xa6, 0x00, p); - sio_write(0, 0xa7, 0x00, p); - sio_write(0, 0xa8, 0x0f, p); + sio_write(0, 0xa0, 0x08, priv); + sio_write(0, 0xa2, 0x00, priv); + sio_write(0, 0xa4, 0x00, priv); + sio_write(0, 0xa5, 0x00, priv); + sio_write(0, 0xa6, 0x00, priv); + sio_write(0, 0xa7, 0x00, priv); + sio_write(0, 0xa8, 0x0f, priv); } } static void -sio_close(void *p) +sio_close(void *priv) { - sio_t *dev = (sio_t *) p; + sio_t *dev = (sio_t *) priv; free(dev); } @@ -536,7 +549,9 @@ sio_init(const device_t *info) timer_add(&dev->timer, NULL, NULL, 0); - // device_add(&i8254_sec_device); +#if 0 + device_add(&i8254_sec_device); +#endif return dev; } diff --git a/src/chipset/neat.c b/src/chipset/neat.c index 83f3eb96a..a54fc312e 100644 --- a/src/chipset/neat.c +++ b/src/chipset/neat.c @@ -30,6 +30,7 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/mem.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> #define NEAT_DEBUG 0 @@ -200,7 +201,7 @@ #define RB11_EMSLEN 0xe0 /* EMS memory chunk size */ #define RB11_EMSLEN_SH 5 -typedef struct { +typedef struct emspage_t { int8_t enabled; /* 1=ENABLED */ char pad; uint16_t page; /* selected page in EMS block */ @@ -209,18 +210,18 @@ typedef struct { mem_mapping_t mapping; /* mapping entry for page */ } emspage_t; -typedef struct { +typedef struct neat_t { uint8_t regs[128]; /* all the CS8221 registers */ uint8_t indx; /* programmed index into registers */ char pad; - uint16_t ems_base, /* configured base address */ - ems_oldbase; - uint32_t ems_frame, /* configured frame address */ - ems_oldframe; - uint16_t ems_size, /* EMS size in KB */ - ems_pages; /* EMS size in pages */ + uint16_t ems_base; /* configured base address */ + uint16_t ems_oldbase; + uint32_t ems_frame; /* configured frame address */ + uint32_t ems_oldframe; + uint16_t ems_size; /* EMS size in KB */ + uint16_t ems_pages; /* EMS size in pages */ emspage_t ems[EMS_MAXPAGE]; /* EMS page registers */ } neat_t; @@ -250,9 +251,9 @@ ems_readb(uint32_t addr, void *priv) uint8_t ret = 0xff; /* Grab the data. */ - ret = *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); - return (ret); + return ret; } /* Read one word from paged RAM. */ @@ -263,9 +264,9 @@ ems_readw(uint32_t addr, void *priv) uint16_t ret = 0xffff; /* Grab the data. */ - ret = *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); - return (ret); + return ret; } /* Write one byte to paged RAM. */ @@ -275,7 +276,7 @@ ems_writeb(uint32_t addr, uint8_t val, void *priv) neat_t *dev = (neat_t *) priv; /* Write the data. */ - *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Write one word to paged RAM. */ @@ -285,7 +286,7 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) neat_t *dev = (neat_t *) priv; /* Write the data. */ - *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Re-calculate the active-page physical address. */ @@ -340,15 +341,17 @@ ems_write(uint16_t port, uint8_t val, void *priv) ems->page |= (val & 0x7f); /* add new bits */ ems_recalc(dev, ems); break; + default: + break; } } static uint8_t ems_read(uint16_t port, void *priv) { - neat_t *dev = (neat_t *) priv; - uint8_t ret = 0xff; - int vpage; + const neat_t *dev = (neat_t *) priv; + uint8_t ret = 0xff; + int vpage; /* Get the viewport page number. */ vpage = (port / EMS_PGSIZE); @@ -359,25 +362,27 @@ ems_read(uint16_t port, void *priv) if (dev->ems[vpage].enabled) ret |= 0x80; break; + default: + break; } #if NEAT_DEBUG > 1 neat_log("NEAT: ems_read(%04x) = %02x\n", port, ret); #endif - return (ret); + return ret; } /* Initialize the EMS module. */ static void ems_init(neat_t *dev, int en) { - int i; + uint8_t j; /* Remove if needed. */ if (!en) { if (dev->ems_base > 0) - for (i = 0; i < EMS_MAXPAGE; i++) { + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { /* Disable for now. */ mem_mapping_disable(&dev->ems[i].mapping); @@ -394,19 +399,19 @@ ems_init(neat_t *dev, int en) } /* Get configured I/O address. */ - i = (dev->regs[REG_RB9] & RB9_BASE) >> RB9_BASE_SH; - dev->ems_base = 0x0208 + (0x10 * i); + j = (dev->regs[REG_RB9] & RB9_BASE) >> RB9_BASE_SH; + dev->ems_base = 0x0208 + (0x10 * j); /* Get configured frame address. */ - i = (dev->regs[REG_RB9] & RB9_FRAME) >> RB9_FRAME_SH; - dev->ems_frame = 0xC0000 + (EMS_PGSIZE * i); + j = (dev->regs[REG_RB9] & RB9_FRAME) >> RB9_FRAME_SH; + dev->ems_frame = 0xC0000 + (EMS_PGSIZE * j); /* * For each supported page (we can have a maximum of 4), * create, initialize and disable the mappings, and set * up the I/O control handler. */ - for (i = 0; i < EMS_MAXPAGE; i++) { + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { /* Create and initialize a page mapping. */ mem_mapping_add(&dev->ems[i].mapping, dev->ems_frame + (EMS_PGSIZE * i), EMS_PGSIZE, @@ -435,9 +440,10 @@ ems_init(neat_t *dev, int en) static void neat_write(uint16_t port, uint8_t val, void *priv) { - neat_t *dev = (neat_t *) priv; - uint8_t xval, *reg; - int i; + neat_t *dev = (neat_t *) priv; + uint8_t xval; + uint8_t *reg; + int i; #if NEAT_DEBUG > 2 neat_log("NEAT: write(%04x, %02x)\n", port, val); @@ -607,6 +613,8 @@ neat_write(uint16_t port, uint8_t val, void *priv) case 7: /* 7 MB */ dev->ems_size = i << 10; break; + default: + break; } dev->ems_pages = (dev->ems_size << 10) / EMS_PGSIZE; if (dev->regs[REG_RB7] & RB7_EMSEN) { @@ -621,14 +629,16 @@ neat_write(uint16_t port, uint8_t val, void *priv) break; } break; + default: + break; } } static uint8_t neat_read(uint16_t port, void *priv) { - neat_t *dev = (neat_t *) priv; - uint8_t ret = 0xff; + const neat_t *dev = (neat_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x22: @@ -647,7 +657,7 @@ neat_read(uint16_t port, void *priv) neat_log("NEAT: read(%04x) = %02x\n", port, ret); #endif - return (ret); + return ret; } static void @@ -659,17 +669,17 @@ neat_close(void *priv) } static void * -neat_init(const device_t *info) +neat_init(UNUSED(const device_t *info)) { neat_t *dev; - int i; + uint8_t dram_mode = 0; /* Create an instance. */ dev = (neat_t *) malloc(sizeof(neat_t)); memset(dev, 0x00, sizeof(neat_t)); /* Initialize some of the registers to specific defaults. */ - for (i = REG_RA0; i <= REG_RB11; i++) { + for (uint8_t i = REG_RA0; i <= REG_RB11; i++) { dev->indx = i; neat_write(0x0023, 0x00, dev); } @@ -681,7 +691,6 @@ neat_init(const device_t *info) * TODO: We might also want to set 'valid' waitstate * bits, based on our cpu speed. */ - i = 0; switch (mem_size) { case 512: /* 512KB */ /* 256K, 0, 0, 0 */ @@ -689,7 +698,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_256K << RTYPE_SH); /* 256K */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_NONE << RTYPE_SH); /* NONE */ - i = 2; + dram_mode = 2; break; case 640: /* 640KB */ @@ -698,7 +707,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_MIXED << RTYPE_SH); /* mixed */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_NONE << RTYPE_SH); /* NONE */ - i = 4; + dram_mode = 4; break; case 1024: /* 1MB */ @@ -707,7 +716,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_256K << RTYPE_SH); /* 256K */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_NONE << RTYPE_SH); /* NONE */ - i = 5; + dram_mode = 5; break; case 1536: /* 1.5MB */ @@ -716,7 +725,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_256K << RTYPE_SH); /* 256K */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_256K << RTYPE_SH); /* 256K */ - i = 7; + dram_mode = 7; break; case 1664: /* 1.64MB */ @@ -725,7 +734,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_MIXED << RTYPE_SH); /* mixed */ dev->regs[REG_RB8] |= RB8_BANKS; /* two banks */ dev->regs[REG_RB8] |= (RTYPE_256K << RTYPE_SH); /* 256K */ - i = 10; + dram_mode = 10; break; case 2048: /* 2MB */ @@ -736,14 +745,14 @@ neat_init(const device_t *info) dev->regs[REG_RB8] |= RB8_BANKS; /* two banks */ dev->regs[REG_RB8] |= (RTYPE_256K << RTYPE_SH); /* 256K */ dev->regs[REG_RB8] |= RB8_4WAY; /* 4way intl */ - i = 11; + dram_mode = 11; #else /* 1M, 0, 0, 0 */ dev->regs[REG_RB6] &= ~RB6_BANKS; /* one bank */ dev->regs[REG_RB6] |= (RTYPE_1M << RTYPE_SH); /* 1M */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_NONE << RTYPE_SH); /* NONE */ - i = 3; + dram_mode = 3; #endif break; @@ -753,7 +762,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_256K << RTYPE_SH); /* 256K */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_1M << RTYPE_SH); /* 1M */ - i = 8; + dram_mode = 8; break; case 4096: /* 4MB */ @@ -762,7 +771,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_1M << RTYPE_SH); /* 1M */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_NONE << RTYPE_SH); /* NONE */ - i = 6; + dram_mode = 6; break; case 4224: /* 4.64MB */ @@ -771,7 +780,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_MIXED << RTYPE_SH); /* mixed */ dev->regs[REG_RB8] |= RB8_BANKS; /* two banks */ dev->regs[REG_RB8] |= (RTYPE_1M << RTYPE_SH); /* 1M */ - i = 12; + dram_mode = 12; break; case 5120: /* 5MB */ @@ -780,7 +789,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_256K << RTYPE_SH); /* 256K */ dev->regs[REG_RB8] |= RB8_BANKS; /* two banks */ dev->regs[REG_RB8] |= (RTYPE_1M << RTYPE_SH); /* 1M */ - i = 13; + dram_mode = 13; break; case 6144: /* 6MB */ @@ -789,7 +798,7 @@ neat_init(const device_t *info) dev->regs[REG_RB6] |= (RTYPE_1M << RTYPE_SH); /* 1M */ dev->regs[REG_RB8] &= ~RB8_BANKS; /* one bank */ dev->regs[REG_RB8] |= (RTYPE_1M << RTYPE_SH); /* 1M */ - i = 9; + dram_mode = 9; break; case 8192: /* 8MB */ @@ -799,13 +808,13 @@ neat_init(const device_t *info) dev->regs[REG_RB8] |= RB8_BANKS; /* two banks */ dev->regs[REG_RB8] |= (RTYPE_1M << RTYPE_SH); /* 1M */ dev->regs[REG_RB8] |= RB8_4WAY; /* 4way intl */ - i = 14; + dram_mode = 14; break; default: neat_log("NEAT: **INVALID DRAM SIZE %iKB !**\n", mem_size); } - if (i > 0) { + if (dram_mode > 0) { neat_log("NEAT: using DRAM mode #%i (mem=%iKB)\n", i, mem_size); } diff --git a/src/chipset/olivetti_eva.c b/src/chipset/olivetti_eva.c index ce9ba9a1f..2f43a01f1 100644 --- a/src/chipset/olivetti_eva.c +++ b/src/chipset/olivetti_eva.c @@ -32,9 +32,9 @@ #include <86box/chipset.h> #include <86box/video.h> #include <86box/mem.h> +#include <86box/plat_unused.h> -typedef struct -{ +typedef struct olivetti_eva_t { uint8_t reg_065; uint8_t reg_067; uint8_t reg_069; @@ -77,20 +77,24 @@ olivetti_eva_write(uint16_t addr, uint8_t val, void *priv) * Unfortunately, if triggered, the BIOS remapping function fails causing * a fatal error. Therefore, this code section is currently commented. */ - // if (val & 1){ - // /* - // * Set the register to 7 or above for the BIOS to trigger the - // * memory remapping function if shadowing is active. - // */ - // dev->reg_069 = 0x7; - // } - // if (val & 8) { - // /* - // * Activate shadowing for region e0000-fffff - // */ - // mem_remap_top(256); - // mem_set_mem_state_both(0xa0000, 0x60000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - // } +#if 0 + if (val & 1) { + /* + * Set the register to 7 or above for the BIOS to trigger the + * memory remapping function if shadowing is active. + */ + dev->reg_069 = 0x7; + } + if (val & 8) { + /* + * Activate shadowing for region e0000-fffff + */ + mem_remap_top(256); + mem_set_mem_state_both(0xa0000, 0x60000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } +#endif + break; + default: break; } } @@ -111,6 +115,8 @@ olivetti_eva_read(uint16_t addr, void *priv) case 0x069: ret = dev->reg_069; break; + default: + break; } olivetti_eva_log("Olivetti EVA Gate Array: Read %02x at %02x\n", ret, addr); return ret; @@ -125,7 +131,7 @@ olivetti_eva_close(void *priv) } static void * -olivetti_eva_init(const device_t *info) +olivetti_eva_init(UNUSED(const device_t *info)) { olivetti_eva_t *dev = (olivetti_eva_t *) malloc(sizeof(olivetti_eva_t)); memset(dev, 0, sizeof(olivetti_eva_t)); diff --git a/src/chipset/opti283.c b/src/chipset/opti283.c index b3b51d8fa..865ec6ff5 100644 --- a/src/chipset/opti283.c +++ b/src/chipset/opti283.c @@ -29,6 +29,8 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> #ifdef ENABLE_OPTI283_LOG @@ -49,15 +51,15 @@ opti283_log(const char *fmt, ...) # define opti283_log(fmt, ...) #endif -typedef struct -{ - uint32_t phys, virt; +typedef struct mem_remapping_t { + uint32_t phys; + uint32_t virt; } mem_remapping_t; -typedef struct -{ - uint8_t index, shadow_high, - regs[256]; +typedef struct opti283_t { + uint8_t index; + uint8_t shadow_high; + uint8_t regs[256]; mem_remapping_t mem_remappings[2]; mem_mapping_t mem_mappings[2]; } opti283_t; @@ -65,7 +67,7 @@ typedef struct static uint8_t opti283_read_remapped_ram(uint32_t addr, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; return mem_read_ram((addr - dev->virt) + dev->phys, priv); } @@ -73,7 +75,7 @@ opti283_read_remapped_ram(uint32_t addr, void *priv) static uint16_t opti283_read_remapped_ramw(uint32_t addr, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; return mem_read_ramw((addr - dev->virt) + dev->phys, priv); } @@ -81,7 +83,7 @@ opti283_read_remapped_ramw(uint32_t addr, void *priv) static uint32_t opti283_read_remapped_raml(uint32_t addr, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; return mem_read_raml((addr - dev->virt) + dev->phys, priv); } @@ -89,7 +91,7 @@ opti283_read_remapped_raml(uint32_t addr, void *priv) static void opti283_write_remapped_ram(uint32_t addr, uint8_t val, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; mem_write_ram((addr - dev->virt) + dev->phys, val, priv); } @@ -97,7 +99,7 @@ opti283_write_remapped_ram(uint32_t addr, uint8_t val, void *priv) static void opti283_write_remapped_ramw(uint32_t addr, uint16_t val, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; mem_write_ramw((addr - dev->virt) + dev->phys, val, priv); } @@ -105,7 +107,7 @@ opti283_write_remapped_ramw(uint32_t addr, uint16_t val, void *priv) static void opti283_write_remapped_raml(uint32_t addr, uint32_t val, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; mem_write_raml((addr - dev->virt) + dev->phys, val, priv); } @@ -113,10 +115,12 @@ opti283_write_remapped_raml(uint32_t addr, uint32_t val, void *priv) static void opti283_shadow_recalc(opti283_t *dev) { - uint32_t i, base; + uint32_t base; uint32_t rbase; - uint8_t sh_enable, sh_mode; - uint8_t rom, sh_copy; + uint8_t sh_enable; + uint8_t sh_mode; + uint8_t rom; + uint8_t sh_copy; shadowbios = shadowbios_write = 0; dev->shadow_high = 0; @@ -143,7 +147,7 @@ opti283_shadow_recalc(opti283_t *dev) } sh_copy = dev->regs[0x11] & 0x08; - for (i = 0; i < 12; i++) { + for (uint8_t i = 0; i < 12; i++) { base = 0xc0000 + (i << 14); if (i >= 4) sh_enable = dev->regs[0x12] & (1 << (i - 4)); @@ -225,23 +229,31 @@ opti283_write(uint16_t addr, uint8_t val, void *priv) case 0x14: reset_on_hlt = !!(val & 0x40); - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: case 0x12: case 0x13: dev->regs[dev->index] = val; opti283_shadow_recalc(dev); break; + + default: + break; } break; + + default: + break; } } static uint8_t opti283_read(uint16_t addr, void *priv) { - opti283_t *dev = (opti283_t *) priv; - uint8_t ret = 0xff; + const opti283_t *dev = (opti283_t *) priv; + uint8_t ret = 0xff; if (addr == 0x24) ret = dev->regs[dev->index]; @@ -258,7 +270,7 @@ opti283_close(void *priv) } static void * -opti283_init(const device_t *info) +opti283_init(UNUSED(const device_t *info)) { opti283_t *dev = (opti283_t *) malloc(sizeof(opti283_t)); memset(dev, 0x00, sizeof(opti283_t)); diff --git a/src/chipset/opti291.c b/src/chipset/opti291.c index b15b71260..6d2256974 100644 --- a/src/chipset/opti291.c +++ b/src/chipset/opti291.c @@ -28,6 +28,7 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/chipset.h> @@ -49,9 +50,9 @@ opti291_log(const char *fmt, ...) # define opti291_log(fmt, ...) #endif -typedef struct -{ - uint8_t index, regs[256]; +typedef struct opti291_t { + uint8_t index; + uint8_t regs[256]; port_92_t *port_92; } opti291_t; @@ -107,15 +108,21 @@ opti291_write(uint16_t addr, uint8_t val, void *priv) case 0x2c: dev->regs[dev->index] = val; break; + + default: + break; } break; + + default: + break; } } static uint8_t opti291_read(uint16_t addr, void *priv) { - opti291_t *dev = (opti291_t *) priv; + const opti291_t *dev = (opti291_t *) priv; return (addr == 0x24) ? dev->regs[dev->index] : 0xff; } @@ -129,7 +136,7 @@ opti291_close(void *priv) } static void * -opti291_init(const device_t *info) +opti291_init(UNUSED(const device_t *info)) { opti291_t *dev = (opti291_t *) malloc(sizeof(opti291_t)); memset(dev, 0, sizeof(opti291_t)); diff --git a/src/chipset/opti391.c b/src/chipset/opti391.c index 4b9b8faff..03cbb2ea7 100644 --- a/src/chipset/opti391.c +++ b/src/chipset/opti391.c @@ -27,6 +27,7 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> #ifdef ENABLE_OPTI391_LOG @@ -47,22 +48,24 @@ opti391_log(const char *fmt, ...) # define opti391_log(fmt, ...) #endif -typedef struct -{ - uint32_t phys, virt; +typedef struct mem_remapping_t { + uint32_t phys; + uint32_t virt; } mem_remapping_t; -typedef struct -{ - uint8_t index, regs[256]; +typedef struct opti391_t { + uint8_t index; + uint8_t regs[256]; } opti391_t; static void opti391_shadow_recalc(opti391_t *dev) { - uint32_t i, base; - uint8_t sh_enable, sh_master; - uint8_t sh_wp, sh_write_internal; + uint32_t base; + uint8_t sh_enable; + uint8_t sh_master; + uint8_t sh_wp; + uint8_t sh_write_internal; shadowbios = shadowbios_write = 0; @@ -75,7 +78,7 @@ opti391_shadow_recalc(opti391_t *dev) sh_write_internal = (dev->regs[0x26] & 0x40); /* D0000-EFFFF */ - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xd0000 + (i << 14); if (base >= 0xe0000) { sh_master = (dev->regs[0x22] & 0x40); @@ -105,7 +108,7 @@ opti391_shadow_recalc(opti391_t *dev) /* C0000-CFFFF */ sh_master = !(dev->regs[0x26] & 0x10); sh_wp = (dev->regs[0x26] & 0x20); - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xc0000 + (i << 14); sh_enable = dev->regs[0x26] & (1 << i); @@ -161,16 +164,22 @@ opti391_write(uint16_t addr, uint8_t val, void *priv) dev->regs[dev->index] = val; opti391_shadow_recalc(dev); break; + + default: + break; } break; + + default: + break; } } static uint8_t opti391_read(uint16_t addr, void *priv) { - opti391_t *dev = (opti391_t *) priv; - uint8_t ret = 0xff; + const opti391_t *dev = (opti391_t *) priv; + uint8_t ret = 0xff; if (addr == 0x24) ret = dev->regs[dev->index]; @@ -187,7 +196,7 @@ opti391_close(void *priv) } static void * -opti391_init(const device_t *info) +opti391_init(UNUSED(const device_t *info)) { opti391_t *dev = (opti391_t *) malloc(sizeof(opti391_t)); memset(dev, 0x00, sizeof(opti391_t)); diff --git a/src/chipset/opti495.c b/src/chipset/opti495.c index 5eb5782e0..13bc2a124 100644 --- a/src/chipset/opti495.c +++ b/src/chipset/opti495.c @@ -31,11 +31,10 @@ #include <86box/port_92.h> #include <86box/chipset.h> -typedef struct -{ - uint8_t idx, - regs[256], - scratch[2]; +typedef struct opti495_t { + uint8_t idx; + uint8_t regs[256]; + uint8_t scratch[2]; } opti495_t; #ifdef ENABLE_OPTI495_LOG @@ -60,7 +59,7 @@ static void opti495_recalc(opti495_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; @@ -77,7 +76,7 @@ opti495_recalc(opti495_t *dev) mem_set_mem_state_both(0xf0000, 0x10000, shflags); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xd0000 + (i << 14); if ((dev->regs[0x22] & ((base >= 0xe0000) ? 0x20 : 0x40)) && (dev->regs[0x23] & (1 << i))) { @@ -94,7 +93,7 @@ opti495_recalc(opti495_t *dev) mem_set_mem_state_both(base, 0x4000, shflags); } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xc0000 + (i << 14); if ((dev->regs[0x26] & 0x10) && (dev->regs[0x26] & (1 << i))) { @@ -140,6 +139,8 @@ opti495_write(uint16_t addr, uint8_t val, void *priv) case 0x26: opti495_recalc(dev); break; + default: + break; } } break; @@ -148,14 +149,16 @@ opti495_write(uint16_t addr, uint8_t val, void *priv) case 0xe2: dev->scratch[~addr & 0x01] = val; break; + default: + break; } } static uint8_t opti495_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - opti495_t *dev = (opti495_t *) priv; + uint8_t ret = 0xff; + const opti495_t *dev = (opti495_t *) priv; switch (addr) { case 0x22: @@ -171,6 +174,8 @@ opti495_read(uint16_t addr, void *priv) case 0xe2: ret = dev->scratch[~addr & 0x01]; break; + default: + break; } return ret; diff --git a/src/chipset/opti499.c b/src/chipset/opti499.c index c033cd4f5..acac4d87b 100644 --- a/src/chipset/opti499.c +++ b/src/chipset/opti499.c @@ -29,12 +29,13 @@ #include <86box/device.h> #include <86box/mem.h> #include <86box/port_92.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> -typedef struct -{ +typedef struct opti499_t { uint8_t idx, - regs[256], scratch[2]; + uint8_t regs[256]; + uint8_t scratch[2]; } opti499_t; #ifdef ENABLE_OPTI499_LOG @@ -59,7 +60,7 @@ static void opti499_recalc(opti499_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; @@ -76,7 +77,7 @@ opti499_recalc(opti499_t *dev) mem_set_mem_state_both(0xf0000, 0x10000, shflags); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xd0000 + (i << 14); if ((dev->regs[0x22] & ((base >= 0xe0000) ? 0x20 : 0x40)) && (dev->regs[0x23] & (1 << i))) { @@ -92,7 +93,7 @@ opti499_recalc(opti499_t *dev) mem_set_mem_state_both(base, 0x4000, shflags); } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xc0000 + (i << 14); if ((dev->regs[0x26] & 0x10) && (dev->regs[0x26] & (1 << i))) { @@ -153,6 +154,9 @@ opti499_write(uint16_t addr, uint8_t val, void *priv) case 0x2d: opti499_recalc(dev); break; + + default: + break; } } break; @@ -161,6 +165,9 @@ opti499_write(uint16_t addr, uint8_t val, void *priv) case 0xe2: dev->scratch[~addr & 0x01] = val; break; + + default: + break; } } @@ -187,6 +194,9 @@ opti499_read(uint16_t addr, void *priv) case 0xe2: ret = dev->scratch[~addr & 0x01]; break; + + default: + break; } return ret; @@ -229,7 +239,7 @@ opti499_close(void *priv) } static void * -opti499_init(const device_t *info) +opti499_init(UNUSED(const device_t *info)) { opti499_t *dev = (opti499_t *) malloc(sizeof(opti499_t)); memset(dev, 0, sizeof(opti499_t)); diff --git a/src/chipset/opti5x7.c b/src/chipset/opti5x7.c index fdcb4fc3e..64adacde4 100644 --- a/src/chipset/opti5x7.c +++ b/src/chipset/opti5x7.c @@ -32,10 +32,10 @@ #include <86box/port_92.h> #include <86box/chipset.h> -typedef struct -{ - uint8_t idx, is_pci, - regs[16]; +typedef struct opti5x7_t { + uint8_t idx; + uint8_t is_pci; + uint8_t regs[16]; } opti5x7_t; #ifdef ENABLE_OPTI5X7_LOG @@ -84,7 +84,7 @@ opti5x7_shadow_map(int cur_reg, opti5x7_t *dev) mem_set_mem_state_both(0xf0000, 0x10000, ((dev->regs[6] & 4) ? MEM_READ_INTERNAL : MEM_READ_EXTANY) | ((dev->regs[6] & 8) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY)); } } else { - for (int i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { if (dev->is_pci) mem_set_mem_state_cpu_both(0xc0000 + ((cur_reg & 1) << 16) + (i << 14), 0x4000, ((dev->regs[cur_reg] & (1 << (2 * i))) ? MEM_READ_INTERNAL : MEM_READ_EXTANY) | ((dev->regs[cur_reg] & (2 << (2 * i))) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY)); else @@ -143,16 +143,20 @@ opti5x7_write(uint16_t addr, uint8_t val, void *priv) case 0x11: /* Master Cycle Control Register */ dev->regs[dev->idx] = val; break; + default: + break; } opti5x7_log("OPTi 5x7: dev->regs[%02x] = %02x\n", dev->idx, dev->regs[dev->idx]); break; + default: + break; } } static uint8_t opti5x7_read(uint16_t addr, void *priv) { - opti5x7_t *dev = (opti5x7_t *) priv; + const opti5x7_t *dev = (opti5x7_t *) priv; return (addr == 0x24) ? dev->regs[dev->idx] : 0xff; } diff --git a/src/chipset/opti822.c b/src/chipset/opti822.c index 7db233935..73548adab 100644 --- a/src/chipset/opti822.c +++ b/src/chipset/opti822.c @@ -33,6 +33,7 @@ #include <86box/timer.h> #include <86box/pic.h> #include <86box/pit.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/hdc_ide.h> #include <86box/hdc.h> @@ -40,10 +41,9 @@ #include <86box/chipset.h> #include <86box/spd.h> -typedef struct -{ - uint8_t irq_convert, - pci_regs[256]; +typedef struct opti822_t { + uint8_t irq_convert; + uint8_t pci_regs[256]; } opti822_t; // #define ENABLE_OPTI822_LOG 1 @@ -71,11 +71,13 @@ opti822_log(const char *fmt, ...) static void opti822_recalc(opti822_t *dev) { - int i, reg, bit_r, bit_w; + int reg; + int bit_r; + int bit_w; int state; uint32_t base; - for (i = 0; i < 12; i++) { + for (uint8_t i = 0; i < 12; i++) { base = 0x000c0000 + (i << 14); reg = 0x44 + ((i >> 2) ^ 3); bit_w = (i & 3); @@ -99,15 +101,18 @@ static void opti822_update_irqs(opti822_t *dev, int set) { uint8_t val; - int i, reg; - int shift, irq; + int reg; + int shift; + int irq; int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; pic_t *temp_pic; - // dev->irq_convert = (dev->pci_regs[0x53] & 0x08); +#if 0 + dev->irq_convert = (dev->pci_regs[0x53] & 0x08); +#endif dev->irq_convert = 1; - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { reg = 0x88 + (i >> 1); shift = (i & 1) << 2; val = (dev->pci_regs[reg] >> shift) & 0x0f; @@ -127,8 +132,10 @@ static void opti822_pci_write(int func, int addr, uint8_t val, void *priv) { opti822_t *dev = (opti822_t *) priv; - int irq, irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; - int pin, slot; + int irq; + int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; + int pin; + int slot; opti822_log("opti822_write(%02X, %02X, %02X)\n", func, addr, val); @@ -320,14 +327,17 @@ opti822_pci_write(int func, int addr, uint8_t val, void *priv) } opti822_update_irqs(dev, 1); break; + + default: + break; } } static uint8_t opti822_pci_read(int func, int addr, void *priv) { - opti822_t *dev = (opti822_t *) priv; - uint8_t ret; + const opti822_t *dev = (opti822_t *) priv; + uint8_t ret; ret = 0xff; @@ -343,7 +353,6 @@ static void opti822_reset(void *priv) { opti822_t *dev = (opti822_t *) priv; - int i; memset(dev->pci_regs, 0, 256); @@ -366,7 +375,7 @@ opti822_reset(void *priv) dev->irq_convert = 1 /*0*/; - for (i = 0; i < 16; i++) + for (uint8_t i = 0; i < 16; i++) pci_set_irq_routing(PCI_INTA + i, PCI_IRQ_DISABLED); } @@ -379,7 +388,7 @@ opti822_close(void *p) } static void * -opti822_init(const device_t *info) +opti822_init(UNUSED(const device_t *info)) { opti822_t *dev = (opti822_t *) malloc(sizeof(opti822_t)); memset(dev, 0, sizeof(opti822_t)); diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index 51ffc7430..8bc93702f 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -32,12 +32,12 @@ #include <86box/port_92.h> #include <86box/chipset.h> -typedef struct -{ - uint8_t idx, forced_green, - is_pci, - regs[256], - scratch[2]; +typedef struct opti895_t { + uint8_t idx; + uint8_t forced_green; + uint8_t is_pci; + uint8_t regs[256]; + uint8_t scratch[2]; smram_t *smram; } opti895_t; @@ -64,7 +64,7 @@ static void opti895_recalc(opti895_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; @@ -84,7 +84,7 @@ opti895_recalc(opti895_t *dev) else mem_set_mem_state_both(0xf0000, 0x10000, shflags); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xd0000 + (i << 14); if (dev->regs[0x23] & (1 << i)) { @@ -108,7 +108,7 @@ opti895_recalc(opti895_t *dev) mem_set_mem_state_both(base, 0x4000, shflags); } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xc0000 + (i << 14); if (dev->regs[0x26] & (1 << i)) { @@ -184,6 +184,9 @@ opti895_write(uint16_t addr, uint8_t val, void *priv) break; } break; + + default: + break; } } break; @@ -192,14 +195,17 @@ opti895_write(uint16_t addr, uint8_t val, void *priv) case 0xe2: dev->scratch[addr - 0xe1] = val; break; + + default: + break; } } static uint8_t opti895_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - opti895_t *dev = (opti895_t *) priv; + uint8_t ret = 0xff; + const opti895_t *dev = (opti895_t *) priv; switch (addr) { case 0x23: @@ -217,6 +223,9 @@ opti895_read(uint16_t addr, void *priv) case 0xe2: ret = dev->scratch[addr - 0xe1]; break; + + default: + break; } return ret; diff --git a/src/chipset/scamp.c b/src/chipset/scamp.c index 6e61db681..122318862 100644 --- a/src/chipset/scamp.c +++ b/src/chipset/scamp.c @@ -31,6 +31,7 @@ #include <86box/io.h> #include <86box/mem.h> #include <86box/nmi.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/chipset.h> @@ -66,20 +67,21 @@ enum { BANK_4M_INTERLEAVED }; -typedef struct { +typedef struct ram_struct_t { void *parent; int bank; } ram_struct_t; -typedef struct { +typedef struct ems_struct_t { void *parent; int segment; } ems_struct_t; -typedef struct { +typedef struct scamp_t { int cfg_index; uint8_t cfg_regs[256]; - int cfg_enable, ram_config; + int cfg_enable; + int ram_config; int ems_index; int ems_autoinc; @@ -91,21 +93,23 @@ typedef struct { ram_struct_t ram_struct[2]; ems_struct_t ems_struct[20]; - uint32_t ram_virt_base[2], ram_phys_base[2]; + uint32_t ram_virt_base[2]; + uint32_t ram_phys_base[2]; uint32_t ram_mask[2]; - int row_virt_shift[2], row_phys_shift[2]; - int ram_interleaved[2], ibank_shift[2]; + int row_virt_shift[2]; + int row_phys_shift[2]; + int ram_interleaved[2]; + int ibank_shift[2]; port_92_t *port_92; } scamp_t; -static const struct -{ +static const struct { int size_kb; int rammap; int bank[2]; } ram_configs[] = { - {512, 0x0, { BANK_256K, BANK_NONE } }, + { 512, 0x0, { BANK_256K, BANK_NONE } }, { 1024, 0x1, { BANK_256K_INTERLEAVED, BANK_NONE } }, { 1536, 0x2, { BANK_256K_INTERLEAVED, BANK_256K } }, { 2048, 0x3, { BANK_256K_INTERLEAVED, BANK_256K_INTERLEAVED }}, @@ -118,12 +122,11 @@ static const struct { 16384, 0x9, { BANK_4M_INTERLEAVED, BANK_NONE } }, }; -static const struct -{ +static const struct { int bank[2]; int remapped; } rammap[16] = { - {{ BANK_256K, BANK_NONE }, 0}, + { { BANK_256K, BANK_NONE }, 0}, { { BANK_256K_INTERLEAVED, BANK_NONE }, 0}, { { BANK_256K_INTERLEAVED, BANK_256K }, 0}, { { BANK_256K_INTERLEAVED, BANK_256K_INTERLEAVED }, 0}, @@ -149,10 +152,12 @@ static const struct static uint8_t ram_mirrored_256k_in_4mi_read(uint32_t addr, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -178,10 +183,12 @@ ram_mirrored_256k_in_4mi_read(uint32_t addr, void *priv) static void ram_mirrored_256k_in_4mi_write(uint32_t addr, uint8_t val, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -209,10 +216,12 @@ ram_mirrored_256k_in_4mi_write(uint32_t addr, uint8_t val, void *priv) static uint8_t ram_mirrored_interleaved_read(uint32_t addr, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -238,10 +247,12 @@ ram_mirrored_interleaved_read(uint32_t addr, void *priv) static void ram_mirrored_interleaved_write(uint32_t addr, uint8_t val, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -267,10 +278,12 @@ ram_mirrored_interleaved_write(uint32_t addr, uint8_t val, void *priv) static uint8_t ram_mirrored_read(uint32_t addr, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -284,10 +297,12 @@ ram_mirrored_read(uint32_t addr, void *priv) static void ram_mirrored_write(uint32_t addr, uint8_t val, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -302,15 +317,16 @@ static void recalc_mappings(void *priv) { scamp_t *dev = (scamp_t *) priv; - int c; - uint32_t virt_base = 0, old_virt_base; + uint32_t virt_base = 0; + uint32_t old_virt_base; uint8_t cur_rammap = dev->cfg_regs[CFG_RAMMAP] & 0xf; - int bank_nr = 0, phys_bank; + int bank_nr = 0; + int phys_bank; mem_set_mem_state_both((1 << 20), (16256 - 1024) * 1024, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); mem_set_mem_state(0xfe0000, 0x20000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - for (c = 0; c < 2; c++) + for (uint8_t c = 0; c < 2; c++) mem_mapping_disable(&dev->ram_mapping[c]); /* Once the BIOS programs the correct DRAM configuration, switch to regular @@ -411,6 +427,9 @@ recalc_mappings(void *priv) virt_base += (1 << 24); dev->row_virt_shift[bank_nr] = 12; break; + + default: + break; } } else { switch (rammap[cur_rammap].bank[bank_nr]) { @@ -476,6 +495,9 @@ recalc_mappings(void *priv) virt_base += (1 << 24); dev->row_virt_shift[bank_nr] = 12; break; + + default: + break; } } switch (rammap[cur_rammap].bank[bank_nr]) { @@ -521,6 +543,9 @@ recalc_mappings(void *priv) ram_mirrored_interleaved_write, NULL, NULL); } break; + + default: + break; } } } @@ -549,9 +574,9 @@ recalc_sltptr(scamp_t *dev) static uint8_t scamp_ems_read(uint32_t addr, void *priv) { - ems_struct_t *ems = (ems_struct_t *) priv; - scamp_t *dev = ems->parent; - int segment = ems->segment; + const ems_struct_t *ems = (ems_struct_t *) priv; + const scamp_t *dev = ems->parent; + int segment = ems->segment; addr = (addr & 0x3fff) | dev->mappings[segment]; return ram[addr]; @@ -560,9 +585,9 @@ scamp_ems_read(uint32_t addr, void *priv) static void scamp_ems_write(uint32_t addr, uint8_t val, void *priv) { - ems_struct_t *ems = (ems_struct_t *) priv; - scamp_t *dev = ems->parent; - int segment = ems->segment; + const ems_struct_t *ems = (ems_struct_t *) priv; + const scamp_t *dev = ems->parent; + int segment = ems->segment; addr = (addr & 0x3fff) | dev->mappings[segment]; ram[addr] = val; @@ -571,7 +596,6 @@ scamp_ems_write(uint32_t addr, uint8_t val, void *priv) static void recalc_ems(scamp_t *dev) { - int segment; const uint32_t ems_base[12] = { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, @@ -580,7 +604,7 @@ recalc_ems(scamp_t *dev) uint32_t new_mappings[20]; uint16_t ems_enable; - for (segment = 0; segment < 20; segment++) + for (int segment = 0; segment < 20; segment++) new_mappings[segment] = 0xa0000 + segment * 0x4000; if (dev->cfg_regs[CFG_EMSEN1] & EMSEN1_EMSENAB) @@ -588,7 +612,7 @@ recalc_ems(scamp_t *dev) else ems_enable = 0; - for (segment = 0; segment < 12; segment++) { + for (int segment = 0; segment < 12; segment++) { if (ems_enable & (1 << segment)) { uint32_t phys_addr = dev->ems[segment] << 14; @@ -600,7 +624,7 @@ recalc_ems(scamp_t *dev) } } - for (segment = 0; segment < 20; segment++) { + for (int segment = 0; segment < 20; segment++) { if (new_mappings[segment] != dev->mappings[segment]) { dev->mappings[segment] = new_mappings[segment]; if (new_mappings[segment] < (mem_size * 1024)) { @@ -631,6 +655,8 @@ shadow_control(uint32_t addr, uint32_t size, int state, int ems_enable) case 3: mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); break; + default: + break; } flushmmucache_nopc(); @@ -743,6 +769,8 @@ scamp_write(uint16_t addr, uint8_t val, void *priv) case CFG_FEAXS: shadow_recalc(dev); break; + default: + break; } } break; @@ -754,6 +782,9 @@ scamp_write(uint16_t addr, uint8_t val, void *priv) mem_a20_recalc(); } break; + + default: + break; } } @@ -796,6 +827,9 @@ scamp_read(uint16_t addr, void *priv) softresetx86(); cpu_set_edx(); break; + + default: + break; } return ret; @@ -810,10 +844,9 @@ scamp_close(void *priv) } static void * -scamp_init(const device_t *info) +scamp_init(UNUSED(const device_t *info)) { uint32_t addr; - int c; scamp_t *dev = (scamp_t *) malloc(sizeof(scamp_t)); memset(dev, 0x00, sizeof(scamp_t)); @@ -834,7 +867,7 @@ scamp_init(const device_t *info) dev->ram_config = 0; /* Find best fit configuration for the requested memory size */ - for (c = 0; c < NR_ELEMS(ram_configs); c++) { + for (uint8_t c = 0; c < NR_ELEMS(ram_configs); c++) { if (mem_size < ram_configs[c].size_kb) break; @@ -850,7 +883,7 @@ scamp_init(const device_t *info) mem_mapping_set_exec(&ram_mid_mapping, ram + 0xf0000); addr = 0; - for (c = 0; c < 2; c++) { + for (uint8_t c = 0; c < 2; c++) { dev->ram_struct[c].parent = dev; dev->ram_struct[c].bank = c; mem_mapping_add(&dev->ram_mapping[c], 0, 0, @@ -911,12 +944,15 @@ scamp_init(const device_t *info) dev->ibank_shift[c] = 23; dev->ram_interleaved[c] = 1; break; + + default: + break; } } mem_set_mem_state(0xfe0000, 0x20000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - for (c = 0; c < 20; c++) { + for (uint8_t c = 0; c < 20; c++) { dev->ems_struct[c].parent = dev; dev->ems_struct[c].segment = c; mem_mapping_add(&dev->ems_mappings[c], diff --git a/src/chipset/scat.c b/src/chipset/scat.c index 2bbac6cc0..aa0c5511a 100644 --- a/src/chipset/scat.c +++ b/src/chipset/scat.c @@ -55,8 +55,9 @@ #define SCATSX_HIGH_PERFORMANCE_REFRESH 0x63 #define SCATSX_CAS_TIMING_FOR_DMA 0x64 -typedef struct { - uint8_t valid, pad; +typedef struct ems_page_t { + uint8_t valid; + uint8_t pad; uint8_t regs_2x8; uint8_t regs_2x9; @@ -75,7 +76,8 @@ typedef struct scat_t { int external_is_RAS; - ems_page_t null_page, page[32]; + ems_page_t null_page; + ems_page_t page[32]; mem_mapping_t low_mapping[32]; mem_mapping_t remap_mapping[6]; @@ -113,13 +115,16 @@ static void scat_out(uint16_t port, uint8_t val, void *priv); static void shadow_state_update(scat_t *dev) { - int i, val; + int val; - uint32_t base, bit, romcs, shflags = 0; + uint32_t base; + uint32_t bit; + uint32_t romcs; + uint32_t shflags = 0; shadowbios = shadowbios_write = 0; - for (i = 0; i < 24; i++) { + for (uint8_t i = 0; i < 24; i++) { if ((dev->regs[SCAT_DRAM_CONFIGURATION] & 0xf) < 4) val = 0; else @@ -150,7 +155,6 @@ static void set_xms_bound(scat_t *dev, uint8_t val) { uint32_t xms_max = ((dev->regs[SCAT_VERSION] & 0xf0) != 0 && ((val & 0x10) != 0)) || (dev->regs[SCAT_VERSION] >= 4) ? 0xfe0000 : 0xfc0000; - int i; switch (val & 0x0f) { case 1: @@ -245,7 +249,7 @@ set_xms_bound(scat_t *dev, uint8_t val) mem_mapping_set_addr(&dev->low_mapping[31], 0xf80000, ((dev->regs[SCAT_VERSION] & 0xf0) != 0 && ((val & 0x10) != 0)) || (dev->regs[SCAT_VERSION] >= 4) ? 0x60000 : 0x40000); if (dev->regs[SCAT_VERSION] & 0xf0) { - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { if (val & 0x10) mem_mapping_disable(&bios_high_mapping); else @@ -258,7 +262,8 @@ static uint32_t get_addr(scat_t *dev, uint32_t addr, ems_page_t *p) { #if 1 - int nbanks_2048k, nbanks_512k; + int nbanks_2048k; + int nbanks_512k; uint32_t addr2; int nbank; #else @@ -882,10 +887,11 @@ get_addr(scat_t *dev, uint32_t addr, ems_page_t *p) static void set_global_EMS_state(scat_t *dev, int state) { - uint32_t base_addr, virt_addr; - int i, conf; + uint32_t base_addr; + uint32_t virt_addr; + int conf; - for (i = ((dev->regs[SCAT_VERSION] & 0xf0) == 0) ? 0 : 24; i < 32; i++) { + for (uint32_t i = ((dev->regs[SCAT_VERSION] & 0xf0) == 0) ? 0 : 24; i < 32; i++) { base_addr = (i + 16) << 14; if (i >= 24) @@ -927,9 +933,8 @@ static void memmap_state_update(scat_t *dev) { uint32_t addr; - int i; - for (i = (((dev->regs[SCAT_VERSION] & 0xf0) == 0) ? 0 : 16); i < 44; i++) { + for (uint8_t i = (((dev->regs[SCAT_VERSION] & 0xf0) == 0) ? 0 : 16); i < 44; i++) { addr = get_addr(dev, 0x40000 + (i << 14), &dev->null_page); mem_mapping_set_exec(&dev->efff_mapping[i], addr < ((uint32_t) mem_size << 10) ? ram + addr : NULL); @@ -943,37 +948,40 @@ memmap_state_update(scat_t *dev) mem_mapping_set_exec(&dev->low_mapping[1], addr < ((uint32_t) mem_size << 10) ? ram + addr : NULL); - for (i = 2; i < 32; i++) { + for (uint8_t i = 2; i < 32; i++) { addr = get_addr(dev, i << 19, &dev->null_page); mem_mapping_set_exec(&dev->low_mapping[i], addr < ((uint32_t) mem_size << 10) ? ram + addr : NULL); } if ((dev->regs[SCAT_VERSION] & 0xf0) == 0) { - for (i = 0; i < max_map[(dev->regs[SCAT_DRAM_CONFIGURATION] & 0x0f) | ((dev->regs[SCAT_EXTENDED_BOUNDARY] & 0x40) >> 2)]; i++) - mem_mapping_enable(&dev->low_mapping[i]); + uint8_t j = 0; - for (; i < 32; i++) - mem_mapping_disable(&dev->low_mapping[i]); + for (j = 0; j < max_map[(dev->regs[SCAT_DRAM_CONFIGURATION] & 0x0f) | ((dev->regs[SCAT_EXTENDED_BOUNDARY] & 0x40) >> 2)]; j++) + mem_mapping_enable(&dev->low_mapping[j]); - for (i = 24; i < 36; i++) { + for (; j < 32; j++) + mem_mapping_disable(&dev->low_mapping[j]); + + for (j = 24; j < 36; j++) { if (((dev->regs[SCAT_DRAM_CONFIGURATION] & 0x0f) | (dev->regs[SCAT_EXTENDED_BOUNDARY] & 0x40)) < 4) - mem_mapping_disable(&dev->efff_mapping[i]); + mem_mapping_disable(&dev->efff_mapping[j]); else - mem_mapping_enable(&dev->efff_mapping[i]); + mem_mapping_enable(&dev->efff_mapping[j]); } } else { - for (i = 0; i < max_map_sx[dev->regs[SCAT_DRAM_CONFIGURATION] & 0x1f]; i++) - mem_mapping_enable(&dev->low_mapping[i]); + uint8_t j = 0; + for (j = 0; j < max_map_sx[dev->regs[SCAT_DRAM_CONFIGURATION] & 0x1f]; j++) + mem_mapping_enable(&dev->low_mapping[j]); - for (; i < 32; i++) - mem_mapping_disable(&dev->low_mapping[i]); + for (; j < 32; j++) + mem_mapping_disable(&dev->low_mapping[j]); - for (i = 24; i < 36; i++) { + for (j = 24; j < 36; j++) { if ((dev->regs[SCAT_DRAM_CONFIGURATION] & 0x1f) < 2 || (dev->regs[SCAT_DRAM_CONFIGURATION] & 0x1f) == 3) - mem_mapping_disable(&dev->efff_mapping[i]); + mem_mapping_disable(&dev->efff_mapping[j]); else - mem_mapping_enable(&dev->efff_mapping[i]); + mem_mapping_enable(&dev->efff_mapping[j]); } } @@ -981,21 +989,21 @@ memmap_state_update(scat_t *dev) if ((((dev->regs[SCAT_VERSION] & 0xf0) == 0) && (dev->regs[SCAT_DRAM_CONFIGURATION] & 0x0f) == 3) || (((dev->regs[SCAT_VERSION] & 0xf0) != 0) && (dev->regs[SCAT_DRAM_CONFIGURATION] & 0x1f) == 3)) { mem_mapping_disable(&dev->low_mapping[2]); - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { addr = get_addr(dev, 0x100000 + (i << 16), &dev->null_page); mem_mapping_set_exec(&dev->remap_mapping[i], addr < ((uint32_t) mem_size << 10) ? ram + addr : NULL); mem_mapping_enable(&dev->remap_mapping[i]); } } else { - for (i = 0; i < 6; i++) + for (uint8_t i = 0; i < 6; i++) mem_mapping_disable(&dev->remap_mapping[i]); if ((((dev->regs[SCAT_VERSION] & 0xf0) == 0) && (dev->regs[SCAT_DRAM_CONFIGURATION] & 0x0f) > 4) || (((dev->regs[SCAT_VERSION] & 0xf0) != 0) && (dev->regs[SCAT_DRAM_CONFIGURATION] & 0x1f) > 3)) mem_mapping_enable(&dev->low_mapping[2]); } } else { - for (i = 0; i < 6; i++) + for (uint8_t i = 0; i < 6; i++) mem_mapping_disable(&dev->remap_mapping[i]); mem_mapping_enable(&dev->low_mapping[2]); @@ -1003,18 +1011,19 @@ memmap_state_update(scat_t *dev) set_global_EMS_state(dev, dev->regs[SCAT_EMS_CONTROL] & 0x80); - flushmmucache_cr3(); + flushmmucache_nopc(); } static void scat_out(uint16_t port, uint8_t val, void *priv) { - scat_t *dev = (scat_t *) priv; - uint8_t reg_valid = 0, - shadow_update = 0, - map_update = 0, - indx; - uint32_t base_addr, virt_addr; + scat_t *dev = (scat_t *) priv; + uint8_t reg_valid = 0; + uint8_t shadow_update = 0; + uint8_t map_update = 0; + uint8_t indx; + uint32_t base_addr; + uint32_t virt_addr; switch (port) { case 0x22: @@ -1186,14 +1195,18 @@ scat_out(uint16_t port, uint8_t val, void *priv) if ((dev->regs[SCAT_EMS_CONTROL] & 0x41) == (0x40 | ((port & 0x10) >> 4))) dev->reg_2xA = ((dev->regs[SCAT_VERSION] & 0xf0) == 0) ? val : val & 0xc3; break; + + default: + break; } } static uint8_t scat_in(uint16_t port, void *priv) { - scat_t *dev = (scat_t *) priv; - uint8_t ret = 0xff, indx; + const scat_t *dev = (scat_t *) priv; + uint8_t ret = 0xff; + uint8_t indx; switch (port) { case 0x23: @@ -1252,6 +1265,8 @@ scat_in(uint16_t port, void *priv) if ((dev->regs[SCAT_EMS_CONTROL] & 0x41) == (0x40 | ((port & 0x10) >> 4))) ret = dev->reg_2xA; break; + default: + break; } return ret; @@ -1304,7 +1319,8 @@ mem_write_scatb(uint32_t addr, uint8_t val, void *priv) { ems_page_t *page = (ems_page_t *) priv; scat_t *dev = (scat_t *) page->scat; - uint32_t oldaddr = addr, chkaddr; + uint32_t oldaddr = addr; + uint32_t chkaddr; addr = get_addr(dev, addr, page); chkaddr = page->valid ? addr : oldaddr; @@ -1322,7 +1338,8 @@ mem_write_scatw(uint32_t addr, uint16_t val, void *priv) { ems_page_t *page = (ems_page_t *) priv; scat_t *dev = (scat_t *) page->scat; - uint32_t oldaddr = addr, chkaddr; + uint32_t oldaddr = addr; + uint32_t chkaddr; addr = get_addr(dev, addr, page); chkaddr = page->valid ? addr : oldaddr; @@ -1340,7 +1357,8 @@ mem_write_scatl(uint32_t addr, uint32_t val, void *priv) { ems_page_t *page = (ems_page_t *) priv; scat_t *dev = (scat_t *) page->scat; - uint32_t oldaddr = addr, chkaddr; + uint32_t oldaddr = addr; + uint32_t chkaddr; addr = get_addr(dev, addr, page); chkaddr = page->valid ? addr : oldaddr; @@ -1365,7 +1383,8 @@ static void * scat_init(const device_t *info) { scat_t *dev; - uint32_t i, k; + uint32_t j; + uint32_t k; int sx; dev = (scat_t *) malloc(sizeof(scat_t)); @@ -1374,7 +1393,7 @@ scat_init(const device_t *info) sx = (dev->type == 32) ? 1 : 0; - for (i = 0; i < sizeof(dev->regs); i++) + for (uint32_t i = 0; i < sizeof(dev->regs); i++) dev->regs[i] = 0xff; if (sx) { @@ -1418,7 +1437,7 @@ scat_init(const device_t *info) mem_mapping_disable(&ram_mid_mapping); mem_mapping_disable(&ram_high_mapping); - k = (sx) ? 0x80000 : 0x40000; + k = sx ? 0x80000 : 0x40000; dev->null_page.valid = 0; dev->null_page.regs_2x8 = 0xff; @@ -1435,7 +1454,7 @@ scat_init(const device_t *info) mem_write_scatb, mem_write_scatw, mem_write_scatl, ram + 0xf0000, MEM_MAPPING_INTERNAL, &dev->null_page); - for (i = 2; i < 32; i++) { + for (uint8_t i = 2; i < 32; i++) { mem_mapping_add(&dev->low_mapping[i], (i << 19), 0x80000, mem_read_scatb, mem_read_scatw, mem_read_scatl, mem_write_scatb, mem_write_scatw, mem_write_scatl, @@ -1443,27 +1462,27 @@ scat_init(const device_t *info) } if (sx) { - i = 16; + j = 16; k = 0x40000; } else { - i = 0; + j = 0; k = (dev->regs[SCAT_VERSION] < 4) ? 0x40000 : 0x60000; } mem_mapping_set_addr(&dev->low_mapping[31], 0xf80000, k); - for (; i < 44; i++) { - mem_mapping_add(&dev->efff_mapping[i], 0x40000 + (i << 14), 0x4000, + for (; j < 44; j++) { + mem_mapping_add(&dev->efff_mapping[j], 0x40000 + (j << 14), 0x4000, mem_read_scatb, mem_read_scatw, mem_read_scatl, mem_write_scatb, mem_write_scatw, mem_write_scatl, - mem_size > (256 + (i << 4)) ? ram + 0x40000 + (i << 14) : NULL, + mem_size > (256 + (j << 4)) ? ram + 0x40000 + (j << 14) : NULL, MEM_MAPPING_INTERNAL, &dev->null_page); if (sx) - mem_mapping_enable(&dev->efff_mapping[i]); + mem_mapping_enable(&dev->efff_mapping[j]); } if (sx) { - for (i = 24; i < 32; i++) { + for (uint8_t i = 24; i < 32; i++) { dev->page[i].valid = 1; dev->page[i].regs_2x8 = 0xff; dev->page[i].regs_2x9 = 0x03; @@ -1475,7 +1494,7 @@ scat_init(const device_t *info) mem_mapping_disable(&dev->ems_mapping[i]); } } else { - for (i = 0; i < 32; i++) { + for (uint8_t i = 0; i < 32; i++) { dev->page[i].valid = 1; dev->page[i].regs_2x8 = 0xff; dev->page[i].regs_2x9 = 0x03; @@ -1488,7 +1507,7 @@ scat_init(const device_t *info) } } - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { mem_mapping_add(&dev->remap_mapping[i], 0x100000 + (i << 16), 0x10000, mem_read_scatb, mem_read_scatw, mem_read_scatl, mem_write_scatb, mem_write_scatw, mem_write_scatl, @@ -1511,7 +1530,7 @@ scat_init(const device_t *info) device_add(&port_92_device); - return (dev); + return dev; } const device_t scat_device = { diff --git a/src/chipset/sis_5511.c b/src/chipset/sis_5511.c index d13a1cf83..dc2ef42e4 100644 --- a/src/chipset/sis_5511.c +++ b/src/chipset/sis_5511.c @@ -32,6 +32,7 @@ #include <86box/hdc_ide.h> #include <86box/hdc_ide_sff8038i.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/smram.h> @@ -65,10 +66,13 @@ sis_5511_log(const char *fmt, ...) #endif typedef struct sis_5511_t { - uint8_t pci_conf[256], pci_conf_sb[2][256], - index, regs[16]; + uint8_t pci_conf[256]; + uint8_t pci_conf_sb[2][256]; + uint8_t index; + uint8_t regs[16]; - int nb_pci_slot, sb_pci_slot; + int nb_pci_slot; + int sb_pci_slot; sff8038i_t *ide_drive[2]; smram_t *smram; @@ -79,10 +83,10 @@ typedef struct sis_5511_t { static void sis_5511_shadow_recalc(sis_5511_t *dev) { - int i, state; + int state; uint32_t base; - for (i = 0x80; i <= 0x86; i++) { + for (uint8_t i = 0x80; i <= 0x86; i++) { if (i == 0x86) { state = (dev->pci_conf[i] & 0x80) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; state |= (dev->pci_conf[i] & 0x20) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; @@ -121,6 +125,9 @@ sis_5511_smram_recalc(sis_5511_t *dev) case 2: smram_enable(dev->smram, 0x000e0000, 0x000b0000, 0x8000, dev->pci_conf[0x65] & 0x10, 1); break; + + default: + break; } flushmmucache(); @@ -153,7 +160,7 @@ sis_5513_bm_handler(sis_5511_t *dev) } static void -sis_5511_write(int func, int addr, uint8_t val, void *priv) +sis_5511_write(UNUSED(int func), int addr, uint8_t val, void *priv) { sis_5511_t *dev = (sis_5511_t *) priv; @@ -331,14 +338,18 @@ sis_5511_write(int func, int addr, uint8_t val, void *priv) case 0x93: /* 5512 General Purpose Register Index */ dev->pci_conf[addr] = val; break; + + default: + break; } sis_5511_log("SiS 5511: dev->pci_conf[%02x] = %02x POST: %02x\n", addr, dev->pci_conf[addr], inb(0x80)); } static uint8_t -sis_5511_read(int func, int addr, void *priv) +sis_5511_read(UNUSED(int func), int addr, void *priv) { - sis_5511_t *dev = (sis_5511_t *) priv; + const sis_5511_t *dev = (sis_5511_t *) priv; + sis_5511_log("SiS 5511: dev->pci_conf[%02x] (%02x) POST %02x\n", addr, dev->pci_conf[addr], inb(0x80)); return dev->pci_conf[addr]; } @@ -428,6 +439,9 @@ sis_5513_pci_to_isa_write(int addr, uint8_t val, sis_5511_t *dev) case 0x6a: /* GPIO Status Register */ dev->pci_conf_sb[0][addr] &= val & 0x15; break; + + default: + break; } } @@ -514,6 +528,9 @@ sis_5513_ide_write(int addr, uint8_t val, sis_5511_t *dev) case 0x4f: /* Prefetch Count of Secondary Channel (High Byte) */ dev->pci_conf_sb[1][addr] = val; break; + + default: + break; } } @@ -528,6 +545,9 @@ sis_5513_write(int func, int addr, uint8_t val, void *priv) case 1: sis_5513_ide_write(addr, val, dev); break; + + default: + break; } sis_5511_log("SiS 5513: dev->pci_conf[%02x][%02x] = %02x POST: %02x\n", func, addr, dev->pci_conf_sb[func][addr], inb(0x80)); } @@ -535,7 +555,7 @@ sis_5513_write(int func, int addr, uint8_t val, void *priv) static uint8_t sis_5513_read(int func, int addr, void *priv) { - sis_5511_t *dev = (sis_5511_t *) priv; + const sis_5511_t *dev = (sis_5511_t *) priv; sis_5511_log("SiS 5513: dev->pci_conf[%02x][%02x] = %02x POST %02x\n", func, addr, dev->pci_conf_sb[func][addr], inb(0x80)); if ((func >= 0) && (func <= 1)) @@ -567,6 +587,9 @@ sis_5513_isa_write(uint16_t addr, uint8_t val, void *priv) case 2: cpu_set_isa_pci_div(3); break; + + default: + break; } break; case 0x01: @@ -587,16 +610,22 @@ sis_5513_isa_write(uint16_t addr, uint8_t val, void *priv) case 0x0b: dev->regs[dev->index] = val; break; + + default: + break; } sis_5511_log("SiS 5513-ISA: dev->regs[%02x] = %02x POST: %02x\n", dev->index + 0x50, dev->regs[dev->index], inb(0x80)); break; + + default: + break; } } static uint8_t sis_5513_isa_read(uint16_t addr, void *priv) { - sis_5511_t *dev = (sis_5511_t *) priv; + const sis_5511_t *dev = (sis_5511_t *) priv; if (addr == 0x23) { sis_5511_log("SiS 5513-ISA: dev->regs[%02x] (%02x) POST: %02x\n", dev->index + 0x50, dev->regs[dev->index], inb(0x80)); @@ -700,7 +729,7 @@ sis_5511_close(void *priv) } static void * -sis_5511_init(const device_t *info) +sis_5511_init(UNUSED(const device_t *info)) { sis_5511_t *dev = (sis_5511_t *) malloc(sizeof(sis_5511_t)); memset(dev, 0, sizeof(sis_5511_t)); diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index daf64aa74..0e09de199 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -29,6 +29,8 @@ #include <86box/dma.h> #include <86box/mem.h> #include <86box/pci.h> +#include <86box/pic.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/hdc_ide.h> #include <86box/hdc_ide_sff8038i.h> @@ -73,15 +75,19 @@ sis_5571_log(const char *fmt, ...) #endif typedef struct sis_5571_t { - uint8_t pci_conf[256], pci_conf_sb[3][256]; + uint8_t pci_conf[256]; + uint8_t pci_conf_sb[3][256]; - int nb_pci_slot, sb_pci_slot; + int nb_pci_slot; + int sb_pci_slot; port_92_t *port_92; sff8038i_t *ide_drive[2]; smram_t *smram; usb_t *usb; + usb_params_t usb_params; + } sis_5571_t; static void @@ -114,6 +120,9 @@ sis_5571_smm_recalc(sis_5571_t *dev) case 0x03: smram_enable(dev->smram, 0xa0000, 0xa0000, 0x10000, (dev->pci_conf[0xa3] & 0x10), 1); break; + + default: + break; } flushmmucache(); @@ -146,7 +155,7 @@ sis_5571_bm_handler(sis_5571_t *dev) } static void -memory_pci_bridge_write(int func, int addr, uint8_t val, void *priv) +memory_pci_bridge_write(UNUSED(int func), int addr, uint8_t val, void *priv) { sis_5571_t *dev = (sis_5571_t *) priv; @@ -321,14 +330,18 @@ memory_pci_bridge_write(int func, int addr, uint8_t val, void *priv) dev->pci_conf[addr] = val & 0xd0; sis_5571_smm_recalc(dev); break; + + default: + break; } sis_5571_log("SiS5571: dev->pci_conf[%02x] = %02x\n", addr, val); } static uint8_t -memory_pci_bridge_read(int func, int addr, void *priv) +memory_pci_bridge_read(UNUSED(int func), int addr, void *priv) { - sis_5571_t *dev = (sis_5571_t *) priv; + const sis_5571_t *dev = (sis_5571_t *) priv; + sis_5571_log("SiS5571: dev->pci_conf[%02x] (%02x)\n", addr, dev->pci_conf[addr]); return dev->pci_conf[addr]; } @@ -372,6 +385,9 @@ pci_isa_bridge_write(int func, int addr, uint8_t val, void *priv) case 2: cpu_set_isa_pci_div(3); break; + + default: + break; } break; @@ -495,6 +511,9 @@ pci_isa_bridge_write(int func, int addr, uint8_t val, void *priv) case 0x77: /* Monitor Standby Timer Reload And Monitor Standby State ExitControl */ dev->pci_conf_sb[0][addr] = val; break; + + default: + break; } sis_5571_log("SiS5571-SB: dev->pci_conf[%02x] = %02x\n", addr, val); break; @@ -574,6 +593,9 @@ pci_isa_bridge_write(int func, int addr, uint8_t val, void *priv) case 0x4f: /* Prefetch Count of Secondary Channel (High Byte) */ dev->pci_conf_sb[1][addr] = val; break; + + default: + break; } sis_5571_log("SiS5571-IDE: dev->pci_conf[%02x] = %02x\n", addr, val); break; @@ -612,15 +634,22 @@ pci_isa_bridge_write(int func, int addr, uint8_t val, void *priv) case 0x3c: /* Interrupt Line */ dev->pci_conf_sb[2][addr] = val; break; + + default: + break; } sis_5571_log("SiS5571-USB: dev->pci_conf[%02x] = %02x\n", addr, val); + break; + + default: + break; } } static uint8_t pci_isa_bridge_read(int func, int addr, void *priv) { - sis_5571_t *dev = (sis_5571_t *) priv; + const sis_5571_t *dev = (sis_5571_t *) priv; switch (func) { case 0: @@ -632,11 +661,49 @@ pci_isa_bridge_read(int func, int addr, void *priv) case 2: sis_5571_log("SiS5571-USB: dev->pci_conf[%02x] (%02x)\n", addr, dev->pci_conf_sb[2][addr]); return dev->pci_conf_sb[2][addr]; + default: return 0xff; } } +static void +sis_5571_usb_update_interrupt(usb_t* usb, void* priv) +{ + const sis_5571_t *dev = (sis_5571_t *) priv; + + if (dev->pci_conf_sb[0][0x68] & 0x80) { + /* TODO: Is the normal PCI interrupt inhibited when USB IRQ remapping is enabled? */ + switch (dev->pci_conf_sb[0][0x68] & 0x0F) { + case 0x00: + case 0x01: + case 0x02: + case 0x08: + case 0x0d: + break; + + default: + if (usb->irq_level) + picint(1 << dev->pci_conf_sb[0][0x68] & 0x0f); + else + picintc(1 << dev->pci_conf_sb[0][0x68] & 0x0f); + break; + } + } else { + if (usb->irq_level) + pci_set_irq(dev->sb_pci_slot, PCI_INTA); + else + pci_clear_irq(dev->sb_pci_slot, PCI_INTA); + } +} + +static uint8_t +sis_5571_usb_handle_smi(UNUSED(usb_t* usb), UNUSED(void* priv)) +{ + /* Left unimplemented for now. */ + return 1; +} + static void sis_5571_reset(void *priv) { @@ -701,7 +768,7 @@ sis_5571_close(void *priv) } static void * -sis_5571_init(const device_t *info) +sis_5571_init(UNUSED(const device_t *info)) { sis_5571_t *dev = (sis_5571_t *) malloc(sizeof(sis_5571_t)); memset(dev, 0x00, sizeof(sis_5571_t)); @@ -721,7 +788,10 @@ sis_5571_init(const device_t *info) dev->ide_drive[1] = device_add_inst(&sff8038i_device, 2); /* USB */ - dev->usb = device_add(&usb_device); + dev->usb_params.parent_priv = dev; + dev->usb_params.update_interrupt = sis_5571_usb_update_interrupt; + dev->usb_params.smi_handle = sis_5571_usb_handle_smi; + dev->usb = device_add_parameters(&usb_device, &dev->usb_params); sis_5571_reset(dev); diff --git a/src/chipset/sis_85c310.c b/src/chipset/sis_85c310.c index c3015e35b..296307fe1 100644 --- a/src/chipset/sis_85c310.c +++ b/src/chipset/sis_85c310.c @@ -10,18 +10,20 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> -typedef struct -{ - uint8_t cur_reg, tries, - regs[258]; +typedef struct rabbit_t { + uint8_t cur_reg; + uint8_t tries; + uint8_t regs[258]; } rabbit_t; static void rabbit_recalcmapping(rabbit_t *dev) { - uint32_t shread, shwrite; + uint32_t shread; + uint32_t shwrite; uint32_t shflags = 0; shread = !!(dev->regs[0x101] & 0x40); @@ -63,6 +65,8 @@ rabbit_recalcmapping(rabbit_t *dev) /* 128K at 0E0000-0FFFFF */ mem_set_mem_state(0x000e0000, 0x00020000, shflags); break; + default: + break; } flushmmucache(); @@ -88,6 +92,8 @@ rabbit_write(uint16_t addr, uint8_t val, void *priv) } else dev->regs[dev->cur_reg] = val; break; + default: + break; } } @@ -105,6 +111,9 @@ rabbit_read(uint16_t addr, void *priv) } else ret = dev->regs[dev->cur_reg]; break; + + default: + break; } return ret; @@ -119,7 +128,7 @@ rabbit_close(void *priv) } static void * -rabbit_init(const device_t *info) +rabbit_init(UNUSED(const device_t *info)) { rabbit_t *dev = (rabbit_t *) malloc(sizeof(rabbit_t)); memset(dev, 0, sizeof(rabbit_t)); diff --git a/src/chipset/sis_85c496.c b/src/chipset/sis_85c496.c index 6a65e2d62..8aac6ecd5 100644 --- a/src/chipset/sis_85c496.c +++ b/src/chipset/sis_85c496.c @@ -32,16 +32,25 @@ #include <86box/dma.h> #include <86box/nvr.h> #include <86box/pic.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/hdc_ide.h> #include <86box/machine.h> #include <86box/chipset.h> #include <86box/spd.h> +#ifndef USE_DRB_HACK +#include <86box/row.h> +#endif typedef struct sis_85c496_t { - uint8_t cur_reg, rmsmiblk_count, - regs[127], - pci_conf[256]; + uint8_t cur_reg; + uint8_t rmsmiblk_count; +#ifndef USE_DRB_HACK + uint8_t drb_default; + uint8_t drb_bits; +#endif + uint8_t regs[127]; + uint8_t pci_conf[256]; smram_t *smram; pc_timer_t rmsmiblk_timer; port_92_t *port_92; @@ -98,14 +107,16 @@ sis_85c497_isa_write(uint16_t port, uint8_t val, void *priv) dev->regs[dev->cur_reg] = val & 0xfc; dma_set_mask((val & 0x80) ? 0xffffffff : 0x00ffffff); break; + default: + break; } } static uint8_t sis_85c497_isa_read(uint16_t port, void *priv) { - sis_85c496_t *dev = (sis_85c496_t *) priv; - uint8_t ret = 0xff; + const sis_85c496_t *dev = (sis_85c496_t *) priv; + uint8_t ret = 0xff; if (port == 0x23) ret = dev->regs[dev->cur_reg]; @@ -121,12 +132,12 @@ static void sis_85c496_recalcmapping(sis_85c496_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); if (dev->pci_conf[0x44] & (1 << i)) { @@ -180,14 +191,37 @@ sis_85c496_ide_handler(sis_85c496_t *dev) } } +#ifndef USE_DRB_HACK +static void +sis_85c496_drb_recalc(sis_85c496_t *dev) +{ + int i; + uint32_t boundary; + + for (i = 7; i >= 0; i--) + row_disable(i); + + for (i = 0; i <= 7; i++) { + boundary = ((uint32_t) dev->pci_conf[0x48 + i]); + row_set_boundary(i, boundary); + } + + flushmmucache(); +} +#endif + + /* 00 - 3F = PCI Configuration, 40 - 7F = 85C496, 80 - FF = 85C497 */ static void -sis_85c49x_pci_write(int func, int addr, uint8_t val, void *priv) +sis_85c49x_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { sis_85c496_t *dev = (sis_85c496_t *) priv; - uint8_t old, valxor; + uint8_t old; + uint8_t valxor; uint8_t smm_irq[4] = { 10, 11, 12, 15 }; - uint32_t host_base, ram_base, size; + uint32_t host_base; + uint32_t ram_base; + uint32_t size; old = dev->pci_conf[addr]; valxor = (dev->pci_conf[addr]) ^ val; @@ -252,8 +286,12 @@ sis_85c49x_pci_write(int func, int addr, uint8_t val, void *priv) case 0x4d: case 0x4e: case 0x4f: - // dev->pci_conf[addr] = val; +#ifdef USE_DRB_HACK spd_write_drbs(dev->pci_conf, 0x48, 0x4f, 1); +#else + dev->pci_conf[addr] = val; + sis_85c496_drb_recalc(dev); +#endif break; case 0x50: case 0x51: /* Exclusive Area 0 Setup */ @@ -318,6 +356,8 @@ sis_85c49x_pci_write(int func, int addr, uint8_t val, void *priv) host_base = 0x000e0000; ram_base = 0x000b0000; break; + default: + break; } smram_enable(dev->smram, host_base, ram_base, size, @@ -456,14 +496,17 @@ sis_85c49x_pci_write(int func, int addr, uint8_t val, void *priv) dev->pci_conf[addr] = val & 0x6e; nvr_bank_set(0, !!(val & 0x40), dev->nvr); break; + + default: + break; } } static uint8_t -sis_85c49x_pci_read(int func, int addr, void *priv) +sis_85c49x_pci_read(UNUSED(int func), int addr, void *priv) { - sis_85c496_t *dev = (sis_85c496_t *) priv; - uint8_t ret = dev->pci_conf[addr]; + const sis_85c496_t *dev = (sis_85c496_t *) priv; + uint8_t ret = dev->pci_conf[addr]; switch (addr) { case 0xa0: @@ -478,6 +521,9 @@ sis_85c49x_pci_read(int func, int addr, void *priv) case 0x83: /*Port 70h Mirror*/ ret = inb(0x70); break; + + default: + break; } sis_85c496_log("[%04X:%08X] PCI Read %02X from %02X:%02X\n", CS, cpu_state.pc, ret, func, addr); @@ -526,7 +572,6 @@ static void sis_85c496_reset(void *priv) { sis_85c496_t *dev = (sis_85c496_t *) priv; - int i; sis_85c49x_pci_write(0, 0x44, 0x00, dev); sis_85c49x_pci_write(0, 0x45, 0x00, dev); @@ -535,8 +580,8 @@ sis_85c496_reset(void *priv) sis_85c49x_pci_write(0, 0x5a, 0x00, dev); // sis_85c49x_pci_write(0, 0x5a, 0x06, dev); - for (i = 0; i < 8; i++) - sis_85c49x_pci_write(0, 0x48 + i, 0x00, dev); + for (uint8_t i = 0; i < 8; i++) + dev->pci_conf[0x48 + i] = 0x02; sis_85c49x_pci_write(0, 0x80, 0x00, dev); sis_85c49x_pci_write(0, 0x81, 0x00, dev); @@ -605,7 +650,9 @@ static void pci_add_card(PCI_ADD_NORTHBRIDGE, sis_85c49x_pci_read, sis_85c49x_pci_write, dev); - // sis_85c497_isa_reset(dev); +#if 0 + sis_85c497_isa_reset(dev); +#endif dev->port_92 = device_add(&port_92_device); port_92_set_period(dev->port_92, 2ULL * TIMER_USEC); @@ -625,6 +672,11 @@ static void timer_add(&dev->rmsmiblk_timer, sis_85c496_rmsmiblk_count, dev, 0); +#ifndef USE_DRB_HACK + row_device.local = 7 | (1 << 8) | (0x02 << 16) | (8 << 24); + device_add((const device_t *) &row_device); +#endif + sis_85c496_reset(dev); return dev; diff --git a/src/chipset/sis_85c4xx.c b/src/chipset/sis_85c4xx.c index 670a2cc83..97c989b73 100644 --- a/src/chipset/sis_85c4xx.c +++ b/src/chipset/sis_85c4xx.c @@ -28,6 +28,7 @@ #include <86box/timer.h> #include <86box/io.h> #include <86box/device.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/mem.h> #include <86box/smram.h> @@ -35,14 +36,19 @@ #include <86box/machine.h> #include <86box/chipset.h> -typedef struct -{ - uint8_t cur_reg, tries, - reg_base, reg_last, - reg_00, is_471, - force_flush, shadowed, - smram_enabled, pad, - regs[39], scratch[2]; +typedef struct sis_85c4xx_t { + uint8_t cur_reg; + uint8_t tries; + uint8_t reg_base; + uint8_t reg_last; + uint8_t reg_00; + uint8_t is_471; + uint8_t force_flush; + uint8_t shadowed; + uint8_t smram_enabled; + uint8_t pad; + uint8_t regs[39]; + uint8_t scratch[2]; uint32_t mem_state[8]; smram_t *smram; port_92_t *port_92; @@ -62,10 +68,13 @@ sis_85c4xx_recalcremap(sis_85c4xx_t *dev) static void sis_85c4xx_recalcmapping(sis_85c4xx_t *dev) { - uint32_t base, n = 0; - uint32_t i, shflags = 0; - uint32_t readext, writeext; - uint8_t romcs = 0xc0, cur_romcs; + uint32_t base; + uint32_t n = 0; + uint32_t shflags = 0; + uint32_t readext; + uint32_t writeext; + uint8_t romcs = 0xc0; + uint8_t cur_romcs; dev->shadowed = 0x00; @@ -79,7 +88,7 @@ sis_85c4xx_recalcmapping(sis_85c4xx_t *dev) if (dev->regs[0x08] & 0x04) romcs |= 0x02; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); cur_romcs = romcs & (1 << i); readext = cur_romcs ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; @@ -121,7 +130,7 @@ sis_85c4xx_recalcmapping(sis_85c4xx_t *dev) } static void -sis_85c4xx_sw_smi_out(uint16_t port, uint8_t val, void *priv) +sis_85c4xx_sw_smi_out(UNUSED(uint16_t port), UNUSED(uint8_t val), void *priv) { sis_85c4xx_t *dev = (sis_85c4xx_t *) priv; @@ -155,7 +164,8 @@ sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) sis_85c4xx_t *dev = (sis_85c4xx_t *) priv; uint8_t rel_reg = dev->cur_reg - dev->reg_base; uint8_t valxor = 0x00; - uint32_t host_base = 0x000e0000, ram_base = 0x000a0000; + uint32_t host_base = 0x000e0000; + uint32_t ram_base = 0x000a0000; switch (port) { case 0x22: @@ -231,6 +241,8 @@ sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) port_92_add(dev->port_92); } break; + default: + break; } } else if ((dev->reg_base == 0x60) && (dev->cur_reg == 0x00)) dev->reg_00 = val; @@ -241,6 +253,8 @@ sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) case 0xe2: dev->scratch[port - 0xe1] = val; return; + default: + break; } } @@ -269,6 +283,10 @@ sis_85c4xx_in(uint16_t port, void *priv) case 0xe1: case 0xe2: ret = dev->scratch[port - 0xe1]; + break; + + default: + break; } return ret; diff --git a/src/chipset/sis_85c50x.c b/src/chipset/sis_85c50x.c index 56d3a0a30..00556c6f0 100644 --- a/src/chipset/sis_85c50x.c +++ b/src/chipset/sis_85c50x.c @@ -29,6 +29,9 @@ #include <86box/timer.h> #include <86box/apm.h> +#include <86box/machine.h> +#include <86box/pic.h> +#include <86box/plat_unused.h> #include <86box/mem.h> #include <86box/smram.h> #include <86box/pci.h> @@ -55,9 +58,10 @@ sis_85c50x_log(const char *fmt, ...) #endif typedef struct sis_85c50x_t { - uint8_t index, - pci_conf[256], pci_conf_sb[256], - regs[256]; + uint8_t index; + uint8_t pci_conf[256]; + uint8_t pci_conf_sb[256]; + uint8_t regs[256]; smram_t *smram[2]; port_92_t *port_92; @@ -66,7 +70,9 @@ typedef struct sis_85c50x_t { static void sis_85c50x_shadow_recalc(sis_85c50x_t *dev) { - uint32_t base, i, can_read, can_write; + uint32_t base; + uint32_t can_read; + uint32_t can_write; can_read = (dev->pci_conf[0x53] & 0x40) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; can_write = (dev->pci_conf[0x53] & 0x20) ? MEM_WRITE_EXTANY : MEM_WRITE_INTERNAL; @@ -77,7 +83,7 @@ sis_85c50x_shadow_recalc(sis_85c50x_t *dev) shadowbios = 1; shadowbios_write = 1; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xe0000 + (i << 14); mem_set_mem_state_both(base, 0x4000, (dev->pci_conf[0x54] & (1 << (7 - i))) ? (can_read | can_write) : (MEM_READ_EXTANY | MEM_WRITE_EXTANY)); base = 0xd0000 + (i << 14); @@ -129,6 +135,8 @@ sis_85c50x_smm_recalc(sis_85c50x_t *dev) smram_enable(dev->smram[0], host_base, 0xb0000, 0x8000, (dev->pci_conf[0x65] & 0x10), 1); smram_enable(dev->smram[1], host_base ^ 0x00100000, 0xa0000, 0x8000, (dev->pci_conf[0x65] & 0x10), 1); break; + default: + break; } } @@ -209,7 +217,10 @@ sis_85c50x_write(int func, int addr, uint8_t val, void *priv) dev->pci_conf[addr] = (val & 0x7f); break; case 0x69: - dev->pci_conf[addr] &= ~(val); + dev->pci_conf[addr] &= ~val; + break; + + default: break; } } @@ -217,8 +228,8 @@ sis_85c50x_write(int func, int addr, uint8_t val, void *priv) static uint8_t sis_85c50x_read(int func, int addr, void *priv) { - sis_85c50x_t *dev = (sis_85c50x_t *) priv; - uint8_t ret = 0xff; + const sis_85c50x_t *dev = (sis_85c50x_t *) priv; + uint8_t ret = 0xff; if (func == 0x00) ret = dev->pci_conf[addr]; @@ -263,14 +274,17 @@ sis_85c50x_sb_write(int func, int addr, uint8_t val, void *priv) case 0x4b: /* ISA Master/DMA Memory Cycle Control Register 4 */ dev->pci_conf_sb[addr] = val; break; + + default: + break; } } static uint8_t sis_85c50x_sb_read(int func, int addr, void *priv) { - sis_85c50x_t *dev = (sis_85c50x_t *) priv; - uint8_t ret = 0xff; + const sis_85c50x_t *dev = (sis_85c50x_t *) priv; + uint8_t ret = 0xff; if (func == 0x00) ret = dev->pci_conf_sb[addr]; @@ -310,16 +324,22 @@ sis_85c50x_isa_write(uint16_t addr, uint8_t val, void *priv) case 0x85: outb(0x70, val); break; + + default: + break; } break; + + default: + break; } } static uint8_t sis_85c50x_isa_read(uint16_t addr, void *priv) { - sis_85c50x_t *dev = (sis_85c50x_t *) priv; - uint8_t ret = 0xff; + const sis_85c50x_t *dev = (sis_85c50x_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0x22: @@ -332,6 +352,9 @@ sis_85c50x_isa_read(uint16_t addr, void *priv) else ret = dev->regs[dev->index]; break; + + default: + break; } sis_85c50x_log("85C503 ISA: [R] (%04X) = %02X\n", addr, ret); @@ -397,7 +420,7 @@ sis_85c50x_close(void *priv) } static void * -sis_85c50x_init(const device_t *info) +sis_85c50x_init(UNUSED(const device_t *info)) { sis_85c50x_t *dev = (sis_85c50x_t *) malloc(sizeof(sis_85c50x_t)); memset(dev, 0x00, sizeof(sis_85c50x_t)); diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index cd13af3f0..092c0ae32 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -30,6 +30,7 @@ #include <86box/timer.h> #include <86box/pit.h> #include <86box/device.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/usb.h> #include <86box/hdc_ide.h> @@ -65,7 +66,11 @@ typedef struct stpc_t { smram_t *smram; usb_t *usb; int ide_slot; + int usb_slot; sff8038i_t *bm[2]; + + /* Miscellaneous */ + usb_params_t usb_params; } stpc_t; typedef struct stpc_serial_t { @@ -100,15 +105,15 @@ stpc_log(const char *fmt, ...) static void stpc_recalcmapping(stpc_t *dev) { - uint8_t reg, bitpair; - uint32_t base, size; + uint32_t base; + uint32_t size; int state; shadowbios = 0; shadowbios_write = 0; - for (reg = 0; reg <= 3; reg++) { - for (bitpair = 0; bitpair <= ((reg == 3) ? 0 : 3); bitpair++) { + for (uint8_t reg = 0; reg <= 3; reg++) { + for (uint8_t bitpair = 0; bitpair <= ((reg == 3) ? 0 : 3); bitpair++) { if (reg == 3) { size = 0x10000; base = 0xf0000; @@ -161,8 +166,8 @@ stpc_host_write(uint16_t addr, uint8_t val, void *priv) static uint8_t stpc_host_read(uint16_t addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (addr == dev->host_base) ret = dev->host_offset; @@ -191,8 +196,8 @@ stpc_localbus_write(uint16_t addr, uint8_t val, void *priv) static uint8_t stpc_localbus_read(uint16_t addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (addr == dev->localbus_base) ret = dev->localbus_offset; @@ -244,6 +249,9 @@ stpc_nb_write(int func, int addr, uint8_t val, void *priv) case 0x52: val &= 0x70; break; + + default: + break; } dev->pci_conf[0][addr] = val; @@ -252,8 +260,8 @@ stpc_nb_write(int func, int addr, uint8_t val, void *priv) static uint8_t stpc_nb_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; @@ -267,7 +275,8 @@ stpc_nb_read(int func, int addr, void *priv) static void stpc_ide_handlers(stpc_t *dev, int bus) { - uint16_t main, side; + uint16_t main; + uint16_t side; if (bus & 0x01) { ide_pri_disable(); @@ -427,14 +436,17 @@ stpc_ide_write(int func, int addr, uint8_t val, void *priv) sff_bus_master_set_irq(0x00, dev->bm[1]); } break; + + default: + break; } } static uint8_t stpc_ide_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; @@ -484,6 +496,9 @@ stpc_isab_write(int func, int addr, uint8_t val, void *priv) case 0x05: val &= 0x01; break; + + default: + break; } dev->pci_conf[1][addr] = val; @@ -492,8 +507,8 @@ stpc_isab_write(int func, int addr, uint8_t val, void *priv) static uint8_t stpc_isab_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if ((func == 1) && (dev->local != STPC_ATLAS)) ret = stpc_ide_read(0, addr, priv); @@ -546,6 +561,8 @@ stpc_usb_write(int func, int addr, uint8_t val, void *priv) dev->pci_conf[3][addr] = val; ohci_update_mem_mapping(dev->usb, dev->pci_conf[3][0x11], dev->pci_conf[3][0x12], dev->pci_conf[3][0x13], 1); break; + default: + break; } dev->pci_conf[3][addr] = val; @@ -554,8 +571,8 @@ stpc_usb_write(int func, int addr, uint8_t val, void *priv) static uint8_t stpc_usb_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; @@ -597,14 +614,17 @@ stpc_remap_localbus(stpc_t *dev, uint16_t localbus_base) static uint8_t stpc_serial_handlers(uint8_t val) { - stpc_serial_t *dev = device_get_priv(&stpc_serial_device); + const stpc_serial_t *dev = device_get_priv(&stpc_serial_device); + if (!dev) { stpc_log("STPC: Not remapping UARTs, disabled by strap (raw %02X)\n", val); return 0; } - uint16_t uart0_io = 0x3f8, uart1_io = 0x3f8; - uint8_t uart0_irq = 4, uart1_irq = 3; + uint16_t uart0_io = 0x3f8; + uint16_t uart1_io = 0x3f8; + uint8_t uart0_irq = 4; + uint8_t uart1_irq = 3; if (val & 0x10) uart1_io &= 0xfeff; @@ -713,6 +733,9 @@ stpc_reg_write(uint16_t addr, uint8_t val, void *priv) val &= 0xf1; stpc_serial_handlers(val); break; + + default: + break; } dev->regs[dev->reg_offset] = val; @@ -722,8 +745,8 @@ stpc_reg_write(uint16_t addr, uint8_t val, void *priv) static uint8_t stpc_reg_read(uint16_t addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (addr == 0x22) ret = dev->reg_offset; @@ -870,6 +893,17 @@ stpc_setup(stpc_t *dev) pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED); } +static void +stpc_usb_update_interrupt(usb_t* usb, void* priv) +{ + const stpc_t *dev = (stpc_t *) priv; + + if (usb->irq_level) + pci_set_irq(dev->usb_slot, PCI_INTA); + else + pci_clear_irq(dev->usb_slot, PCI_INTA); +} + static void stpc_close(void *priv) { @@ -895,9 +929,13 @@ stpc_init(const device_t *info) pci_add_card(PCI_ADD_NORTHBRIDGE, stpc_nb_read, stpc_nb_write, dev); dev->ide_slot = pci_add_card(PCI_ADD_SOUTHBRIDGE, stpc_isab_read, stpc_isab_write, dev); if (dev->local == STPC_ATLAS) { + dev->usb_params.smi_handle = NULL; + dev->usb_params.update_interrupt = stpc_usb_update_interrupt; + dev->usb_params.parent_priv = dev; + dev->ide_slot = pci_add_card(PCI_ADD_SOUTHBRIDGE, stpc_ide_read, stpc_ide_write, dev); - dev->usb = device_add(&usb_device); - pci_add_card(PCI_ADD_SOUTHBRIDGE, stpc_usb_read, stpc_usb_write, dev); + dev->usb = device_add_parameters(&usb_device, &dev->usb_params); + dev->usb_slot = pci_add_card(PCI_ADD_SOUTHBRIDGE, stpc_usb_read, stpc_usb_write, dev); } dev->bm[0] = device_add_inst(&sff8038i_device, 1); @@ -935,7 +973,7 @@ stpc_serial_close(void *priv) } static void * -stpc_serial_init(const device_t *info) +stpc_serial_init(UNUSED(const device_t *info)) { stpc_log("STPC: serial_init()\n"); @@ -953,7 +991,8 @@ stpc_serial_init(const device_t *info) static void stpc_lpt_handlers(stpc_lpt_t *dev, uint8_t val) { - uint8_t old_addr = (dev->reg1 & 0x03), new_addr = (val & 0x03); + uint8_t old_addr = (dev->reg1 & 0x03); + uint8_t new_addr = (val & 0x03); switch (old_addr) { case 0x1: @@ -967,6 +1006,8 @@ stpc_lpt_handlers(stpc_lpt_t *dev, uint8_t val) case 0x3: lpt2_remove(); break; + default: + break; } switch (new_addr) { @@ -1045,7 +1086,7 @@ stpc_lpt_close(void *priv) } static void * -stpc_lpt_init(const device_t *info) +stpc_lpt_init(UNUSED(const device_t *info)) { stpc_log("STPC: lpt_init()\n"); diff --git a/src/chipset/umc_8886.c b/src/chipset/umc_8886.c index dea5ac99a..ded9c7e56 100644 --- a/src/chipset/umc_8886.c +++ b/src/chipset/umc_8886.c @@ -121,10 +121,10 @@ umc_8886_log(const char *fmt, ...) #define SB_ID dev->sb_id typedef struct umc_8886_t { - uint8_t max_func, /* Last function number */ - pci_conf_sb[2][256]; /* PCI Registers */ - uint16_t sb_id; /* Southbridge Revision */ - int has_ide; /* Check if Southbridge Revision is AF or F */ + uint8_t max_func; /* Last function number */ + uint8_t pci_conf_sb[2][256]; /* PCI Registers */ + uint16_t sb_id; /* Southbridge Revision */ + int has_ide; /* Check if Southbridge Revision is AF or F */ } umc_8886_t; static void @@ -202,7 +202,7 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) case 0x56: dev->pci_conf_sb[func][addr] = val; - switch (val & 2) { + switch (val & 3) { case 0: cpu_set_isa_pci_div(3); break; @@ -212,6 +212,8 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) case 2: cpu_set_isa_pci_div(2); break; + default: + break; } break; @@ -250,6 +252,9 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) case 0xa5 ... 0xa8: dev->pci_conf_sb[func][addr] = val; break; + + default: + break; } break; @@ -271,16 +276,21 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) case 0x41: dev->pci_conf_sb[func][addr] = val; break; + + default: + break; } break; + default: + break; } } static uint8_t umc_8886_read(int func, int addr, void *priv) { - umc_8886_t *dev = (umc_8886_t *) priv; - uint8_t ret = 0xff; + const umc_8886_t *dev = (umc_8886_t *) priv; + uint8_t ret = 0xff; if (func <= dev->max_func) ret = dev->pci_conf_sb[func][addr]; @@ -339,7 +349,7 @@ umc_8886_reset(void *priv) umc_8886_ide_handler(1); } - for (int i = 1; i < 5; i++) /* Disable all IRQ interrupts */ + for (uint8_t i = 1; i < 5; i++) /* Disable all IRQ interrupts */ pci_set_irq_routing(i, PCI_IRQ_DISABLED); cpu_set_isa_pci_div(3); diff --git a/src/chipset/umc_hb4.c b/src/chipset/umc_hb4.c index 40d17533b..60b070f0b 100644 --- a/src/chipset/umc_hb4.c +++ b/src/chipset/umc_hb4.c @@ -106,6 +106,7 @@ #include <86box/mem.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/smram.h> @@ -142,9 +143,10 @@ hb4_log(const char *fmt, ...) #endif typedef struct hb4_t { - uint8_t shadow, - shadow_read, shadow_write, - pci_conf[256]; /* PCI Registers */ + uint8_t shadow; + uint8_t shadow_read; + uint8_t shadow_write; + uint8_t pci_conf[256]; /* PCI Registers */ int mem_state[9]; smram_t *smram[3]; /* SMRAM Handlers */ } hb4_t; @@ -191,10 +193,10 @@ hb4_shadow_bios_low(hb4_t *dev) int hb4_shadow_main(hb4_t *dev) { - int i, state; + int state; int n = 0; - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { state = shadow_read[dev->shadow && ((dev->pci_conf[0x54] >> (i + 2)) & 0x01)] | shadow_write[(dev->pci_conf[0x55] >> 6) & 0x01]; if (state != dev->mem_state[i + 1]) { @@ -261,7 +263,7 @@ hb4_smram(hb4_t *dev) } static void -hb4_write(int func, int addr, uint8_t val, void *priv) +hb4_write(UNUSED(int func), int addr, uint8_t val, void *priv) { hb4_t *dev = (hb4_t *) priv; @@ -322,14 +324,17 @@ hb4_write(int func, int addr, uint8_t val, void *priv) case 0x61: dev->pci_conf[addr] = val; break; + + default: + break; } } static uint8_t hb4_read(int func, int addr, void *priv) { - hb4_t *dev = (hb4_t *) priv; - uint8_t ret = 0xff; + const hb4_t *dev = (hb4_t *) priv; + uint8_t ret = 0xff; if (func == 0) ret = dev->pci_conf[addr]; @@ -383,7 +388,7 @@ hb4_close(void *priv) } static void * -hb4_init(const device_t *info) +hb4_init(UNUSED(const device_t *info)) { hb4_t *dev = (hb4_t *) malloc(sizeof(hb4_t)); memset(dev, 0, sizeof(hb4_t)); diff --git a/src/chipset/via_apollo.c b/src/chipset/via_apollo.c index 6ed6f21fe..bd4445521 100644 --- a/src/chipset/via_apollo.c +++ b/src/chipset/via_apollo.c @@ -69,6 +69,8 @@ apollo_map(uint32_t addr, uint32_t size, int state) case 3: mem_set_mem_state_both(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); break; + default: + break; } flushmmucache_nopc(); @@ -392,8 +394,8 @@ via_apollo_host_bridge_write(int func, int addr, uint8_t val, void *priv) smram_disable_all(); if (dev->id >= VIA_691) switch (val & 0x03) { - case 0x00: default: + case 0x00: apollo_smram_map(dev, 1, 0x000a0000, 0x00020000, 1); /* SMM: Code DRAM, Data DRAM */ apollo_smram_map(dev, 0, 0x000a0000, 0x00020000, 0); /* Non-SMM: Code PCI, Data PCI */ break; @@ -412,8 +414,8 @@ via_apollo_host_bridge_write(int func, int addr, uint8_t val, void *priv) } else if (dev->id >= VIA_597) switch (val & 0x03) { - case 0x00: default: + case 0x00: /* Disable SMI Address Redirection (default) */ apollo_smram_map(dev, 1, 0x000a0000, 0x00020000, 0); apollo_smram_map(dev, 0, 0x000a0000, 0x00020000, 0); @@ -458,6 +460,9 @@ via_apollo_host_bridge_write(int func, int addr, uint8_t val, void *priv) apollo_smram_map(dev, 1, 0x000a0000, 0x00020000, 3); apollo_smram_map(dev, 0, 0x000a0000, 0x00020000, 3); break; + + default: + break; } break; case 0x65: @@ -532,7 +537,7 @@ via_apollo_host_bridge_write(int func, int addr, uint8_t val, void *priv) break; case 0x70: - if ((dev->id >= VIA_693A)) + if (dev->id >= VIA_693A) dev->pci_conf[0x70] = (dev->pci_conf[0x70] & ~0xdf) | (val & 0xdf); else if (dev->id == VIA_597) dev->pci_conf[0x70] = (dev->pci_conf[0x70] & ~0xf1) | (val & 0xf1); @@ -666,13 +671,15 @@ via_apollo_host_bridge_write(int func, int addr, uint8_t val, void *priv) static uint8_t via_apollo_read(int func, int addr, void *priv) { - via_apollo_t *dev = (via_apollo_t *) priv; - uint8_t ret = 0xff; + const via_apollo_t *dev = (via_apollo_t *) priv; + uint8_t ret = 0xff; switch (func) { case 0: ret = dev->pci_conf[addr]; break; + default: + break; } return ret; @@ -685,6 +692,8 @@ via_apollo_write(int func, int addr, uint8_t val, void *priv) case 0: via_apollo_host_bridge_write(func, addr, val, priv); break; + default: + break; } } @@ -728,6 +737,9 @@ via_apollo_init(const device_t *info) case VIA_694: device_add(&via_mvp3_agp_device); break; + + default: + break; } if (dev->id >= VIA_597) diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index a568032b4..04bcd5576 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -41,6 +41,8 @@ #include <86box/ddma.h> #include <86box/pci.h> #include <86box/pic.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> @@ -59,13 +61,15 @@ /* Most revision numbers (PCI-ISA bridge or otherwise) were lifted from PCI device listings on forums, as VIA's datasheets are not very helpful regarding those. */ -#define VIA_PIPC_586A 0x05862500 -#define VIA_PIPC_586B 0x05864700 -#define VIA_PIPC_596A 0x05960900 -#define VIA_PIPC_596B 0x05962300 -#define VIA_PIPC_686A 0x06861400 -#define VIA_PIPC_686B 0x06864000 -#define VIA_PIPC_8231 0x82311000 +#define VIA_PIPC_586A 0x05862500 +#define VIA_PIPC_586B 0x05864700 +#define VIA_PIPC_596A 0x05960900 +#define VIA_PIPC_596B 0x05962300 +#define VIA_PIPC_686A 0x06861400 +#define VIA_PIPC_686B 0x06864000 +#define VIA_PIPC_8231 0x82311000 + +#define VIA_PIPC_FM_EMULATION 1 enum { TRAP_DRQ = 0, @@ -107,22 +111,28 @@ enum { typedef struct { struct _pipc_ *dev; void *trap; - uint32_t *sts_reg, *en_reg, mask; + uint32_t *sts_reg; + uint32_t *en_reg; + uint32_t mask; } pipc_io_trap_t; typedef struct _pipc_ { uint32_t local; - uint8_t max_func, max_pcs; + uint8_t max_func; + uint8_t max_pcs; - uint8_t pci_isa_regs[256], - ide_regs[256], - usb_regs[2][256], - power_regs[256], - ac97_regs[2][256], fmnmi_regs[4]; + uint8_t pci_isa_regs[256]; + uint8_t ide_regs[256]; + uint8_t usb_regs[2][256]; + uint8_t power_regs[256]; + uint8_t ac97_regs[2][256]; + uint8_t fmnmi_regs[4]; + uint8_t fmnmi_status; sff8038i_t *bm[2]; nvr_t *nvr; - int nvr_enabled, slot; + int nvr_enabled; + int slot; ddma_t *ddma; smbus_piix4_t *smbus; usb_t *usb[2]; @@ -130,9 +140,14 @@ typedef struct _pipc_ { acpi_t *acpi; pipc_io_trap_t io_traps[TRAP_MAX]; - void *gameport, *ac97, *sio, *hwm; + void *gameport; + void *ac97; + void *sio; + void *hwm; sb_t *sb; - uint16_t midigame_base, sb_base, fmnmi_base; + uint16_t midigame_base; + uint16_t sb_base; + uint16_t fmnmi_base; } pipc_t; #ifdef ENABLE_PIPC_LOG @@ -160,7 +175,7 @@ static uint8_t pipc_read(int func, int addr, void *priv); static void pipc_write(int func, int addr, uint8_t val, void *priv); static void -pipc_io_trap_pact(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) +pipc_io_trap_pact(UNUSED(int size), UNUSED(uint16_t addr), UNUSED(uint8_t write), UNUSED(uint8_t val), void *priv) { pipc_io_trap_t *trap = (pipc_io_trap_t *) priv; @@ -173,7 +188,7 @@ pipc_io_trap_pact(int size, uint16_t addr, uint8_t write, uint8_t val, void *pri } static void -pipc_io_trap_glb(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) +pipc_io_trap_glb(UNUSED(int size), UNUSED(uint16_t addr), uint8_t write, UNUSED(uint8_t val), void *priv) { pipc_io_trap_t *trap = (pipc_io_trap_t *) priv; @@ -330,6 +345,8 @@ pipc_reset_hard(void *priv) case VIA_PIPC_8231: dev->usb_regs[i][0x08] = 0x1e; break; + default: + break; } dev->usb_regs[i][0x0a] = 0x03; @@ -390,6 +407,9 @@ pipc_reset_hard(void *priv) case VIA_PIPC_686B: dev->power_regs[0x08] = 0x40; break; + + default: + break; } if (dev->local == VIA_PIPC_686B) dev->power_regs[0x34] = 0x68; @@ -451,6 +471,9 @@ pipc_reset_hard(void *priv) case VIA_PIPC_8231: dev->ac97_regs[i][0x08] = (i == 0) ? 0x40 : 0x20; break; + + default: + break; } if (i == 0) { @@ -508,7 +531,8 @@ pipc_reset_hard(void *priv) static void pipc_ide_handlers(pipc_t *dev) { - uint16_t main, side; + uint16_t main; + uint16_t side; ide_pri_disable(); ide_sec_disable(); @@ -571,10 +595,14 @@ pipc_bus_master_handlers(pipc_t *dev) static void pipc_pcs_update(pipc_t *dev) { - uint8_t i, io_base_reg, io_mask_reg, io_mask_shift, enable; - uint16_t io_base, io_mask; + uint8_t io_base_reg; + uint8_t io_mask_reg; + uint8_t io_mask_shift; + uint8_t enable; + uint16_t io_base; + uint16_t io_mask; - for (i = 0; i <= dev->max_pcs; i++) { + for (uint8_t i = 0; i <= dev->max_pcs; i++) { if (i & 2) { io_base_reg = 0x8c; io_mask_reg = 0x8a; @@ -648,7 +676,6 @@ static void pipc_trap_update_596(void *priv) { pipc_t *dev = (pipc_t *) priv; - int i; /* TRAP_DRQ (00000001) and TRAP_PIRQ (00000002) not implemented. */ @@ -679,7 +706,7 @@ pipc_trap_update_596(void *priv) by the Positive Decoding Control registers. I couldn't probe this behavior on hardware. It's better to be safe and cover all of them than to assume Intel-like behavior (one range). */ - for (i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { pipc_trap_update_paden(dev, TRAP_AUD_MIDI_0 + i, 0x00000400, (dev->local <= VIA_PIPC_596B) || (dev->power_regs[0x40] & 0x01), 0x300 + (0x10 * i), 4); @@ -724,8 +751,8 @@ pipc_codec_handlers(pipc_t *dev, uint8_t modem) static uint8_t pipc_fmnmi_read(uint16_t addr, void *priv) { - pipc_t *dev = (pipc_t *) priv; - uint8_t ret = dev->fmnmi_regs[addr & 0x03]; + const pipc_t *dev = (pipc_t *) priv; + uint8_t ret = dev->fmnmi_regs[addr & 0x03]; pipc_log("PIPC: fmnmi_read(%02X) = %02X\n", addr & 0x03, ret); @@ -760,10 +787,10 @@ pipc_fmnmi_handlers(pipc_t *dev, uint8_t modem) static uint8_t pipc_fm_read(uint16_t addr, void *priv) { + const pipc_t *dev = (pipc_t *) priv; #ifdef VIA_PIPC_FM_EMULATION - uint8_t ret = 0x00; + uint8_t ret = ((addr & 0x03) == 0x00) ? dev->fmnmi_status : 0x00; #else - pipc_t *dev = (pipc_t *) priv; uint8_t ret = dev->sb->opl.read(addr, dev->sb->opl.priv); #endif @@ -784,12 +811,26 @@ pipc_fm_write(uint16_t addr, uint8_t val, void *priv) index port, and only fires NMI/SMI when writing to the data port. */ if (!(addr & 0x01)) { dev->fmnmi_regs[0x00] = (addr & 0x02) ? 0x02 : 0x01; - dev->fmnmi_regs[0x01] = val; - } else { dev->fmnmi_regs[0x02] = val; + } else { + dev->fmnmi_regs[0x01] = val; + + /* TODO: Probe how real hardware handles OPL timers. This assumed implementation + just sets the relevant interrupt flags as soon as a timer is started. */ + if (!(addr & 0x02) && (dev->fmnmi_regs[0x02] == 0x04)) { + if (val & 0x80) + dev->fmnmi_status = 0x00; + if ((val & 0x41) == 0x01) + dev->fmnmi_status |= 0x40; + if ((val & 0x22) == 0x02) + dev->fmnmi_status |= 0x20; + if (dev->fmnmi_status & 0x60) + dev->fmnmi_status |= 0x80; + } /* Fire NMI/SMI if enabled. */ if (dev->ac97_regs[0][0x48] & 0x01) { + pipc_log("PIPC: Raising %s\n", (dev->ac97_regs[0][0x48] & 0x04) ? "SMI" : "NMI"); if (dev->ac97_regs[0][0x48] & 0x04) smi_raise(); else @@ -1047,6 +1088,10 @@ pipc_write(int func, int addr, uint8_t val, void *priv) break; + case 0x44: + dev->pci_isa_regs[0x44] = val; + break; + case 0x47: if (val & 0x01) trc_write(0x0047, (val & 0x80) ? 0x06 : 0x04, NULL); @@ -1138,7 +1183,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x71: case 0x72: case 0x73: - dev->pci_isa_regs[(addr - 0x44)] = val; + dev->pci_isa_regs[addr - 0x44] = val; break; case 0x74: @@ -1408,7 +1453,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x61: case 0x62: case 0x63: - dev->power_regs[(addr - 0x58)] = val; + dev->power_regs[addr - 0x58] = val; break; case 0x70: @@ -1430,7 +1475,9 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0xd2: if (dev->local == VIA_PIPC_686B) smbus_piix4_setclock(dev->smbus, (val & 0x04) ? 65536 : 16384); - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x90: case 0x91: @@ -1543,33 +1590,36 @@ pipc_write(int func, int addr, uint8_t val, void *priv) } static void -pipc_reset(void *p) +pipc_reset(void *priv) { - pipc_t *dev = (pipc_t *) p; + pipc_t *dev = (pipc_t *) priv; uint8_t pm_func = dev->usb[1] ? 4 : 3; - pipc_write(pm_func, 0x41, 0x00, p); - pipc_write(pm_func, 0x48, 0x01, p); - pipc_write(pm_func, 0x49, 0x00, p); + pipc_write(pm_func, 0x41, 0x00, priv); + pipc_write(pm_func, 0x48, 0x01, priv); + pipc_write(pm_func, 0x49, 0x00, priv); - pipc_write(1, 0x04, 0x80, p); - pipc_write(1, 0x09, 0x85, p); - pipc_write(1, 0x10, 0xf1, p); - pipc_write(1, 0x11, 0x01, p); - pipc_write(1, 0x14, 0xf5, p); - pipc_write(1, 0x15, 0x03, p); - pipc_write(1, 0x18, 0x71, p); - pipc_write(1, 0x19, 0x01, p); - pipc_write(1, 0x1c, 0x75, p); - pipc_write(1, 0x1d, 0x03, p); - pipc_write(1, 0x20, 0x01, p); - pipc_write(1, 0x21, 0xcc, p); + pipc_write(1, 0x04, 0x80, priv); + pipc_write(1, 0x09, 0x85, priv); + pipc_write(1, 0x10, 0xf1, priv); + pipc_write(1, 0x11, 0x01, priv); + pipc_write(1, 0x14, 0xf5, priv); + pipc_write(1, 0x15, 0x03, priv); + pipc_write(1, 0x18, 0x71, priv); + pipc_write(1, 0x19, 0x01, priv); + pipc_write(1, 0x1c, 0x75, priv); + pipc_write(1, 0x1d, 0x03, priv); + pipc_write(1, 0x20, 0x01, priv); + pipc_write(1, 0x21, 0xcc, priv); if (dev->local <= VIA_PIPC_586B) - pipc_write(1, 0x40, 0x04, p); + pipc_write(1, 0x40, 0x04, priv); else - pipc_write(1, 0x40, 0x00, p); + pipc_write(1, 0x40, 0x00, priv); - pipc_write(0, 0x77, 0x00, p); + if (dev->local < VIA_PIPC_586B) + pipc_write(0, 0x44, 0x00, priv); + + pipc_write(0, 0x77, 0x00, priv); } static void * @@ -1655,13 +1705,13 @@ pipc_init(const device_t *info) } static void -pipc_close(void *p) +pipc_close(void *priv) { - pipc_t *dev = (pipc_t *) p; + pipc_t *dev = (pipc_t *) priv; pipc_log("PIPC: close()\n"); - for (int i = 0; i < TRAP_MAX; i++) + for (uint8_t i = 0; i < TRAP_MAX; i++) io_trap_remove(dev->io_traps[i].trap); free(dev); diff --git a/src/chipset/via_vt82c49x.c b/src/chipset/via_vt82c49x.c index 9bd5baf13..e25fdbfa0 100644 --- a/src/chipset/via_vt82c49x.c +++ b/src/chipset/via_vt82c49x.c @@ -35,13 +35,14 @@ #include <86box/port_92.h> #include <86box/chipset.h> -typedef struct -{ - uint8_t has_ide, index, - regs[256]; +typedef struct vt82c49x_t { + uint8_t has_ide; + uint8_t index; + uint8_t regs[256]; - smram_t *smram_smm, *smram_low, - *smram_high; + smram_t *smram_smm; + smram_t *smram_low; + smram_t *smram_high; } vt82c49x_t; #ifdef ENABLE_VT82C49X_LOG @@ -65,9 +66,11 @@ vt82c49x_log(const char *fmt, ...) static void vt82c49x_recalc(vt82c49x_t *dev) { - int i, relocate; - uint8_t reg, bit; - uint32_t base, state; + int relocate; + uint8_t reg; + uint8_t bit; + uint32_t base; + uint32_t state; uint32_t shadow_bitmap = 0x00000000; relocate = (dev->regs[0x33] >> 2) & 0x03; @@ -75,7 +78,7 @@ vt82c49x_recalc(vt82c49x_t *dev) shadowbios = 0; shadowbios_write = 0; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 14); reg = 0x30 + (i >> 2); bit = (i & 3) << 1; @@ -120,7 +123,7 @@ vt82c49x_recalc(vt82c49x_t *dev) mem_set_mem_state_both(base, 0x4000, state); } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xe0000 + (i << 15); bit = 6 - (i & 2); @@ -186,6 +189,8 @@ vt82c49x_recalc(vt82c49x_t *dev) if (!shadow_bitmap) mem_remap_top(384); break; + default: + break; } } @@ -277,16 +282,22 @@ vt82c49x_write(uint16_t addr, uint8_t val, void *priv) (val & 0x40) ? "second" : "prim"); } break; + + default: + break; } break; + + default: + break; } } static uint8_t vt82c49x_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - vt82c49x_t *dev = (vt82c49x_t *) priv; + uint8_t ret = 0xff; + const vt82c49x_t *dev = (vt82c49x_t *) priv; switch (addr) { case 0xa9: @@ -300,6 +311,9 @@ vt82c49x_read(uint16_t addr, void *priv) else if (dev->index < 0x80) ret = dev->regs[dev->index]; break; + + default: + break; } return ret; @@ -308,9 +322,7 @@ vt82c49x_read(uint16_t addr, void *priv) static void vt82c49x_reset(void *priv) { - uint16_t i; - - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) vt82c49x_write(i, 0x00, priv); } diff --git a/src/chipset/via_vt82c505.c b/src/chipset/via_vt82c505.c index 76c533574..136d335c7 100644 --- a/src/chipset/via_vt82c505.c +++ b/src/chipset/via_vt82c505.c @@ -26,6 +26,7 @@ #include <86box/io.h> #include <86box/pic.h> #include <86box/pci.h> +#include <86box/plat_unused.h> #include <86box/device.h> #include <86box/chipset.h> @@ -116,14 +117,17 @@ vt82c505_write(int func, int addr, uint8_t val, void *priv) case 0x93: dev->pci_conf[addr] = val & 0xe0; break; + + default: + break; } } static uint8_t vt82c505_read(int func, int addr, void *priv) { - vt82c505_t *dev = (vt82c505_t *) priv; - uint8_t ret = 0xff; + const vt82c505_t *dev = (vt82c505_t *) priv; + uint8_t ret = 0xff; if (func != 0) return ret; @@ -147,8 +151,8 @@ vt82c505_out(uint16_t addr, uint8_t val, void *priv) static uint8_t vt82c505_in(uint16_t addr, void *priv) { - vt82c505_t *dev = (vt82c505_t *) priv; - uint8_t ret = 0xff; + const vt82c505_t *dev = (vt82c505_t *) priv; + uint8_t ret = 0xff; if ((addr == 0xa9) && (dev->index >= 0x80) && (dev->index <= 0x9f)) ret = vt82c505_read(0, dev->index, priv); @@ -160,12 +164,11 @@ static void vt82c505_reset(void *priv) { vt82c505_t *dev = (vt82c505_t *) malloc(sizeof(vt82c505_t)); - int i; dev->pci_conf[0x04] = 0x07; dev->pci_conf[0x07] = 0x00; - for (i = 0x80; i <= 0x9f; i++) { + for (uint8_t i = 0x80; i <= 0x9f; i++) { switch (i) { case 0x81: vt82c505_write(0, i, 0x01, priv); @@ -195,7 +198,7 @@ vt82c505_close(void *priv) } static void * -vt82c505_init(const device_t *info) +vt82c505_init(UNUSED(const device_t *info)) { vt82c505_t *dev = (vt82c505_t *) malloc(sizeof(vt82c505_t)); memset(dev, 0, sizeof(vt82c505_t)); diff --git a/src/chipset/vl82c480.c b/src/chipset/vl82c480.c index 9e1b9b8f7..00adcc2a4 100644 --- a/src/chipset/vl82c480.c +++ b/src/chipset/vl82c480.c @@ -29,9 +29,9 @@ #include <86box/port_92.h> #include <86box/chipset.h> -typedef struct { - uint8_t idx, - regs[256]; +typedef struct vl82c480_t { + uint8_t idx; + uint8_t regs[256]; } vl82c480_t; static int @@ -40,8 +40,8 @@ vl82c480_shflags(uint8_t access) int ret = MEM_READ_EXTANY | MEM_WRITE_EXTANY; switch (access) { - case 0x00: default: + case 0x00: ret = MEM_READ_EXTANY | MEM_WRITE_EXTANY; break; case 0x01: @@ -61,15 +61,14 @@ vl82c480_shflags(uint8_t access) static void vl82c480_recalc(vl82c480_t *dev) { - int i, j; uint32_t base; uint8_t access; shadowbios = 0; shadowbios_write = 0; - for (i = 0; i < 6; i++) { - for (j = 0; j < 8; j += 2) { + for (uint8_t i = 0; i < 6; i++) { + for (uint8_t j = 0; j < 8; j += 2) { base = 0x000a0000 + (i << 16) + (j << 13); access = (dev->regs[0x0d + i] >> j) & 3; mem_set_mem_state(base, 0x4000, vl82c480_shflags(access)); @@ -82,9 +81,9 @@ vl82c480_recalc(vl82c480_t *dev) } static void -vl82c480_write(uint16_t addr, uint8_t val, void *p) +vl82c480_write(uint16_t addr, uint8_t val, void *priv) { - vl82c480_t *dev = (vl82c480_t *) p; + vl82c480_t *dev = (vl82c480_t *) priv; switch (addr) { case 0xec: @@ -122,18 +121,24 @@ vl82c480_write(uint16_t addr, uint8_t val, void *p) } break; +/* TODO: This is actually Fast A20 disable. */ +#if 0 case 0xee: if (mem_a20_alt) outb(0x92, inb(0x92) & ~2); break; +#endif + + default: + break; } } static uint8_t -vl82c480_read(uint16_t addr, void *p) +vl82c480_read(uint16_t addr, void *priv) { - vl82c480_t *dev = (vl82c480_t *) p; - uint8_t ret = 0xff; + const vl82c480_t *dev = (vl82c480_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0xec: @@ -144,24 +149,30 @@ vl82c480_read(uint16_t addr, void *p) ret = dev->regs[dev->idx]; break; +/* TODO: This is actually Fast A20 enable. */ +#if 0 case 0xee: if (!mem_a20_alt) outb(0x92, inb(0x92) | 2); break; +#endif case 0xef: softresetx86(); cpu_set_edx(); break; + + default: + break; } return ret; } static void -vl82c480_close(void *p) +vl82c480_close(void *priv) { - vl82c480_t *dev = (vl82c480_t *) p; + vl82c480_t *dev = (vl82c480_t *) priv; free(dev); } diff --git a/src/chipset/wd76c10.c b/src/chipset/wd76c10.c index 41fad0418..ae4b30228 100644 --- a/src/chipset/wd76c10.c +++ b/src/chipset/wd76c10.c @@ -37,6 +37,7 @@ #include <86box/hdc_ide.h> #include <86box/lpt.h> #include <86box/mem.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/serial.h> #include <86box/chipset.h> @@ -63,17 +64,33 @@ wd76c10_log(const char *fmt, ...) # define wd76c10_log(fmt, ...) #endif -typedef struct -{ - uint16_t lock_reg, oscillator_40mhz, cache_flush, ems_page_reg, - ems_page_reg_pointer, port_shadow, pmc_interrupt, - high_mem_protect_boundry, delay_line, diagnostic, - nmi_status, pmc_input, pmc_timer, - pmc_output, ems_control_low_address_boundry, shadow_ram, - split_addr, bank32staddr, bank10staddr, - non_page_mode_dram_timing, mem_control, - refresh_control, disk_chip_select, prog_chip_sel_addr, - bus_timing_power_down_ctl, clk_control; +typedef struct wd76c10_t { + uint16_t lock_reg; + uint16_t oscillator_40mhz; + uint16_t cache_flush; + uint16_t ems_page_reg; + uint16_t ems_page_reg_pointer; + uint16_t port_shadow; + uint16_t pmc_interrupt; + uint16_t high_mem_protect_boundry; + uint16_t delay_line; + uint16_t diagnostic; + uint16_t nmi_status; + uint16_t pmc_input; + uint16_t pmc_timer; + uint16_t pmc_output; + uint16_t ems_control_low_address_boundry; + uint16_t shadow_ram; + uint16_t split_addr; + uint16_t bank32staddr; + uint16_t bank10staddr; + uint16_t non_page_mode_dram_timing; + uint16_t mem_control; + uint16_t refresh_control; + uint16_t disk_chip_select; + uint16_t prog_chip_sel_addr; + uint16_t bus_timing_power_down_ctl; + uint16_t clk_control; int lock; @@ -100,6 +117,8 @@ wd76c10_refresh_control(wd76c10_t *dev) case 4: serial_setup(dev->uart[1], 0x2e8, 3); break; + default: + break; } serial_remove(dev->uart[0]); @@ -117,6 +136,8 @@ wd76c10_refresh_control(wd76c10_t *dev) case 4: serial_setup(dev->uart[0], 0x2e8, 4); break; + default: + break; } lpt1_remove(); @@ -134,6 +155,9 @@ wd76c10_refresh_control(wd76c10_t *dev) lpt1_init(0x278); lpt1_irq(7); break; + + default: + break; } } @@ -153,6 +177,8 @@ wd76c10_split_addr(wd76c10_t *dev) if (((dev->shadow_ram >> 8) & 3) == 3) mem_remap_top(384); break; + default: + break; } } @@ -187,6 +213,8 @@ wd76c10_shadow_recalc(wd76c10_t *dev) case 3: mem_set_mem_state_both(0x20000, 0x80000, MEM_READ_DISABLED | MEM_WRITE_DISABLED); break; + default: + break; } switch ((dev->shadow_ram >> 8) & 3) { @@ -203,6 +231,8 @@ wd76c10_shadow_recalc(wd76c10_t *dev) case 3: mem_set_mem_state_both(0x20000, 0x80000, MEM_READ_DISABLED | (!!(dev->shadow_ram & 0x1000) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL)); break; + default: + break; } } @@ -309,6 +339,9 @@ wd76c10_write(uint16_t addr, uint16_t val, void *priv) dev->cache_flush = val; flushmmucache(); break; + + default: + break; } wd76c10_log("WD76C10: dev->regs[%04x] = %04x\n", addr, val); } @@ -326,13 +359,17 @@ wd76c10_write(uint16_t addr, uint16_t val, void *priv) dev->lock_reg = val & 0x00ff; LOCK = !(val & 0x00da); break; + + default: + break; } } static uint16_t wd76c10_read(uint16_t addr, void *priv) { - wd76c10_t *dev = (wd76c10_t *) priv; + const wd76c10_t *dev = (wd76c10_t *) priv; + wd76c10_log("WD76C10: R dev->regs[%04x]\n", addr); switch (addr) { case 0x1072: @@ -424,7 +461,7 @@ wd76c10_close(void *priv) } static void * -wd76c10_init(const device_t *info) +wd76c10_init(UNUSED(const device_t *info)) { wd76c10_t *dev = (wd76c10_t *) malloc(sizeof(wd76c10_t)); memset(dev, 0, sizeof(wd76c10_t)); diff --git a/src/codegen/codegen.h b/src/codegen/codegen.h index cb9df495b..ddcf5095f 100644 --- a/src/codegen/codegen.h +++ b/src/codegen/codegen.h @@ -212,7 +212,8 @@ codeblock_tree_delete(codeblock_t *block) return; } else { /*Difficult case - node has two children. Walk right child to find lowest node*/ - codeblock_t *lowest = block->right, *highest; + codeblock_t *lowest = block->right; + codeblock_t *highest; codeblock_t *old_parent; while (lowest->left) diff --git a/src/codegen/codegen_ops.c b/src/codegen/codegen_ops.c index dc5c9c4ae..894ebb100 100644 --- a/src/codegen/codegen_ops.c +++ b/src/codegen/codegen_ops.c @@ -91,8 +91,8 @@ RecompOpFn recomp_opcodes_0f[512] = { /*40*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /*50*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -/*60*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -/*70*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, ropEMMS, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*60*/ ropPUNPCKLBW, ropPUNPCKLWD, ropPUNPCKLDQ, ropPACKSSWB, ropPCMPGTB, ropPCMPGTW, ropPCMPGTD, ropPACKUSWB, ropPUNPCKHBW, ropPUNPCKHWD, ropPUNPCKHDQ, ropPACKSSDW, NULL, NULL, ropMOVD_mm_l, ropMOVQ_mm_q, +/*70*/ NULL, ropPSxxW_imm, ropPSxxD_imm, ropPSxxQ_imm, ropPCMPEQB, ropPCMPEQW, ropPCMPEQD, ropEMMS, NULL, NULL, NULL, NULL, NULL, NULL, ropMOVD_l_mm, ropMOVQ_q_mm, /*80*/ ropJO_w, ropJNO_w, ropJB_w, ropJNB_w, ropJE_w, ropJNE_w, ropJBE_w, ropJNBE_w, ropJS_w, ropJNS_w, ropJP_w, ropJNP_w, ropJL_w, ropJNL_w, ropJLE_w, ropJNLE_w, /*90*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -100,9 +100,9 @@ RecompOpFn recomp_opcodes_0f[512] = { /*b0*/ NULL, NULL, ropLSS, NULL, ropLFS, ropLGS, ropMOVZX_w_b, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ropMOVSX_w_b, NULL, /*c0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -/*d0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -/*e0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -/*f0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*d0*/ NULL, ropPSRLW, ropPSRLD, ropPSRLQ, NULL, ropPMULLW, NULL, NULL, ropPSUBUSB, ropPSUBUSW, NULL, ropPAND, ropPADDUSB, ropPADDUSW, NULL, ropPANDN, +/*e0*/ NULL, ropPSRAW, ropPSRAD, NULL, NULL, ropPMULHW, NULL, NULL, ropPSUBSB, ropPSUBSW, NULL, ropPOR, ropPADDSB, ropPADDSW, NULL, ropPXOR, +/*f0*/ NULL, ropPSLLW, ropPSLLD, ropPSLLQ, NULL, ropPMADDWD, NULL, NULL, ropPSUBB, ropPSUBW, ropPSUBD, NULL, ropPADDB, ropPADDW, ropPADDD, NULL, /*32-bit data*/ /* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ @@ -128,6 +128,54 @@ RecompOpFn recomp_opcodes_0f[512] = { // clang-format on }; +RecompOpFn recomp_opcodes_0f_no_mmx[512] = { + // clang-format off + /*16-bit data*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*10*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*20*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*30*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*40*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*50*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*60*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*70*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*80*/ ropJO_w, ropJNO_w, ropJB_w, ropJNB_w, ropJE_w, ropJNE_w, ropJBE_w, ropJNBE_w, ropJS_w, ropJNS_w, ropJP_w, ropJNP_w, ropJL_w, ropJNL_w, ropJLE_w, ropJNLE_w, +/*90*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*a0*/ ropPUSH_FS_16, ropPOP_FS_16, NULL, NULL, NULL, NULL, NULL, NULL, ropPUSH_GS_16, ropPOP_GS_16, NULL, NULL, NULL, NULL, NULL, NULL, +/*b0*/ NULL, NULL, ropLSS, NULL, ropLFS, ropLGS, ropMOVZX_w_b, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ropMOVSX_w_b, NULL, + +/*c0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*d0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*e0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*f0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + + /*32-bit data*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*10*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*20*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*30*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*40*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*50*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*60*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*70*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*80*/ ropJO_l, ropJNO_l, ropJB_l, ropJNB_l, ropJE_l, ropJNE_l, ropJBE_l, ropJNBE_l, ropJS_l, ropJNS_l, ropJP_l, ropJNP_l, ropJL_l, ropJNL_l, ropJLE_l, ropJNLE_l, +/*90*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*a0*/ ropPUSH_FS_32, ropPOP_FS_32, NULL, NULL, NULL, NULL, NULL, NULL, ropPUSH_GS_32, ropPOP_GS_32, NULL, NULL, NULL, NULL, NULL, NULL, +/*b0*/ NULL, NULL, ropLSS, NULL, ropLFS, ropLGS, ropMOVZX_l_b, ropMOVZX_l_w, NULL, NULL, NULL, NULL, NULL, NULL, ropMOVSX_l_b, ropMOVSX_l_w, + +/*c0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*d0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*e0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*f0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // clang-format on +}; + RecompOpFn recomp_opcodes_d8[512] = { // clang-format off /*16-bit data*/ diff --git a/src/codegen/codegen_ops.h b/src/codegen/codegen_ops.h index f92ba4f6d..5c19fb666 100644 --- a/src/codegen/codegen_ops.h +++ b/src/codegen/codegen_ops.h @@ -7,6 +7,7 @@ typedef uint32_t (*RecompOpFn)(uint8_t opcode, uint32_t fetchdat, uint32_t op_32 extern RecompOpFn recomp_opcodes[512]; extern RecompOpFn recomp_opcodes_0f[512]; +extern RecompOpFn recomp_opcodes_0f_no_mmx[512]; extern RecompOpFn recomp_opcodes_d8[512]; extern RecompOpFn recomp_opcodes_d9[512]; extern RecompOpFn recomp_opcodes_da[512]; diff --git a/src/codegen/codegen_ops_arith.h b/src/codegen/codegen_ops_arith.h index 87f1640e6..e6561208e 100644 --- a/src/codegen/codegen_ops_arith.h +++ b/src/codegen/codegen_ops_arith.h @@ -281,7 +281,8 @@ ROP_ARITH_RM(SUB, SUB, 1) static uint32_t ropCMP_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { src_reg = LOAD_REG_B(fetchdat & 7); @@ -307,7 +308,8 @@ ropCMP_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c static uint32_t ropCMP_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { src_reg = LOAD_REG_W(fetchdat & 7); @@ -333,7 +335,8 @@ ropCMP_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c static uint32_t ropCMP_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { src_reg = LOAD_REG_L(fetchdat & 7); @@ -360,7 +363,8 @@ ropCMP_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c static uint32_t ropCMP_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { dst_reg = LOAD_REG_B(fetchdat & 7); @@ -386,7 +390,8 @@ ropCMP_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, static uint32_t ropCMP_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { dst_reg = LOAD_REG_W(fetchdat & 7); @@ -412,7 +417,8 @@ ropCMP_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, static uint32_t ropCMP_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { dst_reg = LOAD_REG_L(fetchdat & 7); diff --git a/src/codegen/codegen_ops_fpu.h b/src/codegen/codegen_ops_fpu.h index 4ffbb45a0..323a25542 100644 --- a/src/codegen/codegen_ops_fpu.h +++ b/src/codegen/codegen_ops_fpu.h @@ -156,7 +156,8 @@ static uint32_t ropFSTd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { x86seg *target_seg; - int host_reg1, host_reg2 = 0; + int host_reg1; + int host_reg2 = 0; FP_ENTER(); op_pc--; @@ -593,7 +594,8 @@ static uint32_t ropFISTPq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { x86seg *target_seg; - int host_reg1, host_reg2; + int host_reg1; + int host_reg2; FP_ENTER(); op_pc--; @@ -679,7 +681,7 @@ opFLDimm(Z, 0.0) static uint32_t ropFLDLN2(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { FP_ENTER(); - FP_LOAD_IMM_Q(0x3fe62e42fefa39f0ull); + FP_LOAD_IMM_Q(0x3fe62e42fefa39f0ULL); return op_pc; } diff --git a/src/codegen/codegen_ops_logic.h b/src/codegen/codegen_ops_logic.h index 55b4e117d..d0216644c 100644 --- a/src/codegen/codegen_ops_logic.h +++ b/src/codegen/codegen_ops_logic.h @@ -175,7 +175,8 @@ ROP_LOGIC(XOR, XOR, 1) static uint32_t ropTEST_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { src_reg = LOAD_REG_B(fetchdat & 7); @@ -198,7 +199,8 @@ ropTEST_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, static uint32_t ropTEST_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { src_reg = LOAD_REG_W(fetchdat & 7); @@ -221,7 +223,8 @@ ropTEST_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, static uint32_t ropTEST_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg; + int src_reg; + int dst_reg; if ((fetchdat & 0xc0) == 0xc0) { src_reg = LOAD_REG_L(fetchdat & 7); diff --git a/src/codegen/codegen_ops_mmx.h b/src/codegen/codegen_ops_mmx.h index edb5b0586..e667bc40e 100644 --- a/src/codegen/codegen_ops_mmx.h +++ b/src/codegen/codegen_ops_mmx.h @@ -1,7 +1,8 @@ static uint32_t ropMOVQ_q_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int host_reg1, host_reg2 = 0; + int host_reg1; + int host_reg2 = 0; MMX_ENTER(); @@ -29,7 +30,8 @@ ropMOVQ_mm_q(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, MMX_ENTER(); if ((fetchdat & 0xc0) == 0xc0) { - int host_reg1, host_reg2; + int host_reg1; + int host_reg2; LOAD_MMX_Q(fetchdat & 7, &host_reg1, &host_reg2); STORE_MMX_Q((fetchdat >> 3) & 7, host_reg1, host_reg2); diff --git a/src/codegen/codegen_ops_x86-64.h b/src/codegen/codegen_ops_x86-64.h index 77f7c02ab..18480a6b5 100644 --- a/src/codegen/codegen_ops_x86-64.h +++ b/src/codegen/codegen_ops_x86-64.h @@ -536,7 +536,8 @@ FETCH_EA_16(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc) addlong((fetchdat >> 8) & 0xffff); (*op_pc) += 2; } else { - int base_reg = 0, index_reg = 0; + int base_reg = 0; + int index_reg = 0; switch (rm) { case 0: @@ -639,8 +640,9 @@ FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t new_eaaddr; if (rm == 4) { - uint8_t sib = fetchdat >> 8; - int base_reg = -1, index_reg = -1; + uint8_t sib = fetchdat >> 8; + int base_reg = -1; + int index_reg = -1; (*op_pc)++; diff --git a/src/codegen/codegen_ops_xchg.h b/src/codegen/codegen_ops_xchg.h index 071acc3d8..820d4461a 100644 --- a/src/codegen/codegen_ops_xchg.h +++ b/src/codegen/codegen_ops_xchg.h @@ -45,7 +45,9 @@ OP_XCHG_EAX_(EBP) static uint32_t ropXCHG_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg, temp_reg; + int src_reg; + int dst_reg; + int temp_reg; if ((fetchdat & 0xc0) != 0xc0) return 0; @@ -61,7 +63,9 @@ ropXCHG_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod static uint32_t ropXCHG_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg, temp_reg; + int src_reg; + int dst_reg; + int temp_reg; if ((fetchdat & 0xc0) != 0xc0) return 0; @@ -77,7 +81,9 @@ ropXCHG_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod static uint32_t ropXCHG_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - int src_reg, dst_reg, temp_reg; + int src_reg; + int dst_reg; + int temp_reg; if ((fetchdat & 0xc0) != 0xc0) return 0; diff --git a/src/codegen/codegen_x86-64.c b/src/codegen/codegen_x86-64.c index 4a184b981..3934b4ac5 100644 --- a/src/codegen/codegen_x86-64.c +++ b/src/codegen/codegen_x86-64.c @@ -845,7 +845,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p switch (opcode) { case 0x0f: op_table = x86_dynarec_opcodes_0f; - recomp_op_table = recomp_opcodes_0f; + recomp_op_table = fpu_softfloat ? recomp_opcodes_0f_no_mmx : recomp_opcodes_0f; over = 1; break; @@ -883,7 +883,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p case 0xd8: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_d8_a32 : x86_dynarec_opcodes_d8_a16; - recomp_op_table = recomp_opcodes_d8; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_d8; opcode_shift = 3; opcode_mask = 0x1f; over = 1; @@ -893,7 +893,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xd9: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_d9_a32 : x86_dynarec_opcodes_d9_a16; - recomp_op_table = recomp_opcodes_d9; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_d9; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -902,7 +902,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xda: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_da_a32 : x86_dynarec_opcodes_da_a16; - recomp_op_table = recomp_opcodes_da; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_da; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -911,7 +911,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdb: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_db_a32 : x86_dynarec_opcodes_db_a16; - recomp_op_table = recomp_opcodes_db; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_db; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -920,7 +920,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdc: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_dc_a32 : x86_dynarec_opcodes_dc_a16; - recomp_op_table = recomp_opcodes_dc; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_dc; opcode_shift = 3; opcode_mask = 0x1f; over = 1; @@ -930,7 +930,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdd: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_dd_a32 : x86_dynarec_opcodes_dd_a16; - recomp_op_table = recomp_opcodes_dd; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_dd; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -939,7 +939,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xde: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_de_a32 : x86_dynarec_opcodes_de_a16; - recomp_op_table = recomp_opcodes_de; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_de; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -948,7 +948,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdf: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_df_a32 : x86_dynarec_opcodes_df_a16; - recomp_op_table = recomp_opcodes_df; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_df; opcode_mask = 0xff; over = 1; pc_off = -1; diff --git a/src/codegen/codegen_x86.c b/src/codegen/codegen_x86.c index dbf76c2e4..712fbe087 100644 --- a/src/codegen/codegen_x86.c +++ b/src/codegen/codegen_x86.c @@ -69,7 +69,8 @@ # include # endif -int codegen_flat_ds, codegen_flat_ss; +int codegen_flat_ds; +int codegen_flat_ss; int mmx_ebx_ecx_loaded; int codegen_flags_changed = 0; int codegen_fpu_entered = 0; @@ -1883,7 +1884,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p switch (opcode) { case 0x0f: op_table = x86_dynarec_opcodes_0f; - recomp_op_table = recomp_opcodes_0f; + recomp_op_table = fpu_softfloat ? recomp_opcodes_0f_no_mmx : recomp_opcodes_0f; over = 1; break; @@ -1921,7 +1922,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p case 0xd8: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_d8_a32 : x86_dynarec_opcodes_d8_a16; - recomp_op_table = recomp_opcodes_d8; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_d8; opcode_shift = 3; opcode_mask = 0x1f; over = 1; @@ -1931,7 +1932,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xd9: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_d9_a32 : x86_dynarec_opcodes_d9_a16; - recomp_op_table = recomp_opcodes_d9; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_d9; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -1940,7 +1941,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xda: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_da_a32 : x86_dynarec_opcodes_da_a16; - recomp_op_table = recomp_opcodes_da; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_da; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -1949,7 +1950,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdb: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_db_a32 : x86_dynarec_opcodes_db_a16; - recomp_op_table = recomp_opcodes_db; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_db; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -1958,7 +1959,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdc: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_dc_a32 : x86_dynarec_opcodes_dc_a16; - recomp_op_table = recomp_opcodes_dc; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_dc; opcode_shift = 3; opcode_mask = 0x1f; over = 1; @@ -1968,7 +1969,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdd: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_dd_a32 : x86_dynarec_opcodes_dd_a16; - recomp_op_table = recomp_opcodes_dd; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_dd; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -1977,7 +1978,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xde: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_de_a32 : x86_dynarec_opcodes_de_a16; - recomp_op_table = recomp_opcodes_de; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_de; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -1986,7 +1987,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xdf: op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_df_a32 : x86_dynarec_opcodes_df_a16; - recomp_op_table = recomp_opcodes_df; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_df; opcode_mask = 0xff; over = 1; pc_off = -1; diff --git a/src/codegen_new/codegen.c b/src/codegen_new/codegen.c index bf6ad123c..b0250fb7d 100644 --- a/src/codegen_new/codegen.c +++ b/src/codegen_new/codegen.c @@ -31,9 +31,7 @@ static struct int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_instruction, int *TOP) { - int c; - - for (c = 0; c <= block->ins; c++) { + for (uint8_t c = 0; c <= block->ins; c++) { if (codegen_instructions[c].pc == pc) { *first_instruction = c; *TOP = codegen_instructions[c].TOP; @@ -137,7 +135,9 @@ codegen_generate_ea_16_long(ir_data_t *ir, x86seg *op_ea_seg, uint32_t fetchdat, uop_MOV_IMM(ir, IREG_eaaddr, addr); (*op_pc) += 2; } else { - int base_reg, index_reg, offset; + int base_reg; + int index_reg; + int offset; switch (cpu_rm & 7) { case 0: @@ -374,7 +374,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p codeblock_t *block = &codeblock[block_current]; ir_data_t *ir = codegen_get_ir_data(); uint32_t op_pc = new_pc; - OpFn *op_table = (OpFn *) x86_dynarec_opcodes; + const OpFn *op_table = (OpFn *) x86_dynarec_opcodes; RecompOpFn *recomp_op_table = recomp_opcodes; int opcode_shift = 0; int opcode_mask = 0x3ff; @@ -398,8 +398,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0x0f; #endif - op_table = (OpFn *) x86_dynarec_opcodes_0f; - recomp_op_table = recomp_opcodes_0f; + op_table = x86_dynarec_opcodes_0f; + recomp_op_table = fpu_softfloat ? recomp_opcodes_0f_no_mmx : recomp_opcodes_0f; over = 1; break; @@ -439,8 +439,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xd8; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_d8_a32 : (OpFn *) x86_dynarec_opcodes_d8_a16; - recomp_op_table = recomp_opcodes_d8; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_d8_a32 : x86_dynarec_opcodes_d8_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_d8; opcode_shift = 3; opcode_mask = 0x1f; over = 1; @@ -452,8 +452,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xd9; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_d9_a32 : (OpFn *) x86_dynarec_opcodes_d9_a16; - recomp_op_table = recomp_opcodes_d9; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_d9_a32 : x86_dynarec_opcodes_d9_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_d9; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -464,8 +464,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xda; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_da_a32 : (OpFn *) x86_dynarec_opcodes_da_a16; - recomp_op_table = recomp_opcodes_da; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_da_a32 : x86_dynarec_opcodes_da_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_da; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -476,8 +476,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdb; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_db_a32 : (OpFn *) x86_dynarec_opcodes_db_a16; - recomp_op_table = recomp_opcodes_db; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_db_a32 : x86_dynarec_opcodes_db_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_db; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -488,8 +488,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdc; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_dc_a32 : (OpFn *) x86_dynarec_opcodes_dc_a16; - recomp_op_table = recomp_opcodes_dc; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_dc_a32 : x86_dynarec_opcodes_dc_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_dc; opcode_shift = 3; opcode_mask = 0x1f; over = 1; @@ -501,8 +501,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdd; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_dd_a32 : (OpFn *) x86_dynarec_opcodes_dd_a16; - recomp_op_table = recomp_opcodes_dd; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_dd_a32 : x86_dynarec_opcodes_dd_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_dd; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -513,8 +513,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xde; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_de_a32 : (OpFn *) x86_dynarec_opcodes_de_a16; - recomp_op_table = recomp_opcodes_de; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_de_a32 : x86_dynarec_opcodes_de_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_de; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -525,8 +525,8 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdf; #endif - op_table = (op_32 & 0x200) ? (OpFn *) x86_dynarec_opcodes_df_a32 : (OpFn *) x86_dynarec_opcodes_df_a16; - recomp_op_table = recomp_opcodes_df; + op_table = (op_32 & 0x200) ? x86_dynarec_opcodes_df_a32 : x86_dynarec_opcodes_df_a16; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_df; opcode_mask = 0xff; over = 1; pc_off = -1; @@ -541,14 +541,14 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xf2; #endif - op_table = (OpFn *) x86_dynarec_opcodes_REPNE; + op_table = x86_dynarec_opcodes_REPNE; recomp_op_table = NULL; // recomp_opcodes_REPNE; break; case 0xf3: /*REPE*/ #ifdef DEBUG_EXTRA last_prefix = 0xf3; #endif - op_table = (OpFn *) x86_dynarec_opcodes_REPE; + op_table = x86_dynarec_opcodes_REPE; recomp_op_table = NULL; // recomp_opcodes_REPE; break; @@ -634,11 +634,11 @@ generate_call: } opcode_3dnow = fastreadb(cs + opcode_pc); - if (recomp_opcodes_3DNOW[opcode_3dnow]) { + if (!fpu_softfloat && recomp_opcodes_3DNOW[opcode_3dnow]) { next_pc = opcode_pc + 1; op_table = (OpFn *) x86_dynarec_opcodes_3DNOW; - recomp_op_table = recomp_opcodes_3DNOW; + recomp_op_table = fpu_softfloat ? NULL : recomp_opcodes_3DNOW; opcode = opcode_3dnow; recomp_opcode_mask = 0xff; opcode_mask = 0xff; @@ -713,6 +713,7 @@ generate_call: uop_MOV_IMM(ir, IREG_ssegs, op_ssegs); uop_LOAD_FUNC_ARG_IMM(ir, 0, fetchdat); uop_CALL_INSTRUCTION_FUNC(ir, op); + codegen_flags_changed = 0; codegen_mark_code_present(block, cs + cpu_state.pc, 8); last_op_32 = op_32; diff --git a/src/codegen_new/codegen.h b/src/codegen_new/codegen.h index cc7e3f083..547f867e3 100644 --- a/src/codegen_new/codegen.h +++ b/src/codegen_new/codegen.h @@ -140,12 +140,16 @@ codeblock_tree_add(codeblock_t *new_block) block = block->right ? &codeblock[block->right] : NULL; } - if (a < old_block_cmp) - old_block->left = get_block_nr(new_block); - else - old_block->right = get_block_nr(new_block); + if (old_block != NULL) { + if (a < old_block_cmp) + old_block->left = get_block_nr(new_block); + else + old_block->right = get_block_nr(new_block); + + new_block->parent = get_block_nr(old_block); + } else + new_block->parent = BLOCK_INVALID; - new_block->parent = get_block_nr(old_block); new_block->left = new_block->right = BLOCK_INVALID; } } @@ -212,7 +216,8 @@ codeblock_tree_delete(codeblock_t *block) return; } else { /*Difficult case - node has two children. Walk right child to find lowest node*/ - codeblock_t *lowest = &codeblock[block->right], *highest; + codeblock_t *lowest = &codeblock[block->right]; + codeblock_t *highest; codeblock_t *old_parent; uint16_t lowest_nr; diff --git a/src/codegen_new/codegen_allocator.c b/src/codegen_new/codegen_allocator.c index 2badc35e8..9661cf631 100644 --- a/src/codegen_new/codegen_allocator.c +++ b/src/codegen_new/codegen_allocator.c @@ -32,8 +32,6 @@ int codegen_allocator_usage = 0; void codegen_allocator_init(void) { - int c; - #if defined WIN32 || defined _WIN32 || defined _WIN32 mem_block_alloc = VirtualAlloc(NULL, MEM_BLOCK_NR * MEM_BLOCK_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE); /* TODO: check deployment target: older Intel-based versions of macOS don't play @@ -44,7 +42,7 @@ codegen_allocator_init(void) mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); #endif - for (c = 0; c < MEM_BLOCK_NR; c++) { + for (uint32_t c = 0; c < MEM_BLOCK_NR; c++) { mem_blocks[c].offset = c * MEM_BLOCK_SIZE; mem_blocks[c].code_block = BLOCK_INVALID; if (c < MEM_BLOCK_NR - 1) diff --git a/src/codegen_new/codegen_backend_arm64_imm.c b/src/codegen_new/codegen_backend_arm64_imm.c index 5e1e1038f..6e5034cc0 100644 --- a/src/codegen_new/codegen_backend_arm64_imm.c +++ b/src/codegen_new/codegen_backend_arm64_imm.c @@ -1313,7 +1313,8 @@ static uint32_t imm_table[][2] = { uint32_t host_arm64_find_imm(uint32_t data) { - int l = 0, r = IMM_NR - 1; + int l = 0; + int r = IMM_NR - 1; while (l <= r) { int m = (l + r) >> 1; diff --git a/src/codegen_new/codegen_backend_x86.c b/src/codegen_new/codegen_backend_x86.c index 2de794ad1..f656e708f 100644 --- a/src/codegen_new/codegen_backend_x86.c +++ b/src/codegen_new/codegen_backend_x86.c @@ -263,7 +263,6 @@ void codegen_backend_init(void) { codeblock_t *block; - int c; codeblock = malloc(BLOCK_SIZE * sizeof(codeblock_t)); codeblock_hash = malloc(HASH_SIZE * sizeof(codeblock_t *)); @@ -271,7 +270,7 @@ codegen_backend_init(void) memset(codeblock, 0, BLOCK_SIZE * sizeof(codeblock_t)); memset(codeblock_hash, 0, HASH_SIZE * sizeof(codeblock_t *)); - for (c = 0; c < BLOCK_SIZE; c++) + for (uint32_t c = 0; c < BLOCK_SIZE; c++) codeblock[c].pc = BLOCK_PC_INVALID; block_current = 0; diff --git a/src/codegen_new/codegen_backend_x86_uops.c b/src/codegen_new/codegen_backend_x86_uops.c index 83844b3cd..00ae453c3 100644 --- a/src/codegen_new/codegen_backend_x86_uops.c +++ b/src/codegen_new/codegen_backend_x86_uops.c @@ -34,8 +34,12 @@ static int codegen_ADD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -61,8 +65,10 @@ codegen_ADD(codeblock_t *block, uop_t *uop) static int codegen_ADD_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -105,8 +111,12 @@ codegen_ADD_LSHIFT(codeblock_t *block, uop_t *uop) static int codegen_AND(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PAND_XREG_XREG(block, dest_reg, src_reg_b); @@ -133,8 +143,10 @@ codegen_AND(codeblock_t *block, uop_t *uop) static int codegen_AND_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -159,8 +171,14 @@ codegen_AND_IMM(codeblock_t *block, uop_t *uop) static int codegen_ANDN(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), /*src_reg_a = HOST_REG_GET(uop->src_reg_a_real), */ src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); +#if 0 + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); +#endif + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PANDN_XREG_XREG(block, dest_reg, src_reg_b); @@ -267,8 +285,10 @@ codegen_CMP_IMM_JZ_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JB(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); uint32_t *jump_p; if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { @@ -286,8 +306,10 @@ codegen_CMP_JB(codeblock_t *block, uop_t *uop) static int codegen_CMP_JNBE(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); uint32_t *jump_p; if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { @@ -306,8 +328,10 @@ codegen_CMP_JNBE(codeblock_t *block, uop_t *uop) static int codegen_CMP_JNB_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -327,8 +351,10 @@ codegen_CMP_JNB_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JNBE_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -348,8 +374,10 @@ codegen_CMP_JNBE_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JNL_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -369,8 +397,10 @@ codegen_CMP_JNL_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JNLE_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -390,8 +420,10 @@ codegen_CMP_JNLE_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JNO_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -411,8 +443,10 @@ codegen_CMP_JNO_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JNZ_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -432,8 +466,10 @@ codegen_CMP_JNZ_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JB_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -453,8 +489,10 @@ codegen_CMP_JB_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JBE_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -474,8 +512,10 @@ codegen_CMP_JBE_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JL_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -495,8 +535,10 @@ codegen_CMP_JL_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JLE_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -516,8 +558,10 @@ codegen_CMP_JLE_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JO_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -537,8 +581,10 @@ codegen_CMP_JO_DEST(codeblock_t *block, uop_t *uop) static int codegen_CMP_JZ_DEST(codeblock_t *block, uop_t *uop) { - int src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { host_x86_CMP32_REG_REG(block, src_reg_a, src_reg_b); @@ -559,8 +605,10 @@ codegen_CMP_JZ_DEST(codeblock_t *block, uop_t *uop) static int codegen_FABS(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && dest_reg == src_reg_a) { host_x86_PXOR_XREG_XREG(block, REG_XMM_TEMP, REG_XMM_TEMP); @@ -576,8 +624,10 @@ codegen_FABS(codeblock_t *block, uop_t *uop) static int codegen_FCHS(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a)) { host_x86_MOVQ_XREG_XREG(block, REG_XMM_TEMP, src_reg_a); @@ -593,8 +643,10 @@ codegen_FCHS(codeblock_t *block, uop_t *uop) static int codegen_FSQRT(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a)) { host_x86_SQRTSD_XREG_XREG(block, dest_reg, src_reg_a); @@ -608,8 +660,10 @@ codegen_FSQRT(codeblock_t *block, uop_t *uop) static int codegen_FTST(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_W(dest_size) && REG_IS_D(src_size_a)) { host_x86_PXOR_XREG_XREG(block, REG_XMM_TEMP, REG_XMM_TEMP); @@ -634,8 +688,12 @@ codegen_FTST(codeblock_t *block, uop_t *uop) static int codegen_FADD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b) && dest_reg == src_reg_a) { host_x86_ADDSD_XREG_XREG(block, dest_reg, src_reg_b); @@ -649,8 +707,12 @@ codegen_FADD(codeblock_t *block, uop_t *uop) static int codegen_FCOM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_W(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b)) { if (dest_reg != REG_EAX) @@ -673,8 +735,12 @@ codegen_FCOM(codeblock_t *block, uop_t *uop) static int codegen_FDIV(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b) && dest_reg == src_reg_a) { host_x86_DIVSD_XREG_XREG(block, dest_reg, src_reg_b); @@ -692,8 +758,12 @@ codegen_FDIV(codeblock_t *block, uop_t *uop) static int codegen_FMUL(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b) && dest_reg == src_reg_a) { host_x86_MULSD_XREG_XREG(block, dest_reg, src_reg_b); @@ -707,8 +777,12 @@ codegen_FMUL(codeblock_t *block, uop_t *uop) static int codegen_FSUB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a) && REG_IS_D(src_size_b) && dest_reg == src_reg_a) { host_x86_SUBSD_XREG_XREG(block, dest_reg, src_reg_b); @@ -864,7 +938,8 @@ codegen_LOAD_SEG(codeblock_t *block, uop_t *uop) static int codegen_MEM_LOAD_ABS(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); host_x86_LEA_REG_IMM(block, REG_ESI, seg_reg, uop->imm_data); @@ -894,7 +969,9 @@ codegen_MEM_LOAD_ABS(codeblock_t *block, uop_t *uop) static int codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); host_x86_LEA_REG_REG(block, REG_ESI, seg_reg, addr_reg); @@ -930,7 +1007,9 @@ codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop) static int codegen_MEM_LOAD_SINGLE(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); # ifdef RECOMPILER_DEBUG int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); @@ -951,7 +1030,9 @@ codegen_MEM_LOAD_SINGLE(codeblock_t *block, uop_t *uop) static int codegen_MEM_LOAD_DOUBLE(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); # ifdef RECOMPILER_DEBUG int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); @@ -972,7 +1053,8 @@ codegen_MEM_LOAD_DOUBLE(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_ABS(codeblock_t *block, uop_t *uop) { - int seg_reg = HOST_REG_GET(uop->src_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_b_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_b_real); int src_size = IREG_GET_SIZE(uop->src_reg_b_real); host_x86_LEA_REG_IMM(block, REG_ESI, seg_reg, uop->imm_data); @@ -999,7 +1081,9 @@ codegen_MEM_STORE_ABS(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_REG(codeblock_t *block, uop_t *uop) { - int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int src_reg = HOST_REG_GET(uop->src_reg_c_real); int src_size = IREG_GET_SIZE(uop->src_reg_c_real); host_x86_LEA_REG_REG(block, REG_ESI, seg_reg, addr_reg); @@ -1031,7 +1115,8 @@ codegen_MEM_STORE_REG(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_IMM_8(codeblock_t *block, uop_t *uop) { - int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); host_x86_LEA_REG_REG(block, REG_ESI, seg_reg, addr_reg); host_x86_MOV8_REG_IMM(block, REG_ECX, uop->imm_data); @@ -1044,7 +1129,8 @@ codegen_MEM_STORE_IMM_8(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_IMM_16(codeblock_t *block, uop_t *uop) { - int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); host_x86_LEA_REG_REG(block, REG_ESI, seg_reg, addr_reg); host_x86_MOV16_REG_IMM(block, REG_ECX, uop->imm_data); @@ -1057,7 +1143,8 @@ codegen_MEM_STORE_IMM_16(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_IMM_32(codeblock_t *block, uop_t *uop) { - int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); host_x86_LEA_REG_REG(block, REG_ESI, seg_reg, addr_reg); host_x86_MOV32_REG_IMM(block, REG_ECX, uop->imm_data); @@ -1071,7 +1158,9 @@ codegen_MEM_STORE_IMM_32(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_SINGLE(codeblock_t *block, uop_t *uop) { - int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int src_reg = HOST_REG_GET(uop->src_reg_c_real); # ifdef RECOMPILER_DEBUG int src_size = IREG_GET_SIZE(uop->src_reg_c_real); @@ -1091,7 +1180,9 @@ codegen_MEM_STORE_SINGLE(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_DOUBLE(codeblock_t *block, uop_t *uop) { - int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real); + int seg_reg = HOST_REG_GET(uop->src_reg_a_real); + int addr_reg = HOST_REG_GET(uop->src_reg_b_real); + int src_reg = HOST_REG_GET(uop->src_reg_c_real); # ifdef RECOMPILER_DEBUG int src_size = IREG_GET_SIZE(uop->src_reg_c_real); @@ -1112,8 +1203,10 @@ codegen_MEM_STORE_DOUBLE(codeblock_t *block, uop_t *uop) static int codegen_MOV(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { host_x86_MOV32_REG_REG(block, dest_reg, src_reg); @@ -1205,8 +1298,10 @@ codegen_MOVZX_REG_PTR_16(codeblock_t *block, uop_t *uop) static int codegen_MOVSX(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_W(src_size)) { host_x86_MOVSX_REG_32_16(block, dest_reg, src_reg); @@ -1224,8 +1319,10 @@ codegen_MOVSX(codeblock_t *block, uop_t *uop) static int codegen_MOVZX(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_Q(dest_size) && REG_IS_L(src_size)) { host_x86_MOVD_XREG_REG(block, dest_reg, src_reg); @@ -1248,8 +1345,10 @@ codegen_MOVZX(codeblock_t *block, uop_t *uop) static int codegen_MOV_DOUBLE_INT(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_D(dest_size) && REG_IS_L(src_size)) { host_x86_CVTSI2SD_XREG_REG(block, dest_reg, src_reg); @@ -1273,8 +1372,10 @@ codegen_MOV_DOUBLE_INT(codeblock_t *block, uop_t *uop) static int codegen_MOV_INT_DOUBLE(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_D(src_size)) { host_x86_LDMXCSR(block, &cpu_state.new_fp_control); @@ -1296,8 +1397,13 @@ codegen_MOV_INT_DOUBLE(codeblock_t *block, uop_t *uop) static int codegen_MOV_INT_DOUBLE_64(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), src_64_reg = HOST_REG_GET(uop->src_reg_b_real), tag_reg = HOST_REG_GET(uop->src_reg_c_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real), src_64_size = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int src_64_reg = HOST_REG_GET(uop->src_reg_b_real); + int tag_reg = HOST_REG_GET(uop->src_reg_c_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int src_64_size = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_D(src_size) && REG_IS_Q(src_64_size)) { uint32_t *branch_offset; @@ -1334,8 +1440,12 @@ codegen_NOP(codeblock_t *block, uop_t *uop) static int codegen_OR(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_POR_XREG_XREG(block, dest_reg, src_reg_b); @@ -1361,7 +1471,8 @@ codegen_OR(codeblock_t *block, uop_t *uop) static int codegen_OR_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); if (REG_IS_L(dest_size) && dest_reg == src_reg) { @@ -1381,8 +1492,10 @@ codegen_OR_IMM(codeblock_t *block, uop_t *uop) static int codegen_PACKSSWB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PACKSSWB_XREG_XREG(block, dest_reg, src_reg_b); @@ -1396,8 +1509,10 @@ codegen_PACKSSWB(codeblock_t *block, uop_t *uop) static int codegen_PACKSSDW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PACKSSDW_XREG_XREG(block, dest_reg, src_reg_b); @@ -1411,8 +1526,10 @@ codegen_PACKSSDW(codeblock_t *block, uop_t *uop) static int codegen_PACKUSWB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PACKUSWB_XREG_XREG(block, dest_reg, src_reg_b); @@ -1427,8 +1544,10 @@ codegen_PACKUSWB(codeblock_t *block, uop_t *uop) static int codegen_PADDB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PADDB_XREG_XREG(block, dest_reg, src_reg_b); @@ -1442,8 +1561,10 @@ codegen_PADDB(codeblock_t *block, uop_t *uop) static int codegen_PADDW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PADDW_XREG_XREG(block, dest_reg, src_reg_b); @@ -1457,8 +1578,10 @@ codegen_PADDW(codeblock_t *block, uop_t *uop) static int codegen_PADDD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PADDD_XREG_XREG(block, dest_reg, src_reg_b); @@ -1472,8 +1595,10 @@ codegen_PADDD(codeblock_t *block, uop_t *uop) static int codegen_PADDSB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PADDSB_XREG_XREG(block, dest_reg, src_reg_b); @@ -1487,8 +1612,10 @@ codegen_PADDSB(codeblock_t *block, uop_t *uop) static int codegen_PADDSW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PADDSW_XREG_XREG(block, dest_reg, src_reg_b); @@ -1502,8 +1629,10 @@ codegen_PADDSW(codeblock_t *block, uop_t *uop) static int codegen_PADDUSB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PADDUSB_XREG_XREG(block, dest_reg, src_reg_b); @@ -1517,8 +1646,10 @@ codegen_PADDUSB(codeblock_t *block, uop_t *uop) static int codegen_PADDUSW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PADDUSW_XREG_XREG(block, dest_reg, src_reg_b); @@ -1533,8 +1664,10 @@ codegen_PADDUSW(codeblock_t *block, uop_t *uop) static int codegen_PCMPEQB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PCMPEQB_XREG_XREG(block, dest_reg, src_reg_b); @@ -1548,8 +1681,10 @@ codegen_PCMPEQB(codeblock_t *block, uop_t *uop) static int codegen_PCMPEQW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PCMPEQW_XREG_XREG(block, dest_reg, src_reg_b); @@ -1563,8 +1698,10 @@ codegen_PCMPEQW(codeblock_t *block, uop_t *uop) static int codegen_PCMPEQD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PCMPEQD_XREG_XREG(block, dest_reg, src_reg_b); @@ -1578,8 +1715,10 @@ codegen_PCMPEQD(codeblock_t *block, uop_t *uop) static int codegen_PCMPGTB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PCMPGTB_XREG_XREG(block, dest_reg, src_reg_b); @@ -1593,8 +1732,10 @@ codegen_PCMPGTB(codeblock_t *block, uop_t *uop) static int codegen_PCMPGTW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PCMPGTW_XREG_XREG(block, dest_reg, src_reg_b); @@ -1608,8 +1749,10 @@ codegen_PCMPGTW(codeblock_t *block, uop_t *uop) static int codegen_PCMPGTD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PCMPGTD_XREG_XREG(block, dest_reg, src_reg_b); @@ -1624,8 +1767,10 @@ codegen_PCMPGTD(codeblock_t *block, uop_t *uop) static int codegen_PF2ID(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a)) { host_x86_LDMXCSR(block, &cpu_state.trunc_fp_control); @@ -1641,8 +1786,10 @@ codegen_PF2ID(codeblock_t *block, uop_t *uop) static int codegen_PFADD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_ADDPS_XREG_XREG(block, dest_reg, src_reg_b); @@ -1656,8 +1803,10 @@ codegen_PFADD(codeblock_t *block, uop_t *uop) static int codegen_PFCMPEQ(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_CMPPS_XREG_XREG(block, dest_reg, src_reg_b, CMPPS_EQ); @@ -1671,8 +1820,10 @@ codegen_PFCMPEQ(codeblock_t *block, uop_t *uop) static int codegen_PFCMPGE(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_CMPPS_XREG_XREG(block, dest_reg, src_reg_b, CMPPS_NLT); @@ -1686,8 +1837,10 @@ codegen_PFCMPGE(codeblock_t *block, uop_t *uop) static int codegen_PFCMPGT(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_CMPPS_XREG_XREG(block, dest_reg, src_reg_b, CMPPS_NLE); @@ -1701,8 +1854,10 @@ codegen_PFCMPGT(codeblock_t *block, uop_t *uop) static int codegen_PFMAX(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_MAXPS_XREG_XREG(block, dest_reg, src_reg_b); @@ -1716,8 +1871,10 @@ codegen_PFMAX(codeblock_t *block, uop_t *uop) static int codegen_PFMIN(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_MINPS_XREG_XREG(block, dest_reg, src_reg_b); @@ -1731,8 +1888,10 @@ codegen_PFMIN(codeblock_t *block, uop_t *uop) static int codegen_PFMUL(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_MULPS_XREG_XREG(block, dest_reg, src_reg_b); @@ -1746,8 +1905,10 @@ codegen_PFMUL(codeblock_t *block, uop_t *uop) static int codegen_PFRCP(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a)) { /*TODO: This could be improved (use RCPSS + iteration)*/ @@ -1766,8 +1927,10 @@ codegen_PFRCP(codeblock_t *block, uop_t *uop) static int codegen_PFRSQRT(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a)) { /*TODO: This could be improved (use RSQRTSS + iteration)*/ @@ -1786,8 +1949,12 @@ codegen_PFRSQRT(codeblock_t *block, uop_t *uop) static int codegen_PFSUB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_SUBPS_XREG_XREG(block, dest_reg, src_reg_b); @@ -1805,8 +1972,10 @@ codegen_PFSUB(codeblock_t *block, uop_t *uop) static int codegen_PI2FD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a)) { host_x86_CVTDQ2PS_XREG_XREG(block, dest_reg, src_reg_a); @@ -1821,8 +1990,10 @@ codegen_PI2FD(codeblock_t *block, uop_t *uop) static int codegen_PMADDWD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PMADDWD_XREG_XREG(block, dest_reg, src_reg_b); @@ -1836,8 +2007,10 @@ codegen_PMADDWD(codeblock_t *block, uop_t *uop) static int codegen_PMULHW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PMULHW_XREG_XREG(block, dest_reg, src_reg_b); @@ -1851,8 +2024,10 @@ codegen_PMULHW(codeblock_t *block, uop_t *uop) static int codegen_PMULLW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PMULLW_XREG_XREG(block, dest_reg, src_reg_b); @@ -2003,8 +2178,10 @@ codegen_PSRLQ_IMM(codeblock_t *block, uop_t *uop) static int codegen_PSUBB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PSUBB_XREG_XREG(block, dest_reg, src_reg_b); @@ -2018,8 +2195,10 @@ codegen_PSUBB(codeblock_t *block, uop_t *uop) static int codegen_PSUBW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PSUBW_XREG_XREG(block, dest_reg, src_reg_b); @@ -2033,8 +2212,10 @@ codegen_PSUBW(codeblock_t *block, uop_t *uop) static int codegen_PSUBD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PSUBD_XREG_XREG(block, dest_reg, src_reg_b); @@ -2048,8 +2229,10 @@ codegen_PSUBD(codeblock_t *block, uop_t *uop) static int codegen_PSUBSB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PSUBSB_XREG_XREG(block, dest_reg, src_reg_b); @@ -2063,8 +2246,10 @@ codegen_PSUBSB(codeblock_t *block, uop_t *uop) static int codegen_PSUBSW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PSUBSW_XREG_XREG(block, dest_reg, src_reg_b); @@ -2078,8 +2263,10 @@ codegen_PSUBSW(codeblock_t *block, uop_t *uop) static int codegen_PSUBUSB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PSUBUSB_XREG_XREG(block, dest_reg, src_reg_b); @@ -2093,8 +2280,10 @@ codegen_PSUBUSB(codeblock_t *block, uop_t *uop) static int codegen_PSUBUSW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PSUBUSW_XREG_XREG(block, dest_reg, src_reg_b); @@ -2109,8 +2298,10 @@ codegen_PSUBUSW(codeblock_t *block, uop_t *uop) static int codegen_PUNPCKHBW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PUNPCKLBW_XREG_XREG(block, dest_reg, src_reg_b); @@ -2125,8 +2316,10 @@ codegen_PUNPCKHBW(codeblock_t *block, uop_t *uop) static int codegen_PUNPCKHWD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PUNPCKLWD_XREG_XREG(block, dest_reg, src_reg_b); @@ -2141,8 +2334,10 @@ codegen_PUNPCKHWD(codeblock_t *block, uop_t *uop) static int codegen_PUNPCKHDQ(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PUNPCKLDQ_XREG_XREG(block, dest_reg, src_reg_b); @@ -2157,8 +2352,10 @@ codegen_PUNPCKHDQ(codeblock_t *block, uop_t *uop) static int codegen_PUNPCKLBW(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PUNPCKLBW_XREG_XREG(block, dest_reg, src_reg_b); @@ -2172,8 +2369,10 @@ codegen_PUNPCKLBW(codeblock_t *block, uop_t *uop) static int codegen_PUNPCKLWD(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PUNPCKLWD_XREG_XREG(block, dest_reg, src_reg_b); @@ -2187,8 +2386,10 @@ codegen_PUNPCKLWD(codeblock_t *block, uop_t *uop) static int codegen_PUNPCKLDQ(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PUNPCKLDQ_XREG_XREG(block, dest_reg, src_reg_b); @@ -2203,8 +2404,11 @@ codegen_PUNPCKLDQ(codeblock_t *block, uop_t *uop) static int codegen_ROL(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int shift_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); host_x86_MOV32_REG_REG(block, REG_ECX, shift_reg); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { @@ -2229,8 +2433,10 @@ codegen_ROL(codeblock_t *block, uop_t *uop) static int codegen_ROL_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -2254,8 +2460,11 @@ codegen_ROL_IMM(codeblock_t *block, uop_t *uop) static int codegen_ROR(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int shift_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); host_x86_MOV32_REG_REG(block, REG_ECX, shift_reg); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { @@ -2280,8 +2489,10 @@ codegen_ROR(codeblock_t *block, uop_t *uop) static int codegen_ROR_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -2306,8 +2517,11 @@ codegen_ROR_IMM(codeblock_t *block, uop_t *uop) static int codegen_SAR(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int shift_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); host_x86_MOV32_REG_REG(block, REG_ECX, shift_reg); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { @@ -2332,8 +2546,10 @@ codegen_SAR(codeblock_t *block, uop_t *uop) static int codegen_SAR_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -2357,8 +2573,11 @@ codegen_SAR_IMM(codeblock_t *block, uop_t *uop) static int codegen_SHL(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int shift_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); host_x86_MOV32_REG_REG(block, REG_ECX, shift_reg); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { @@ -2383,8 +2602,10 @@ codegen_SHL(codeblock_t *block, uop_t *uop) static int codegen_SHL_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -2408,8 +2629,11 @@ codegen_SHL_IMM(codeblock_t *block, uop_t *uop) static int codegen_SHR(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real), shift_reg = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int shift_reg = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); host_x86_MOV32_REG_REG(block, REG_ECX, shift_reg); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { @@ -2434,8 +2658,10 @@ codegen_SHR(codeblock_t *block, uop_t *uop) static int codegen_SHR_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -2479,8 +2705,12 @@ codegen_STORE_PTR_IMM_16(codeblock_t *block, uop_t *uop) static int codegen_SUB(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_a = HOST_REG_GET(uop->src_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_a = HOST_REG_GET(uop->src_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size_a) && REG_IS_L(src_size_b)) { if (uop->dest_reg_a_real != uop->src_reg_a_real) @@ -2504,8 +2734,10 @@ codegen_SUB(codeblock_t *block, uop_t *uop) static int codegen_SUB_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg = HOST_REG_GET(uop->src_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg = HOST_REG_GET(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) { if (dest_reg != src_reg) @@ -2573,8 +2805,11 @@ codegen_TEST_JS_DEST(codeblock_t *block, uop_t *uop) static int codegen_XOR(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); + int src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); + int src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_PXOR_XREG_XREG(block, dest_reg, src_reg_b); @@ -2595,7 +2830,8 @@ static int codegen_XOR_IMM(codeblock_t *block, uop_t *uop) { int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); - int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size) && uop->dest_reg_a_real == uop->src_reg_a_real) { host_x86_XOR32_REG_IMM(block, dest_reg, uop->imm_data); diff --git a/src/codegen_new/codegen_block.c b/src/codegen_new/codegen_block.c index c519b34d2..3a1a5e1ab 100644 --- a/src/codegen_new/codegen_block.c +++ b/src/codegen_new/codegen_block.c @@ -21,7 +21,8 @@ uint8_t *block_write_data = NULL; -int codegen_flat_ds, codegen_flat_ss; +int codegen_flat_ds; +int codegen_flat_ss; int mmx_ebx_ecx_loaded; int codegen_flags_changed = 0; int codegen_fpu_entered = 0; @@ -61,7 +62,8 @@ static void delete_dirty_block(codeblock_t *block); The size of this list is limited to DIRTY_LIST_MAX_SIZE blocks. When this is exceeded the oldest entry will be moved to the free list.*/ -static uint16_t block_dirty_list_head, block_dirty_list_tail; +static uint16_t block_dirty_list_head; +static uint16_t block_dirty_list_tail; static int dirty_list_size = 0; #define DIRTY_LIST_MAX_SIZE 64 @@ -210,13 +212,11 @@ block_free_list_get(void) void codegen_init(void) { - int c; - codegen_allocator_init(); codegen_backend_init(); block_free_list = 0; - for (c = 0; c < BLOCK_SIZE; c++) + for (uint32_t c = 0; c < BLOCK_SIZE; c++) block_free_list_add(&codeblock[c]); block_dirty_list_head = block_dirty_list_tail = 0; dirty_list_size = 0; @@ -472,7 +472,6 @@ codegen_check_flush(page_t *page, uint64_t mask, uint32_t phys_addr) { uint16_t block_nr = page->block; int remove_from_evict_list = 0; - int c; while (block_nr) { codeblock_t *block = &codeblock[block_nr]; @@ -509,7 +508,7 @@ codegen_check_flush(page_t *page, uint64_t mask, uint32_t phys_addr) page->code_present_mask &= ~page->dirty_mask; page->dirty_mask = 0; - for (c = 0; c < 64; c++) { + for (uint8_t c = 0; c < 64; c++) { if (page->byte_code_present_mask[c] & page->byte_dirty_mask[c]) remove_from_evict_list = 0; page->byte_code_present_mask[c] &= ~page->byte_dirty_mask[c]; diff --git a/src/codegen_new/codegen_ir.c b/src/codegen_new/codegen_ir.c index bc38a3666..44689a5d1 100644 --- a/src/codegen_new/codegen_ir.c +++ b/src/codegen_new/codegen_ir.c @@ -12,7 +12,8 @@ extern int has_ea; static ir_data_t ir_block; -static int codegen_unroll_start, codegen_unroll_count; +static int codegen_unroll_start; +static int codegen_unroll_count; static int codegen_unroll_first_instruction; ir_data_t * @@ -64,13 +65,12 @@ codegen_ir_compile(ir_data_t *ir, codeblock_t *block) int c; if (codegen_unroll_count) { - int unroll_count; int unroll_end; codegen_set_loop_start(ir, codegen_unroll_first_instruction); unroll_end = ir->wr_pos; - for (unroll_count = 1; unroll_count < codegen_unroll_count; unroll_count++) { + for (int unroll_count = 1; unroll_count < codegen_unroll_count; unroll_count++) { int offset = ir->wr_pos - codegen_unroll_start; // pclog("Unroll from %i to %i, offset %i - iteration %i\n", codegen_unroll_start, ir->wr_pos, offset, unroll_count); for (c = codegen_unroll_start; c < unroll_end; c++) { diff --git a/src/codegen_new/codegen_ops.c b/src/codegen_new/codegen_ops.c index 3fadd4a13..ae93aa80f 100644 --- a/src/codegen_new/codegen_ops.c +++ b/src/codegen_new/codegen_ops.c @@ -144,6 +144,54 @@ RecompOpFn recomp_opcodes_0f[512] = { // clang-format on }; +RecompOpFn recomp_opcodes_0f_no_mmx[512] = { + // clang-format off + /*16-bit data*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*10*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*20*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*30*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*40*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*50*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*60*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*70*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*80*/ ropJO_16, ropJNO_16, ropJB_16, ropJNB_16, ropJE_16, ropJNE_16, ropJBE_16, ropJNBE_16, ropJS_16, ropJNS_16, ropJP_16, ropJNP_16, ropJL_16, ropJNL_16, ropJLE_16, ropJNLE_16, +/*90*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*a0*/ ropPUSH_FS_16, ropPOP_FS_16, NULL, NULL, ropSHLD_16_imm, NULL, NULL, NULL, ropPUSH_GS_16, ropPOP_GS_16, NULL, NULL, ropSHRD_16_imm, NULL, NULL, NULL, +/*b0*/ NULL, NULL, ropLSS_16, NULL, ropLFS_16, ropLGS_16, ropMOVZX_16_8, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ropMOVSX_16_8, NULL, + +/*c0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*d0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*e0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*f0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + + /*32-bit data*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*10*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*20*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*30*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*40*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*50*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*60*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*70*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + +/*80*/ ropJO_32, ropJNO_32, ropJB_32, ropJNB_32, ropJE_32, ropJNE_32, ropJBE_32, ropJNBE_32, ropJS_32, ropJNS_32, ropJP_32, ropJNP_32, ropJL_32, ropJNL_32, ropJLE_32, ropJNLE_32, +/*90*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*a0*/ ropPUSH_FS_32, ropPOP_FS_32, NULL, NULL, ropSHLD_32_imm, NULL, NULL, NULL, ropPUSH_GS_32, ropPOP_GS_32, NULL, NULL, ropSHRD_32_imm, NULL, NULL, NULL, +/*b0*/ NULL, NULL, ropLSS_32, NULL, ropLFS_32, ropLGS_32, ropMOVZX_32_8, ropMOVZX_32_16, NULL, NULL, NULL, NULL, NULL, NULL, ropMOVSX_32_8, ropMOVSX_32_16, + +/*c0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*d0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*e0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +/*f0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // clang-format on +}; + RecompOpFn recomp_opcodes_3DNOW[256] = { // clang-format off #if defined __ARM_EABI__ || defined _ARM_ || defined _M_ARM || defined __aarch64__ || defined _M_ARM64 @@ -556,3 +604,4 @@ RecompOpFn recomp_opcodes_df[512] = { /*f0*/ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // clang-format on }; + diff --git a/src/codegen_new/codegen_ops.h b/src/codegen_new/codegen_ops.h index 9cef07e15..352d95f13 100644 --- a/src/codegen_new/codegen_ops.h +++ b/src/codegen_new/codegen_ops.h @@ -9,6 +9,7 @@ typedef uint32_t (*RecompOpFn)(codeblock_t *block, struct ir_data_t *ir, uint8_t extern RecompOpFn recomp_opcodes[512]; extern RecompOpFn recomp_opcodes_0f[512]; +extern RecompOpFn recomp_opcodes_0f_no_mmx[512]; extern RecompOpFn recomp_opcodes_3DNOW[256]; extern RecompOpFn recomp_opcodes_d8[512]; extern RecompOpFn recomp_opcodes_d9[512]; diff --git a/src/codegen_new/codegen_ops_branch.c b/src/codegen_new/codegen_ops_branch.c index 85ebd3f8e..9a6722342 100644 --- a/src/codegen_new/codegen_ops_branch.c +++ b/src/codegen_new/codegen_ops_branch.c @@ -264,7 +264,8 @@ ropJNE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t ne static int ropJBE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t next_pc) { - int jump_uop, jump_uop2 = -1; + int jump_uop; + int jump_uop2 = -1; int do_unroll = ((CF_SET() || ZF_SET()) && codegen_can_unroll(block, ir, next_pc, dest_addr)); switch (codegen_flags_changed ? cpu_state.flags_op : FLAGS_UNKNOWN) { @@ -331,7 +332,8 @@ ropJBE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t ne static int ropJNBE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t next_pc) { - int jump_uop, jump_uop2 = -1; + int jump_uop; + int jump_uop2 = -1; int do_unroll = ((!CF_SET() && !ZF_SET()) && codegen_can_unroll(block, ir, next_pc, dest_addr)); switch (codegen_flags_changed ? cpu_state.flags_op : FLAGS_UNKNOWN) { @@ -686,7 +688,8 @@ ropJNL_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t ne static int ropJLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t next_pc) { - int jump_uop, jump_uop2 = -1; + int jump_uop; + int jump_uop2 = -1; int do_unroll = (((NF_SET() ? 1 : 0) != (VF_SET() ? 1 : 0) || ZF_SET()) && codegen_can_unroll(block, ir, next_pc, dest_addr)); switch (codegen_flags_changed ? cpu_state.flags_op : FLAGS_UNKNOWN) { @@ -748,7 +751,8 @@ ropJLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t ne static int ropJNLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t next_pc) { - int jump_uop, jump_uop2 = -1; + int jump_uop; + int jump_uop2 = -1; int do_unroll = ((NF_SET() ? 1 : 0) == (VF_SET() ? 1 : 0) && !ZF_SET() && codegen_can_unroll(block, ir, next_pc, dest_addr)); switch (codegen_flags_changed ? cpu_state.flags_op : FLAGS_UNKNOWN) { @@ -928,7 +932,8 @@ ropLOOPE(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, u { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; - int jump_uop, jump_uop2; + int jump_uop; + int jump_uop2; if (!(op_32 & 0x100)) dest_addr &= 0xffff; @@ -960,7 +965,8 @@ ropLOOPNE(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; - int jump_uop, jump_uop2; + int jump_uop; + int jump_uop2; if (!(op_32 & 0x100)) dest_addr &= 0xffff; diff --git a/src/codegen_new/codegen_ops_misc.c b/src/codegen_new/codegen_ops_misc.c index 7f7613dbf..9a23536ed 100644 --- a/src/codegen_new/codegen_ops_misc.c +++ b/src/codegen_new/codegen_ops_misc.c @@ -269,7 +269,8 @@ uint32_t ropFF_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) { x86seg *target_seg = NULL; - int src_reg, sp_reg; + int src_reg; + int sp_reg; if ((fetchdat & 0x38) != 0x00 && (fetchdat & 0x38) != 0x08 && (fetchdat & 0x38) != 0x10 && (fetchdat & 0x38) != 0x20 && (fetchdat & 0x38) != 0x28 && (fetchdat & 0x38) != 0x30) return 0; @@ -367,7 +368,8 @@ uint32_t ropFF_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) { x86seg *target_seg = NULL; - int src_reg, sp_reg; + int src_reg; + int sp_reg; if ((fetchdat & 0x38) != 0x00 && (fetchdat & 0x38) != 0x08 && (fetchdat & 0x38) != 0x10 && (fetchdat & 0x38) != 0x20 && (fetchdat & 0x38) != 0x28 && (fetchdat & 0x38) != 0x30) return 0; diff --git a/src/codegen_new/codegen_reg.c b/src/codegen_new/codegen_reg.c index 7cd7b418a..63277690f 100644 --- a/src/codegen_new/codegen_reg.c +++ b/src/codegen_new/codegen_reg.c @@ -30,7 +30,8 @@ typedef struct host_reg_set_t { int nr_regs; } host_reg_set_t; -static host_reg_set_t host_reg_set, host_fp_reg_set; +static host_reg_set_t host_reg_set; +static host_reg_set_t host_fp_reg_set; enum { REG_BYTE, @@ -182,9 +183,7 @@ struct void codegen_reg_mark_as_required(void) { - int reg; - - for (reg = 0; reg < IREG_COUNT; reg++) { + for (uint8_t reg = 0; reg < IREG_COUNT; reg++) { int last_version = reg_last_version[reg]; if (last_version > 0 && ireg_data[reg].is_volatile == REG_PERMANENT) @@ -533,9 +532,8 @@ alloc_reg(ir_reg_t ir_reg) { host_reg_set_t *reg_set = get_reg_set(ir_reg); int nr_regs = (reg_set == &host_reg_set) ? CODEGEN_HOST_REGS : CODEGEN_HOST_FP_REGS; - int c; - for (c = 0; c < nr_regs; c++) { + for (int c = 0; c < nr_regs; c++) { if (IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(ir_reg.reg)) { #ifndef RELEASE_BUILD if (reg_set->regs[c].version != ir_reg.version) @@ -552,9 +550,8 @@ alloc_dest_reg(ir_reg_t ir_reg, int dest_reference) { host_reg_set_t *reg_set = get_reg_set(ir_reg); int nr_regs = (reg_set == &host_reg_set) ? CODEGEN_HOST_REGS : CODEGEN_HOST_FP_REGS; - int c; - for (c = 0; c < nr_regs; c++) { + for (int c = 0; c < nr_regs; c++) { if (IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(ir_reg.reg)) { if (reg_set->regs[c].version == ir_reg.version) { reg_set->locked |= (1 << c); @@ -737,10 +734,9 @@ int codegen_reg_is_loaded(ir_reg_t ir_reg) { host_reg_set_t *reg_set = get_reg_set(ir_reg); - int c; /*Search for previous version in host register*/ - for (c = 0; c < reg_set->nr_regs; c++) { + for (int c = 0; c < reg_set->nr_regs; c++) { if (!ir_reg_is_invalid(reg_set->regs[c]) && IREG_GET_REG(reg_set->regs[c].reg) == IREG_GET_REG(ir_reg.reg)) { if (reg_set->regs[c].version <= ir_reg.version - 1) { # ifndef RELEASE_BUILD diff --git a/src/config.c b/src/config.c index 6399c91ab..d917d4548 100644 --- a/src/config.c +++ b/src/config.c @@ -78,7 +78,10 @@ #include <86box/ui.h> #include <86box/snd_opl.h> -static int cx, cy, cw, ch; +static int cx; +static int cy; +static int cw; +static int ch; static ini_t config; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ @@ -223,8 +226,9 @@ static void load_monitor(int monitor_index) { ini_section_t cat; - char name[512], temp[512]; - char *p = NULL; + char name[512]; + char temp[512]; + const char *p = NULL; sprintf(name, "Monitor #%i", monitor_index + 1); sprintf(temp, "%i, %i, %i, %i", cx, cy, cw, ch); @@ -251,8 +255,14 @@ static void load_machine(void) { ini_section_t cat = ini_find_section(config, "Machine"); - char *p, *migrate_from = NULL; - int c, i, j, speed, legacy_mfg, legacy_cpu; + char *p; + const char *migrate_from = NULL; + int c; + int i; + int j; + int speed; + int legacy_mfg; + int legacy_cpu; double multi; p = ini_section_get_string(cat, "machine", NULL); @@ -438,7 +448,7 @@ load_machine(void) cpu_f = cpu_get_family(legacy_table_entry->family); if (cpu_f) { /* Save the new values. */ - ini_section_set_string(cat, "cpu_family", (char *) legacy_table_entry->family); + ini_section_set_string(cat, "cpu_family", legacy_table_entry->family); ini_section_set_int(cat, "cpu_speed", legacy_table_entry->rspeed); ini_section_set_double(cat, "cpu_multi", legacy_table_entry->multi); } @@ -490,7 +500,7 @@ load_machine(void) cpu_waitstates = ini_section_get_int(cat, "cpu_waitstates", 0); - p = (char *) ini_section_get_string(cat, "fpu_type", "none"); + p = ini_section_get_string(cat, "fpu_type", "none"); fpu_type = fpu_get_type(cpu_f, cpu, p); mem_size = ini_section_get_int(cat, "mem_size", 64); @@ -504,6 +514,9 @@ load_machine(void) mem_size = machine_get_max_ram(machine); cpu_use_dynarec = !!ini_section_get_int(cat, "cpu_use_dynarec", 0); + fpu_softfloat = !!ini_section_get_int(cat, "fpu_softfloat", 0); + if (machine_has_flags(machine, MACHINE_SOFTFLOAT_ONLY)) + fpu_softfloat = 1; p = ini_section_get_string(cat, "time_sync", NULL); if (p != NULL) { @@ -574,7 +587,8 @@ load_input_devices(void) { ini_section_t cat = ini_find_section(config, "Input devices"); char temp[512]; - int c, d; + int c; + int d; char *p; p = ini_section_get_string(cat, "mouse_type", NULL); @@ -718,6 +732,24 @@ load_sound(void) mpu401_standalone_enable = !!ini_section_get_int(cat, "mpu401_standalone", 0); + /* Backwards compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ + const char *legacy_cards[][2] = { + {"ssi2001", "ssi2001"}, + { "gameblaster", "cms" }, + { "gus", "gus" } + }; + for (int i = 0, j = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { + if (ini_section_get_int(cat, legacy_cards[i][0], 0) == 1) { + /* Migrate to the first available sound card slot. */ + for (; j < (sizeof(sound_card_current) / sizeof(sound_card_current[0])); j++) { + if (!sound_card_current[j]) { + sound_card_current[j] = sound_card_get_from_internal_name(legacy_cards[i][1]); + break; + } + } + } + } + memset(temp, '\0', sizeof(temp)); p = ini_section_get_string(cat, "sound_type", "float"); if (strlen(p) > 511) @@ -744,7 +776,8 @@ load_network(void) ini_section_t cat = ini_find_section(config, "Network"); char *p; char temp[512]; - uint16_t c = 0, min = 0; + uint16_t c = 0; + uint16_t min = 0; /* Handle legacy configuration which supported only one NIC */ p = ini_section_get_string(cat, "net_card", NULL); @@ -757,6 +790,8 @@ load_network(void) net_cards_conf[c].net_type = NET_TYPE_PCAP; else if (!strcmp(p, "slirp") || !strcmp(p, "2")) net_cards_conf[c].net_type = NET_TYPE_SLIRP; + else if (!strcmp(p, "vde") || !strcmp(p, "2")) + net_cards_conf[c].net_type = NET_TYPE_VDE; else net_cards_conf[c].net_type = NET_TYPE_NONE; } else { @@ -765,13 +800,17 @@ load_network(void) p = ini_section_get_string(cat, "net_host_device", NULL); if (p != NULL) { - if ((network_dev_to_id(p) == -1) || (network_ndev == 1)) { - if (network_ndev == 1) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2095, (wchar_t *) IDS_2130); - } else if (network_dev_to_id(p) == -1) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2096, (wchar_t *) IDS_2130); + if (net_cards_conf[c].net_type == NET_TYPE_PCAP) { + if ((network_dev_to_id(p) == -1) || (network_ndev == 1)) { + if (network_ndev == 1) { + ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2095, (wchar_t *) IDS_2130); + } else if (network_dev_to_id(p) == -1) { + ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2096, (wchar_t *) IDS_2130); + } + strcpy(net_cards_conf[c].host_dev_name, "none"); + } else { + strncpy(net_cards_conf[c].host_dev_name, p, sizeof(net_cards_conf[c].host_dev_name) - 1); } - strcpy(net_cards_conf[c].host_dev_name, "none"); } else { strncpy(net_cards_conf[c].host_dev_name, p, sizeof(net_cards_conf[c].host_dev_name) - 1); } @@ -802,6 +841,8 @@ load_network(void) net_cards_conf[c].net_type = NET_TYPE_PCAP; } else if (!strcmp(p, "slirp") || !strcmp(p, "2")) { net_cards_conf[c].net_type = NET_TYPE_SLIRP; + } else if (!strcmp(p, "vde") || !strcmp(p, "2")) { + net_cards_conf[c].net_type = NET_TYPE_VDE; } else { net_cards_conf[c].net_type = NET_TYPE_NONE; } @@ -812,13 +853,17 @@ load_network(void) sprintf(temp, "net_%02i_host_device", c + 1); p = ini_section_get_string(cat, temp, NULL); if (p != NULL) { - if ((network_dev_to_id(p) == -1) || (network_ndev == 1)) { - if (network_ndev == 1) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2095, (wchar_t *) IDS_2130); - } else if (network_dev_to_id(p) == -1) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2096, (wchar_t *) IDS_2130); + if (net_cards_conf[c].net_type == NET_TYPE_PCAP) { + if ((network_dev_to_id(p) == -1) || (network_ndev == 1)) { + if (network_ndev == 1) { + ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2095, (wchar_t *) IDS_2130); + } else if (network_dev_to_id(p) == -1) { + ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2096, (wchar_t *) IDS_2130); + } + strcpy(net_cards_conf[c].host_dev_name, "none"); + } else { + strncpy(net_cards_conf[c].host_dev_name, p, sizeof(net_cards_conf[c].host_dev_name) - 1); } - strcpy(net_cards_conf[c].host_dev_name, "none"); } else { strncpy(net_cards_conf[c].host_dev_name, p, sizeof(net_cards_conf[c].host_dev_name) - 1); } @@ -839,7 +884,8 @@ load_ports(void) ini_section_t cat = ini_find_section(config, "Ports (COM & LPT)"); char *p; char temp[512]; - int c, d; + int c; + int d; memset(temp, 0, sizeof(temp)); @@ -847,11 +893,11 @@ load_ports(void) sprintf(temp, "serial%d_enabled", c + 1); com_ports[c].enabled = !!ini_section_get_int(cat, temp, (c >= 2) ? 0 : 1); - /* +#if 0 sprintf(temp, "serial%d_device", c + 1); p = (char *) ini_section_get_string(cat, temp, "none"); com_ports[c].device = com_device_get_from_internal_name(p); - */ +#endif sprintf(temp, "serial%d_passthrough_enabled", c + 1); serial_passthrough_enabled[c] = !!ini_section_get_int(cat, temp, 0); @@ -865,7 +911,7 @@ load_ports(void) lpt_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0); sprintf(temp, "lpt%d_device", c + 1); - p = (char *) ini_section_get_string(cat, temp, "none"); + p = ini_section_get_string(cat, temp, "none"); lpt_ports[c].device = lpt_device_get_from_internal_name(p); } @@ -883,8 +929,10 @@ static void load_storage_controllers(void) { ini_section_t cat = ini_find_section(config, "Storage controllers"); - char *p, temp[512]; - int c, min = 0; + char *p; + char temp[512]; + int c; + int min = 0; int free_p = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ @@ -955,9 +1003,11 @@ load_storage_controllers(void) ide_ter_enabled = !!ini_section_get_int(cat, "ide_ter", 0); ide_qua_enabled = !!ini_section_get_int(cat, "ide_qua", 0); - /* TODO: Re-enable by default after we actually have a proper machine flag for this. */ - cassette_enable = !!ini_section_get_int(cat, "cassette_enabled", 0); - p = ini_section_get_string(cat, "cassette_file", ""); + if (machine_has_bus(machine, MACHINE_BUS_CASSETTE)) + cassette_enable = !!ini_section_get_int(cat, "cassette_enabled", 0); + else + cassette_enable = 0; + p = ini_section_get_string(cat, "cassette_file", ""); if (strlen(p) > 511) fatal("load_storage_controllers(): strlen(p) > 511\n"); else @@ -1006,15 +1056,18 @@ static void load_hard_disks(void) { ini_section_t cat = ini_find_section(config, "Hard disks"); - char temp[512], tmp2[512]; + char temp[512]; + char tmp2[512]; char s[512]; - int c; char *p; - uint32_t max_spt, max_hpc, max_tracks; - uint32_t board = 0, dev = 0; + uint32_t max_spt; + uint32_t max_hpc; + uint32_t max_tracks; + uint32_t board = 0; + uint32_t dev = 0; memset(temp, '\0', sizeof(temp)); - for (c = 0; c < HDD_NUM; c++) { + for (uint8_t c = 0; c < HDD_NUM; c++) { sprintf(temp, "hdd_%02i_parameters", c + 1); p = ini_section_get_string(cat, temp, "0, 0, 0, 0, none"); sscanf(p, "%u, %u, %u, %i, %s", @@ -1022,8 +1075,8 @@ load_hard_disks(void) hdd[c].bus = hdd_string_to_bus(s, 0); switch (hdd[c].bus) { - case HDD_BUS_DISABLED: default: + case HDD_BUS_DISABLED: max_spt = max_hpc = max_tracks = 0; break; @@ -1142,7 +1195,6 @@ load_hard_disks(void) ini_section_delete_var(cat, temp); memset(hdd[c].fn, 0x00, sizeof(hdd[c].fn)); - memset(hdd[c].prev_fn, 0x00, sizeof(hdd[c].prev_fn)); sprintf(temp, "hdd_%02i_fn", c + 1); p = ini_section_get_string(cat, temp, ""); @@ -1175,6 +1227,13 @@ load_hard_disks(void) } path_normalize(hdd[c].fn); + sprintf(temp, "hdd_%02i_vhd_blocksize", c + 1); + hdd[c].vhd_blocksize = ini_section_get_int(cat, temp, 0); + + sprintf(temp, "hdd_%02i_vhd_parent", c + 1); + p = ini_section_get_string(cat, temp, ""); + strncpy(hdd[c].vhd_parent, p, sizeof(hdd[c].vhd_parent) - 1); + /* If disk is empty or invalid, mark it for deletion. */ if (!hdd_is_valid(c)) { sprintf(temp, "hdd_%02i_parameters", c + 1); @@ -1207,13 +1266,13 @@ static void load_floppy_drives(void) { ini_section_t cat = ini_find_section(config, "Floppy drives"); - char temp[512], *p; - int c; + char temp[512]; + char *p; if (!backwards_compat) return; - for (c = 0; c < FDD_NUM; c++) { + for (uint8_t c = 0; c < FDD_NUM; c++) { sprintf(temp, "fdd_%02i_type", c + 1); p = ini_section_get_string(cat, temp, (c < 2) ? "525_2dd" : "none"); fdd_set_type(c, fdd_get_from_internal_name(p)); @@ -1247,8 +1306,10 @@ load_floppy_drives(void) else strncpy(floppyfns[c], p, 511); - /* if (*wp != L'\0') - config_log("Floppy%d: %ls\n", c, floppyfns[c]); */ +#if 0 + if (*wp != L'\0') + config_log("Floppy%d: %ls\n", c, floppyfns[c]); +#endif sprintf(temp, "fdd_%02i_writeprot", c + 1); ui_writeprot[c] = !!ini_section_get_int(cat, temp, 0); ini_section_delete_var(cat, temp); @@ -1268,10 +1329,14 @@ static void load_floppy_and_cdrom_drives(void) { ini_section_t cat = ini_find_section(config, "Floppy and CD-ROM drives"); - char temp[512], tmp2[512], *p; + char temp[512]; + char tmp2[512]; + char *p; char s[512]; - unsigned int board = 0, dev = 0; - int c, d = 0; + unsigned int board = 0; + unsigned int dev = 0; + int c; + int d = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ backwards_compat = (cat == NULL); @@ -1309,8 +1374,10 @@ load_floppy_and_cdrom_drives(void) else strncpy(floppyfns[c], p, 511); - /* if (*wp != L'\0') - config_log("Floppy%d: %ls\n", c, floppyfns[c]); */ +#if 0 + if (*wp != L'\0') + config_log("Floppy%d: %ls\n", c, floppyfns[c]); +#endif sprintf(temp, "fdd_%02i_writeprot", c + 1); ui_writeprot[c] = !!ini_section_get_int(cat, temp, 0); sprintf(temp, "fdd_%02i_turbo", c + 1); @@ -1488,10 +1555,14 @@ static void load_other_removable_devices(void) { ini_section_t cat = ini_find_section(config, "Other removable devices"); - char temp[512], tmp2[512], *p; + char temp[512]; + char tmp2[512]; + const char *p; char s[512]; - unsigned int board = 0, dev = 0; - int c, d = 0; + unsigned int board = 0; + unsigned int dev = 0; + int c; + int d = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ if (backwards_compat) { @@ -1766,7 +1837,7 @@ load_other_peripherals(void) ini_section_t cat = ini_find_section(config, "Other peripherals"); char *p; char temp[512]; - int c, free_p = 0; + int free_p = 0; if (backwards_compat2) { p = ini_section_get_string(cat, "scsicard", NULL); @@ -1823,7 +1894,7 @@ load_other_peripherals(void) bugger_enabled = !!ini_section_get_int(cat, "bugger_enabled", 0); postcard_enabled = !!ini_section_get_int(cat, "postcard_enabled", 0); - for (c = 0; c < ISAMEM_MAX; c++) { + for (uint8_t c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); p = ini_section_get_string(cat, temp, "none"); @@ -1901,8 +1972,7 @@ config_load(void) for (i = 0; i < ISAMEM_MAX; i++) isamem_type[i] = 0; - /* TODO: Re-enable by default when we have a proper machine flag for this. */ - cassette_enable = 0; + cassette_enable = 1; memset(cassette_fname, 0x00, sizeof(cassette_fname)); memcpy(cassette_mode, "load", strlen("load") + 1); cassette_pos = 0; @@ -1944,9 +2014,10 @@ static void save_general(void) { ini_section_t cat = ini_find_or_create_section(config, "General"); - char temp[512], buffer[512] = { 0 }; + char temp[512]; + char buffer[512] = { 0 }; - char *va_name; + const char *va_name = NULL; ini_section_set_int(cat, "vid_resize", vid_resize); if (vid_resize == 0) @@ -2145,13 +2216,17 @@ static void save_machine(void) { ini_section_t cat = ini_find_or_create_section(config, "Machine"); - char *p; - int c, i = 0, legacy_mfg, legacy_cpu = -1, closest_legacy_cpu = -1; + const char *p; + int c; + int i = 0; + int legacy_mfg; + int legacy_cpu = -1; + int closest_legacy_cpu = -1; p = machine_get_internal_name(); ini_section_set_string(cat, "machine", p); - ini_section_set_string(cat, "cpu_family", (char *) cpu_f->internal_name); + ini_section_set_string(cat, "cpu_family", cpu_f->internal_name); ini_section_set_int(cat, "cpu_speed", cpu_f->cpus[cpu].rspeed); ini_section_set_double(cat, "cpu_multi", cpu_f->cpus[cpu].multi); if (cpu_override) @@ -2159,7 +2234,7 @@ save_machine(void) else ini_section_delete_var(cat, "cpu_override"); - /* Forwards compatibility with the previous CPU model system. */ + /* Downgrade compatibility with the previous CPU model system. */ ini_section_delete_var(cat, "cpu_manufacturer"); ini_section_delete_var(cat, "cpu"); @@ -2172,14 +2247,14 @@ save_machine(void) } if (cpu_legacy_table[c].machine) { /* Look for a corresponding CPU entry. */ - cpu_legacy_table_t *legacy_table_entry; + const cpu_legacy_table_t *legacy_table_entry; for (legacy_mfg = 0; legacy_mfg < 4; legacy_mfg++) { if (!cpu_legacy_table[c].tables[legacy_mfg]) continue; i = 0; while (cpu_legacy_table[c].tables[legacy_mfg][i].family) { - legacy_table_entry = (cpu_legacy_table_t *) &cpu_legacy_table[c].tables[legacy_mfg][i]; + legacy_table_entry = &cpu_legacy_table[c].tables[legacy_mfg][i]; /* Match the family name, speed and multiplier. */ if (!strcmp(cpu_f->internal_name, legacy_table_entry->family)) { @@ -2219,13 +2294,14 @@ save_machine(void) if (fpu_type == 0) ini_section_delete_var(cat, "fpu_type"); else - ini_section_set_string(cat, "fpu_type", (char *) fpu_get_internal_name(cpu_f, cpu, fpu_type)); + ini_section_set_string(cat, "fpu_type", fpu_get_internal_name(cpu_f, cpu, fpu_type)); // Write the mem_size explicitly to the setttings in order to help managers to display it without having the actual machine table ini_section_delete_var(cat, "mem_size"); ini_section_set_int(cat, "mem_size", mem_size); ini_section_set_int(cat, "cpu_use_dynarec", cpu_use_dynarec); + ini_section_set_int(cat, "fpu_softfloat", fpu_softfloat); if (time_sync & TIME_SYNC_ENABLED) if (time_sync & TIME_SYNC_UTC) @@ -2290,8 +2366,10 @@ static void save_input_devices(void) { ini_section_t cat = ini_find_or_create_section(config, "Input devices"); - char temp[512], tmp2[512]; - int c, d; + char temp[512]; + char tmp2[512]; + int c; + int d; ini_section_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); @@ -2390,6 +2468,27 @@ save_sound(void) else ini_section_set_int(cat, "mpu401_standalone", mpu401_standalone_enable); + /* Downgrade compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ + const char *legacy_cards[][2] = { + {"ssi2001", "ssi2001"}, + { "gameblaster", "cms" }, + { "gus", "gus" } + }; + for (int i = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { + int card_id = sound_card_get_from_internal_name(legacy_cards[i][1]); + for (int j = 0; j < (sizeof(sound_card_current) / sizeof(sound_card_current[0])); j++) { + if (sound_card_current[j] == card_id) { + /* A special value of 2 still enables the cards on older versions, + but lets newer versions know that they've already been migrated. */ + ini_section_set_int(cat, legacy_cards[i][0], 2); + card_id = 0; /* mark as found */ + break; + } + } + if (card_id > 0) /* not found */ + ini_section_delete_var(cat, legacy_cards[i][0]); + } + if (sound_is_float == 1) ini_section_delete_var(cat, "sound_type"); else @@ -2404,7 +2503,6 @@ save_sound(void) static void save_network(void) { - int c = 0; char temp[512]; ini_section_t cat = ini_find_or_create_section(config, "Network"); @@ -2412,7 +2510,7 @@ save_network(void) ini_section_delete_var(cat, "net_host_device"); ini_section_delete_var(cat, "net_card"); - for (c = 0; c < NET_CARD_MAX; c++) { + for (uint8_t c = 0; c < NET_CARD_MAX; c++) { sprintf(temp, "net_%02i_card", c + 1); if (net_cards_conf[c].device_num == 0) { ini_section_delete_var(cat, temp); @@ -2421,11 +2519,22 @@ save_network(void) } sprintf(temp, "net_%02i_net_type", c + 1); - if (net_cards_conf[c].net_type == NET_TYPE_NONE) { - ini_section_delete_var(cat, temp); - } else { - ini_section_set_string(cat, temp, - (net_cards_conf[c].net_type == NET_TYPE_SLIRP) ? "slirp" : "pcap"); + switch(net_cards_conf[c].net_type) { + case NET_TYPE_NONE: + ini_section_delete_var(cat, temp); + break; + case NET_TYPE_SLIRP: + ini_section_set_string(cat, temp, "slirp"); + break; + case NET_TYPE_PCAP: + ini_section_set_string(cat, temp, "pcap"); + break; + case NET_TYPE_VDE: + ini_section_set_string(cat, temp, "vde"); + break; + + default: + break; } sprintf(temp, "net_%02i_host_device", c + 1); @@ -2435,7 +2544,9 @@ save_network(void) else ini_section_set_string(cat, temp, net_cards_conf[c].host_dev_name); } else { - /* ini_section_set_string(cat, temp, "none"); */ +#if 0 + ini_section_set_string(cat, temp, "none"); +#endif ini_section_delete_var(cat, temp); } @@ -2456,7 +2567,8 @@ save_ports(void) { ini_section_t cat = ini_find_or_create_section(config, "Ports (COM & LPT)"); char temp[512]; - int c, d; + int c; + int d; for (c = 0; c < SERIAL_MAX; c++) { sprintf(temp, "serial%d_enabled", c + 1); @@ -2465,7 +2577,7 @@ save_ports(void) else ini_section_set_int(cat, temp, com_ports[c].enabled); - /* +#if 0 sprintf(temp, "serial%d_type", c + 1); if (!com_ports[c].enabled)) ini_section_delete_var(cat, temp); @@ -2478,7 +2590,7 @@ save_ports(void) else ini_section_set_string(cat, temp, (char *) com_device_get_internal_name(com_ports[c].device)); - */ +#endif sprintf(temp, "serial%d_passthrough_enabled", c + 1); if (serial_passthrough_enabled[c]) { @@ -2501,7 +2613,7 @@ save_ports(void) ini_section_delete_var(cat, temp); else ini_section_set_string(cat, temp, - (char *) lpt_device_get_internal_name(lpt_ports[c].device)); + lpt_device_get_internal_name(lpt_ports[c].device)); } ini_delete_section_if_empty(config, cat); @@ -2609,7 +2721,6 @@ save_other_peripherals(void) { ini_section_t cat = ini_find_or_create_section(config, "Other peripherals"); char temp[512]; - int c; if (bugger_enabled == 0) ini_section_delete_var(cat, "bugger_enabled"); @@ -2621,13 +2732,13 @@ save_other_peripherals(void) else ini_section_set_int(cat, "postcard_enabled", postcard_enabled); - for (c = 0; c < ISAMEM_MAX; c++) { + for (uint8_t c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); if (isamem_type[c] == 0) ini_section_delete_var(cat, temp); else ini_section_set_string(cat, temp, - (char *) isamem_get_internal_name(isamem_type[c])); + isamem_get_internal_name(isamem_type[c])); } if (isartc_type == 0) @@ -2644,12 +2755,12 @@ static void save_hard_disks(void) { ini_section_t cat = ini_find_or_create_section(config, "Hard disks"); - char temp[32], tmp2[512]; + char temp[32]; + char tmp2[512]; char *p; - int c; memset(temp, 0x00, sizeof(temp)); - for (c = 0; c < HDD_NUM; c++) { + for (uint8_t c = 0; c < HDD_NUM; c++) { sprintf(temp, "hdd_%02i_parameters", c + 1); if (hdd_is_valid(c)) { p = hdd_bus_to_string(hdd[c].bus, 0); @@ -2708,11 +2819,24 @@ save_hard_disks(void) } else ini_section_delete_var(cat, temp); + sprintf(temp, "hdd_%02i_vhd_blocksize", c + 1); + if (hdd_is_valid(c) && (hdd[c].vhd_blocksize > 0)) + ini_section_set_int(cat, temp, hdd[c].vhd_blocksize); + else + ini_section_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_vhd_parent", c + 1); + if (hdd_is_valid(c) && hdd[c].vhd_parent[0]) { + path_normalize(hdd[c].vhd_parent); + ini_section_set_string(cat, temp, hdd[c].vhd_parent); + } else + ini_section_delete_var(cat, temp); + sprintf(temp, "hdd_%02i_speed", c + 1); if (!hdd_is_valid(c) || (hdd[c].bus != HDD_BUS_IDE && hdd[c].bus != HDD_BUS_ESDI)) ini_section_delete_var(cat, temp); else - ini_section_set_string(cat, temp, (char *) hdd_preset_get_internal_name(hdd[c].speed_preset)); + ini_section_set_string(cat, temp, hdd_preset_get_internal_name(hdd[c].speed_preset)); } ini_delete_section_if_empty(config, cat); @@ -2723,7 +2847,8 @@ static void save_floppy_and_cdrom_drives(void) { ini_section_t cat = ini_find_or_create_section(config, "Floppy and CD-ROM drives"); - char temp[512], tmp2[512]; + char temp[512]; + char tmp2[512]; int c; for (c = 0; c < FDD_NUM; c++) { @@ -2859,7 +2984,8 @@ static void save_other_removable_devices(void) { ini_section_t cat = ini_find_or_create_section(config, "Other removable devices"); - char temp[512], tmp2[512]; + char temp[512]; + char tmp2[512]; int c; for (c = 0; c < ZIP_NUM; c++) { @@ -2946,10 +3072,8 @@ save_other_removable_devices(void) void config_save(void) { - int i; - save_general(); /* General */ - for (i = 0; i < MONITORS_NUM; i++) + for (uint8_t i = 0; i < MONITORS_NUM; i++) save_monitor(i); save_machine(); /* Machine */ save_video(); /* Video */ diff --git a/src/cpu/386.c b/src/cpu/386.c index a5bae7de6..87d481e1f 100644 --- a/src/cpu/386.c +++ b/src/cpu/386.c @@ -46,6 +46,42 @@ uint32_t backupregs[16]; x86seg _oldds; +#if 1 +int opcode_length[256] = { 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 1, 3, /* 0x0x */ + 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, /* 0x1x */ + 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, /* 0x2x */ + 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, /* 0x3x */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x4x */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x5x */ + 1, 1, 3, 3, 1, 1, 1, 1, 3, 3, 2, 3, 1, 1, 1, 1, /* 0x6x */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x7x */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x8x */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, /* 0x9x */ + 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, /* 0xax */ + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xbx */ + 3, 3, 3, 1, 3, 3, 3, 3, 3, 1, 3, 1, 1, 2, 1, 1, /* 0xcx */ + 3, 3, 3, 3, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xdx */ + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 2, 1, 1, 1, 1, /* 0xex */ + 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 3, 3 }; /* 0xfx */ +#else +int opcode_length[256] = { 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 1, 3, /* 0x0x */ + 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, /* 0x1x */ + 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 1, /* 0x2x */ + 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 1, /* 0x3x */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x4x */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x5x */ + 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 1, 1, 1, 1, /* 0x6x */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x7x */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x8x */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, /* 0x9x */ + 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, /* 0xax */ + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xbx */ + 3, 3, 3, 1, 3, 3, 3, 3, 3, 1, 3, 1, 1, 2, 1, 1, /* 0xcx */ + 3, 3, 3, 3, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xdx */ + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 2, 1, 1, 1, 1, /* 0xex */ + 3, 1, 3, 3, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 3, 3 }; /* 0xfx */ +#endif + #ifdef ENABLE_386_LOG int x386_do_log = ENABLE_386_LOG; @@ -143,7 +179,7 @@ exec386(int cycs) cpu_state.ea_seg = &cpu_state.seg_ds; cpu_state.ssegs = 0; - fetchdat = fastreadl(cs + cpu_state.pc); + fetchdat = fastreadl_fetch(cs + cpu_state.pc); if (!cpu_state.abrt) { #ifdef ENABLE_386_LOG diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index f8e7c11ce..760e41eaa 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -780,8 +780,8 @@ smram_restore_state_p6(uint32_t *saved_state) cpu_state.seg_gs.ar_high = (saved_state[SMRAM_FIELD_P6_GS_SELECTOR_AR] >> 24) & 0xff; smm_seg_load(&cpu_state.seg_gs); - mem_a20_alt = 0; - keyboard_at_set_a20_key(!saved_state[SMRAM_FIELD_P6_A20M]); + mem_a20_alt = 0x00; + mem_a20_key = saved_state[SMRAM_FIELD_P6_A20M] ? 0x00 : 0x02; mem_a20_recalc(); if (SMM_REVISION_ID & SMM_SMBASE_RELOCATION) @@ -1053,13 +1053,13 @@ enter_smm(int in_hlt) memset(saved_state, 0x00, SMM_SAVE_STATE_MAP_SIZE * sizeof(uint32_t)); - if (is_cxsmm) /* Cx6x86 */ + if (is_cxsmm) /* Cx6x86 */ smram_save_state_cyrix(saved_state, in_hlt); else if (is_pentium || is_am486) /* Am486 / 5x86 / Intel P5 (Pentium) */ smram_save_state_p5(saved_state, in_hlt); - else if (is_k5 || is_k6) /* AMD K5 and K6 */ + else if (is_k5 || is_k6) /* AMD K5 and K6 */ smram_save_state_amd_k(saved_state, in_hlt); - else if (is_p6) /* Intel P6 (Pentium Pro, Pentium II, Celeron) */ + else if (is_p6) /* Intel P6 (Pentium Pro, Pentium II, Celeron) */ smram_save_state_p6(saved_state, in_hlt); cr0 &= ~0x8000000d; @@ -1224,13 +1224,13 @@ leave_smm(void) } x386_common_log("New SMBASE: %08X (%08X)\n", saved_state[SMRAM_FIELD_P5_SMBASE_OFFSET], saved_state[66]); - if (is_cxsmm) /* Cx6x86 */ + if (is_cxsmm) /* Cx6x86 */ smram_restore_state_cyrix(saved_state); else if (is_pentium || is_am486) /* Am486 / 5x86 / Intel P5 (Pentium) */ smram_restore_state_p5(saved_state); - else if (is_k5 || is_k6) /* AMD K5 and K6 */ + else if (is_k5 || is_k6) /* AMD K5 and K6 */ smram_restore_state_amd_k(saved_state); - else if (is_p6) /* Intel P6 (Pentium Pro, Pentium II, Celeron) */ + else if (is_p6) /* Intel P6 (Pentium Pro, Pentium II, Celeron) */ smram_restore_state_p6(saved_state); in_smm = 0; @@ -1427,25 +1427,29 @@ x86illegal(void) } int -checkio(uint32_t port) +checkio(uint32_t port, int mask) { - uint16_t t; - uint8_t d; + uint32_t t; cpl_override = 1; t = readmemw(tr.base, 0x66); - cpl_override = 0; - if (cpu_state.abrt) + if (UNLIKELY(cpu_state.abrt)) { + cpl_override = 0; return 0; + } - if ((t + (port >> 3UL)) > tr.limit) - return 1; - - cpl_override = 1; - d = readmembl(tr.base + t + (port >> 3)); + t += (port >> 3UL); + mask <<= (port & 7); + if (UNLIKELY(mask & 0xff00)) { + if (LIKELY(t < tr.limit)) + mask &= readmemwl(tr.base + t); + } else { + if (LIKELY(t <= tr.limit)) + mask &= readmembl(tr.base + t); + } cpl_override = 0; - return d & (1 << (port & 7)); + return mask; } #ifdef OLD_DIVEXCP @@ -1679,7 +1683,7 @@ sysexit(uint32_t fetchdat) cpu_cur_status &= ~(CPU_STATUS_NOTFLATSS /* | CPU_STATUS_V86*/); cpu_cur_status |= (CPU_STATUS_USE32 | CPU_STATUS_STACK32 | CPU_STATUS_PMODE); - flushmmucache_cr3(); + flushmmucache_nopc(); set_use32(1); set_stack32(1); @@ -1800,7 +1804,7 @@ sysret(uint32_t fetchdat) cpu_cur_status &= ~(CPU_STATUS_NOTFLATSS /* | CPU_STATUS_V86*/); cpu_cur_status |= (CPU_STATUS_USE32 | CPU_STATUS_STACK32 | CPU_STATUS_PMODE); - flushmmucache_cr3(); + flushmmucache_nopc(); set_use32(1); set_stack32(1); diff --git a/src/cpu/386_common.h b/src/cpu/386_common.h index f26eb7f98..8cad28ae7 100644 --- a/src/cpu/386_common.h +++ b/src/cpu/386_common.h @@ -20,6 +20,7 @@ #define _386_COMMON_H_ #include + #include #define readmemb_n(s, a, b) ((readlookup2[(uint32_t) ((s) + (a)) >> 12] == (uintptr_t) LOOKUP_INV || (s) == 0xFFFFFFFF) ? readmembl_no_mmut((s) + (a), b) : *(uint8_t *) (readlookup2[(uint32_t) ((s) + (a)) >> 12] + (uintptr_t) ((s) + (a)))) #define readmemw_n(s, a, b) ((readlookup2[(uint32_t) ((s) + (a)) >> 12] == (uintptr_t) LOOKUP_INV || (s) == 0xFFFFFFFF || (((s) + (a)) & 1)) ? readmemwl_no_mmut((s) + (a), b) : *(uint16_t *) (readlookup2[(uint32_t) ((s) + (a)) >> 12] + (uint32_t) ((s) + (a)))) @@ -97,11 +98,11 @@ if (writelookup2[(uint32_t) ((s) + (a)) >> 12] == (uintptr_t) LOOKUP_INV || (s) == 0xFFFFFFFF || (((s) + (a)) & 3)) \ do_mmutranslate((s) + (a), b, 4, 1) -int checkio(uint32_t port); +int checkio(uint32_t port, int mask); -#define check_io_perm(port) \ +#define check_io_perm(port, size) \ if (msw & 1 && ((CPL > IOPL) || (cpu_state.eflags & VM_FLAG))) { \ - int tempi = checkio(port); \ + int tempi = checkio(port, (1 << size) - 1); \ if (cpu_state.abrt) \ return 1; \ if (tempi) { \ @@ -196,13 +197,21 @@ fastreadb(uint32_t a) uint8_t *t; if ((a >> 12) == pccache) +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint8_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else return *((uint8_t *) &pccache2[a]); +#endif t = getpccache(a); if (cpu_state.abrt) return 0; pccache = a >> 12; pccache2 = t; +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint8_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else return *((uint8_t *) &pccache2[a]); +#endif } static __inline uint16_t @@ -216,14 +225,22 @@ fastreadw(uint32_t a) return val; } if ((a >> 12) == pccache) +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint16_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else return *((uint16_t *) &pccache2[a]); +#endif t = getpccache(a); if (cpu_state.abrt) return 0; pccache = a >> 12; pccache2 = t; +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint16_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else return *((uint16_t *) &pccache2[a]); +#endif } static __inline uint32_t @@ -239,7 +256,11 @@ fastreadl(uint32_t a) pccache2 = t; pccache = a >> 12; } +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint32_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else return *((uint32_t *) &pccache2[a]); +#endif } val = fastreadw(a); val |= (fastreadw(a + 2) << 16); @@ -250,13 +271,78 @@ static __inline void * get_ram_ptr(uint32_t a) { if ((a >> 12) == pccache) +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return (void *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL)); +#else return &pccache2[a]; +#endif else { uint8_t *t = getpccache(a); +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return (void *) (((uintptr_t) &t[a] & 0x00000000ffffffffULL) | ((uintptr_t) &t[0] & 0xffffffff00000000ULL)); +#else return &t[a]; +#endif } } +extern int opcode_length[256]; + +static __inline uint16_t +fastreadw_fetch(uint32_t a) +{ + uint8_t *t; + uint16_t val; + if ((a & 0xFFF) > 0xFFE) { + val = fastreadb(a); + if (opcode_length[val & 0xff] > 1) + val |= (fastreadb(a + 1) << 8); + return val; + } + if ((a >> 12) == pccache) +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint16_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else + return *((uint16_t *) &pccache2[a]); +#endif + t = getpccache(a); + if (cpu_state.abrt) + return 0; + + pccache = a >> 12; + pccache2 = t; +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint16_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else + return *((uint16_t *) &pccache2[a]); +#endif +} + +static __inline uint32_t +fastreadl_fetch(uint32_t a) +{ + uint8_t *t; + uint32_t val; + if ((a & 0xFFF) < 0xFFD) { + if ((a >> 12) != pccache) { + t = getpccache(a); + if (cpu_state.abrt) + return 0; + pccache2 = t; + pccache = a >> 12; + } +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + return *((uint32_t *) (((uintptr_t) &pccache2[a] & 0x00000000ffffffffULL) | ((uintptr_t) &pccache2[0] & 0xffffffff00000000ULL))); +#else + return *((uint32_t *) &pccache2[a]); +#endif + } + val = fastreadw_fetch(a); + if (opcode_length[val & 0xff] > 2) + val |= (fastreadw(a + 2) << 16); + return val; +} + static __inline uint8_t getbyte(void) { diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index f2e04b54a..d7b3751b2 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -348,7 +348,7 @@ exec386_dynarec_int(void) cpu_state.ea_seg = &cpu_state.seg_ds; cpu_state.ssegs = 0; - fetchdat = fastreadl(cs + cpu_state.pc); + fetchdat = fastreadl_fetch(cs + cpu_state.pc); # ifdef ENABLE_386_DYNAREC_LOG if (in_smm) x386_dynarec_log("[%04X:%08X] fetchdat = %08X\n", CS, cpu_state.pc, fetchdat); @@ -431,7 +431,7 @@ exec386_dynarec_dyn(void) uint64_t mask = (uint64_t) 1 << ((phys_addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); # ifdef USE_NEW_DYNAREC int byte_offset = (phys_addr >> PAGE_BYTE_MASK_SHIFT) & PAGE_BYTE_MASK_OFFSET_MASK; - uint64_t byte_mask = 1ull << (PAGE_BYTE_MASK_MASK & 0x3f); + uint64_t byte_mask = 1ULL << (PAGE_BYTE_MASK_MASK & 0x3f); if ((page->code_present_mask & mask) || (page->byte_code_present_mask[byte_offset] & byte_mask)) # else @@ -572,7 +572,7 @@ exec386_dynarec_dyn(void) cpu_state.ea_seg = &cpu_state.seg_ds; cpu_state.ssegs = 0; - fetchdat = fastreadl(cs + cpu_state.pc); + fetchdat = fastreadl_fetch(cs + cpu_state.pc); # ifdef ENABLE_386_DYNAREC_LOG if (in_smm) x386_dynarec_log("[%04X:%08X] fetchdat = %08X\n", CS, cpu_state.pc, fetchdat); @@ -668,7 +668,7 @@ exec386_dynarec_dyn(void) cpu_state.ssegs = 0; codegen_endpc = (cs + cpu_state.pc) + 8; - fetchdat = fastreadl(cs + cpu_state.pc); + fetchdat = fastreadl_fetch(cs + cpu_state.pc); # ifdef ENABLE_386_DYNAREC_LOG if (in_smm) diff --git a/src/cpu/386_ops.h b/src/cpu/386_ops.h index e345ee8d8..91449efeb 100644 --- a/src/cpu/386_ops.h +++ b/src/cpu/386_ops.h @@ -223,10 +223,11 @@ extern void x386_dynarec_log(const char *fmt, ...); static int opVPCEXT(uint32_t fetchdat) { - uint8_t b1, b2; + uint8_t b1; + uint8_t b2; uint16_t cent; time_t now; - struct tm *tm; + struct tm *tm = NULL; if (!is_vpc) /* only emulate this on Virtual PC machines */ return ILLEGAL(fetchdat); diff --git a/src/cpu/808x.c b/src/cpu/808x.c index b2859153a..e0419a9f7 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -70,6 +70,38 @@ static int in_rep = 0, repeating = 0, rep_c_flag = 0; static int oldc, clear_lock = 0; static int refresh = 0, cycdiff; +static int access_code = 0; +static int hlda = 0; +static int not_ready = 0; +static int bus_request_type = 0; +static int pic_data = -1; +static int last_was_code = 0; +static uint16_t mem_data = 0; +static uint32_t mem_seg = 0; +static uint16_t mem_addr = 0; +static int schedule_fetch = 1; +static int pasv = 0; + +#define BUS_OUT 1 +#define BUS_HIGH 2 +#define BUS_WIDE 4 +#define BUS_CODE 8 +#define BUS_IO 16 +#define BUS_MEM 32 +#define BUS_PIC 64 +#define BUS_ACCESS_TYPE (BUS_CODE | BUS_IO | BUS_MEM | BUS_PIC) + +#define BUS_CYCLE (biu_cycles & 3) +#define BUS_CYCLE_T1 biu_cycles = 0 +#define BUS_CYCLE_NEXT biu_cycles = (biu_cycles + 1) & 3 + +enum { + BUS_T1 = 0, + BUS_T2, + BUS_T3, + BUS_T4 +}; + /* Various things needed for 8087. */ #define OP_TABLE(name) ops_##name @@ -151,7 +183,7 @@ x808x_log(const char *fmt, ...) # define x808x_log(fmt, ...) #endif -static void pfq_add(int c, int add); +static void pfq_add(void); static void set_pzs(int bits); uint16_t @@ -172,62 +204,344 @@ clock_end(void) int diff = cycdiff - cycles; /* On 808x systems, clock speed is usually crystal frequency divided by an integer. */ - tsc += (uint64_t) diff * ((uint64_t) xt_cpu_multi >> 32ULL); /* Shift xt_cpu_multi by 32 bits to the right and then multiply. */ + tsc += ((uint64_t) diff * ((uint64_t) xt_cpu_multi >> 32ULL)); /* Shift xt_cpu_multi by 32 bits to the right and then multiply. */ if (TIMER_VAL_LESS_THAN_VAL(timer_target, (uint32_t) tsc)) timer_process(); } static void -fetch_and_bus(int c, int bus) -{ - if (refresh > 0) { - /* Finish the current fetch, if any. */ - cycles -= ((4 - (biu_cycles & 3)) & 3); - pfq_add((4 - (biu_cycles & 3)) & 3, 1); - /* Add 4 memory access cycles. */ - cycles -= 4; - pfq_add(4, 0); +process_timers(void) +{ + clock_end(); + clock_start(); +} - refresh--; +static void +cycles_forward(int c) +{ + cycles -= c; + + if (!is286) + process_timers(); +} + +static void +bus_outb(uint16_t port, uint8_t val) +{ + int old_cycles = cycles; + + cycles--; + outb(port, val); + resub_cycles(old_cycles); +} + +static void +bus_outw(uint16_t port, uint16_t val) +{ + int old_cycles = cycles; + + cycles--; + outw(port, val); + resub_cycles(old_cycles); +} + +static uint8_t +bus_inb(uint16_t port) +{ + int old_cycles = cycles; + uint8_t ret; + + cycles--; + ret = inb(port); + resub_cycles(old_cycles); + + return ret; +} + +static uint16_t +bus_inw(uint16_t port) +{ + int old_cycles = cycles; + uint16_t ret; + + cycles--; + ret = inw(port); + resub_cycles(old_cycles); + + return ret; +} + +static void +bus_do_io(int io_type) +{ + last_was_code = 0; + + x808x_log("(%02X) bus_do_io(%02X): %04X\n", opcode, io_type, cpu_state.eaaddr); + + if (io_type & BUS_OUT) { + if (io_type & BUS_WIDE) + bus_outw((uint16_t) cpu_state.eaaddr, AX); + else if (io_type & BUS_HIGH) + bus_outb(((uint16_t) cpu_state.eaaddr + 1) & 0xffff, AH); + else + bus_outb((uint16_t) cpu_state.eaaddr, AL); + } else { + if (io_type & BUS_WIDE) + AX = bus_inw((uint16_t) cpu_state.eaaddr); + else if (io_type & BUS_HIGH) + AH = bus_inb(((uint16_t) cpu_state.eaaddr + 1) & 0xffff); + else + AL = bus_inb((uint16_t) cpu_state.eaaddr); } - pfq_add(c, !bus); - if (bus < 2) { - clock_end(); - clock_start(); + process_timers(); +} + +static void +bus_writeb(uint32_t seg, uint32_t addr, uint8_t val) +{ + write_mem_b(seg + addr, val); +} + +static void +bus_writew(uint32_t seg, uint32_t addr, uint16_t val) +{ + write_mem_w(seg + addr, val); +} + +static uint8_t +bus_readb(uint32_t seg, uint32_t addr) +{ + uint8_t ret = read_mem_b(seg + addr); + + return ret; +} + +static uint16_t +bus_readw(uint32_t seg, uint32_t addr) +{ + uint16_t ret = read_mem_w(seg + addr); + + return ret; +} + +static void +bus_do_mem(int io_type) +{ + last_was_code = 0; + + if (io_type & BUS_OUT) { + if (io_type & BUS_WIDE) + bus_writew(mem_seg, (uint32_t) mem_addr, mem_data); + else if (io_type & BUS_HIGH) { + if (is186 && !is_nec) + bus_writeb(mem_seg, ((uint32_t) mem_addr) + 1, mem_data >> 8); + else + bus_writeb(mem_seg, (uint32_t) ((mem_addr + 1) & 0xffff), mem_data >> 8); + } else + bus_writeb(mem_seg, (uint32_t) mem_addr, mem_data & 0xff); + } else { + if (io_type & BUS_WIDE) + mem_data = bus_readw(mem_seg, (uint32_t) mem_addr); + else if (io_type & BUS_HIGH) { + if (is186 && !is_nec) + mem_data = (mem_data & 0x00ff) | (((uint16_t) bus_readb(mem_seg, ((uint32_t) mem_addr) + 1)) << 8); + else + mem_data = (mem_data & 0x00ff) | (((uint16_t) bus_readb(mem_seg, (uint32_t) ((mem_addr + 1) & 0xffff))) << 8); + } else + mem_data = (mem_data & 0xff00) | ((uint16_t) bus_readb(mem_seg, (uint32_t) mem_addr)); } } static void -wait(int c, int bus) +run_bus_cycle(int io_type) { - cycles -= c; - fetch_and_bus(c, bus); + int do_bus_access = (io_type != 0) && (!(io_type & BUS_CODE) || schedule_fetch); + + x808x_log("[%04X:%04X] %02X bus access %02X (%i)\n", CS, cpu_state.pc, opcode, io_type, do_bus_access); + + if (do_bus_access) { + if (not_ready > 0) { + x808x_log("[%04X:%04X] %02X TW x%i\n", CS, cpu_state.pc, opcode, not_ready); + cycles_forward(not_ready); + not_ready = 0; + } + + switch(BUS_CYCLE) { + case BUS_T1: + access_code = !!(io_type & BUS_CODE); + break; + case BUS_T3: + switch (io_type & BUS_ACCESS_TYPE) { + case BUS_CODE: + pfq_add(); + last_was_code = 1; + break; + case BUS_IO: + bus_do_io(io_type); + break; + case BUS_MEM: + bus_do_mem(io_type); + break; + case BUS_PIC: + pic_data = pic_irq_ack(); + last_was_code = 0; + break; + default: + break; + } + break; + default: + break; + } + } } -/* This is for external subtraction of cycles. */ +static void +run_dma_cycle(int idle) +{ + if (not_ready > 0) { + /* Subtract one not ready cycle. */ + not_ready--; + } else if (hlda > 0) { + hlda--; + /* DMAWAIT is two cycles in, the actual wait states + are inserted with one cycle of delay. */ + if (hlda == 0) { + /* Deassert READY. */ + not_ready = 6; + } + } else if ((refresh > 0) && (in_lock == 0) && (idle || (BUS_CYCLE >= BUS_T3))) { + /* Refresh pending and it's either non-bus cycle or T3-T4, + raise HLDA. */ + hlda = 2; + /* Decrease the refresh count. */ + refresh--; + } +} + +static void +cycles_idle(int c) +{ + int d; + + for (d = 0; d < c; d++) { + x808x_log("[%04X:%04X] %02X TI\n", CS, cpu_state.pc, opcode); + + cycles_forward(1); + run_dma_cycle(1); + } +} + +static void +cycles_biu(int bus, int init) +{ + /* T1, T2 = Nothing, T3 = Start and schedule, T4 = Nothing */ + pasv = (bus || ((BUS_CYCLE == BUS_T1) && schedule_fetch)) ? 0 : 1; + + x808x_log("cycles_biu(%i, %i): %i, %i, %i, %i\n", bus, init, prefetching, pfq_pos, pfq_size, BUS_CYCLE); + if (bus) { + /* CPU wants non-code bus access. */ + if (init) { + if (schedule_fetch) { + switch (BUS_CYCLE) { + case BUS_T1: + case BUS_T2: + BUS_CYCLE_T1; /* Simply abort the prefetch before actual scheduling, no penalty. */ + break; + case BUS_T3: + case BUS_T4: + cycles_idle(5 - BUS_CYCLE); /* Leftover BIU cycles + 2 idle cycles. */ + BUS_CYCLE_T1; /* Abort the prefetch. */ + break; + } + + schedule_fetch = 0; + access_code = 0; + } + } + + run_bus_cycle(bus_request_type); + } else { + /* CPU wants idle or code bus access. */ + if (schedule_fetch) + run_bus_cycle(BUS_CODE); + } + + if (BUS_CYCLE == BUS_T3) + schedule_fetch = prefetching && (pfq_pos < pfq_size); + + run_dma_cycle(pasv); + + BUS_CYCLE_NEXT; +} + +#ifdef REENIGNE_MODELING +static void +bus_init(void) +{ + /* Replacement for the old access() stuff. */ + if ((BUS_CYCLE == BUS_T4) && last_was_code && (opcode != 0x8f) && (opcode != 0xc7) && (opcode != 0xcc) && (opcode != 0xcd) && (opcode != 0xce) && ((opcode & 0xf0) != 0xa0)) + cycles_idle(1); + + cycles_idle(2); + + while ((BUS_CYCLE == BUS_T2) || (BUS_CYCLE == BUS_T3)) + cycles_idle(1); +} +#endif + +/* Bus: + 0 CPU cycles without bus access. + 1 CPU cycle T1-T4, bus access. + 2 CPU cycle Tw (wait state). + 3 CPU cycle Ti (idle). + */ +static void +wait(int c, int bus) +{ + int d; + + if (c < 0) + pclog("Negative cycles: %i!\n", c); + + x808x_log("[%04X:%04X] %02X %i cycles (%i)\n", CS, cpu_state.pc, opcode, c, bus); + + for (d = 0; d < c; d++) { + x808x_log("[%04X:%04X] %02X cycle %i BIU\n", CS, cpu_state.pc, opcode, d); + cycles_biu(bus, !d); + x808x_log("[%04X:%04X] %02X cycle %i EU\n", CS, cpu_state.pc, opcode, d); + cycles_forward(1); + } +} + +/* This is for external subtraction of cycles, ie. wait states. */ void sub_cycles(int c) { - if (c <= 0) - return; - - cycles -= c; - - if (!is286) - fetch_and_bus(c, 2); + if (is286) + cycles -= c; + else { + if (c > 0) + cycles_idle(c); + } } void resub_cycles(int old_cycles) { - int cyc_diff = 0; + int i, cyc_diff = 0; if (old_cycles > cycles) { cyc_diff = old_cycles - cycles; - cycles = old_cycles; - sub_cycles(cyc_diff); + + for (i = 0; i < cyc_diff; i++) { + if (not_ready > 0) + not_ready--; + } } + + process_timers(); } #undef readmemb @@ -238,53 +552,63 @@ resub_cycles(int old_cycles) static void cpu_io(int bits, int out, uint16_t port) { - int old_cycles = cycles; +#ifdef REENIGNE_MODELING + bus_init(); +#endif if (out) { - wait(4, 1); if (bits == 16) { if (is8086 && !(port & 1)) { - old_cycles = cycles; - outw(port, AX); - } else { + bus_request_type = BUS_IO | BUS_OUT | BUS_WIDE; + wait(4, 1); + } else { + bus_request_type = BUS_IO | BUS_OUT; + wait(4, 1); + schedule_fetch = 0; + bus_request_type = BUS_IO | BUS_OUT | BUS_HIGH; wait(4, 1); - old_cycles = cycles; - outb(port++, AL); - outb(port, AH); } } else { - old_cycles = cycles; - outb(port, AL); + bus_request_type = BUS_IO | BUS_OUT; + wait(4, 1); } } else { - wait(4, 1); if (bits == 16) { if (is8086 && !(port & 1)) { - old_cycles = cycles; - AX = inw(port); - } else { + bus_request_type = BUS_IO | BUS_WIDE; + wait(4, 1); + } else { + bus_request_type = BUS_IO; + wait(4, 1); + schedule_fetch = 0; + bus_request_type = BUS_IO | BUS_HIGH; wait(4, 1); - old_cycles = cycles; - AL = inb(port++); - AH = inb(port); } } else { - old_cycles = cycles; - AL = inb(port); + bus_request_type = BUS_IO; + wait(4, 1); } } - resub_cycles(old_cycles); + bus_request_type = 0; } /* Reads a byte from the memory and advances the BIU. */ static uint8_t -readmemb(uint32_t a) +readmemb(uint32_t s, uint16_t a) { uint8_t ret; +#ifdef REENIGNE_MODELING + bus_init(); +#endif + + mem_seg = s; + mem_addr = a; + bus_request_type = BUS_MEM; wait(4, 1); - ret = read_mem_b(a); + ret = mem_data & 0xff; + bus_request_type = 0; return ret; } @@ -298,6 +622,8 @@ readmembf(uint32_t a) a = cs + (a & 0xffff); ret = read_mem_b(a); + last_was_code = 1; + return ret; } @@ -307,14 +633,24 @@ readmemw(uint32_t s, uint16_t a) { uint16_t ret; - wait(4, 1); - if (is8086 && !(a & 1)) - ret = read_mem_w(s + a); - else { +#ifdef REENIGNE_MODELING + bus_init(); +#endif + + mem_seg = s; + mem_addr = a; + if (is8086 && !(a & 1)) { + bus_request_type = BUS_MEM | BUS_WIDE; + wait(4, 1); + } else { + bus_request_type = BUS_MEM | BUS_HIGH; + wait(4, 1); + schedule_fetch = 0; + bus_request_type = BUS_MEM; wait(4, 1); - ret = read_mem_b(s + a); - ret |= read_mem_b(s + ((is186 && !is_nec) ? (a + 1) : (a + 1) & 0xffff)) << 8; } + ret = mem_data; + bus_request_type = 0; return ret; } @@ -326,6 +662,8 @@ readmemwf(uint16_t a) ret = read_mem_w(cs + (a & 0xffff)); + last_was_code = 1; + return ret; } @@ -335,7 +673,7 @@ readmem(uint32_t s) if (opcode & 1) return readmemw(s, cpu_state.eaaddr); else - return (uint16_t) readmemb(s + cpu_state.eaaddr); + return (uint16_t) readmemb(s, cpu_state.eaaddr); } static uint32_t @@ -357,6 +695,8 @@ readmemq(uint32_t s, uint16_t a) temp = (uint64_t) (readmeml(s, a + 4)) << 32; temp |= readmeml(s, a); + last_was_code = 0; + return temp; } @@ -366,8 +706,16 @@ writememb(uint32_t s, uint32_t a, uint8_t v) { uint32_t addr = s + a; +#ifdef REENIGNE_MODELING + bus_init(); +#endif + + mem_seg = s; + mem_addr = a; + mem_data = v; + bus_request_type = BUS_MEM | BUS_OUT; wait(4, 1); - write_mem_b(addr, v); + bus_request_type = 0; if ((addr >= 0xf0000) && (addr <= 0xfffff)) last_addr = addr & 0xffff; @@ -379,15 +727,24 @@ writememw(uint32_t s, uint32_t a, uint16_t v) { uint32_t addr = s + a; - wait(4, 1); - if (is8086 && !(a & 1)) - write_mem_w(addr, v); - else { - write_mem_b(addr, v & 0xff); +#ifdef REENIGNE_MODELING + bus_init(); +#endif + + mem_seg = s; + mem_addr = a; + mem_data = v; + if (is8086 && !(a & 1)) { + bus_request_type = BUS_MEM | BUS_OUT | BUS_WIDE; + wait(4, 1); + } else { + bus_request_type = BUS_MEM | BUS_OUT | BUS_HIGH; + wait(4, 1); + schedule_fetch = 0; + bus_request_type = BUS_MEM | BUS_OUT; wait(4, 1); - addr = s + ((is186 && !is_nec) ? (a + 1) : ((a + 1) & 0xffff)); - write_mem_b(addr, v >> 8); } + bus_request_type = 0; if ((addr >= 0xf0000) && (addr <= 0xfffff)) last_addr = addr & 0xffff; @@ -420,38 +777,49 @@ static void pfq_write(void) { uint16_t tempw; + /* Byte fetch on odd addres on 8086 to simulate the HL toggle. */ + int fetch_word = is8086 && !(pfq_ip & 1); - if (is8086 && (pfq_pos < (pfq_size - 1))) { + if (fetch_word && (pfq_pos < (pfq_size - 1))) { /* The 8086 fetches 2 bytes at a time, and only if there's at least 2 bytes free in the queue. */ tempw = readmemwf(pfq_ip); *(uint16_t *) &(pfq[pfq_pos]) = tempw; - pfq_ip += 2; + pfq_ip = (pfq_ip + 2) & 0xffff; pfq_pos += 2; - } else if (!is8086 && (pfq_pos < pfq_size)) { + } else if (!fetch_word && (pfq_pos < pfq_size)) { /* The 8088 fetches 1 byte at a time, and only if there's at least 1 byte free in the queue. */ pfq[pfq_pos] = readmembf(pfq_ip); - pfq_ip++; + pfq_ip = (pfq_ip + 1) & 0xffff; pfq_pos++; } + + if (pfq_pos >= pfq_size) + pfq_pos = pfq_size; } static uint8_t pfq_read(void) { - uint8_t temp, i; + uint8_t temp; temp = pfq[0]; - for (i = 0; i < (pfq_size - 1); i++) + for (int i = 0; i < (pfq_size - 1); i++) pfq[i] = pfq[i + 1]; pfq_pos--; + if (pfq_pos < 0) + pfq_pos = 0; cpu_state.pc = (cpu_state.pc + 1) & 0xffff; return temp; } /* Fetches a byte from the prefetch queue, or from memory if the queue has - been drained. */ + been drained. + + Cycles: 1 If fetching from the queue; + (4 - (biu_cycles & 3)) If fetching from the bus - fetch into the queue; + 1 If fetching from the bus - delay. */ static uint8_t pfq_fetchb_common(void) { @@ -461,7 +829,8 @@ pfq_fetchb_common(void) /* Reset prefetch queue internal position. */ pfq_ip = cpu_state.pc; /* Fill the queue. */ - wait(4 - (biu_cycles & 3), 0); + while (pfq_pos == 0) + wait(1, 0); } /* Fetch. */ @@ -469,6 +838,7 @@ pfq_fetchb_common(void) return temp; } +/* The timings are above. */ static uint8_t pfq_fetchb(void) { @@ -504,18 +874,10 @@ pfq_fetch(void) /* Adds bytes to the prefetch queue based on the instruction's cycle count. */ static void -pfq_add(int c, int add) +pfq_add(void) { - int d; - - if ((c <= 0) || (pfq_pos >= pfq_size)) - return; - - for (d = 0; d < c; d++) { - biu_cycles = (biu_cycles + 1) & 0x03; - if (prefetching && add && (biu_cycles == 0x00)) - pfq_write(); - } + if (prefetching && (pfq_pos < pfq_size)) + pfq_write(); } /* Clear the prefetch queue - called on reset and on anything that affects either CS or IP. */ @@ -524,6 +886,16 @@ pfq_clear(void) { pfq_pos = 0; prefetching = 0; + schedule_fetch = 0; + + BUS_CYCLE_T1; +} + +static void +pfq_suspend(void) +{ + pfq_clear(); + cycles_idle(3); } static void @@ -543,7 +915,7 @@ load_seg(uint16_t seg, x86seg *s) void reset_808x(int hard) { - biu_cycles = 0; + BUS_CYCLE_T1; in_rep = 0; in_lock = 0; completed = 1; @@ -573,10 +945,24 @@ reset_808x(int hard) rammask = 0xfffff; prefetching = 1; + + schedule_fetch = 1; + pasv = 0; + cpu_alu_op = 0; use_custom_nmi_vector = 0x00; custom_nmi_vector = 0x00000000; + + access_code = 0; + hlda = 0; + not_ready = 0; + bus_request_type = 0; + pic_data = -1; + last_was_code = 0; + mem_data = 0; + mem_seg = 0; + mem_addr = 0; } static void @@ -584,6 +970,7 @@ set_ip(uint16_t new_ip) { pfq_ip = cpu_state.pc = new_ip; prefetching = 1; + schedule_fetch = prefetching && (pfq_pos < pfq_size); } /* Memory refresh read - called by reads and writes on DMA channel 0. */ @@ -626,34 +1013,34 @@ do_mod_rm(void) if (cpu_mod == 3) return; - wait(1, 0); + wait(2, 0); if ((rmdat & 0xc7) == 0x06) { - wait(1, 0); cpu_state.eaaddr = pfq_fetchw(); easeg = ovr_seg ? *ovr_seg : ds; - wait(1, 0); + wait(2, 0); return; - } else - switch (cpu_rm) { - case 0: - case 3: - wait(2, 0); - break; - case 1: - case 2: - wait(3, 0); - break; - } + } else switch (cpu_rm) { + case 0: + case 3: + wait(2, 0); + break; + case 1: + case 2: + wait(3, 0); + break; + } cpu_state.eaaddr = (*mod1add[0][cpu_rm]) + (*mod1add[1][cpu_rm]); easeg = ovr_seg ? *ovr_seg : *mod1seg[cpu_rm]; switch (rmdat & 0xc0) { case 0x40: - wait(3, 0); + wait(2, 0); cpu_state.eaaddr += sign_extend(pfq_fetchb()); + wait(1, 0); break; case 0x80: - wait(3, 0); + wait(2, 0); cpu_state.eaaddr += pfq_fetchw(); + wait(1, 0); break; } cpu_state.eaaddr &= 0xffff; @@ -677,7 +1064,7 @@ geteab(void) if (cpu_mod == 3) return (getr8(cpu_rm)); - return readmemb(easeg + cpu_state.eaaddr); + return readmemb(easeg, cpu_state.eaaddr); } /* Reads a word from the effective address. */ @@ -721,7 +1108,7 @@ read_ea(int memory_only, int bits) if (bits == 16) cpu_data = readmemw(easeg, cpu_state.eaaddr); else - cpu_data = readmemb(easeg + cpu_state.eaaddr); + cpu_data = readmemb(easeg, cpu_state.eaaddr); return; } if (!memory_only) { @@ -739,7 +1126,7 @@ read_ea2(int bits) if (bits == 16) cpu_data = readmemw(easeg, cpu_state.eaaddr); else - cpu_data = readmemb(easeg + cpu_state.eaaddr); + cpu_data = readmemb(easeg, cpu_state.eaaddr); } /* Writes a byte to the effective address. */ @@ -814,135 +1201,6 @@ pop(void) return readmemw(ss, cpu_state.eaaddr); } -static void -access(int num, int bits) -{ - switch (num) { - case 0: - case 61: - case 63: - case 64: - case 67: - case 69: - case 71: - case 72: - default: - break; - case 1: - case 6: - case 7: - case 8: - case 9: - case 17: - case 20: - case 21: - case 24: - case 28: - case 47: - case 48: - case 49: - case 50: - case 51: - case 55: - case 56: - case 62: - case 66: - case 68: - wait(1, 0); - break; - case 3: - case 11: - case 15: - case 22: - case 23: - case 25: - case 26: - case 35: - case 44: - case 45: - case 46: - case 52: - case 53: - case 54: - wait(2, 0); - break; - case 16: - case 18: - case 19: - case 27: - case 32: - case 37: - case 42: - wait(3, 0); - break; - case 10: - case 12: - case 13: - case 14: - case 29: - case 30: - case 33: - case 34: - case 39: - case 41: - case 60: - wait(4, 0); - break; - case 4: - case 70: - wait(5, 0); - break; - case 31: - case 38: - case 40: - wait(6, 0); - break; - case 5: - if (opcode == 0xcc) - wait(7, 0); - else - wait(4, 0); - break; - case 36: - wait(1, 0); - pfq_clear(); - wait(1, 0); - if (cpu_mod != 3) - wait(1, 0); - wait(3, 0); - break; - case 43: - wait(2, 0); - pfq_clear(); - wait(1, 0); - break; - case 57: - if (cpu_mod != 3) - wait(2, 0); - wait(4, 0); - break; - case 58: - if (cpu_mod != 3) - wait(1, 0); - wait(4, 0); - break; - case 59: - wait(2, 0); - pfq_clear(); - if (cpu_mod != 3) - wait(1, 0); - wait(3, 0); - break; - case 65: - wait(1, 0); - pfq_clear(); - wait(2, 0); - if (cpu_mod != 3) - wait(1, 0); - break; - } -} - /* Calls an interrupt. */ static void interrupt(uint16_t addr) @@ -954,26 +1212,24 @@ interrupt(uint16_t addr) addr <<= 2; cpu_state.eaaddr = addr; old_cs = CS; - access(5, 16); new_ip = readmemw(0, cpu_state.eaaddr); wait(1, 0); cpu_state.eaaddr = (cpu_state.eaaddr + 2) & 0xffff; - access(6, 16); new_cs = readmemw(0, cpu_state.eaaddr); prefetching = 0; pfq_clear(); ovr_seg = NULL; - access(39, 16); + wait(2, 0); tempf = cpu_state.flags & (is_nec ? 0x8fd7 : 0x0fd7); push(&tempf); cpu_state.flags &= ~(I_FLAG | T_FLAG); - access(40, 16); + wait(5, 0); push(&old_cs); old_ip = cpu_state.pc; load_cs(new_cs); - access(68, 16); + pfq_suspend(); set_ip(new_ip); - access(41, 16); + wait(2, 0); push(&old_ip); } @@ -992,28 +1248,26 @@ custom_nmi(void) cpu_state.eaaddr = 0x0002; old_cs = CS; - access(5, 16); (void) readmemw(0, cpu_state.eaaddr); new_ip = custom_nmi_vector & 0xffff; wait(1, 0); cpu_state.eaaddr = (cpu_state.eaaddr + 2) & 0xffff; - access(6, 16); (void) readmemw(0, cpu_state.eaaddr); new_cs = custom_nmi_vector >> 16; prefetching = 0; pfq_clear(); ovr_seg = NULL; - access(39, 16); + wait(2, 0); tempf = cpu_state.flags & (is_nec ? 0x8fd7 : 0x0fd7); push(&tempf); cpu_state.flags &= ~(I_FLAG | T_FLAG); - access(40, 16); + wait(5, 0); push(&old_cs); old_ip = cpu_state.pc; load_cs(new_cs); - access(68, 16); + pfq_suspend(); set_ip(new_ip); - access(41, 16); + wait(2, 0); push(&old_ip); } @@ -1027,6 +1281,18 @@ irq_pending(void) return temp; } +static int +bus_pic_ack(void) +{ + int old_in_lock = in_lock; + + in_lock = 1; + bus_request_type = BUS_PIC; + wait(4, 1); + in_lock = old_in_lock; + return pic_data; +} + static void check_interrupts(void) { @@ -1034,11 +1300,13 @@ check_interrupts(void) if (irq_pending()) { if ((cpu_state.flags & T_FLAG) && !noint) { + wait(2, 0); interrupt(1); return; } if (nmi && nmi_enable && nmi_mask) { nmi_enable = 0; + wait(2, 0); if (use_custom_nmi_vector) custom_nmi(); else @@ -1052,26 +1320,61 @@ check_interrupts(void) repeating = 0; completed = 1; ovr_seg = NULL; - wait(3, 0); + wait(4, 0); /* ACK to PIC */ - temp = pic_irq_ack(); - wait(4, 1); + temp = bus_pic_ack(); wait(1, 0); /* ACK to PIC */ - temp = pic_irq_ack(); - wait(4, 1); + temp = bus_pic_ack(); wait(1, 0); in_lock = 0; clear_lock = 0; - wait(1, 0); + if (BUS_CYCLE != BUS_T3) + wait(1, 0); + wait(5, 0); /* Here is where temp should be filled, but we cheat. */ - wait(3, 0); opcode = 0x00; interrupt(temp); } } } +static uint16_t tmpc; + +static int +rep_setup(void) +{ + if (repeating) + return 0; + wait(2, 0); + if (in_rep == 0) + return 0; + wait(4, 0); + tmpc = CX; + if (tmpc == 0) + return 1; + wait(3, 0); + return 0; +} + +static int +rep_interrupt(void) +{ + if (!irq_pending()) { + repeating = 1; + completed = 0; + return 0; + } + completed = 1; + CX = tmpc; + pfq_clear(); + if (is_nec && (ovr_seg != NULL)) + set_ip(cpu_state.pc - 3); + else + set_ip(cpu_state.pc - 2); + return 1; +} + static int rep_action(int bits) { @@ -1082,7 +1385,6 @@ rep_action(int bits) wait(2, 0); t = CX; if (irq_pending() && (repeating != 0)) { - access(71, bits); pfq_clear(); if (is_nec && (ovr_seg != NULL)) set_ip(cpu_state.pc - 3); @@ -1108,9 +1410,9 @@ static uint16_t jump(uint16_t delta) { uint16_t old_ip; - access(67, 8); - pfq_clear(); - wait(5, 0); + wait(1, 0); + pfq_suspend(); + cycles_idle(1); old_ip = cpu_state.pc; set_ip((cpu_state.pc + delta) & 0xffff); return old_ip; @@ -1132,8 +1434,6 @@ jump_near(void) static void jcc(uint8_t opcode, int cond) { - /* int8_t offset; */ - wait(1, 0); cpu_data = pfq_fetchb(); wait(1, 0); @@ -1536,7 +1836,7 @@ lods(int bits) if (bits == 16) cpu_data = readmemw((ovr_seg ? *ovr_seg : ds), cpu_state.eaaddr); else - cpu_data = readmemb((ovr_seg ? *ovr_seg : ds) + cpu_state.eaaddr); + cpu_data = readmemb((ovr_seg ? *ovr_seg : ds), cpu_state.eaaddr); SI = string_increment(bits); } @@ -1658,6 +1958,7 @@ execx86(int cycs) uint16_t tempw_int, size, tempbp, lowbound; uint16_t highbound, regval, orig_sp, wordtopush; uint16_t immediate, old_flags; + uint16_t tmpa; int bits; uint32_t dest_seg, i, carry, nibble; uint32_t srcseg, byteaddr; @@ -1669,7 +1970,8 @@ execx86(int cycs) if (!repeating) { cpu_state.oldpc = cpu_state.pc; - opcode = pfq_fetchb(); + // opcode = pfq_fetchb(); + opcode = pfq_fetchb_common(); handled = 0; oldc = cpu_state.flags & C_FLAG; if (clear_lock) { @@ -1680,7 +1982,7 @@ execx86(int cycs) } completed = 1; - // pclog("[%04X:%04X] Opcode: %02X\n", CS, cpu_state.pc, opcode); + x808x_log("[%04X:%04X] Opcode: %02X\n", CS, cpu_state.pc, opcode); if (is186) { switch (opcode) { case 0x60: /*PUSHA/PUSH R*/ @@ -1820,7 +2122,7 @@ execx86(int cycs) SI += (cpu_state.flags & D_FLAG) ? -2 : 2; } else { wait(4, 0); - outb(DX, readmemb(dest_seg + SI)); + outb(DX, readmemb(dest_seg, SI)); SI += (cpu_state.flags & D_FLAG) ? -1 : 1; } if (in_rep == 0) @@ -1858,7 +2160,6 @@ execx86(int cycs) do_mod_rm(); if (cpu_mod == 3) wait(1, 0); - access(53, bits); cpu_data = get_ea(); cpu_src = pfq_fetchb(); @@ -1937,7 +2238,6 @@ execx86(int cycs) wait(4, 0); --cpu_src; } - access(17, bits); set_ea(cpu_data); handled = 1; break; @@ -1955,7 +2255,7 @@ execx86(int cycs) case 0x0E: case 0x16: case 0x1E: /* PUSH seg */ - access(29, 16); + wait(3, 0); push(&(_opseg[(opcode >> 3) & 0x03]->seg)); break; case 0x07: @@ -2229,7 +2529,7 @@ execx86(int cycs) AX = 0; for (i = 0; i < bit_length; i++) { byteaddr = (ds) + SI; - AX |= (!!(readmemb(byteaddr) & (1 << bit_offset))) << i; + AX |= (!!(readmemb((ds), SI) & (1 << bit_offset))) << i; bit_offset++; if (bit_offset == 8) { SI++; @@ -2248,22 +2548,19 @@ execx86(int cycs) default: opcode = orig_opcode; - cpu_state.pc--; + cpu_state.pc = (cpu_state.pc - 1) & 0xffff; break; } - } else - handled = 0; - if (handled) - break; - access(22, 16); - if (opcode == 0x0F) { - load_cs(pop()); - pfq_pos = 0; - } else - load_seg(pop(), _opseg[(opcode >> 3) & 0x03]); - wait(1, 0); - /* All POP segment instructions suppress interrupts for one instruction. */ - noint = 1; + } else { + wait(1, 0); + if (opcode == 0x0F) { + load_cs(pop()); + pfq_pos = 0; + } else + load_seg(pop(), _opseg[(opcode >> 3) & 0x03]); + /* All POP segment instructions suppress interrupts for one instruction. */ + noint = 1; + } break; case 0x26: /*ES:*/ @@ -2310,7 +2607,6 @@ execx86(int cycs) /* alu rm, r / r, rm */ bits = 8 << (opcode & 1); do_mod_rm(); - access(46, bits); tempw = get_ea(); cpu_alu_op = (opcode >> 3) & 7; if ((opcode & 2) == 0) { @@ -2320,22 +2616,19 @@ execx86(int cycs) cpu_dest = get_reg(cpu_reg); cpu_src = tempw; } - if (cpu_mod != 3) - wait(2, 0); wait(1, 0); + if (cpu_mod != 3) + wait(1, 0); alu_op(bits); + wait(1, 0); if (cpu_alu_op != 7) { if ((opcode & 2) == 0) { - access(10, bits); - set_ea(cpu_data); if (cpu_mod == 3) - wait(1, 0); - } else { + wait(2, 0); + set_ea(cpu_data); + } else set_reg(cpu_reg, cpu_data); - wait(1, 0); - } - } else - wait(1, 0); + } break; case 0x04: @@ -2485,7 +2778,7 @@ execx86(int cycs) case 0x55: case 0x56: case 0x57: - access(30, 16); + wait(3, 0); push(&(cpu_state.regs[opcode & 0x07].w)); break; case 0x58: @@ -2496,9 +2789,8 @@ execx86(int cycs) case 0x5D: case 0x5E: case 0x5F: - access(23, 16); - cpu_state.regs[opcode & 0x07].w = pop(); wait(1, 0); + cpu_state.regs[opcode & 0x07].w = pop(); break; case 0x60: /*JO alias*/ @@ -2561,18 +2853,14 @@ execx86(int cycs) /* alu rm, imm */ bits = 8 << (opcode & 1); do_mod_rm(); - access(47, bits); cpu_data = get_ea(); cpu_dest = cpu_data; if (cpu_mod != 3) - wait(3, 0); - if (opcode == 0x81) { - if (cpu_mod == 3) - wait(1, 0); + wait(1, 0); + wait(1, 0); + if (opcode == 0x81) cpu_src = pfq_fetchw(); - } else { - if (cpu_mod == 3) - wait(1, 0); + else { if (opcode == 0x83) cpu_src = sign_extend(pfq_fetchb()); else @@ -2582,7 +2870,8 @@ execx86(int cycs) cpu_alu_op = (rmdat & 0x38) >> 3; alu_op(bits); if (cpu_alu_op != 7) { - access(11, bits); + if (cpu_mod != 3) + wait(1, 0); set_ea(cpu_data); } else { if (cpu_mod != 3) @@ -2595,11 +2884,10 @@ execx86(int cycs) /* TEST rm, reg */ bits = 8 << (opcode & 1); do_mod_rm(); - access(48, bits); cpu_data = get_ea(); test(bits, cpu_data, get_reg(cpu_reg)); - if (cpu_mod == 3) - wait(2, 0); + if (cpu_mod != 3) + wait(1, 0); wait(2, 0); break; case 0x86: @@ -2607,12 +2895,12 @@ execx86(int cycs) /* XCHG rm, reg */ bits = 8 << (opcode & 1); do_mod_rm(); - access(49, bits); cpu_data = get_ea(); cpu_src = get_reg(cpu_reg); set_reg(cpu_reg, cpu_data); wait(3, 0); - access(12, bits); + if (cpu_mod != 3) + wait(3, 0); set_ea(cpu_src); break; @@ -2622,7 +2910,8 @@ execx86(int cycs) bits = 8 << (opcode & 1); do_mod_rm(); wait(1, 0); - access(13, bits); + if (cpu_mod != 3) + wait(3, 0); set_ea(get_reg(cpu_reg)); break; case 0x8A: @@ -2630,18 +2919,17 @@ execx86(int cycs) /* MOV reg, rm */ bits = 8 << (opcode & 1); do_mod_rm(); - access(50, bits); set_reg(cpu_reg, get_ea()); wait(1, 0); if (cpu_mod != 3) - wait(2, 0); + wait(1, 0); break; case 0x8C: /*MOV w,sreg*/ do_mod_rm(); - if (cpu_mod == 3) - wait(1, 0); - access(14, 16); + wait(1, 0); + if (cpu_mod != 3) + wait(2, 0); seteaw(_opseg[(rmdat & 0x18) >> 3]->seg); break; @@ -2650,12 +2938,11 @@ execx86(int cycs) cpu_state.regs[cpu_reg].w = cpu_state.eaaddr; wait(1, 0); if (cpu_mod != 3) - wait(2, 0); + wait(1, 0); break; case 0x8E: /*MOV sreg,w*/ do_mod_rm(); - access(51, 16); tempw = geteaw(); if ((rmdat & 0x18) == 0x08) { load_cs(tempw); @@ -2664,22 +2951,22 @@ execx86(int cycs) load_seg(tempw, _opseg[(rmdat & 0x18) >> 3]); wait(1, 0); if (cpu_mod != 3) - wait(2, 0); + wait(1, 0); if (((rmdat & 0x18) >> 3) == 2) noint = 1; break; case 0x8F: /*POPW*/ do_mod_rm(); - wait(1, 0); + wait(2, 0); cpu_src = cpu_state.eaaddr; - access(24, 16); + if (cpu_mod != 3) + wait(1, 0); + wait(1, 0); if (cpu_mod != 3) wait(2, 0); cpu_data = pop(); cpu_state.eaaddr = cpu_src; - wait(2, 0); - access(15, 16); seteaw(cpu_data); break; @@ -2717,14 +3004,14 @@ execx86(int cycs) new_ip = pfq_fetchw(); wait(1, 0); new_cs = pfq_fetchw(); - pfq_clear(); - access(31, 16); + wait(1, 0); + pfq_suspend(); push(&(CS)); - access(60, 16); + wait(4, 0); cpu_state.oldpc = cpu_state.pc; load_cs(new_cs); set_ip(new_ip); - access(32, 16); + wait(1, 0); push((uint16_t *) &(cpu_state.oldpc)); break; case 0x9B: /*WAIT*/ @@ -2746,7 +3033,7 @@ execx86(int cycs) #endif break; case 0x9C: /*PUSHF*/ - access(33, 16); + wait(4, 0); if (is_nec) tempw = (cpu_state.flags & 0x8fd7) | 0x7000; else @@ -2754,12 +3041,11 @@ execx86(int cycs) push(&tempw); break; case 0x9D: /*POPF*/ - access(25, 16); + wait(1, 0); if (is_nec) cpu_state.flags = pop() | 0x8002; else cpu_state.flags = pop() | 0x0002; - wait(1, 0); break; case 0x9E: /*SAHF*/ wait(1, 0); @@ -2775,20 +3061,18 @@ execx86(int cycs) case 0xA1: /* MOV A, [iw] */ bits = 8 << (opcode & 1); - wait(1, 0); + wait(2, 0); cpu_state.eaaddr = pfq_fetchw(); - access(1, bits); set_accum(bits, readmem((ovr_seg ? *ovr_seg : ds))); - wait(1, 0); break; case 0xA2: case 0xA3: /* MOV [iw], A */ bits = 8 << (opcode & 1); - wait(1, 0); + wait(2, 0); cpu_state.eaaddr = pfq_fetchw(); - access(7, bits); writemem((ovr_seg ? *ovr_seg : ds), get_accum(bits)); + wait(2, 0); break; case 0xA4: @@ -2796,37 +3080,33 @@ execx86(int cycs) case 0xAC: case 0xAD: /* LODS */ bits = 8 << (opcode & 1); - if (!repeating) { - wait(1, 0); - if ((opcode & 8) == 0 && in_rep != 0) - wait(1, 0); - } - if (rep_action(bits)) { - wait(1, 0); - if ((opcode & 8) != 0) - wait(1, 0); + if (rep_setup()) break; - } - if (in_rep != 0 && (opcode & 8) != 0) + if (in_rep != 0 && (BUS_CYCLE == BUS_T4)) wait(1, 0); - access(20, bits); lods(bits); if ((opcode & 8) == 0) { - access(27, bits); + wait(1, 0); stos(bits); - } else { + } else set_accum(bits, cpu_data); - if (in_rep != 0) + wait(3, 0); + if (in_rep == 0) + break; + --tmpc; + if (rep_interrupt()) + break; + CX = tmpc; + if (tmpc == 0) { + completed = 1; + wait(1, 0); + if ((opcode & 8) != 0) + wait(2, 0); + } else { + wait(2, 0); + if ((opcode & 8) != 0) wait(2, 0); } - if (in_rep == 0) { - wait(3, 0); - if ((opcode & 8) != 0) - wait(1, 0); - break; - } - repeating = 1; - clock_end(); break; case 0xA6: @@ -2834,40 +3114,39 @@ execx86(int cycs) case 0xAE: case 0xAF: /* SCAS */ bits = 8 << (opcode & 1); - if (!repeating) - wait(1, 0); - if (rep_action(bits)) { - wait(2, 0); + if (rep_setup()) break; - } - if (in_rep != 0) - wait(1, 0); - wait(1, 0); - cpu_dest = get_accum(bits); + tmpa = AX; if ((opcode & 8) == 0) { - access(21, bits); - lods(bits); wait(1, 0); - cpu_dest = cpu_data; + lods(bits); + tmpa = cpu_data; } - access(2, bits); + wait(2, 0); cpu_state.eaaddr = DI; cpu_data = readmem(es); - DI = string_increment(bits); + DI = string_increment(bits); cpu_src = cpu_data; + cpu_dest = tmpa; sub(bits); wait(2, 0); if (in_rep == 0) { + wait(2, 0); + break; + } + --tmpc; + CX = tmpc; + if ((!!(cpu_state.flags & (rep_c_flag ? C_FLAG : Z_FLAG))) == (in_rep == 1)) { wait(3, 0); break; } - if ((!!(cpu_state.flags & (rep_c_flag ? C_FLAG : Z_FLAG))) == (in_rep == 1)) { - completed = 1; - wait(4, 0); + if (rep_interrupt()) break; - } - repeating = 1; - clock_end(); + wait(4, 0); + if (tmpc == 0) + completed = 1; + else + wait(1, 0); break; case 0xA8: @@ -2883,24 +3162,24 @@ execx86(int cycs) case 0xAA: case 0xAB: /* STOS */ bits = 8 << (opcode & 1); - if (!repeating) { - wait(1, 0); - if (in_rep != 0) - wait(1, 0); - } - if (rep_action(bits)) { - wait(1, 0); + if (rep_setup()) break; - } cpu_data = AX; - access(28, bits); + if (in_rep == 0 && (BUS_CYCLE == BUS_T4)) + wait(1, 0); stos(bits); - if (in_rep == 0) { - wait(3, 0); + wait(3, 0); + if (in_rep == 0) break; - } - repeating = 1; - clock_end(); + --tmpc; + if (rep_interrupt()) + break; + CX = tmpc; + if (tmpc == 0) { + completed = 1; + wait(1, 0); + } else + wait(2, 0); break; case 0xB0: @@ -2942,32 +3221,27 @@ execx86(int cycs) case 0xCB: /* RET */ bits = 8 + (opcode & 0x08); - if ((opcode & 9) != 1) - wait(1, 0); + wait(1, 0); if (!(opcode & 1)) { cpu_src = pfq_fetchw(); - wait(1, 0); + wait(2, 0); } if ((opcode & 9) == 9) - wait(1, 0); + wait(2, 0); pfq_clear(); - access(26, bits); new_ip = pop(); - wait(2, 0); - if ((opcode & 8) == 0) + wait(1, 0); + if ((opcode & 8) == 0) { new_cs = CS; - else { - access(42, bits); - new_cs = pop(); if (opcode & 1) wait(1, 0); + } else { + wait(2, 0); + new_cs = pop(); } - if (!(opcode & 1)) { + if (!(opcode & 1)) SP += cpu_src; - wait(1, 0); - } load_cs(new_cs); - access(72, bits); set_ip(new_ip); break; @@ -2976,13 +3250,12 @@ execx86(int cycs) /* LsS rw, rmd */ do_mod_rm(); bits = 16; - access(52, bits); read_ea(1, bits); cpu_state.regs[cpu_reg].w = cpu_data; - access(57, bits); + if (cpu_mod != 3) + wait(2, 0); read_ea2(bits); load_seg(cpu_data, (opcode & 0x01) ? &cpu_state.seg_ds : &cpu_state.seg_es); - wait(1, 0); break; case 0xC6: @@ -2991,40 +3264,40 @@ execx86(int cycs) bits = 8 << (opcode & 1); do_mod_rm(); wait(1, 0); - if (cpu_mod != 3) - wait(2, 0); cpu_data = pfq_fetch(); - if (cpu_mod == 3) - wait(1, 0); - access(16, bits); + wait(2, 0); set_ea(cpu_data); break; case 0xCC: /*INT 3*/ + wait(7, 0); interrupt(3); break; case 0xCD: /*INT*/ wait(1, 0); - interrupt(pfq_fetchb()); + temp = pfq_fetchb(); + wait(1, 0); + if (BUS_CYCLE != BUS_T4) + wait(1, 0); + wait(1, 0); + + interrupt(temp); break; case 0xCE: /*INTO*/ wait(3, 0); if (cpu_state.flags & V_FLAG) { - wait(2, 0); + wait(5, 0); interrupt(4); } break; case 0xCF: /*IRET*/ - access(43, 8); - new_ip = pop(); wait(3, 0); - access(44, 8); + pfq_clear(); + new_ip = pop(); new_cs = pop(); load_cs(new_cs); - access(62, 8); set_ip(new_ip); - access(45, 8); if (is_nec) cpu_state.flags = pop() | 0x8002; else @@ -3041,10 +3314,9 @@ execx86(int cycs) /* rot rm */ bits = 8 << (opcode & 1); do_mod_rm(); + cpu_data = get_ea(); if (cpu_mod == 3) wait(1, 0); - access(53, bits); - cpu_data = get_ea(); if ((opcode & 2) == 0) { cpu_src = 1; wait((cpu_mod != 3) ? 4 : 0, 0); @@ -3125,7 +3397,6 @@ execx86(int cycs) wait(4, 0); --cpu_src; } - access(17, bits); set_ea(cpu_data); break; @@ -3159,9 +3430,8 @@ execx86(int cycs) break; case 0xD7: /*XLATB*/ cpu_state.eaaddr = (BX + AL) & 0xffff; - access(4, 8); - AL = readmemb((ovr_seg ? *ovr_seg : ds) + cpu_state.eaaddr); - wait(1, 0); + wait(4, 0); + AL = readmemb((ovr_seg ? *ovr_seg : ds), cpu_state.eaaddr); break; case 0xD8: @@ -3174,42 +3444,70 @@ execx86(int cycs) case 0xDF: /* esc i, r, rm */ do_mod_rm(); - access(54, 16); tempw = cpu_state.pc; - if (!hasfpu) - geteaw(); - else - switch (opcode) { - case 0xD8: - ops_fpu_8087_d8[(rmdat >> 3) & 0x1f]((uint32_t) rmdat); - break; - case 0xD9: - ops_fpu_8087_d9[rmdat & 0xff]((uint32_t) rmdat); - break; - case 0xDA: - ops_fpu_8087_da[rmdat & 0xff]((uint32_t) rmdat); - break; - case 0xDB: - ops_fpu_8087_db[rmdat & 0xff]((uint32_t) rmdat); - break; - case 0xDC: - ops_fpu_8087_dc[(rmdat >> 3) & 0x1f]((uint32_t) rmdat); - break; - case 0xDD: - ops_fpu_8087_dd[rmdat & 0xff]((uint32_t) rmdat); - break; - case 0xDE: - ops_fpu_8087_de[rmdat & 0xff]((uint32_t) rmdat); - break; - case 0xDF: - ops_fpu_8087_df[rmdat & 0xff]((uint32_t) rmdat); - break; - } - cpu_state.pc = tempw; /* Do this as the x87 code advances it, which is needed on - the 286+ core, but not here. */ + geteaw(); wait(1, 0); if (cpu_mod != 3) - wait(2, 0); + wait(1, 0); + if (hasfpu) { + if (fpu_softfloat) { + switch (opcode) { + case 0xD8: + ops_sf_fpu_8087_d8[(rmdat >> 3) & 0x1f]((uint32_t) rmdat); + break; + case 0xD9: + ops_sf_fpu_8087_d9[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDA: + ops_sf_fpu_8087_da[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDB: + ops_sf_fpu_8087_db[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDC: + ops_sf_fpu_8087_dc[(rmdat >> 3) & 0x1f]((uint32_t) rmdat); + break; + case 0xDD: + ops_sf_fpu_8087_dd[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDE: + ops_sf_fpu_8087_de[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDF: + ops_sf_fpu_8087_df[rmdat & 0xff]((uint32_t) rmdat); + break; + } + } else { + switch (opcode) { + case 0xD8: + ops_fpu_8087_d8[(rmdat >> 3) & 0x1f]((uint32_t) rmdat); + break; + case 0xD9: + ops_fpu_8087_d9[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDA: + ops_fpu_8087_da[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDB: + ops_fpu_8087_db[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDC: + ops_fpu_8087_dc[(rmdat >> 3) & 0x1f]((uint32_t) rmdat); + break; + case 0xDD: + ops_fpu_8087_dd[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDE: + ops_fpu_8087_de[rmdat & 0xff]((uint32_t) rmdat); + break; + case 0xDF: + ops_fpu_8087_df[rmdat & 0xff]((uint32_t) rmdat); + break; + } + } + } + cpu_state.pc = tempw; /* Do this as the x87 code advances it, which is needed on + the 286+ core, but not here. */ break; case 0xE0: @@ -3242,43 +3540,46 @@ execx86(int cycs) case 0xE4: case 0xE5: + bits = 8 << (opcode & 1); + wait(1, 0); + cpu_data = pfq_fetchb(); + cpu_state.eaaddr = cpu_data; + wait(1, 0); + cpu_io(bits, 0, cpu_state.eaaddr); + break; case 0xE6: case 0xE7: + bits = 8 << (opcode & 1); + wait(1, 0); + cpu_data = pfq_fetchb(); + cpu_state.eaaddr = cpu_data; + cpu_data = (bits == 16) ? AX : AL; + wait(2, 0); + cpu_io(bits, 1, cpu_state.eaaddr); + break; case 0xEC: case 0xED: + bits = 8 << (opcode & 1); + cpu_data = DX; + cpu_state.eaaddr = cpu_data; + wait(1, 0); + cpu_io(bits, 0, cpu_state.eaaddr); + break; case 0xEE: case 0xEF: bits = 8 << (opcode & 1); - if ((opcode & 0x0e) != 0x0c) - wait(1, 0); - if ((opcode & 8) == 0) - cpu_data = pfq_fetchb(); - else - cpu_data = DX; + wait(2, 0); + cpu_data = DX; cpu_state.eaaddr = cpu_data; - if ((opcode & 2) == 0) { - access(3, bits); - if (opcode & 1) - cpu_io(16, 0, cpu_data); - else - cpu_io(8, 0, cpu_data); - wait(1, 0); - } else { - if ((opcode & 8) == 0) - access(8, bits); - else - access(9, bits); - if (opcode & 1) - cpu_io(16, 1, cpu_data); - else - cpu_io(8, 1, cpu_data); - } + cpu_data = (bits == 16) ? AX : AL; + cpu_io(bits, 1, cpu_state.eaaddr); + wait(1, 0); break; case 0xE8: /*CALL rel 16*/ wait(1, 0); cpu_state.oldpc = jump_near(); - access(34, 8); + wait(2, 0); push((uint16_t *) &(cpu_state.oldpc)); break; case 0xE9: /*JMP rel 16*/ @@ -3291,8 +3592,8 @@ execx86(int cycs) wait(1, 0); tempw = pfq_fetchw(); load_cs(tempw); - access(70, 8); pfq_clear(); + wait(4, 0); set_ip(addr); break; case 0xEB: /*JMP rel*/ @@ -3319,17 +3620,22 @@ execx86(int cycs) case 0xF4: /*HLT*/ if (!repeating) { - wait(1, 0); + if ((BUS_CYCLE == BUS_T4) || !last_was_code) + cpu_data = 1; + else + cpu_data = 2; + wait(2, 0); pfq_clear(); } wait(1, 0); if (irq_pending()) { - wait(cycles & 1, 0); + wait(1, 0); + if (cpu_data == 2) + wait(1, 0); check_interrupts(); } else { repeating = 1; completed = 0; - clock_end(); } break; case 0xF5: /*CMC*/ @@ -3341,15 +3647,12 @@ execx86(int cycs) case 0xF7: bits = 8 << (opcode & 1); do_mod_rm(); - access(55, bits); cpu_data = get_ea(); switch (rmdat & 0x38) { case 0x00: case 0x08: /* TEST */ wait(2, 0); - if (cpu_mod != 3) - wait(1, 0); cpu_src = pfq_fetch(); wait(1, 0); test(bits, cpu_data, cpu_src); @@ -3366,7 +3669,8 @@ execx86(int cycs) cpu_dest = 0; sub(bits); } - access(18, bits); + if (cpu_mod != 3) + wait(2, 0); set_ea(cpu_data); break; case 0x20: /* MUL */ @@ -3388,8 +3692,6 @@ execx86(int cycs) } set_sf(bits); set_pf(); - if (cpu_mod != 3) - wait(1, 0); /* NOTE: When implementing the V20, care should be taken to not change the zero flag. */ if (is_nec) @@ -3397,8 +3699,6 @@ execx86(int cycs) break; case 0x30: /* DIV */ case 0x38: /* IDIV */ - if (cpu_mod != 3) - wait(1, 0); cpu_src = cpu_data; if (x86_div(AL, AH)) wait(1, 0); @@ -3430,7 +3730,6 @@ execx86(int cycs) /* misc */ bits = 8 << (opcode & 1); do_mod_rm(); - access(56, bits); read_ea(((rmdat & 0x38) == 0x18) || ((rmdat & 0x38) == 0x28), bits); switch (rmdat & 0x38) { case 0x00: /* INC rm */ @@ -3447,62 +3746,60 @@ execx86(int cycs) do_af(); set_pzs(bits); wait(2, 0); - access(19, bits); set_ea(cpu_data); break; case 0x10: /* CALL rm */ cpu_data_opff_rm(); - access(63, bits); - wait(1, 0); + wait(2, 0); pfq_clear(); - wait(4, 0); - if (cpu_mod != 3) - wait(1, 0); - wait(1, 0); /* Wait. */ + wait(5, 0); cpu_state.oldpc = cpu_state.pc; set_ip(cpu_data); wait(2, 0); - access(35, bits); push((uint16_t *) &(cpu_state.oldpc)); break; case 0x18: /* CALL rmd */ new_ip = cpu_data; - access(58, bits); + wait(3, 0); read_ea2(bits); if (!(opcode & 1)) cpu_data |= 0xff00; new_cs = cpu_data; - access(36, bits); + wait(1, 0); + pfq_clear(); push(&(CS)); - access(64, bits); wait(4, 0); cpu_state.oldpc = cpu_state.pc; load_cs(new_cs); set_ip(new_ip); - access(37, bits); + wait(1, 0); push((uint16_t *) &(cpu_state.oldpc)); break; case 0x20: /* JMP rm */ cpu_data_opff_rm(); - access(65, bits); + wait(2, 0); + pfq_clear(); + if (BUS_CYCLE != BUS_T4) + wait(1, 0); set_ip(cpu_data); break; case 0x28: /* JMP rmd */ new_ip = cpu_data; - access(59, bits); + wait(3, 0); + pfq_clear(); + wait(1, 0); read_ea2(bits); if (!(opcode & 1)) cpu_data |= 0xff00; new_cs = cpu_data; load_cs(new_cs); - access(66, bits); set_ip(new_ip); break; case 0x30: /* PUSH rm */ case 0x38: if (cpu_mod != 3) wait(1, 0); - access(38, bits); + wait(4, 0); push((uint16_t *) &(cpu_data)); break; } diff --git a/src/cpu/808x/CMakeLists.txt b/src/cpu/808x/CMakeLists.txt new file mode 100644 index 000000000..d29bdf4e0 --- /dev/null +++ b/src/cpu/808x/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# 86Box A hypervisor and IBM PC system emulator that specializes in +# running old operating systems and software designed for IBM +# PC systems and compatibles from 1981 through fairly recent +# system designs based on the PCI bus. +# +# This file is part of the 86Box distribution. +# +# CMake build script. +# +# Authors: David Hrdlička, +# +# Copyright 2020-2021 David Hrdlička. +# + +add_library(808x OBJECT queue.c) diff --git a/src/cpu/808x/queue.c b/src/cpu/808x/queue.c new file mode 100644 index 000000000..2eebde0ce --- /dev/null +++ b/src/cpu/808x/queue.c @@ -0,0 +1,190 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * 808x CPU emulation, mostly ported from reenigne's XTCE, which + * is cycle-accurate. + * + * Authors: gloriouscow, + * Miran Grca, + * + * Copyright 2023 gloriouscow. + * Copyright 2023 Miran Grca. + */ +#include +#include +#include +#include +#include +#include + +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include "x86.h" +#include <86box/machine.h> +#include <86box/io.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/nmi.h> +#include <86box/pic.h> +#include <86box/ppi.h> +#include <86box/timer.h> +#include <86box/gdbstub.h> +// #include "808x.h" +#include "queue.h" + +/* TODO: Move to cpu.h so this can eventually be reused for 286+ as well. */ +#define QUEUE_MAX 6 + +typedef struct queue_t +{ + size_t size; + size_t len; + size_t back; + size_t front; + uint8_t q[QUEUE_MAX]; + uint16_t preload; + queue_delay_t delay; +} queue_t; + +static queue_t queue; + +#ifdef ENABLE_QUEUE_LOG +int queue_do_log = ENABLE_QUEUE_LOG; + +static void +queue_log(const char *fmt, ...) +{ + va_list ap; + + if (queue_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define queue_log(fmt, ...) +#endif + +void +queue_set_size(size_t size) +{ + if (size > QUEUE_MAX) + fatal("Requested prefetch queue of %i bytes is too big\n", size); + + queue.size = size; +} + +size_t +queue_get_len(void) +{ + return queue.len; +} + +int +queue_is_full(void) +{ + return (queue.len != queue.size); +} + +uint16_t +queue_get_preload(void) +{ + uint16_t ret = queue.preload; + queue.preload = 0x0000; + + return ret; +} + +int +queue_has_preload(void) +{ + return (queue.preload & FLAG_PRELOADED) ? 1 : 0; +} + +void +queue_set_preload(void) +{ + uint8_t byte; + + if (queue.len > 0) { + byte = queue_pop(); + queue.preload = ((uint16_t) byte) | FLAG_PRELOADED; + } else + fatal("Tried to preload with empty queue\n"); +} + +void +queue_push8(uint8_t byte) +{ + if (queue.len < queue.size) { + queue.q[queue.front] = byte; + queue.front = (queue.front + 1) % queue.size; + queue.len++; + + if (queue.len == 3) + queue.delay = DELAY_WRITE; + else + queue.delay = DELAY_NONE; + } else + fatal("Queue overrun\n"); +} + +void +queue_push16(uint16_t word) +{ + queue_push8((uint8_t) (word & 0xff)); + queue_push8((uint8_t) ((word >> 8) & 0xff)); +} + +uint8_t +queue_pop(void) +{ + uint8_t byte = 0xff; + + if (queue.len > 0) { + byte = queue.q[queue.back]; + + queue.back = (queue.back + 1) % queue.size; + queue.len--; + + if (queue.len >= 3) + queue.delay = DELAY_READ; + else + queue.delay = DELAY_NONE; + } else + fatal("Queue underrun\n"); + + return byte; +} + +queue_delay_t +queue_get_delay(void) +{ + return queue.delay; +} + +void +queue_flush(void) +{ + memset(&queue, 0x00, sizeof(queue_t)); + + queue.delay = DELAY_NONE; +} + +void +queue_init(void) +{ + queue_flush(); + + if (is8086) + queue_set_size(6); + else + queue_set_size(4); +} diff --git a/src/cpu/808x/queue.h b/src/cpu/808x/queue.h new file mode 100644 index 000000000..544455784 --- /dev/null +++ b/src/cpu/808x/queue.h @@ -0,0 +1,43 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Prefetch queue implementation header. + * + * Authors: gloriouscow, + * Miran Grca, + * + * Copyright 2023 gloriouscow. + * Copyright 2023 Miran Grca. + */ +#ifndef EMU_QUEUE_H +#define EMU_QUEUE_H + +typedef enum queue_delay_t +{ + DELAY_READ, + DELAY_WRITE, + DELAY_NONE +} queue_delay_t; + +#define FLAG_PRELOADED 0x8000 + +extern void queue_set_size(size_t size); +extern size_t queue_get_len(void); +extern int queue_is_full(void); +extern uint16_t queue_get_preload(void); +extern int queue_has_preload(void); +extern void queue_set_preload(void); +extern void queue_push8(uint8_t byte); +extern void queue_push16(uint16_t word); +extern uint8_t queue_pop(void); +extern queue_delay_t queue_get_delay(void); +extern void queue_flush(void); + +extern void queue_init(void); + +#endif /*EMU_QUEUE_H*/ diff --git a/src/cpu/CMakeLists.txt b/src/cpu/CMakeLists.txt index 68baaf293..e4d8e71b2 100644 --- a/src/cpu/CMakeLists.txt +++ b/src/cpu/CMakeLists.txt @@ -14,7 +14,7 @@ # add_library(cpu OBJECT cpu.c cpu_table.c fpu.c x86.c 808x.c 386.c 386_common.c - 386_dynarec.c x86seg.c x87.c x87_timings.c 8080.c) + 386_dynarec.c x86_ops_mmx.c x86seg.c x87.c x87_timings.c 8080.c) if(AMD_K5) target_compile_definitions(cpu PRIVATE USE_AMD_K5) @@ -32,3 +32,9 @@ if(DYNAREC) codegen_timing_pentium.c codegen_timing_p6.c codegen_timing_winchip.c codegen_timing_winchip2.c) endif() + +add_subdirectory(softfloat) +target_link_libraries(86Box softfloat) + +add_subdirectory(808x) +target_link_libraries(86Box 808x) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index d48ebe194..d633b9bb2 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -74,71 +74,153 @@ enum { /* Make sure this is as low as possible. */ cpu_state_t cpu_state; +fpu_state_t fpu_state; /* Place this immediately after. */ uint32_t abrt_error; #ifdef USE_DYNAREC -const OpFn *x86_dynarec_opcodes, *x86_dynarec_opcodes_0f, - *x86_dynarec_opcodes_d8_a16, *x86_dynarec_opcodes_d8_a32, - *x86_dynarec_opcodes_d9_a16, *x86_dynarec_opcodes_d9_a32, - *x86_dynarec_opcodes_da_a16, *x86_dynarec_opcodes_da_a32, - *x86_dynarec_opcodes_db_a16, *x86_dynarec_opcodes_db_a32, - *x86_dynarec_opcodes_dc_a16, *x86_dynarec_opcodes_dc_a32, - *x86_dynarec_opcodes_dd_a16, *x86_dynarec_opcodes_dd_a32, - *x86_dynarec_opcodes_de_a16, *x86_dynarec_opcodes_de_a32, - *x86_dynarec_opcodes_df_a16, *x86_dynarec_opcodes_df_a32, - *x86_dynarec_opcodes_REPE, *x86_dynarec_opcodes_REPNE, - *x86_dynarec_opcodes_3DNOW; +const OpFn *x86_dynarec_opcodes; +const OpFn *x86_dynarec_opcodes_0f; +const OpFn *x86_dynarec_opcodes_d8_a16; +const OpFn *x86_dynarec_opcodes_d8_a32; +const OpFn *x86_dynarec_opcodes_d9_a16; +const OpFn *x86_dynarec_opcodes_d9_a32; +const OpFn *x86_dynarec_opcodes_da_a16; +const OpFn *x86_dynarec_opcodes_da_a32; +const OpFn *x86_dynarec_opcodes_db_a16; +const OpFn *x86_dynarec_opcodes_db_a32; +const OpFn *x86_dynarec_opcodes_dc_a16; +const OpFn *x86_dynarec_opcodes_dc_a32; +const OpFn *x86_dynarec_opcodes_dd_a16; +const OpFn *x86_dynarec_opcodes_dd_a32; +const OpFn *x86_dynarec_opcodes_de_a16; +const OpFn *x86_dynarec_opcodes_de_a32; +const OpFn *x86_dynarec_opcodes_df_a16; +const OpFn *x86_dynarec_opcodes_df_a32; +const OpFn *x86_dynarec_opcodes_REPE; +const OpFn *x86_dynarec_opcodes_REPNE; +const OpFn *x86_dynarec_opcodes_3DNOW; #endif -const OpFn *x86_opcodes, *x86_opcodes_0f, - *x86_opcodes_d8_a16, *x86_opcodes_d8_a32, - *x86_opcodes_d9_a16, *x86_opcodes_d9_a32, - *x86_opcodes_da_a16, *x86_opcodes_da_a32, - *x86_opcodes_db_a16, *x86_opcodes_db_a32, - *x86_opcodes_dc_a16, *x86_opcodes_dc_a32, - *x86_opcodes_dd_a16, *x86_opcodes_dd_a32, - *x86_opcodes_de_a16, *x86_opcodes_de_a32, - *x86_opcodes_df_a16, *x86_opcodes_df_a32, - *x86_opcodes_REPE, *x86_opcodes_REPNE, - *x86_opcodes_3DNOW; +const OpFn *x86_opcodes; +const OpFn *x86_opcodes_0f; +const OpFn *x86_opcodes_d8_a16; +const OpFn *x86_opcodes_d8_a32; +const OpFn *x86_opcodes_d9_a16; +const OpFn *x86_opcodes_d9_a32; +const OpFn *x86_opcodes_da_a16; +const OpFn *x86_opcodes_da_a32; +const OpFn *x86_opcodes_db_a16; +const OpFn *x86_opcodes_db_a32; +const OpFn *x86_opcodes_dc_a16; +const OpFn *x86_opcodes_dc_a32; +const OpFn *x86_opcodes_dd_a16; +const OpFn *x86_opcodes_dd_a32; +const OpFn *x86_opcodes_de_a16; +const OpFn *x86_opcodes_de_a32; +const OpFn *x86_opcodes_df_a16; +const OpFn *x86_opcodes_df_a32; +const OpFn *x86_opcodes_REPE; +const OpFn *x86_opcodes_REPNE; +const OpFn *x86_opcodes_3DNOW; -uint16_t cpu_fast_off_count, cpu_fast_off_val; +uint16_t cpu_fast_off_count; +uint16_t cpu_fast_off_val; uint16_t temp_seg_data[4] = { 0, 0, 0, 0 }; -int isa_cycles, cpu_inited, +int isa_cycles; +int cpu_inited; - cpu_cycles_read, cpu_cycles_read_l, cpu_cycles_write, cpu_cycles_write_l, - cpu_prefetch_cycles, cpu_prefetch_width, cpu_mem_prefetch_cycles, cpu_rom_prefetch_cycles, - cpu_waitstates, cpu_cache_int_enabled, cpu_cache_ext_enabled, - cpu_isa_speed, cpu_pci_speed, cpu_isa_pci_div, cpu_agp_speed, cpu_alt_reset, +int cpu_cycles_read; +int cpu_cycles_read_l; +int cpu_cycles_write; +int cpu_cycles_write_l; +int cpu_prefetch_cycles; +int cpu_prefetch_width; +int cpu_mem_prefetch_cycles; +int cpu_rom_prefetch_cycles; +int cpu_waitstates; +int cpu_cache_int_enabled; +int cpu_cache_ext_enabled; +int cpu_isa_speed; +int cpu_pci_speed; +int cpu_isa_pci_div; +int cpu_agp_speed; +int cpu_alt_reset; - cpu_override, cpu_effective, cpu_multi, cpu_16bitbus, cpu_64bitbus, cpu_busspeed, - cpu_cyrix_alignment, CPUID, +int cpu_override; +int cpu_effective; +int cpu_multi; +int cpu_16bitbus; +int cpu_64bitbus; +int cpu_cyrix_alignment; +int CPUID; - is186, is_nec, - is286, is386, is6117, is486 = 1, - cpu_isintel, cpu_iscyrix, hascache, isibm486, israpidcad, is_vpc, - is_am486, is_am486dxl, is_pentium, is_k5, is_k6, is_p6, is_cxsmm, hasfpu, +int is186; +int is_nec; +int is286; +int is386; +int is6117; +int is486 = 1; +int cpu_isintel; +int cpu_iscyrix; +int hascache; +int isibm486; +int israpidcad; +int is_vpc; +int is_am486; +int is_am486dxl; +int is_pentium; +int is_k5; +int is_k6; +int is_p6; +int is_cxsmm; +int hasfpu; - timing_rr, timing_mr, timing_mrl, timing_rm, timing_rml, - timing_mm, timing_mml, timing_bt, timing_bnt, - timing_int, timing_int_rm, timing_int_v86, timing_int_pm, - timing_int_pm_outer, timing_iret_rm, timing_iret_v86, timing_iret_pm, - timing_iret_pm_outer, timing_call_rm, timing_call_pm, timing_call_pm_gate, - timing_call_pm_gate_inner, timing_retf_rm, timing_retf_pm, timing_retf_pm_outer, - timing_jmp_rm, timing_jmp_pm, timing_jmp_pm_gate, timing_misaligned; -uint32_t cpu_features, cpu_fast_off_flags; +int timing_rr; +int timing_mr; +int timing_mrl; +int timing_rm; +int timing_rml; +int timing_mm; +int timing_mml; +int timing_bt; +int timing_bnt; +int timing_int; +int timing_int_rm; +int timing_int_v86; +int timing_int_pm; +int timing_int_pm_outer; +int timing_iret_rm; +int timing_iret_v86; +int timing_iret_pm; +int timing_iret_pm_outer; +int timing_call_rm; +int timing_call_pm; +int timing_call_pm_gate; +int timing_call_pm_gate_inner; +int timing_retf_rm; +int timing_retf_pm; +int timing_retf_pm_outer; +int timing_jmp_rm; +int timing_jmp_pm; +int timing_jmp_pm_gate; +int timing_misaligned; + +uint32_t cpu_features; +uint32_t cpu_fast_off_flags; uint32_t _tr[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; uint32_t cache_index = 0; uint8_t _cache[2048]; -uint64_t cpu_CR4_mask, tsc = 0; +uint64_t cpu_CR4_mask; +uint64_t tsc = 0; uint64_t pmc[2] = { 0, 0 }; double cpu_dmulti; +double cpu_busspeed; msr_t msr; @@ -147,11 +229,18 @@ cyrix_t cyrix; cpu_family_t *cpu_f; CPU *cpu_s; -uint8_t do_translate = 0, do_translate2 = 0; +uint8_t do_translate = 0; +uint8_t do_translate2 = 0; void (*cpu_exec)(int cycs); -static uint8_t ccr0, ccr1, ccr2, ccr3, ccr4, ccr5, ccr6; +static uint8_t ccr0; +static uint8_t ccr1; +static uint8_t ccr2; +static uint8_t ccr3; +static uint8_t ccr4; +static uint8_t ccr5; +static uint8_t ccr6; static int cyrix_addr; @@ -201,6 +290,8 @@ void cpu_set_edx(void) { EDX = cpu_s->edx_reset; + if (fpu_softfloat) + SF_FPU_reset(); } cpu_family_t * @@ -222,7 +313,8 @@ cpu_is_eligible(const cpu_family_t *cpu_family, int cpu, int machine) { const machine_t *machine_s = &machines[machine]; const CPU *cpu_s = &cpu_family->cpus[cpu]; - uint32_t packages, bus_speed; + uint32_t packages; + uint32_t bus_speed; uint8_t i; double multi; @@ -344,6 +436,23 @@ cpu_family_is_eligible(const cpu_family_t *cpu_family, int machine) return 0; } +void +SF_FPU_reset(void) +{ + if (fpu_type != FPU_NONE) { + fpu_state.cwd = 0x0040; + fpu_state.swd = 0; + fpu_state.tos = 0; + fpu_state.tag = 0x5555; + fpu_state.foo = 0; + fpu_state.fip = 0; + fpu_state.fcs = 0; + fpu_state.fds = 0; + fpu_state.fdp = 0; + memset(fpu_state.st_space, 0, sizeof(floatx80)*8); + } +} + void cpu_set(void) { @@ -437,39 +546,77 @@ cpu_set(void) if (hasfpu) { #ifdef USE_DYNAREC - x86_dynarec_opcodes_d8_a16 = dynarec_ops_fpu_d8_a16; - x86_dynarec_opcodes_d8_a32 = dynarec_ops_fpu_d8_a32; - x86_dynarec_opcodes_d9_a16 = dynarec_ops_fpu_d9_a16; - x86_dynarec_opcodes_d9_a32 = dynarec_ops_fpu_d9_a32; - x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_da_a16; - x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_da_a32; - x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_db_a16; - x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_db_a32; - x86_dynarec_opcodes_dc_a16 = dynarec_ops_fpu_dc_a16; - x86_dynarec_opcodes_dc_a32 = dynarec_ops_fpu_dc_a32; - x86_dynarec_opcodes_dd_a16 = dynarec_ops_fpu_dd_a16; - x86_dynarec_opcodes_dd_a32 = dynarec_ops_fpu_dd_a32; - x86_dynarec_opcodes_de_a16 = dynarec_ops_fpu_de_a16; - x86_dynarec_opcodes_de_a32 = dynarec_ops_fpu_de_a32; - x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_df_a16; - x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_df_a32; + if (fpu_softfloat) { + x86_dynarec_opcodes_d8_a16 = dynarec_ops_sf_fpu_d8_a16; + x86_dynarec_opcodes_d8_a32 = dynarec_ops_sf_fpu_d8_a32; + x86_dynarec_opcodes_d9_a16 = dynarec_ops_sf_fpu_d9_a16; + x86_dynarec_opcodes_d9_a32 = dynarec_ops_sf_fpu_d9_a32; + x86_dynarec_opcodes_da_a16 = dynarec_ops_sf_fpu_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_sf_fpu_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_sf_fpu_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_sf_fpu_db_a32; + x86_dynarec_opcodes_dc_a16 = dynarec_ops_sf_fpu_dc_a16; + x86_dynarec_opcodes_dc_a32 = dynarec_ops_sf_fpu_dc_a32; + x86_dynarec_opcodes_dd_a16 = dynarec_ops_sf_fpu_dd_a16; + x86_dynarec_opcodes_dd_a32 = dynarec_ops_sf_fpu_dd_a32; + x86_dynarec_opcodes_de_a16 = dynarec_ops_sf_fpu_de_a16; + x86_dynarec_opcodes_de_a32 = dynarec_ops_sf_fpu_de_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_sf_fpu_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_sf_fpu_df_a32; + } else { + x86_dynarec_opcodes_d8_a16 = dynarec_ops_fpu_d8_a16; + x86_dynarec_opcodes_d8_a32 = dynarec_ops_fpu_d8_a32; + x86_dynarec_opcodes_d9_a16 = dynarec_ops_fpu_d9_a16; + x86_dynarec_opcodes_d9_a32 = dynarec_ops_fpu_d9_a32; + x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_db_a32; + x86_dynarec_opcodes_dc_a16 = dynarec_ops_fpu_dc_a16; + x86_dynarec_opcodes_dc_a32 = dynarec_ops_fpu_dc_a32; + x86_dynarec_opcodes_dd_a16 = dynarec_ops_fpu_dd_a16; + x86_dynarec_opcodes_dd_a32 = dynarec_ops_fpu_dd_a32; + x86_dynarec_opcodes_de_a16 = dynarec_ops_fpu_de_a16; + x86_dynarec_opcodes_de_a32 = dynarec_ops_fpu_de_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_df_a32; + } #endif - x86_opcodes_d8_a16 = ops_fpu_d8_a16; - x86_opcodes_d8_a32 = ops_fpu_d8_a32; - x86_opcodes_d9_a16 = ops_fpu_d9_a16; - x86_opcodes_d9_a32 = ops_fpu_d9_a32; - x86_opcodes_da_a16 = ops_fpu_da_a16; - x86_opcodes_da_a32 = ops_fpu_da_a32; - x86_opcodes_db_a16 = ops_fpu_db_a16; - x86_opcodes_db_a32 = ops_fpu_db_a32; - x86_opcodes_dc_a16 = ops_fpu_dc_a16; - x86_opcodes_dc_a32 = ops_fpu_dc_a32; - x86_opcodes_dd_a16 = ops_fpu_dd_a16; - x86_opcodes_dd_a32 = ops_fpu_dd_a32; - x86_opcodes_de_a16 = ops_fpu_de_a16; - x86_opcodes_de_a32 = ops_fpu_de_a32; - x86_opcodes_df_a16 = ops_fpu_df_a16; - x86_opcodes_df_a32 = ops_fpu_df_a32; + if (fpu_softfloat) { + x86_opcodes_d8_a16 = ops_sf_fpu_d8_a16; + x86_opcodes_d8_a32 = ops_sf_fpu_d8_a32; + x86_opcodes_d9_a16 = ops_sf_fpu_d9_a16; + x86_opcodes_d9_a32 = ops_sf_fpu_d9_a32; + x86_opcodes_da_a16 = ops_sf_fpu_da_a16; + x86_opcodes_da_a32 = ops_sf_fpu_da_a32; + x86_opcodes_db_a16 = ops_sf_fpu_db_a16; + x86_opcodes_db_a32 = ops_sf_fpu_db_a32; + x86_opcodes_dc_a16 = ops_sf_fpu_dc_a16; + x86_opcodes_dc_a32 = ops_sf_fpu_dc_a32; + x86_opcodes_dd_a16 = ops_sf_fpu_dd_a16; + x86_opcodes_dd_a32 = ops_sf_fpu_dd_a32; + x86_opcodes_de_a16 = ops_sf_fpu_de_a16; + x86_opcodes_de_a32 = ops_sf_fpu_de_a32; + x86_opcodes_df_a16 = ops_sf_fpu_df_a16; + x86_opcodes_df_a32 = ops_sf_fpu_df_a32; + } else { + x86_opcodes_d8_a16 = ops_fpu_d8_a16; + x86_opcodes_d8_a32 = ops_fpu_d8_a32; + x86_opcodes_d9_a16 = ops_fpu_d9_a16; + x86_opcodes_d9_a32 = ops_fpu_d9_a32; + x86_opcodes_da_a16 = ops_fpu_da_a16; + x86_opcodes_da_a32 = ops_fpu_da_a32; + x86_opcodes_db_a16 = ops_fpu_db_a16; + x86_opcodes_db_a32 = ops_fpu_db_a32; + x86_opcodes_dc_a16 = ops_fpu_dc_a16; + x86_opcodes_dc_a32 = ops_fpu_dc_a32; + x86_opcodes_dd_a16 = ops_fpu_dd_a16; + x86_opcodes_dd_a32 = ops_fpu_dd_a32; + x86_opcodes_de_a16 = ops_fpu_de_a16; + x86_opcodes_de_a32 = ops_fpu_de_a32; + x86_opcodes_df_a16 = ops_fpu_df_a16; + x86_opcodes_df_a32 = ops_fpu_df_a32; + } } else { #ifdef USE_DYNAREC x86_dynarec_opcodes_d8_a16 = dynarec_ops_nofpu_a16; @@ -542,35 +689,69 @@ cpu_set(void) if (fpu_type == FPU_287) { #ifdef USE_DYNAREC - x86_dynarec_opcodes_d9_a16 = dynarec_ops_fpu_287_d9_a16; - x86_dynarec_opcodes_d9_a32 = dynarec_ops_fpu_287_d9_a32; - x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_287_da_a16; - x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_287_da_a32; - x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_287_db_a16; - x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_287_db_a32; - x86_dynarec_opcodes_dc_a16 = dynarec_ops_fpu_287_dc_a16; - x86_dynarec_opcodes_dc_a32 = dynarec_ops_fpu_287_dc_a32; - x86_dynarec_opcodes_dd_a16 = dynarec_ops_fpu_287_dd_a16; - x86_dynarec_opcodes_dd_a32 = dynarec_ops_fpu_287_dd_a32; - x86_dynarec_opcodes_de_a16 = dynarec_ops_fpu_287_de_a16; - x86_dynarec_opcodes_de_a32 = dynarec_ops_fpu_287_de_a32; - x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_287_df_a16; - x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_287_df_a32; + if (fpu_softfloat) { + x86_dynarec_opcodes_d9_a16 = dynarec_ops_sf_fpu_287_d9_a16; + x86_dynarec_opcodes_d9_a32 = dynarec_ops_sf_fpu_287_d9_a32; + x86_dynarec_opcodes_da_a16 = dynarec_ops_sf_fpu_287_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_sf_fpu_287_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_sf_fpu_287_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_sf_fpu_287_db_a32; + x86_dynarec_opcodes_dc_a16 = dynarec_ops_sf_fpu_287_dc_a16; + x86_dynarec_opcodes_dc_a32 = dynarec_ops_sf_fpu_287_dc_a32; + x86_dynarec_opcodes_dd_a16 = dynarec_ops_sf_fpu_287_dd_a16; + x86_dynarec_opcodes_dd_a32 = dynarec_ops_sf_fpu_287_dd_a32; + x86_dynarec_opcodes_de_a16 = dynarec_ops_sf_fpu_287_de_a16; + x86_dynarec_opcodes_de_a32 = dynarec_ops_sf_fpu_287_de_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_sf_fpu_287_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_sf_fpu_287_df_a32; + } else { + x86_dynarec_opcodes_d9_a16 = dynarec_ops_fpu_287_d9_a16; + x86_dynarec_opcodes_d9_a32 = dynarec_ops_fpu_287_d9_a32; + x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_287_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_287_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_287_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_287_db_a32; + x86_dynarec_opcodes_dc_a16 = dynarec_ops_fpu_287_dc_a16; + x86_dynarec_opcodes_dc_a32 = dynarec_ops_fpu_287_dc_a32; + x86_dynarec_opcodes_dd_a16 = dynarec_ops_fpu_287_dd_a16; + x86_dynarec_opcodes_dd_a32 = dynarec_ops_fpu_287_dd_a32; + x86_dynarec_opcodes_de_a16 = dynarec_ops_fpu_287_de_a16; + x86_dynarec_opcodes_de_a32 = dynarec_ops_fpu_287_de_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_287_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_287_df_a32; + } #endif - x86_opcodes_d9_a16 = ops_fpu_287_d9_a16; - x86_opcodes_d9_a32 = ops_fpu_287_d9_a32; - x86_opcodes_da_a16 = ops_fpu_287_da_a16; - x86_opcodes_da_a32 = ops_fpu_287_da_a32; - x86_opcodes_db_a16 = ops_fpu_287_db_a16; - x86_opcodes_db_a32 = ops_fpu_287_db_a32; - x86_opcodes_dc_a16 = ops_fpu_287_dc_a16; - x86_opcodes_dc_a32 = ops_fpu_287_dc_a32; - x86_opcodes_dd_a16 = ops_fpu_287_dd_a16; - x86_opcodes_dd_a32 = ops_fpu_287_dd_a32; - x86_opcodes_de_a16 = ops_fpu_287_de_a16; - x86_opcodes_de_a32 = ops_fpu_287_de_a32; - x86_opcodes_df_a16 = ops_fpu_287_df_a16; - x86_opcodes_df_a32 = ops_fpu_287_df_a32; + if (fpu_softfloat) { + x86_opcodes_d9_a16 = ops_sf_fpu_287_d9_a16; + x86_opcodes_d9_a32 = ops_sf_fpu_287_d9_a32; + x86_opcodes_da_a16 = ops_sf_fpu_287_da_a16; + x86_opcodes_da_a32 = ops_sf_fpu_287_da_a32; + x86_opcodes_db_a16 = ops_sf_fpu_287_db_a16; + x86_opcodes_db_a32 = ops_sf_fpu_287_db_a32; + x86_opcodes_dc_a16 = ops_sf_fpu_287_dc_a16; + x86_opcodes_dc_a32 = ops_sf_fpu_287_dc_a32; + x86_opcodes_dd_a16 = ops_sf_fpu_287_dd_a16; + x86_opcodes_dd_a32 = ops_sf_fpu_287_dd_a32; + x86_opcodes_de_a16 = ops_sf_fpu_287_de_a16; + x86_opcodes_de_a32 = ops_sf_fpu_287_de_a32; + x86_opcodes_df_a16 = ops_sf_fpu_287_df_a16; + x86_opcodes_df_a32 = ops_sf_fpu_287_df_a32; + } else { + x86_opcodes_d9_a16 = ops_fpu_287_d9_a16; + x86_opcodes_d9_a32 = ops_fpu_287_d9_a32; + x86_opcodes_da_a16 = ops_fpu_287_da_a16; + x86_opcodes_da_a32 = ops_fpu_287_da_a32; + x86_opcodes_db_a16 = ops_fpu_287_db_a16; + x86_opcodes_db_a32 = ops_fpu_287_db_a32; + x86_opcodes_dc_a16 = ops_fpu_287_dc_a16; + x86_opcodes_dc_a32 = ops_fpu_287_dc_a32; + x86_opcodes_dd_a16 = ops_fpu_287_dd_a16; + x86_opcodes_dd_a32 = ops_fpu_287_dd_a32; + x86_opcodes_de_a16 = ops_fpu_287_de_a16; + x86_opcodes_de_a32 = ops_fpu_287_de_a32; + x86_opcodes_df_a16 = ops_fpu_287_df_a16; + x86_opcodes_df_a32 = ops_fpu_287_df_a32; + } } timing_rr = 2; /* register dest - register src */ @@ -618,35 +799,69 @@ cpu_set(void) case CPU_386DX: if (fpu_type == FPU_287) { /* In case we get Deskpro 386 emulation */ #ifdef USE_DYNAREC - x86_dynarec_opcodes_d9_a16 = dynarec_ops_fpu_287_d9_a16; - x86_dynarec_opcodes_d9_a32 = dynarec_ops_fpu_287_d9_a32; - x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_287_da_a16; - x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_287_da_a32; - x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_287_db_a16; - x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_287_db_a32; - x86_dynarec_opcodes_dc_a16 = dynarec_ops_fpu_287_dc_a16; - x86_dynarec_opcodes_dc_a32 = dynarec_ops_fpu_287_dc_a32; - x86_dynarec_opcodes_dd_a16 = dynarec_ops_fpu_287_dd_a16; - x86_dynarec_opcodes_dd_a32 = dynarec_ops_fpu_287_dd_a32; - x86_dynarec_opcodes_de_a16 = dynarec_ops_fpu_287_de_a16; - x86_dynarec_opcodes_de_a32 = dynarec_ops_fpu_287_de_a32; - x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_287_df_a16; - x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_287_df_a32; + if (fpu_softfloat) { + x86_dynarec_opcodes_d9_a16 = dynarec_ops_sf_fpu_287_d9_a16; + x86_dynarec_opcodes_d9_a32 = dynarec_ops_sf_fpu_287_d9_a32; + x86_dynarec_opcodes_da_a16 = dynarec_ops_sf_fpu_287_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_sf_fpu_287_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_sf_fpu_287_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_sf_fpu_287_db_a32; + x86_dynarec_opcodes_dc_a16 = dynarec_ops_sf_fpu_287_dc_a16; + x86_dynarec_opcodes_dc_a32 = dynarec_ops_sf_fpu_287_dc_a32; + x86_dynarec_opcodes_dd_a16 = dynarec_ops_sf_fpu_287_dd_a16; + x86_dynarec_opcodes_dd_a32 = dynarec_ops_sf_fpu_287_dd_a32; + x86_dynarec_opcodes_de_a16 = dynarec_ops_sf_fpu_287_de_a16; + x86_dynarec_opcodes_de_a32 = dynarec_ops_sf_fpu_287_de_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_sf_fpu_287_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_sf_fpu_287_df_a32; + } else { + x86_dynarec_opcodes_d9_a16 = dynarec_ops_fpu_287_d9_a16; + x86_dynarec_opcodes_d9_a32 = dynarec_ops_fpu_287_d9_a32; + x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_287_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_287_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_287_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_287_db_a32; + x86_dynarec_opcodes_dc_a16 = dynarec_ops_fpu_287_dc_a16; + x86_dynarec_opcodes_dc_a32 = dynarec_ops_fpu_287_dc_a32; + x86_dynarec_opcodes_dd_a16 = dynarec_ops_fpu_287_dd_a16; + x86_dynarec_opcodes_dd_a32 = dynarec_ops_fpu_287_dd_a32; + x86_dynarec_opcodes_de_a16 = dynarec_ops_fpu_287_de_a16; + x86_dynarec_opcodes_de_a32 = dynarec_ops_fpu_287_de_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_287_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_287_df_a32; + } #endif - x86_opcodes_d9_a16 = ops_fpu_287_d9_a16; - x86_opcodes_d9_a32 = ops_fpu_287_d9_a32; - x86_opcodes_da_a16 = ops_fpu_287_da_a16; - x86_opcodes_da_a32 = ops_fpu_287_da_a32; - x86_opcodes_db_a16 = ops_fpu_287_db_a16; - x86_opcodes_db_a32 = ops_fpu_287_db_a32; - x86_opcodes_dc_a16 = ops_fpu_287_dc_a16; - x86_opcodes_dc_a32 = ops_fpu_287_dc_a32; - x86_opcodes_dd_a16 = ops_fpu_287_dd_a16; - x86_opcodes_dd_a32 = ops_fpu_287_dd_a32; - x86_opcodes_de_a16 = ops_fpu_287_de_a16; - x86_opcodes_de_a32 = ops_fpu_287_de_a32; - x86_opcodes_df_a16 = ops_fpu_287_df_a16; - x86_opcodes_df_a32 = ops_fpu_287_df_a32; + if (fpu_softfloat) { + x86_opcodes_d9_a16 = ops_sf_fpu_287_d9_a16; + x86_opcodes_d9_a32 = ops_sf_fpu_287_d9_a32; + x86_opcodes_da_a16 = ops_sf_fpu_287_da_a16; + x86_opcodes_da_a32 = ops_sf_fpu_287_da_a32; + x86_opcodes_db_a16 = ops_sf_fpu_287_db_a16; + x86_opcodes_db_a32 = ops_sf_fpu_287_db_a32; + x86_opcodes_dc_a16 = ops_sf_fpu_287_dc_a16; + x86_opcodes_dc_a32 = ops_sf_fpu_287_dc_a32; + x86_opcodes_dd_a16 = ops_sf_fpu_287_dd_a16; + x86_opcodes_dd_a32 = ops_sf_fpu_287_dd_a32; + x86_opcodes_de_a16 = ops_sf_fpu_287_de_a16; + x86_opcodes_de_a32 = ops_sf_fpu_287_de_a32; + x86_opcodes_df_a16 = ops_sf_fpu_287_df_a16; + x86_opcodes_df_a32 = ops_sf_fpu_287_df_a32; + } else { + x86_opcodes_d9_a16 = ops_fpu_287_d9_a16; + x86_opcodes_d9_a32 = ops_fpu_287_d9_a32; + x86_opcodes_da_a16 = ops_fpu_287_da_a16; + x86_opcodes_da_a32 = ops_fpu_287_da_a32; + x86_opcodes_db_a16 = ops_fpu_287_db_a16; + x86_opcodes_db_a32 = ops_fpu_287_db_a32; + x86_opcodes_dc_a16 = ops_fpu_287_dc_a16; + x86_opcodes_dc_a32 = ops_fpu_287_dc_a32; + x86_opcodes_dd_a16 = ops_fpu_287_dd_a16; + x86_opcodes_dd_a32 = ops_fpu_287_dd_a32; + x86_opcodes_de_a16 = ops_fpu_287_de_a16; + x86_opcodes_de_a32 = ops_fpu_287_de_a32; + x86_opcodes_df_a16 = ops_fpu_287_df_a16; + x86_opcodes_df_a32 = ops_fpu_287_df_a32; + } } timing_rr = 2; /* register dest - register src */ @@ -1041,19 +1256,37 @@ cpu_set(void) case CPU_Cx6x86MX: if (cpu_s->cpu_type == CPU_Cx6x86MX) { # ifdef USE_DYNAREC - x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_686_da_a16; - x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_686_da_a32; - x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_686_db_a16; - x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_686_db_a32; - x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_686_df_a16; - x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_686_df_a32; + if (fpu_softfloat) { + x86_dynarec_opcodes_da_a16 = dynarec_ops_sf_fpu_686_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_sf_fpu_686_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_sf_fpu_686_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_sf_fpu_686_db_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_sf_fpu_686_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_sf_fpu_686_df_a32; + } else { + x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_686_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_686_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_686_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_686_db_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_686_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_686_df_a32; + } # endif - x86_opcodes_da_a16 = ops_fpu_686_da_a16; - x86_opcodes_da_a32 = ops_fpu_686_da_a32; - x86_opcodes_db_a16 = ops_fpu_686_db_a16; - x86_opcodes_db_a32 = ops_fpu_686_db_a32; - x86_opcodes_df_a16 = ops_fpu_686_df_a16; - x86_opcodes_df_a32 = ops_fpu_686_df_a32; + if (fpu_softfloat) { + x86_opcodes_da_a16 = ops_sf_fpu_686_da_a16; + x86_opcodes_da_a32 = ops_sf_fpu_686_da_a32; + x86_opcodes_db_a16 = ops_sf_fpu_686_db_a16; + x86_opcodes_db_a32 = ops_sf_fpu_686_db_a32; + x86_opcodes_df_a16 = ops_sf_fpu_686_df_a16; + x86_opcodes_df_a32 = ops_sf_fpu_686_df_a32; + } else { + x86_opcodes_da_a16 = ops_fpu_686_da_a16; + x86_opcodes_da_a32 = ops_fpu_686_da_a32; + x86_opcodes_db_a16 = ops_fpu_686_db_a16; + x86_opcodes_db_a32 = ops_fpu_686_db_a32; + x86_opcodes_df_a16 = ops_fpu_686_df_a16; + x86_opcodes_df_a32 = ops_fpu_686_df_a32; + } } # ifdef USE_DYNAREC @@ -1070,7 +1303,8 @@ cpu_set(void) else if (cpu_s->cpu_type == CPU_Cx6x86L) x86_setopcodes(ops_386, ops_pentium_0f); else - x86_setopcodes(ops_386, ops_c6x86_0f); + x86_setopcodes(ops_386, ops_c6x86mx_0f); + // x86_setopcodes(ops_386, ops_c6x86_0f); # endif timing_rr = 1; /* register dest - register src */ @@ -1244,24 +1478,42 @@ cpu_set(void) x86_setopcodes(ops_386, ops_pentium2_0f, dynarec_ops_386, dynarec_ops_pentium2_0f); else x86_setopcodes(ops_386, ops_pentiumpro_0f, dynarec_ops_386, dynarec_ops_pentiumpro_0f); - x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_686_da_a16; - x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_686_da_a32; - x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_686_db_a16; - x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_686_db_a32; - x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_686_df_a16; - x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_686_df_a32; + if (fpu_softfloat) { + x86_dynarec_opcodes_da_a16 = dynarec_ops_sf_fpu_686_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_sf_fpu_686_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_sf_fpu_686_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_sf_fpu_686_db_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_sf_fpu_686_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_sf_fpu_686_df_a32; + } else { + x86_dynarec_opcodes_da_a16 = dynarec_ops_fpu_686_da_a16; + x86_dynarec_opcodes_da_a32 = dynarec_ops_fpu_686_da_a32; + x86_dynarec_opcodes_db_a16 = dynarec_ops_fpu_686_db_a16; + x86_dynarec_opcodes_db_a32 = dynarec_ops_fpu_686_db_a32; + x86_dynarec_opcodes_df_a16 = dynarec_ops_fpu_686_df_a16; + x86_dynarec_opcodes_df_a32 = dynarec_ops_fpu_686_df_a32; + } #else if (cpu_s->cpu_type == CPU_PENTIUM2D) x86_setopcodes(ops_386, ops_pentium2d_0f); else x86_setopcodes(ops_386, ops_pentium2_0f); #endif - x86_opcodes_da_a16 = ops_fpu_686_da_a16; - x86_opcodes_da_a32 = ops_fpu_686_da_a32; - x86_opcodes_db_a16 = ops_fpu_686_db_a16; - x86_opcodes_db_a32 = ops_fpu_686_db_a32; - x86_opcodes_df_a16 = ops_fpu_686_df_a16; - x86_opcodes_df_a32 = ops_fpu_686_df_a32; + if (fpu_softfloat) { + x86_opcodes_da_a16 = ops_sf_fpu_686_da_a16; + x86_opcodes_da_a32 = ops_sf_fpu_686_da_a32; + x86_opcodes_db_a16 = ops_sf_fpu_686_db_a16; + x86_opcodes_db_a32 = ops_sf_fpu_686_db_a32; + x86_opcodes_df_a16 = ops_sf_fpu_686_df_a16; + x86_opcodes_df_a32 = ops_sf_fpu_686_df_a32; + } else { + x86_opcodes_da_a16 = ops_fpu_686_da_a16; + x86_opcodes_da_a32 = ops_fpu_686_da_a32; + x86_opcodes_db_a16 = ops_fpu_686_db_a16; + x86_opcodes_db_a32 = ops_fpu_686_db_a32; + x86_opcodes_df_a16 = ops_fpu_686_df_a16; + x86_opcodes_df_a32 = ops_fpu_686_df_a32; + } timing_rr = 1; /* register dest - register src */ timing_rm = 2; /* register dest - memory src */ @@ -1357,7 +1609,7 @@ cpu_set(void) break; default: - fatal("cpu_set : unknown CPU type %i\n", cpu_s->cpu_type); + fatal("cpu_set : unknown CPU type %llu\n", cpu_s->cpu_type); } switch (fpu_type) { @@ -1394,6 +1646,7 @@ cpu_set(void) cpu_exec = exec386; else cpu_exec = execx86; + mmx_init(); gdbstub_cpu_init(); } @@ -1484,7 +1737,7 @@ cpu_current_pc(char *bufp) sprintf(bufp, "%04X:%04X", CS, cpu_state.pc); - return (bufp); + return bufp; } void @@ -3062,7 +3315,7 @@ cpu_write(uint16_t addr, uint8_t val, void *priv) if (!(ccr3 & CCR3_SMI_LOCK) || in_smm) { cyrix.arr[3].base = (cyrix.arr[3].base & ~0x0000f000) | ((val & 0xf0) << 8); if ((val & 0xf) == 0xf) - cyrix.arr[3].size = 1ull << 32; /* 4 GB */ + cyrix.arr[3].size = 1ULL << 32; /* 4 GB */ else if (val & 0xf) cyrix.arr[3].size = 2048 << (val & 0xf); else @@ -3124,6 +3377,9 @@ cpu_read(uint16_t addr, void *priv) return cpu_s->cyrix_id & 0xff; case 0xff: return cpu_s->cyrix_id >> 8; + + default: + break; } if ((cyrix_addr & 0xf0) == 0xc0) diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 25ff141a7..d13201608 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -21,6 +21,8 @@ #ifndef EMU_CPU_H #define EMU_CPU_H +#include "softfloat/softfloat.h" + enum { FPU_NONE, FPU_8087, @@ -131,13 +133,13 @@ enum { # define LOOKUP_INV -1 #endif -typedef struct { +typedef struct fpu_t { const char *name; const char *internal_name; const int type; } FPU; -typedef struct { +typedef struct cpu_t { const char *name; uint64_t cpu_type; const FPU *fpus; @@ -148,8 +150,10 @@ typedef struct { uint32_t cpuid_model; uint16_t cyrix_id; uint8_t cpu_flags; - int8_t mem_read_cycles, mem_write_cycles; - int8_t cache_read_cycles, cache_write_cycles; + int8_t mem_read_cycles; + int8_t mem_write_cycles; + int8_t cache_read_cycles; + int8_t cache_write_cycles; int8_t atclk_div; } CPU; @@ -213,17 +217,19 @@ typedef union { uint32_t l; uint16_t w; struct { - uint8_t l, - h; + uint8_t l; + uint8_t h; } b; } x86reg; typedef struct { uint32_t base; uint32_t limit; - uint8_t access, ar_high; + uint8_t access; + uint8_t ar_high; uint16_t seg; - uint32_t limit_low, limit_high; + uint32_t limit_low; + uint32_t limit_high; int checked; /*Non-zero if selector is known to be valid*/ } x86seg; @@ -241,8 +247,9 @@ typedef union { typedef struct { /* IDT WinChip and WinChip 2 MSR's */ - uint32_t tr1, tr12; /* 0x00000002, 0x0000000e */ - uint32_t cesr; /* 0x00000011 */ + uint32_t tr1; /* 0x00000002, 0x0000000e */ + uint32_t tr12; /* 0x00000002, 0x0000000e */ + uint32_t cesr; /* 0x00000011 */ /* Pentium Pro, Pentium II Klamath, and Pentium II Deschutes MSR's */ uint64_t apic_base; /* 0x0000001b - Should the Pentium not also have this? */ @@ -257,8 +264,9 @@ typedef struct { uint64_t mtrr_cap; /* 0x000000fe */ /* IDT WinChip and WinChip 2 MSR's that are also on the VIA Cyrix III */ - uint32_t fcr; /* 0x00000107 (IDT), 0x00001107 (VIA) */ - uint64_t fcr2, fcr3; /* 0x00000108 (IDT), 0x00001108 (VIA) */ + uint32_t fcr; /* 0x00000107 (IDT), 0x00001107 (VIA) */ + uint64_t fcr2; /* 0x00000108 (IDT), 0x00001108 (VIA) */ + uint64_t fcr3; /* 0x00000108 (IDT), 0x00001108 (VIA) */ /* Pentium Pro, Pentium II Klamath, and Pentium II Deschutes MSR's */ uint64_t ecx116; /* 0x00000116 */ @@ -274,8 +282,9 @@ typedef struct { uint64_t mcg_ctl; /* 0x0000017b - Machine Check Architecture */ /* Pentium Pro, Pentium II Klamath, and Pentium II Deschutes MSR's */ - uint64_t ecx186, ecx187; /* 0x00000186, 0x00000187 */ - uint64_t ecx1e0; /* 0x000001e0 */ + uint64_t ecx186; /* 0x00000186, 0x00000187 */ + uint64_t ecx187; /* 0x00000186, 0x00000187 */ + uint64_t ecx1e0; /* 0x000001e0 */ /* Pentium Pro, Pentium II Klamath, and Pentium II Deschutes MSR's that are also on the VIA Cyrix III */ @@ -323,7 +332,8 @@ typedef struct { uint64_t amd_epmr; /* 0xc0000086 */ /* AMD K6-2C, K6-3, K6-2P, and K6-3P MSR's */ - uint64_t amd_psor, amd_pfir; /* 0xc0000087, 0xc0000088 */ + uint64_t amd_psor; /* 0xc0000087, 0xc0000088 */ + uint64_t amd_pfir; /* 0xc0000087, 0xc0000088 */ /* K6-3, K6-2P, and K6-3P MSR's */ uint64_t amd_l2aar; /* 0xc0000089 */ @@ -343,33 +353,38 @@ typedef struct { uint32_t eaaddr; int flags_op; - uint32_t flags_res, - flags_op1, flags_op2; + uint32_t flags_res; + uint32_t flags_op1; + uint32_t flags_op2; - uint32_t pc, - oldpc, op32; + uint32_t pc; + uint32_t oldpc; + uint32_t op32; int TOP; union { struct { - int8_t rm, - mod, - reg; + int8_t rm; + int8_t mod; + int8_t reg; } rm_mod_reg; int32_t rm_mod_reg_data; } rm_data; - uint8_t ssegs, ismmx, - abrt, _smi_line; + uint8_t ssegs; + uint8_t ismmx; + uint8_t abrt; + uint8_t _smi_line; + int _cycles; #ifdef FPU_CYCLES - int _cycles, _fpu_cycles, _in_smm; -#else - int _cycles, _in_smm; + int _fpu_cycles; #endif + int _in_smm; - uint16_t npxs, npxc; + uint16_t npxs; + uint16_t npxc; double ST[8]; @@ -378,36 +393,58 @@ typedef struct { MMX_REG MM[8]; #ifdef USE_NEW_DYNAREC - uint32_t old_fp_control, new_fp_control; + uint32_t old_fp_control; + uint32_t new_fp_control; # if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 - uint16_t old_fp_control2, new_fp_control2; + uint16_t old_fp_control2; + uint16_t new_fp_control2; # endif # if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 || defined __amd64__ || defined _M_X64 - uint32_t trunc_fp_control; + uint32_t trunc_fp_control; # endif #else - uint16_t old_npxc, new_npxc; + uint16_t old_npxc; + uint16_t new_npxc; #endif - x86seg seg_cs, seg_ds, seg_es, seg_ss, - seg_fs, seg_gs; + x86seg seg_cs; + x86seg seg_ds; + x86seg seg_es; + x86seg seg_ss; + x86seg seg_fs; + x86seg seg_gs; union { uint32_t l; uint16_t w; } CR0; - uint16_t flags, eflags; + uint16_t flags; + uint16_t eflags; uint32_t _smbase; - - uint8_t inside_emulation_mode; } cpu_state_t; +typedef struct { + uint16_t cwd; + uint16_t swd; + uint16_t tag; + uint16_t foo; + uint32_t fip; + uint32_t fdp; + uint16_t fcs; + uint16_t fds; + floatx80 st_space[8]; + unsigned char tos; + unsigned char align1; + unsigned char align2; + unsigned char align3; +} fpu_state_t; + #define in_smm cpu_state._in_smm #define smi_line cpu_state._smi_line -#define smbase cpu_state._smbase +#define smbase cpu_state._smbase /*The cpu_state.flags below must match in both cpu_cur_status and block->status for a block to be valid*/ @@ -416,7 +453,11 @@ typedef struct { #define CPU_STATUS_PMODE (1 << 2) #define CPU_STATUS_V86 (1 << 3) #define CPU_STATUS_SMM (1 << 4) +#ifdef USE_NEW_DYNAREC +#define CPU_STATUS_FLAGS 0xff +#else #define CPU_STATUS_FLAGS 0xffff +#endif /*If the cpu_state.flags below are set in cpu_cur_status, they must be set in block->status. Otherwise they are ignored*/ @@ -480,6 +521,7 @@ COMPILE_TIME_ASSERT(sizeof(cpu_state_t) <= 128) /* Global variables. */ extern cpu_state_t cpu_state; +extern fpu_state_t fpu_state; extern const cpu_family_t cpu_families[]; extern const cpu_legacy_machine_t cpu_legacy_table[]; @@ -489,16 +531,29 @@ extern int cpu_override; extern int cpu_isintel; extern int cpu_iscyrix; -extern int cpu_16bitbus, cpu_64bitbus; -extern int cpu_busspeed, cpu_pci_speed; +extern int cpu_16bitbus; +extern int cpu_64bitbus; +extern int cpu_pci_speed; extern int cpu_multi; extern double cpu_dmulti; extern double fpu_multi; +extern double cpu_busspeed; extern int cpu_cyrix_alignment; /*Cyrix 5x86/6x86 only has data misalignment penalties when crossing 8-byte boundaries*/ -extern int is8086, is186, is286, is386, is6117, is486; -extern int is_am486, is_am486dxl, is_pentium, is_k5, is_k6, is_p6, is_cxsmm; +extern int is8086; +extern int is186; +extern int is286; +extern int is386; +extern int is6117; +extern int is486; +extern int is_am486; +extern int is_am486dxl; +extern int is_pentium; +extern int is_k5; +extern int is_k6; +extern int is_p6; +extern int is_cxsmm; extern int hascache; extern int isibm486; extern int is_nec; @@ -516,7 +571,8 @@ extern int hasfpu; extern uint32_t cpu_features; -extern int smi_latched, smm_in_hlt; +extern int smi_latched; +extern int smm_in_hlt; extern int smi_block; #ifdef USE_NEW_DYNAREC @@ -532,12 +588,21 @@ extern int cgate16; extern int cpl_override; extern int CPUID; extern uint64_t xt_cpu_multi; -extern int isa_cycles, cpu_inited; -extern uint32_t oldds, oldss, olddslimit, oldsslimit, olddslimitw, oldsslimitw; +extern int isa_cycles; +extern int cpu_inited; +extern uint32_t oldds; +extern uint32_t oldss; +extern uint32_t olddslimit; +extern uint32_t oldsslimit; +extern uint32_t olddslimitw; +extern uint32_t oldsslimitw; extern uint32_t pccache; extern uint8_t *pccache2; -extern double bus_timing, isa_timing, pci_timing, agp_timing; +extern double bus_timing; +extern double isa_timing; +extern double pci_timing; +extern double agp_timing; extern uint64_t pmc[2]; extern uint16_t temp_seg_data[4]; extern uint16_t cs_msr; @@ -545,13 +610,16 @@ extern uint32_t esp_msr; extern uint32_t eip_msr; /* For the AMD K6. */ -extern uint64_t amd_efer, star; +extern uint64_t amd_efer; +extern uint64_t star; #define FPU_CW_Reserved_Bits (0xe0c0) -#define cr0 cpu_state.CR0.l -#define msw cpu_state.CR0.w -extern uint32_t cr2, cr3, cr4; +#define cr0 cpu_state.CR0.l +#define msw cpu_state.CR0.w +extern uint32_t cr2; +extern uint32_t cr3; +extern uint32_t cr4; extern uint32_t dr[8]; extern uint32_t _tr[8]; extern uint32_t cache_index; @@ -561,7 +629,10 @@ extern uint8_t _cache[2048]; _cs,_ds,_es,_ss are the segment structures CS,DS,ES,SS is the 16-bit data cs,ds,es,ss are defines to the bases*/ -extern x86seg gdt, ldt, idt, tr; +extern x86seg gdt; +extern x86seg ldt; +extern x86seg idt; +extern x86seg tr; extern x86seg _oldds; #define CS cpu_state.seg_cs.seg #define DS cpu_state.seg_ds.seg @@ -578,37 +649,67 @@ extern x86seg _oldds; #define ISA_CYCLES(x) (x * isa_cycles) -extern int cpu_cycles_read, cpu_cycles_read_l, cpu_cycles_write, cpu_cycles_write_l; -extern int cpu_prefetch_cycles, cpu_prefetch_width, cpu_mem_prefetch_cycles, cpu_rom_prefetch_cycles; +extern int cpu_cycles_read; +extern int cpu_cycles_read_l; +extern int cpu_cycles_write; +extern int cpu_cycles_write_l; +extern int cpu_prefetch_cycles; +extern int cpu_prefetch_width; +extern int cpu_mem_prefetch_cycles; +extern int cpu_rom_prefetch_cycles; extern int cpu_waitstates; -extern int cpu_cache_int_enabled, cpu_cache_ext_enabled; -extern int cpu_isa_speed, cpu_pci_speed, cpu_agp_speed; +extern int cpu_cache_int_enabled; +extern int cpu_cache_ext_enabled; +extern int cpu_isa_speed; +extern int cpu_pci_speed; +extern int cpu_agp_speed; extern int timing_rr; -extern int timing_mr, timing_mrl; -extern int timing_rm, timing_rml; -extern int timing_mm, timing_mml; -extern int timing_bt, timing_bnt; -extern int timing_int, timing_int_rm, timing_int_v86, timing_int_pm; -extern int timing_int_pm_outer, timing_iret_rm, timing_iret_v86, timing_iret_pm; -extern int timing_iret_pm_outer, timing_call_rm, timing_call_pm; -extern int timing_call_pm_gate, timing_call_pm_gate_inner; -extern int timing_retf_rm, timing_retf_pm, timing_retf_pm_outer; -extern int timing_jmp_rm, timing_jmp_pm, timing_jmp_pm_gate; +extern int timing_mr; +extern int timing_mrl; +extern int timing_rm; +extern int timing_rml; +extern int timing_mm; +extern int timing_mml; +extern int timing_bt; +extern int timing_bnt; +extern int timing_int; +extern int timing_int_rm; +extern int timing_int_v86; +extern int timing_int_pm; +extern int timing_int_pm_outer; +extern int timing_iret_rm; +extern int timing_iret_v86; +extern int timing_iret_pm; +extern int timing_iret_pm_outer; +extern int timing_call_rm; +extern int timing_call_pm; +extern int timing_call_pm_gate; +extern int timing_call_pm_gate_inner; +extern int timing_retf_rm; +extern int timing_retf_pm; +extern int timing_retf_pm_outer; +extern int timing_jmp_rm; +extern int timing_jmp_pm; +extern int timing_jmp_pm_gate; extern int timing_misaligned; -extern int in_sys, unmask_a20_in_smm; +extern int in_sys; +extern int unmask_a20_in_smm; extern int cycles_main; extern uint32_t old_rammask; #ifdef USE_ACYCS extern int acycs; #endif -extern int pic_pending, is_vpc; -extern int soft_reset_mask, alt_access; +extern int pic_pending; +extern int is_vpc; +extern int soft_reset_mask; +extern int alt_access; extern int cpu_end_block_after_ins; -extern uint16_t cpu_fast_off_count, cpu_fast_off_val; +extern uint16_t cpu_fast_off_count; +extern uint16_t cpu_fast_off_val; extern uint32_t cpu_fast_off_flags; /* Functions. */ @@ -637,7 +738,7 @@ extern void cpu_CPUID(void); extern void cpu_RDMSR(void); extern void cpu_WRMSR(void); -extern int checkio(uint32_t port); +extern int checkio(uint32_t port, int mask); extern void codegen_block_end(void); extern void codegen_reset(void); extern void cpu_set_edx(void); @@ -683,7 +784,8 @@ extern void x87_dumpregs(void); extern void x87_reset(void); #endif -extern int cpu_effective, cpu_alt_reset; +extern int cpu_effective; +extern int cpu_alt_reset; extern void cpu_dynamic_switch(int new_cpu); extern void cpu_ven_reset(void); @@ -708,22 +810,23 @@ void cyrix_write_seg_descriptor(uint32_t addr, x86seg *seg); #define SMHR_VALID (1 << 0) #define SMHR_ADDR_MASK (0xfffffffc) -typedef struct -{ - struct - { +typedef struct { + struct { uint32_t base; uint64_t size; } arr[8]; uint32_t smhr; } cyrix_t; -extern uint32_t addr64, addr64_2; -extern uint32_t addr64a[8], addr64a_2[8]; +extern uint32_t addr64; +extern uint32_t addr64_2; +extern uint32_t addr64a[8]; +extern uint32_t addr64a_2[8]; extern int soft_reset_pci; -extern int reset_on_hlt, hlt_reset_pending; +extern int reset_on_hlt; +extern int hlt_reset_pending; extern cyrix_t cyrix; @@ -731,7 +834,10 @@ extern uint8_t use_custom_nmi_vector; extern uint32_t custom_nmi_vector; extern void (*cpu_exec)(int cycs); -extern uint8_t do_translate, do_translate2; +extern uint8_t do_translate; +extern uint8_t do_translate2; + +extern void SF_FPU_reset(void); extern void reset_808x(int hard); extern void interrupt_808x(uint16_t addr); @@ -744,4 +850,9 @@ extern void cpu_fast_off_reset(void); extern void smi_raise(void); extern void nmi_raise(void); +extern MMX_REG *MMP[8]; +extern uint16_t *MMEP[8]; + +extern void mmx_init(void); + #endif /*EMU_CPU_H*/ diff --git a/src/cpu/softfloat/CMakeLists.txt b/src/cpu/softfloat/CMakeLists.txt new file mode 100644 index 000000000..936157185 --- /dev/null +++ b/src/cpu/softfloat/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# 86Box A hypervisor and IBM PC system emulator that specializes in +# running old operating systems and software designed for IBM +# PC systems and compatibles from 1981 through fairly recent +# system designs based on the PCI bus. +# +# This file is part of the 86Box distribution. +# +# CMake build script. +# +# Authors: David Hrdlička, +# +# Copyright 2020-2021 David Hrdlička. +# + +add_library(softfloat OBJECT f2xm1.cc fpatan.cc fprem.cc fsincos.cc fyl2x.cc softfloat_poly.cc softfloat.cc softfloat16.cc + softfloat-muladd.cc softfloat-round-pack.cc softfloat-specialize.cc softfloatx80.cc) diff --git a/src/cpu/softfloat/config.h b/src/cpu/softfloat/config.h new file mode 100644 index 000000000..3889b5c02 --- /dev/null +++ b/src/cpu/softfloat/config.h @@ -0,0 +1,46 @@ +#include + +typedef int8_t flag; +typedef uint8_t uint8; +typedef int8_t int8; +typedef uint16_t uint16; +typedef int16_t int16; +typedef uint32_t uint32; +typedef int32_t int32; +typedef uint64_t uint64; +typedef int64_t int64; + +/*---------------------------------------------------------------------------- +| Each of the following `typedef's defines a type that holds integers +| of _exactly_ the number of bits specified. For instance, for most +| implementation of C, `bits16' and `sbits16' should be `typedef'ed to +| `unsigned short int' and `signed short int' (or `short int'), respectively. +*----------------------------------------------------------------------------*/ +typedef uint8_t bits8; +typedef int8_t sbits8; +typedef uint16_t bits16; +typedef int16_t sbits16; +typedef uint32_t bits32; +typedef int32_t sbits32; +typedef uint64_t bits64; +typedef int64_t sbits64; + +typedef uint8_t Bit8u; +typedef int8_t Bit8s; +typedef uint16_t Bit16u; +typedef int16_t Bit16s; +typedef uint32_t Bit32u; +typedef int32_t Bit32s; +typedef uint64_t Bit64u; +typedef int64_t Bit64s; + +/*---------------------------------------------------------------------------- +| The `LIT64' macro takes as its argument a textual integer literal and +| if necessary ``marks'' the literal as having a 64-bit integer type. +| For example, the GNU C Compiler (`gcc') requires that 64-bit literals be +| appended with the letters `LL' standing for `long long', which is `gcc's +| name for the 64-bit integer type. Some compilers may allow `LIT64' to be +| defined as the identity macro: `#define LIT64( a ) a'. +*----------------------------------------------------------------------------*/ +#define BX_CONST64(a) a##LL +#define BX_CPP_INLINE static __inline diff --git a/src/cpu/softfloat/f2xm1.cc b/src/cpu/softfloat/f2xm1.cc new file mode 100644 index 000000000..ed4af1d12 --- /dev/null +++ b/src/cpu/softfloat/f2xm1.cc @@ -0,0 +1,182 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#define FLOAT128 + +#include "softfloatx80.h" +#include "softfloat-round-pack.h" + +static const floatx80 floatx80_negone = packFloatx80(1, 0x3fff, BX_CONST64(0x8000000000000000)); +static const floatx80 floatx80_neghalf = packFloatx80(1, 0x3ffe, BX_CONST64(0x8000000000000000)); +static const float128 float128_ln2 = + packFloat128(BX_CONST64(0x3ffe62e42fefa39e), BX_CONST64(0xf35793c7673007e6)); + +#ifdef BETTER_THAN_PENTIUM + +#define LN2_SIG_HI BX_CONST64(0xb17217f7d1cf79ab) +#define LN2_SIG_LO BX_CONST64(0xc9e3b39800000000) /* 96 bit precision */ + +#else + +#define LN2_SIG_HI BX_CONST64(0xb17217f7d1cf79ab) +#define LN2_SIG_LO BX_CONST64(0xc000000000000000) /* 67-bit precision */ + +#endif + +#define EXP_ARR_SIZE 15 + +static float128 exp_arr[EXP_ARR_SIZE] = +{ + PACK_FLOAT_128(0x3fff000000000000, 0x0000000000000000), /* 1 */ + PACK_FLOAT_128(0x3ffe000000000000, 0x0000000000000000), /* 2 */ + PACK_FLOAT_128(0x3ffc555555555555, 0x5555555555555555), /* 3 */ + PACK_FLOAT_128(0x3ffa555555555555, 0x5555555555555555), /* 4 */ + PACK_FLOAT_128(0x3ff8111111111111, 0x1111111111111111), /* 5 */ + PACK_FLOAT_128(0x3ff56c16c16c16c1, 0x6c16c16c16c16c17), /* 6 */ + PACK_FLOAT_128(0x3ff2a01a01a01a01, 0xa01a01a01a01a01a), /* 7 */ + PACK_FLOAT_128(0x3fefa01a01a01a01, 0xa01a01a01a01a01a), /* 8 */ + PACK_FLOAT_128(0x3fec71de3a556c73, 0x38faac1c88e50017), /* 9 */ + PACK_FLOAT_128(0x3fe927e4fb7789f5, 0xc72ef016d3ea6679), /* 10 */ + PACK_FLOAT_128(0x3fe5ae64567f544e, 0x38fe747e4b837dc7), /* 11 */ + PACK_FLOAT_128(0x3fe21eed8eff8d89, 0x7b544da987acfe85), /* 12 */ + PACK_FLOAT_128(0x3fde6124613a86d0, 0x97ca38331d23af68), /* 13 */ + PACK_FLOAT_128(0x3fda93974a8c07c9, 0xd20badf145dfa3e5), /* 14 */ + PACK_FLOAT_128(0x3fd6ae7f3e733b81, 0xf11d8656b0ee8cb0) /* 15 */ +}; + +extern float128 EvalPoly(float128 x, float128 *arr, int n, struct float_status_t *status); + +/* required -1 < x < 1 */ +static float128 poly_exp(float128 x, struct float_status_t *status) +{ +/* + // 2 3 4 5 6 7 8 9 + // x x x x x x x x x + // e - 1 ~ x + --- + --- + --- + --- + --- + --- + --- + --- + ... + // 2! 3! 4! 5! 6! 7! 8! 9! + // + // 2 3 4 5 6 7 8 + // x x x x x x x x + // = x [ 1 + --- + --- + --- + --- + --- + --- + --- + --- + ... ] + // 2! 3! 4! 5! 6! 7! 8! 9! + // + // 8 8 + // -- 2k -- 2k+1 + // p(x) = > C * x q(x) = > C * x + // -- 2k -- 2k+1 + // k=0 k=0 + // + // x + // e - 1 ~ x * [ p(x) + x * q(x) ] + // +*/ + float128 t = EvalPoly(x, exp_arr, EXP_ARR_SIZE, status); + return float128_mul(t, x, status); +} + +// ================================================= +// x +// FX2M1 Compute 2 - 1 +// ================================================= + +// +// Uses the following identities: +// +// 1. ---------------------------------------------------------- +// x x*ln(2) +// 2 = e +// +// 2. ---------------------------------------------------------- +// 2 3 4 5 n +// x x x x x x x +// e = 1 + --- + --- + --- + --- + --- + ... + --- + ... +// 1! 2! 3! 4! 5! n! +// + +floatx80 f2xm1(floatx80 a, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + Bit64u zSig0, zSig1, zSig2; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a)) + { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + Bit64u aSig = extractFloatx80Frac(a); + Bit32s aExp = extractFloatx80Exp(a); + int aSign = extractFloatx80Sign(a); + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1)) + return propagateFloatx80NaNOne(a, status); + + return (aSign) ? floatx80_negone : a; + } + + if (aExp == 0) { + if (aSig == 0) return a; + float_raise(status, float_flag_denormal | float_flag_inexact); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + + tiny_argument: + mul128By64To192(LN2_SIG_HI, LN2_SIG_LO, aSig, &zSig0, &zSig1, &zSig2); + if (0 < (Bit64s) zSig0) { + shortShift128Left(zSig0, zSig1, 1, &zSig0, &zSig1); + --aExp; + } + return + roundAndPackFloatx80(80, aSign, aExp, zSig0, zSig1, status); + } + + float_raise(status, float_flag_inexact); + + if (aExp < 0x3FFF) + { + if (aExp < FLOATX80_EXP_BIAS-68) + goto tiny_argument; + + /* ******************************** */ + /* using float128 for approximation */ + /* ******************************** */ + + float128 x = floatx80_to_float128(a, status); + x = float128_mul(x, float128_ln2, status); + x = poly_exp(x, status); + return float128_to_floatx80(x, status); + } + else + { + if (a.exp == 0xBFFF && ! (aSig<<1)) + return floatx80_neghalf; + + return a; + } +} diff --git a/src/cpu/softfloat/fpatan.cc b/src/cpu/softfloat/fpatan.cc new file mode 100644 index 000000000..f33a3ff66 --- /dev/null +++ b/src/cpu/softfloat/fpatan.cc @@ -0,0 +1,288 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#define FLOAT128 + +#include "softfloatx80.h" +#include "softfloat-round-pack.h" +#include "fpu_constant.h" + +#define FPATAN_ARR_SIZE 11 + +static const float128 float128_one = + packFloat128(BX_CONST64(0x3fff000000000000), BX_CONST64(0x0000000000000000)); +static const float128 float128_sqrt3 = + packFloat128(BX_CONST64(0x3fffbb67ae8584ca), BX_CONST64(0xa73b25742d7078b8)); +static const floatx80 floatx80_pi = + packFloatx80(0, 0x4000, BX_CONST64(0xc90fdaa22168c235)); + +static const float128 float128_pi2 = + packFloat128(BX_CONST64(0x3fff921fb54442d1), BX_CONST64(0x8469898CC5170416)); +static const float128 float128_pi4 = + packFloat128(BX_CONST64(0x3ffe921fb54442d1), BX_CONST64(0x8469898CC5170416)); +static const float128 float128_pi6 = + packFloat128(BX_CONST64(0x3ffe0c152382d736), BX_CONST64(0x58465BB32E0F580F)); + +static float128 atan_arr[FPATAN_ARR_SIZE] = +{ + PACK_FLOAT_128(0x3fff000000000000, 0x0000000000000000), /* 1 */ + PACK_FLOAT_128(0xbffd555555555555, 0x5555555555555555), /* 3 */ + PACK_FLOAT_128(0x3ffc999999999999, 0x999999999999999a), /* 5 */ + PACK_FLOAT_128(0xbffc249249249249, 0x2492492492492492), /* 7 */ + PACK_FLOAT_128(0x3ffbc71c71c71c71, 0xc71c71c71c71c71c), /* 9 */ + PACK_FLOAT_128(0xbffb745d1745d174, 0x5d1745d1745d1746), /* 11 */ + PACK_FLOAT_128(0x3ffb3b13b13b13b1, 0x3b13b13b13b13b14), /* 13 */ + PACK_FLOAT_128(0xbffb111111111111, 0x1111111111111111), /* 15 */ + PACK_FLOAT_128(0x3ffae1e1e1e1e1e1, 0xe1e1e1e1e1e1e1e2), /* 17 */ + PACK_FLOAT_128(0xbffaaf286bca1af2, 0x86bca1af286bca1b), /* 19 */ + PACK_FLOAT_128(0x3ffa861861861861, 0x8618618618618618) /* 21 */ +}; + +extern float128 OddPoly(float128 x, float128 *arr, int n, struct float_status_t *status); + +/* |x| < 1/4 */ +static float128 poly_atan(float128 x1, struct float_status_t *status) +{ +/* + // 3 5 7 9 11 13 15 17 + // x x x x x x x x + // atan(x) ~ x - --- + --- - --- + --- - ---- + ---- - ---- + ---- + // 3 5 7 9 11 13 15 17 + // + // 2 4 6 8 10 12 14 16 + // x x x x x x x x + // = x * [ 1 - --- + --- - --- + --- - ---- + ---- - ---- + ---- ] + // 3 5 7 9 11 13 15 17 + // + // 5 5 + // -- 4k -- 4k+2 + // p(x) = > C * x q(x) = > C * x + // -- 2k -- 2k+1 + // k=0 k=0 + // + // 2 + // atan(x) ~ x * [ p(x) + x * q(x) ] + // +*/ + return OddPoly(x1, atan_arr, FPATAN_ARR_SIZE, status); +} + +// ================================================= +// FPATAN Compute y * log (x) +// 2 +// ================================================= + +// +// Uses the following identities: +// +// 1. ---------------------------------------------------------- +// +// atan(-x) = -atan(x) +// +// 2. ---------------------------------------------------------- +// +// x + y +// atan(x) + atan(y) = atan -------, xy < 1 +// 1-xy +// +// x + y +// atan(x) + atan(y) = atan ------- + PI, x > 0, xy > 1 +// 1-xy +// +// x + y +// atan(x) + atan(y) = atan ------- - PI, x < 0, xy > 1 +// 1-xy +// +// 3. ---------------------------------------------------------- +// +// atan(x) = atan(INF) + atan(- 1/x) +// +// x-1 +// atan(x) = PI/4 + atan( ----- ) +// x+1 +// +// x * sqrt(3) - 1 +// atan(x) = PI/6 + atan( ----------------- ) +// x + sqrt(3) +// +// 4. ---------------------------------------------------------- +// 3 5 7 9 2n+1 +// x x x x n x +// atan(x) = x - --- + --- - --- + --- - ... + (-1) ------ + ... +// 3 5 7 9 2n+1 +// + +floatx80 fpatan(floatx80 a, floatx80 b, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + Bit64u aSig = extractFloatx80Frac(a); + Bit32s aExp = extractFloatx80Exp(a); + int aSign = extractFloatx80Sign(a); + Bit64u bSig = extractFloatx80Frac(b); + Bit32s bExp = extractFloatx80Exp(b); + int bSign = extractFloatx80Sign(b); + + int zSign = aSign ^ bSign; + + if (bExp == 0x7FFF) + { + if ((Bit64u) (bSig<<1)) + return propagateFloatx80NaN(a, b, status); + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1)) + return propagateFloatx80NaN(a, b, status); + + if (aSign) { /* return 3PI/4 */ + return roundAndPackFloatx80(80, bSign, + FLOATX80_3PI4_EXP, FLOAT_3PI4_HI, FLOAT_3PI4_LO, status); + } + else { /* return PI/4 */ + return roundAndPackFloatx80(80, bSign, + FLOATX80_PI4_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); + } + } + + if (aSig && (aExp == 0)) + float_raise(status, float_flag_denormal); + + /* return PI/2 */ + return roundAndPackFloatx80(80, bSign, FLOATX80_PI2_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); + } + if (aExp == 0x7FFF) + { + if ((Bit64u) (aSig<<1)) + return propagateFloatx80NaN(a, b, status); + + if (bSig && (bExp == 0)) + float_raise(status, float_flag_denormal); + +return_PI_or_ZERO: + + if (aSign) { /* return PI */ + return roundAndPackFloatx80(80, bSign, FLOATX80_PI_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); + } else { /* return 0 */ + return packFloatx80(bSign, 0, 0); + } + } + if (bExp == 0) + { + if (bSig == 0) { + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + goto return_PI_or_ZERO; + } + + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + if (aExp == 0) + { + if (aSig == 0) /* return PI/2 */ + return roundAndPackFloatx80(80, bSign, FLOATX80_PI2_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); + + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + + float_raise(status, float_flag_inexact); + + /* |a| = |b| ==> return PI/4 */ + if (aSig == bSig && aExp == bExp) + return roundAndPackFloatx80(80, bSign, FLOATX80_PI4_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); + + /* ******************************** */ + /* using float128 for approximation */ + /* ******************************** */ + + float128 a128 = normalizeRoundAndPackFloat128(0, aExp-0x10, aSig, 0, status); + float128 b128 = normalizeRoundAndPackFloat128(0, bExp-0x10, bSig, 0, status); + float128 x; + int swap = 0, add_pi6 = 0, add_pi4 = 0; + + if (aExp > bExp || (aExp == bExp && aSig > bSig)) + { + x = float128_div(b128, a128, status); + } + else { + x = float128_div(a128, b128, status); + swap = 1; + } + + Bit32s xExp = extractFloat128Exp(x); + + if (xExp <= FLOATX80_EXP_BIAS-40) + goto approximation_completed; + + if (x.hi >= BX_CONST64(0x3ffe800000000000)) // 3/4 < x < 1 + { + /* + arctan(x) = arctan((x-1)/(x+1)) + pi/4 + */ + float128 t1 = float128_sub(x, float128_one, status); + float128 t2 = float128_add(x, float128_one, status); + x = float128_div(t1, t2, status); + add_pi4 = 1; + } + else + { + /* argument correction */ + if (xExp >= 0x3FFD) // 1/4 < x < 3/4 + { + /* + arctan(x) = arctan((x*sqrt(3)-1)/(x+sqrt(3))) + pi/6 + */ + float128 t1 = float128_mul(x, float128_sqrt3, status); + float128 t2 = float128_add(x, float128_sqrt3, status); + x = float128_sub(t1, float128_one, status); + x = float128_div(x, t2, status); + add_pi6 = 1; + } + } + + x = poly_atan(x, status); + if (add_pi6) x = float128_add(x, float128_pi6, status); + if (add_pi4) x = float128_add(x, float128_pi4, status); + +approximation_completed: + if (swap) x = float128_sub(float128_pi2, x, status); + floatx80 result = float128_to_floatx80(x, status); + if (zSign) floatx80_chs(result); + int rSign = extractFloatx80Sign(result); + if (!bSign && rSign) + return floatx80_add(result, floatx80_pi, status); + if (bSign && !rSign) + return floatx80_sub(result, floatx80_pi, status); + return result; +} diff --git a/src/cpu/softfloat/fprem.cc b/src/cpu/softfloat/fprem.cc new file mode 100644 index 000000000..26637c5c5 --- /dev/null +++ b/src/cpu/softfloat/fprem.cc @@ -0,0 +1,196 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "softfloatx80.h" +#include "softfloat-round-pack.h" +#define USE_estimateDiv128To64 +#include "softfloat-macros.h" + +/* executes single exponent reduction cycle */ +static Bit64u remainder_kernel(Bit64u aSig0, Bit64u bSig, int expDiff, Bit64u *zSig0, Bit64u *zSig1) +{ + Bit64u term0, term1; + Bit64u aSig1 = 0; + + shortShift128Left(aSig1, aSig0, expDiff, &aSig1, &aSig0); + Bit64u q = estimateDiv128To64(aSig1, aSig0, bSig); + mul64To128(bSig, q, &term0, &term1); + sub128(aSig1, aSig0, term0, term1, zSig1, zSig0); + while ((Bit64s)(*zSig1) < 0) { + --q; + add128(*zSig1, *zSig0, 0, bSig, zSig1, zSig0); + } + return q; +} + +static int do_fprem(floatx80 a, floatx80 b, floatx80 *r, Bit64u *q, int rounding_mode, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit32s aExp, bExp, zExp, expDiff; + Bit64u aSig0, aSig1, bSig; + int aSign; + *q = 0; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) + { + float_raise(status, float_flag_invalid); + *r = floatx80_default_nan; + return -1; + } + + aSig0 = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig0<<1) || ((bExp == 0x7FFF) && (Bit64u) (bSig<<1))) { + *r = propagateFloatx80NaN(a, b, status); + return -1; + } + float_raise(status, float_flag_invalid); + *r = floatx80_default_nan; + return -1; + } + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) { + *r = propagateFloatx80NaN(a, b, status); + return -1; + } + if (aExp == 0 && aSig0) { + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); + *r = (a.fraction & BX_CONST64(0x8000000000000000)) ? + packFloatx80(aSign, aExp, aSig0) : a; + return 0; + } + *r = a; + return 0; + + } + if (bExp == 0) { + if (bSig == 0) { + float_raise(status, float_flag_invalid); + *r = floatx80_default_nan; + return -1; + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + if (aExp == 0) { + if (aSig0 == 0) { + *r = a; + return 0; + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); + } + expDiff = aExp - bExp; + aSig1 = 0; + + Bit32u overflow = 0; + + if (expDiff >= 64) { + int n = (expDiff & 0x1f) | 0x20; + remainder_kernel(aSig0, bSig, n, &aSig0, &aSig1); + zExp = aExp - n; + overflow = 1; + } + else { + zExp = bExp; + + if (expDiff < 0) { + if (expDiff < -1) { + *r = (a.fraction & BX_CONST64(0x8000000000000000)) ? + packFloatx80(aSign, aExp, aSig0) : a; + return 0; + } + shift128Right(aSig0, 0, 1, &aSig0, &aSig1); + expDiff = 0; + } + + if (expDiff > 0) { + *q = remainder_kernel(aSig0, bSig, expDiff, &aSig0, &aSig1); + } + else { + if (bSig <= aSig0) { + aSig0 -= bSig; + *q = 1; + } + } + + if (rounding_mode == float_round_nearest_even) + { + Bit64u term0, term1; + shift128Right(bSig, 0, 1, &term0, &term1); + + if (! lt128(aSig0, aSig1, term0, term1)) + { + int lt = lt128(term0, term1, aSig0, aSig1); + int eq = eq128(aSig0, aSig1, term0, term1); + + if ((eq && ((*q) & 1)) || lt) { + aSign = !aSign; + ++(*q); + } + if (lt) sub128(bSig, 0, aSig0, aSig1, &aSig0, &aSig1); + } + } + } + + *r = normalizeRoundAndPackFloatx80(80, aSign, zExp, aSig0, aSig1, status); + return overflow; +} + +/*---------------------------------------------------------------------------- +| Returns the remainder of the extended double-precision floating-point value +| `a' with respect to the corresponding value `b'. The operation is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +int floatx80_ieee754_remainder(floatx80 a, floatx80 b, floatx80 *r, Bit64u *q, struct float_status_t *status) +{ + return do_fprem(a, b, r, q, float_round_nearest_even, status); +} + +/*---------------------------------------------------------------------------- +| Returns the remainder of the extended double-precision floating-point value +| `a' with respect to the corresponding value `b'. Unlike previous function +| the function does not compute the remainder specified in the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. This function operates +| differently from the previous function in the way that it rounds the +| quotient of 'a' divided by 'b' to an integer. +*----------------------------------------------------------------------------*/ + +int floatx80_remainder(floatx80 a, floatx80 b, floatx80 *r, Bit64u *q, struct float_status_t *status) +{ + return do_fprem(a, b, r, q, float_round_to_zero, status); +} diff --git a/src/cpu/softfloat/fpu_constant.h b/src/cpu/softfloat/fpu_constant.h new file mode 100644 index 000000000..7a7fc6f1a --- /dev/null +++ b/src/cpu/softfloat/fpu_constant.h @@ -0,0 +1,82 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +#ifndef _FPU_CONSTANTS_H_ +#define _FPU_CONSTANTS_H_ + +#include "config.h" + +// Pentium CPU uses only 68-bit precision M_PI approximation +//#define BETTER_THAN_PENTIUM + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +////////////////////////////// +// PI, PI/2, PI/4 constants +////////////////////////////// + +#define FLOATX80_PI_EXP (0x4000) + +// 128-bit PI fraction +#ifdef BETTER_THAN_PENTIUM +#define FLOAT_PI_HI (BX_CONST64(0xc90fdaa22168c234)) +#define FLOAT_PI_LO (BX_CONST64(0xc4c6628b80dc1cd1)) +#else +#define FLOAT_PI_HI (BX_CONST64(0xc90fdaa22168c234)) +#define FLOAT_PI_LO (BX_CONST64(0xC000000000000000)) +#endif + +#define FLOATX80_PI2_EXP (0x3FFF) +#define FLOATX80_PI4_EXP (0x3FFE) + +////////////////////////////// +// 3PI/4 constant +////////////////////////////// + +#define FLOATX80_3PI4_EXP (0x4000) + +// 128-bit 3PI/4 fraction +#ifdef BETTER_THAN_PENTIUM +#define FLOAT_3PI4_HI (BX_CONST64(0x96cbe3f9990e91a7)) +#define FLOAT_3PI4_LO (BX_CONST64(0x9394c9e8a0a5159c)) +#else +#define FLOAT_3PI4_HI (BX_CONST64(0x96cbe3f9990e91a7)) +#define FLOAT_3PI4_LO (BX_CONST64(0x9000000000000000)) +#endif + +////////////////////////////// +// 1/LN2 constant +////////////////////////////// + +#define FLOAT_LN2INV_EXP (0x3FFF) + +// 128-bit 1/LN2 fraction +#ifdef BETTER_THAN_PENTIUM +#define FLOAT_LN2INV_HI (BX_CONST64(0xb8aa3b295c17f0bb)) +#define FLOAT_LN2INV_LO (BX_CONST64(0xbe87fed0691d3e89)) +#else +#define FLOAT_LN2INV_HI (BX_CONST64(0xb8aa3b295c17f0bb)) +#define FLOAT_LN2INV_LO (BX_CONST64(0xC000000000000000)) +#endif + +#endif diff --git a/src/cpu/softfloat/fsincos.cc b/src/cpu/softfloat/fsincos.cc new file mode 100644 index 000000000..f5b33a823 --- /dev/null +++ b/src/cpu/softfloat/fsincos.cc @@ -0,0 +1,441 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#define FLOAT128 + +#define USE_estimateDiv128To64 +#include "softfloatx80.h" +#include "softfloat-round-pack.h" +#include "fpu_constant.h" + +static const floatx80 floatx80_one = packFloatx80(0, 0x3fff, BX_CONST64(0x8000000000000000)); + +/* reduce trigonometric function argument using 128-bit precision + M_PI approximation */ +static Bit64u argument_reduction_kernel(Bit64u aSig0, int Exp, Bit64u *zSig0, Bit64u *zSig1) +{ + Bit64u term0, term1, term2; + Bit64u aSig1 = 0; + + shortShift128Left(aSig1, aSig0, Exp, &aSig1, &aSig0); + Bit64u q = estimateDiv128To64(aSig1, aSig0, FLOAT_PI_HI); + mul128By64To192(FLOAT_PI_HI, FLOAT_PI_LO, q, &term0, &term1, &term2); + sub128(aSig1, aSig0, term0, term1, zSig1, zSig0); + while ((Bit64s)(*zSig1) < 0) { + --q; + add192(*zSig1, *zSig0, term2, 0, FLOAT_PI_HI, FLOAT_PI_LO, zSig1, zSig0, &term2); + } + *zSig1 = term2; + return q; +} + +static int reduce_trig_arg(int expDiff, int *zSign, Bit64u *aSig0, Bit64u *aSig1) +{ + Bit64u term0, term1, q = 0; + + if (expDiff < 0) { + shift128Right(*aSig0, 0, 1, aSig0, aSig1); + expDiff = 0; + } + if (expDiff > 0) { + q = argument_reduction_kernel(*aSig0, expDiff, aSig0, aSig1); + } + else { + if (FLOAT_PI_HI <= *aSig0) { + *aSig0 -= FLOAT_PI_HI; + q = 1; + } + } + + shift128Right(FLOAT_PI_HI, FLOAT_PI_LO, 1, &term0, &term1); + if (! lt128(*aSig0, *aSig1, term0, term1)) + { + int lt = lt128(term0, term1, *aSig0, *aSig1); + int eq = eq128(*aSig0, *aSig1, term0, term1); + + if ((eq && (q & 1)) || lt) { + *zSign = !(*zSign); + ++q; + } + if (lt) sub128(FLOAT_PI_HI, FLOAT_PI_LO, *aSig0, *aSig1, aSig0, aSig1); + } + + return (int)(q & 3); +} + +#define SIN_ARR_SIZE 11 +#define COS_ARR_SIZE 11 + +static float128 sin_arr[SIN_ARR_SIZE] = +{ + PACK_FLOAT_128(0x3fff000000000000, 0x0000000000000000), /* 1 */ + PACK_FLOAT_128(0xbffc555555555555, 0x5555555555555555), /* 3 */ + PACK_FLOAT_128(0x3ff8111111111111, 0x1111111111111111), /* 5 */ + PACK_FLOAT_128(0xbff2a01a01a01a01, 0xa01a01a01a01a01a), /* 7 */ + PACK_FLOAT_128(0x3fec71de3a556c73, 0x38faac1c88e50017), /* 9 */ + PACK_FLOAT_128(0xbfe5ae64567f544e, 0x38fe747e4b837dc7), /* 11 */ + PACK_FLOAT_128(0x3fde6124613a86d0, 0x97ca38331d23af68), /* 13 */ + PACK_FLOAT_128(0xbfd6ae7f3e733b81, 0xf11d8656b0ee8cb0), /* 15 */ + PACK_FLOAT_128(0x3fce952c77030ad4, 0xa6b2605197771b00), /* 17 */ + PACK_FLOAT_128(0xbfc62f49b4681415, 0x724ca1ec3b7b9675), /* 19 */ + PACK_FLOAT_128(0x3fbd71b8ef6dcf57, 0x18bef146fcee6e45) /* 21 */ +}; + +static float128 cos_arr[COS_ARR_SIZE] = +{ + PACK_FLOAT_128(0x3fff000000000000, 0x0000000000000000), /* 0 */ + PACK_FLOAT_128(0xbffe000000000000, 0x0000000000000000), /* 2 */ + PACK_FLOAT_128(0x3ffa555555555555, 0x5555555555555555), /* 4 */ + PACK_FLOAT_128(0xbff56c16c16c16c1, 0x6c16c16c16c16c17), /* 6 */ + PACK_FLOAT_128(0x3fefa01a01a01a01, 0xa01a01a01a01a01a), /* 8 */ + PACK_FLOAT_128(0xbfe927e4fb7789f5, 0xc72ef016d3ea6679), /* 10 */ + PACK_FLOAT_128(0x3fe21eed8eff8d89, 0x7b544da987acfe85), /* 12 */ + PACK_FLOAT_128(0xbfda93974a8c07c9, 0xd20badf145dfa3e5), /* 14 */ + PACK_FLOAT_128(0x3fd2ae7f3e733b81, 0xf11d8656b0ee8cb0), /* 16 */ + PACK_FLOAT_128(0xbfca6827863b97d9, 0x77bb004886a2c2ab), /* 18 */ + PACK_FLOAT_128(0x3fc1e542ba402022, 0x507a9cad2bf8f0bb) /* 20 */ +}; + +extern float128 OddPoly (float128 x, float128 *arr, int n, struct float_status_t *status); + +/* 0 <= x <= pi/4 */ +BX_CPP_INLINE float128 poly_sin(float128 x, struct float_status_t *status) +{ + // 3 5 7 9 11 13 15 + // x x x x x x x + // sin (x) ~ x - --- + --- - --- + --- - ---- + ---- - ---- = + // 3! 5! 7! 9! 11! 13! 15! + // + // 2 4 6 8 10 12 14 + // x x x x x x x + // = x * [ 1 - --- + --- - --- + --- - ---- + ---- - ---- ] = + // 3! 5! 7! 9! 11! 13! 15! + // + // 3 3 + // -- 4k -- 4k+2 + // p(x) = > C * x > 0 q(x) = > C * x < 0 + // -- 2k -- 2k+1 + // k=0 k=0 + // + // 2 + // sin(x) ~ x * [ p(x) + x * q(x) ] + // + + return OddPoly(x, sin_arr, SIN_ARR_SIZE, status); +} + +extern float128 EvenPoly(float128 x, float128 *arr, int n, struct float_status_t *status); + +/* 0 <= x <= pi/4 */ +BX_CPP_INLINE float128 poly_cos(float128 x, struct float_status_t *status) +{ + // 2 4 6 8 10 12 14 + // x x x x x x x + // cos (x) ~ 1 - --- + --- - --- + --- - ---- + ---- - ---- + // 2! 4! 6! 8! 10! 12! 14! + // + // 3 3 + // -- 4k -- 4k+2 + // p(x) = > C * x > 0 q(x) = > C * x < 0 + // -- 2k -- 2k+1 + // k=0 k=0 + // + // 2 + // cos(x) ~ [ p(x) + x * q(x) ] + // + + return EvenPoly(x, cos_arr, COS_ARR_SIZE, status); +} + +BX_CPP_INLINE void sincos_invalid(floatx80 *sin_a, floatx80 *cos_a, floatx80 a) +{ + if (sin_a) *sin_a = a; + if (cos_a) *cos_a = a; +} + +BX_CPP_INLINE void sincos_tiny_argument(floatx80 *sin_a, floatx80 *cos_a, floatx80 a) +{ + if (sin_a) *sin_a = a; + if (cos_a) *cos_a = floatx80_one; +} + +static floatx80 sincos_approximation(int neg, float128 r, Bit64u quotient, struct float_status_t *status) +{ + if (quotient & 0x1) { + r = poly_cos(r, status); + neg = 0; + } else { + r = poly_sin(r, status); + } + + floatx80 result = float128_to_floatx80(r, status); + if (quotient & 0x2) + neg = ! neg; + + if (neg) + floatx80_chs(result); + + return result; +} + +// ================================================= +// FSINCOS Compute sin(x) and cos(x) +// ================================================= + +// +// Uses the following identities: +// ---------------------------------------------------------- +// +// sin(-x) = -sin(x) +// cos(-x) = cos(x) +// +// sin(x+y) = sin(x)*cos(y)+cos(x)*sin(y) +// cos(x+y) = sin(x)*sin(y)+cos(x)*cos(y) +// +// sin(x+ pi/2) = cos(x) +// sin(x+ pi) = -sin(x) +// sin(x+3pi/2) = -cos(x) +// sin(x+2pi) = sin(x) +// + +int fsincos(floatx80 a, floatx80 *sin_a, floatx80 *cos_a, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit64u aSig0, aSig1 = 0; + Bit32s aExp, zExp, expDiff; + int aSign, zSign; + int q = 0; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a)) { + goto invalid; + } + + aSig0 = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + + /* invalid argument */ + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig0<<1)) { + sincos_invalid(sin_a, cos_a, propagateFloatx80NaNOne(a, status)); + return 0; + } + + invalid: + float_raise(status, float_flag_invalid); + sincos_invalid(sin_a, cos_a, floatx80_default_nan); + return 0; + } + + if (aExp == 0) { + if (aSig0 == 0) { + sincos_tiny_argument(sin_a, cos_a, a); + return 0; + } + + float_raise(status, float_flag_denormal); + + /* handle pseudo denormals */ + if (! (aSig0 & BX_CONST64(0x8000000000000000))) + { + float_raise(status, float_flag_inexact); + if (sin_a) + float_raise(status, float_flag_underflow); + sincos_tiny_argument(sin_a, cos_a, a); + return 0; + } + + normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); + } + + zSign = aSign; + zExp = FLOATX80_EXP_BIAS; + expDiff = aExp - zExp; + + /* argument is out-of-range */ + if (expDiff >= 63) + return -1; + + float_raise(status, float_flag_inexact); + + if (expDiff < -1) { // doesn't require reduction + if (expDiff <= -68) { + a = packFloatx80(aSign, aExp, aSig0); + sincos_tiny_argument(sin_a, cos_a, a); + return 0; + } + zExp = aExp; + } + else { + q = reduce_trig_arg(expDiff, &zSign, &aSig0, &aSig1); + } + + /* **************************** */ + /* argument reduction completed */ + /* **************************** */ + + /* using float128 for approximation */ + float128 r = normalizeRoundAndPackFloat128(0, zExp-0x10, aSig0, aSig1, status); + + if (aSign) q = -q; + if (sin_a) *sin_a = sincos_approximation(zSign, r, q, status); + if (cos_a) *cos_a = sincos_approximation(zSign, r, q+1, status); + + return 0; +} + +int fsin(floatx80 *a, struct float_status_t *status) +{ + return fsincos(*a, a, 0, status); +} + +int fcos(floatx80 *a, struct float_status_t *status) +{ + return fsincos(*a, 0, a, status); +} + +// ================================================= +// FPTAN Compute tan(x) +// ================================================= + +// +// Uses the following identities: +// +// 1. ---------------------------------------------------------- +// +// sin(-x) = -sin(x) +// cos(-x) = cos(x) +// +// sin(x+y) = sin(x)*cos(y)+cos(x)*sin(y) +// cos(x+y) = sin(x)*sin(y)+cos(x)*cos(y) +// +// sin(x+ pi/2) = cos(x) +// sin(x+ pi) = -sin(x) +// sin(x+3pi/2) = -cos(x) +// sin(x+2pi) = sin(x) +// +// 2. ---------------------------------------------------------- +// +// sin(x) +// tan(x) = ------ +// cos(x) +// + +int ftan(floatx80 *a, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit64u aSig0, aSig1 = 0; + Bit32s aExp, zExp, expDiff; + int aSign, zSign; + int q = 0; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(*a)) { + goto invalid; + } + + aSig0 = extractFloatx80Frac(*a); + aExp = extractFloatx80Exp(*a); + aSign = extractFloatx80Sign(*a); + + /* invalid argument */ + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig0<<1)) + { + *a = propagateFloatx80NaNOne(*a, status); + return 0; + } + + invalid: + float_raise(status, float_flag_invalid); + *a = floatx80_default_nan; + return 0; + } + + if (aExp == 0) { + if (aSig0 == 0) return 0; + float_raise(status, float_flag_denormal); + /* handle pseudo denormals */ + if (! (aSig0 & BX_CONST64(0x8000000000000000))) + { + float_raise(status, float_flag_inexact | float_flag_underflow); + return 0; + } + normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); + } + + zSign = aSign; + zExp = FLOATX80_EXP_BIAS; + expDiff = aExp - zExp; + + /* argument is out-of-range */ + if (expDiff >= 63) + return -1; + + float_raise(status, float_flag_inexact); + + if (expDiff < -1) { // doesn't require reduction + if (expDiff <= -68) { + *a = packFloatx80(aSign, aExp, aSig0); + return 0; + } + zExp = aExp; + } + else { + q = reduce_trig_arg(expDiff, &zSign, &aSig0, &aSig1); + } + + /* **************************** */ + /* argument reduction completed */ + /* **************************** */ + + /* using float128 for approximation */ + float128 r = normalizeRoundAndPackFloat128(0, zExp-0x10, aSig0, aSig1, status); + + float128 sin_r = poly_sin(r, status); + float128 cos_r = poly_cos(r, status); + + if (q & 0x1) { + r = float128_div(cos_r, sin_r, status); + zSign = ! zSign; + } else { + r = float128_div(sin_r, cos_r, status); + } + + *a = float128_to_floatx80(r, status); + if (zSign) + floatx80_chs(*a); + + return 0; +} diff --git a/src/cpu/softfloat/fyl2x.cc b/src/cpu/softfloat/fyl2x.cc new file mode 100644 index 000000000..875f866a9 --- /dev/null +++ b/src/cpu/softfloat/fyl2x.cc @@ -0,0 +1,363 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#define FLOAT128 + +#include "softfloatx80.h" +#include "softfloat-round-pack.h" +#include "fpu_constant.h" + +static const floatx80 floatx80_one = + packFloatx80(0, 0x3fff, BX_CONST64(0x8000000000000000)); + +static const float128 float128_one = + packFloat128(BX_CONST64(0x3fff000000000000), BX_CONST64(0x0000000000000000)); +static const float128 float128_two = + packFloat128(BX_CONST64(0x4000000000000000), BX_CONST64(0x0000000000000000)); + +static const float128 float128_ln2inv2 = + packFloat128(BX_CONST64(0x400071547652b82f), BX_CONST64(0xe1777d0ffda0d23a)); + +#define SQRT2_HALF_SIG BX_CONST64(0xb504f333f9de6484) + +extern float128 OddPoly(float128 x, float128 *arr, int n, struct float_status_t *status); + +#define L2_ARR_SIZE 9 + +static float128 ln_arr[L2_ARR_SIZE] = +{ + PACK_FLOAT_128(0x3fff000000000000, 0x0000000000000000), /* 1 */ + PACK_FLOAT_128(0x3ffd555555555555, 0x5555555555555555), /* 3 */ + PACK_FLOAT_128(0x3ffc999999999999, 0x999999999999999a), /* 5 */ + PACK_FLOAT_128(0x3ffc249249249249, 0x2492492492492492), /* 7 */ + PACK_FLOAT_128(0x3ffbc71c71c71c71, 0xc71c71c71c71c71c), /* 9 */ + PACK_FLOAT_128(0x3ffb745d1745d174, 0x5d1745d1745d1746), /* 11 */ + PACK_FLOAT_128(0x3ffb3b13b13b13b1, 0x3b13b13b13b13b14), /* 13 */ + PACK_FLOAT_128(0x3ffb111111111111, 0x1111111111111111), /* 15 */ + PACK_FLOAT_128(0x3ffae1e1e1e1e1e1, 0xe1e1e1e1e1e1e1e2) /* 17 */ +}; + +static float128 poly_ln(float128 x1, struct float_status_t *status) +{ +/* + // + // 3 5 7 9 11 13 15 + // 1+u u u u u u u u + // 1/2 ln --- ~ u + --- + --- + --- + --- + ---- + ---- + ---- = + // 1-u 3 5 7 9 11 13 15 + // + // 2 4 6 8 10 12 14 + // u u u u u u u + // = u * [ 1 + --- + --- + --- + --- + ---- + ---- + ---- ] = + // 3 5 7 9 11 13 15 + // + // 3 3 + // -- 4k -- 4k+2 + // p(u) = > C * u q(u) = > C * u + // -- 2k -- 2k+1 + // k=0 k=0 + // + // 1+u 2 + // 1/2 ln --- ~ u * [ p(u) + u * q(u) ] + // 1-u + // +*/ + return OddPoly(x1, ln_arr, L2_ARR_SIZE, status); +} + +/* required sqrt(2)/2 < x < sqrt(2) */ +static float128 poly_l2(float128 x, struct float_status_t *status) +{ + /* using float128 for approximation */ + float128 x_p1 = float128_add(x, float128_one, status); + float128 x_m1 = float128_sub(x, float128_one, status); + x = float128_div(x_m1, x_p1, status); + x = poly_ln(x, status); + x = float128_mul(x, float128_ln2inv2, status); + return x; +} + +static float128 poly_l2p1(float128 x, struct float_status_t *status) +{ + /* using float128 for approximation */ + float128 x_p2 = float128_add(x, float128_two, status); + x = float128_div(x, x_p2, status); + x = poly_ln(x, status); + x = float128_mul(x, float128_ln2inv2, status); + return x; +} + +// ================================================= +// FYL2X Compute y * log (x) +// 2 +// ================================================= + +// +// Uses the following identities: +// +// 1. ---------------------------------------------------------- +// ln(x) +// log (x) = -------, ln (x*y) = ln(x) + ln(y) +// 2 ln(2) +// +// 2. ---------------------------------------------------------- +// 1+u x-1 +// ln (x) = ln -----, when u = ----- +// 1-u x+1 +// +// 3. ---------------------------------------------------------- +// 3 5 7 2n+1 +// 1+u u u u u +// ln ----- = 2 [ u + --- + --- + --- + ... + ------ + ... ] +// 1-u 3 5 7 2n+1 +// + +floatx80 fyl2x(floatx80 a, floatx80 b, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) { +invalid: + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + Bit64u aSig = extractFloatx80Frac(a); + Bit32s aExp = extractFloatx80Exp(a); + int aSign = extractFloatx80Sign(a); + Bit64u bSig = extractFloatx80Frac(b); + Bit32s bExp = extractFloatx80Exp(b); + int bSign = extractFloatx80Sign(b); + + int zSign = bSign ^ 1; + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1) + || ((bExp == 0x7FFF) && (Bit64u) (bSig<<1))) + { + return propagateFloatx80NaN(a, b, status); + } + if (aSign) goto invalid; + else { + if (bExp == 0) { + if (bSig == 0) goto invalid; + float_raise(status, float_flag_denormal); + } + return packFloatx80(bSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + } + if (bExp == 0x7FFF) + { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + if (aSign && (Bit64u)(aExp | aSig)) goto invalid; + if (aSig && (aExp == 0)) + float_raise(status, float_flag_denormal); + if (aExp < 0x3FFF) { + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0x3FFF && ((Bit64u) (aSig<<1) == 0)) goto invalid; + return packFloatx80(bSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) { + if (aSig == 0) { + if ((bExp | bSig) == 0) goto invalid; + float_raise(status, float_flag_divbyzero); + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aSign) goto invalid; + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + if (aSign) goto invalid; + if (bExp == 0) { + if (bSig == 0) { + if (aExp < 0x3FFF) return packFloatx80(zSign, 0, 0); + return packFloatx80(bSign, 0, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + if (aExp == 0x3FFF && ((Bit64u) (aSig<<1) == 0)) + return packFloatx80(bSign, 0, 0); + + float_raise(status, float_flag_inexact); + + int ExpDiff = aExp - 0x3FFF; + aExp = 0; + if (aSig >= SQRT2_HALF_SIG) { + ExpDiff++; + aExp--; + } + + /* ******************************** */ + /* using float128 for approximation */ + /* ******************************** */ + + Bit64u zSig0, zSig1; + shift128Right(aSig<<1, 0, 16, &zSig0, &zSig1); + float128 x = packFloat128Four(0, aExp+0x3FFF, zSig0, zSig1); + x = poly_l2(x, status); + x = float128_add(x, int64_to_float128((Bit64s) ExpDiff), status); + return floatx80_128_mul(b, x, status); +} + +// ================================================= +// FYL2XP1 Compute y * log (x + 1) +// 2 +// ================================================= + +// +// Uses the following identities: +// +// 1. ---------------------------------------------------------- +// ln(x) +// log (x) = ------- +// 2 ln(2) +// +// 2. ---------------------------------------------------------- +// 1+u x +// ln (x+1) = ln -----, when u = ----- +// 1-u x+2 +// +// 3. ---------------------------------------------------------- +// 3 5 7 2n+1 +// 1+u u u u u +// ln ----- = 2 [ u + --- + --- + --- + ... + ------ + ... ] +// 1-u 3 5 7 2n+1 +// + +floatx80 fyl2xp1(floatx80 a, floatx80 b, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit32s aExp, bExp; + Bit64u aSig, bSig, zSig0, zSig1, zSig2; + int aSign, bSign; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) { +invalid: + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + bSign = extractFloatx80Sign(b); + int zSign = aSign ^ bSign; + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1) + || ((bExp == 0x7FFF) && (Bit64u) (bSig<<1))) + { + return propagateFloatx80NaN(a, b, status); + } + if (aSign) goto invalid; + else { + if (bExp == 0) { + if (bSig == 0) goto invalid; + float_raise(status, float_flag_denormal); + } + return packFloatx80(bSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + } + if (bExp == 0x7FFF) + { + if ((Bit64u) (bSig<<1)) + return propagateFloatx80NaN(a, b, status); + + if (aExp == 0) { + if (aSig == 0) goto invalid; + float_raise(status, float_flag_denormal); + } + + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) { + if (aSig == 0) { + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloatx80(zSign, 0, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + if (bSig == 0) return packFloatx80(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + + float_raise(status, float_flag_inexact); + + if (aSign && aExp >= 0x3FFF) + return a; + + if (aExp >= 0x3FFC) // big argument + { + return fyl2x(floatx80_add(a, floatx80_one, status), b, status); + } + + // handle tiny argument + if (aExp < FLOATX80_EXP_BIAS-70) + { + // first order approximation, return (a*b)/ln(2) + Bit32s zExp = aExp + FLOAT_LN2INV_EXP - 0x3FFE; + + mul128By64To192(FLOAT_LN2INV_HI, FLOAT_LN2INV_LO, aSig, &zSig0, &zSig1, &zSig2); + if (0 < (Bit64s) zSig0) { + shortShift128Left(zSig0, zSig1, 1, &zSig0, &zSig1); + --zExp; + } + + zExp = zExp + bExp - 0x3FFE; + mul128By64To192(zSig0, zSig1, bSig, &zSig0, &zSig1, &zSig2); + if (0 < (Bit64s) zSig0) { + shortShift128Left(zSig0, zSig1, 1, &zSig0, &zSig1); + --zExp; + } + + return + roundAndPackFloatx80(80, aSign ^ bSign, zExp, zSig0, zSig1, status); + } + + /* ******************************** */ + /* using float128 for approximation */ + /* ******************************** */ + + shift128Right(aSig<<1, 0, 16, &zSig0, &zSig1); + float128 x = packFloat128Four(aSign, aExp, zSig0, zSig1); + x = poly_l2p1(x, status); + return floatx80_128_mul(b, x, status); +} diff --git a/src/cpu/softfloat/softfloat-compare.h b/src/cpu/softfloat/softfloat-compare.h new file mode 100644 index 000000000..8b9821460 --- /dev/null +++ b/src/cpu/softfloat/softfloat-compare.h @@ -0,0 +1,496 @@ +/*============================================================================ +This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#ifndef _SOFTFLOAT_COMPARE_H_ +#define _SOFTFLOAT_COMPARE_H_ + +#include "softfloat.h" + +// ======= float32 ======= // + +typedef int (*float32_compare_method)(float32, float32, struct float_status_t *status); + +// 0x00 +BX_CPP_INLINE int float32_eq_ordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_equal); +} + +// 0x01 +BX_CPP_INLINE int float32_lt_ordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_less); +} + +// 0x02 +BX_CPP_INLINE int float32_le_ordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_equal); +} + +// 0x03 +BX_CPP_INLINE int float32_unordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_unordered); +} + +// 0x04 +BX_CPP_INLINE int float32_neq_unordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation != float_relation_equal); +} + +// 0x05 +BX_CPP_INLINE int float32_nlt_unordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation != float_relation_less); +} + +// 0x06 +BX_CPP_INLINE int float32_nle_unordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation != float_relation_less) && (relation != float_relation_equal); +} + +// 0x07 +BX_CPP_INLINE int float32_ordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation != float_relation_unordered); +} + +// 0x08 +BX_CPP_INLINE int float32_eq_unordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_equal) || (relation == float_relation_unordered); +} + +// 0x09 +BX_CPP_INLINE int float32_nge_unordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_unordered); +} + +// 0x0a +BX_CPP_INLINE int float32_ngt_unordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation != float_relation_greater); +} + +// 0x0b +BX_CPP_INLINE int float32_false_quiet(float32 a, float32 b, struct float_status_t *status) +{ + float32_compare_quiet(a, b, status); + return 0; +} + +// 0x0c +BX_CPP_INLINE int float32_neq_ordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation != float_relation_equal) && (relation != float_relation_unordered); +} + +// 0x0d +BX_CPP_INLINE int float32_ge_ordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_greater) || (relation == float_relation_equal); +} + +// 0x0e +BX_CPP_INLINE int float32_gt_ordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_greater); +} + +// 0x0f +BX_CPP_INLINE int float32_true_quiet(float32 a, float32 b, struct float_status_t *status) +{ + float32_compare_quiet(a, b, status); + return 1; +} + +// 0x10 +BX_CPP_INLINE int float32_eq_ordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_equal); +} + +// 0x11 +BX_CPP_INLINE int float32_lt_ordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_less); +} + +// 0x12 +BX_CPP_INLINE int float32_le_ordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_equal); +} + +// 0x13 +BX_CPP_INLINE int float32_unordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_unordered); +} + +// 0x14 +BX_CPP_INLINE int float32_neq_unordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation != float_relation_equal); +} + +// 0x15 +BX_CPP_INLINE int float32_nlt_unordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation != float_relation_less); +} + +// 0x16 +BX_CPP_INLINE int float32_nle_unordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation != float_relation_less) && (relation != float_relation_equal); +} + +// 0x17 +BX_CPP_INLINE int float32_ordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation != float_relation_unordered); +} + +// 0x18 +BX_CPP_INLINE int float32_eq_unordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation == float_relation_equal) || (relation == float_relation_unordered); +} + +// 0x19 +BX_CPP_INLINE int float32_nge_unordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_unordered); +} + +// 0x1a +BX_CPP_INLINE int float32_ngt_unordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation != float_relation_greater); +} + +// 0x1b +BX_CPP_INLINE int float32_false_signalling(float32 a, float32 b, struct float_status_t *status) +{ + float32_compare_two(a, b, status); + return 0; +} + +// 0x1c +BX_CPP_INLINE int float32_neq_ordered_signalling(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_two(a, b, status); + return (relation != float_relation_equal) && (relation != float_relation_unordered); +} + +// 0x1d +BX_CPP_INLINE int float32_ge_ordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_greater) || (relation == float_relation_equal); +} + +// 0x1e +BX_CPP_INLINE int float32_gt_ordered_quiet(float32 a, float32 b, struct float_status_t *status) +{ + int relation = float32_compare_quiet(a, b, status); + return (relation == float_relation_greater); +} + +// 0x1f +BX_CPP_INLINE int float32_true_signalling(float32 a, float32 b, struct float_status_t *status) +{ + float32_compare_two(a, b, status); + return 1; +} + +// ======= float64 ======= // + +typedef int (*float64_compare_method)(float64, float64, struct float_status_t *status); + +// 0x00 +BX_CPP_INLINE int float64_eq_ordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_equal); +} + +// 0x01 +BX_CPP_INLINE int float64_lt_ordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_less); +} + +// 0x02 +BX_CPP_INLINE int float64_le_ordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_equal); +} + +// 0x03 +BX_CPP_INLINE int float64_unordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_unordered); +} + +// 0x04 +BX_CPP_INLINE int float64_neq_unordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation != float_relation_equal); +} + +// 0x05 +BX_CPP_INLINE int float64_nlt_unordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation != float_relation_less); +} + +// 0x06 +BX_CPP_INLINE int float64_nle_unordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation != float_relation_less) && (relation != float_relation_equal); +} + +// 0x07 +BX_CPP_INLINE int float64_ordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation != float_relation_unordered); +} + +// 0x08 +BX_CPP_INLINE int float64_eq_unordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_equal) || (relation == float_relation_unordered); +} + +// 0x09 +BX_CPP_INLINE int float64_nge_unordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_unordered); +} + +// 0x0a +BX_CPP_INLINE int float64_ngt_unordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation != float_relation_greater); +} + +// 0x0b +BX_CPP_INLINE int float64_false_quiet(float64 a, float64 b, struct float_status_t *status) +{ + float64_compare_quiet(a, b, status); + return 0; +} + +// 0x0c +BX_CPP_INLINE int float64_neq_ordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation != float_relation_equal) && (relation != float_relation_unordered); +} + +// 0x0d +BX_CPP_INLINE int float64_ge_ordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_greater) || (relation == float_relation_equal); +} + +// 0x0e +BX_CPP_INLINE int float64_gt_ordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_greater); +} + +// 0x0f +BX_CPP_INLINE int float64_true_quiet(float64 a, float64 b, struct float_status_t *status) +{ + float64_compare_quiet(a, b, status); + return 1; +} + +// 0x10 +BX_CPP_INLINE int float64_eq_ordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_equal); +} + +// 0x11 +BX_CPP_INLINE int float64_lt_ordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_less); +} + +// 0x12 +BX_CPP_INLINE int float64_le_ordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_equal); +} + +// 0x13 +BX_CPP_INLINE int float64_unordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_unordered); +} + +// 0x14 +BX_CPP_INLINE int float64_neq_unordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation != float_relation_equal); +} + +// 0x15 +BX_CPP_INLINE int float64_nlt_unordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation != float_relation_less); +} + +// 0x16 +BX_CPP_INLINE int float64_nle_unordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation != float_relation_less) && (relation != float_relation_equal); +} + +// 0x17 +BX_CPP_INLINE int float64_ordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation != float_relation_unordered); +} + +// 0x18 +BX_CPP_INLINE int float64_eq_unordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation == float_relation_equal) || (relation == float_relation_unordered); +} + +// 0x19 +BX_CPP_INLINE int float64_nge_unordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_less) || (relation == float_relation_unordered); +} + +// 0x1a +BX_CPP_INLINE int float64_ngt_unordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation != float_relation_greater); +} + +// 0x1b +BX_CPP_INLINE int float64_false_signalling(float64 a, float64 b, struct float_status_t *status) +{ + float64_compare_two(a, b, status); + return 0; +} + +// 0x1c +BX_CPP_INLINE int float64_neq_ordered_signalling(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_two(a, b, status); + return (relation != float_relation_equal) && (relation != float_relation_unordered); +} + +// 0x1d +BX_CPP_INLINE int float64_ge_ordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_greater) || (relation == float_relation_equal); +} + +// 0x1e +BX_CPP_INLINE int float64_gt_ordered_quiet(float64 a, float64 b, struct float_status_t *status) +{ + int relation = float64_compare_quiet(a, b, status); + return (relation == float_relation_greater); +} + +// 0x1f +BX_CPP_INLINE int float64_true_signalling(float64 a, float64 b, struct float_status_t *status) +{ + float64_compare_two(a, b, status); + return 1; +} + +#endif diff --git a/src/cpu/softfloat/softfloat-macros.h b/src/cpu/softfloat/softfloat-macros.h new file mode 100644 index 000000000..cb867bf5d --- /dev/null +++ b/src/cpu/softfloat/softfloat-macros.h @@ -0,0 +1,686 @@ +/*============================================================================ +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal notice) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#ifndef _SOFTFLOAT_MACROS_H_ +#define _SOFTFLOAT_MACROS_H_ + +/*---------------------------------------------------------------------------- +| Shifts `a' right by the number of bits given in `count'. If any nonzero +| bits are shifted off, they are ``jammed'' into the least significant bit of +| the result by setting the least significant bit to 1. The value of `count' +| can be arbitrarily large; in particular, if `count' is greater than 16, the +| result will be either 0 or 1, depending on whether `a' is zero or nonzero. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit16u shift16RightJamming(Bit16u a, int count) +{ + Bit16u z; + + if (count == 0) { + z = a; + } + else if (count < 16) { + z = (a>>count) | ((a<<((-count) & 15)) != 0); + } + else { + z = (a != 0); + } + + return z; +} + +/*---------------------------------------------------------------------------- +| Shifts `a' right by the number of bits given in `count'. If any nonzero +| bits are shifted off, they are ``jammed'' into the least significant bit of +| the result by setting the least significant bit to 1. The value of `count' +| can be arbitrarily large; in particular, if `count' is greater than 32, the +| result will be either 0 or 1, depending on whether `a' is zero or nonzero. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit32u shift32RightJamming(Bit32u a, int count) +{ + Bit32u z; + + if (count == 0) { + z = a; + } + else if (count < 32) { + z = (a>>count) | ((a<<((-count) & 31)) != 0); + } + else { + z = (a != 0); + } + + return z; +} + +/*---------------------------------------------------------------------------- +| Shifts `a' right by the number of bits given in `count'. If any nonzero +| bits are shifted off, they are ``jammed'' into the least significant bit of +| the result by setting the least significant bit to 1. The value of `count' +| can be arbitrarily large; in particular, if `count' is greater than 64, the +| result will be either 0 or 1, depending on whether `a' is zero or nonzero. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit64u shift64RightJamming(Bit64u a, int count) +{ + Bit64u z; + + if (count == 0) { + z = a; + } + else if (count < 64) { + z = (a>>count) | ((a << ((-count) & 63)) != 0); + } + else { + z = (a != 0); + } + + return z; +} + +/*---------------------------------------------------------------------------- +| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by 64 +| _plus_ the number of bits given in `count'. The shifted result is at most +| 64 nonzero bits; this is stored at the location pointed to by `z0Ptr'. The +| bits shifted off form a second 64-bit result as follows: The _last_ bit +| shifted off is the most-significant bit of the extra result, and the other +| 63 bits of the extra result are all zero if and only if _all_but_the_last_ +| bits shifted off were all zero. This extra result is stored in the location +| pointed to by `z1Ptr'. The value of `count' can be arbitrarily large. +| (This routine makes more sense if `a0' and `a1' are considered to form +| a fixed-point value with binary point between `a0' and `a1'. This fixed- +| point value is shifted right by the number of bits given in `count', and +| the integer part of the result is returned at the location pointed to by +| `z0Ptr'. The fractional part of the result may be slightly corrupted as +| described above, and is returned at the location pointed to by `z1Ptr'.) +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void shift64ExtraRightJamming(Bit64u a0, Bit64u a1, int count, Bit64u *z0Ptr, Bit64u *z1Ptr) +{ + Bit64u z0, z1; + int negCount = (-count) & 63; + + if (count == 0) { + z1 = a1; + z0 = a0; + } + else if (count < 64) { + z1 = (a0<>count; + } + else { + if (count == 64) { + z1 = a0 | (a1 != 0); + } + else { + z1 = ((a0 | a1) != 0); + } + z0 = 0; + } + *z1Ptr = z1; + *z0Ptr = z0; +} + +/*---------------------------------------------------------------------------- +| Adds the 128-bit value formed by concatenating `a0' and `a1' to the 128-bit +| value formed by concatenating `b0' and `b1'. Addition is modulo 2^128, so +| any carry out is lost. The result is broken into two 64-bit pieces which +| are stored at the locations pointed to by `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void add128(Bit64u a0, Bit64u a1, Bit64u b0, Bit64u b1, Bit64u *z0Ptr, Bit64u *z1Ptr) +{ + Bit64u z1 = a1 + b1; + *z1Ptr = z1; + *z0Ptr = a0 + b0 + (z1 < a1); +} + +/*---------------------------------------------------------------------------- +| Subtracts the 128-bit value formed by concatenating `b0' and `b1' from the +| 128-bit value formed by concatenating `a0' and `a1'. Subtraction is modulo +| 2^128, so any borrow out (carry out) is lost. The result is broken into two +| 64-bit pieces which are stored at the locations pointed to by `z0Ptr' and +| `z1Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void + sub128(Bit64u a0, Bit64u a1, Bit64u b0, Bit64u b1, Bit64u *z0Ptr, Bit64u *z1Ptr) +{ + *z1Ptr = a1 - b1; + *z0Ptr = a0 - b0 - (a1 < b1); +} + +/*---------------------------------------------------------------------------- +| Multiplies `a' by `b' to obtain a 128-bit product. The product is broken +| into two 64-bit pieces which are stored at the locations pointed to by +| `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void mul64To128(Bit64u a, Bit64u b, Bit64u *z0Ptr, Bit64u *z1Ptr) +{ + Bit32u aHigh, aLow, bHigh, bLow; + Bit64u z0, zMiddleA, zMiddleB, z1; + + aLow = (Bit32u) a; + aHigh = (Bit32u)(a>>32); + bLow = (Bit32u) b; + bHigh = (Bit32u)(b>>32); + z1 = ((Bit64u) aLow) * bLow; + zMiddleA = ((Bit64u) aLow) * bHigh; + zMiddleB = ((Bit64u) aHigh) * bLow; + z0 = ((Bit64u) aHigh) * bHigh; + zMiddleA += zMiddleB; + z0 += (((Bit64u) (zMiddleA < zMiddleB))<<32) + (zMiddleA>>32); + zMiddleA <<= 32; + z1 += zMiddleA; + z0 += (z1 < zMiddleA); + *z1Ptr = z1; + *z0Ptr = z0; +} + +/*---------------------------------------------------------------------------- +| Returns an approximation to the 64-bit integer quotient obtained by dividing +| `b' into the 128-bit value formed by concatenating `a0' and `a1'. The +| divisor `b' must be at least 2^63. If q is the exact quotient truncated +| toward zero, the approximation returned lies between q and q + 2 inclusive. +| If the exact quotient q is larger than 64 bits, the maximum positive 64-bit +| unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +#ifdef USE_estimateDiv128To64 +static Bit64u estimateDiv128To64(Bit64u a0, Bit64u a1, Bit64u b) +{ + Bit64u b0, b1; + Bit64u rem0, rem1, term0, term1; + Bit64u z; + + if (b <= a0) return BX_CONST64(0xFFFFFFFFFFFFFFFF); + b0 = b>>32; + z = (b0<<32 <= a0) ? BX_CONST64(0xFFFFFFFF00000000) : (a0 / b0)<<32; + mul64To128(b, z, &term0, &term1); + sub128(a0, a1, term0, term1, &rem0, &rem1); + while (((Bit64s) rem0) < 0) { + z -= BX_CONST64(0x100000000); + b1 = b<<32; + add128(rem0, rem1, b0, b1, &rem0, &rem1); + } + rem0 = (rem0<<32) | (rem1>>32); + z |= (b0<<32 <= rem0) ? 0xFFFFFFFF : rem0 / b0; + return z; +} +#endif + +/*---------------------------------------------------------------------------- +| Returns an approximation to the square root of the 32-bit significand given +| by `a'. Considered as an integer, `a' must be at least 2^31. If bit 0 of +| `aExp' (the least significant bit) is 1, the integer returned approximates +| 2^31*sqrt(`a'/2^31), where `a' is considered an integer. If bit 0 of `aExp' +| is 0, the integer returned approximates 2^31*sqrt(`a'/2^30). In either +| case, the approximation returned lies strictly within +/-2 of the exact +| value. +*----------------------------------------------------------------------------*/ + +#ifdef USE_estimateSqrt32 +static Bit32u estimateSqrt32(Bit16s aExp, Bit32u a) +{ + static const Bit16u sqrtOddAdjustments[] = { + 0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0, + 0x039C, 0x0468, 0x0545, 0x0631, 0x072B, 0x0832, 0x0946, 0x0A67 + }; + static const Bit16u sqrtEvenAdjustments[] = { + 0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E, + 0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002 + }; + Bit32u z; + + int index = (a>>27) & 15; + if (aExp & 1) { + z = 0x4000 + (a>>17) - sqrtOddAdjustments[index]; + z = ((a / z)<<14) + (z<<15); + a >>= 1; + } + else { + z = 0x8000 + (a>>17) - sqrtEvenAdjustments[index]; + z = a / z + z; + z = (0x20000 <= z) ? 0xFFFF8000 : (z<<15); + if (z <= a) return (Bit32u) (((Bit32s) a)>>1); + } + return ((Bit32u) ((((Bit64u) a)<<31) / z)) + (z>>1); +} +#endif + +static const int countLeadingZeros8[] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +#ifdef FLOAT16 + +/*---------------------------------------------------------------------------- +| Returns the number of leading 0 bits before the most-significant 1 bit of +| `a'. If `a' is zero, 16 is returned. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int countLeadingZeros16(Bit16u a) +{ + int shiftCount = 0; + if (a < 0x100) { + shiftCount += 8; + a <<= 8; + } + shiftCount += countLeadingZeros8[a>>8]; + return shiftCount; +} + +#endif + +/*---------------------------------------------------------------------------- +| Returns the number of leading 0 bits before the most-significant 1 bit of +| `a'. If `a' is zero, 32 is returned. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int countLeadingZeros32(Bit32u a) +{ + int shiftCount = 0; + if (a < 0x10000) { + shiftCount += 16; + a <<= 16; + } + if (a < 0x1000000) { + shiftCount += 8; + a <<= 8; + } + shiftCount += countLeadingZeros8[a>>24]; + return shiftCount; +} + +/*---------------------------------------------------------------------------- +| Returns the number of leading 0 bits before the most-significant 1 bit of +| `a'. If `a' is zero, 64 is returned. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int countLeadingZeros64(Bit64u a) +{ + int shiftCount = 0; + if (a < BX_CONST64(0x100000000)) { + shiftCount += 32; + } + else { + a >>= 32; + } + shiftCount += countLeadingZeros32((Bit32u)(a)); + return shiftCount; +} + +#ifdef FLOATX80 + +/*---------------------------------------------------------------------------- +| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by the +| number of bits given in `count'. Any bits shifted off are lost. The value +| of `count' can be arbitrarily large; in particular, if `count' is greater +| than 128, the result will be 0. The result is broken into two 64-bit pieces +| which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void shift128Right(Bit64u a0, Bit64u a1, int count, Bit64u *z0Ptr, Bit64u *z1Ptr) +{ + Bit64u z0, z1; + int negCount = (-count) & 63; + + if (count == 0) { + z1 = a1; + z0 = a0; + } + else if (count < 64) { + z1 = (a0<>count); + z0 = a0>>count; + } + else { + z1 = (count < 128) ? (a0>>(count & 63)) : 0; + z0 = 0; + } + *z1Ptr = z1; + *z0Ptr = z0; +} + +/*---------------------------------------------------------------------------- +| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by the +| number of bits given in `count'. If any nonzero bits are shifted off, they +| are ``jammed'' into the least significant bit of the result by setting the +| least significant bit to 1. The value of `count' can be arbitrarily large; +| in particular, if `count' is greater than 128, the result will be either +| 0 or 1, depending on whether the concatenation of `a0' and `a1' is zero or +| nonzero. The result is broken into two 64-bit pieces which are stored at +| the locations pointed to by `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void shift128RightJamming(Bit64u a0, Bit64u a1, int count, Bit64u *z0Ptr, Bit64u *z1Ptr) +{ + Bit64u z0, z1; + int negCount = (-count) & 63; + + if (count == 0) { + z1 = a1; + z0 = a0; + } + else if (count < 64) { + z1 = (a0<>count) | ((a1<>count; + } + else { + if (count == 64) { + z1 = a0 | (a1 != 0); + } + else if (count < 128) { + z1 = (a0>>(count & 63)) | (((a0<>((-count) & 63)); +} + +/*---------------------------------------------------------------------------- +| Adds the 192-bit value formed by concatenating `a0', `a1', and `a2' to the +| 192-bit value formed by concatenating `b0', `b1', and `b2'. Addition is +| modulo 2^192, so any carry out is lost. The result is broken into three +| 64-bit pieces which are stored at the locations pointed to by `z0Ptr', +| `z1Ptr', and `z2Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void add192( + Bit64u a0, + Bit64u a1, + Bit64u a2, + Bit64u b0, + Bit64u b1, + Bit64u b2, + Bit64u *z0Ptr, + Bit64u *z1Ptr, + Bit64u *z2Ptr +) +{ + Bit64u z0, z1, z2; + unsigned carry0, carry1; + + z2 = a2 + b2; + carry1 = (z2 < a2); + z1 = a1 + b1; + carry0 = (z1 < a1); + z0 = a0 + b0; + z1 += carry1; + z0 += (z1 < carry1); + z0 += carry0; + *z2Ptr = z2; + *z1Ptr = z1; + *z0Ptr = z0; +} + +/*---------------------------------------------------------------------------- +| Subtracts the 192-bit value formed by concatenating `b0', `b1', and `b2' +| from the 192-bit value formed by concatenating `a0', `a1', and `a2'. +| Subtraction is modulo 2^192, so any borrow out (carry out) is lost. The +| result is broken into three 64-bit pieces which are stored at the locations +| pointed to by `z0Ptr', `z1Ptr', and `z2Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void sub192( + Bit64u a0, + Bit64u a1, + Bit64u a2, + Bit64u b0, + Bit64u b1, + Bit64u b2, + Bit64u *z0Ptr, + Bit64u *z1Ptr, + Bit64u *z2Ptr +) +{ + Bit64u z0, z1, z2; + unsigned borrow0, borrow1; + + z2 = a2 - b2; + borrow1 = (a2 < b2); + z1 = a1 - b1; + borrow0 = (a1 < b1); + z0 = a0 - b0; + z0 -= (z1 < borrow1); + z1 -= borrow1; + z0 -= borrow0; + *z2Ptr = z2; + *z1Ptr = z1; + *z0Ptr = z0; +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' +| is equal to the 128-bit value formed by concatenating `b0' and `b1'. +| Otherwise, returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int eq128(Bit64u a0, Bit64u a1, Bit64u b0, Bit64u b1) +{ + return (a0 == b0) && (a1 == b1); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less +| than or equal to the 128-bit value formed by concatenating `b0' and `b1'. +| Otherwise, returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int le128(Bit64u a0, Bit64u a1, Bit64u b0, Bit64u b1) +{ + return (a0 < b0) || ((a0 == b0) && (a1 <= b1)); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less +| than the 128-bit value formed by concatenating `b0' and `b1'. Otherwise, +| returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int lt128(Bit64u a0, Bit64u a1, Bit64u b0, Bit64u b1) +{ + return (a0 < b0) || ((a0 == b0) && (a1 < b1)); +} + +#endif /* FLOATX80 */ + +/*---------------------------------------------------------------------------- +| Multiplies the 128-bit value formed by concatenating `a0' and `a1' by +| `b' to obtain a 192-bit product. The product is broken into three 64-bit +| pieces which are stored at the locations pointed to by `z0Ptr', `z1Ptr', and +| `z2Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void mul128By64To192( + Bit64u a0, + Bit64u a1, + Bit64u b, + Bit64u *z0Ptr, + Bit64u *z1Ptr, + Bit64u *z2Ptr +) +{ + Bit64u z0, z1, z2, more1; + + mul64To128(a1, b, &z1, &z2); + mul64To128(a0, b, &z0, &more1); + add128(z0, more1, 0, z1, &z0, &z1); + *z2Ptr = z2; + *z1Ptr = z1; + *z0Ptr = z0; +} + +#ifdef FLOAT128 + +/*---------------------------------------------------------------------------- +| Multiplies the 128-bit value formed by concatenating `a0' and `a1' to the +| 128-bit value formed by concatenating `b0' and `b1' to obtain a 256-bit +| product. The product is broken into four 64-bit pieces which are stored at +| the locations pointed to by `z0Ptr', `z1Ptr', `z2Ptr', and `z3Ptr'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void mul128To256( + Bit64u a0, + Bit64u a1, + Bit64u b0, + Bit64u b1, + Bit64u *z0Ptr, + Bit64u *z1Ptr, + Bit64u *z2Ptr, + Bit64u *z3Ptr +) +{ + Bit64u z0, z1, z2, z3; + Bit64u more1, more2; + + mul64To128(a1, b1, &z2, &z3); + mul64To128(a1, b0, &z1, &more2); + add128(z1, more2, 0, z2, &z1, &z2); + mul64To128(a0, b0, &z0, &more1); + add128(z0, more1, 0, z1, &z0, &z1); + mul64To128(a0, b1, &more1, &more2); + add128(more1, more2, 0, z2, &more1, &z2); + add128(z0, z1, 0, more1, &z0, &z1); + *z3Ptr = z3; + *z2Ptr = z2; + *z1Ptr = z1; + *z0Ptr = z0; +} + + +/*---------------------------------------------------------------------------- +| Shifts the 192-bit value formed by concatenating `a0', `a1', and `a2' right +| by 64 _plus_ the number of bits given in `count'. The shifted result is +| at most 128 nonzero bits; these are broken into two 64-bit pieces which are +| stored at the locations pointed to by `z0Ptr' and `z1Ptr'. The bits shifted +| off form a third 64-bit result as follows: The _last_ bit shifted off is +| the most-significant bit of the extra result, and the other 63 bits of the +| extra result are all zero if and only if _all_but_the_last_ bits shifted off +| were all zero. This extra result is stored in the location pointed to by +| `z2Ptr'. The value of `count' can be arbitrarily large. +| (This routine makes more sense if `a0', `a1', and `a2' are considered +| to form a fixed-point value with binary point between `a1' and `a2'. This +| fixed-point value is shifted right by the number of bits given in `count', +| and the integer part of the result is returned at the locations pointed to +| by `z0Ptr' and `z1Ptr'. The fractional part of the result may be slightly +| corrupted as described above, and is returned at the location pointed to by +| `z2Ptr'.) +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void shift128ExtraRightJamming( + Bit64u a0, + Bit64u a1, + Bit64u a2, + int count, + Bit64u *z0Ptr, + Bit64u *z1Ptr, + Bit64u *z2Ptr +) +{ + Bit64u z0, z1, z2; + int negCount = (-count) & 63; + + if (count == 0) { + z2 = a2; + z1 = a1; + z0 = a0; + } + else { + if (count < 64) { + z2 = a1<>count); + z0 = a0>>count; + } + else { + if (count == 64) { + z2 = a1; + z1 = a0; + } + else { + a2 |= a1; + if (count < 128) { + z2 = a0<>(count & 63); + } + else { + z2 = (count == 128) ? a0 : (a0 != 0); + z1 = 0; + } + } + z0 = 0; + } + z2 |= (a2 != 0); + } + *z2Ptr = z2; + *z1Ptr = z1; + *z0Ptr = z0; +} + +#endif /* FLOAT128 */ + +#endif diff --git a/src/cpu/softfloat/softfloat-muladd.cc b/src/cpu/softfloat/softfloat-muladd.cc new file mode 100644 index 000000000..7c9fec70e --- /dev/null +++ b/src/cpu/softfloat/softfloat-muladd.cc @@ -0,0 +1,558 @@ +/*============================================================================ +This C source file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * This code is based on QEMU patch by Peter Maydell + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "softfloat.h" +#include "softfloat-round-pack.h" + +/*---------------------------------------------------------------------------- +| Primitive arithmetic functions, including multi-word arithmetic, and +| division and square root approximations. (Can be specialized to target +| if desired). +*----------------------------------------------------------------------------*/ +#include "softfloat-macros.h" + +/*---------------------------------------------------------------------------- +| Functions and definitions to determine: (1) whether tininess for underflow +| is detected before or after rounding by default, (2) what (if anything) +| happens when exceptions are raised, (3) how signaling NaNs are distinguished +| from quiet NaNs, (4) the default generated quiet NaNs, and (5) how NaNs +| are propagated from function inputs to output. These details are target- +| specific. +*----------------------------------------------------------------------------*/ +#include "softfloat-specialize.h" + +/*---------------------------------------------------------------------------- +| Takes three single-precision floating-point values `a', `b' and `c', one of +| which is a NaN, and returns the appropriate NaN result. If any of `a', +| `b' or `c' is a signaling NaN, the invalid exception is raised. +| The input infzero indicates whether a*b was 0*inf or inf*0 (in which case +| obviously c is a NaN, and whether to propagate c or some other NaN is +| implementation defined). +*----------------------------------------------------------------------------*/ + +static float32 propagateFloat32MulAddNaN(float32 a, float32 b, float32 c, struct float_status_t *status) +{ + int aIsNaN = float32_is_nan(a); + int bIsNaN = float32_is_nan(b); + + int aIsSignalingNaN = float32_is_signaling_nan(a); + int bIsSignalingNaN = float32_is_signaling_nan(b); + int cIsSignalingNaN = float32_is_signaling_nan(c); + + a |= 0x00400000; + b |= 0x00400000; + c |= 0x00400000; + + if (aIsSignalingNaN | bIsSignalingNaN | cIsSignalingNaN) + float_raise(status, float_flag_invalid); + + // operate according to float_first_operand_nan mode + if (aIsSignalingNaN | aIsNaN) { + return a; + } + else { + return (bIsSignalingNaN | bIsNaN) ? b : c; + } +} + +/*---------------------------------------------------------------------------- +| Takes three double-precision floating-point values `a', `b' and `c', one of +| which is a NaN, and returns the appropriate NaN result. If any of `a', +| `b' or `c' is a signaling NaN, the invalid exception is raised. +| The input infzero indicates whether a*b was 0*inf or inf*0 (in which case +| obviously c is a NaN, and whether to propagate c or some other NaN is +| implementation defined). +*----------------------------------------------------------------------------*/ + +static float64 propagateFloat64MulAddNaN(float64 a, float64 b, float64 c, struct float_status_t *status) +{ + int aIsNaN = float64_is_nan(a); + int bIsNaN = float64_is_nan(b); + + int aIsSignalingNaN = float64_is_signaling_nan(a); + int bIsSignalingNaN = float64_is_signaling_nan(b); + int cIsSignalingNaN = float64_is_signaling_nan(c); + + a |= BX_CONST64(0x0008000000000000); + b |= BX_CONST64(0x0008000000000000); + c |= BX_CONST64(0x0008000000000000); + + if (aIsSignalingNaN | bIsSignalingNaN | cIsSignalingNaN) + float_raise(status, float_flag_invalid); + + // operate according to float_first_operand_nan mode + if (aIsSignalingNaN | aIsNaN) { + return a; + } + else { + return (bIsSignalingNaN | bIsNaN) ? b : c; + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of multiplying the single-precision floating-point values +| `a' and `b' then adding 'c', with no intermediate rounding step after the +| multiplication. The operation is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic 754-2008. +| The flags argument allows the caller to select negation of the +| addend, the intermediate product, or the final result. (The difference +| between this and having the caller do a separate negation is that negating +| externally will flip the sign bit on NaNs.) +*----------------------------------------------------------------------------*/ + +float32 float32_muladd(float32 a, float32 b, float32 c, int flags, struct float_status_t *status) +{ + int aSign, bSign, cSign, zSign; + Bit16s aExp, bExp, cExp, pExp, zExp; + Bit32u aSig, bSig, cSig; + int pInf, pZero, pSign; + Bit64u pSig64, cSig64, zSig64; + Bit32u pSig; + int shiftcount; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + bSig = extractFloat32Frac(b); + bExp = extractFloat32Exp(b); + bSign = extractFloat32Sign(b); + cSig = extractFloat32Frac(c); + cExp = extractFloat32Exp(c); + cSign = extractFloat32Sign(c); + + /* It is implementation-defined whether the cases of (0,inf,qnan) + * and (inf,0,qnan) raise InvalidOperation or not (and what QNaN + * they return if they do), so we have to hand this information + * off to the target-specific pick-a-NaN routine. + */ + if (((aExp == 0xff) && aSig) || + ((bExp == 0xff) && bSig) || + ((cExp == 0xff) && cSig)) { + return propagateFloat32MulAddNaN(a, b, c, status); + } + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + if (cExp == 0) cSig = 0; + } + + int infzero = ((aExp == 0 && aSig == 0 && bExp == 0xff && bSig == 0) || + (aExp == 0xff && aSig == 0 && bExp == 0 && bSig == 0)); + + if (infzero) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + + if (flags & float_muladd_negate_c) { + cSign ^= 1; + } + + /* Work out the sign and type of the product */ + pSign = aSign ^ bSign; + if (flags & float_muladd_negate_product) { + pSign ^= 1; + } + pInf = (aExp == 0xff) || (bExp == 0xff); + pZero = ((aExp | aSig) == 0) || ((bExp | bSig) == 0); + + if (cExp == 0xff) { + if (pInf && (pSign ^ cSign)) { + /* addition of opposite-signed infinities => InvalidOperation */ + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + /* Otherwise generate an infinity of the same sign */ + if ((aSig && aExp == 0) || (bSig && bExp == 0)) { + float_raise(status, float_flag_denormal); + } + return packFloat32(cSign, 0xff, 0); + } + + if (pInf) { + if ((aSig && aExp == 0) || (bSig && bExp == 0) || (cSig && cExp == 0)) { + float_raise(status, float_flag_denormal); + } + return packFloat32(pSign, 0xff, 0); + } + + if (pZero) { + if (cExp == 0) { + if (cSig == 0) { + /* Adding two exact zeroes */ + if (pSign == cSign) { + zSign = pSign; + } else if (get_float_rounding_mode(status) == float_round_down) { + zSign = 1; + } else { + zSign = 0; + } + return packFloat32(zSign, 0, 0); + } + /* Exact zero plus a denormal */ + float_raise(status, float_flag_denormal); + if (get_flush_underflow_to_zero(status)) { + float_raise(status, float_flag_underflow | float_flag_inexact); + return packFloat32(cSign, 0, 0); + } + } + /* Zero plus something non-zero */ + return packFloat32(cSign, cExp, cSig); + } + + if (aExp == 0) { + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(bSig, &bExp, &bSig); + } + + /* Calculate the actual result a * b + c */ + + /* Multiply first; this is easy. */ + /* NB: we subtract 0x7e where float32_mul() subtracts 0x7f + * because we want the true exponent, not the "one-less-than" + * flavour that roundAndPackFloat32() takes. + */ + pExp = aExp + bExp - 0x7e; + aSig = (aSig | 0x00800000) << 7; + bSig = (bSig | 0x00800000) << 8; + pSig64 = (Bit64u)aSig * bSig; + if ((Bit64s)(pSig64 << 1) >= 0) { + pSig64 <<= 1; + pExp--; + } + + zSign = pSign; + + /* Now pSig64 is the significand of the multiply, with the explicit bit in + * position 62. + */ + if (cExp == 0) { + if (!cSig) { + /* Throw out the special case of c being an exact zero now */ + pSig = (Bit32u) shift64RightJamming(pSig64, 32); + return roundAndPackFloat32(zSign, pExp - 1, pSig, status); + } + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(cSig, &cExp, &cSig); + } + + cSig64 = (Bit64u)cSig << 39; + cSig64 |= BX_CONST64(0x4000000000000000); + int expDiff = pExp - cExp; + + if (pSign == cSign) { + /* Addition */ + if (expDiff > 0) { + /* scale c to match p */ + cSig64 = shift64RightJamming(cSig64, expDiff); + zExp = pExp; + } else if (expDiff < 0) { + /* scale p to match c */ + pSig64 = shift64RightJamming(pSig64, -expDiff); + zExp = cExp; + } else { + /* no scaling needed */ + zExp = cExp; + } + /* Add significands and make sure explicit bit ends up in posn 62 */ + zSig64 = pSig64 + cSig64; + if ((Bit64s)zSig64 < 0) { + zSig64 = shift64RightJamming(zSig64, 1); + } else { + zExp--; + } + zSig64 = shift64RightJamming(zSig64, 32); + return roundAndPackFloat32(zSign, zExp, zSig64, status); + } else { + /* Subtraction */ + if (expDiff > 0) { + cSig64 = shift64RightJamming(cSig64, expDiff); + zSig64 = pSig64 - cSig64; + zExp = pExp; + } else if (expDiff < 0) { + pSig64 = shift64RightJamming(pSig64, -expDiff); + zSig64 = cSig64 - pSig64; + zExp = cExp; + zSign ^= 1; + } else { + zExp = pExp; + if (cSig64 < pSig64) { + zSig64 = pSig64 - cSig64; + } else if (pSig64 < cSig64) { + zSig64 = cSig64 - pSig64; + zSign ^= 1; + } else { + /* Exact zero */ + return packFloat32(get_float_rounding_mode(status) == float_round_down, 0, 0); + } + } + --zExp; + /* Do the equivalent of normalizeRoundAndPackFloat32() but + * starting with the significand in a Bit64u. + */ + shiftcount = countLeadingZeros64(zSig64) - 1; + zSig64 <<= shiftcount; + zExp -= shiftcount; + zSig64 = shift64RightJamming(zSig64, 32); + return roundAndPackFloat32(zSign, zExp, zSig64, status); + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of multiplying the double-precision floating-point values +| `a' and `b' then adding 'c', with no intermediate rounding step after the +| multiplication. The operation is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic 754-2008. +| The flags argument allows the caller to select negation of the +| addend, the intermediate product, or the final result. (The difference +| between this and having the caller do a separate negation is that negating +| externally will flip the sign bit on NaNs.) +*----------------------------------------------------------------------------*/ + +float64 float64_muladd(float64 a, float64 b, float64 c, int flags, struct float_status_t *status) +{ + int aSign, bSign, cSign, zSign; + Bit16s aExp, bExp, cExp, pExp, zExp; + Bit64u aSig, bSig, cSig; + int pInf, pZero, pSign; + Bit64u pSig0, pSig1, cSig0, cSig1, zSig0, zSig1; + int shiftcount; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + bSig = extractFloat64Frac(b); + bExp = extractFloat64Exp(b); + bSign = extractFloat64Sign(b); + cSig = extractFloat64Frac(c); + cExp = extractFloat64Exp(c); + cSign = extractFloat64Sign(c); + + /* It is implementation-defined whether the cases of (0,inf,qnan) + * and (inf,0,qnan) raise InvalidOperation or not (and what QNaN + * they return if they do), so we have to hand this information + * off to the target-specific pick-a-NaN routine. + */ + if (((aExp == 0x7ff) && aSig) || + ((bExp == 0x7ff) && bSig) || + ((cExp == 0x7ff) && cSig)) { + return propagateFloat64MulAddNaN(a, b, c, status); + } + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + if (cExp == 0) cSig = 0; + } + + int infzero = ((aExp == 0 && aSig == 0 && bExp == 0x7ff && bSig == 0) || + (aExp == 0x7ff && aSig == 0 && bExp == 0 && bSig == 0)); + + if (infzero) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + + if (flags & float_muladd_negate_c) { + cSign ^= 1; + } + + /* Work out the sign and type of the product */ + pSign = aSign ^ bSign; + if (flags & float_muladd_negate_product) { + pSign ^= 1; + } + pInf = (aExp == 0x7ff) || (bExp == 0x7ff); + pZero = ((aExp | aSig) == 0) || ((bExp | bSig) == 0); + + if (cExp == 0x7ff) { + if (pInf && (pSign ^ cSign)) { + /* addition of opposite-signed infinities => InvalidOperation */ + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + /* Otherwise generate an infinity of the same sign */ + if ((aSig && aExp == 0) || (bSig && bExp == 0)) { + float_raise(status, float_flag_denormal); + } + return packFloat64(cSign, 0x7ff, 0); + } + + if (pInf) { + if ((aSig && aExp == 0) || (bSig && bExp == 0) || (cSig && cExp == 0)) { + float_raise(status, float_flag_denormal); + } + return packFloat64(pSign, 0x7ff, 0); + } + + if (pZero) { + if (cExp == 0) { + if (cSig == 0) { + /* Adding two exact zeroes */ + if (pSign == cSign) { + zSign = pSign; + } else if (get_float_rounding_mode(status) == float_round_down) { + zSign = 1; + } else { + zSign = 0; + } + return packFloat64(zSign, 0, 0); + } + /* Exact zero plus a denormal */ + float_raise(status, float_flag_denormal); + if (get_flush_underflow_to_zero(status)) { + float_raise(status, float_flag_underflow | float_flag_inexact); + return packFloat64(cSign, 0, 0); + } + } + /* Zero plus something non-zero */ + return packFloat64(cSign, cExp, cSig); + } + + if (aExp == 0) { + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(bSig, &bExp, &bSig); + } + + /* Calculate the actual result a * b + c */ + + /* Multiply first; this is easy. */ + /* NB: we subtract 0x3fe where float64_mul() subtracts 0x3ff + * because we want the true exponent, not the "one-less-than" + * flavour that roundAndPackFloat64() takes. + */ + pExp = aExp + bExp - 0x3fe; + aSig = (aSig | BX_CONST64(0x0010000000000000))<<10; + bSig = (bSig | BX_CONST64(0x0010000000000000))<<11; + mul64To128(aSig, bSig, &pSig0, &pSig1); + if ((Bit64s)(pSig0 << 1) >= 0) { + shortShift128Left(pSig0, pSig1, 1, &pSig0, &pSig1); + pExp--; + } + + zSign = pSign; + + /* Now [pSig0:pSig1] is the significand of the multiply, with the explicit + * bit in position 126. + */ + if (cExp == 0) { + if (!cSig) { + /* Throw out the special case of c being an exact zero now */ + shift128RightJamming(pSig0, pSig1, 64, &pSig0, &pSig1); + return roundAndPackFloat64(zSign, pExp - 1, pSig1, status); + } + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(cSig, &cExp, &cSig); + } + + cSig0 = cSig << 10; + cSig1 = 0; + cSig0 |= BX_CONST64(0x4000000000000000); + int expDiff = pExp - cExp; + + if (pSign == cSign) { + /* Addition */ + if (expDiff > 0) { + /* scale c to match p */ + shift128RightJamming(cSig0, cSig1, expDiff, &cSig0, &cSig1); + zExp = pExp; + } else if (expDiff < 0) { + /* scale p to match c */ + shift128RightJamming(pSig0, pSig1, -expDiff, &pSig0, &pSig1); + zExp = cExp; + } else { + /* no scaling needed */ + zExp = cExp; + } + /* Add significands and make sure explicit bit ends up in posn 126 */ + add128(pSig0, pSig1, cSig0, cSig1, &zSig0, &zSig1); + if ((Bit64s)zSig0 < 0) { + shift128RightJamming(zSig0, zSig1, 1, &zSig0, &zSig1); + } else { + zExp--; + } + shift128RightJamming(zSig0, zSig1, 64, &zSig0, &zSig1); + return roundAndPackFloat64(zSign, zExp, zSig1, status); + } else { + /* Subtraction */ + if (expDiff > 0) { + shift128RightJamming(cSig0, cSig1, expDiff, &cSig0, &cSig1); + sub128(pSig0, pSig1, cSig0, cSig1, &zSig0, &zSig1); + zExp = pExp; + } else if (expDiff < 0) { + shift128RightJamming(pSig0, pSig1, -expDiff, &pSig0, &pSig1); + sub128(cSig0, cSig1, pSig0, pSig1, &zSig0, &zSig1); + zExp = cExp; + zSign ^= 1; + } else { + zExp = pExp; + if (lt128(cSig0, cSig1, pSig0, pSig1)) { + sub128(pSig0, pSig1, cSig0, cSig1, &zSig0, &zSig1); + } else if (lt128(pSig0, pSig1, cSig0, cSig1)) { + sub128(cSig0, cSig1, pSig0, pSig1, &zSig0, &zSig1); + zSign ^= 1; + } else { + /* Exact zero */ + return packFloat64(get_float_rounding_mode(status) == float_round_down, 0, 0); + } + } + --zExp; + /* Do the equivalent of normalizeRoundAndPackFloat64() but + * starting with the significand in a pair of Bit64u. + */ + if (zSig0) { + shiftcount = countLeadingZeros64(zSig0) - 1; + shortShift128Left(zSig0, zSig1, shiftcount, &zSig0, &zSig1); + if (zSig1) { + zSig0 |= 1; + } + zExp -= shiftcount; + } else { + shiftcount = countLeadingZeros64(zSig1) - 1; + zSig0 = zSig1 << shiftcount; + zExp -= (shiftcount + 64); + } + return roundAndPackFloat64(zSign, zExp, zSig0, status); + } +} diff --git a/src/cpu/softfloat/softfloat-round-pack.cc b/src/cpu/softfloat/softfloat-round-pack.cc new file mode 100644 index 000000000..2b3965840 --- /dev/null +++ b/src/cpu/softfloat/softfloat-round-pack.cc @@ -0,0 +1,896 @@ +/*============================================================================ +This C source file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +#define FLOAT128 + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "softfloat.h" +#include "softfloat-round-pack.h" + +/*---------------------------------------------------------------------------- +| Primitive arithmetic functions, including multi-word arithmetic, and +| division and square root approximations. (Can be specialized to target +| if desired). +*----------------------------------------------------------------------------*/ +#include "softfloat-macros.h" + +/*---------------------------------------------------------------------------- +| Functions and definitions to determine: (1) whether tininess for underflow +| is detected before or after rounding by default, (2) what (if anything) +| happens when exceptions are raised, (3) how signaling NaNs are distinguished +| from quiet NaNs, (4) the default generated quiet NaNs, and (5) how NaNs +| are propagated from function inputs to output. These details are target- +| specific. +*----------------------------------------------------------------------------*/ +#include "softfloat-specialize.h" + +/*---------------------------------------------------------------------------- +| Takes a 64-bit fixed-point value `absZ' with binary point between bits 6 +| and 7, and returns the properly rounded 32-bit integer corresponding to the +| input. If `zSign' is 1, the input is negated before being converted to an +| integer. Bit 63 of `absZ' must be zero. Ordinarily, the fixed-point input +| is simply rounded to an integer, with the inexact exception raised if the +| input cannot be represented exactly as an integer. However, if the fixed- +| point input is too large, the invalid exception is raised and the integer +| indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit32s roundAndPackInt32(int zSign, Bit64u exactAbsZ, struct float_status_t *status) +{ + int roundingMode = get_float_rounding_mode(status); + int roundNearestEven = (roundingMode == float_round_nearest_even); + int roundIncrement = 0x40; + if (! roundNearestEven) { + if (roundingMode == float_round_to_zero) roundIncrement = 0; + else { + roundIncrement = 0x7F; + if (zSign) { + if (roundingMode == float_round_up) roundIncrement = 0; + } + else { + if (roundingMode == float_round_down) roundIncrement = 0; + } + } + } + int roundBits = (int)(exactAbsZ & 0x7F); + Bit64u absZ = (exactAbsZ + roundIncrement)>>7; + absZ &= ~(((roundBits ^ 0x40) == 0) & roundNearestEven); + Bit32s z = (Bit32s) absZ; + if (zSign) z = -z; + if ((absZ>>32) || (z && ((z < 0) ^ zSign))) { + float_raise(status, float_flag_invalid); + return (Bit32s)(int32_indefinite); + } + if (roundBits) { + float_raise(status, float_flag_inexact); + if ((absZ << 7) > exactAbsZ) + set_float_rounding_up(status); + } + return z; +} + +/*---------------------------------------------------------------------------- +| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and +| `absZ1', with binary point between bits 63 and 64 (between the input words), +| and returns the properly rounded 64-bit integer corresponding to the input. +| If `zSign' is 1, the input is negated before being converted to an integer. +| Ordinarily, the fixed-point input is simply rounded to an integer, with +| the inexact exception raised if the input cannot be represented exactly as +| an integer. However, if the fixed-point input is too large, the invalid +| exception is raised and the integer indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit64s roundAndPackInt64(int zSign, Bit64u absZ0, Bit64u absZ1, struct float_status_t *status) +{ + Bit64s z; + int roundingMode = get_float_rounding_mode(status); + int roundNearestEven = (roundingMode == float_round_nearest_even); + int increment = ((Bit64s) absZ1 < 0); + if (! roundNearestEven) { + if (roundingMode == float_round_to_zero) increment = 0; + else { + if (zSign) { + increment = (roundingMode == float_round_down) && absZ1; + } + else { + increment = (roundingMode == float_round_up) && absZ1; + } + } + } + Bit64u exactAbsZ0 = absZ0; + if (increment) { + ++absZ0; + if (absZ0 == 0) goto overflow; + absZ0 &= ~(((Bit64u) (absZ1<<1) == 0) & roundNearestEven); + } + z = absZ0; + if (zSign) z = -z; + if (z && ((z < 0) ^ zSign)) { + overflow: + float_raise(status, float_flag_invalid); + return (Bit64s)(int64_indefinite); + } + if (absZ1) { + float_raise(status, float_flag_inexact); + if (absZ0 > exactAbsZ0) + set_float_rounding_up(status); + } + return z; +} + +/*---------------------------------------------------------------------------- +| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and +| `absZ1', with binary point between bits 63 and 64 (between the input words), +| and returns the properly rounded 64-bit unsigned integer corresponding to the +| input. Ordinarily, the fixed-point input is simply rounded to an integer, +| with the inexact exception raised if the input cannot be represented exactly +| as an integer. However, if the fixed-point input is too large, the invalid +| exception is raised and the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit64u roundAndPackUint64(int zSign, Bit64u absZ0, Bit64u absZ1, struct float_status_t *status) +{ + int roundingMode = get_float_rounding_mode(status); + int roundNearestEven = (roundingMode == float_round_nearest_even); + int increment = ((Bit64s) absZ1 < 0); + if (!roundNearestEven) { + if (roundingMode == float_round_to_zero) { + increment = 0; + } else if (absZ1) { + if (zSign) { + increment = (roundingMode == float_round_down) && absZ1; + } else { + increment = (roundingMode == float_round_up) && absZ1; + } + } + } + if (increment) { + ++absZ0; + if (absZ0 == 0) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + absZ0 &= ~(((Bit64u) (absZ1<<1) == 0) & roundNearestEven); + } + + if (zSign && absZ0) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + + if (absZ1) { + float_raise(status, float_flag_inexact); + } + return absZ0; +} + +#ifdef FLOAT16 + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal half-precision floating-point value represented +| by the denormalized significand `aSig'. The normalized exponent and +| significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ + +void normalizeFloat16Subnormal(Bit16u aSig, Bit16s *zExpPtr, Bit16u *zSigPtr) +{ + int shiftCount = countLeadingZeros16(aSig) - 5; + *zSigPtr = aSig<> 4; + zSigRound &= ~(((roundBits ^ 0x10) == 0) & roundNearestEven); + if (zSigRound == 0) zExp = 0; + return packFloat16(zSign, zExp, zSigRound); +} + +#endif + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal single-precision floating-point value represented +| by the denormalized significand `aSig'. The normalized exponent and +| significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ + +void normalizeFloat32Subnormal(Bit32u aSig, Bit16s *zExpPtr, Bit32u *zSigPtr) +{ + int shiftCount = countLeadingZeros32(aSig) - 8; + *zSigPtr = aSig<> 7; + zSigRound &= ~(((roundBits ^ 0x40) == 0) & roundNearestEven); + if (zSigRound == 0) zExp = 0; + if (roundBits) { + float_raise(status, float_flag_inexact); + if ((zSigRound << 7) > zSig) set_float_rounding_up(status); + } + return packFloat32(zSign, zExp, zSigRound); +} + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper single-precision floating- +| point value corresponding to the abstract input. This routine is just like +| `roundAndPackFloat32' except that `zSig' does not have to be normalized. +| Bit 31 of `zSig' must be zero, and `zExp' must be 1 less than the ``true'' +| floating-point exponent. +*----------------------------------------------------------------------------*/ + +float32 normalizeRoundAndPackFloat32(int zSign, Bit16s zExp, Bit32u zSig, struct float_status_t *status) +{ + int shiftCount = countLeadingZeros32(zSig) - 1; + return roundAndPackFloat32(zSign, zExp - shiftCount, zSig<>10; + zSigRound &= ~(((roundBits ^ 0x200) == 0) & roundNearestEven); + if (zSigRound == 0) zExp = 0; + if (roundBits) { + float_raise(status, float_flag_inexact); + if ((zSigRound << 10) > zSig) set_float_rounding_up(status); + } + return packFloat64(zSign, zExp, zSigRound); +} + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper double-precision floating- +| point value corresponding to the abstract input. This routine is just like +| `roundAndPackFloat64' except that `zSig' does not have to be normalized. +| Bit 63 of `zSig' must be zero, and `zExp' must be 1 less than the ``true'' +| floating-point exponent. +*----------------------------------------------------------------------------*/ + +float64 normalizeRoundAndPackFloat64(int zSign, Bit16s zExp, Bit64u zSig, struct float_status_t *status) +{ + int shiftCount = countLeadingZeros64(zSig) - 1; + return roundAndPackFloat64(zSign, zExp - shiftCount, zSig< zSigExact) set_float_rounding_up(status); + } + return packFloatx80(zSign, zExp, zSig0); + } + } + if (roundBits) float_raise(status, float_flag_inexact); + zSigExact = zSig0; + zSig0 += roundIncrement; + if (zSig0 < roundIncrement) { + // Basically scale by shifting right and keep overflow + ++zExp; + zSig0 = BX_CONST64(0x8000000000000000); + zSigExact >>= 1; // must scale also, or else later tests will fail + } + roundIncrement = roundMask + 1; + if (roundNearestEven && (roundBits<<1 == roundIncrement)) + roundMask |= roundIncrement; + zSig0 &= ~roundMask; + if (zSig0 > zSigExact) set_float_rounding_up(status); + if (zSig0 == 0) zExp = 0; + return packFloatx80(zSign, zExp, zSig0); + precision80: + increment = ((Bit64s) zSig1 < 0); + if (! roundNearestEven) { + if (roundingMode == float_round_to_zero) increment = 0; + else { + if (zSign) { + increment = (roundingMode == float_round_down) && zSig1; + } + else { + increment = (roundingMode == float_round_up) && zSig1; + } + } + } + if (0x7FFD <= (Bit32u) (zExp - 1)) { + if ((0x7FFE < zExp) + || ((zExp == 0x7FFE) + && (zSig0 == BX_CONST64(0xFFFFFFFFFFFFFFFF)) + && increment)) + { + roundMask = 0; + overflow: + float_raise(status, float_flag_overflow | float_flag_inexact); + if ((roundingMode == float_round_to_zero) + || (zSign && (roundingMode == float_round_up)) + || (! zSign && (roundingMode == float_round_down))) + { + return packFloatx80(zSign, 0x7FFE, ~roundMask); + } + set_float_rounding_up(status); + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (zExp <= 0) { + int isTiny = (zExp < 0) || (! increment) + || (zSig0 < BX_CONST64(0xFFFFFFFFFFFFFFFF)); + shift64ExtraRightJamming(zSig0, zSig1, 1 - zExp, &zSig0, &zSig1); + zExp = 0; + if (isTiny) { + if (zSig1 || (zSig0 && !float_exception_masked(status, float_flag_underflow))) + float_raise(status, float_flag_underflow); + } + if (zSig1) float_raise(status, float_flag_inexact); + if (roundNearestEven) increment = ((Bit64s) zSig1 < 0); + else { + if (zSign) { + increment = (roundingMode == float_round_down) && zSig1; + } else { + increment = (roundingMode == float_round_up) && zSig1; + } + } + if (increment) { + zSigExact = zSig0++; + zSig0 &= ~(((Bit64u) (zSig1<<1) == 0) & roundNearestEven); + if (zSig0 > zSigExact) set_float_rounding_up(status); + if ((Bit64s) zSig0 < 0) zExp = 1; + } + return packFloatx80(zSign, zExp, zSig0); + } + } + if (zSig1) float_raise(status, float_flag_inexact); + if (increment) { + zSigExact = zSig0++; + if (zSig0 == 0) { + zExp++; + zSig0 = BX_CONST64(0x8000000000000000); + zSigExact >>= 1; // must scale also, or else later tests will fail + } + else { + zSig0 &= ~(((Bit64u) (zSig1<<1) == 0) & roundNearestEven); + } + if (zSig0 > zSigExact) set_float_rounding_up(status); + } + else { + if (zSig0 == 0) zExp = 0; + } + return packFloatx80(zSign, zExp, zSig0); +} + +floatx80 roundAndPackFloatx80(int roundingPrecision, + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, struct float_status_t *status) +{ + struct float_status_t *round_status = status; + floatx80 result = SoftFloatRoundAndPackFloatx80(roundingPrecision, zSign, zExp, zSig0, zSig1, status); + + // bias unmasked undeflow + if (status->float_exception_flags & ~status->float_exception_masks & float_flag_underflow) { + float_raise(round_status, float_flag_underflow); + return SoftFloatRoundAndPackFloatx80(roundingPrecision, zSign, zExp + 0x6000, zSig0, zSig1, status = round_status); + } + + // bias unmasked overflow + if (status->float_exception_flags & ~status->float_exception_masks & float_flag_overflow) { + float_raise(round_status, float_flag_overflow); + return SoftFloatRoundAndPackFloatx80(roundingPrecision, zSign, zExp - 0x6000, zSig0, zSig1, status = round_status); + } + + return result; +} + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent +| `zExp', and significand formed by the concatenation of `zSig0' and `zSig1', +| and returns the proper extended double-precision floating-point value +| corresponding to the abstract input. This routine is just like +| `roundAndPackFloatx80' except that the input significand does not have to be +| normalized. +*----------------------------------------------------------------------------*/ + +floatx80 normalizeRoundAndPackFloatx80(int roundingPrecision, + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, struct float_status_t *status) +{ + if (zSig0 == 0) { + zSig0 = zSig1; + zSig1 = 0; + zExp -= 64; + } + int shiftCount = countLeadingZeros64(zSig0); + shortShift128Left(zSig0, zSig1, shiftCount, &zSig0, &zSig1); + zExp -= shiftCount; + return + roundAndPackFloatx80(roundingPrecision, zSign, zExp, zSig0, zSig1, status); +} + +#endif + +#ifdef FLOAT128 + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal quadruple-precision floating-point value +| represented by the denormalized significand formed by the concatenation of +| `aSig0' and `aSig1'. The normalized exponent is stored at the location +| pointed to by `zExpPtr'. The most significant 49 bits of the normalized +| significand are stored at the location pointed to by `zSig0Ptr', and the +| least significant 64 bits of the normalized significand are stored at the +| location pointed to by `zSig1Ptr'. +*----------------------------------------------------------------------------*/ + +void normalizeFloat128Subnormal( + Bit64u aSig0, Bit64u aSig1, Bit32s *zExpPtr, Bit64u *zSig0Ptr, Bit64u *zSig1Ptr) +{ + int shiftCount; + + if (aSig0 == 0) { + shiftCount = countLeadingZeros64(aSig1) - 15; + if (shiftCount < 0) { + *zSig0Ptr = aSig1 >>(-shiftCount); + *zSig1Ptr = aSig1 << (shiftCount & 63); + } + else { + *zSig0Ptr = aSig1 << shiftCount; + *zSig1Ptr = 0; + } + *zExpPtr = - shiftCount - 63; + } + else { + shiftCount = countLeadingZeros64(aSig0) - 15; + shortShift128Left(aSig0, aSig1, shiftCount, zSig0Ptr, zSig1Ptr); + *zExpPtr = 1 - shiftCount; + } +} + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and extended significand formed by the concatenation of `zSig0', `zSig1', +| and `zSig2', and returns the proper quadruple-precision floating-point value +| corresponding to the abstract input. Ordinarily, the abstract value is +| simply rounded and packed into the quadruple-precision format, with the +| inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded to +| a subnormal number, and the underflow and inexact exceptions are raised if +| the abstract input cannot be represented exactly as a subnormal quadruple- +| precision floating-point number. +| The input significand must be normalized or smaller. If the input +| significand is not normalized, `zExp' must be 0; in that case, the result +| returned is a subnormal number, and it must not require rounding. In the +| usual case that the input significand is normalized, `zExp' must be 1 less +| than the ``true'' floating-point exponent. The handling of underflow and +| overflow follows the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 roundAndPackFloat128( + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, Bit64u zSig2, struct float_status_t *status) +{ + int increment = ((Bit64s) zSig2 < 0); + if (0x7FFD <= (Bit32u) zExp) { + if ((0x7FFD < zExp) + || ((zExp == 0x7FFD) + && eq128(BX_CONST64(0x0001FFFFFFFFFFFF), + BX_CONST64(0xFFFFFFFFFFFFFFFF), zSig0, zSig1) + && increment)) + { + float_raise(status, float_flag_overflow | float_flag_inexact); + return packFloat128Four(zSign, 0x7FFF, 0, 0); + } + if (zExp < 0) { + int isTiny = (zExp < -1) + || ! increment + || lt128(zSig0, zSig1, + BX_CONST64(0x0001FFFFFFFFFFFF), + BX_CONST64(0xFFFFFFFFFFFFFFFF)); + shift128ExtraRightJamming( + zSig0, zSig1, zSig2, -zExp, &zSig0, &zSig1, &zSig2); + zExp = 0; + if (isTiny && zSig2) float_raise(status, float_flag_underflow); + increment = ((Bit64s) zSig2 < 0); + } + } + if (zSig2) float_raise(status, float_flag_inexact); + if (increment) { + add128(zSig0, zSig1, 0, 1, &zSig0, &zSig1); + zSig1 &= ~((zSig2 + zSig2 == 0) & 1); + } + else { + if ((zSig0 | zSig1) == 0) zExp = 0; + } + return packFloat128Four(zSign, zExp, zSig0, zSig1); +} + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand formed by the concatenation of `zSig0' and `zSig1', and +| returns the proper quadruple-precision floating-point value corresponding +| to the abstract input. This routine is just like `roundAndPackFloat128' +| except that the input significand has fewer bits and does not have to be +| normalized. In all cases, `zExp' must be 1 less than the ``true'' floating- +| point exponent. +*----------------------------------------------------------------------------*/ + +float128 normalizeRoundAndPackFloat128( + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, struct float_status_t *status) +{ + Bit64u zSig2; + + if (zSig0 == 0) { + zSig0 = zSig1; + zSig1 = 0; + zExp -= 64; + } + int shiftCount = countLeadingZeros64(zSig0) - 15; + if (0 <= shiftCount) { + zSig2 = 0; + shortShift128Left(zSig0, zSig1, shiftCount, &zSig0, &zSig1); + } + else { + shift128ExtraRightJamming( + zSig0, zSig1, 0, -shiftCount, &zSig0, &zSig1, &zSig2); + } + zExp -= shiftCount; + return roundAndPackFloat128(zSign, zExp, zSig0, zSig1, zSig2, status); +} + +#endif diff --git a/src/cpu/softfloat/softfloat-round-pack.h b/src/cpu/softfloat/softfloat-round-pack.h new file mode 100644 index 000000000..1422aaea6 --- /dev/null +++ b/src/cpu/softfloat/softfloat-round-pack.h @@ -0,0 +1,309 @@ +/*============================================================================ +This C source file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#ifndef _SOFTFLOAT_ROUND_PACK_H_ +#define _SOFTFLOAT_ROUND_PACK_H_ + +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Takes a 64-bit fixed-point value `absZ' with binary point between bits 6 +| and 7, and returns the properly rounded 32-bit integer corresponding to the +| input. If `zSign' is 1, the input is negated before being converted to an +| integer. Bit 63 of `absZ' must be zero. Ordinarily, the fixed-point input +| is simply rounded to an integer, with the inexact exception raised if the +| input cannot be represented exactly as an integer. However, if the fixed- +| point input is too large, the invalid exception is raised and the integer +| indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit32s roundAndPackInt32(int zSign, Bit64u absZ, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and +| `absZ1', with binary point between bits 63 and 64 (between the input words), +| and returns the properly rounded 64-bit integer corresponding to the input. +| If `zSign' is 1, the input is negated before being converted to an integer. +| Ordinarily, the fixed-point input is simply rounded to an integer, with +| the inexact exception raised if the input cannot be represented exactly as +| an integer. However, if the fixed-point input is too large, the invalid +| exception is raised and the integer indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit64s roundAndPackInt64(int zSign, Bit64u absZ0, Bit64u absZ1, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and +| `absZ1', with binary point between bits 63 and 64 (between the input words), +| and returns the properly rounded 64-bit unsigned integer corresponding to the +| input. Ordinarily, the fixed-point input is simply rounded to an integer, +| with the inexact exception raised if the input cannot be represented exactly +| as an integer. However, if the fixed-point input is too large, the invalid +| exception is raised and the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit64u roundAndPackUint64(int zSign, Bit64u absZ0, Bit64u absZ1, struct float_status_t *status); + +#ifdef FLOAT16 + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal half-precision floating-point value represented +| by the denormalized significand `aSig'. The normalized exponent and +| significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ + +void normalizeFloat16Subnormal(Bit16u aSig, Bit16s *zExpPtr, Bit16u *zSigPtr); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper half-precision floating- +| point value corresponding to the abstract input. Ordinarily, the abstract +| value is simply rounded and packed into the half-precision format, with +| the inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded to +| a subnormal number, and the underflow and inexact exceptions are raised if +| the abstract input cannot be represented exactly as a subnormal single- +| precision floating-point number. +| The input significand `zSig' has its binary point between bits 14 +| and 13, which is 4 bits to the left of the usual location. This shifted +| significand must be normalized or smaller. If `zSig' is not normalized, +| `zExp' must be 0; in that case, the result returned is a subnormal number, +| and it must not require rounding. In the usual case that `zSig' is +| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent. +| The handling of underflow and overflow follows the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float16 roundAndPackFloat16(int zSign, Bit16s zExp, Bit16u zSig, struct float_status_t *status); + +#endif + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal single-precision floating-point value represented +| by the denormalized significand `aSig'. The normalized exponent and +| significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ + +void normalizeFloat32Subnormal(Bit32u aSig, Bit16s *zExpPtr, Bit32u *zSigPtr); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper single-precision floating- +| point value corresponding to the abstract input. Ordinarily, the abstract +| value is simply rounded and packed into the single-precision format, with +| the inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded to +| a subnormal number, and the underflow and inexact exceptions are raised if +| the abstract input cannot be represented exactly as a subnormal single- +| precision floating-point number. +| The input significand `zSig' has its binary point between bits 30 +| and 29, which is 7 bits to the left of the usual location. This shifted +| significand must be normalized or smaller. If `zSig' is not normalized, +| `zExp' must be 0; in that case, the result returned is a subnormal number, +| and it must not require rounding. In the usual case that `zSig' is +| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent. +| The handling of underflow and overflow follows the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 roundAndPackFloat32(int zSign, Bit16s zExp, Bit32u zSig, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper single-precision floating- +| point value corresponding to the abstract input. This routine is just like +| `roundAndPackFloat32' except that `zSig' does not have to be normalized. +| Bit 31 of `zSig' must be zero, and `zExp' must be 1 less than the ``true'' +| floating-point exponent. +*----------------------------------------------------------------------------*/ + +float32 normalizeRoundAndPackFloat32(int zSign, Bit16s zExp, Bit32u zSig, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal double-precision floating-point value represented +| by the denormalized significand `aSig'. The normalized exponent and +| significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ + +void normalizeFloat64Subnormal(Bit64u aSig, Bit16s *zExpPtr, Bit64u *zSigPtr); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper double-precision floating- +| point value corresponding to the abstract input. Ordinarily, the abstract +| value is simply rounded and packed into the double-precision format, with +| the inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded +| to a subnormal number, and the underflow and inexact exceptions are raised +| if the abstract input cannot be represented exactly as a subnormal double- +| precision floating-point number. +| The input significand `zSig' has its binary point between bits 62 +| and 61, which is 10 bits to the left of the usual location. This shifted +| significand must be normalized or smaller. If `zSig' is not normalized, +| `zExp' must be 0; in that case, the result returned is a subnormal number, +| and it must not require rounding. In the usual case that `zSig' is +| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent. +| The handling of underflow and overflow follows the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 roundAndPackFloat64(int zSign, Bit16s zExp, Bit64u zSig, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper double-precision floating- +| point value corresponding to the abstract input. This routine is just like +| `roundAndPackFloat64' except that `zSig' does not have to be normalized. +| Bit 63 of `zSig' must be zero, and `zExp' must be 1 less than the ``true'' +| floating-point exponent. +*----------------------------------------------------------------------------*/ + +float64 normalizeRoundAndPackFloat64(int zSign, Bit16s zExp, Bit64u zSig, struct float_status_t *status); + +#ifdef FLOATX80 + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal extended double-precision floating-point value +| represented by the denormalized significand `aSig'. The normalized exponent +| and significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ + +void normalizeFloatx80Subnormal(Bit64u aSig, Bit32s *zExpPtr, Bit64u *zSigPtr); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and extended significand formed by the concatenation of `zSig0' and `zSig1', +| and returns the proper extended double-precision floating-point value +| corresponding to the abstract input. Ordinarily, the abstract value is +| rounded and packed into the extended double-precision format, with the +| inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded to +| a subnormal number, and the underflow and inexact exceptions are raised if +| the abstract input cannot be represented exactly as a subnormal extended +| double-precision floating-point number. +| If `roundingPrecision' is 32 or 64, the result is rounded to the same +| number of bits as single or double precision, respectively. Otherwise, the +| result is rounded to the full precision of the extended double-precision +| format. +| The input significand must be normalized or smaller. If the input +| significand is not normalized, `zExp' must be 0; in that case, the result +| returned is a subnormal number, and it must not require rounding. The +| handling of underflow and overflow follows the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 roundAndPackFloatx80(int roundingPrecision, + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent +| `zExp', and significand formed by the concatenation of `zSig0' and `zSig1', +| and returns the proper extended double-precision floating-point value +| corresponding to the abstract input. This routine is just like +| `roundAndPackFloatx80' except that the input significand does not have to be +| normalized. +*----------------------------------------------------------------------------*/ + +floatx80 normalizeRoundAndPackFloatx80(int roundingPrecision, + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, struct float_status_t *status); + +#endif // FLOATX80 + +#ifdef FLOAT128 + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal quadruple-precision floating-point value +| represented by the denormalized significand formed by the concatenation of +| `aSig0' and `aSig1'. The normalized exponent is stored at the location +| pointed to by `zExpPtr'. The most significant 49 bits of the normalized +| significand are stored at the location pointed to by `zSig0Ptr', and the +| least significant 64 bits of the normalized significand are stored at the +| location pointed to by `zSig1Ptr'. +*----------------------------------------------------------------------------*/ + +void normalizeFloat128Subnormal( + Bit64u aSig0, Bit64u aSig1, Bit32s *zExpPtr, Bit64u *zSig0Ptr, Bit64u *zSig1Ptr); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and extended significand formed by the concatenation of `zSig0', `zSig1', +| and `zSig2', and returns the proper quadruple-precision floating-point value +| corresponding to the abstract input. Ordinarily, the abstract value is +| simply rounded and packed into the quadruple-precision format, with the +| inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded to +| a subnormal number, and the underflow and inexact exceptions are raised if +| the abstract input cannot be represented exactly as a subnormal quadruple- +| precision floating-point number. +| The input significand must be normalized or smaller. If the input +| significand is not normalized, `zExp' must be 0; in that case, the result +| returned is a subnormal number, and it must not require rounding. In the +| usual case that the input significand is normalized, `zExp' must be 1 less +| than the ``true'' floating-point exponent. The handling of underflow and +| overflow follows the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 roundAndPackFloat128( + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, Bit64u zSig2, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand formed by the concatenation of `zSig0' and `zSig1', and +| returns the proper quadruple-precision floating-point value corresponding +| to the abstract input. This routine is just like `roundAndPackFloat128' +| except that the input significand has fewer bits and does not have to be +| normalized. In all cases, `zExp' must be 1 less than the ``true'' floating- +| point exponent. +*----------------------------------------------------------------------------*/ + +float128 normalizeRoundAndPackFloat128( + int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1, struct float_status_t *status); + +#endif // FLOAT128 + +#endif diff --git a/src/cpu/softfloat/softfloat-specialize.cc b/src/cpu/softfloat/softfloat-specialize.cc new file mode 100644 index 000000000..bf0d11144 --- /dev/null +++ b/src/cpu/softfloat/softfloat-specialize.cc @@ -0,0 +1,187 @@ +/*============================================================================ +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +#define FLOAT128 + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "softfloat.h" +#include "softfloat-specialize.h" + +/*---------------------------------------------------------------------------- +| Takes two single-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +float32 propagateFloat32NaN(float32 a, float32 b, struct float_status_t *status) +{ + int aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN; + + aIsNaN = float32_is_nan(a); + aIsSignalingNaN = float32_is_signaling_nan(a); + bIsNaN = float32_is_nan(b); + bIsSignalingNaN = float32_is_signaling_nan(b); + a |= 0x00400000; + b |= 0x00400000; + if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid); + if (get_float_nan_handling_mode(status) == float_larger_significand_nan) { + if (aIsSignalingNaN) { + if (bIsSignalingNaN) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if (aIsNaN) { + if (bIsSignalingNaN | ! bIsNaN) return a; + returnLargerSignificand: + if ((Bit32u) (a<<1) < (Bit32u) (b<<1)) return b; + if ((Bit32u) (b<<1) < (Bit32u) (a<<1)) return a; + return (a < b) ? a : b; + } + else { + return b; + } + } else { + return (aIsSignalingNaN | aIsNaN) ? a : b; + } +} + +/*---------------------------------------------------------------------------- +| Takes two double-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +float64 propagateFloat64NaN(float64 a, float64 b, struct float_status_t *status) +{ + int aIsNaN = float64_is_nan(a); + int aIsSignalingNaN = float64_is_signaling_nan(a); + int bIsNaN = float64_is_nan(b); + int bIsSignalingNaN = float64_is_signaling_nan(b); + a |= BX_CONST64(0x0008000000000000); + b |= BX_CONST64(0x0008000000000000); + if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid); + if (get_float_nan_handling_mode(status) == float_larger_significand_nan) { + if (aIsSignalingNaN) { + if (bIsSignalingNaN) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if (aIsNaN) { + if (bIsSignalingNaN | ! bIsNaN) return a; + returnLargerSignificand: + if ((Bit64u) (a<<1) < (Bit64u) (b<<1)) return b; + if ((Bit64u) (b<<1) < (Bit64u) (a<<1)) return a; + return (a < b) ? a : b; + } + else { + return b; + } + } else { + return (aIsSignalingNaN | aIsNaN) ? a : b; + } +} + +#ifdef FLOATX80 + +/*---------------------------------------------------------------------------- +| Takes two extended double-precision floating-point values `a' and `b', one +| of which is a NaN, and returns the appropriate NaN result. If either `a' or +| `b' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, struct float_status_t *status) +{ + int aIsNaN = floatx80_is_nan(a); + int aIsSignalingNaN = floatx80_is_signaling_nan(a); + int bIsNaN = floatx80_is_nan(b); + int bIsSignalingNaN = floatx80_is_signaling_nan(b); + a.fraction |= BX_CONST64(0xC000000000000000); + b.fraction |= BX_CONST64(0xC000000000000000); + if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid); + if (aIsSignalingNaN) { + if (bIsSignalingNaN) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if (aIsNaN) { + if (bIsSignalingNaN | ! bIsNaN) return a; + returnLargerSignificand: + if (a.fraction < b.fraction) return b; + if (b.fraction < a.fraction) return a; + return (a.exp < b.exp) ? a : b; + } + else { + return b; + } +} + +#endif /* FLOATX80 */ + +#ifdef FLOAT128 + +/*---------------------------------------------------------------------------- +| Takes two quadruple-precision floating-point values `a' and `b', one of +| which is a NaN, and returns the appropriate NaN result. If either `a' or +| `b' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +float128 propagateFloat128NaN(float128 a, float128 b, struct float_status_t *status) +{ + int aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN; + aIsNaN = float128_is_nan(a); + aIsSignalingNaN = float128_is_signaling_nan(a); + bIsNaN = float128_is_nan(b); + bIsSignalingNaN = float128_is_signaling_nan(b); + a.hi |= BX_CONST64(0x0000800000000000); + b.hi |= BX_CONST64(0x0000800000000000); + if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid); + if (aIsSignalingNaN) { + if (bIsSignalingNaN) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if (aIsNaN) { + if (bIsSignalingNaN | !bIsNaN) return a; + returnLargerSignificand: + if (lt128(a.hi<<1, a.lo, b.hi<<1, b.lo)) return b; + if (lt128(b.hi<<1, b.lo, a.hi<<1, a.lo)) return a; + return (a.hi < b.hi) ? a : b; + } + else { + return b; + } +} + +/*---------------------------------------------------------------------------- +| The pattern for a default generated quadruple-precision NaN. +*----------------------------------------------------------------------------*/ +const float128 float128_default_nan = + packFloat128(float128_default_nan_hi, float128_default_nan_lo); + +#endif /* FLOAT128 */ diff --git a/src/cpu/softfloat/softfloat-specialize.h b/src/cpu/softfloat/softfloat-specialize.h new file mode 100644 index 000000000..302ce53e4 --- /dev/null +++ b/src/cpu/softfloat/softfloat-specialize.h @@ -0,0 +1,789 @@ +/*============================================================================ +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +#ifndef _SOFTFLOAT_SPECIALIZE_H_ +#define _SOFTFLOAT_SPECIALIZE_H_ + +#include "softfloat.h" + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#define int16_indefinite ((Bit16s)0x8000) +#define int32_indefinite ((Bit32s)0x80000000) +#define int64_indefinite BX_CONST64(0x8000000000000000) + +#define uint16_indefinite (0xffff) +#define uint32_indefinite (0xffffffff) +#define uint64_indefinite BX_CONST64(0xffffffffffffffff) + +/*---------------------------------------------------------------------------- +| Internal canonical NaN format. +*----------------------------------------------------------------------------*/ + +typedef struct { + int sign; + Bit64u hi, lo; +} commonNaNT; + +#ifdef FLOAT16 + +/*---------------------------------------------------------------------------- +| The pattern for a default generated half-precision NaN. +*----------------------------------------------------------------------------*/ +extern const float16 float16_default_nan; + +#define float16_fraction extractFloat16Frac +#define float16_exp extractFloat16Exp +#define float16_sign extractFloat16Sign + +/*---------------------------------------------------------------------------- +| Returns the fraction bits of the half-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit16u extractFloat16Frac(float16 a) +{ + return a & 0x3FF; +} + +/*---------------------------------------------------------------------------- +| Returns the exponent bits of the half-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit16s extractFloat16Exp(float16 a) +{ + return (a>>10) & 0x1F; +} + +/*---------------------------------------------------------------------------- +| Returns the sign bit of the half-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int extractFloat16Sign(float16 a) +{ + return a>>15; +} + +/*---------------------------------------------------------------------------- +| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a +| single-precision floating-point value, returning the result. After being +| shifted into the proper positions, the three fields are simply added +| together to form the result. This means that any integer portion of `zSig' +| will be added into the exponent. Since a properly normalized significand +| will have an integer portion equal to 1, the `zExp' input should be 1 less +| than the desired result exponent whenever `zSig' is a complete, normalized +| significand. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float16 packFloat16(int zSign, int zExp, Bit16u zSig) +{ + return (((Bit16u) zSign)<<15) + (((Bit16u) zExp)<<10) + zSig; +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the half-precision floating-point value `a' is a NaN; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float16_is_nan(float16 a) +{ + return (0xF800 < (Bit16u) (a<<1)); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the half-precision floating-point value `a' is a signaling +| NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float16_is_signaling_nan(float16 a) +{ + return (((a>>9) & 0x3F) == 0x3E) && (a & 0x1FF); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the half-precision floating-point value `a' is denormal; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float16_is_denormal(float16 a) +{ + return (extractFloat16Exp(a) == 0) && (extractFloat16Frac(a) != 0); +} + +/*---------------------------------------------------------------------------- +| Convert float16 denormals to zero. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float16 float16_denormal_to_zero(float16 a) +{ + if (float16_is_denormal(a)) a &= 0x8000; + return a; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the half-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE commonNaNT float16ToCommonNaN(float16 a, struct float_status_t *status) +{ + commonNaNT z; + if (float16_is_signaling_nan(a)) float_raise(status, float_flag_invalid); + z.sign = a>>15; + z.lo = 0; + z.hi = ((Bit64u) a)<<54; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the half- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float16 commonNaNToFloat16(commonNaNT a) +{ + return (((Bit16u) a.sign)<<15) | 0x7E00 | (Bit16u)(a.hi>>54); +} + +#endif + +/*---------------------------------------------------------------------------- +| Commonly used single-precision floating point constants +*----------------------------------------------------------------------------*/ +extern const float32 float32_negative_inf; +extern const float32 float32_positive_inf; +extern const float32 float32_negative_zero; +extern const float32 float32_positive_zero; +extern const float32 float32_negative_one; +extern const float32 float32_positive_one; +extern const float32 float32_max_float; +extern const float32 float32_min_float; + +/*---------------------------------------------------------------------------- +| The pattern for a default generated single-precision NaN. +*----------------------------------------------------------------------------*/ +extern const float32 float32_default_nan; + +#define float32_fraction extractFloat32Frac +#define float32_exp extractFloat32Exp +#define float32_sign extractFloat32Sign + +#define FLOAT32_EXP_BIAS 0x7F + +/*---------------------------------------------------------------------------- +| Returns the fraction bits of the single-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit32u extractFloat32Frac(float32 a) +{ + return a & 0x007FFFFF; +} + +/*---------------------------------------------------------------------------- +| Returns the exponent bits of the single-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit16s extractFloat32Exp(float32 a) +{ + return (a>>23) & 0xFF; +} + +/*---------------------------------------------------------------------------- +| Returns the sign bit of the single-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int extractFloat32Sign(float32 a) +{ + return a>>31; +} + +/*---------------------------------------------------------------------------- +| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a +| single-precision floating-point value, returning the result. After being +| shifted into the proper positions, the three fields are simply added +| together to form the result. This means that any integer portion of `zSig' +| will be added into the exponent. Since a properly normalized significand +| will have an integer portion equal to 1, the `zExp' input should be 1 less +| than the desired result exponent whenever `zSig' is a complete, normalized +| significand. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float32 packFloat32(int zSign, Bit16s zExp, Bit32u zSig) +{ + return (((Bit32u) zSign)<<31) + (((Bit32u) zExp)<<23) + zSig; +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is a NaN; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float32_is_nan(float32 a) +{ + return (0xFF000000 < (Bit32u) (a<<1)); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is a signaling +| NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float32_is_signaling_nan(float32 a) +{ + return (((a>>22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is denormal; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float32_is_denormal(float32 a) +{ + return (extractFloat32Exp(a) == 0) && (extractFloat32Frac(a) != 0); +} + +/*---------------------------------------------------------------------------- +| Convert float32 denormals to zero. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float32 float32_denormal_to_zero(float32 a) +{ + if (float32_is_denormal(a)) a &= 0x80000000; + return a; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE commonNaNT float32ToCommonNaN(float32 a, struct float_status_t *status) +{ + commonNaNT z; + if (float32_is_signaling_nan(a)) float_raise(status, float_flag_invalid); + z.sign = a>>31; + z.lo = 0; + z.hi = ((Bit64u) a)<<41; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the single- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float32 commonNaNToFloat32(commonNaNT a) +{ + return (((Bit32u) a.sign)<<31) | 0x7FC00000 | (Bit32u)(a.hi>>41); +} + +/*---------------------------------------------------------------------------- +| Takes two single-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +float32 propagateFloat32NaN(float32 a, float32 b, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes single-precision floating-point NaN `a' and returns the appropriate +| NaN result. If `a' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float32 propagateFloat32NaNOne(float32 a, struct float_status_t *status) +{ + if (float32_is_signaling_nan(a)) + float_raise(status, float_flag_invalid); + + return a | 0x00400000; +} + +/*---------------------------------------------------------------------------- +| Commonly used single-precision floating point constants +*----------------------------------------------------------------------------*/ +extern const float64 float64_negative_inf; +extern const float64 float64_positive_inf; +extern const float64 float64_negative_zero; +extern const float64 float64_positive_zero; +extern const float64 float64_negative_one; +extern const float64 float64_positive_one; +extern const float64 float64_max_float; +extern const float64 float64_min_float; + +/*---------------------------------------------------------------------------- +| The pattern for a default generated double-precision NaN. +*----------------------------------------------------------------------------*/ +extern const float64 float64_default_nan; + +#define float64_fraction extractFloat64Frac +#define float64_exp extractFloat64Exp +#define float64_sign extractFloat64Sign + +#define FLOAT64_EXP_BIAS 0x3FF + +/*---------------------------------------------------------------------------- +| Returns the fraction bits of the double-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit64u extractFloat64Frac(float64 a) +{ + return a & BX_CONST64(0x000FFFFFFFFFFFFF); +} + +/*---------------------------------------------------------------------------- +| Returns the exponent bits of the double-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit16s extractFloat64Exp(float64 a) +{ + return (Bit16s)(a>>52) & 0x7FF; +} + +/*---------------------------------------------------------------------------- +| Returns the sign bit of the double-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int extractFloat64Sign(float64 a) +{ + return (int)(a>>63); +} + +/*---------------------------------------------------------------------------- +| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a +| double-precision floating-point value, returning the result. After being +| shifted into the proper positions, the three fields are simply added +| together to form the result. This means that any integer portion of `zSig' +| will be added into the exponent. Since a properly normalized significand +| will have an integer portion equal to 1, the `zExp' input should be 1 less +| than the desired result exponent whenever `zSig' is a complete, normalized +| significand. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float64 packFloat64(int zSign, Bit16s zExp, Bit64u zSig) +{ + return (((Bit64u) zSign)<<63) + (((Bit64u) zExp)<<52) + zSig; +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the double-precision floating-point value `a' is a NaN; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float64_is_nan(float64 a) +{ + return (BX_CONST64(0xFFE0000000000000) < (Bit64u) (a<<1)); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the double-precision floating-point value `a' is a signaling +| NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float64_is_signaling_nan(float64 a) +{ + return (((a>>51) & 0xFFF) == 0xFFE) && (a & BX_CONST64(0x0007FFFFFFFFFFFF)); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the double-precision floating-point value `a' is denormal; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float64_is_denormal(float64 a) +{ + return (extractFloat64Exp(a) == 0) && (extractFloat64Frac(a) != 0); +} + +/*---------------------------------------------------------------------------- +| Convert float64 denormals to zero. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float64 float64_denormal_to_zero(float64 a) +{ + if (float64_is_denormal(a)) a &= ((Bit64u)(1) << 63); + return a; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE commonNaNT float64ToCommonNaN(float64 a, struct float_status_t *status) +{ + commonNaNT z; + if (float64_is_signaling_nan(a)) float_raise(status, float_flag_invalid); + z.sign = (int)(a>>63); + z.lo = 0; + z.hi = a<<12; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the double- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float64 commonNaNToFloat64(commonNaNT a) +{ + return (((Bit64u) a.sign)<<63) | BX_CONST64(0x7FF8000000000000) | (a.hi>>12); +} + +/*---------------------------------------------------------------------------- +| Takes two double-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +float64 propagateFloat64NaN(float64 a, float64 b, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes double-precision floating-point NaN `a' and returns the appropriate +| NaN result. If `a' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float64 propagateFloat64NaNOne(float64 a, struct float_status_t *status) +{ + if (float64_is_signaling_nan(a)) + float_raise(status, float_flag_invalid); + + return a | BX_CONST64(0x0008000000000000); +} + +#ifdef FLOATX80 + +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. The +| `high' and `low' values hold the most- and least-significant bits, +| respectively. +*----------------------------------------------------------------------------*/ +#define floatx80_default_nan_exp 0xFFFF +#define floatx80_default_nan_fraction BX_CONST64(0xC000000000000000) + +#define floatx80_fraction extractFloatx80Frac +#define floatx80_exp extractFloatx80Exp +#define floatx80_sign extractFloatx80Sign + +#define FLOATX80_EXP_BIAS 0x3FFF + +/*---------------------------------------------------------------------------- +| Returns the fraction bits of the extended double-precision floating-point +| value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit64u extractFloatx80Frac(floatx80 a) +{ + return a.fraction; +} + +/*---------------------------------------------------------------------------- +| Returns the exponent bits of the extended double-precision floating-point +| value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit32s extractFloatx80Exp(floatx80 a) +{ + return a.exp & 0x7FFF; +} + +/*---------------------------------------------------------------------------- +| Returns the sign bit of the extended double-precision floating-point value +| `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int extractFloatx80Sign(floatx80 a) +{ + return a.exp>>15; +} + +/*---------------------------------------------------------------------------- +| Packs the sign `zSign', exponent `zExp', and significand `zSig' into an +| extended double-precision floating-point value, returning the result. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE floatx80 packFloatx80(int zSign, Bit32s zExp, Bit64u zSig) +{ + floatx80 z; + z.fraction = zSig; + z.exp = (zSign << 15) + zExp; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the extended double-precision floating-point value `a' is a +| NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int floatx80_is_nan(floatx80 a) +{ + // return ((a.exp & 0x7FFF) == 0x7FFF) && (Bit64s) (a.fraction<<1); + return ((a.exp & 0x7FFF) == 0x7FFF) && (((Bit64s) (a.fraction<<1)) != 0); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the extended double-precision floating-point value `a' is a +| signaling NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int floatx80_is_signaling_nan(floatx80 a) +{ + Bit64u aLow = a.fraction & ~BX_CONST64(0x4000000000000000); + return ((a.exp & 0x7FFF) == 0x7FFF) && + ((Bit64u) (aLow<<1)) && (a.fraction == aLow); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the extended double-precision floating-point value `a' is an +| unsupported; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int floatx80_is_unsupported(floatx80 a) +{ + return ((a.exp & 0x7FFF) && !(a.fraction & BX_CONST64(0x8000000000000000))); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the extended double-precision floating- +| point NaN `a' to the canonical NaN format. If `a' is a signaling NaN, the +| invalid exception is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE commonNaNT floatx80ToCommonNaN(floatx80 a, struct float_status_t *status) +{ + commonNaNT z; + if (floatx80_is_signaling_nan(a)) float_raise(status, float_flag_invalid); + z.sign = a.exp >> 15; + z.lo = 0; + z.hi = a.fraction << 1; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the extended +| double-precision floating-point format. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE floatx80 commonNaNToFloatx80(commonNaNT a) +{ + floatx80 z; + z.fraction = BX_CONST64(0xC000000000000000) | (a.hi>>1); + z.exp = (((Bit16u) a.sign)<<15) | 0x7FFF; + return z; +} + +/*---------------------------------------------------------------------------- +| Takes two extended double-precision floating-point values `a' and `b', one +| of which is a NaN, and returns the appropriate NaN result. If either `a' or +| `b' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Takes extended double-precision floating-point NaN `a' and returns the +| appropriate NaN result. If `a' is a signaling NaN, the invalid exception +| is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE floatx80 propagateFloatx80NaNOne(floatx80 a, struct float_status_t *status) +{ + if (floatx80_is_signaling_nan(a)) + float_raise(status, float_flag_invalid); + + a.fraction |= BX_CONST64(0xC000000000000000); + + return a; +} + +#endif /* FLOATX80 */ + +#ifdef FLOAT128 + +#include "softfloat-macros.h" + +/*---------------------------------------------------------------------------- +| The pattern for a default generated quadruple-precision NaN. The `high' and +| `low' values hold the most- and least-significant bits, respectively. +*----------------------------------------------------------------------------*/ +#define float128_default_nan_hi BX_CONST64(0xFFFF800000000000) +#define float128_default_nan_lo BX_CONST64(0x0000000000000000) + +#define float128_exp extractFloat128Exp + +/*---------------------------------------------------------------------------- +| Returns the least-significant 64 fraction bits of the quadruple-precision +| floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit64u extractFloat128Frac1(float128 a) +{ + return a.lo; +} + +/*---------------------------------------------------------------------------- +| Returns the most-significant 48 fraction bits of the quadruple-precision +| floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit64u extractFloat128Frac0(float128 a) +{ + return a.hi & BX_CONST64(0x0000FFFFFFFFFFFF); +} + +/*---------------------------------------------------------------------------- +| Returns the exponent bits of the quadruple-precision floating-point value +| `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE Bit32s extractFloat128Exp(float128 a) +{ + return ((Bit32s)(a.hi>>48)) & 0x7FFF; +} + +/*---------------------------------------------------------------------------- +| Returns the sign bit of the quadruple-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int extractFloat128Sign(float128 a) +{ + return (int)(a.hi >> 63); +} + +/*---------------------------------------------------------------------------- +| Packs the sign `zSign', the exponent `zExp', and the significand formed +| by the concatenation of `zSig0' and `zSig1' into a quadruple-precision +| floating-point value, returning the result. After being shifted into the +| proper positions, the three fields `zSign', `zExp', and `zSig0' are simply +| added together to form the most significant 32 bits of the result. This +| means that any integer portion of `zSig0' will be added into the exponent. +| Since a properly normalized significand will have an integer portion equal +| to 1, the `zExp' input should be 1 less than the desired result exponent +| whenever `zSig0' and `zSig1' concatenated form a complete, normalized +| significand. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float128 packFloat128Four(int zSign, Bit32s zExp, Bit64u zSig0, Bit64u zSig1) +{ + float128 z; + z.lo = zSig1; + z.hi = (((Bit64u) zSign)<<63) + (((Bit64u) zExp)<<48) + zSig0; + return z; +} + +/*---------------------------------------------------------------------------- +| Packs two 64-bit precision integers into into the quadruple-precision +| floating-point value, returning the result. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float128 packFloat128(Bit64u zHi, Bit64u zLo) +{ + float128 z; + z.lo = zLo; + z.hi = zHi; + return z; +} + +#ifdef _MSC_VER +#define PACK_FLOAT_128(hi,lo) { lo, hi } +#else +#define PACK_FLOAT_128(hi,lo) packFloat128(BX_CONST64(hi),BX_CONST64(lo)) +#endif + +/*---------------------------------------------------------------------------- +| Returns 1 if the quadruple-precision floating-point value `a' is a NaN; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float128_is_nan(float128 a) +{ + return (BX_CONST64(0xFFFE000000000000) <= (Bit64u) (a.hi<<1)) + && (a.lo || (a.hi & BX_CONST64(0x0000FFFFFFFFFFFF))); +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the quadruple-precision floating-point value `a' is a +| signaling NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float128_is_signaling_nan(float128 a) +{ + return (((a.hi>>47) & 0xFFFF) == 0xFFFE) + && (a.lo || (a.hi & BX_CONST64(0x00007FFFFFFFFFFF))); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the quadruple-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE commonNaNT float128ToCommonNaN(float128 a, struct float_status_t *status) +{ + commonNaNT z; + if (float128_is_signaling_nan(a)) float_raise(status, float_flag_invalid); + z.sign = (int)(a.hi>>63); + shortShift128Left(a.hi, a.lo, 16, &z.hi, &z.lo); + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the quadruple- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE float128 commonNaNToFloat128(commonNaNT a) +{ + float128 z; + shift128Right(a.hi, a.lo, 16, &z.hi, &z.lo); + z.hi |= (((Bit64u) a.sign)<<63) | BX_CONST64(0x7FFF800000000000); + return z; +} + +/*---------------------------------------------------------------------------- +| Takes two quadruple-precision floating-point values `a' and `b', one of +| which is a NaN, and returns the appropriate NaN result. If either `a' or +| `b' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +float128 propagateFloat128NaN(float128 a, float128 b, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| The pattern for a default generated quadruple-precision NaN. +*----------------------------------------------------------------------------*/ +extern const float128 float128_default_nan; + +#endif /* FLOAT128 */ + +#endif diff --git a/src/cpu/softfloat/softfloat.cc b/src/cpu/softfloat/softfloat.cc new file mode 100644 index 000000000..0802089b9 --- /dev/null +++ b/src/cpu/softfloat/softfloat.cc @@ -0,0 +1,4012 @@ +/*============================================================================ +This C source file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +#define FLOAT128 + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "softfloat.h" +#include "softfloat-round-pack.h" + +/*---------------------------------------------------------------------------- +| Primitive arithmetic functions, including multi-word arithmetic, and +| division and square root approximations. (Can be specialized to target +| if desired). +*----------------------------------------------------------------------------*/ +#define USE_estimateDiv128To64 +#define USE_estimateSqrt32 +#include "softfloat-macros.h" + +/*---------------------------------------------------------------------------- +| Functions and definitions to determine: (1) whether tininess for underflow +| is detected before or after rounding by default, (2) what (if anything) +| happens when exceptions are raised, (3) how signaling NaNs are distinguished +| from quiet NaNs, (4) the default generated quiet NaNs, and (5) how NaNs +| are propagated from function inputs to output. These details are target- +| specific. +*----------------------------------------------------------------------------*/ +#include "softfloat-specialize.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the 32-bit two's complement integer `a' +| to the single-precision floating-point format. The conversion is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +const unsigned float_all_exceptions_mask = 0x3f; + +float32 int32_to_float32(Bit32s a, struct float_status_t *status) +{ + if (a == 0) return 0; + if (a == (Bit32s) 0x80000000) return packFloat32(1, 0x9E, 0); + int zSign = (a < 0); + return normalizeRoundAndPackFloat32(zSign, 0x9C, zSign ? -a : a, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the 32-bit two's complement integer `a' +| to the double-precision floating-point format. The conversion is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 int32_to_float64(Bit32s a) +{ + if (a == 0) return 0; + int zSign = (a < 0); + Bit32u absA = zSign ? -a : a; + int shiftCount = countLeadingZeros32(absA) + 21; + Bit64u zSig = absA; + return packFloat64(zSign, 0x432 - shiftCount, zSig<> 1, status); + return normalizeRoundAndPackFloat32(0, 0x9C, a, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the 32-bit unsigned integer `a' to the +| double-precision floating-point format. The conversion is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 uint32_to_float64(Bit32u a) +{ + if (a == 0) return 0; + int shiftCount = countLeadingZeros32(a) + 21; + Bit64u zSig = a; + return packFloat64(0, 0x432 - shiftCount, zSig<> 1, status); + return normalizeRoundAndPackFloat64(0, 0x43C, a, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 32-bit two's complement integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic - which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN or the +| conversion overflows the integer indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit32s float32_to_int32(float32 a, struct float_status_t *status) +{ + Bit32u aSig = extractFloat32Frac(a); + Bit16s aExp = extractFloat32Exp(a); + int aSign = extractFloat32Sign(a); + if ((aExp == 0xFF) && aSig) aSign = 0; + if (aExp) aSig |= 0x00800000; + else { + if (get_denormals_are_zeros(status)) aSig = 0; + } + int shiftCount = 0xAF - aExp; + Bit64u aSig64 = Bit64u(aSig) << 32; + if (0 < shiftCount) aSig64 = shift64RightJamming(aSig64, shiftCount); + return roundAndPackInt32(aSign, aSig64, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 32-bit two's complement integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic, except that the conversion is always rounded toward zero. +| If `a' is a NaN or the conversion overflows, the integer indefinite +| value is returned. +*----------------------------------------------------------------------------*/ + +Bit32s float32_to_int32_round_to_zero(float32 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp; + Bit32u aSig; + Bit32s z; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + int shiftCount = aExp - 0x9E; + if (0 <= shiftCount) { + if (a != 0xCF000000) { + float_raise(status, float_flag_invalid); + } + return (Bit32s)(int32_indefinite); + } + else if (aExp <= 0x7E) { + if (get_denormals_are_zeros(status) && aExp == 0) aSig = 0; + if (aExp | aSig) float_raise(status, float_flag_inexact); + return 0; + } + aSig = (aSig | 0x800000)<<8; + z = aSig>>(-shiftCount); + if ((Bit32u) (aSig<<(shiftCount & 31))) { + float_raise(status, float_flag_inexact); + } + if (aSign) z = -z; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 32-bit unsigned integer format. The conversion is performed +| according to the IEC/IEEE Standard for Binary Floating-point Arithmetic, +| except that the conversion is always rounded toward zero. If `a' is a NaN +| or conversion overflows, the largest positive integer is returned. +*----------------------------------------------------------------------------*/ + +Bit32u float32_to_uint32_round_to_zero(float32 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp; + Bit32u aSig; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + int shiftCount = aExp - 0x9E; + + if (aExp <= 0x7E) { + if (get_denormals_are_zeros(status) && aExp == 0) aSig = 0; + if (aExp | aSig) float_raise(status, float_flag_inexact); + return 0; + } + else if (0 < shiftCount || aSign) { + float_raise(status, float_flag_invalid); + return uint32_indefinite; + } + + aSig = (aSig | 0x800000)<<8; + Bit32u z = aSig >> (-shiftCount); + if (aSig << (shiftCount & 31)) { + float_raise(status, float_flag_inexact); + } + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 64-bit two's complement integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic - which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN or the +| conversion overflows, the integer indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit64s float32_to_int64(float32 a, struct float_status_t *status) +{ + Bit64u aSig64, aSigExtra; + + Bit32u aSig = extractFloat32Frac(a); + Bit16s aExp = extractFloat32Exp(a); + int aSign = extractFloat32Sign(a); + + int shiftCount = 0xBE - aExp; + if (shiftCount < 0) { + float_raise(status, float_flag_invalid); + return (Bit64s)(int64_indefinite); + } + if (aExp) aSig |= 0x00800000; + else { + if (get_denormals_are_zeros(status)) aSig = 0; + } + aSig64 = aSig; + aSig64 <<= 40; + shift64ExtraRightJamming(aSig64, 0, shiftCount, &aSig64, &aSigExtra); + return roundAndPackInt64(aSign, aSig64, aSigExtra, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 64-bit two's complement integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic, except that the conversion is always rounded toward zero. +| If `a' is a NaN or the conversion overflows, the integer indefinite +| value is returned. +*----------------------------------------------------------------------------*/ + +Bit64s float32_to_int64_round_to_zero(float32 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp; + Bit32u aSig; + Bit64u aSig64; + Bit64s z; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + int shiftCount = aExp - 0xBE; + if (0 <= shiftCount) { + if (a != 0xDF000000) { + float_raise(status, float_flag_invalid); + } + return (Bit64s)(int64_indefinite); + } + else if (aExp <= 0x7E) { + if (get_denormals_are_zeros(status) && aExp == 0) aSig = 0; + if (aExp | aSig) float_raise(status, float_flag_inexact); + return 0; + } + aSig64 = aSig | 0x00800000; + aSig64 <<= 40; + z = aSig64>>(-shiftCount); + if ((Bit64u) (aSig64<<(shiftCount & 63))) { + float_raise(status, float_flag_inexact); + } + if (aSign) z = -z; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 64-bit unsigned integer format. The conversion is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic, +| except that the conversion is always rounded toward zero. If `a' is a NaN +| or the conversion overflows, the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit64u float32_to_uint64_round_to_zero(float32 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp; + Bit32u aSig; + Bit64u aSig64; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + int shiftCount = aExp - 0xBE; + + if (aExp <= 0x7E) { + if (get_denormals_are_zeros(status) && aExp == 0) aSig = 0; + if (aExp | aSig) float_raise(status, float_flag_inexact); + return 0; + } + else if (0 < shiftCount || aSign) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + + aSig64 = aSig | 0x00800000; + aSig64 <<= 40; + Bit64u z = aSig64>>(-shiftCount); + if ((Bit64u) (aSig64<<(shiftCount & 63))) { + float_raise(status, float_flag_inexact); + } + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 64-bit unsigned integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic---which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN or the conversion +| overflows, the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit64u float32_to_uint64(float32 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp, shiftCount; + Bit32u aSig; + Bit64u aSig64, aSigExtra; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + } + + if ((aSign) && (aExp > 0x7E)) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + + shiftCount = 0xBE - aExp; + if (aExp) aSig |= 0x00800000; + + if (shiftCount < 0) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + + aSig64 = aSig; + aSig64 <<= 40; + shift64ExtraRightJamming(aSig64, 0, shiftCount, &aSig64, &aSigExtra); + return roundAndPackUint64(aSign, aSig64, aSigExtra, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the 32-bit unsigned integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic---which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN or the conversion +| overflows, the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit32u float32_to_uint32(float32 a, struct float_status_t *status) +{ + Bit64u val_64 = float32_to_uint64(a, status); + + if (val_64 > 0xffffffff) { + status->float_exception_flags = float_flag_invalid; // throw away other flags + return uint32_indefinite; + } + + return (Bit32u) val_64; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the double-precision floating-point format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float32_to_float64(float32 a, struct float_status_t *status) +{ + Bit32u aSig = extractFloat32Frac(a); + Bit16s aExp = extractFloat32Exp(a); + int aSign = extractFloat32Sign(a); + + if (aExp == 0xFF) { + if (aSig) return commonNaNToFloat64(float32ToCommonNaN(a, status)); + return packFloat64(aSign, 0x7FF, 0); + } + if (aExp == 0) { + if (aSig == 0 || get_denormals_are_zeros(status)) + return packFloat64(aSign, 0, 0); + + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(aSig, &aExp, &aSig); + --aExp; + } + return packFloat64(aSign, aExp + 0x380, ((Bit64u) aSig)<<29); +} + +/*---------------------------------------------------------------------------- +| Rounds the single-precision floating-point value `a' to an integer, and +| returns the result as a single-precision floating-point value. The +| operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_round_to_int(float32 a, Bit8u scale, struct float_status_t *status) +{ + Bit32u lastBitMask, roundBitsMask; + int roundingMode = get_float_rounding_mode(status); + Bit16s aExp = extractFloat32Exp(a); + scale &= 0xf; + + if ((aExp == 0xFF) && extractFloat32Frac(a)) { + return propagateFloat32NaNOne(a, status); + } + + aExp += scale; // scale the exponent + + if (0x96 <= aExp) { + return a; + } + + if (get_denormals_are_zeros(status)) { + a = float32_denormal_to_zero(a); + } + + if (aExp <= 0x7E) { + if ((Bit32u) (a<<1) == 0) return a; + float_raise(status, float_flag_inexact); + int aSign = extractFloat32Sign(a); + switch (roundingMode) { + case float_round_nearest_even: + if ((aExp == 0x7E) && extractFloat32Frac(a)) { + return packFloat32(aSign, 0x7F - scale, 0); + } + break; + case float_round_down: + return aSign ? packFloat32(1, 0x7F - scale, 0) : float32_positive_zero; + case float_round_up: + return aSign ? float32_negative_zero : packFloat32(0, 0x7F - scale, 0); + } + return packFloat32(aSign, 0, 0); + } + + lastBitMask = 1; + lastBitMask <<= 0x96 - aExp; + roundBitsMask = lastBitMask - 1; + float32 z = a; + if (roundingMode == float_round_nearest_even) { + z += lastBitMask>>1; + if ((z & roundBitsMask) == 0) z &= ~lastBitMask; + } + else if (roundingMode != float_round_to_zero) { + if (extractFloat32Sign(z) ^ (roundingMode == float_round_up)) { + z += roundBitsMask; + } + } + z &= ~roundBitsMask; + if (z != a) float_raise(status, float_flag_inexact); + return z; +} + +/*---------------------------------------------------------------------------- +| Extracts the fractional portion of single-precision floating-point value `a', +| and returns the result as a single-precision floating-point value. The +| fractional results are precise. The operation is performed according to the +| IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_frc(float32 a, struct float_status_t *status) +{ + int roundingMode = get_float_rounding_mode(status); + + Bit16s aExp = extractFloat32Exp(a); + Bit32u aSig = extractFloat32Frac(a); + int aSign = extractFloat32Sign(a); + + if (aExp == 0xFF) { + if (aSig) return propagateFloat32NaNOne(a, status); + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + + if (aExp >= 0x96) { + return packFloat32(roundingMode == float_round_down, 0, 0); + } + + if (aExp < 0x7F) { + if (aExp == 0) { + if (aSig == 0 || get_denormals_are_zeros(status)) + return packFloat32(roundingMode == float_round_down, 0, 0); + + float_raise(status, float_flag_denormal); + if (! float_exception_masked(status, float_flag_underflow)) + float_raise(status, float_flag_underflow); + + if(get_flush_underflow_to_zero(status)) { + float_raise(status, float_flag_underflow | float_flag_inexact); + return packFloat32(aSign, 0, 0); + } + } + return a; + } + + Bit32u lastBitMask = 1 << (0x96 - aExp); + Bit32u roundBitsMask = lastBitMask - 1; + + aSig &= roundBitsMask; + aSig <<= 7; + aExp--; + + if (aSig == 0) + return packFloat32(roundingMode == float_round_down, 0, 0); + + return normalizeRoundAndPackFloat32(aSign, aExp, aSig, status); +} + +/*---------------------------------------------------------------------------- +| Extracts the exponent portion of single-precision floating-point value 'a', +| and returns the result as a single-precision floating-point value +| representing unbiased integer exponent. The operation is performed according +| to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_getexp(float32 a, struct float_status_t *status) +{ + Bit16s aExp = extractFloat32Exp(a); + Bit32u aSig = extractFloat32Frac(a); + + if (aExp == 0xFF) { + if (aSig) return propagateFloat32NaNOne(a, status); + return float32_positive_inf; + } + + if (aExp == 0) { + if (aSig == 0 || get_denormals_are_zeros(status)) + return float32_negative_inf; + + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(aSig, &aExp, &aSig); + } + + return int32_to_float32(aExp - 0x7F, status); +} + +/*---------------------------------------------------------------------------- +| Extracts the mantissa of single-precision floating-point value 'a' and +| returns the result as a single-precision floating-point after applying +| the mantissa interval normalization and sign control. The operation is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_getmant(float32 a, struct float_status_t *status, int sign_ctrl, int interv) +{ + Bit16s aExp = extractFloat32Exp(a); + Bit32u aSig = extractFloat32Frac(a); + int aSign = extractFloat32Sign(a); + + if (aExp == 0xFF) { + if (aSig) return propagateFloat32NaNOne(a, status); + if (aSign) { + if (sign_ctrl & 0x2) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + } + return packFloat32(~sign_ctrl & aSign, 0x7F, 0); + } + + if (aExp == 0 && (aSig == 0 || get_denormals_are_zeros(status))) { + return packFloat32(~sign_ctrl & aSign, 0x7F, 0); + } + + if (aSign) { + if (sign_ctrl & 0x2) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + } + + if (aExp == 0) { + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(aSig, &aExp, &aSig); +// aExp += 0x7E; + aSig &= 0x7FFFFF; + } + + switch(interv) { + case 0x0: // interval [1,2) + aExp = 0x7F; + break; + case 0x1: // interval [1/2,2) + aExp -= 0x7F; + aExp = 0x7F - (aExp & 0x1); + break; + case 0x2: // interval [1/2,1) + aExp = 0x7E; + break; + case 0x3: // interval [3/4,3/2) + aExp = 0x7F - ((aSig >> 22) & 0x1); + break; + } + + return packFloat32(~sign_ctrl & aSign, aExp, aSig); +} + +/*---------------------------------------------------------------------------- +| Return the result of a floating point scale of the single-precision floating +| point value `a' by multiplying it by 2 power of the single-precision +| floating point value 'b' converted to integral value. If the result cannot +| be represented in single precision, then the proper overflow response (for +| positive scaling operand), or the proper underflow response (for negative +| scaling operand) is issued. The operation is performed according to the +| IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_scalef(float32 a, float32 b, struct float_status_t *status) +{ + Bit32u aSig = extractFloat32Frac(a); + Bit16s aExp = extractFloat32Exp(a); + int aSign = extractFloat32Sign(a); + Bit32u bSig = extractFloat32Frac(b); + Bit16s bExp = extractFloat32Exp(b); + int bSign = extractFloat32Sign(b); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + if (bExp == 0xFF) { + if (bSig) return propagateFloat32NaN(a, b, status); + } + + if (aExp == 0xFF) { + if (aSig) { + int aIsSignalingNaN = (aSig & 0x00400000) == 0; + if (aIsSignalingNaN || bExp != 0xFF || bSig) + return propagateFloat32NaN(a, b, status); + + return bSign ? 0 : float32_positive_inf; + } + + if (bExp == 0xFF && bSign) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + return a; + } + + if (aExp == 0) { + if (aSig == 0) { + if (bExp == 0xFF && ! bSign) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + return a; + } + float_raise(status, float_flag_denormal); + } + + if ((bExp | bSig) == 0) return a; + + if (bExp == 0xFF) { + if (bSign) return packFloat32(aSign, 0, 0); + return packFloat32(aSign, 0xFF, 0); + } + + if (bExp >= 0x8E) { + // handle obvious overflow/underflow result + return roundAndPackFloat32(aSign, bSign ? -0x7F : 0xFF, aSig, status); + } + + int scale = 0; + + if (bExp <= 0x7E) { + if (bExp == 0) + float_raise(status, float_flag_denormal); + scale = -bSign; + } + else { + int shiftCount = bExp - 0x9E; + bSig = (bSig | 0x800000)<<8; + scale = bSig>>(-shiftCount); + + if (bSign) { + if ((Bit32u) (bSig<<(shiftCount & 31))) scale++; + scale = -scale; + } + + if (scale > 0x200) scale = 0x200; + if (scale < -0x200) scale = -0x200; + } + + if (aExp != 0) { + aSig |= 0x00800000; + } else { + aExp++; + } + + aExp += scale - 1; + aSig <<= 7; + return normalizeRoundAndPackFloat32(aSign, aExp, aSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the absolute values of the single-precision +| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated +| before being returned. `zSign' is ignored if the result is a NaN. +| The addition is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static float32 addFloat32Sigs(float32 a, float32 b, int zSign, struct float_status_t *status) +{ + Bit16s aExp, bExp, zExp; + Bit32u aSig, bSig, zSig; + Bit16s expDiff; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + bSig = extractFloat32Frac(b); + bExp = extractFloat32Exp(b); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + expDiff = aExp - bExp; + aSig <<= 6; + bSig <<= 6; + + if (0 < expDiff) { + if (aExp == 0xFF) { + if (aSig) return propagateFloat32NaN(a, b, status); + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return a; + } + if ((aExp == 0) && aSig) + float_raise(status, float_flag_denormal); + + if (bExp == 0) { + if (bSig) float_raise(status, float_flag_denormal); + --expDiff; + } + else bSig |= 0x20000000; + + bSig = shift32RightJamming(bSig, expDiff); + zExp = aExp; + } + else if (expDiff < 0) { + if (bExp == 0xFF) { + if (bSig) return propagateFloat32NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat32(zSign, 0xFF, 0); + } + if ((bExp == 0) && bSig) + float_raise(status, float_flag_denormal); + + if (aExp == 0) { + if (aSig) float_raise(status, float_flag_denormal); + ++expDiff; + } + else aSig |= 0x20000000; + + aSig = shift32RightJamming(aSig, -expDiff); + zExp = bExp; + } + else { + if (aExp == 0xFF) { + if (aSig | bSig) return propagateFloat32NaN(a, b, status); + return a; + } + if (aExp == 0) { + zSig = (aSig + bSig) >> 6; + if (aSig | bSig) { + float_raise(status, float_flag_denormal); + if (get_flush_underflow_to_zero(status) && (extractFloat32Frac(zSig) == zSig)) { + float_raise(status, float_flag_underflow | float_flag_inexact); + return packFloat32(zSign, 0, 0); + } + if (! float_exception_masked(status, float_flag_underflow)) { + if (extractFloat32Frac(zSig) == zSig) + float_raise(status, float_flag_underflow); + } + } + return packFloat32(zSign, 0, zSig); + } + zSig = 0x40000000 + aSig + bSig; + return roundAndPackFloat32(zSign, aExp, zSig, status); + } + aSig |= 0x20000000; + zSig = (aSig + bSig)<<1; + --zExp; + if ((Bit32s) zSig < 0) { + zSig = aSig + bSig; + ++zExp; + } + return roundAndPackFloat32(zSign, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the absolute values of the single- +| precision floating-point values `a' and `b'. If `zSign' is 1, the +| difference is negated before being returned. `zSign' is ignored if the +| result is a NaN. The subtraction is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static float32 subFloat32Sigs(float32 a, float32 b, int zSign, struct float_status_t *status) +{ + Bit16s aExp, bExp, zExp; + Bit32u aSig, bSig, zSig; + Bit16s expDiff; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + bSig = extractFloat32Frac(b); + bExp = extractFloat32Exp(b); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + expDiff = aExp - bExp; + aSig <<= 7; + bSig <<= 7; + if (0 < expDiff) goto aExpBigger; + if (expDiff < 0) goto bExpBigger; + if (aExp == 0xFF) { + if (aSig | bSig) return propagateFloat32NaN(a, b, status); + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + if (aExp == 0) { + if (aSig | bSig) float_raise(status, float_flag_denormal); + aExp = 1; + bExp = 1; + } + if (bSig < aSig) goto aBigger; + if (aSig < bSig) goto bBigger; + return packFloat32(get_float_rounding_mode(status) == float_round_down, 0, 0); + bExpBigger: + if (bExp == 0xFF) { + if (bSig) return propagateFloat32NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat32(zSign ^ 1, 0xFF, 0); + } + if ((bExp == 0) && bSig) + float_raise(status, float_flag_denormal); + + if (aExp == 0) { + if (aSig) float_raise(status, float_flag_denormal); + ++expDiff; + } + else aSig |= 0x40000000; + + aSig = shift32RightJamming(aSig, -expDiff); + bSig |= 0x40000000; + bBigger: + zSig = bSig - aSig; + zExp = bExp; + zSign ^= 1; + goto normalizeRoundAndPack; + aExpBigger: + if (aExp == 0xFF) { + if (aSig) return propagateFloat32NaN(a, b, status); + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return a; + } + if ((aExp == 0) && aSig) + float_raise(status, float_flag_denormal); + + if (bExp == 0) { + if (bSig) float_raise(status, float_flag_denormal); + --expDiff; + } + else bSig |= 0x40000000; + + bSig = shift32RightJamming(bSig, expDiff); + aSig |= 0x40000000; + aBigger: + zSig = aSig - bSig; + zExp = aExp; + normalizeRoundAndPack: + --zExp; + return normalizeRoundAndPackFloat32(zSign, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the single-precision floating-point values `a' +| and `b'. The operation is performed according to the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_add(float32 a, float32 b, struct float_status_t *status) +{ + int aSign = extractFloat32Sign(a); + int bSign = extractFloat32Sign(b); + + if (aSign == bSign) { + return addFloat32Sigs(a, b, aSign, status); + } + else { + return subFloat32Sigs(a, b, aSign, status); + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the single-precision floating-point values +| `a' and `b'. The operation is performed according to the IEC/IEEE Standard +| for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_sub(float32 a, float32 b, struct float_status_t *status) +{ + int aSign = extractFloat32Sign(a); + int bSign = extractFloat32Sign(b); + + if (aSign == bSign) { + return subFloat32Sigs(a, b, aSign, status); + } + else { + return addFloat32Sigs(a, b, aSign, status); + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of multiplying the single-precision floating-point values +| `a' and `b'. The operation is performed according to the IEC/IEEE Standard +| for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_mul(float32 a, float32 b, struct float_status_t *status) +{ + int aSign, bSign, zSign; + Bit16s aExp, bExp, zExp; + Bit32u aSig, bSig; + Bit64u zSig64; + Bit32u zSig; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + bSig = extractFloat32Frac(b); + bExp = extractFloat32Exp(b); + bSign = extractFloat32Sign(b); + zSign = aSign ^ bSign; + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + if (aExp == 0xFF) { + if (aSig || ((bExp == 0xFF) && bSig)) + return propagateFloat32NaN(a, b, status); + + if ((bExp | bSig) == 0) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloat32(zSign, 0xFF, 0); + } + if (bExp == 0xFF) { + if (bSig) return propagateFloat32NaN(a, b, status); + if ((aExp | aSig) == 0) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat32(zSign, 0xFF, 0); + } + if (aExp == 0) { + if (aSig == 0) { + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloat32(zSign, 0, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + if (bSig == 0) return packFloat32(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(bSig, &bExp, &bSig); + } + zExp = aExp + bExp - 0x7F; + aSig = (aSig | 0x00800000)<<7; + bSig = (bSig | 0x00800000)<<8; + zSig64 = shift64RightJamming(((Bit64u) aSig) * bSig, 32); + zSig = (Bit32u) zSig64; + if (0 <= (Bit32s) (zSig<<1)) { + zSig <<= 1; + --zExp; + } + return roundAndPackFloat32(zSign, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of dividing the single-precision floating-point value `a' +| by the corresponding value `b'. The operation is performed according to the +| IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_div(float32 a, float32 b, struct float_status_t *status) +{ + int aSign, bSign, zSign; + Bit16s aExp, bExp, zExp; + Bit32u aSig, bSig, zSig; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + bSig = extractFloat32Frac(b); + bExp = extractFloat32Exp(b); + bSign = extractFloat32Sign(b); + zSign = aSign ^ bSign; + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + if (aExp == 0xFF) { + if (aSig) return propagateFloat32NaN(a, b, status); + if (bExp == 0xFF) { + if (bSig) return propagateFloat32NaN(a, b, status); + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloat32(zSign, 0xFF, 0); + } + if (bExp == 0xFF) { + if (bSig) return propagateFloat32NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat32(zSign, 0, 0); + } + if (bExp == 0) { + if (bSig == 0) { + if ((aExp | aSig) == 0) { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + float_raise(status, float_flag_divbyzero); + return packFloat32(zSign, 0xFF, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(bSig, &bExp, &bSig); + } + if (aExp == 0) { + if (aSig == 0) return packFloat32(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(aSig, &aExp, &aSig); + } + zExp = aExp - bExp + 0x7D; + aSig = (aSig | 0x00800000)<<7; + bSig = (bSig | 0x00800000)<<8; + if (bSig <= (aSig + aSig)) { + aSig >>= 1; + ++zExp; + } + zSig = (((Bit64u) aSig)<<32) / bSig; + if ((zSig & 0x3F) == 0) { + zSig |= ((Bit64u) bSig * zSig != ((Bit64u) aSig)<<32); + } + return roundAndPackFloat32(zSign, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the square root of the single-precision floating-point value `a'. +| The operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_sqrt(float32 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp, zExp; + Bit32u aSig, zSig; + Bit64u rem, term; + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + + if (aExp == 0xFF) { + if (aSig) return propagateFloat32NaNOne(a, status); + if (! aSign) return a; + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + } + + if (aSign) { + if ((aExp | aSig) == 0) return packFloat32(aSign, 0, 0); + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + if (aExp == 0) { + if (aSig == 0) return 0; + float_raise(status, float_flag_denormal); + normalizeFloat32Subnormal(aSig, &aExp, &aSig); + } + zExp = ((aExp - 0x7F)>>1) + 0x7E; + aSig = (aSig | 0x00800000)<<8; + zSig = estimateSqrt32(aExp, aSig) + 2; + if ((zSig & 0x7F) <= 5) { + if (zSig < 2) { + zSig = 0x7FFFFFFF; + goto roundAndPack; + } + aSig >>= aExp & 1; + term = ((Bit64u) zSig) * zSig; + rem = (((Bit64u) aSig)<<32) - term; + while ((Bit64s) rem < 0) { + --zSig; + rem += (((Bit64u) zSig)<<1) | 1; + } + zSig |= (rem != 0); + } + zSig = shift32RightJamming(zSig, 1); + roundAndPack: + return roundAndPackFloat32(0, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Determine single-precision floating-point number class. +*----------------------------------------------------------------------------*/ + +float_class_t float32_class(float32 a) +{ + Bit16s aExp = extractFloat32Exp(a); + Bit32u aSig = extractFloat32Frac(a); + int aSign = extractFloat32Sign(a); + + if(aExp == 0xFF) { + if (aSig == 0) + return (aSign) ? float_negative_inf : float_positive_inf; + + return (aSig & 0x00400000) ? float_QNaN : float_SNaN; + } + + if(aExp == 0) { + if (aSig == 0) return float_zero; + return float_denormal; + } + + return float_normalized; +} + +/*---------------------------------------------------------------------------- +| Compare between two single precision floating point numbers. Returns +| 'float_relation_equal' if the operands are equal, 'float_relation_less' if +| the value 'a' is less than the corresponding value `b', +| 'float_relation_greater' if the value 'a' is greater than the corresponding +| value `b', or 'float_relation_unordered' otherwise. +*----------------------------------------------------------------------------*/ + +int float32_compare(float32 a, float32 b, int quiet, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float32_denormal_to_zero(a); + b = float32_denormal_to_zero(b); + } + + float_class_t aClass = float32_class(a); + float_class_t bClass = float32_class(b); + + if (aClass == float_SNaN || bClass == float_SNaN) { + float_raise(status, float_flag_invalid); + return float_relation_unordered; + } + + if (aClass == float_QNaN || bClass == float_QNaN) { + if (! quiet) float_raise(status, float_flag_invalid); + return float_relation_unordered; + } + + if (aClass == float_denormal || bClass == float_denormal) { + float_raise(status, float_flag_denormal); + } + + if ((a == b) || ((Bit32u) ((a | b)<<1) == 0)) return float_relation_equal; + + int aSign = extractFloat32Sign(a); + int bSign = extractFloat32Sign(b); + if (aSign != bSign) + return (aSign) ? float_relation_less : float_relation_greater; + + if (aSign ^ (a < b)) return float_relation_less; + return float_relation_greater; +} + +/*---------------------------------------------------------------------------- +| Compare between two single precision floating point numbers and return the +| smaller of them. +*----------------------------------------------------------------------------*/ + +float32 float32_min(float32 a, float32 b, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float32_denormal_to_zero(a); + b = float32_denormal_to_zero(b); + } + + return (float32_compare_two(a, b, status) == float_relation_less) ? a : b; +} + +/*---------------------------------------------------------------------------- +| Compare between two single precision floating point numbers and return the +| larger of them. +*----------------------------------------------------------------------------*/ + +float32 float32_max(float32 a, float32 b, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float32_denormal_to_zero(a); + b = float32_denormal_to_zero(b); + } + + return (float32_compare_two(a, b, status) == float_relation_greater) ? a : b; +} + +/*---------------------------------------------------------------------------- +| Compare between two single precision floating point numbers and return the +| smaller/larger of them. The operation is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float32_minmax(float32 a, float32 b, int is_max, int is_abs, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float32_denormal_to_zero(a); + b = float32_denormal_to_zero(b); + } + + if (float32_is_nan(a) || float32_is_nan(b)) { + if (float32_is_signaling_nan(a)) { + return propagateFloat32NaNOne(a, status); + } + if (float32_is_signaling_nan(b) ) { + return propagateFloat32NaNOne(b, status); + } + if (! float32_is_nan(b)) { + if (float32_is_denormal(b)) + float_raise(status, float_flag_denormal); + return b; + } + if (! float32_is_nan(a)) { + if (float32_is_denormal(a)) + float_raise(status, float_flag_denormal); + return a; + } + return propagateFloat32NaN(a, b, status); + } + + float32 tmp_a = a, tmp_b = b; + if (is_abs) { + tmp_a &= ~0x80000000; // clear the sign bit + tmp_b &= ~0x80000000; + } + + int aSign = extractFloat32Sign(tmp_a); + int bSign = extractFloat32Sign(tmp_b); + + if (float32_is_denormal(a) || float32_is_denormal(b)) + float_raise(status, float_flag_denormal); + + if (aSign != bSign) { + if (! is_max) { + return aSign ? a : b; + } else { + return aSign ? b : a; + } + } else { + if (! is_max) { + return (aSign ^ (tmp_a < tmp_b)) ? a : b; + } else { + return (aSign ^ (tmp_a < tmp_b)) ? b : a; + } + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point value +| `a' to the 32-bit two's complement integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic - which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN or the +| conversion overflows, the integer indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit32s float64_to_int32(float64 a, struct float_status_t *status) +{ + Bit64u aSig = extractFloat64Frac(a); + Bit16s aExp = extractFloat64Exp(a); + int aSign = extractFloat64Sign(a); + if ((aExp == 0x7FF) && aSig) aSign = 0; + if (aExp) aSig |= BX_CONST64(0x0010000000000000); + else { + if (get_denormals_are_zeros(status)) aSig = 0; + } + int shiftCount = 0x42C - aExp; + if (0 < shiftCount) aSig = shift64RightJamming(aSig, shiftCount); + return roundAndPackInt32(aSign, aSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point value +| `a' to the 32-bit two's complement integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic, except that the conversion is always rounded toward zero. +| If `a' is a NaN or the conversion overflows, the integer indefinite +| value is returned. +*----------------------------------------------------------------------------*/ + +Bit32s float64_to_int32_round_to_zero(float64 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp; + Bit64u aSig, savedASig; + Bit32s z; + int shiftCount; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + if (0x41E < aExp) { + float_raise(status, float_flag_invalid); + return (Bit32s)(int32_indefinite); + } + else if (aExp < 0x3FF) { + if (get_denormals_are_zeros(status) && aExp == 0) aSig = 0; + if (aExp || aSig) float_raise(status, float_flag_inexact); + return 0; + } + aSig |= BX_CONST64(0x0010000000000000); + shiftCount = 0x433 - aExp; + savedASig = aSig; + aSig >>= shiftCount; + z = (Bit32s) aSig; + if (aSign) z = -z; + if ((z < 0) ^ aSign) { + float_raise(status, float_flag_invalid); + return (Bit32s)(int32_indefinite); + } + if ((aSig<>= shiftCount; + if ((aSig<>(-shiftCount); + if ((Bit64u) (aSig<<(shiftCount & 63))) { + float_raise(status, float_flag_inexact); + } + } + if (aSign) z = -z; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point value +| `a' to the 64-bit unsigned integer format. The conversion is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic, +| except that the conversion is always rounded toward zero. If `a' is a NaN +| or the conversion overflows, the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit64u float64_to_uint64_round_to_zero(float64 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp; + Bit64u aSig, z; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + + if (aExp < 0x3FE) { + if (get_denormals_are_zeros(status) && aExp == 0) aSig = 0; + if (aExp | aSig) float_raise(status, float_flag_inexact); + return 0; + } + + if (0x43E <= aExp || aSign) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + + if (aExp) aSig |= BX_CONST64(0x0010000000000000); + int shiftCount = aExp - 0x433; + + if (0 <= shiftCount) { + z = aSig<>(-shiftCount); + if ((Bit64u) (aSig<<(shiftCount & 63))) { + float_raise(status, float_flag_inexact); + } + } + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point value +| `a' to the 32-bit unsigned integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic---which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN or the conversion +| overflows, the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit32u float64_to_uint32(float64 a, struct float_status_t *status) +{ + Bit64u val_64 = float64_to_uint64(a, status); + + if (val_64 > 0xffffffff) { + status->float_exception_flags = float_flag_invalid; // throw away other flags + return uint32_indefinite; + } + + return (Bit32u) val_64; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point value +| `a' to the 64-bit unsigned integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic---which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN or the conversion +| overflows, the largest unsigned integer is returned. +*----------------------------------------------------------------------------*/ + +Bit64u float64_to_uint64(float64 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp, shiftCount; + Bit64u aSig, aSigExtra; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + } + + if (aSign && (aExp > 0x3FE)) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + + if (aExp) { + aSig |= BX_CONST64(0x0010000000000000); + } + shiftCount = 0x433 - aExp; + if (shiftCount <= 0) { + if (0x43E < aExp) { + float_raise(status, float_flag_invalid); + return uint64_indefinite; + } + aSigExtra = 0; + aSig <<= -shiftCount; + } else { + shift64ExtraRightJamming(aSig, 0, shiftCount, &aSig, &aSigExtra); + } + + return roundAndPackUint64(aSign, aSig, aSigExtra, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point value +| `a' to the single-precision floating-point format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float64_to_float32(float64 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp; + Bit64u aSig; + Bit32u zSig; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + if (aExp == 0x7FF) { + if (aSig) return commonNaNToFloat32(float64ToCommonNaN(a, status)); + return packFloat32(aSign, 0xFF, 0); + } + if (aExp == 0) { + if (aSig == 0 || get_denormals_are_zeros(status)) + return packFloat32(aSign, 0, 0); + float_raise(status, float_flag_denormal); + } + aSig = shift64RightJamming(aSig, 22); + zSig = (Bit32u) aSig; + if (aExp || zSig) { + zSig |= 0x40000000; + aExp -= 0x381; + } + return roundAndPackFloat32(aSign, aExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Rounds the double-precision floating-point value `a' to an integer, and +| returns the result as a double-precision floating-point value. The +| operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_round_to_int(float64 a, Bit8u scale, struct float_status_t *status) +{ + Bit64u lastBitMask, roundBitsMask; + int roundingMode = get_float_rounding_mode(status); + Bit16s aExp = extractFloat64Exp(a); + scale &= 0xf; + + if ((aExp == 0x7FF) && extractFloat64Frac(a)) { + return propagateFloat64NaNOne(a, status); + } + + aExp += scale; // scale the exponent + + if (0x433 <= aExp) { + return a; + } + + if (get_denormals_are_zeros(status)) { + a = float64_denormal_to_zero(a); + } + + if (aExp < 0x3FF) { + if ((Bit64u) (a<<1) == 0) return a; + float_raise(status, float_flag_inexact); + int aSign = extractFloat64Sign(a); + switch (roundingMode) { + case float_round_nearest_even: + if ((aExp == 0x3FE) && extractFloat64Frac(a)) { + return packFloat64(aSign, 0x3FF - scale, 0); + } + break; + case float_round_down: + return aSign ? packFloat64(1, 0x3FF - scale, 0) : float64_positive_zero; + case float_round_up: + return aSign ? float64_negative_zero : packFloat64(0, 0x3FF - scale, 0); + } + return packFloat64(aSign, 0, 0); + } + + lastBitMask = 1; + lastBitMask <<= 0x433 - aExp; + roundBitsMask = lastBitMask - 1; + float64 z = a; + if (roundingMode == float_round_nearest_even) { + z += lastBitMask>>1; + if ((z & roundBitsMask) == 0) z &= ~lastBitMask; + } + else if (roundingMode != float_round_to_zero) { + if (extractFloat64Sign(z) ^ (roundingMode == float_round_up)) { + z += roundBitsMask; + } + } + z &= ~roundBitsMask; + if (z != a) float_raise(status, float_flag_inexact); + return z; +} + +/*---------------------------------------------------------------------------- +| Extracts the fractional portion of double-precision floating-point value `a', +| and returns the result as a double-precision floating-point value. The +| fractional results are precise. The operation is performed according to the +| IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_frc(float64 a, struct float_status_t *status) +{ + int roundingMode = get_float_rounding_mode(status); + + Bit64u aSig = extractFloat64Frac(a); + Bit16s aExp = extractFloat64Exp(a); + int aSign = extractFloat64Sign(a); + + if (aExp == 0x7FF) { + if (aSig) return propagateFloat64NaNOne(a, status); + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + + if (aExp >= 0x433) { + return packFloat64(roundingMode == float_round_down, 0, 0); + } + + if (aExp < 0x3FF) { + if (aExp == 0) { + if (aSig == 0 || get_denormals_are_zeros(status)) + return packFloat64(roundingMode == float_round_down, 0, 0); + + float_raise(status, float_flag_denormal); + if (! float_exception_masked(status, float_flag_underflow)) + float_raise(status, float_flag_underflow); + + if(get_flush_underflow_to_zero(status)) { + float_raise(status, float_flag_underflow | float_flag_inexact); + return packFloat64(aSign, 0, 0); + } + } + return a; + } + + Bit64u lastBitMask = BX_CONST64(1) << (0x433 - aExp); + Bit64u roundBitsMask = lastBitMask - 1; + + aSig &= roundBitsMask; + aSig <<= 10; + aExp--; + + if (aSig == 0) + return packFloat64(roundingMode == float_round_down, 0, 0); + + return normalizeRoundAndPackFloat64(aSign, aExp, aSig, status); +} + +/*---------------------------------------------------------------------------- +| Extracts the exponent portion of double-precision floating-point value 'a', +| and returns the result as a double-precision floating-point value +| representing unbiased integer exponent. The operation is performed according +| to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_getexp(float64 a, struct float_status_t *status) +{ + Bit16s aExp = extractFloat64Exp(a); + Bit64u aSig = extractFloat64Frac(a); + + if (aExp == 0x7FF) { + if (aSig) return propagateFloat64NaNOne(a, status); + return float64_positive_inf; + } + + if (aExp == 0) { + if (aSig == 0 || get_denormals_are_zeros(status)) + return float64_negative_inf; + + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(aSig, &aExp, &aSig); + } + + return int32_to_float64(aExp - 0x3FF); +} + +/*---------------------------------------------------------------------------- +| Extracts the mantissa of double-precision floating-point value 'a' and +| returns the result as a double-precision floating-point after applying +| the mantissa interval normalization and sign control. The operation is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_getmant(float64 a, struct float_status_t *status, int sign_ctrl, int interv) +{ + Bit16s aExp = extractFloat64Exp(a); + Bit64u aSig = extractFloat64Frac(a); + int aSign = extractFloat64Sign(a); + + if (aExp == 0x7FF) { + if (aSig) return propagateFloat64NaNOne(a, status); + if (aSign) { + if (sign_ctrl & 0x2) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + } + return packFloat64(~sign_ctrl & aSign, 0x3FF, 0); + } + + if (aExp == 0 && (aSig == 0 || get_denormals_are_zeros(status))) { + return packFloat64(~sign_ctrl & aSign, 0x3FF, 0); + } + + if (aSign) { + if (sign_ctrl & 0x2) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + } + + if (aExp == 0) { + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(aSig, &aExp, &aSig); +// aExp += 0x3FE; + aSig &= BX_CONST64(0xFFFFFFFFFFFFFFFF); + } + + switch(interv) { + case 0x0: // interval [1,2) + aExp = 0x3FF; + break; + case 0x1: // interval [1/2,2) + aExp -= 0x3FF; + aExp = 0x3FF - (aExp & 0x1); + break; + case 0x2: // interval [1/2,1) + aExp = 0x3FE; + break; + case 0x3: // interval [3/4,3/2) + aExp = 0x3FF - ((aSig >> 51) & 0x1); + break; + } + + return packFloat64(~sign_ctrl & aSign, aExp, aSig); +} + +/*---------------------------------------------------------------------------- +| Return the result of a floating point scale of the double-precision floating +| point value `a' by multiplying it by 2 power of the double-precision +| floating point value 'b' converted to integral value. If the result cannot +| be represented in double precision, then the proper overflow response (for +| positive scaling operand), or the proper underflow response (for negative +| scaling operand) is issued. The operation is performed according to the +| IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_scalef(float64 a, float64 b, struct float_status_t *status) +{ + Bit64u aSig = extractFloat64Frac(a); + Bit16s aExp = extractFloat64Exp(a); + int aSign = extractFloat64Sign(a); + Bit64u bSig = extractFloat64Frac(b); + Bit16s bExp = extractFloat64Exp(b); + int bSign = extractFloat64Sign(b); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + if (bExp == 0x7FF) { + if (bSig) return propagateFloat64NaN(a, b, status); + } + + if (aExp == 0x7FF) { + if (aSig) { + int aIsSignalingNaN = (aSig & BX_CONST64(0x0008000000000000)) == 0; + if (aIsSignalingNaN || bExp != 0x7FF || bSig) + return propagateFloat64NaN(a, b, status); + + return bSign ? 0 : float64_positive_inf; + } + + if (bExp == 0x7FF && bSign) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + return a; + } + + if (aExp == 0) { + if (aSig == 0) { + if (bExp == 0x7FF && ! bSign) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + return a; + } + float_raise(status, float_flag_denormal); + } + + if ((bExp | bSig) == 0) return a; + + if (bExp == 0x7FF) { + if (bSign) return packFloat64(aSign, 0, 0); + return packFloat64(aSign, 0x7FF, 0); + } + + if (0x40F <= bExp) { + // handle obvious overflow/underflow result + return roundAndPackFloat64(aSign, bSign ? -0x3FF : 0x7FF, aSig, status); + } + + int scale = 0; + + if (bExp < 0x3FF) { + if (bExp == 0) + float_raise(status, float_flag_denormal); + scale = -bSign; + } + else { + bSig |= BX_CONST64(0x0010000000000000); + int shiftCount = 0x433 - bExp; + Bit64u savedBSig = bSig; + bSig >>= shiftCount; + scale = (Bit32s) bSig; + if (bSign) { + if ((bSig< 0x1000) scale = 0x1000; + if (scale < -0x1000) scale = -0x1000; + } + + if (aExp != 0) { + aSig |= BX_CONST64(0x0010000000000000); + } else { + aExp++; + } + + aExp += scale - 1; + aSig <<= 10; + return normalizeRoundAndPackFloat64(aSign, aExp, aSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the absolute values of the double-precision +| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated +| before being returned. `zSign' is ignored if the result is a NaN. +| The addition is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static float64 addFloat64Sigs(float64 a, float64 b, int zSign, struct float_status_t *status) +{ + Bit16s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig; + Bit16s expDiff; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + bSig = extractFloat64Frac(b); + bExp = extractFloat64Exp(b); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + expDiff = aExp - bExp; + aSig <<= 9; + bSig <<= 9; + if (0 < expDiff) { + if (aExp == 0x7FF) { + if (aSig) return propagateFloat64NaN(a, b, status); + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return a; + } + if ((aExp == 0) && aSig) + float_raise(status, float_flag_denormal); + + if (bExp == 0) { + if (bSig) float_raise(status, float_flag_denormal); + --expDiff; + } + else bSig |= BX_CONST64(0x2000000000000000); + + bSig = shift64RightJamming(bSig, expDiff); + zExp = aExp; + } + else if (expDiff < 0) { + if (bExp == 0x7FF) { + if (bSig) return propagateFloat64NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat64(zSign, 0x7FF, 0); + } + if ((bExp == 0) && bSig) + float_raise(status, float_flag_denormal); + + if (aExp == 0) { + if (aSig) float_raise(status, float_flag_denormal); + ++expDiff; + } + else aSig |= BX_CONST64(0x2000000000000000); + + aSig = shift64RightJamming(aSig, -expDiff); + zExp = bExp; + } + else { + if (aExp == 0x7FF) { + if (aSig | bSig) return propagateFloat64NaN(a, b, status); + return a; + } + if (aExp == 0) { + zSig = (aSig + bSig) >> 9; + if (aSig | bSig) { + float_raise(status, float_flag_denormal); + if (get_flush_underflow_to_zero(status) && (extractFloat64Frac(zSig) == zSig)) { + float_raise(status, float_flag_underflow | float_flag_inexact); + return packFloat64(zSign, 0, 0); + } + if (! float_exception_masked(status, float_flag_underflow)) { + if (extractFloat64Frac(zSig) == zSig) + float_raise(status, float_flag_underflow); + } + } + return packFloat64(zSign, 0, zSig); + } + zSig = BX_CONST64(0x4000000000000000) + aSig + bSig; + return roundAndPackFloat64(zSign, aExp, zSig, status); + } + aSig |= BX_CONST64(0x2000000000000000); + zSig = (aSig + bSig)<<1; + --zExp; + if ((Bit64s) zSig < 0) { + zSig = aSig + bSig; + ++zExp; + } + return roundAndPackFloat64(zSign, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the absolute values of the double- +| precision floating-point values `a' and `b'. If `zSign' is 1, the +| difference is negated before being returned. `zSign' is ignored if the +| result is a NaN. The subtraction is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static float64 subFloat64Sigs(float64 a, float64 b, int zSign, struct float_status_t *status) +{ + Bit16s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig; + Bit16s expDiff; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + bSig = extractFloat64Frac(b); + bExp = extractFloat64Exp(b); + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + expDiff = aExp - bExp; + aSig <<= 10; + bSig <<= 10; + if (0 < expDiff) goto aExpBigger; + if (expDiff < 0) goto bExpBigger; + if (aExp == 0x7FF) { + if (aSig | bSig) return propagateFloat64NaN(a, b, status); + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + if (aExp == 0) { + if (aSig | bSig) float_raise(status, float_flag_denormal); + aExp = 1; + bExp = 1; + } + if (bSig < aSig) goto aBigger; + if (aSig < bSig) goto bBigger; + return packFloat64(get_float_rounding_mode(status) == float_round_down, 0, 0); + bExpBigger: + if (bExp == 0x7FF) { + if (bSig) return propagateFloat64NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat64(zSign ^ 1, 0x7FF, 0); + } + if ((bExp == 0) && bSig) + float_raise(status, float_flag_denormal); + + if (aExp == 0) { + if (aSig) float_raise(status, float_flag_denormal); + ++expDiff; + } + else aSig |= BX_CONST64(0x4000000000000000); + + aSig = shift64RightJamming(aSig, -expDiff); + bSig |= BX_CONST64(0x4000000000000000); + bBigger: + zSig = bSig - aSig; + zExp = bExp; + zSign ^= 1; + goto normalizeRoundAndPack; + aExpBigger: + if (aExp == 0x7FF) { + if (aSig) return propagateFloat64NaN(a, b, status); + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return a; + } + if ((aExp == 0) && aSig) + float_raise(status, float_flag_denormal); + + if (bExp == 0) { + if (bSig) float_raise(status, float_flag_denormal); + --expDiff; + } + else bSig |= BX_CONST64(0x4000000000000000); + + bSig = shift64RightJamming(bSig, expDiff); + aSig |= BX_CONST64(0x4000000000000000); + aBigger: + zSig = aSig - bSig; + zExp = aExp; + normalizeRoundAndPack: + --zExp; + return normalizeRoundAndPackFloat64(zSign, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the double-precision floating-point values `a' +| and `b'. The operation is performed according to the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_add(float64 a, float64 b, struct float_status_t *status) +{ + int aSign = extractFloat64Sign(a); + int bSign = extractFloat64Sign(b); + + if (aSign == bSign) { + return addFloat64Sigs(a, b, aSign, status); + } + else { + return subFloat64Sigs(a, b, aSign, status); + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the double-precision floating-point values +| `a' and `b'. The operation is performed according to the IEC/IEEE Standard +| for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_sub(float64 a, float64 b, struct float_status_t *status) +{ + int aSign = extractFloat64Sign(a); + int bSign = extractFloat64Sign(b); + + if (aSign == bSign) { + return subFloat64Sigs(a, b, aSign, status); + } + else { + return addFloat64Sigs(a, b, aSign, status); + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of multiplying the double-precision floating-point values +| `a' and `b'. The operation is performed according to the IEC/IEEE Standard +| for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_mul(float64 a, float64 b, struct float_status_t *status) +{ + int aSign, bSign, zSign; + Bit16s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig0, zSig1; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + bSig = extractFloat64Frac(b); + bExp = extractFloat64Exp(b); + bSign = extractFloat64Sign(b); + zSign = aSign ^ bSign; + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + if (aExp == 0x7FF) { + if (aSig || ((bExp == 0x7FF) && bSig)) { + return propagateFloat64NaN(a, b, status); + } + if ((bExp | bSig) == 0) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloat64(zSign, 0x7FF, 0); + } + if (bExp == 0x7FF) { + if (bSig) return propagateFloat64NaN(a, b, status); + if ((aExp | aSig) == 0) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat64(zSign, 0x7FF, 0); + } + if (aExp == 0) { + if (aSig == 0) { + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloat64(zSign, 0, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + if (bSig == 0) return packFloat64(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(bSig, &bExp, &bSig); + } + zExp = aExp + bExp - 0x3FF; + aSig = (aSig | BX_CONST64(0x0010000000000000))<<10; + bSig = (bSig | BX_CONST64(0x0010000000000000))<<11; + mul64To128(aSig, bSig, &zSig0, &zSig1); + zSig0 |= (zSig1 != 0); + if (0 <= (Bit64s) (zSig0<<1)) { + zSig0 <<= 1; + --zExp; + } + return roundAndPackFloat64(zSign, zExp, zSig0, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of dividing the double-precision floating-point value `a' +| by the corresponding value `b'. The operation is performed according to +| the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_div(float64 a, float64 b, struct float_status_t *status) +{ + int aSign, bSign, zSign; + Bit16s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig; + Bit64u rem0, rem1; + Bit64u term0, term1; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + bSig = extractFloat64Frac(b); + bExp = extractFloat64Exp(b); + bSign = extractFloat64Sign(b); + zSign = aSign ^ bSign; + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + if (bExp == 0) bSig = 0; + } + + if (aExp == 0x7FF) { + if (aSig) return propagateFloat64NaN(a, b, status); + if (bExp == 0x7FF) { + if (bSig) return propagateFloat64NaN(a, b, status); + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloat64(zSign, 0x7FF, 0); + } + if (bExp == 0x7FF) { + if (bSig) return propagateFloat64NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloat64(zSign, 0, 0); + } + if (bExp == 0) { + if (bSig == 0) { + if ((aExp | aSig) == 0) { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + float_raise(status, float_flag_divbyzero); + return packFloat64(zSign, 0x7FF, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(bSig, &bExp, &bSig); + } + if (aExp == 0) { + if (aSig == 0) return packFloat64(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(aSig, &aExp, &aSig); + } + zExp = aExp - bExp + 0x3FD; + aSig = (aSig | BX_CONST64(0x0010000000000000))<<10; + bSig = (bSig | BX_CONST64(0x0010000000000000))<<11; + if (bSig <= (aSig + aSig)) { + aSig >>= 1; + ++zExp; + } + zSig = estimateDiv128To64(aSig, 0, bSig); + if ((zSig & 0x1FF) <= 2) { + mul64To128(bSig, zSig, &term0, &term1); + sub128(aSig, 0, term0, term1, &rem0, &rem1); + while ((Bit64s) rem0 < 0) { + --zSig; + add128(rem0, rem1, 0, bSig, &rem0, &rem1); + } + zSig |= (rem1 != 0); + } + return roundAndPackFloat64(zSign, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the square root of the double-precision floating-point value `a'. +| The operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_sqrt(float64 a, struct float_status_t *status) +{ + int aSign; + Bit16s aExp, zExp; + Bit64u aSig, zSig, doubleZSig; + Bit64u rem0, rem1, term0, term1; + + aSig = extractFloat64Frac(a); + aExp = extractFloat64Exp(a); + aSign = extractFloat64Sign(a); + + if (aExp == 0x7FF) { + if (aSig) return propagateFloat64NaNOne(a, status); + if (! aSign) return a; + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + + if (get_denormals_are_zeros(status)) { + if (aExp == 0) aSig = 0; + } + + if (aSign) { + if ((aExp | aSig) == 0) return packFloat64(aSign, 0, 0); + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + if (aExp == 0) { + if (aSig == 0) return 0; + float_raise(status, float_flag_denormal); + normalizeFloat64Subnormal(aSig, &aExp, &aSig); + } + zExp = ((aExp - 0x3FF)>>1) + 0x3FE; + aSig |= BX_CONST64(0x0010000000000000); + zSig = estimateSqrt32(aExp, (Bit32u)(aSig>>21)); + aSig <<= 9 - (aExp & 1); + zSig = estimateDiv128To64(aSig, 0, zSig<<32) + (zSig<<30); + if ((zSig & 0x1FF) <= 5) { + doubleZSig = zSig<<1; + mul64To128(zSig, zSig, &term0, &term1); + sub128(aSig, 0, term0, term1, &rem0, &rem1); + while ((Bit64s) rem0 < 0) { + --zSig; + doubleZSig -= 2; + add128(rem0, rem1, zSig>>63, doubleZSig | 1, &rem0, &rem1); + } + zSig |= ((rem0 | rem1) != 0); + } + return roundAndPackFloat64(0, zExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Determine double-precision floating-point number class +*----------------------------------------------------------------------------*/ + +float_class_t float64_class(float64 a) +{ + Bit16s aExp = extractFloat64Exp(a); + Bit64u aSig = extractFloat64Frac(a); + int aSign = extractFloat64Sign(a); + + if(aExp == 0x7FF) { + if (aSig == 0) + return (aSign) ? float_negative_inf : float_positive_inf; + + return (aSig & BX_CONST64(0x0008000000000000)) ? float_QNaN : float_SNaN; + } + + if(aExp == 0) { + if (aSig == 0) + return float_zero; + return float_denormal; + } + + return float_normalized; +} + +/*---------------------------------------------------------------------------- +| Compare between two double precision floating point numbers. Returns +| 'float_relation_equal' if the operands are equal, 'float_relation_less' if +| the value 'a' is less than the corresponding value `b', +| 'float_relation_greater' if the value 'a' is greater than the corresponding +| value `b', or 'float_relation_unordered' otherwise. +*----------------------------------------------------------------------------*/ + +int float64_compare(float64 a, float64 b, int quiet, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float64_denormal_to_zero(a); + b = float64_denormal_to_zero(b); + } + + float_class_t aClass = float64_class(a); + float_class_t bClass = float64_class(b); + + if (aClass == float_SNaN || bClass == float_SNaN) { + float_raise(status, float_flag_invalid); + return float_relation_unordered; + } + + if (aClass == float_QNaN || bClass == float_QNaN) { + if (! quiet) float_raise(status, float_flag_invalid); + return float_relation_unordered; + } + + if (aClass == float_denormal || bClass == float_denormal) { + float_raise(status, float_flag_denormal); + } + + if ((a == b) || ((Bit64u) ((a | b)<<1) == 0)) return float_relation_equal; + + int aSign = extractFloat64Sign(a); + int bSign = extractFloat64Sign(b); + if (aSign != bSign) + return (aSign) ? float_relation_less : float_relation_greater; + + if (aSign ^ (a < b)) return float_relation_less; + return float_relation_greater; +} + +/*---------------------------------------------------------------------------- +| Compare between two double precision floating point numbers and return the +| smaller of them. +*----------------------------------------------------------------------------*/ + +float64 float64_min(float64 a, float64 b, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float64_denormal_to_zero(a); + b = float64_denormal_to_zero(b); + } + + return (float64_compare_two(a, b, status) == float_relation_less) ? a : b; +} + +/*---------------------------------------------------------------------------- +| Compare between two double precision floating point numbers and return the +| larger of them. +*----------------------------------------------------------------------------*/ + +float64 float64_max(float64 a, float64 b, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float64_denormal_to_zero(a); + b = float64_denormal_to_zero(b); + } + + return (float64_compare_two(a, b, status) == float_relation_greater) ? a : b; +} + +/*---------------------------------------------------------------------------- +| Compare between two double precision floating point numbers and return the +| smaller/larger of them. The operation is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 float64_minmax(float64 a, float64 b, int is_max, int is_abs, struct float_status_t *status) +{ + if (get_denormals_are_zeros(status)) { + a = float64_denormal_to_zero(a); + b = float64_denormal_to_zero(b); + } + + if (float64_is_nan(a) || float64_is_nan(b)) { + if (float64_is_signaling_nan(a)) { + return propagateFloat64NaNOne(a, status); + } + if (float64_is_signaling_nan(b)) { + return propagateFloat64NaNOne(b, status); + } + if (! float64_is_nan(b)) { + if (float64_is_denormal(b)) + float_raise(status, float_flag_denormal); + return b; + } + if (! float64_is_nan(a)) { + if (float64_is_denormal(a)) + float_raise(status, float_flag_denormal); + return a; + } + return propagateFloat64NaN(a, b, status); + } + + float64 tmp_a = a, tmp_b = b; + if (is_abs) { + tmp_a &= ~BX_CONST64(0x8000000000000000); // clear the sign bit + tmp_b &= ~BX_CONST64(0x8000000000000000); + } + + int aSign = extractFloat64Sign(tmp_a); + int bSign = extractFloat64Sign(tmp_b); + + if (float64_is_denormal(a) || float64_is_denormal(b)) + float_raise(status, float_flag_denormal); + + if (aSign != bSign) { + if (! is_max) { + return aSign ? a : b; + } else { + return aSign ? b : a; + } + } else { + if (! is_max) { + return (aSign ^ (tmp_a < tmp_b)) ? a : b; + } else { + return (aSign ^ (tmp_a < tmp_b)) ? b : a; + } + } +} + +#ifdef FLOATX80 + +/*---------------------------------------------------------------------------- +| Returns the result of converting the 32-bit two's complement integer `a' +| to the extended double-precision floating-point format. The conversion +| is performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 int32_to_floatx80(Bit32s a) +{ + if (a == 0) return packFloatx80(0, 0, 0); + int zSign = (a < 0); + Bit32u absA = zSign ? -a : a; + int shiftCount = countLeadingZeros32(absA) + 32; + Bit64u zSig = absA; + return packFloatx80(zSign, 0x403E - shiftCount, zSig< 0x401E) { + float_raise(status, float_flag_invalid); + return (Bit32s)(int32_indefinite); + } + if (aExp < 0x3FFF) { + if (aExp || aSig) float_raise(status, float_flag_inexact); + return 0; + } + shiftCount = 0x403E - aExp; + savedASig = aSig; + aSig >>= shiftCount; + z = (Bit32s) aSig; + if (aSign) z = -z; + if ((z < 0) ^ aSign) { + float_raise(status, float_flag_invalid); + return (Bit32s)(int32_indefinite); + } + if ((aSig<>(-shiftCount); + if ((Bit64u) (aSig<<(shiftCount & 63))) { + float_raise(status, float_flag_inexact); + } + if (aSign) z = -z; + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the extended double-precision floating- +| point value `a' to the single-precision floating-point format. The +| conversion is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 floatx80_to_float32(floatx80 a, struct float_status_t *status) +{ + Bit64u aSig = extractFloatx80Frac(a); + Bit32s aExp = extractFloatx80Exp(a); + int aSign = extractFloatx80Sign(a); + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a)) + { + float_raise(status, float_flag_invalid); + return float32_default_nan; + } + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1)) + return commonNaNToFloat32(floatx80ToCommonNaN(a, status)); + + return packFloat32(aSign, 0xFF, 0); + } + aSig = shift64RightJamming(aSig, 33); + if (aExp || aSig) aExp -= 0x3F81; + return roundAndPackFloat32(aSign, aExp, (Bit32u) aSig, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the extended double-precision floating- +| point value `a' to the double-precision floating-point format. The +| conversion is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float64 floatx80_to_float64(floatx80 a, struct float_status_t *status) +{ + Bit32s aExp; + Bit64u aSig, zSig; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a)) + { + float_raise(status, float_flag_invalid); + return float64_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + int aSign = extractFloatx80Sign(a); + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1)) { + return commonNaNToFloat64(floatx80ToCommonNaN(a, status)); + } + return packFloat64(aSign, 0x7FF, 0); + } + zSig = shift64RightJamming(aSig, 1); + if (aExp || aSig) aExp -= 0x3C01; + return roundAndPackFloat64(aSign, aExp, zSig, status); +} + +/*---------------------------------------------------------------------------- +| Rounds the extended double-precision floating-point value `a' to an integer, +| and returns the result as an extended double-precision floating-point +| value. The operation is performed according to the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_round_to_int(floatx80 a, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + int aSign; + Bit64u lastBitMask, roundBitsMask; + int roundingMode = get_float_rounding_mode(status); + floatx80 z; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a)) + { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + Bit32s aExp = extractFloatx80Exp(a); + Bit64u aSig = extractFloatx80Frac(a); + if (0x403E <= aExp) { + if ((aExp == 0x7FFF) && (Bit64u) (aSig<<1)) { + return propagateFloatx80NaNOne(a, status); + } + return a; + } + if (aExp < 0x3FFF) { + if (aExp == 0) { + if ((aSig<<1) == 0) return a; + float_raise(status, float_flag_denormal); + } + float_raise(status, float_flag_inexact); + aSign = extractFloatx80Sign(a); + switch (roundingMode) { + case float_round_nearest_even: + if ((aExp == 0x3FFE) && (Bit64u) (aSig<<1)) { + set_float_rounding_up(status); + return packFloatx80(aSign, 0x3FFF, BX_CONST64(0x8000000000000000)); + } + break; + case float_round_down: + if (aSign) { + set_float_rounding_up(status); + return packFloatx80(1, 0x3FFF, BX_CONST64(0x8000000000000000)); + } + else { + return packFloatx80(0, 0, 0); + } + case float_round_up: + if (aSign) { + return packFloatx80(1, 0, 0); + } + else { + set_float_rounding_up(status); + return packFloatx80(0, 0x3FFF, BX_CONST64(0x8000000000000000)); + } + } + return packFloatx80(aSign, 0, 0); + } + lastBitMask = 1; + lastBitMask <<= 0x403E - aExp; + roundBitsMask = lastBitMask - 1; + z = a; + if (roundingMode == float_round_nearest_even) { + z.fraction += lastBitMask>>1; + if ((z.fraction & roundBitsMask) == 0) z.fraction &= ~lastBitMask; + } + else if (roundingMode != float_round_to_zero) { + if (extractFloatx80Sign(z) ^ (roundingMode == float_round_up)) + z.fraction += roundBitsMask; + } + z.fraction &= ~roundBitsMask; + if (z.fraction == 0) { + z.exp++; + z.fraction = BX_CONST64(0x8000000000000000); + } + if (z.fraction != a.fraction) { + float_raise(status, float_flag_inexact); + if (z.fraction > a.fraction || z.exp > a.exp) + set_float_rounding_up(status); + } + return z; +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the absolute values of the extended double- +| precision floating-point values `a' and `b'. If `zSign' is 1, the sum is +| negated before being returned. `zSign' is ignored if the result is a NaN. +| The addition is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static floatx80 addFloatx80Sigs(floatx80 a, floatx80 b, int zSign, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit32s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig0, zSig1; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) + { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1) || ((bExp == 0x7FFF) && (Bit64u) (bSig<<1))) + return propagateFloatx80NaN(a, b, status); + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return a; + } + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) { + if (aSig == 0) { + if ((bExp == 0) && bSig) { + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + return roundAndPackFloatx80(get_float_rounding_precision(status), + zSign, bExp, bSig, 0, status); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + if (bSig == 0) + return roundAndPackFloatx80(get_float_rounding_precision(status), + zSign, aExp, aSig, 0, status); + + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + Bit32s expDiff = aExp - bExp; + zExp = aExp; + if (0 < expDiff) { + shift64ExtraRightJamming(bSig, 0, expDiff, &bSig, &zSig1); + } + else if (expDiff < 0) { + shift64ExtraRightJamming(aSig, 0, -expDiff, &aSig, &zSig1); + zExp = bExp; + } + else { + zSig0 = aSig + bSig; + zSig1 = 0; + goto shiftRight1; + } + zSig0 = aSig + bSig; + if ((Bit64s) zSig0 < 0) goto roundAndPack; + shiftRight1: + shift64ExtraRightJamming(zSig0, zSig1, 1, &zSig0, &zSig1); + zSig0 |= BX_CONST64(0x8000000000000000); + zExp++; + roundAndPack: + return + roundAndPackFloatx80(get_float_rounding_precision(status), + zSign, zExp, zSig0, zSig1, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the absolute values of the extended +| double-precision floating-point values `a' and `b'. If `zSign' is 1, the +| difference is negated before being returned. `zSign' is ignored if the +| result is a NaN. The subtraction is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static floatx80 subFloatx80Sigs(floatx80 a, floatx80 b, int zSign, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit32s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig0, zSig1; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) + { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1)) return propagateFloatx80NaN(a, b, status); + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return a; + } + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloatx80(zSign ^ 1, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) { + if (aSig == 0) { + if (bExp == 0) { + if (bSig) { + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + return roundAndPackFloatx80(get_float_rounding_precision(status), + zSign ^ 1, bExp, bSig, 0, status); + } + return packFloatx80(get_float_rounding_mode(status) == float_round_down, 0, 0); + } + return roundAndPackFloatx80(get_float_rounding_precision(status), + zSign ^ 1, bExp, bSig, 0, status); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + if (bSig == 0) + return roundAndPackFloatx80(get_float_rounding_precision(status), + zSign, aExp, aSig, 0, status); + + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + Bit32s expDiff = aExp - bExp; + if (0 < expDiff) { + shift128RightJamming(bSig, 0, expDiff, &bSig, &zSig1); + goto aBigger; + } + if (expDiff < 0) { + shift128RightJamming(aSig, 0, -expDiff, &aSig, &zSig1); + goto bBigger; + } + zSig1 = 0; + if (bSig < aSig) goto aBigger; + if (aSig < bSig) goto bBigger; + return packFloatx80(get_float_rounding_mode(status) == float_round_down, 0, 0); + bBigger: + sub128(bSig, 0, aSig, zSig1, &zSig0, &zSig1); + zExp = bExp; + zSign ^= 1; + goto normalizeRoundAndPack; + aBigger: + sub128(aSig, 0, bSig, zSig1, &zSig0, &zSig1); + zExp = aExp; + normalizeRoundAndPack: + return + normalizeRoundAndPackFloatx80(get_float_rounding_precision(status), + zSign, zExp, zSig0, zSig1, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the extended double-precision floating-point +| values `a' and `b'. The operation is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_add(floatx80 a, floatx80 b, struct float_status_t *status) +{ + int aSign = extractFloatx80Sign(a); + int bSign = extractFloatx80Sign(b); + + if (aSign == bSign) + return addFloatx80Sigs(a, b, aSign, status); + else + return subFloatx80Sigs(a, b, aSign, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the extended double-precision floating- +| point values `a' and `b'. The operation is performed according to the +| IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_sub(floatx80 a, floatx80 b, struct float_status_t *status) +{ + int aSign = extractFloatx80Sign(a); + int bSign = extractFloatx80Sign(b); + + if (aSign == bSign) + return subFloatx80Sigs(a, b, aSign, status); + else + return addFloatx80Sigs(a, b, aSign, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of multiplying the extended double-precision floating- +| point values `a' and `b'. The operation is performed according to the +| IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_mul(floatx80 a, floatx80 b, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + int aSign, bSign, zSign; + Bit32s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig0, zSig1; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) + { + invalid: + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + bSign = extractFloatx80Sign(b); + zSign = aSign ^ bSign; + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1) || ((bExp == 0x7FFF) && (Bit64u) (bSig<<1))) { + return propagateFloatx80NaN(a, b, status); + } + if (bExp == 0) { + if (bSig == 0) goto invalid; + float_raise(status, float_flag_denormal); + } + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + if (aExp == 0) { + if (aSig == 0) goto invalid; + float_raise(status, float_flag_denormal); + } + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) { + if (aSig == 0) { + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloatx80(zSign, 0, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + if (bSig == 0) return packFloatx80(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + zExp = aExp + bExp - 0x3FFE; + mul64To128(aSig, bSig, &zSig0, &zSig1); + if (0 < (Bit64s) zSig0) { + shortShift128Left(zSig0, zSig1, 1, &zSig0, &zSig1); + --zExp; + } + return + roundAndPackFloatx80(get_float_rounding_precision(status), + zSign, zExp, zSig0, zSig1, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of dividing the extended double-precision floating-point +| value `a' by the corresponding value `b'. The operation is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_div(floatx80 a, floatx80 b, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + int aSign, bSign, zSign; + Bit32s aExp, bExp, zExp; + Bit64u aSig, bSig, zSig0, zSig1; + Bit64u rem0, rem1, rem2, term0, term1, term2; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) + { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + bSign = extractFloatx80Sign(b); + + zSign = aSign ^ bSign; + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1)) return propagateFloatx80NaN(a, b, status); + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + return packFloatx80(zSign, 0, 0); + } + if (bExp == 0) { + if (bSig == 0) { + if ((aExp | aSig) == 0) { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + float_raise(status, float_flag_divbyzero); + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + if (aExp == 0) { + if (aSig == 0) return packFloatx80(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + zExp = aExp - bExp + 0x3FFE; + rem1 = 0; + if (bSig <= aSig) { + shift128Right(aSig, 0, 1, &aSig, &rem1); + ++zExp; + } + zSig0 = estimateDiv128To64(aSig, rem1, bSig); + mul64To128(bSig, zSig0, &term0, &term1); + sub128(aSig, rem1, term0, term1, &rem0, &rem1); + while ((Bit64s) rem0 < 0) { + --zSig0; + add128(rem0, rem1, 0, bSig, &rem0, &rem1); + } + zSig1 = estimateDiv128To64(rem1, 0, bSig); + if ((Bit64u) (zSig1<<1) <= 8) { + mul64To128(bSig, zSig1, &term1, &term2); + sub128(rem1, 0, term1, term2, &rem1, &rem2); + while ((Bit64s) rem1 < 0) { + --zSig1; + add128(rem1, rem2, 0, bSig, &rem1, &rem2); + } + zSig1 |= ((rem1 | rem2) != 0); + } + return + roundAndPackFloatx80(get_float_rounding_precision(status), + zSign, zExp, zSig0, zSig1, status); +} + +/*---------------------------------------------------------------------------- +| Returns the square root of the extended double-precision floating-point +| value `a'. The operation is performed according to the IEC/IEEE Standard +| for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_sqrt(floatx80 a, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + int aSign; + Bit32s aExp, zExp; + Bit64u aSig0, aSig1, zSig0, zSig1, doubleZSig0; + Bit64u rem0, rem1, rem2, rem3, term0, term1, term2, term3; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a)) + { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig0 = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig0<<1)) return propagateFloatx80NaNOne(a, status); + if (! aSign) return a; + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + if (aSign) { + if ((aExp | aSig0) == 0) return a; + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + if (aExp == 0) { + if (aSig0 == 0) return packFloatx80(0, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); + } + zExp = ((aExp - 0x3FFF)>>1) + 0x3FFF; + zSig0 = estimateSqrt32(aExp, aSig0>>32); + shift128Right(aSig0, 0, 2 + (aExp & 1), &aSig0, &aSig1); + zSig0 = estimateDiv128To64(aSig0, aSig1, zSig0<<32) + (zSig0<<30); + doubleZSig0 = zSig0<<1; + mul64To128(zSig0, zSig0, &term0, &term1); + sub128(aSig0, aSig1, term0, term1, &rem0, &rem1); + while ((Bit64s) rem0 < 0) { + --zSig0; + doubleZSig0 -= 2; + add128(rem0, rem1, zSig0>>63, doubleZSig0 | 1, &rem0, &rem1); + } + zSig1 = estimateDiv128To64(rem1, 0, doubleZSig0); + if ((zSig1 & BX_CONST64(0x3FFFFFFFFFFFFFFF)) <= 5) { + if (zSig1 == 0) zSig1 = 1; + mul64To128(doubleZSig0, zSig1, &term1, &term2); + sub128(rem1, 0, term1, term2, &rem1, &rem2); + mul64To128(zSig1, zSig1, &term2, &term3); + sub192(rem1, rem2, 0, 0, term2, term3, &rem1, &rem2, &rem3); + while ((Bit64s) rem1 < 0) { + --zSig1; + shortShift128Left(0, zSig1, 1, &term2, &term3); + term3 |= 1; + term2 |= doubleZSig0; + add192(rem1, rem2, rem3, 0, term2, term3, &rem1, &rem2, &rem3); + } + zSig1 |= ((rem1 | rem2 | rem3) != 0); + } + shortShift128Left(0, zSig1, 1, &zSig0, &zSig1); + zSig0 |= doubleZSig0; + return + roundAndPackFloatx80(get_float_rounding_precision(status), + 0, zExp, zSig0, zSig1, status); +} + +#endif + +#ifdef FLOAT128 + +/*---------------------------------------------------------------------------- +| Returns the result of converting the extended double-precision floating- +| point value `a' to the quadruple-precision floating-point format. The +| conversion is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 floatx80_to_float128(floatx80 a, struct float_status_t *status) +{ + Bit64u zSig0, zSig1; + + Bit64u aSig = extractFloatx80Frac(a); + Bit32s aExp = extractFloatx80Exp(a); + int aSign = extractFloatx80Sign(a); + + if ((aExp == 0x7FFF) && (Bit64u) (aSig<<1)) + return commonNaNToFloat128(floatx80ToCommonNaN(a, status)); + + shift128Right(aSig<<1, 0, 16, &zSig0, &zSig1); + return packFloat128Four(aSign, aExp, zSig0, zSig1); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the quadruple-precision floating-point +| value `a' to the extended double-precision floating-point format. The +| conversion is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 float128_to_floatx80(float128 a, struct float_status_t *status) +{ + Bit32s aExp; + Bit64u aSig0, aSig1; + + aSig1 = extractFloat128Frac1(a); + aSig0 = extractFloat128Frac0(a); + aExp = extractFloat128Exp(a); + int aSign = extractFloat128Sign(a); + + if (aExp == 0x7FFF) { + if (aSig0 | aSig1) + return commonNaNToFloatx80(float128ToCommonNaN(a, status)); + + return packFloatx80(aSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + + if (aExp == 0) { + if ((aSig0 | aSig1) == 0) return packFloatx80(aSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat128Subnormal(aSig0, aSig1, &aExp, &aSig0, &aSig1); + } + else aSig0 |= BX_CONST64(0x0001000000000000); + + shortShift128Left(aSig0, aSig1, 15, &aSig0, &aSig1); + return roundAndPackFloatx80(80, aSign, aExp, aSig0, aSig1, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of multiplying the extended double-precision floating- +| point value `a' and quadruple-precision floating point value `b'. The +| operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_128_mul(floatx80 a, float128 b, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit32s aExp, bExp, zExp; + Bit64u aSig, bSig0, bSig1, zSig0, zSig1, zSig2; + int aSign, bSign, zSign; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a)) + { + invalid: + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + bSig0 = extractFloat128Frac0(b); + bSig1 = extractFloat128Frac1(b); + bExp = extractFloat128Exp(b); + bSign = extractFloat128Sign(b); + + zSign = aSign ^ bSign; + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1) + || ((bExp == 0x7FFF) && (bSig0 | bSig1))) + { + floatx80 r = commonNaNToFloatx80(float128ToCommonNaN(b, status)); + return propagateFloatx80NaN(a, r, status); + } + if (bExp == 0) { + if ((bSig0 | bSig1) == 0) goto invalid; + float_raise(status, float_flag_denormal); + } + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (bExp == 0x7FFF) { + if (bSig0 | bSig1) { + floatx80 r = commonNaNToFloatx80(float128ToCommonNaN(b, status)); + return propagateFloatx80NaN(a, r, status); + } + if (aExp == 0) { + if (aSig == 0) goto invalid; + float_raise(status, float_flag_denormal); + } + return packFloatx80(zSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) { + if (aSig == 0) { + if ((bExp == 0) && (bSig0 | bSig1)) float_raise(status, float_flag_denormal); + return packFloatx80(zSign, 0, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + if (bExp == 0) { + if ((bSig0 | bSig1) == 0) return packFloatx80(zSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat128Subnormal(bSig0, bSig1, &bExp, &bSig0, &bSig1); + } + else bSig0 |= BX_CONST64(0x0001000000000000); + + zExp = aExp + bExp - 0x3FFE; + shortShift128Left(bSig0, bSig1, 15, &bSig0, &bSig1); + mul128By64To192(bSig0, bSig1, aSig, &zSig0, &zSig1, &zSig2); + if (0 < (Bit64s) zSig0) { + shortShift128Left(zSig0, zSig1, 1, &zSig0, &zSig1); + --zExp; + } + return + roundAndPackFloatx80(get_float_rounding_precision(status), + zSign, zExp, zSig0, zSig1, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the absolute values of the quadruple-precision +| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated +| before being returned. `zSign' is ignored if the result is a NaN. +| The addition is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static float128 addFloat128Sigs(float128 a, float128 b, int zSign, struct float_status_t *status) +{ + Bit32s aExp, bExp, zExp; + Bit64u aSig0, aSig1, bSig0, bSig1, zSig0, zSig1, zSig2; + Bit32s expDiff; + + aSig1 = extractFloat128Frac1(a); + aSig0 = extractFloat128Frac0(a); + aExp = extractFloat128Exp(a); + bSig1 = extractFloat128Frac1(b); + bSig0 = extractFloat128Frac0(b); + bExp = extractFloat128Exp(b); + expDiff = aExp - bExp; + + if (0 < expDiff) { + if (aExp == 0x7FFF) { + if (aSig0 | aSig1) return propagateFloat128NaN(a, b, status); + return a; + } + if (bExp == 0) --expDiff; + else bSig0 |= BX_CONST64(0x0001000000000000); + shift128ExtraRightJamming(bSig0, bSig1, 0, expDiff, &bSig0, &bSig1, &zSig2); + zExp = aExp; + } + else if (expDiff < 0) { + if (bExp == 0x7FFF) { + if (bSig0 | bSig1) return propagateFloat128NaN(a, b, status); + return packFloat128Four(zSign, 0x7FFF, 0, 0); + } + if (aExp == 0) ++expDiff; + else aSig0 |= BX_CONST64(0x0001000000000000); + shift128ExtraRightJamming(aSig0, aSig1, 0, -expDiff, &aSig0, &aSig1, &zSig2); + zExp = bExp; + } + else { + if (aExp == 0x7FFF) { + if (aSig0 | aSig1 | bSig0 | bSig1) + return propagateFloat128NaN(a, b, status); + + return a; + } + add128(aSig0, aSig1, bSig0, bSig1, &zSig0, &zSig1); + if (aExp == 0) return packFloat128Four(zSign, 0, zSig0, zSig1); + zSig2 = 0; + zSig0 |= BX_CONST64(0x0002000000000000); + zExp = aExp; + goto shiftRight1; + } + aSig0 |= BX_CONST64(0x0001000000000000); + add128(aSig0, aSig1, bSig0, bSig1, &zSig0, &zSig1); + --zExp; + if (zSig0 < BX_CONST64(0x0002000000000000)) goto roundAndPack; + ++zExp; + shiftRight1: + shift128ExtraRightJamming(zSig0, zSig1, zSig2, 1, &zSig0, &zSig1, &zSig2); + roundAndPack: + return roundAndPackFloat128(zSign, zExp, zSig0, zSig1, zSig2, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the absolute values of the quadruple- +| precision floating-point values `a' and `b'. If `zSign' is 1, the +| difference is negated before being returned. `zSign' is ignored if the +| result is a NaN. The subtraction is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +static float128 subFloat128Sigs(float128 a, float128 b, int zSign, struct float_status_t *status) +{ + Bit32s aExp, bExp, zExp; + Bit64u aSig0, aSig1, bSig0, bSig1, zSig0, zSig1; + Bit32s expDiff; + + aSig1 = extractFloat128Frac1(a); + aSig0 = extractFloat128Frac0(a); + aExp = extractFloat128Exp(a); + bSig1 = extractFloat128Frac1(b); + bSig0 = extractFloat128Frac0(b); + bExp = extractFloat128Exp(b); + + expDiff = aExp - bExp; + shortShift128Left(aSig0, aSig1, 14, &aSig0, &aSig1); + shortShift128Left(bSig0, bSig1, 14, &bSig0, &bSig1); + if (0 < expDiff) goto aExpBigger; + if (expDiff < 0) goto bExpBigger; + if (aExp == 0x7FFF) { + if (aSig0 | aSig1 | bSig0 | bSig1) + return propagateFloat128NaN(a, b, status); + + float_raise(status, float_flag_invalid); + return float128_default_nan; + } + if (aExp == 0) { + aExp = 1; + bExp = 1; + } + if (bSig0 < aSig0) goto aBigger; + if (aSig0 < bSig0) goto bBigger; + if (bSig1 < aSig1) goto aBigger; + if (aSig1 < bSig1) goto bBigger; + return packFloat128(0, 0); + + bExpBigger: + if (bExp == 0x7FFF) { + if (bSig0 | bSig1) return propagateFloat128NaN(a, b, status); + return packFloat128Four(zSign ^ 1, 0x7FFF, 0, 0); + } + if (aExp == 0) ++expDiff; + else { + aSig0 |= BX_CONST64(0x4000000000000000); + } + shift128RightJamming(aSig0, aSig1, - expDiff, &aSig0, &aSig1); + bSig0 |= BX_CONST64(0x4000000000000000); + bBigger: + sub128(bSig0, bSig1, aSig0, aSig1, &zSig0, &zSig1); + zExp = bExp; + zSign ^= 1; + goto normalizeRoundAndPack; + aExpBigger: + if (aExp == 0x7FFF) { + if (aSig0 | aSig1) return propagateFloat128NaN(a, b, status); + return a; + } + if (bExp == 0) --expDiff; + else { + bSig0 |= BX_CONST64(0x4000000000000000); + } + shift128RightJamming(bSig0, bSig1, expDiff, &bSig0, &bSig1); + aSig0 |= BX_CONST64(0x4000000000000000); + aBigger: + sub128(aSig0, aSig1, bSig0, bSig1, &zSig0, &zSig1); + zExp = aExp; + normalizeRoundAndPack: + --zExp; + return normalizeRoundAndPackFloat128(zSign, zExp - 14, zSig0, zSig1, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of adding the quadruple-precision floating-point values +| `a' and `b'. The operation is performed according to the IEC/IEEE Standard +| for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 float128_add(float128 a, float128 b, struct float_status_t *status) +{ + int aSign = extractFloat128Sign(a); + int bSign = extractFloat128Sign(b); + + if (aSign == bSign) { + return addFloat128Sigs(a, b, aSign, status); + } + else { + return subFloat128Sigs(a, b, aSign, status); + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the quadruple-precision floating-point +| values `a' and `b'. The operation is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 float128_sub(float128 a, float128 b, struct float_status_t *status) +{ + int aSign = extractFloat128Sign(a); + int bSign = extractFloat128Sign(b); + + if (aSign == bSign) { + return subFloat128Sigs(a, b, aSign, status); + } + else { + return addFloat128Sigs(a, b, aSign, status); + } +} + +/*---------------------------------------------------------------------------- +| Returns the result of multiplying the quadruple-precision floating-point +| values `a' and `b'. The operation is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 float128_mul(float128 a, float128 b, struct float_status_t *status) +{ + int aSign, bSign, zSign; + Bit32s aExp, bExp, zExp; + Bit64u aSig0, aSig1, bSig0, bSig1, zSig0, zSig1, zSig2, zSig3; + + aSig1 = extractFloat128Frac1(a); + aSig0 = extractFloat128Frac0(a); + aExp = extractFloat128Exp(a); + aSign = extractFloat128Sign(a); + bSig1 = extractFloat128Frac1(b); + bSig0 = extractFloat128Frac0(b); + bExp = extractFloat128Exp(b); + bSign = extractFloat128Sign(b); + + zSign = aSign ^ bSign; + if (aExp == 0x7FFF) { + if ((aSig0 | aSig1) || ((bExp == 0x7FFF) && (bSig0 | bSig1))) { + return propagateFloat128NaN(a, b, status); + } + if ((bExp | bSig0 | bSig1) == 0) { + float_raise(status, float_flag_invalid); + return float128_default_nan; + } + return packFloat128Four(zSign, 0x7FFF, 0, 0); + } + if (bExp == 0x7FFF) { + if (bSig0 | bSig1) return propagateFloat128NaN(a, b, status); + if ((aExp | aSig0 | aSig1) == 0) { + float_raise(status, float_flag_invalid); + return float128_default_nan; + } + return packFloat128Four(zSign, 0x7FFF, 0, 0); + } + if (aExp == 0) { + if ((aSig0 | aSig1) == 0) return packFloat128Four(zSign, 0, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat128Subnormal(aSig0, aSig1, &aExp, &aSig0, &aSig1); + } + if (bExp == 0) { + if ((bSig0 | bSig1) == 0) return packFloat128Four(zSign, 0, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat128Subnormal(bSig0, bSig1, &bExp, &bSig0, &bSig1); + } + zExp = aExp + bExp - 0x4000; + aSig0 |= BX_CONST64(0x0001000000000000); + shortShift128Left(bSig0, bSig1, 16, &bSig0, &bSig1); + mul128To256(aSig0, aSig1, bSig0, bSig1, &zSig0, &zSig1, &zSig2, &zSig3); + add128(zSig0, zSig1, aSig0, aSig1, &zSig0, &zSig1); + zSig2 |= (zSig3 != 0); + if (BX_CONST64(0x0002000000000000) <= zSig0) { + shift128ExtraRightJamming(zSig0, zSig1, zSig2, 1, &zSig0, &zSig1, &zSig2); + ++zExp; + } + return roundAndPackFloat128(zSign, zExp, zSig0, zSig1, zSig2, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of dividing the quadruple-precision floating-point value +| `a' by the corresponding value `b'. The operation is performed according to +| the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 float128_div(float128 a, float128 b, struct float_status_t *status) +{ + int aSign, bSign, zSign; + Bit32s aExp, bExp, zExp; + Bit64u aSig0, aSig1, bSig0, bSig1, zSig0, zSig1, zSig2; + Bit64u rem0, rem1, rem2, rem3, term0, term1, term2, term3; + + aSig1 = extractFloat128Frac1(a); + aSig0 = extractFloat128Frac0(a); + aExp = extractFloat128Exp(a); + aSign = extractFloat128Sign(a); + bSig1 = extractFloat128Frac1(b); + bSig0 = extractFloat128Frac0(b); + bExp = extractFloat128Exp(b); + bSign = extractFloat128Sign(b); + + zSign = aSign ^ bSign; + if (aExp == 0x7FFF) { + if (aSig0 | aSig1) return propagateFloat128NaN(a, b, status); + if (bExp == 0x7FFF) { + if (bSig0 | bSig1) return propagateFloat128NaN(a, b, status); + float_raise(status, float_flag_invalid); + return float128_default_nan; + } + return packFloat128Four(zSign, 0x7FFF, 0, 0); + } + if (bExp == 0x7FFF) { + if (bSig0 | bSig1) return propagateFloat128NaN(a, b, status); + return packFloat128Four(zSign, 0, 0, 0); + } + if (bExp == 0) { + if ((bSig0 | bSig1) == 0) { + if ((aExp | aSig0 | aSig1) == 0) { + float_raise(status, float_flag_invalid); + return float128_default_nan; + } + float_raise(status, float_flag_divbyzero); + return packFloat128Four(zSign, 0x7FFF, 0, 0); + } + float_raise(status, float_flag_denormal); + normalizeFloat128Subnormal(bSig0, bSig1, &bExp, &bSig0, &bSig1); + } + if (aExp == 0) { + if ((aSig0 | aSig1) == 0) return packFloat128Four(zSign, 0, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat128Subnormal(aSig0, aSig1, &aExp, &aSig0, &aSig1); + } + zExp = aExp - bExp + 0x3FFD; + shortShift128Left( + aSig0 | BX_CONST64(0x0001000000000000), aSig1, 15, &aSig0, &aSig1); + shortShift128Left( + bSig0 | BX_CONST64(0x0001000000000000), bSig1, 15, &bSig0, &bSig1); + if (le128(bSig0, bSig1, aSig0, aSig1)) { + shift128Right(aSig0, aSig1, 1, &aSig0, &aSig1); + ++zExp; + } + zSig0 = estimateDiv128To64(aSig0, aSig1, bSig0); + mul128By64To192(bSig0, bSig1, zSig0, &term0, &term1, &term2); + sub192(aSig0, aSig1, 0, term0, term1, term2, &rem0, &rem1, &rem2); + while ((Bit64s) rem0 < 0) { + --zSig0; + add192(rem0, rem1, rem2, 0, bSig0, bSig1, &rem0, &rem1, &rem2); + } + zSig1 = estimateDiv128To64(rem1, rem2, bSig0); + if ((zSig1 & 0x3FFF) <= 4) { + mul128By64To192(bSig0, bSig1, zSig1, &term1, &term2, &term3); + sub192(rem1, rem2, 0, term1, term2, term3, &rem1, &rem2, &rem3); + while ((Bit64s) rem1 < 0) { + --zSig1; + add192(rem1, rem2, rem3, 0, bSig0, bSig1, &rem1, &rem2, &rem3); + } + zSig1 |= ((rem1 | rem2 | rem3) != 0); + } + shift128ExtraRightJamming(zSig0, zSig1, 0, 15, &zSig0, &zSig1, &zSig2); + return roundAndPackFloat128(zSign, zExp, zSig0, zSig1, zSig2, status); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the 64-bit two's complement integer `a' to +| the quadruple-precision floating-point format. The conversion is performed +| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float128 int64_to_float128(Bit64s a) +{ + Bit64u zSig0, zSig1; + + if (a == 0) return packFloat128Four(0, 0, 0, 0); + int zSign = (a < 0); + Bit64u absA = zSign ? - a : a; + Bit8u shiftCount = countLeadingZeros64(absA) + 49; + Bit32s zExp = 0x406E - shiftCount; + if (64 <= shiftCount) { + zSig1 = 0; + zSig0 = absA; + shiftCount -= 64; + } + else { + zSig1 = absA; + zSig0 = 0; + } + shortShift128Left(zSig0, zSig1, shiftCount, &zSig0, &zSig1); + return packFloat128Four(zSign, zExp, zSig0, zSig1); +} + +#endif diff --git a/src/cpu/softfloat/softfloat.h b/src/cpu/softfloat/softfloat.h new file mode 100644 index 000000000..1d1b0f08f --- /dev/null +++ b/src/cpu/softfloat/softfloat.h @@ -0,0 +1,488 @@ +/*============================================================================ +This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "config.h" /* generated by configure script from config.h.in */ + +#ifndef _SOFTFLOAT_H_ +#define _SOFTFLOAT_H_ + +#define FLOAT16 +#define FLOATX80 + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point types. +*----------------------------------------------------------------------------*/ +#ifdef FLOAT16 +typedef Bit16u float16; +#endif +typedef Bit32u float32; +typedef Bit64u float64; + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point class. +*----------------------------------------------------------------------------*/ +typedef enum { + float_zero, + float_SNaN, + float_QNaN, + float_negative_inf, + float_positive_inf, + float_denormal, + float_normalized +} float_class_t; + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point NaN operands handling mode. +*----------------------------------------------------------------------------*/ +enum float_nan_handling_mode_t { + float_larger_significand_nan = 0, // this mode used by x87 FPU + float_first_operand_nan = 1 // this mode used by SSE +}; + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point rounding mode. +*----------------------------------------------------------------------------*/ +enum float_round_t { + float_round_nearest_even = 0, + float_round_down = 1, + float_round_up = 2, + float_round_to_zero = 3 +}; + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point exception flags. +*----------------------------------------------------------------------------*/ +enum float_exception_flag_t { + float_flag_invalid = 0x01, + float_flag_denormal = 0x02, + float_flag_divbyzero = 0x04, + float_flag_overflow = 0x08, + float_flag_underflow = 0x10, + float_flag_inexact = 0x20 +}; + +extern const unsigned float_all_exceptions_mask; + +#ifdef FLOATX80 +#define RAISE_SW_C1 0x0200 +#endif + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point ordering relations +*----------------------------------------------------------------------------*/ +enum { + float_relation_less = -1, + float_relation_equal = 0, + float_relation_greater = 1, + float_relation_unordered = 2 +}; + +/*---------------------------------------------------------------------------- +| Options to indicate which negations to perform in float*_muladd() +| Using these differs from negating an input or output before calling +| the muladd function in that this means that a NaN doesn't have its +| sign bit inverted before it is propagated. +*----------------------------------------------------------------------------*/ +enum { + float_muladd_negate_c = 1, + float_muladd_negate_product = 2, + float_muladd_negate_result = float_muladd_negate_c | float_muladd_negate_product +}; + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point status structure. +*----------------------------------------------------------------------------*/ +struct float_status_t +{ +#ifdef FLOATX80 + int float_rounding_precision; /* floatx80 only */ +#endif + int float_rounding_mode; + int float_exception_flags; + int float_exception_masks; + int float_suppress_exception; + int float_nan_handling_mode; /* flag register */ + int flush_underflow_to_zero; /* flag register */ + int denormals_are_zeros; /* flag register */ +}; + +/*---------------------------------------------------------------------------- +| Routine to raise any or all of the software IEC/IEEE floating-point +| exception flags. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE void float_raise(struct float_status_t *status, int flags) +{ + status->float_exception_flags |= flags; +} + +/*---------------------------------------------------------------------------- +| Returns raised IEC/IEEE floating-point exception flags. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int get_exception_flags(const struct float_status_t *status) +{ + return status->float_exception_flags & ~status->float_suppress_exception; +} + +/*---------------------------------------------------------------------------- +| Routine to check if any or all of the software IEC/IEEE floating-point +| exceptions are masked. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int float_exception_masked(const struct float_status_t *status, int flag) +{ + return status->float_exception_masks & flag; +} + +/*---------------------------------------------------------------------------- +| Returns current floating point rounding mode specified by status word. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int get_float_rounding_mode(const struct float_status_t *status) +{ + return status->float_rounding_mode; +} + +/*---------------------------------------------------------------------------- +| Returns current floating point precision (floatx80 only). +*----------------------------------------------------------------------------*/ + +#ifdef FLOATX80 +BX_CPP_INLINE int get_float_rounding_precision(const struct float_status_t *status) +{ + return status->float_rounding_precision; +} +#endif + +/*---------------------------------------------------------------------------- +| Returns current floating point NaN operands handling mode specified +| by status word. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int get_float_nan_handling_mode(const struct float_status_t *status) +{ + return status->float_nan_handling_mode; +} + +/*---------------------------------------------------------------------------- +| Raise floating point precision lost up flag (floatx80 only). +*----------------------------------------------------------------------------*/ + +#ifdef FLOATX80 +BX_CPP_INLINE void set_float_rounding_up(struct float_status_t *status) +{ + status->float_exception_flags |= RAISE_SW_C1; +} +#endif + +/*---------------------------------------------------------------------------- +| Returns 1 if the feature is supported; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int get_denormals_are_zeros(const struct float_status_t *status) +{ + return status->denormals_are_zeros; +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the feature is supported; +| otherwise returns 0. +*----------------------------------------------------------------------------*/ + +BX_CPP_INLINE int get_flush_underflow_to_zero(const struct float_status_t *status) +{ + return status->flush_underflow_to_zero; +} + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE integer-to-floating-point conversion routines. +*----------------------------------------------------------------------------*/ +float32 int32_to_float32(Bit32s, struct float_status_t *status); +float64 int32_to_float64(Bit32s); +float32 int64_to_float32(Bit64s, struct float_status_t *status); +float64 int64_to_float64(Bit64s, struct float_status_t *status); + +float32 uint32_to_float32(Bit32u, struct float_status_t *status); +float64 uint32_to_float64(Bit32u); +float32 uint64_to_float32(Bit64u, struct float_status_t *status); +float64 uint64_to_float64(Bit64u, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE single-precision conversion routines. +*----------------------------------------------------------------------------*/ +Bit32s float32_to_int32(float32, struct float_status_t *status); +Bit32s float32_to_int32_round_to_zero(float32, struct float_status_t *status); +Bit64s float32_to_int64(float32, struct float_status_t *status); +Bit64s float32_to_int64_round_to_zero(float32, struct float_status_t *status); +Bit32u float32_to_uint32(float32, struct float_status_t *status); +Bit32u float32_to_uint32_round_to_zero(float32, struct float_status_t *status); +Bit64u float32_to_uint64(float32, struct float_status_t *status); +Bit64u float32_to_uint64_round_to_zero(float32, struct float_status_t *status); +float64 float32_to_float64(float32, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE single-precision operations. +*----------------------------------------------------------------------------*/ +float32 float32_round_to_int(float32, Bit8u scale, struct float_status_t *status); +float32 float32_add(float32, float32, struct float_status_t *status); +float32 float32_sub(float32, float32, struct float_status_t *status); +float32 float32_mul(float32, float32, struct float_status_t *status); +float32 float32_div(float32, float32, struct float_status_t *status); +float32 float32_sqrt(float32, struct float_status_t *status); +float32 float32_frc(float32, struct float_status_t *status); +float32 float32_muladd(float32, float32, float32, int flags, struct float_status_t *status); +float32 float32_scalef(float32, float32, struct float_status_t *status); +int float32_compare(float32, float32, int quiet, struct float_status_t *status); + +BX_CPP_INLINE float32 float32_round_to_int_one(float32 a, struct float_status_t *status) +{ + return float32_round_to_int(a, 0, status); +} + +BX_CPP_INLINE float32 float32_fmadd(float32 a, float32 b, float32 c, struct float_status_t *status) +{ + return float32_muladd(a, b, c, 0, status); +} + +BX_CPP_INLINE float32 float32_fmsub(float32 a, float32 b, float32 c, struct float_status_t *status) +{ + return float32_muladd(a, b, c, float_muladd_negate_c, status); +} + +BX_CPP_INLINE float32 float32_fnmadd(float32 a, float32 b, float32 c, struct float_status_t *status) +{ + return float32_muladd(a, b, c, float_muladd_negate_product, status); +} + +BX_CPP_INLINE float32 float32_fnmsub(float32 a, float32 b, float32 c, struct float_status_t *status) +{ + return float32_muladd(a, b, c, float_muladd_negate_result, status); +} + +BX_CPP_INLINE int float32_compare_two(float32 a, float32 b, struct float_status_t *status) +{ + return float32_compare(a, b, 0, status); +} + +BX_CPP_INLINE int float32_compare_quiet(float32 a, float32 b, struct float_status_t *status) +{ + return float32_compare(a, b, 1, status); +} + +float_class_t float32_class(float32); + +float32 float32_min(float32 a, float32 b, struct float_status_t *status); +float32 float32_max(float32 a, float32 b, struct float_status_t *status); + +float32 float32_minmax(float32 a, float32 b, int is_max, int is_abs, struct float_status_t *status); +float32 float32_getexp(float32 a, struct float_status_t *status); +float32 float32_getmant(float32 a, struct float_status_t *status, int sign_ctrl, int interv); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE double-precision conversion routines. +*----------------------------------------------------------------------------*/ +Bit32s float64_to_int32(float64, struct float_status_t *status); +Bit32s float64_to_int32_round_to_zero(float64, struct float_status_t *status); +Bit64s float64_to_int64(float64, struct float_status_t *status); +Bit64s float64_to_int64_round_to_zero(float64, struct float_status_t *status); +Bit32u float64_to_uint32(float64, struct float_status_t *status); +Bit32u float64_to_uint32_round_to_zero(float64, struct float_status_t *status); +Bit64u float64_to_uint64(float64, struct float_status_t *status); +Bit64u float64_to_uint64_round_to_zero(float64, struct float_status_t *status); +float32 float64_to_float32(float64, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE double-precision operations. +*----------------------------------------------------------------------------*/ +float64 float64_round_to_int(float64, Bit8u scale, struct float_status_t *status); +float64 float64_add(float64, float64, struct float_status_t *status); +float64 float64_sub(float64, float64, struct float_status_t *status); +float64 float64_mul(float64, float64, struct float_status_t *status); +float64 float64_div(float64, float64, struct float_status_t *status); +float64 float64_sqrt(float64, struct float_status_t *status); +float64 float64_frc(float64, struct float_status_t *status); +float64 float64_muladd(float64, float64, float64, int flags, struct float_status_t *status); +float64 float64_scalef(float64, float64, struct float_status_t *status); +int float64_compare(float64, float64, int quiet, struct float_status_t *status); + +BX_CPP_INLINE float64 float64_round_to_int_one(float64 a, struct float_status_t *status) +{ + return float64_round_to_int(a, 0, status); +} + +BX_CPP_INLINE float64 float64_fmadd(float64 a, float64 b, float64 c, struct float_status_t *status) +{ + return float64_muladd(a, b, c, 0, status); +} + +BX_CPP_INLINE float64 float64_fmsub(float64 a, float64 b, float64 c, struct float_status_t *status) +{ + return float64_muladd(a, b, c, float_muladd_negate_c, status); +} + +BX_CPP_INLINE float64 float64_fnmadd(float64 a, float64 b, float64 c, struct float_status_t *status) +{ + return float64_muladd(a, b, c, float_muladd_negate_product, status); +} + +BX_CPP_INLINE float64 float64_fnmsub(float64 a, float64 b, float64 c, struct float_status_t *status) +{ + return float64_muladd(a, b, c, float_muladd_negate_result, status); +} + +BX_CPP_INLINE int float64_compare_two(float64 a, float64 b, struct float_status_t *status) +{ + return float64_compare(a, b, 0, status); +} + +BX_CPP_INLINE int float64_compare_quiet(float64 a, float64 b, struct float_status_t *status) +{ + return float64_compare(a, b, 1, status); +} + +float_class_t float64_class(float64); + +float64 float64_min(float64 a, float64 b, struct float_status_t *status); +float64 float64_max(float64 a, float64 b, struct float_status_t *status); + +float64 float64_minmax(float64 a, float64 b, int is_max, int is_abs, struct float_status_t *status); +float64 float64_getexp(float64 a, struct float_status_t *status); +float64 float64_getmant(float64 a, struct float_status_t *status, int sign_ctrl, int interv); + +#ifdef FLOAT16 +float32 float16_to_float32(float16, struct float_status_t *status); +float16 float32_to_float16(float32, struct float_status_t *status); + +float_class_t float16_class(float16); +#endif + +#ifdef FLOATX80 +/*---------------------------------------------------------------------------- +| Software IEC/IEEE floating-point types. +*----------------------------------------------------------------------------*/ + +#ifdef BX_BIG_ENDIAN +typedef struct floatx80 { // leave alignment to compiler + Bit16u exp; + Bit64u fraction; +}; floatx80 +#else +typedef struct floatx80 { + Bit64u fraction; + Bit16u exp; +} floatx80; +#endif + +#ifdef __cplusplus +extern "C" { +#endif +/*---------------------------------------------------------------------------- +| Software IEC/IEEE integer-to-floating-point conversion routines. +*----------------------------------------------------------------------------*/ +floatx80 int32_to_floatx80(Bit32s); +floatx80 int64_to_floatx80(Bit64s); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE extended double-precision conversion routines. +*----------------------------------------------------------------------------*/ +floatx80 float32_to_floatx80(float32, struct float_status_t *status); +floatx80 float64_to_floatx80(float64, struct float_status_t *status); + +Bit32s floatx80_to_int32(floatx80, struct float_status_t *status); +Bit32s floatx80_to_int32_round_to_zero(floatx80, struct float_status_t *status); +Bit64s floatx80_to_int64(floatx80, struct float_status_t *status); +Bit64s floatx80_to_int64_round_to_zero(floatx80, struct float_status_t *status); + +float32 floatx80_to_float32(floatx80, struct float_status_t *status); +float64 floatx80_to_float64(floatx80, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE extended double-precision operations. +*----------------------------------------------------------------------------*/ +floatx80 floatx80_round_to_int(floatx80, struct float_status_t *status); +floatx80 floatx80_add(floatx80, floatx80, struct float_status_t *status); +floatx80 floatx80_sub(floatx80, floatx80, struct float_status_t *status); +floatx80 floatx80_mul(floatx80, floatx80, struct float_status_t *status); +floatx80 floatx80_div(floatx80, floatx80, struct float_status_t *status); +floatx80 floatx80_sqrt(floatx80, struct float_status_t *status); + +float_class_t floatx80_class(floatx80); +#ifdef __cplusplus +} +#endif +#endif /* FLOATX80 */ + +#ifdef FLOAT128 + +#ifdef BX_BIG_ENDIAN +typedef struct float128 { + Bit64u hi, lo; +} float128; +#else +typedef struct float128 { + Bit64u lo, hi; +} float128; +#endif + +#ifdef __cplusplus +extern "C" { +#endif +/*---------------------------------------------------------------------------- +| Software IEC/IEEE quadruple-precision conversion routines. +*----------------------------------------------------------------------------*/ +float128 floatx80_to_float128(floatx80 a, struct float_status_t *status); +floatx80 float128_to_floatx80(float128 a, struct float_status_t *status); + +float128 int64_to_float128(Bit64s a); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE extended double-precision operations. +*----------------------------------------------------------------------------*/ +floatx80 floatx80_128_mul(floatx80 a, float128 b, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE quadruple-precision operations. +*----------------------------------------------------------------------------*/ +float128 float128_add(float128 a, float128 b, struct float_status_t *status); +float128 float128_sub(float128 a, float128 b, struct float_status_t *status); +float128 float128_mul(float128 a, float128 b, struct float_status_t *status); +float128 float128_div(float128 a, float128 b, struct float_status_t *status); +#ifdef __cplusplus +} +#endif +#endif /* FLOAT128 */ + +#endif diff --git a/src/cpu/softfloat/softfloat16.cc b/src/cpu/softfloat/softfloat16.cc new file mode 100644 index 000000000..8c17d3a86 --- /dev/null +++ b/src/cpu/softfloat/softfloat16.cc @@ -0,0 +1,129 @@ +/*============================================================================ +This C source file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Adapted for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "softfloat.h" + +#ifdef FLOAT16 + +#include "softfloat-round-pack.h" +#include "softfloat-specialize.h" +#include "softfloat-macros.h" + +/*---------------------------------------------------------------------------- +| Determine half-precision floating-point number class +*----------------------------------------------------------------------------*/ + +float_class_t float16_class(float16 a) +{ + Bit16s aExp = extractFloat16Exp(a); + Bit16u aSig = extractFloat16Frac(a); + int aSign = extractFloat16Sign(a); + + if(aExp == 0x1F) { + if (aSig == 0) + return (aSign) ? float_negative_inf : float_positive_inf; + + return (aSig & 0x200) ? float_QNaN : float_SNaN; + } + + if(aExp == 0) { + if (aSig == 0) return float_zero; + return float_denormal; + } + + return float_normalized; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the half-precision floating-point value +| `a' to the single-precision floating-point format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic. +*----------------------------------------------------------------------------*/ + +float32 float16_to_float32(float16 a, struct float_status_t *status) +{ + Bit16u aSig = extractFloat16Frac(a); + Bit16s aExp = extractFloat16Exp(a); + int aSign = extractFloat16Sign(a); + + if (aExp == 0x1F) { + if (aSig) return commonNaNToFloat32(float16ToCommonNaN(a, status)); + return packFloat32(aSign, 0xFF, 0); + } + if (aExp == 0) { + // ignore denormals_are_zeros flag + if (aSig == 0) return packFloat32(aSign, 0, 0); + float_raise(status, float_flag_denormal); + normalizeFloat16Subnormal(aSig, &aExp, &aSig); + --aExp; + } + + return packFloat32(aSign, aExp + 0x70, ((Bit32u) aSig)<<13); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value +| `a' to the half-precision floating-point format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic. +*----------------------------------------------------------------------------*/ + +float16 float32_to_float16(float32 a, struct float_status_t *status) +{ + Bit32u aSig = extractFloat32Frac(a); + Bit16s aExp = extractFloat32Exp(a); + int aSign = extractFloat32Sign(a); + + if (aExp == 0xFF) { + if (aSig) return commonNaNToFloat16(float32ToCommonNaN(a, status)); + return packFloat16(aSign, 0x1F, 0); + } + if (aExp == 0) { + if (get_denormals_are_zeros(status)) aSig = 0; + if (aSig == 0) return packFloat16(aSign, 0, 0); + float_raise(status, float_flag_denormal); + } + + aSig = shift32RightJamming(aSig, 9); + Bit16u zSig = (Bit16u) aSig; + if (aExp || zSig) { + zSig |= 0x4000; + aExp -= 0x71; + } + + return roundAndPackFloat16(aSign, aExp, zSig, status); +} + +#endif diff --git a/src/cpu/softfloat/softfloat_poly.cc b/src/cpu/softfloat/softfloat_poly.cc new file mode 100644 index 000000000..5c7079353 --- /dev/null +++ b/src/cpu/softfloat/softfloat_poly.cc @@ -0,0 +1,89 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#define FLOAT128 + +#include +#include "softfloat.h" + +// 2 3 4 n +// f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x) +// 0 1 2 3 4 n +// +// -- 2k -- 2k+1 +// p(x) = > C * x q(x) = > C * x +// -- 2k -- 2k+1 +// +// f(x) ~ [ p(x) + x * q(x) ] +// + +float128 EvalPoly(float128 x, float128 *arr, int n, struct float_status_t *status) +{ + float128 r = arr[--n]; + + do { + r = float128_mul(r, x, status); + r = float128_add(r, arr[--n], status); + } while (n > 0); + + return r; +} + +// 2 4 6 8 2n +// f(x) ~ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x) +// 0 1 2 3 4 n +// +// -- 4k -- 4k+2 +// p(x) = > C * x q(x) = > C * x +// -- 2k -- 2k+1 +// +// 2 +// f(x) ~ [ p(x) + x * q(x) ] +// + +float128 EvenPoly(float128 x, float128 *arr, int n, struct float_status_t *status) +{ + return EvalPoly(float128_mul(x, x, status), arr, n, status); +} + +// 3 5 7 9 2n+1 +// f(x) ~ (C * x) + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x) +// 0 1 2 3 4 n +// 2 4 6 8 2n +// = x * [ C + (C * x) + (C * x) + (C * x) + (C * x) + ... + (C * x) +// 0 1 2 3 4 n +// +// -- 4k -- 4k+2 +// p(x) = > C * x q(x) = > C * x +// -- 2k -- 2k+1 +// +// 2 +// f(x) ~ x * [ p(x) + x * q(x) ] +// + +float128 OddPoly(float128 x, float128 *arr, int n, struct float_status_t *status) +{ + return float128_mul(x, EvenPoly(x, arr, n, status), status); +} diff --git a/src/cpu/softfloat/softfloatx80.cc b/src/cpu/softfloat/softfloatx80.cc new file mode 100644 index 000000000..3ac3e61b3 --- /dev/null +++ b/src/cpu/softfloat/softfloatx80.cc @@ -0,0 +1,367 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#include "softfloatx80.h" +#include "softfloat-round-pack.h" +#include "softfloat-macros.h" + +const floatx80 Const_QNaN = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); +const floatx80 Const_Z = packFloatx80(0, 0x0000, 0); +const floatx80 Const_1 = packFloatx80(0, 0x3fff, BX_CONST64(0x8000000000000000)); +const floatx80 Const_L2T = packFloatx80(0, 0x4000, BX_CONST64(0xd49a784bcd1b8afe)); +const floatx80 Const_L2E = packFloatx80(0, 0x3fff, BX_CONST64(0xb8aa3b295c17f0bc)); +const floatx80 Const_PI = packFloatx80(0, 0x4000, BX_CONST64(0xc90fdaa22168c235)); +const floatx80 Const_LG2 = packFloatx80(0, 0x3ffd, BX_CONST64(0x9a209a84fbcff799)); +const floatx80 Const_LN2 = packFloatx80(0, 0x3ffe, BX_CONST64(0xb17217f7d1cf79ac)); +const floatx80 Const_INF = packFloatx80(0, 0x7fff, BX_CONST64(0x8000000000000000)); + +/*---------------------------------------------------------------------------- +| Commonly used single-precision floating point constants +*----------------------------------------------------------------------------*/ +const float32 float32_negative_inf = 0xff800000; +const float32 float32_positive_inf = 0x7f800000; +const float32 float32_negative_zero = 0x80000000; +const float32 float32_positive_zero = 0x00000000; +const float32 float32_negative_one = 0xbf800000; +const float32 float32_positive_one = 0x3f800000; +const float32 float32_max_float = 0x7f7fffff; +const float32 float32_min_float = 0xff7fffff; + +/*---------------------------------------------------------------------------- +| The pattern for a default generated single-precision NaN. +*----------------------------------------------------------------------------*/ +const float32 float32_default_nan = 0xffc00000; + +/*---------------------------------------------------------------------------- +| Commonly used single-precision floating point constants +*----------------------------------------------------------------------------*/ +const float64 float64_negative_inf = BX_CONST64(0xfff0000000000000); +const float64 float64_positive_inf = BX_CONST64(0x7ff0000000000000); +const float64 float64_negative_zero = BX_CONST64(0x8000000000000000); +const float64 float64_positive_zero = BX_CONST64(0x0000000000000000); +const float64 float64_negative_one = BX_CONST64(0xbff0000000000000); +const float64 float64_positive_one = BX_CONST64(0x3ff0000000000000); +const float64 float64_max_float = BX_CONST64(0x7fefffffffffffff); +const float64 float64_min_float = BX_CONST64(0xffefffffffffffff); + +/*---------------------------------------------------------------------------- +| The pattern for a default generated double-precision NaN. +*----------------------------------------------------------------------------*/ +const float64 float64_default_nan = BX_CONST64(0xFFF8000000000000); + +/*---------------------------------------------------------------------------- +| Returns the result of converting the extended double-precision floating- +| point value `a' to the 16-bit two's complement integer format. The +| conversion is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic - which means in particular that the conversion +| is rounded according to the current rounding mode. If `a' is a NaN or the +| conversion overflows, the integer indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit16s floatx80_to_int16(floatx80 a, struct float_status_t *status) +{ + if (floatx80_is_unsupported(a)) { + float_raise(status, float_flag_invalid); + return int16_indefinite; + } + + Bit32s v32 = floatx80_to_int32(a, status); + + if ((v32 > 32767) || (v32 < -32768)) { + status->float_exception_flags = float_flag_invalid; // throw away other flags + return int16_indefinite; + } + + return (Bit16s) v32; +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the extended double-precision floating- +| point value `a' to the 16-bit two's complement integer format. The +| conversion is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic, except that the conversion is always rounded +| toward zero. If `a' is a NaN or the conversion overflows, the integer +| indefinite value is returned. +*----------------------------------------------------------------------------*/ + +Bit16s floatx80_to_int16_round_to_zero(floatx80 a, struct float_status_t *status) +{ + if (floatx80_is_unsupported(a)) { + float_raise(status, float_flag_invalid); + return int16_indefinite; + } + + Bit32s v32 = floatx80_to_int32_round_to_zero(a, status); + + if ((v32 > 32767) || (v32 < -32768)) { + status->float_exception_flags = float_flag_invalid; // throw away other flags + return int16_indefinite; + } + + return (Bit16s) v32; +} + +/*---------------------------------------------------------------------------- +| Separate the source extended double-precision floating point value `a' +| into its exponent and significand, store the significant back to the +| 'a' and return the exponent. The operation performed is a superset of +| the IEC/IEEE recommended logb(x) function. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_extract(floatx80 *a, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit64u aSig = extractFloatx80Frac(*a); + Bit32s aExp = extractFloatx80Exp(*a); + int aSign = extractFloatx80Sign(*a); + + if (floatx80_is_unsupported(*a)) + { + float_raise(status, float_flag_invalid); + *a = floatx80_default_nan; + return *a; + } + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1)) + { + *a = propagateFloatx80NaNOne(*a, status); + return *a; + } + return packFloatx80(0, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) + { + if (aSig == 0) { + float_raise(status, float_flag_divbyzero); + *a = packFloatx80(aSign, 0, 0); + return packFloatx80(1, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + } + + a->exp = (aSign << 15) + 0x3FFF; + a->fraction = aSig; + return int32_to_floatx80(aExp - 0x3FFF); +} + +/*---------------------------------------------------------------------------- +| Scales extended double-precision floating-point value in operand `a' by +| value `b'. The function truncates the value in the second operand 'b' to +| an integral value and adds that value to the exponent of the operand 'a'. +| The operation performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_scale(floatx80 a, floatx80 b, struct float_status_t *status) +{ +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. +*----------------------------------------------------------------------------*/ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + Bit32s aExp, bExp; + Bit64u aSig, bSig; + + // handle unsupported extended double-precision floating encodings + if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) + { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + int aSign = extractFloatx80Sign(a); + bSig = extractFloatx80Frac(b); + bExp = extractFloatx80Exp(b); + int bSign = extractFloatx80Sign(b); + + if (aExp == 0x7FFF) { + if ((Bit64u) (aSig<<1) || ((bExp == 0x7FFF) && (Bit64u) (bSig<<1))) + { + return propagateFloatx80NaN(a, b, status); + } + if ((bExp == 0x7FFF) && bSign) { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + return a; + } + if (bExp == 0x7FFF) { + if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); + if ((aExp | aSig) == 0) { + if (! bSign) { + float_raise(status, float_flag_invalid); + return floatx80_default_nan; + } + return a; + } + if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); + if (bSign) return packFloatx80(aSign, 0, 0); + return packFloatx80(aSign, 0x7FFF, BX_CONST64(0x8000000000000000)); + } + if (aExp == 0) { + if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); + if (aSig == 0) return a; + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + if (bExp < 0x3FFF) + return normalizeRoundAndPackFloatx80(80, aSign, aExp, aSig, 0, status); + } + if (bExp == 0) { + if (bSig == 0) return a; + float_raise(status, float_flag_denormal); + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + } + + if (bExp > 0x400E) { + /* generate appropriate overflow/underflow */ + return roundAndPackFloatx80(80, aSign, + bSign ? -0x3FFF : 0x7FFF, aSig, 0, status); + } + + if (bExp < 0x3FFF) return a; + + int shiftCount = 0x403E - bExp; + bSig >>= shiftCount; + Bit32s scale = (Bit32s) bSig; + if (bSign) scale = -scale; /* -32768..32767 */ + return + roundAndPackFloatx80(80, aSign, aExp+scale, aSig, 0, status); +} + +/*---------------------------------------------------------------------------- +| Determine extended-precision floating-point number class. +*----------------------------------------------------------------------------*/ + +float_class_t floatx80_class(floatx80 a) +{ + Bit32s aExp = extractFloatx80Exp(a); + Bit64u aSig = extractFloatx80Frac(a); + + if(aExp == 0) { + if (aSig == 0) + return float_zero; + + /* denormal or pseudo-denormal */ + return float_denormal; + } + + /* valid numbers have the MS bit set */ + if (!(aSig & BX_CONST64(0x8000000000000000))) + return float_SNaN; /* report unsupported as SNaNs */ + + if(aExp == 0x7fff) { + int aSign = extractFloatx80Sign(a); + + if (((Bit64u) (aSig<< 1)) == 0) + return (aSign) ? float_negative_inf : float_positive_inf; + + return (aSig & BX_CONST64(0x4000000000000000)) ? float_QNaN : float_SNaN; + } + + return float_normalized; +} + +/*---------------------------------------------------------------------------- +| Compare between two extended precision floating point numbers. Returns +| 'float_relation_equal' if the operands are equal, 'float_relation_less' if +| the value 'a' is less than the corresponding value `b', +| 'float_relation_greater' if the value 'a' is greater than the corresponding +| value `b', or 'float_relation_unordered' otherwise. +*----------------------------------------------------------------------------*/ + +int floatx80_compare(floatx80 a, floatx80 b, int quiet, struct float_status_t *status) +{ + float_class_t aClass = floatx80_class(a); + float_class_t bClass = floatx80_class(b); + + if (aClass == float_SNaN || bClass == float_SNaN) + { + /* unsupported reported as SNaN */ + float_raise(status, float_flag_invalid); + return float_relation_unordered; + } + + if (aClass == float_QNaN || bClass == float_QNaN) { + if (! quiet) float_raise(status, float_flag_invalid); + return float_relation_unordered; + } + + if (aClass == float_denormal || bClass == float_denormal) { + float_raise(status, float_flag_denormal); + } + + int aSign = extractFloatx80Sign(a); + int bSign = extractFloatx80Sign(b); + + if (aClass == float_zero) { + if (bClass == float_zero) return float_relation_equal; + return bSign ? float_relation_greater : float_relation_less; + } + + if (bClass == float_zero || aSign != bSign) { + return aSign ? float_relation_less : float_relation_greater; + } + + Bit64u aSig = extractFloatx80Frac(a); + Bit32s aExp = extractFloatx80Exp(a); + Bit64u bSig = extractFloatx80Frac(b); + Bit32s bExp = extractFloatx80Exp(b); + + if (aClass == float_denormal) + normalizeFloatx80Subnormal(aSig, &aExp, &aSig); + + if (bClass == float_denormal) + normalizeFloatx80Subnormal(bSig, &bExp, &bSig); + + if (aExp == bExp && aSig == bSig) + return float_relation_equal; + + int less_than = + aSign ? ((bExp < aExp) || ((bExp == aExp) && (bSig < aSig))) + : ((aExp < bExp) || ((aExp == bExp) && (aSig < bSig))); + + if (less_than) return float_relation_less; + return float_relation_greater; +} + + +int floatx80_compare_two(floatx80 a, floatx80 b, struct float_status_t *status) +{ + return floatx80_compare(a, b, 0, status); +} + +int floatx80_compare_quiet(floatx80 a, floatx80 b, struct float_status_t *status) +{ + return floatx80_compare(a, b, 1, status); +} diff --git a/src/cpu/softfloat/softfloatx80.h b/src/cpu/softfloat/softfloatx80.h new file mode 100644 index 000000000..1f96141b4 --- /dev/null +++ b/src/cpu/softfloat/softfloatx80.h @@ -0,0 +1,121 @@ +/*============================================================================ +This source file is an extension to the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b, written for Bochs (x86 achitecture simulator) +floating point emulation. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. +=============================================================================*/ + +/*============================================================================ + * Written for Bochs (x86 achitecture simulator) by + * Stanislav Shwartsman [sshwarts at sourceforge net] + * ==========================================================================*/ + +#ifndef _SOFTFLOATX80_EXTENSIONS_H_ +#define _SOFTFLOATX80_EXTENSIONS_H_ + +#include "softfloat.h" +#include "softfloat-specialize.h" + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE integer-to-floating-point conversion routines. +*----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +Bit16s floatx80_to_int16(floatx80, struct float_status_t *status); +Bit16s floatx80_to_int16_round_to_zero(floatx80, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE extended double-precision operations. +*----------------------------------------------------------------------------*/ + +floatx80 floatx80_extract(floatx80 *a, struct float_status_t *status); +floatx80 floatx80_scale(floatx80 a, floatx80 b, struct float_status_t *status); +int floatx80_remainder(floatx80 a, floatx80 b, floatx80 *r, Bit64u *q, struct float_status_t *status); +int floatx80_ieee754_remainder(floatx80 a, floatx80 b, floatx80 *r, Bit64u *q, struct float_status_t *status); +floatx80 f2xm1(floatx80 a, struct float_status_t *status); +floatx80 fyl2x(floatx80 a, floatx80 b, struct float_status_t *status); +floatx80 fyl2xp1(floatx80 a, floatx80 b, struct float_status_t *status); +floatx80 fpatan(floatx80 a, floatx80 b, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE extended double-precision trigonometric functions. +*----------------------------------------------------------------------------*/ + +int fsincos(floatx80 a, floatx80 *sin_a, floatx80 *cos_a, struct float_status_t *status); +int fsin(floatx80 *a, struct float_status_t *status); +int fcos(floatx80 *a, struct float_status_t *status); +int ftan(floatx80 *a, struct float_status_t *status); + +/*---------------------------------------------------------------------------- +| Software IEC/IEEE extended double-precision compare. +*----------------------------------------------------------------------------*/ + +int floatx80_compare(floatx80, floatx80, int quiet, struct float_status_t *status); +int floatx80_compare_two(floatx80 a, floatx80 b, struct float_status_t *status); +int floatx80_compare_quiet(floatx80 a, floatx80 b, struct float_status_t *status); + +#ifdef __cplusplus +} +#endif + +/*----------------------------------------------------------------------------- +| Calculates the absolute value of the extended double-precision floating-point +| value `a'. The operation is performed according to the IEC/IEEE Standard +| for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +BX_CPP_INLINE floatx80& floatx80_abs(floatx80 ®) +#else +BX_CPP_INLINE floatx80 floatx80_abs(floatx80 reg) +#endif +{ + reg.exp &= 0x7FFF; + return reg; +} + +/*----------------------------------------------------------------------------- +| Changes the sign of the extended double-precision floating-point value 'a'. +| The operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +BX_CPP_INLINE floatx80& floatx80_chs(floatx80 ®) +#else +BX_CPP_INLINE floatx80 floatx80_chs(floatx80 reg) +#endif +{ + reg.exp ^= 0x8000; + return reg; +} + +/*----------------------------------------------------------------------------- +| Commonly used extended double-precision floating-point constants. +*----------------------------------------------------------------------------*/ + +extern const floatx80 Const_Z; +extern const floatx80 Const_1; +extern const floatx80 Const_L2T; +extern const floatx80 Const_L2E; +extern const floatx80 Const_PI; +extern const floatx80 Const_LG2; +extern const floatx80 Const_LN2; +extern const floatx80 Const_INF; +#endif diff --git a/src/cpu/x86.c b/src/cpu/x86.c index eb1dc463f..76101c344 100644 --- a/src/cpu/x86.c +++ b/src/cpu/x86.c @@ -29,6 +29,7 @@ #include <86box/device.h> #include <86box/dma.h> #include <86box/io.h> +#include <86box/keyboard.h> #include <86box/mem.h> #include <86box/rom.h> #include <86box/nmi.h> @@ -244,7 +245,7 @@ reset_common(int hard) /* TODO: Hack, but will do for time being, because all AT machines currently are 286+, and vice-versa. */ dma_set_at(is286); - device_reset_all(); + device_reset_all(DEVICE_ALL); } } @@ -265,9 +266,12 @@ reset_common(int hard) if (is286) { loadcs(0xF000); cpu_state.pc = 0xFFF0; - rammask = cpu_16bitbus ? 0xFFFFFF : 0xFFFFFFFF; - if (is6117) - rammask |= 0x03000000; + if (hard) { + rammask = cpu_16bitbus ? 0xFFFFFF : 0xFFFFFFFF; + if (is6117) + rammask |= 0x03000000; + mem_a20_key = mem_a20_alt = mem_a20_state = 0; + } } idt.base = 0; cpu_state.flags = 2; @@ -315,6 +319,10 @@ reset_common(int hard) cache_index = 0; memset(_tr, 0x00, sizeof(_tr)); memset(_cache, 0x00, sizeof(_cache)); + + /* If we have an AT or PS/2 keyboard controller, make sure the A20 state + is correct. */ + device_reset_all(DEVICE_KBC); } if (!is286) @@ -351,7 +359,7 @@ hardresetx86(void) /* TODO: Hack, but will do for time being, because all AT machines currently are 286+, and vice-versa. */ dma_set_at(is286); - device_reset_all(); + device_reset_all(DEVICE_ALL); cpu_alt_reset = 0; diff --git a/src/cpu/x86_flags.h b/src/cpu/x86_flags.h index b8b1a706a..e82041783 100644 --- a/src/cpu/x86_flags.h +++ b/src/cpu/x86_flags.h @@ -536,7 +536,7 @@ flags_rebuild_c(void) static __inline int flags_res_valid(void) { - if (cpu_state.flags_op == FLAGS_UNKNOWN || (cpu_state.flags_op >= FLAGS_ROL8 && cpu_state.flags_op <= FLAGS_ROR32)) + if ((cpu_state.flags_op == FLAGS_UNKNOWN) || ((cpu_state.flags_op >= FLAGS_ROL8) && (cpu_state.flags_op <= FLAGS_ROR32))) return 0; return 1; diff --git a/src/cpu/x86_ops.h b/src/cpu/x86_ops.h index ca4d83d69..0cd449236 100644 --- a/src/cpu/x86_ops.h +++ b/src/cpu/x86_ops.h @@ -102,6 +102,38 @@ extern const OpFn dynarec_ops_pentiumpro_0f[1024]; extern const OpFn dynarec_ops_pentium2_0f[1024]; extern const OpFn dynarec_ops_pentium2d_0f[1024]; +extern const OpFn dynarec_ops_sf_fpu_287_d9_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_287_d9_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_287_da_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_287_da_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_287_db_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_287_db_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_287_dc_a16[32]; +extern const OpFn dynarec_ops_sf_fpu_287_dc_a32[32]; +extern const OpFn dynarec_ops_sf_fpu_287_dd_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_287_dd_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_287_de_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_287_de_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_287_df_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_287_df_a32[256]; + +extern const OpFn dynarec_ops_sf_fpu_d8_a16[32]; +extern const OpFn dynarec_ops_sf_fpu_d8_a32[32]; +extern const OpFn dynarec_ops_sf_fpu_d9_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_d9_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_da_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_da_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_db_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_db_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_dc_a16[32]; +extern const OpFn dynarec_ops_sf_fpu_dc_a32[32]; +extern const OpFn dynarec_ops_sf_fpu_dd_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_dd_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_de_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_de_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_df_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_df_a32[256]; + extern const OpFn dynarec_ops_fpu_287_d9_a16[256]; extern const OpFn dynarec_ops_fpu_287_d9_a32[256]; extern const OpFn dynarec_ops_fpu_287_da_a16[256]; @@ -136,6 +168,13 @@ extern const OpFn dynarec_ops_fpu_df_a32[256]; extern const OpFn dynarec_ops_nofpu_a16[256]; extern const OpFn dynarec_ops_nofpu_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_686_da_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_686_da_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_686_db_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_686_db_a32[256]; +extern const OpFn dynarec_ops_sf_fpu_686_df_a16[256]; +extern const OpFn dynarec_ops_sf_fpu_686_df_a32[256]; + extern const OpFn dynarec_ops_fpu_686_da_a16[256]; extern const OpFn dynarec_ops_fpu_686_da_a32[256]; extern const OpFn dynarec_ops_fpu_686_db_a16[256]; @@ -151,6 +190,7 @@ extern const OpFn dynarec_ops_3DNOWE[256]; void x86_setopcodes(const OpFn *opcodes, const OpFn *opcodes_0f); #endif + extern const OpFn *x86_opcodes; extern const OpFn *x86_opcodes_0f; extern const OpFn *x86_opcodes_d8_a16; @@ -205,6 +245,38 @@ extern const OpFn ops_pentiumpro_0f[1024]; extern const OpFn ops_pentium2_0f[1024]; extern const OpFn ops_pentium2d_0f[1024]; +extern const OpFn ops_sf_fpu_287_d9_a16[256]; +extern const OpFn ops_sf_fpu_287_d9_a32[256]; +extern const OpFn ops_sf_fpu_287_da_a16[256]; +extern const OpFn ops_sf_fpu_287_da_a32[256]; +extern const OpFn ops_sf_fpu_287_db_a16[256]; +extern const OpFn ops_sf_fpu_287_db_a32[256]; +extern const OpFn ops_sf_fpu_287_dc_a16[32]; +extern const OpFn ops_sf_fpu_287_dc_a32[32]; +extern const OpFn ops_sf_fpu_287_dd_a16[256]; +extern const OpFn ops_sf_fpu_287_dd_a32[256]; +extern const OpFn ops_sf_fpu_287_de_a16[256]; +extern const OpFn ops_sf_fpu_287_de_a32[256]; +extern const OpFn ops_sf_fpu_287_df_a16[256]; +extern const OpFn ops_sf_fpu_287_df_a32[256]; + +extern const OpFn ops_sf_fpu_d8_a16[32]; +extern const OpFn ops_sf_fpu_d8_a32[32]; +extern const OpFn ops_sf_fpu_d9_a16[256]; +extern const OpFn ops_sf_fpu_d9_a32[256]; +extern const OpFn ops_sf_fpu_da_a16[256]; +extern const OpFn ops_sf_fpu_da_a32[256]; +extern const OpFn ops_sf_fpu_db_a16[256]; +extern const OpFn ops_sf_fpu_db_a32[256]; +extern const OpFn ops_sf_fpu_dc_a16[32]; +extern const OpFn ops_sf_fpu_dc_a32[32]; +extern const OpFn ops_sf_fpu_dd_a16[256]; +extern const OpFn ops_sf_fpu_dd_a32[256]; +extern const OpFn ops_sf_fpu_de_a16[256]; +extern const OpFn ops_sf_fpu_de_a32[256]; +extern const OpFn ops_sf_fpu_df_a16[256]; +extern const OpFn ops_sf_fpu_df_a32[256]; + extern const OpFn ops_fpu_287_d9_a16[256]; extern const OpFn ops_fpu_287_d9_a32[256]; extern const OpFn ops_fpu_287_da_a16[256]; @@ -239,6 +311,13 @@ extern const OpFn ops_fpu_df_a32[256]; extern const OpFn ops_nofpu_a16[256]; extern const OpFn ops_nofpu_a32[256]; +extern const OpFn ops_sf_fpu_686_da_a16[256]; +extern const OpFn ops_sf_fpu_686_da_a32[256]; +extern const OpFn ops_sf_fpu_686_db_a16[256]; +extern const OpFn ops_sf_fpu_686_db_a32[256]; +extern const OpFn ops_sf_fpu_686_df_a16[256]; +extern const OpFn ops_sf_fpu_686_df_a32[256]; + extern const OpFn ops_fpu_686_da_a16[256]; extern const OpFn ops_fpu_686_da_a32[256]; extern const OpFn ops_fpu_686_db_a16[256]; diff --git a/src/cpu/x86_ops_3dnow.h b/src/cpu/x86_ops_3dnow.h index eb7a35ace..ff657d708 100644 --- a/src/cpu/x86_ops_3dnow.h +++ b/src/cpu/x86_ops_3dnow.h @@ -36,17 +36,20 @@ static int opPAVGUSB(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = (cpu_state.MM[cpu_reg].b[0] + src.b[0] + 1) >> 1; - cpu_state.MM[cpu_reg].b[1] = (cpu_state.MM[cpu_reg].b[1] + src.b[1] + 1) >> 1; - cpu_state.MM[cpu_reg].b[2] = (cpu_state.MM[cpu_reg].b[2] + src.b[2] + 1) >> 1; - cpu_state.MM[cpu_reg].b[3] = (cpu_state.MM[cpu_reg].b[3] + src.b[3] + 1) >> 1; - cpu_state.MM[cpu_reg].b[4] = (cpu_state.MM[cpu_reg].b[4] + src.b[4] + 1) >> 1; - cpu_state.MM[cpu_reg].b[5] = (cpu_state.MM[cpu_reg].b[5] + src.b[5] + 1) >> 1; - cpu_state.MM[cpu_reg].b[6] = (cpu_state.MM[cpu_reg].b[6] + src.b[6] + 1) >> 1; - cpu_state.MM[cpu_reg].b[7] = (cpu_state.MM[cpu_reg].b[7] + src.b[7] + 1) >> 1; + dst->b[0] = (dst->b[0] + src.b[0] + 1) >> 1; + dst->b[1] = (dst->b[1] + src.b[1] + 1) >> 1; + dst->b[2] = (dst->b[2] + src.b[2] + 1) >> 1; + dst->b[3] = (dst->b[3] + src.b[3] + 1) >> 1; + dst->b[4] = (dst->b[4] + src.b[4] + 1) >> 1; + dst->b[5] = (dst->b[5] + src.b[5] + 1) >> 1; + dst->b[6] = (dst->b[6] + src.b[6] + 1) >> 1; + dst->b[7] = (dst->b[7] + src.b[7] + 1) >> 1; + + MMX_SETEXP(cpu_reg); return 0; } @@ -54,11 +57,14 @@ static int opPF2ID(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].sl[0] = (int32_t) src.f[0]; - cpu_state.MM[cpu_reg].sl[1] = (int32_t) src.f[1]; + dst->sl[0] = (int32_t) src.f[0]; + dst->sl[1] = (int32_t) src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -66,11 +72,14 @@ static int opPF2IW(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].sw[0] = (int32_t) src.f[0]; - cpu_state.MM[cpu_reg].sw[1] = (int32_t) src.f[1]; + dst->sw[0] = (int32_t) src.f[0]; + dst->sw[1] = (int32_t) src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -78,13 +87,16 @@ static int opPFACC(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); float tempf; MMX_GETSRC(); - tempf = cpu_state.MM[cpu_reg].f[0] + cpu_state.MM[cpu_reg].f[1]; - cpu_state.MM[cpu_reg].f[1] = src.f[0] + src.f[1]; - cpu_state.MM[cpu_reg].f[0] = tempf; + tempf = dst->f[0] + dst->f[1]; + dst->f[1] = src.f[0] + src.f[1]; + dst->f[0] = tempf; + + MMX_SETEXP(cpu_reg); return 0; } @@ -92,13 +104,16 @@ static int opPFNACC(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); float tempf; MMX_GETSRC(); - tempf = cpu_state.MM[cpu_reg].f[0] - cpu_state.MM[cpu_reg].f[1]; - cpu_state.MM[cpu_reg].f[1] = src.f[0] - src.f[1]; - cpu_state.MM[cpu_reg].f[0] = tempf; + tempf = dst->f[0] - dst->f[1]; + dst->f[1] = src.f[0] - src.f[1]; + dst->f[0] = tempf; + + MMX_SETEXP(cpu_reg); return 0; } @@ -106,13 +121,16 @@ static int opPFPNACC(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); float tempf; MMX_GETSRC(); - tempf = cpu_state.MM[cpu_reg].f[0] - cpu_state.MM[cpu_reg].f[1]; - cpu_state.MM[cpu_reg].f[1] = src.f[0] + src.f[1]; - cpu_state.MM[cpu_reg].f[0] = tempf; + tempf = dst->f[0] - dst->f[1]; + dst->f[1] = src.f[0] + src.f[1]; + dst->f[0] = tempf; + + MMX_SETEXP(cpu_reg); return 0; } @@ -120,15 +138,18 @@ static int opPSWAPD(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); float tempf, tempf2; MMX_GETSRC(); /* We have to do this in case source and destination overlap. */ - tempf = src.f[0]; - tempf2 = src.f[1]; - cpu_state.MM[cpu_reg].f[1] = tempf; - cpu_state.MM[cpu_reg].f[0] = tempf2; + tempf = src.f[0]; + tempf2 = src.f[1]; + dst->f[1] = tempf; + dst->f[0] = tempf2; + + MMX_SETEXP(cpu_reg); return 0; } @@ -136,11 +157,14 @@ static int opPFADD(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] += src.f[0]; - cpu_state.MM[cpu_reg].f[1] += src.f[1]; + dst->f[0] += src.f[0]; + dst->f[1] += src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -148,11 +172,14 @@ static int opPFCMPEQ(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = (cpu_state.MM[cpu_reg].f[0] == src.f[0]) ? 0xffffffff : 0; - cpu_state.MM[cpu_reg].l[1] = (cpu_state.MM[cpu_reg].f[1] == src.f[1]) ? 0xffffffff : 0; + dst->l[0] = (dst->f[0] == src.f[0]) ? 0xffffffff : 0; + dst->l[1] = (dst->f[1] == src.f[1]) ? 0xffffffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -160,11 +187,14 @@ static int opPFCMPGE(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = (cpu_state.MM[cpu_reg].f[0] >= src.f[0]) ? 0xffffffff : 0; - cpu_state.MM[cpu_reg].l[1] = (cpu_state.MM[cpu_reg].f[1] >= src.f[1]) ? 0xffffffff : 0; + dst->l[0] = (dst->f[0] >= src.f[0]) ? 0xffffffff : 0; + dst->l[1] = (dst->f[1] >= src.f[1]) ? 0xffffffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -172,11 +202,14 @@ static int opPFCMPGT(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = (cpu_state.MM[cpu_reg].f[0] > src.f[0]) ? 0xffffffff : 0; - cpu_state.MM[cpu_reg].l[1] = (cpu_state.MM[cpu_reg].f[1] > src.f[1]) ? 0xffffffff : 0; + dst->l[0] = (dst->f[0] > src.f[0]) ? 0xffffffff : 0; + dst->l[1] = (dst->f[1] > src.f[1]) ? 0xffffffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -184,13 +217,16 @@ static int opPFMAX(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - if (src.f[0] > cpu_state.MM[cpu_reg].f[0]) - cpu_state.MM[cpu_reg].f[0] = src.f[0]; - if (src.f[1] > cpu_state.MM[cpu_reg].f[1]) - cpu_state.MM[cpu_reg].f[1] = src.f[1]; + if (src.f[0] > dst->f[0]) + dst->f[0] = src.f[0]; + if (src.f[1] > dst->f[1]) + dst->f[1] = src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -198,13 +234,16 @@ static int opPFMIN(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - if (src.f[0] < cpu_state.MM[cpu_reg].f[0]) - cpu_state.MM[cpu_reg].f[0] = src.f[0]; - if (src.f[1] < cpu_state.MM[cpu_reg].f[1]) - cpu_state.MM[cpu_reg].f[1] = src.f[1]; + if (src.f[0] < dst->f[0]) + dst->f[0] = src.f[0]; + if (src.f[1] < dst->f[1]) + dst->f[1] = src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -212,24 +251,29 @@ static int opPFMUL(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] *= src.f[0]; - cpu_state.MM[cpu_reg].f[1] *= src.f[1]; + dst->f[0] *= src.f[0]; + dst->f[1] *= src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } static int opPFRCP(uint32_t fetchdat) { + MMX_REG *dst = MMX_GETREGP(cpu_reg); + union { uint32_t i; float f; } src; if (cpu_mod == 3) { - src.f = cpu_state.MM[cpu_rm].f[0]; + src.f = (MMX_GETREG(cpu_rm)).f[0]; CLOCK_CYCLES(1); } else { SEG_CHECK_READ(cpu_state.ea_seg); @@ -239,8 +283,10 @@ opPFRCP(uint32_t fetchdat) CLOCK_CYCLES(2); } - cpu_state.MM[cpu_reg].f[0] = 1.0 / src.f; - cpu_state.MM[cpu_reg].f[1] = cpu_state.MM[cpu_reg].f[0]; + dst->f[0] = 1.0 / src.f; + dst->f[1] = dst->f[0]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -249,11 +295,14 @@ static int opPFRCPIT1(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] = src.f[0]; - cpu_state.MM[cpu_reg].f[1] = src.f[1]; + dst->f[0] = src.f[0]; + dst->f[1] = src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -261,24 +310,29 @@ static int opPFRCPIT2(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] = src.f[0]; - cpu_state.MM[cpu_reg].f[1] = src.f[1]; + dst->f[0] = src.f[0]; + dst->f[1] = src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } static int opPFRSQRT(uint32_t fetchdat) { + MMX_REG *dst = MMX_GETREGP(cpu_reg); + union { uint32_t i; float f; } src; if (cpu_mod == 3) { - src.f = cpu_state.MM[cpu_rm].f[0]; + src.f = (MMX_GETREG(cpu_rm)).f[0]; CLOCK_CYCLES(1); } else { SEG_CHECK_READ(cpu_state.ea_seg); @@ -288,8 +342,10 @@ opPFRSQRT(uint32_t fetchdat) CLOCK_CYCLES(2); } - cpu_state.MM[cpu_reg].f[0] = 1.0 / sqrt(src.f); - cpu_state.MM[cpu_reg].f[1] = cpu_state.MM[cpu_reg].f[0]; + dst->f[0] = 1.0 / sqrt(src.f); + dst->f[1] = dst->f[0]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -308,11 +364,14 @@ static int opPFSUB(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] -= src.f[0]; - cpu_state.MM[cpu_reg].f[1] -= src.f[1]; + dst->f[0] -= src.f[0]; + dst->f[1] -= src.f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -320,11 +379,14 @@ static int opPFSUBR(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] = src.f[0] - cpu_state.MM[cpu_reg].f[0]; - cpu_state.MM[cpu_reg].f[1] = src.f[1] - cpu_state.MM[cpu_reg].f[1]; + dst->f[0] = src.f[0] - dst->f[0]; + dst->f[1] = src.f[1] - dst->f[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -332,11 +394,14 @@ static int opPI2FD(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] = (float) src.sl[0]; - cpu_state.MM[cpu_reg].f[1] = (float) src.sl[1]; + dst->f[0] = (float) src.sl[0]; + dst->f[1] = (float) src.sl[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -344,37 +409,46 @@ static int opPI2FW(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); MMX_GETSRC(); - cpu_state.MM[cpu_reg].f[0] = (float) src.sw[0]; - cpu_state.MM[cpu_reg].f[1] = (float) src.sw[1]; + dst->f[0] = (float) src.sw[0]; + dst->f[1] = (float) src.sw[1]; + + MMX_SETEXP(cpu_reg); return 0; } static int opPMULHRW(uint32_t fetchdat) { + MMX_REG src; + MMX_REG *dst = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].w[0] = (((int32_t) cpu_state.MM[cpu_reg].sw[0] * (int32_t) cpu_state.MM[cpu_rm].sw[0]) + 0x8000) >> 16; - cpu_state.MM[cpu_reg].w[1] = (((int32_t) cpu_state.MM[cpu_reg].sw[1] * (int32_t) cpu_state.MM[cpu_rm].sw[1]) + 0x8000) >> 16; - cpu_state.MM[cpu_reg].w[2] = (((int32_t) cpu_state.MM[cpu_reg].sw[2] * (int32_t) cpu_state.MM[cpu_rm].sw[2]) + 0x8000) >> 16; - cpu_state.MM[cpu_reg].w[3] = (((int32_t) cpu_state.MM[cpu_reg].sw[3] * (int32_t) cpu_state.MM[cpu_rm].sw[3]) + 0x8000) >> 16; + src = MMX_GETREG(cpu_rm); + + dst->w[0] = (((int32_t) dst->sw[0] * (int32_t) src.sw[0]) + 0x8000) >> 16; + dst->w[1] = (((int32_t) dst->sw[1] * (int32_t) src.sw[1]) + 0x8000) >> 16; + dst->w[2] = (((int32_t) dst->sw[2] * (int32_t) src.sw[2]) + 0x8000) >> 16; + dst->w[3] = (((int32_t) dst->sw[3] * (int32_t) src.sw[3]) + 0x8000) >> 16; CLOCK_CYCLES(1); } else { - MMX_REG src; - SEG_CHECK_READ(cpu_state.ea_seg); src.l[0] = readmeml(easeg, cpu_state.eaaddr); src.l[1] = readmeml(easeg, cpu_state.eaaddr + 4); if (cpu_state.abrt) return 0; - cpu_state.MM[cpu_reg].w[0] = ((int32_t) (cpu_state.MM[cpu_reg].sw[0] * (int32_t) src.sw[0]) + 0x8000) >> 16; - cpu_state.MM[cpu_reg].w[1] = ((int32_t) (cpu_state.MM[cpu_reg].sw[1] * (int32_t) src.sw[1]) + 0x8000) >> 16; - cpu_state.MM[cpu_reg].w[2] = ((int32_t) (cpu_state.MM[cpu_reg].sw[2] * (int32_t) src.sw[2]) + 0x8000) >> 16; - cpu_state.MM[cpu_reg].w[3] = ((int32_t) (cpu_state.MM[cpu_reg].sw[3] * (int32_t) src.sw[3]) + 0x8000) >> 16; + dst->w[0] = ((int32_t) (dst->sw[0] * (int32_t) src.sw[0]) + 0x8000) >> 16; + dst->w[1] = ((int32_t) (dst->sw[1] * (int32_t) src.sw[1]) + 0x8000) >> 16; + dst->w[2] = ((int32_t) (dst->sw[2] * (int32_t) src.sw[2]) + 0x8000) >> 16; + dst->w[3] = ((int32_t) (dst->sw[3] * (int32_t) src.sw[3]) + 0x8000) >> 16; CLOCK_CYCLES(2); } + + MMX_SETEXP(cpu_reg); + return 0; } diff --git a/src/cpu/x86_ops_fpu.h b/src/cpu/x86_ops_fpu.h index 314ec321b..29e999941 100644 --- a/src/cpu/x86_ops_fpu.h +++ b/src/cpu/x86_ops_fpu.h @@ -96,6 +96,16 @@ opWAIT(uint32_t fetchdat) x86_int(7); return 1; } + + // if (!cpu_use_dynarec && fpu_softfloat) { + if (fpu_softfloat) { + if (fpu_state.swd & FPU_SW_Summary) { + if (cr0 & 0x20) { + x86_int(16); + return 1; + } + } + } CLOCK_CYCLES(4); return 0; } diff --git a/src/cpu/x86_ops_i686.h b/src/cpu/x86_ops_i686.h index 8940a98a0..f2b07a1c4 100644 --- a/src/cpu/x86_ops_i686.h +++ b/src/cpu/x86_ops_i686.h @@ -43,6 +43,132 @@ opSYSEXIT(uint32_t fetchdat) return ret; } +static int +sf_fx_save_stor_common(uint32_t fetchdat, int bits) +{ + uint8_t fxinst = 0; + uint32_t tag_byte; + unsigned index; + floatx80 reg; + + if (CPUID < 0x650) + return ILLEGAL(fetchdat); + + FP_ENTER(); + + if (bits == 32) { + fetch_ea_32(fetchdat); + } else { + fetch_ea_16(fetchdat); + } + + if (cpu_state.eaaddr & 0xf) { + x386_dynarec_log("Effective address %08X not on 16-byte boundary\n", cpu_state.eaaddr); + x86gpf(NULL, 0); + return cpu_state.abrt; + } + + fxinst = (rmdat >> 3) & 7; + + if ((fxinst > 1) || (cpu_mod == 3)) { + x86illegal(); + return cpu_state.abrt; + } + + FP_ENTER(); + + if (fxinst == 1) { + /* FXRSTOR */ + fpu_state.cwd = readmemw(easeg, cpu_state.eaaddr); + fpu_state.swd = readmemw(easeg, cpu_state.eaaddr + 2); + fpu_state.tos = (fpu_state.swd >> 11) & 7; + + /* always set bit 6 as '1 */ + fpu_state.cwd = (fpu_state.cwd & ~FPU_CW_Reserved_Bits) | 0x0040; + + /* Restore x87 FPU Opcode */ + /* The lower 11 bits contain the FPU opcode, upper 5 bits are reserved */ + fpu_state.foo = readmemw(easeg, cpu_state.eaaddr + 6) & 0x7FF; + + fpu_state.fip = readmeml(easeg, cpu_state.eaaddr + 8); + fpu_state.fcs = readmemw(easeg, cpu_state.eaaddr + 12); + + tag_byte = readmemb(easeg, cpu_state.eaaddr + 4); + + fpu_state.fdp = readmeml(easeg, cpu_state.eaaddr + 16); + fpu_state.fds = readmemw(easeg, cpu_state.eaaddr + 20); + + /* load i387 register file */ + for (index = 0; index < 8; index++) { + reg.fraction = readmemq(easeg, cpu_state.eaaddr + (index * 16) + 32); + reg.exp = readmemw(easeg, cpu_state.eaaddr + (index * 16) + 40); + + // update tag only if it is not empty + FPU_save_regi_tag(reg, IS_TAG_EMPTY(index) ? X87_TAG_EMPTY : FPU_tagof(reg), index); + } + + fpu_state.tag = unpack_FPU_TW(tag_byte); + + /* check for unmasked exceptions */ + if (fpu_state.swd & ~fpu_state.cwd & FPU_CW_Exceptions_Mask) { + /* set the B and ES bits in the status-word */ + fpu_state.swd |= (FPU_SW_Summary | FPU_SW_Backward); + } else { + /* clear the B and ES bits in the status-word */ + fpu_state.swd &= ~(FPU_SW_Summary | FPU_SW_Backward); + } + + CLOCK_CYCLES((cr0 & 1) ? 34 : 44); + } else { + /* FXSAVE */ + writememw(easeg, cpu_state.eaaddr, i387_get_control_word()); + writememw(easeg, cpu_state.eaaddr + 2, i387_get_status_word()); + writememw(easeg, cpu_state.eaaddr + 4, pack_FPU_TW(fpu_state.tag)); + + /* x87 FPU Opcode (16 bits) */ + /* The lower 11 bits contain the FPU opcode, upper 5 bits are reserved */ + writememw(easeg, cpu_state.eaaddr + 6, fpu_state.foo); + + /* + * x87 FPU IP Offset (32/64 bits) + * The contents of this field differ depending on the current + * addressing mode (16/32/64 bit) when the FXSAVE instruction was executed: + * + 64-bit mode - 64-bit IP offset + * + 32-bit mode - 32-bit IP offset + * + 16-bit mode - low 16 bits are IP offset; high 16 bits are reserved. + * x87 CS FPU IP Selector + * + 16 bit, in 16/32 bit mode only + */ + writememl(easeg, cpu_state.eaaddr + 8, fpu_state.fip); + writememl(easeg, cpu_state.eaaddr + 12, fpu_state.fcs); + + /* + * x87 FPU Instruction Operand (Data) Pointer Offset (32/64 bits) + * The contents of this field differ depending on the current + * addressing mode (16/32 bit) when the FXSAVE instruction was executed: + * + 64-bit mode - 64-bit offset + * + 32-bit mode - 32-bit offset + * + 16-bit mode - low 16 bits are offset; high 16 bits are reserved. + * x87 DS FPU Instruction Operand (Data) Pointer Selector + * + 16 bit, in 16/32 bit mode only + */ + writememl(easeg, cpu_state.eaaddr + 16, fpu_state.fdp); + writememl(easeg, cpu_state.eaaddr + 20, fpu_state.fds); + + /* store i387 register file */ + for (index = 0; index < 8; index++) { + const floatx80 fp = FPU_read_regi(index); + + writememq(easeg, cpu_state.eaaddr + (index * 16) + 32, fp.fraction); + writememw(easeg, cpu_state.eaaddr + (index * 16) + 40, fp.exp); + } + + CLOCK_CYCLES((cr0 & 1) ? 56 : 67); + } + + return cpu_state.abrt; +} + static int fx_save_stor_common(uint32_t fetchdat, int bits) { @@ -52,7 +178,64 @@ fx_save_stor_common(uint32_t fetchdat, int bits) uint8_t ftwb = 0; uint16_t rec_ftw = 0; uint16_t fpus = 0; - uint64_t *p; + int i, mmx_tags = 0; + uint16_t exp = 0x0000; + uint64_t mant = 0x0000000000000000ULL; + uint64_t fraction; + uint8_t jm, valid; + /* Exp_all_1 Exp_all_0 Frac_all_0 J M FTW_Valid | Ent + ----------------------------------------------+------ */ + uint8_t ftw_table_idx; + uint8_t ftw_table[48] = { 0x03, /* 0 0 0 0 0 0 | 0x00 */ + 0x02, /* 0 0 0 0 0 1 | 0x01 */ + 0x03, /* 0 0 0 0 0 0 | 0x02 */ + 0x02, /* 0 0 0 0 1 1 | 0x03 */ + 0x03, /* 0 0 0 1 0 0 | 0x04 */ + 0x00, /* 0 0 0 1 0 1 | 0x05 */ + 0x03, /* 0 0 0 1 1 0 | 0x06 */ + 0x00, /* 0 0 0 1 1 1 | 0x07 */ + 0x03, /* 0 0 1 0 0 0 | 0x08 */ + 0x02, /* 0 0 1 0 0 1 | 0x09 */ + 0x03, /* 0 0 1 0 1 0 | 0x0a - Impossible */ + 0x03, /* 0 0 1 0 1 1 | 0x0b - Impossible */ + 0x03, /* 0 0 1 1 0 0 | 0x0c */ + 0x02, /* 0 0 1 1 0 1 | 0x0d */ + 0x03, /* 0 0 1 1 1 0 | 0x0e - Impossible */ + 0x03, /* 0 0 1 1 1 1 | 0x0f - Impossible */ + 0x03, /* 0 1 0 0 0 0 | 0x10 */ + 0x02, /* 0 1 0 0 0 1 | 0x11 */ + 0x03, /* 0 1 0 0 1 0 | 0x12 */ + 0x02, /* 0 1 0 0 1 1 | 0x13 */ + 0x03, /* 0 1 0 1 0 0 | 0x14 */ + 0x02, /* 0 1 0 1 0 1 | 0x15 */ + 0x03, /* 0 1 0 1 1 0 | 0x16 */ + 0x02, /* 0 1 0 1 1 1 | 0x17 */ + 0x03, /* 0 1 1 0 0 0 | 0x18 */ + 0x01, /* 0 1 1 0 0 1 | 0x19 */ + 0x03, /* 0 1 1 0 1 0 | 0x1a - Impossible */ + 0x03, /* 0 1 1 0 1 1 | 0x1b - Impossible */ + 0x03, /* 0 1 1 1 0 0 | 0x1c */ + 0x01, /* 0 1 1 1 0 1 | 0x1d */ + 0x03, /* 0 1 1 1 1 0 | 0x1e - Impossible */ + 0x03, /* 0 1 1 1 1 1 | 0x1f - Impossible */ + 0x03, /* 1 0 0 0 0 0 | 0x20 */ + 0x02, /* 1 0 0 0 0 1 | 0x21 */ + 0x03, /* 1 0 0 0 1 0 | 0x22 */ + 0x02, /* 1 0 0 0 1 1 | 0x23 */ + 0x03, /* 1 0 0 1 0 0 | 0x24 */ + 0x02, /* 1 0 0 1 0 1 | 0x25 */ + 0x03, /* 1 0 0 1 1 0 | 0x26 */ + 0x02, /* 1 0 0 1 1 1 | 0x27 */ + 0x03, /* 1 0 1 0 0 0 | 0x28 */ + 0x02, /* 1 0 1 0 0 1 | 0x29 */ + 0x03, /* 1 0 1 0 1 0 | 0x2a - Impossible */ + 0x03, /* 1 0 1 0 1 1 | 0x2b - Impossible */ + 0x03, /* 1 0 1 1 0 0 | 0x2c */ + 0x02, /* 1 0 1 1 0 1 | 0x2d */ + 0x03, /* 1 0 1 1 1 0 | 0x2e - Impossible */ + 0x03 }; /* 1 0 1 1 1 1 | 0x2f - Impossible */ + /* M is the most significant bit of the franction, so it is impossible + for M to o be 1 when the fraction is all 0's. */ if (CPUID < 0x650) return ILLEGAL(fetchdat); @@ -96,90 +279,70 @@ fx_save_stor_common(uint32_t fetchdat, int bits) ftwb = readmemb(easeg, cpu_state.eaaddr + 4); - if (ftwb & 0x01) - rec_ftw |= 0x0003; - if (ftwb & 0x02) - rec_ftw |= 0x000C; - if (ftwb & 0x04) - rec_ftw |= 0x0030; - if (ftwb & 0x08) - rec_ftw |= 0x00C0; - if (ftwb & 0x10) - rec_ftw |= 0x0300; - if (ftwb & 0x20) - rec_ftw |= 0x0C00; - if (ftwb & 0x40) - rec_ftw |= 0x3000; - if (ftwb & 0x80) - rec_ftw |= 0xC000; - x87_op_off = readmeml(easeg, cpu_state.eaaddr + 16); x87_op_off |= (readmemw(easeg, cpu_state.eaaddr + 6) >> 12) << 16; x87_op_seg = readmemw(easeg, cpu_state.eaaddr + 20); - cpu_state.eaaddr = old_eaaddr + 32; - x87_ldmmx(&(cpu_state.MM[0]), &(cpu_state.MM_w4[0])); - x87_ld_frstor(0); + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + mant = readmemq(easeg, cpu_state.eaaddr); + fraction = mant & 0x7fffffffffffffffULL; + exp = readmemw(easeg, cpu_state.eaaddr + 8); + jm = (mant >> 62) & 0x03; + valid = !(ftwb & (1 << i)); - cpu_state.eaaddr = old_eaaddr + 48; - x87_ldmmx(&(cpu_state.MM[1]), &(cpu_state.MM_w4[1])); - x87_ld_frstor(1); + ftw_table_idx = (!!(exp == 0x1111)) << 5; + ftw_table_idx |= (!!(exp == 0x0000)) << 4; + ftw_table_idx |= (!!(fraction == 0x0000000000000000ULL)) << 3; + ftw_table_idx |= (jm << 1); + ftw_table_idx |= valid; - cpu_state.eaaddr = old_eaaddr + 64; - x87_ldmmx(&(cpu_state.MM[2]), &(cpu_state.MM_w4[2])); - x87_ld_frstor(2); + rec_ftw |= (ftw_table[ftw_table_idx] << (i << 1)); - cpu_state.eaaddr = old_eaaddr + 80; - x87_ldmmx(&(cpu_state.MM[3]), &(cpu_state.MM_w4[3])); - x87_ld_frstor(3); - - cpu_state.eaaddr = old_eaaddr + 96; - x87_ldmmx(&(cpu_state.MM[4]), &(cpu_state.MM_w4[4])); - x87_ld_frstor(4); - - cpu_state.eaaddr = old_eaaddr + 112; - x87_ldmmx(&(cpu_state.MM[5]), &(cpu_state.MM_w4[5])); - x87_ld_frstor(5); - - cpu_state.eaaddr = old_eaaddr + 128; - x87_ldmmx(&(cpu_state.MM[6]), &(cpu_state.MM_w4[6])); - x87_ld_frstor(6); - - cpu_state.eaaddr = old_eaaddr + 144; - x87_ldmmx(&(cpu_state.MM[7]), &(cpu_state.MM_w4[7])); - x87_ld_frstor(7); + if (exp == 0xffff) + mmx_tags++; + } cpu_state.ismmx = 0; - /*Horrible hack, but as 86Box doesn't keep the FPU stack in 80-bit precision at all times - something like this is needed*/ - p = (uint64_t *) cpu_state.tag; -#ifdef USE_NEW_DYNAREC - if (cpu_state.MM_w4[0] == 0xffff && cpu_state.MM_w4[1] == 0xffff && cpu_state.MM_w4[2] == 0xffff && cpu_state.MM_w4[3] == 0xffff && cpu_state.MM_w4[4] == 0xffff && cpu_state.MM_w4[5] == 0xffff && cpu_state.MM_w4[6] == 0xffff && cpu_state.MM_w4[7] == 0xffff && !cpu_state.TOP && (*p == 0x0101010101010101ull)) -#else - if (cpu_state.MM_w4[0] == 0xffff && cpu_state.MM_w4[1] == 0xffff && cpu_state.MM_w4[2] == 0xffff && cpu_state.MM_w4[3] == 0xffff && cpu_state.MM_w4[4] == 0xffff && cpu_state.MM_w4[5] == 0xffff && cpu_state.MM_w4[6] == 0xffff && cpu_state.MM_w4[7] == 0xffff && !cpu_state.TOP && !(*p)) -#endif + /* Determine, whether or not the saved state is x87 or MMX based on a heuristic, + because we do not keep the internal state in 64-bit precision. + + TODO: Is there no way to unify the whole lot? */ + if ((mmx_tags == 8) && !cpu_state.TOP) cpu_state.ismmx = 1; x87_settag(rec_ftw); + if (cpu_state.ismmx) { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_ldmmx(&(cpu_state.MM[i]), &(cpu_state.MM_w4[i])); + } + } else { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_ld_frstor(i); + } + } + CLOCK_CYCLES((cr0 & 1) ? 34 : 44); } else { /* FXSAVE */ - if ((twd & 0x0003) == 0x0003) + if ((twd & 0x0003) != 0x0003) ftwb |= 0x01; - if ((twd & 0x000C) == 0x000C) + if ((twd & 0x000c) != 0x000c) ftwb |= 0x02; - if ((twd & 0x0030) == 0x0030) + if ((twd & 0x0030) != 0x0030) ftwb |= 0x04; - if ((twd & 0x00C0) == 0x00C0) + if ((twd & 0x00c0) != 0x00c0) ftwb |= 0x08; - if ((twd & 0x0300) == 0x0300) + if ((twd & 0x0300) != 0x0300) ftwb |= 0x10; - if ((twd & 0x0C00) == 0x0C00) + if ((twd & 0x0c00) != 0x0c00) ftwb |= 0x20; - if ((twd & 0x3000) == 0x3000) + if ((twd & 0x3000) != 0x3000) ftwb |= 0x40; - if ((twd & 0xC000) == 0xC000) + if ((twd & 0xc000) != 0xc000) ftwb |= 0x80; writememw(easeg, cpu_state.eaaddr, cpu_state.npxc); @@ -193,44 +356,20 @@ fx_save_stor_common(uint32_t fetchdat, int bits) writememl(easeg, cpu_state.eaaddr + 16, x87_op_off); writememw(easeg, cpu_state.eaaddr + 20, x87_op_seg); - cpu_state.eaaddr = old_eaaddr + 32; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[0]) : x87_st_fsave(0); - - cpu_state.eaaddr = old_eaaddr + 48; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[1]) : x87_st_fsave(1); - - cpu_state.eaaddr = old_eaaddr + 64; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[2]) : x87_st_fsave(2); - - cpu_state.eaaddr = old_eaaddr + 80; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[3]) : x87_st_fsave(3); - - cpu_state.eaaddr = old_eaaddr + 96; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[4]) : x87_st_fsave(4); - - cpu_state.eaaddr = old_eaaddr + 112; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[5]) : x87_st_fsave(5); - - cpu_state.eaaddr = old_eaaddr + 128; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[6]) : x87_st_fsave(6); - - cpu_state.eaaddr = old_eaaddr + 144; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[7]) : x87_st_fsave(7); + if (cpu_state.ismmx) { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_stmmx(cpu_state.MM[i]); + } + } else { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_st_fsave(i); + } + } cpu_state.eaaddr = old_eaaddr; - cpu_state.npxc = 0x37F; - codegen_set_rounding_mode(X87_ROUNDING_NEAREST); - cpu_state.npxs = 0; - p = (uint64_t *) cpu_state.tag; -#ifdef USE_NEW_DYNAREC - *p = 0; -#else - *p = 0x0303030303030303ll; -#endif - cpu_state.TOP = 0; - cpu_state.ismmx = 0; - CLOCK_CYCLES((cr0 & 1) ? 56 : 67); } @@ -240,12 +379,18 @@ fx_save_stor_common(uint32_t fetchdat, int bits) static int opFXSAVESTOR_a16(uint32_t fetchdat) { + if (fpu_softfloat) + return sf_fx_save_stor_common(fetchdat, 16); + return fx_save_stor_common(fetchdat, 16); } static int opFXSAVESTOR_a32(uint32_t fetchdat) { + if (fpu_softfloat) + return sf_fx_save_stor_common(fetchdat, 32); + return fx_save_stor_common(fetchdat, 32); } diff --git a/src/cpu/x86_ops_io.h b/src/cpu/x86_ops_io.h index c4d46404d..8a99b8668 100644 --- a/src/cpu/x86_ops_io.h +++ b/src/cpu/x86_ops_io.h @@ -2,7 +2,7 @@ static int opIN_AL_imm(uint32_t fetchdat) { uint16_t port = (uint16_t) getbytef(); - check_io_perm(port); + check_io_perm(port, 1); AL = inb(port); CLOCK_CYCLES(12); PREFETCH_RUN(12, 2, -1, 1, 0, 0, 0, 0); @@ -14,8 +14,7 @@ static int opIN_AX_imm(uint32_t fetchdat) { uint16_t port = (uint16_t) getbytef(); - check_io_perm(port); - check_io_perm(port + 1); + check_io_perm(port, 2); AX = inw(port); CLOCK_CYCLES(12); PREFETCH_RUN(12, 2, -1, 1, 0, 0, 0, 0); @@ -27,10 +26,7 @@ static int opIN_EAX_imm(uint32_t fetchdat) { uint16_t port = (uint16_t) getbytef(); - check_io_perm(port); - check_io_perm(port + 1); - check_io_perm(port + 2); - check_io_perm(port + 3); + check_io_perm(port, 4); EAX = inl(port); CLOCK_CYCLES(12); PREFETCH_RUN(12, 2, -1, 0, 1, 0, 0, 0); @@ -43,7 +39,7 @@ static int opOUT_AL_imm(uint32_t fetchdat) { uint16_t port = (uint16_t) getbytef(); - check_io_perm(port); + check_io_perm(port, 1); outb(port, AL); CLOCK_CYCLES(10); PREFETCH_RUN(10, 2, -1, 0, 0, 1, 0, 0); @@ -57,8 +53,7 @@ static int opOUT_AX_imm(uint32_t fetchdat) { uint16_t port = (uint16_t) getbytef(); - check_io_perm(port); - check_io_perm(port + 1); + check_io_perm(port, 2); outw(port, AX); CLOCK_CYCLES(10); PREFETCH_RUN(10, 2, -1, 0, 0, 1, 0, 0); @@ -70,10 +65,7 @@ static int opOUT_EAX_imm(uint32_t fetchdat) { uint16_t port = (uint16_t) getbytef(); - check_io_perm(port); - check_io_perm(port + 1); - check_io_perm(port + 2); - check_io_perm(port + 3); + check_io_perm(port, 4); outl(port, EAX); CLOCK_CYCLES(10); PREFETCH_RUN(10, 2, -1, 0, 0, 0, 1, 0); @@ -85,7 +77,7 @@ opOUT_EAX_imm(uint32_t fetchdat) static int opIN_AL_DX(uint32_t fetchdat) { - check_io_perm(DX); + check_io_perm(DX, 1); AL = inb(DX); CLOCK_CYCLES(12); PREFETCH_RUN(12, 1, -1, 1, 0, 0, 0, 0); @@ -96,8 +88,7 @@ opIN_AL_DX(uint32_t fetchdat) static int opIN_AX_DX(uint32_t fetchdat) { - check_io_perm(DX); - check_io_perm(DX + 1); + check_io_perm(DX, 2); AX = inw(DX); CLOCK_CYCLES(12); PREFETCH_RUN(12, 1, -1, 1, 0, 0, 0, 0); @@ -108,10 +99,7 @@ opIN_AX_DX(uint32_t fetchdat) static int opIN_EAX_DX(uint32_t fetchdat) { - check_io_perm(DX); - check_io_perm(DX + 1); - check_io_perm(DX + 2); - check_io_perm(DX + 3); + check_io_perm(DX, 4); EAX = inl(DX); CLOCK_CYCLES(12); PREFETCH_RUN(12, 1, -1, 0, 1, 0, 0, 0); @@ -123,7 +111,7 @@ opIN_EAX_DX(uint32_t fetchdat) static int opOUT_AL_DX(uint32_t fetchdat) { - check_io_perm(DX); + check_io_perm(DX, 1); outb(DX, AL); CLOCK_CYCLES(11); PREFETCH_RUN(11, 1, -1, 0, 0, 1, 0, 0); @@ -134,8 +122,7 @@ opOUT_AL_DX(uint32_t fetchdat) static int opOUT_AX_DX(uint32_t fetchdat) { - check_io_perm(DX); - check_io_perm(DX + 1); + check_io_perm(DX, 2); outw(DX, AX); CLOCK_CYCLES(11); PREFETCH_RUN(11, 1, -1, 0, 0, 1, 0, 0); @@ -146,10 +133,7 @@ opOUT_AX_DX(uint32_t fetchdat) static int opOUT_EAX_DX(uint32_t fetchdat) { - check_io_perm(DX); - check_io_perm(DX + 1); - check_io_perm(DX + 2); - check_io_perm(DX + 3); + check_io_perm(DX, 4); outl(DX, EAX); PREFETCH_RUN(11, 1, -1, 0, 0, 0, 1, 0); if (nmi && nmi_enable && nmi_mask) diff --git a/src/cpu/x86_ops_misc.h b/src/cpu/x86_ops_misc.h index bd1139ba4..60ed873e4 100644 --- a/src/cpu/x86_ops_misc.h +++ b/src/cpu/x86_ops_misc.h @@ -51,8 +51,10 @@ opSETALC(uint32_t fetchdat) static int opF6_a16(uint32_t fetchdat) { - int tempws, tempws2 = 0; - uint16_t tempw, src16; + int tempws = 0; + int tempws2 = 0; + uint16_t tempw = 0; + uint16_t src16; uint8_t src, dst; int8_t temps; @@ -167,8 +169,10 @@ opF6_a16(uint32_t fetchdat) static int opF6_a32(uint32_t fetchdat) { - int tempws, tempws2 = 0; - uint16_t tempw, src16; + int tempws = 0; + int tempws2 = 0; + uint16_t tempw = 0; + uint16_t src16; uint8_t src, dst; int8_t temps; @@ -282,10 +286,13 @@ opF6_a32(uint32_t fetchdat) static int opF7_w_a16(uint32_t fetchdat) { - uint32_t templ, templ2 = 0; - int tempws, tempws2 = 0; + uint32_t templ; + uint32_t templ2 = 0; + int tempws; + int tempws2 = 0; int16_t temps16; - uint16_t src, dst; + uint16_t src; + uint16_t dst; fetch_ea_16(fetchdat); if (cpu_mod != 3) @@ -392,8 +399,10 @@ opF7_w_a16(uint32_t fetchdat) static int opF7_w_a32(uint32_t fetchdat) { - uint32_t templ, templ2 = 0; - int tempws, tempws2 = 1; + uint32_t templ; + uint32_t templ2 = 0; + int tempws; + int tempws2 = 1; int16_t temps16; uint16_t src, dst; @@ -996,7 +1005,7 @@ opLOADALL386(uint32_t fetchdat) loadall_load_segment(la_addr + 0xc0, &cpu_state.seg_es); if (CPL == 3 && oldcpl != 3) - flushmmucache_cr3(); + flushmmucache_nopc(); oldcpl = CPL; CLOCK_CYCLES(350); diff --git a/src/cpu/x86_ops_mmx.c b/src/cpu/x86_ops_mmx.c new file mode 100644 index 000000000..1afc4fba2 --- /dev/null +++ b/src/cpu/x86_ops_mmx.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include +#ifndef INFINITY +# define INFINITY (__builtin_inff()) +#endif +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include "x86.h" +#include "x87.h" +#include <86box/nmi.h> +#include <86box/mem.h> +#include <86box/smram.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/keyboard.h> +#include <86box/timer.h> +#include "386_common.h" +#include "x86_flags.h" +#include "x86seg.h" + +MMX_REG *MMP[8]; +uint16_t *MMEP[8]; + +static uint16_t MME[8]; + +#define MMX_GETREGP(r) fpu_softfloat ? ((MMX_REG *) &fpu_state.st_space[r].fraction) : &(cpu_state.MM[r]) +void +mmx_init(void) +{ + memset(MME, 0xff, sizeof(MME)); + + for (uint8_t i = 0; i < 8; i++) { + if (fpu_softfloat) { + MMP[i] = (MMX_REG *) &fpu_state.st_space[i].fraction; + MMEP[i] = (uint16_t *) &fpu_state.st_space[i].exp; + } else { + MMP[i] = &(cpu_state.MM[i]); + MMEP[i] = &(MME[i]); + } + } +} diff --git a/src/cpu/x86_ops_mmx.h b/src/cpu/x86_ops_mmx.h index d270b728f..47751d059 100644 --- a/src/cpu/x86_ops_mmx.h +++ b/src/cpu/x86_ops_mmx.h @@ -3,9 +3,15 @@ #define USATB(val) (((val) < 0) ? 0 : (((val) > 255) ? 255 : (val))) #define USATW(val) (((val) < 0) ? 0 : (((val) > 65535) ? 65535 : (val))) +#define MMX_GETREGP(r) MMP[r] +#define MMX_GETREG(r) *(MMP[r]) + +#define MMX_SETEXP(r) \ + *(MMEP[r]) = 0xffff + #define MMX_GETSRC() \ if (cpu_mod == 3) { \ - src = cpu_state.MM[cpu_rm]; \ + src = MMX_GETREG(cpu_rm); \ CLOCK_CYCLES(1); \ } else { \ SEG_CHECK_READ(cpu_state.ea_seg); \ diff --git a/src/cpu/x86_ops_mmx_arith.h b/src/cpu/x86_ops_mmx_arith.h index e473f8ec5..642e99c8a 100644 --- a/src/cpu/x86_ops_mmx_arith.h +++ b/src/cpu/x86_ops_mmx_arith.h @@ -2,19 +2,25 @@ static int opPADDB_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] += src.b[0]; - cpu_state.MM[cpu_reg].b[1] += src.b[1]; - cpu_state.MM[cpu_reg].b[2] += src.b[2]; - cpu_state.MM[cpu_reg].b[3] += src.b[3]; - cpu_state.MM[cpu_reg].b[4] += src.b[4]; - cpu_state.MM[cpu_reg].b[5] += src.b[5]; - cpu_state.MM[cpu_reg].b[6] += src.b[6]; - cpu_state.MM[cpu_reg].b[7] += src.b[7]; + dst->b[0] += src.b[0]; + dst->b[1] += src.b[1]; + dst->b[2] += src.b[2]; + dst->b[3] += src.b[3]; + dst->b[4] += src.b[4]; + dst->b[5] += src.b[5]; + dst->b[6] += src.b[6]; + dst->b[7] += src.b[7]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -22,19 +28,25 @@ static int opPADDB_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] += src.b[0]; - cpu_state.MM[cpu_reg].b[1] += src.b[1]; - cpu_state.MM[cpu_reg].b[2] += src.b[2]; - cpu_state.MM[cpu_reg].b[3] += src.b[3]; - cpu_state.MM[cpu_reg].b[4] += src.b[4]; - cpu_state.MM[cpu_reg].b[5] += src.b[5]; - cpu_state.MM[cpu_reg].b[6] += src.b[6]; - cpu_state.MM[cpu_reg].b[7] += src.b[7]; + dst->b[0] += src.b[0]; + dst->b[1] += src.b[1]; + dst->b[2] += src.b[2]; + dst->b[3] += src.b[3]; + dst->b[4] += src.b[4]; + dst->b[5] += src.b[5]; + dst->b[6] += src.b[6]; + dst->b[7] += src.b[7]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -43,15 +55,21 @@ static int opPADDW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] += src.w[0]; - cpu_state.MM[cpu_reg].w[1] += src.w[1]; - cpu_state.MM[cpu_reg].w[2] += src.w[2]; - cpu_state.MM[cpu_reg].w[3] += src.w[3]; + dst->w[0] += src.w[0]; + dst->w[1] += src.w[1]; + dst->w[2] += src.w[2]; + dst->w[3] += src.w[3]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -59,15 +77,21 @@ static int opPADDW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] += src.w[0]; - cpu_state.MM[cpu_reg].w[1] += src.w[1]; - cpu_state.MM[cpu_reg].w[2] += src.w[2]; - cpu_state.MM[cpu_reg].w[3] += src.w[3]; + dst->w[0] += src.w[0]; + dst->w[1] += src.w[1]; + dst->w[2] += src.w[2]; + dst->w[3] += src.w[3]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -76,13 +100,19 @@ static int opPADDD_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] += src.l[0]; - cpu_state.MM[cpu_reg].l[1] += src.l[1]; + dst->l[0] += src.l[0]; + dst->l[1] += src.l[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -90,13 +120,19 @@ static int opPADDD_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] += src.l[0]; - cpu_state.MM[cpu_reg].l[1] += src.l[1]; + dst->l[0] += src.l[0]; + dst->l[1] += src.l[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -105,19 +141,25 @@ static int opPADDSB_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sb[0] = SSATB(cpu_state.MM[cpu_reg].sb[0] + src.sb[0]); - cpu_state.MM[cpu_reg].sb[1] = SSATB(cpu_state.MM[cpu_reg].sb[1] + src.sb[1]); - cpu_state.MM[cpu_reg].sb[2] = SSATB(cpu_state.MM[cpu_reg].sb[2] + src.sb[2]); - cpu_state.MM[cpu_reg].sb[3] = SSATB(cpu_state.MM[cpu_reg].sb[3] + src.sb[3]); - cpu_state.MM[cpu_reg].sb[4] = SSATB(cpu_state.MM[cpu_reg].sb[4] + src.sb[4]); - cpu_state.MM[cpu_reg].sb[5] = SSATB(cpu_state.MM[cpu_reg].sb[5] + src.sb[5]); - cpu_state.MM[cpu_reg].sb[6] = SSATB(cpu_state.MM[cpu_reg].sb[6] + src.sb[6]); - cpu_state.MM[cpu_reg].sb[7] = SSATB(cpu_state.MM[cpu_reg].sb[7] + src.sb[7]); + dst->sb[0] = SSATB(dst->sb[0] + src.sb[0]); + dst->sb[1] = SSATB(dst->sb[1] + src.sb[1]); + dst->sb[2] = SSATB(dst->sb[2] + src.sb[2]); + dst->sb[3] = SSATB(dst->sb[3] + src.sb[3]); + dst->sb[4] = SSATB(dst->sb[4] + src.sb[4]); + dst->sb[5] = SSATB(dst->sb[5] + src.sb[5]); + dst->sb[6] = SSATB(dst->sb[6] + src.sb[6]); + dst->sb[7] = SSATB(dst->sb[7] + src.sb[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -125,19 +167,25 @@ static int opPADDSB_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sb[0] = SSATB(cpu_state.MM[cpu_reg].sb[0] + src.sb[0]); - cpu_state.MM[cpu_reg].sb[1] = SSATB(cpu_state.MM[cpu_reg].sb[1] + src.sb[1]); - cpu_state.MM[cpu_reg].sb[2] = SSATB(cpu_state.MM[cpu_reg].sb[2] + src.sb[2]); - cpu_state.MM[cpu_reg].sb[3] = SSATB(cpu_state.MM[cpu_reg].sb[3] + src.sb[3]); - cpu_state.MM[cpu_reg].sb[4] = SSATB(cpu_state.MM[cpu_reg].sb[4] + src.sb[4]); - cpu_state.MM[cpu_reg].sb[5] = SSATB(cpu_state.MM[cpu_reg].sb[5] + src.sb[5]); - cpu_state.MM[cpu_reg].sb[6] = SSATB(cpu_state.MM[cpu_reg].sb[6] + src.sb[6]); - cpu_state.MM[cpu_reg].sb[7] = SSATB(cpu_state.MM[cpu_reg].sb[7] + src.sb[7]); + dst->sb[0] = SSATB(dst->sb[0] + src.sb[0]); + dst->sb[1] = SSATB(dst->sb[1] + src.sb[1]); + dst->sb[2] = SSATB(dst->sb[2] + src.sb[2]); + dst->sb[3] = SSATB(dst->sb[3] + src.sb[3]); + dst->sb[4] = SSATB(dst->sb[4] + src.sb[4]); + dst->sb[5] = SSATB(dst->sb[5] + src.sb[5]); + dst->sb[6] = SSATB(dst->sb[6] + src.sb[6]); + dst->sb[7] = SSATB(dst->sb[7] + src.sb[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -146,19 +194,25 @@ static int opPADDUSB_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = USATB(cpu_state.MM[cpu_reg].b[0] + src.b[0]); - cpu_state.MM[cpu_reg].b[1] = USATB(cpu_state.MM[cpu_reg].b[1] + src.b[1]); - cpu_state.MM[cpu_reg].b[2] = USATB(cpu_state.MM[cpu_reg].b[2] + src.b[2]); - cpu_state.MM[cpu_reg].b[3] = USATB(cpu_state.MM[cpu_reg].b[3] + src.b[3]); - cpu_state.MM[cpu_reg].b[4] = USATB(cpu_state.MM[cpu_reg].b[4] + src.b[4]); - cpu_state.MM[cpu_reg].b[5] = USATB(cpu_state.MM[cpu_reg].b[5] + src.b[5]); - cpu_state.MM[cpu_reg].b[6] = USATB(cpu_state.MM[cpu_reg].b[6] + src.b[6]); - cpu_state.MM[cpu_reg].b[7] = USATB(cpu_state.MM[cpu_reg].b[7] + src.b[7]); + dst->b[0] = USATB(dst->b[0] + src.b[0]); + dst->b[1] = USATB(dst->b[1] + src.b[1]); + dst->b[2] = USATB(dst->b[2] + src.b[2]); + dst->b[3] = USATB(dst->b[3] + src.b[3]); + dst->b[4] = USATB(dst->b[4] + src.b[4]); + dst->b[5] = USATB(dst->b[5] + src.b[5]); + dst->b[6] = USATB(dst->b[6] + src.b[6]); + dst->b[7] = USATB(dst->b[7] + src.b[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -166,19 +220,25 @@ static int opPADDUSB_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = USATB(cpu_state.MM[cpu_reg].b[0] + src.b[0]); - cpu_state.MM[cpu_reg].b[1] = USATB(cpu_state.MM[cpu_reg].b[1] + src.b[1]); - cpu_state.MM[cpu_reg].b[2] = USATB(cpu_state.MM[cpu_reg].b[2] + src.b[2]); - cpu_state.MM[cpu_reg].b[3] = USATB(cpu_state.MM[cpu_reg].b[3] + src.b[3]); - cpu_state.MM[cpu_reg].b[4] = USATB(cpu_state.MM[cpu_reg].b[4] + src.b[4]); - cpu_state.MM[cpu_reg].b[5] = USATB(cpu_state.MM[cpu_reg].b[5] + src.b[5]); - cpu_state.MM[cpu_reg].b[6] = USATB(cpu_state.MM[cpu_reg].b[6] + src.b[6]); - cpu_state.MM[cpu_reg].b[7] = USATB(cpu_state.MM[cpu_reg].b[7] + src.b[7]); + dst->b[0] = USATB(dst->b[0] + src.b[0]); + dst->b[1] = USATB(dst->b[1] + src.b[1]); + dst->b[2] = USATB(dst->b[2] + src.b[2]); + dst->b[3] = USATB(dst->b[3] + src.b[3]); + dst->b[4] = USATB(dst->b[4] + src.b[4]); + dst->b[5] = USATB(dst->b[5] + src.b[5]); + dst->b[6] = USATB(dst->b[6] + src.b[6]); + dst->b[7] = USATB(dst->b[7] + src.b[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -187,15 +247,21 @@ static int opPADDSW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sw[0] = SSATW(cpu_state.MM[cpu_reg].sw[0] + src.sw[0]); - cpu_state.MM[cpu_reg].sw[1] = SSATW(cpu_state.MM[cpu_reg].sw[1] + src.sw[1]); - cpu_state.MM[cpu_reg].sw[2] = SSATW(cpu_state.MM[cpu_reg].sw[2] + src.sw[2]); - cpu_state.MM[cpu_reg].sw[3] = SSATW(cpu_state.MM[cpu_reg].sw[3] + src.sw[3]); + dst->sw[0] = SSATW(dst->sw[0] + src.sw[0]); + dst->sw[1] = SSATW(dst->sw[1] + src.sw[1]); + dst->sw[2] = SSATW(dst->sw[2] + src.sw[2]); + dst->sw[3] = SSATW(dst->sw[3] + src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -203,15 +269,21 @@ static int opPADDSW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sw[0] = SSATW(cpu_state.MM[cpu_reg].sw[0] + src.sw[0]); - cpu_state.MM[cpu_reg].sw[1] = SSATW(cpu_state.MM[cpu_reg].sw[1] + src.sw[1]); - cpu_state.MM[cpu_reg].sw[2] = SSATW(cpu_state.MM[cpu_reg].sw[2] + src.sw[2]); - cpu_state.MM[cpu_reg].sw[3] = SSATW(cpu_state.MM[cpu_reg].sw[3] + src.sw[3]); + dst->sw[0] = SSATW(dst->sw[0] + src.sw[0]); + dst->sw[1] = SSATW(dst->sw[1] + src.sw[1]); + dst->sw[2] = SSATW(dst->sw[2] + src.sw[2]); + dst->sw[3] = SSATW(dst->sw[3] + src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -220,15 +292,21 @@ static int opPADDUSW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = USATW(cpu_state.MM[cpu_reg].w[0] + src.w[0]); - cpu_state.MM[cpu_reg].w[1] = USATW(cpu_state.MM[cpu_reg].w[1] + src.w[1]); - cpu_state.MM[cpu_reg].w[2] = USATW(cpu_state.MM[cpu_reg].w[2] + src.w[2]); - cpu_state.MM[cpu_reg].w[3] = USATW(cpu_state.MM[cpu_reg].w[3] + src.w[3]); + dst->w[0] = USATW(dst->w[0] + src.w[0]); + dst->w[1] = USATW(dst->w[1] + src.w[1]); + dst->w[2] = USATW(dst->w[2] + src.w[2]); + dst->w[3] = USATW(dst->w[3] + src.w[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -236,15 +314,21 @@ static int opPADDUSW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = USATW(cpu_state.MM[cpu_reg].w[0] + src.w[0]); - cpu_state.MM[cpu_reg].w[1] = USATW(cpu_state.MM[cpu_reg].w[1] + src.w[1]); - cpu_state.MM[cpu_reg].w[2] = USATW(cpu_state.MM[cpu_reg].w[2] + src.w[2]); - cpu_state.MM[cpu_reg].w[3] = USATW(cpu_state.MM[cpu_reg].w[3] + src.w[3]); + dst->w[0] = USATW(dst->w[0] + src.w[0]); + dst->w[1] = USATW(dst->w[1] + src.w[1]); + dst->w[2] = USATW(dst->w[2] + src.w[2]); + dst->w[3] = USATW(dst->w[3] + src.w[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -253,20 +337,26 @@ static int opPMADDWD_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - if (cpu_state.MM[cpu_reg].l[0] == 0x80008000 && src.l[0] == 0x80008000) - cpu_state.MM[cpu_reg].l[0] = 0x80000000; + if (dst->l[0] == 0x80008000 && src.l[0] == 0x80008000) + dst->l[0] = 0x80000000; else - cpu_state.MM[cpu_reg].sl[0] = ((int32_t) cpu_state.MM[cpu_reg].sw[0] * (int32_t) src.sw[0]) + ((int32_t) cpu_state.MM[cpu_reg].sw[1] * (int32_t) src.sw[1]); + dst->sl[0] = ((int32_t) dst->sw[0] * (int32_t) src.sw[0]) + ((int32_t) dst->sw[1] * (int32_t) src.sw[1]); - if (cpu_state.MM[cpu_reg].l[1] == 0x80008000 && src.l[1] == 0x80008000) - cpu_state.MM[cpu_reg].l[1] = 0x80000000; + if (dst->l[1] == 0x80008000 && src.l[1] == 0x80008000) + dst->l[1] = 0x80000000; else - cpu_state.MM[cpu_reg].sl[1] = ((int32_t) cpu_state.MM[cpu_reg].sw[2] * (int32_t) src.sw[2]) + ((int32_t) cpu_state.MM[cpu_reg].sw[3] * (int32_t) src.sw[3]); + dst->sl[1] = ((int32_t) dst->sw[2] * (int32_t) src.sw[2]) + ((int32_t) dst->sw[3] * (int32_t) src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -274,20 +364,26 @@ static int opPMADDWD_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - if (cpu_state.MM[cpu_reg].l[0] == 0x80008000 && src.l[0] == 0x80008000) - cpu_state.MM[cpu_reg].l[0] = 0x80000000; + if (dst->l[0] == 0x80008000 && src.l[0] == 0x80008000) + dst->l[0] = 0x80000000; else - cpu_state.MM[cpu_reg].sl[0] = ((int32_t) cpu_state.MM[cpu_reg].sw[0] * (int32_t) src.sw[0]) + ((int32_t) cpu_state.MM[cpu_reg].sw[1] * (int32_t) src.sw[1]); + dst->sl[0] = ((int32_t) dst->sw[0] * (int32_t) src.sw[0]) + ((int32_t) dst->sw[1] * (int32_t) src.sw[1]); - if (cpu_state.MM[cpu_reg].l[1] == 0x80008000 && src.l[1] == 0x80008000) - cpu_state.MM[cpu_reg].l[1] = 0x80000000; + if (dst->l[1] == 0x80008000 && src.l[1] == 0x80008000) + dst->l[1] = 0x80000000; else - cpu_state.MM[cpu_reg].sl[1] = ((int32_t) cpu_state.MM[cpu_reg].sw[2] * (int32_t) src.sw[2]) + ((int32_t) cpu_state.MM[cpu_reg].sw[3] * (int32_t) src.sw[3]); + dst->sl[1] = ((int32_t) dst->sw[2] * (int32_t) src.sw[2]) + ((int32_t) dst->sw[3] * (int32_t) src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -295,114 +391,126 @@ opPMADDWD_a32(uint32_t fetchdat) static int opPMULLW_a16(uint32_t fetchdat) { + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); - if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].w[0] *= cpu_state.MM[cpu_rm].w[0]; - cpu_state.MM[cpu_reg].w[1] *= cpu_state.MM[cpu_rm].w[1]; - cpu_state.MM[cpu_reg].w[2] *= cpu_state.MM[cpu_rm].w[2]; - cpu_state.MM[cpu_reg].w[3] *= cpu_state.MM[cpu_rm].w[3]; - CLOCK_CYCLES(1); - } else { - MMX_REG src; + dst = MMX_GETREGP(cpu_reg); + + if (cpu_mod == 3) + src = MMX_GETREG(cpu_rm); + else { SEG_CHECK_READ(cpu_state.ea_seg); src.l[0] = readmeml(easeg, cpu_state.eaaddr); src.l[1] = readmeml(easeg, cpu_state.eaaddr + 4); if (cpu_state.abrt) return 0; - cpu_state.MM[cpu_reg].w[0] *= src.w[0]; - cpu_state.MM[cpu_reg].w[1] *= src.w[1]; - cpu_state.MM[cpu_reg].w[2] *= src.w[2]; - cpu_state.MM[cpu_reg].w[3] *= src.w[3]; - CLOCK_CYCLES(2); + CLOCK_CYCLES(1); } + dst->w[0] *= src.w[0]; + dst->w[1] *= src.w[1]; + dst->w[2] *= src.w[2]; + dst->w[3] *= src.w[3]; + CLOCK_CYCLES(1); + + MMX_SETEXP(cpu_reg); + return 0; } static int opPMULLW_a32(uint32_t fetchdat) { + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); - if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].w[0] *= cpu_state.MM[cpu_rm].w[0]; - cpu_state.MM[cpu_reg].w[1] *= cpu_state.MM[cpu_rm].w[1]; - cpu_state.MM[cpu_reg].w[2] *= cpu_state.MM[cpu_rm].w[2]; - cpu_state.MM[cpu_reg].w[3] *= cpu_state.MM[cpu_rm].w[3]; - CLOCK_CYCLES(1); - } else { - MMX_REG src; + dst = MMX_GETREGP(cpu_reg); + + if (cpu_mod == 3) + src = MMX_GETREG(cpu_rm); + else { SEG_CHECK_READ(cpu_state.ea_seg); src.l[0] = readmeml(easeg, cpu_state.eaaddr); src.l[1] = readmeml(easeg, cpu_state.eaaddr + 4); if (cpu_state.abrt) return 0; - cpu_state.MM[cpu_reg].w[0] *= src.w[0]; - cpu_state.MM[cpu_reg].w[1] *= src.w[1]; - cpu_state.MM[cpu_reg].w[2] *= src.w[2]; - cpu_state.MM[cpu_reg].w[3] *= src.w[3]; - CLOCK_CYCLES(2); + CLOCK_CYCLES(1); } + dst->w[0] *= src.w[0]; + dst->w[1] *= src.w[1]; + dst->w[2] *= src.w[2]; + dst->w[3] *= src.w[3]; + CLOCK_CYCLES(1); + + MMX_SETEXP(cpu_reg); + return 0; } static int opPMULHW_a16(uint32_t fetchdat) { + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); - if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].w[0] = ((int32_t) cpu_state.MM[cpu_reg].sw[0] * (int32_t) cpu_state.MM[cpu_rm].sw[0]) >> 16; - cpu_state.MM[cpu_reg].w[1] = ((int32_t) cpu_state.MM[cpu_reg].sw[1] * (int32_t) cpu_state.MM[cpu_rm].sw[1]) >> 16; - cpu_state.MM[cpu_reg].w[2] = ((int32_t) cpu_state.MM[cpu_reg].sw[2] * (int32_t) cpu_state.MM[cpu_rm].sw[2]) >> 16; - cpu_state.MM[cpu_reg].w[3] = ((int32_t) cpu_state.MM[cpu_reg].sw[3] * (int32_t) cpu_state.MM[cpu_rm].sw[3]) >> 16; - CLOCK_CYCLES(1); - } else { - MMX_REG src; + dst = MMX_GETREGP(cpu_reg); + + if (cpu_mod == 3) + src = MMX_GETREG(cpu_rm); + else { SEG_CHECK_READ(cpu_state.ea_seg); src.l[0] = readmeml(easeg, cpu_state.eaaddr); src.l[1] = readmeml(easeg, cpu_state.eaaddr + 4); if (cpu_state.abrt) return 0; - cpu_state.MM[cpu_reg].w[0] = ((int32_t) cpu_state.MM[cpu_reg].sw[0] * (int32_t) src.sw[0]) >> 16; - cpu_state.MM[cpu_reg].w[1] = ((int32_t) cpu_state.MM[cpu_reg].sw[1] * (int32_t) src.sw[1]) >> 16; - cpu_state.MM[cpu_reg].w[2] = ((int32_t) cpu_state.MM[cpu_reg].sw[2] * (int32_t) src.sw[2]) >> 16; - cpu_state.MM[cpu_reg].w[3] = ((int32_t) cpu_state.MM[cpu_reg].sw[3] * (int32_t) src.sw[3]) >> 16; - CLOCK_CYCLES(2); + CLOCK_CYCLES(1); } + dst->w[0] = ((int32_t) dst->sw[0] * (int32_t) src.sw[0]) >> 16; + dst->w[1] = ((int32_t) dst->sw[1] * (int32_t) src.sw[1]) >> 16; + dst->w[2] = ((int32_t) dst->sw[2] * (int32_t) src.sw[2]) >> 16; + dst->w[3] = ((int32_t) dst->sw[3] * (int32_t) src.sw[3]) >> 16; + CLOCK_CYCLES(1); + + MMX_SETEXP(cpu_reg); + return 0; } static int opPMULHW_a32(uint32_t fetchdat) { + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); - if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].w[0] = ((int32_t) cpu_state.MM[cpu_reg].sw[0] * (int32_t) cpu_state.MM[cpu_rm].sw[0]) >> 16; - cpu_state.MM[cpu_reg].w[1] = ((int32_t) cpu_state.MM[cpu_reg].sw[1] * (int32_t) cpu_state.MM[cpu_rm].sw[1]) >> 16; - cpu_state.MM[cpu_reg].w[2] = ((int32_t) cpu_state.MM[cpu_reg].sw[2] * (int32_t) cpu_state.MM[cpu_rm].sw[2]) >> 16; - cpu_state.MM[cpu_reg].w[3] = ((int32_t) cpu_state.MM[cpu_reg].sw[3] * (int32_t) cpu_state.MM[cpu_rm].sw[3]) >> 16; - CLOCK_CYCLES(1); - } else { - MMX_REG src; + dst = MMX_GETREGP(cpu_reg); + + if (cpu_mod == 3) + src = MMX_GETREG(cpu_rm); + else { SEG_CHECK_READ(cpu_state.ea_seg); src.l[0] = readmeml(easeg, cpu_state.eaaddr); src.l[1] = readmeml(easeg, cpu_state.eaaddr + 4); if (cpu_state.abrt) return 0; - cpu_state.MM[cpu_reg].w[0] = ((int32_t) cpu_state.MM[cpu_reg].sw[0] * (int32_t) src.sw[0]) >> 16; - cpu_state.MM[cpu_reg].w[1] = ((int32_t) cpu_state.MM[cpu_reg].sw[1] * (int32_t) src.sw[1]) >> 16; - cpu_state.MM[cpu_reg].w[2] = ((int32_t) cpu_state.MM[cpu_reg].sw[2] * (int32_t) src.sw[2]) >> 16; - cpu_state.MM[cpu_reg].w[3] = ((int32_t) cpu_state.MM[cpu_reg].sw[3] * (int32_t) src.sw[3]) >> 16; - CLOCK_CYCLES(2); + CLOCK_CYCLES(1); } + dst->w[0] = ((int32_t) dst->sw[0] * (int32_t) src.sw[0]) >> 16; + dst->w[1] = ((int32_t) dst->sw[1] * (int32_t) src.sw[1]) >> 16; + dst->w[2] = ((int32_t) dst->sw[2] * (int32_t) src.sw[2]) >> 16; + dst->w[3] = ((int32_t) dst->sw[3] * (int32_t) src.sw[3]) >> 16; + CLOCK_CYCLES(1); + + MMX_SETEXP(cpu_reg); + return 0; } @@ -410,19 +518,25 @@ static int opPSUBB_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] -= src.b[0]; - cpu_state.MM[cpu_reg].b[1] -= src.b[1]; - cpu_state.MM[cpu_reg].b[2] -= src.b[2]; - cpu_state.MM[cpu_reg].b[3] -= src.b[3]; - cpu_state.MM[cpu_reg].b[4] -= src.b[4]; - cpu_state.MM[cpu_reg].b[5] -= src.b[5]; - cpu_state.MM[cpu_reg].b[6] -= src.b[6]; - cpu_state.MM[cpu_reg].b[7] -= src.b[7]; + dst->b[0] -= src.b[0]; + dst->b[1] -= src.b[1]; + dst->b[2] -= src.b[2]; + dst->b[3] -= src.b[3]; + dst->b[4] -= src.b[4]; + dst->b[5] -= src.b[5]; + dst->b[6] -= src.b[6]; + dst->b[7] -= src.b[7]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -430,19 +544,25 @@ static int opPSUBB_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] -= src.b[0]; - cpu_state.MM[cpu_reg].b[1] -= src.b[1]; - cpu_state.MM[cpu_reg].b[2] -= src.b[2]; - cpu_state.MM[cpu_reg].b[3] -= src.b[3]; - cpu_state.MM[cpu_reg].b[4] -= src.b[4]; - cpu_state.MM[cpu_reg].b[5] -= src.b[5]; - cpu_state.MM[cpu_reg].b[6] -= src.b[6]; - cpu_state.MM[cpu_reg].b[7] -= src.b[7]; + dst->b[0] -= src.b[0]; + dst->b[1] -= src.b[1]; + dst->b[2] -= src.b[2]; + dst->b[3] -= src.b[3]; + dst->b[4] -= src.b[4]; + dst->b[5] -= src.b[5]; + dst->b[6] -= src.b[6]; + dst->b[7] -= src.b[7]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -451,15 +571,21 @@ static int opPSUBW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] -= src.w[0]; - cpu_state.MM[cpu_reg].w[1] -= src.w[1]; - cpu_state.MM[cpu_reg].w[2] -= src.w[2]; - cpu_state.MM[cpu_reg].w[3] -= src.w[3]; + dst->w[0] -= src.w[0]; + dst->w[1] -= src.w[1]; + dst->w[2] -= src.w[2]; + dst->w[3] -= src.w[3]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -467,15 +593,21 @@ static int opPSUBW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] -= src.w[0]; - cpu_state.MM[cpu_reg].w[1] -= src.w[1]; - cpu_state.MM[cpu_reg].w[2] -= src.w[2]; - cpu_state.MM[cpu_reg].w[3] -= src.w[3]; + dst->w[0] -= src.w[0]; + dst->w[1] -= src.w[1]; + dst->w[2] -= src.w[2]; + dst->w[3] -= src.w[3]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -484,13 +616,19 @@ static int opPSUBD_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] -= src.l[0]; - cpu_state.MM[cpu_reg].l[1] -= src.l[1]; + dst->l[0] -= src.l[0]; + dst->l[1] -= src.l[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -498,13 +636,19 @@ static int opPSUBD_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] -= src.l[0]; - cpu_state.MM[cpu_reg].l[1] -= src.l[1]; + dst->l[0] -= src.l[0]; + dst->l[1] -= src.l[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -513,20 +657,25 @@ static int opPSUBSB_a16(uint32_t fetchdat) { MMX_REG src; - pclog("opPSUBSB_a16(%08X)\n", fetchdat); + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sb[0] = SSATB(cpu_state.MM[cpu_reg].sb[0] - src.sb[0]); - cpu_state.MM[cpu_reg].sb[1] = SSATB(cpu_state.MM[cpu_reg].sb[1] - src.sb[1]); - cpu_state.MM[cpu_reg].sb[2] = SSATB(cpu_state.MM[cpu_reg].sb[2] - src.sb[2]); - cpu_state.MM[cpu_reg].sb[3] = SSATB(cpu_state.MM[cpu_reg].sb[3] - src.sb[3]); - cpu_state.MM[cpu_reg].sb[4] = SSATB(cpu_state.MM[cpu_reg].sb[4] - src.sb[4]); - cpu_state.MM[cpu_reg].sb[5] = SSATB(cpu_state.MM[cpu_reg].sb[5] - src.sb[5]); - cpu_state.MM[cpu_reg].sb[6] = SSATB(cpu_state.MM[cpu_reg].sb[6] - src.sb[6]); - cpu_state.MM[cpu_reg].sb[7] = SSATB(cpu_state.MM[cpu_reg].sb[7] - src.sb[7]); + dst->sb[0] = SSATB(dst->sb[0] - src.sb[0]); + dst->sb[1] = SSATB(dst->sb[1] - src.sb[1]); + dst->sb[2] = SSATB(dst->sb[2] - src.sb[2]); + dst->sb[3] = SSATB(dst->sb[3] - src.sb[3]); + dst->sb[4] = SSATB(dst->sb[4] - src.sb[4]); + dst->sb[5] = SSATB(dst->sb[5] - src.sb[5]); + dst->sb[6] = SSATB(dst->sb[6] - src.sb[6]); + dst->sb[7] = SSATB(dst->sb[7] - src.sb[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -534,20 +683,25 @@ static int opPSUBSB_a32(uint32_t fetchdat) { MMX_REG src; - pclog("opPSUBSB_a32(%08X)\n", fetchdat); + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sb[0] = SSATB(cpu_state.MM[cpu_reg].sb[0] - src.sb[0]); - cpu_state.MM[cpu_reg].sb[1] = SSATB(cpu_state.MM[cpu_reg].sb[1] - src.sb[1]); - cpu_state.MM[cpu_reg].sb[2] = SSATB(cpu_state.MM[cpu_reg].sb[2] - src.sb[2]); - cpu_state.MM[cpu_reg].sb[3] = SSATB(cpu_state.MM[cpu_reg].sb[3] - src.sb[3]); - cpu_state.MM[cpu_reg].sb[4] = SSATB(cpu_state.MM[cpu_reg].sb[4] - src.sb[4]); - cpu_state.MM[cpu_reg].sb[5] = SSATB(cpu_state.MM[cpu_reg].sb[5] - src.sb[5]); - cpu_state.MM[cpu_reg].sb[6] = SSATB(cpu_state.MM[cpu_reg].sb[6] - src.sb[6]); - cpu_state.MM[cpu_reg].sb[7] = SSATB(cpu_state.MM[cpu_reg].sb[7] - src.sb[7]); + dst->sb[0] = SSATB(dst->sb[0] - src.sb[0]); + dst->sb[1] = SSATB(dst->sb[1] - src.sb[1]); + dst->sb[2] = SSATB(dst->sb[2] - src.sb[2]); + dst->sb[3] = SSATB(dst->sb[3] - src.sb[3]); + dst->sb[4] = SSATB(dst->sb[4] - src.sb[4]); + dst->sb[5] = SSATB(dst->sb[5] - src.sb[5]); + dst->sb[6] = SSATB(dst->sb[6] - src.sb[6]); + dst->sb[7] = SSATB(dst->sb[7] - src.sb[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -556,19 +710,25 @@ static int opPSUBUSB_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = USATB(cpu_state.MM[cpu_reg].b[0] - src.b[0]); - cpu_state.MM[cpu_reg].b[1] = USATB(cpu_state.MM[cpu_reg].b[1] - src.b[1]); - cpu_state.MM[cpu_reg].b[2] = USATB(cpu_state.MM[cpu_reg].b[2] - src.b[2]); - cpu_state.MM[cpu_reg].b[3] = USATB(cpu_state.MM[cpu_reg].b[3] - src.b[3]); - cpu_state.MM[cpu_reg].b[4] = USATB(cpu_state.MM[cpu_reg].b[4] - src.b[4]); - cpu_state.MM[cpu_reg].b[5] = USATB(cpu_state.MM[cpu_reg].b[5] - src.b[5]); - cpu_state.MM[cpu_reg].b[6] = USATB(cpu_state.MM[cpu_reg].b[6] - src.b[6]); - cpu_state.MM[cpu_reg].b[7] = USATB(cpu_state.MM[cpu_reg].b[7] - src.b[7]); + dst->b[0] = USATB(dst->b[0] - src.b[0]); + dst->b[1] = USATB(dst->b[1] - src.b[1]); + dst->b[2] = USATB(dst->b[2] - src.b[2]); + dst->b[3] = USATB(dst->b[3] - src.b[3]); + dst->b[4] = USATB(dst->b[4] - src.b[4]); + dst->b[5] = USATB(dst->b[5] - src.b[5]); + dst->b[6] = USATB(dst->b[6] - src.b[6]); + dst->b[7] = USATB(dst->b[7] - src.b[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -576,19 +736,25 @@ static int opPSUBUSB_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = USATB(cpu_state.MM[cpu_reg].b[0] - src.b[0]); - cpu_state.MM[cpu_reg].b[1] = USATB(cpu_state.MM[cpu_reg].b[1] - src.b[1]); - cpu_state.MM[cpu_reg].b[2] = USATB(cpu_state.MM[cpu_reg].b[2] - src.b[2]); - cpu_state.MM[cpu_reg].b[3] = USATB(cpu_state.MM[cpu_reg].b[3] - src.b[3]); - cpu_state.MM[cpu_reg].b[4] = USATB(cpu_state.MM[cpu_reg].b[4] - src.b[4]); - cpu_state.MM[cpu_reg].b[5] = USATB(cpu_state.MM[cpu_reg].b[5] - src.b[5]); - cpu_state.MM[cpu_reg].b[6] = USATB(cpu_state.MM[cpu_reg].b[6] - src.b[6]); - cpu_state.MM[cpu_reg].b[7] = USATB(cpu_state.MM[cpu_reg].b[7] - src.b[7]); + dst->b[0] = USATB(dst->b[0] - src.b[0]); + dst->b[1] = USATB(dst->b[1] - src.b[1]); + dst->b[2] = USATB(dst->b[2] - src.b[2]); + dst->b[3] = USATB(dst->b[3] - src.b[3]); + dst->b[4] = USATB(dst->b[4] - src.b[4]); + dst->b[5] = USATB(dst->b[5] - src.b[5]); + dst->b[6] = USATB(dst->b[6] - src.b[6]); + dst->b[7] = USATB(dst->b[7] - src.b[7]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -597,15 +763,21 @@ static int opPSUBSW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sw[0] = SSATW(cpu_state.MM[cpu_reg].sw[0] - src.sw[0]); - cpu_state.MM[cpu_reg].sw[1] = SSATW(cpu_state.MM[cpu_reg].sw[1] - src.sw[1]); - cpu_state.MM[cpu_reg].sw[2] = SSATW(cpu_state.MM[cpu_reg].sw[2] - src.sw[2]); - cpu_state.MM[cpu_reg].sw[3] = SSATW(cpu_state.MM[cpu_reg].sw[3] - src.sw[3]); + dst->sw[0] = SSATW(dst->sw[0] - src.sw[0]); + dst->sw[1] = SSATW(dst->sw[1] - src.sw[1]); + dst->sw[2] = SSATW(dst->sw[2] - src.sw[2]); + dst->sw[3] = SSATW(dst->sw[3] - src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -613,15 +785,21 @@ static int opPSUBSW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].sw[0] = SSATW(cpu_state.MM[cpu_reg].sw[0] - src.sw[0]); - cpu_state.MM[cpu_reg].sw[1] = SSATW(cpu_state.MM[cpu_reg].sw[1] - src.sw[1]); - cpu_state.MM[cpu_reg].sw[2] = SSATW(cpu_state.MM[cpu_reg].sw[2] - src.sw[2]); - cpu_state.MM[cpu_reg].sw[3] = SSATW(cpu_state.MM[cpu_reg].sw[3] - src.sw[3]); + dst->sw[0] = SSATW(dst->sw[0] - src.sw[0]); + dst->sw[1] = SSATW(dst->sw[1] - src.sw[1]); + dst->sw[2] = SSATW(dst->sw[2] - src.sw[2]); + dst->sw[3] = SSATW(dst->sw[3] - src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -630,15 +808,21 @@ static int opPSUBUSW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = USATW(cpu_state.MM[cpu_reg].w[0] - src.w[0]); - cpu_state.MM[cpu_reg].w[1] = USATW(cpu_state.MM[cpu_reg].w[1] - src.w[1]); - cpu_state.MM[cpu_reg].w[2] = USATW(cpu_state.MM[cpu_reg].w[2] - src.w[2]); - cpu_state.MM[cpu_reg].w[3] = USATW(cpu_state.MM[cpu_reg].w[3] - src.w[3]); + dst->w[0] = USATW(dst->w[0] - src.w[0]); + dst->w[1] = USATW(dst->w[1] - src.w[1]); + dst->w[2] = USATW(dst->w[2] - src.w[2]); + dst->w[3] = USATW(dst->w[3] - src.w[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -646,15 +830,21 @@ static int opPSUBUSW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = USATW(cpu_state.MM[cpu_reg].w[0] - src.w[0]); - cpu_state.MM[cpu_reg].w[1] = USATW(cpu_state.MM[cpu_reg].w[1] - src.w[1]); - cpu_state.MM[cpu_reg].w[2] = USATW(cpu_state.MM[cpu_reg].w[2] - src.w[2]); - cpu_state.MM[cpu_reg].w[3] = USATW(cpu_state.MM[cpu_reg].w[3] - src.w[3]); + dst->w[0] = USATW(dst->w[0] - src.w[0]); + dst->w[1] = USATW(dst->w[1] - src.w[1]); + dst->w[2] = USATW(dst->w[2] - src.w[2]); + dst->w[3] = USATW(dst->w[3] - src.w[3]); + + MMX_SETEXP(cpu_reg); return 0; } diff --git a/src/cpu/x86_ops_mmx_cmp.h b/src/cpu/x86_ops_mmx_cmp.h index 40ae66a9c..b3081b8e8 100644 --- a/src/cpu/x86_ops_mmx_cmp.h +++ b/src/cpu/x86_ops_mmx_cmp.h @@ -2,20 +2,25 @@ static int opPCMPEQB_a16(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = (cpu_state.MM[cpu_reg].b[0] == src.b[0]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[1] = (cpu_state.MM[cpu_reg].b[1] == src.b[1]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[2] = (cpu_state.MM[cpu_reg].b[2] == src.b[2]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[3] = (cpu_state.MM[cpu_reg].b[3] == src.b[3]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[4] = (cpu_state.MM[cpu_reg].b[4] == src.b[4]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[5] = (cpu_state.MM[cpu_reg].b[5] == src.b[5]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[6] = (cpu_state.MM[cpu_reg].b[6] == src.b[6]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[7] = (cpu_state.MM[cpu_reg].b[7] == src.b[7]) ? 0xff : 0; + dst->b[0] = (dst->b[0] == src.b[0]) ? 0xff : 0; + dst->b[1] = (dst->b[1] == src.b[1]) ? 0xff : 0; + dst->b[2] = (dst->b[2] == src.b[2]) ? 0xff : 0; + dst->b[3] = (dst->b[3] == src.b[3]) ? 0xff : 0; + dst->b[4] = (dst->b[4] == src.b[4]) ? 0xff : 0; + dst->b[5] = (dst->b[5] == src.b[5]) ? 0xff : 0; + dst->b[6] = (dst->b[6] == src.b[6]) ? 0xff : 0; + dst->b[7] = (dst->b[7] == src.b[7]) ? 0xff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -23,20 +28,25 @@ static int opPCMPEQB_a32(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = (cpu_state.MM[cpu_reg].b[0] == src.b[0]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[1] = (cpu_state.MM[cpu_reg].b[1] == src.b[1]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[2] = (cpu_state.MM[cpu_reg].b[2] == src.b[2]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[3] = (cpu_state.MM[cpu_reg].b[3] == src.b[3]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[4] = (cpu_state.MM[cpu_reg].b[4] == src.b[4]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[5] = (cpu_state.MM[cpu_reg].b[5] == src.b[5]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[6] = (cpu_state.MM[cpu_reg].b[6] == src.b[6]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[7] = (cpu_state.MM[cpu_reg].b[7] == src.b[7]) ? 0xff : 0; + dst->b[0] = (dst->b[0] == src.b[0]) ? 0xff : 0; + dst->b[1] = (dst->b[1] == src.b[1]) ? 0xff : 0; + dst->b[2] = (dst->b[2] == src.b[2]) ? 0xff : 0; + dst->b[3] = (dst->b[3] == src.b[3]) ? 0xff : 0; + dst->b[4] = (dst->b[4] == src.b[4]) ? 0xff : 0; + dst->b[5] = (dst->b[5] == src.b[5]) ? 0xff : 0; + dst->b[6] = (dst->b[6] == src.b[6]) ? 0xff : 0; + dst->b[7] = (dst->b[7] == src.b[7]) ? 0xff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -45,20 +55,25 @@ static int opPCMPGTB_a16(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = (cpu_state.MM[cpu_reg].sb[0] > src.sb[0]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[1] = (cpu_state.MM[cpu_reg].sb[1] > src.sb[1]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[2] = (cpu_state.MM[cpu_reg].sb[2] > src.sb[2]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[3] = (cpu_state.MM[cpu_reg].sb[3] > src.sb[3]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[4] = (cpu_state.MM[cpu_reg].sb[4] > src.sb[4]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[5] = (cpu_state.MM[cpu_reg].sb[5] > src.sb[5]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[6] = (cpu_state.MM[cpu_reg].sb[6] > src.sb[6]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[7] = (cpu_state.MM[cpu_reg].sb[7] > src.sb[7]) ? 0xff : 0; + dst->b[0] = (dst->sb[0] > src.sb[0]) ? 0xff : 0; + dst->b[1] = (dst->sb[1] > src.sb[1]) ? 0xff : 0; + dst->b[2] = (dst->sb[2] > src.sb[2]) ? 0xff : 0; + dst->b[3] = (dst->sb[3] > src.sb[3]) ? 0xff : 0; + dst->b[4] = (dst->sb[4] > src.sb[4]) ? 0xff : 0; + dst->b[5] = (dst->sb[5] > src.sb[5]) ? 0xff : 0; + dst->b[6] = (dst->sb[6] > src.sb[6]) ? 0xff : 0; + dst->b[7] = (dst->sb[7] > src.sb[7]) ? 0xff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -66,20 +81,25 @@ static int opPCMPGTB_a32(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = (cpu_state.MM[cpu_reg].sb[0] > src.sb[0]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[1] = (cpu_state.MM[cpu_reg].sb[1] > src.sb[1]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[2] = (cpu_state.MM[cpu_reg].sb[2] > src.sb[2]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[3] = (cpu_state.MM[cpu_reg].sb[3] > src.sb[3]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[4] = (cpu_state.MM[cpu_reg].sb[4] > src.sb[4]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[5] = (cpu_state.MM[cpu_reg].sb[5] > src.sb[5]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[6] = (cpu_state.MM[cpu_reg].sb[6] > src.sb[6]) ? 0xff : 0; - cpu_state.MM[cpu_reg].b[7] = (cpu_state.MM[cpu_reg].sb[7] > src.sb[7]) ? 0xff : 0; + dst->b[0] = (dst->sb[0] > src.sb[0]) ? 0xff : 0; + dst->b[1] = (dst->sb[1] > src.sb[1]) ? 0xff : 0; + dst->b[2] = (dst->sb[2] > src.sb[2]) ? 0xff : 0; + dst->b[3] = (dst->sb[3] > src.sb[3]) ? 0xff : 0; + dst->b[4] = (dst->sb[4] > src.sb[4]) ? 0xff : 0; + dst->b[5] = (dst->sb[5] > src.sb[5]) ? 0xff : 0; + dst->b[6] = (dst->sb[6] > src.sb[6]) ? 0xff : 0; + dst->b[7] = (dst->sb[7] > src.sb[7]) ? 0xff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -88,16 +108,21 @@ static int opPCMPEQW_a16(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = (cpu_state.MM[cpu_reg].w[0] == src.w[0]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[1] = (cpu_state.MM[cpu_reg].w[1] == src.w[1]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[2] = (cpu_state.MM[cpu_reg].w[2] == src.w[2]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[3] = (cpu_state.MM[cpu_reg].w[3] == src.w[3]) ? 0xffff : 0; + dst->w[0] = (dst->w[0] == src.w[0]) ? 0xffff : 0; + dst->w[1] = (dst->w[1] == src.w[1]) ? 0xffff : 0; + dst->w[2] = (dst->w[2] == src.w[2]) ? 0xffff : 0; + dst->w[3] = (dst->w[3] == src.w[3]) ? 0xffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -105,16 +130,21 @@ static int opPCMPEQW_a32(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = (cpu_state.MM[cpu_reg].w[0] == src.w[0]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[1] = (cpu_state.MM[cpu_reg].w[1] == src.w[1]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[2] = (cpu_state.MM[cpu_reg].w[2] == src.w[2]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[3] = (cpu_state.MM[cpu_reg].w[3] == src.w[3]) ? 0xffff : 0; + dst->w[0] = (dst->w[0] == src.w[0]) ? 0xffff : 0; + dst->w[1] = (dst->w[1] == src.w[1]) ? 0xffff : 0; + dst->w[2] = (dst->w[2] == src.w[2]) ? 0xffff : 0; + dst->w[3] = (dst->w[3] == src.w[3]) ? 0xffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -123,16 +153,21 @@ static int opPCMPGTW_a16(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = (cpu_state.MM[cpu_reg].sw[0] > src.sw[0]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[1] = (cpu_state.MM[cpu_reg].sw[1] > src.sw[1]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[2] = (cpu_state.MM[cpu_reg].sw[2] > src.sw[2]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[3] = (cpu_state.MM[cpu_reg].sw[3] > src.sw[3]) ? 0xffff : 0; + dst->w[0] = (dst->sw[0] > src.sw[0]) ? 0xffff : 0; + dst->w[1] = (dst->sw[1] > src.sw[1]) ? 0xffff : 0; + dst->w[2] = (dst->sw[2] > src.sw[2]) ? 0xffff : 0; + dst->w[3] = (dst->sw[3] > src.sw[3]) ? 0xffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -140,16 +175,21 @@ static int opPCMPGTW_a32(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = (cpu_state.MM[cpu_reg].sw[0] > src.sw[0]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[1] = (cpu_state.MM[cpu_reg].sw[1] > src.sw[1]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[2] = (cpu_state.MM[cpu_reg].sw[2] > src.sw[2]) ? 0xffff : 0; - cpu_state.MM[cpu_reg].w[3] = (cpu_state.MM[cpu_reg].sw[3] > src.sw[3]) ? 0xffff : 0; + dst->w[0] = (dst->sw[0] > src.sw[0]) ? 0xffff : 0; + dst->w[1] = (dst->sw[1] > src.sw[1]) ? 0xffff : 0; + dst->w[2] = (dst->sw[2] > src.sw[2]) ? 0xffff : 0; + dst->w[3] = (dst->sw[3] > src.sw[3]) ? 0xffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -158,14 +198,19 @@ static int opPCMPEQD_a16(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = (cpu_state.MM[cpu_reg].l[0] == src.l[0]) ? 0xffffffff : 0; - cpu_state.MM[cpu_reg].l[1] = (cpu_state.MM[cpu_reg].l[1] == src.l[1]) ? 0xffffffff : 0; + dst->l[0] = (dst->l[0] == src.l[0]) ? 0xffffffff : 0; + dst->l[1] = (dst->l[1] == src.l[1]) ? 0xffffffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -173,14 +218,19 @@ static int opPCMPEQD_a32(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = (cpu_state.MM[cpu_reg].l[0] == src.l[0]) ? 0xffffffff : 0; - cpu_state.MM[cpu_reg].l[1] = (cpu_state.MM[cpu_reg].l[1] == src.l[1]) ? 0xffffffff : 0; + dst->l[0] = (dst->l[0] == src.l[0]) ? 0xffffffff : 0; + dst->l[1] = (dst->l[1] == src.l[1]) ? 0xffffffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -189,14 +239,19 @@ static int opPCMPGTD_a16(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = (cpu_state.MM[cpu_reg].sl[0] > src.sl[0]) ? 0xffffffff : 0; - cpu_state.MM[cpu_reg].l[1] = (cpu_state.MM[cpu_reg].sl[1] > src.sl[1]) ? 0xffffffff : 0; + dst->l[0] = (dst->sl[0] > src.sl[0]) ? 0xffffffff : 0; + dst->l[1] = (dst->sl[1] > src.sl[1]) ? 0xffffffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } @@ -204,14 +259,19 @@ static int opPCMPGTD_a32(uint32_t fetchdat) { MMX_REG src; - + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = (cpu_state.MM[cpu_reg].sl[0] > src.sl[0]) ? 0xffffffff : 0; - cpu_state.MM[cpu_reg].l[1] = (cpu_state.MM[cpu_reg].sl[1] > src.sl[1]) ? 0xffffffff : 0; + dst->l[0] = (dst->sl[0] > src.sl[0]) ? 0xffffffff : 0; + dst->l[1] = (dst->sl[1] > src.sl[1]) ? 0xffffffff : 0; + + MMX_SETEXP(cpu_reg); return 0; } diff --git a/src/cpu/x86_ops_mmx_logic.h b/src/cpu/x86_ops_mmx_logic.h index c22c820c1..26d7c1693 100644 --- a/src/cpu/x86_ops_mmx_logic.h +++ b/src/cpu/x86_ops_mmx_logic.h @@ -2,24 +2,38 @@ static int opPAND_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q &= src.q; + dst->q &= src.q; + + MMX_SETEXP(cpu_reg); + return 0; } static int opPAND_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q &= src.q; + dst->q &= src.q; + + MMX_SETEXP(cpu_reg); + return 0; } @@ -27,24 +41,38 @@ static int opPANDN_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q = ~cpu_state.MM[cpu_reg].q & src.q; + dst->q = ~dst->q & src.q; + + MMX_SETEXP(cpu_reg); + return 0; } static int opPANDN_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q = ~cpu_state.MM[cpu_reg].q & src.q; + dst->q = ~dst->q & src.q; + + MMX_SETEXP(cpu_reg); + return 0; } @@ -52,24 +80,38 @@ static int opPOR_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q |= src.q; + dst->q |= src.q; + + MMX_SETEXP(cpu_reg); + return 0; } static int opPOR_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q |= src.q; + dst->q |= src.q; + + MMX_SETEXP(cpu_reg); + return 0; } @@ -77,23 +119,37 @@ static int opPXOR_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q ^= src.q; + dst->q ^= src.q; + + MMX_SETEXP(cpu_reg); + return 0; } static int opPXOR_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].q ^= src.q; + dst->q ^= src.q; + + MMX_SETEXP(cpu_reg); + return 0; } diff --git a/src/cpu/x86_ops_mmx_mov.h b/src/cpu/x86_ops_mmx_mov.h index bb51573e6..65bbb0c01 100644 --- a/src/cpu/x86_ops_mmx_mov.h +++ b/src/cpu/x86_ops_mmx_mov.h @@ -1,88 +1,112 @@ static int opMOVD_l_mm_a16(uint32_t fetchdat) { + uint32_t dst; + MMX_REG *op; MMX_ENTER(); fetch_ea_16(fetchdat); + + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].l[0] = cpu_state.regs[cpu_rm].l; - cpu_state.MM[cpu_reg].l[1] = 0; + op->l[0] = cpu_state.regs[cpu_rm].l; + op->l[1] = 0; CLOCK_CYCLES(1); } else { - uint32_t dst; - SEG_CHECK_READ(cpu_state.ea_seg); dst = readmeml(easeg, cpu_state.eaaddr); if (cpu_state.abrt) return 1; - cpu_state.MM[cpu_reg].l[0] = dst; - cpu_state.MM[cpu_reg].l[1] = 0; + op->l[0] = dst; + op->l[1] = 0; CLOCK_CYCLES(2); } + + MMX_SETEXP(cpu_reg); + return 0; } static int opMOVD_l_mm_a32(uint32_t fetchdat) { + uint32_t dst; + MMX_REG *op; MMX_ENTER(); fetch_ea_32(fetchdat); + + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].l[0] = cpu_state.regs[cpu_rm].l; - cpu_state.MM[cpu_reg].l[1] = 0; + op->l[0] = cpu_state.regs[cpu_rm].l; + op->l[1] = 0; CLOCK_CYCLES(1); } else { - uint32_t dst; - SEG_CHECK_READ(cpu_state.ea_seg); dst = readmeml(easeg, cpu_state.eaaddr); if (cpu_state.abrt) return 1; - cpu_state.MM[cpu_reg].l[0] = dst; - cpu_state.MM[cpu_reg].l[1] = 0; + op->l[0] = dst; + op->l[1] = 0; CLOCK_CYCLES(2); } + + MMX_SETEXP(cpu_reg); + return 0; } static int opMOVD_mm_l_a16(uint32_t fetchdat) { + MMX_REG *op; MMX_ENTER(); fetch_ea_16(fetchdat); + + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.regs[cpu_rm].l = cpu_state.MM[cpu_reg].l[0]; + cpu_state.regs[cpu_rm].l = op->l[0]; CLOCK_CYCLES(1); } else { SEG_CHECK_WRITE(cpu_state.ea_seg); CHECK_WRITE_COMMON(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); - writememl(easeg, cpu_state.eaaddr, cpu_state.MM[cpu_reg].l[0]); + writememl(easeg, cpu_state.eaaddr, op->l[0]); if (cpu_state.abrt) return 1; + CLOCK_CYCLES(2); } + return 0; } static int opMOVD_mm_l_a32(uint32_t fetchdat) { + MMX_REG *op; MMX_ENTER(); fetch_ea_32(fetchdat); + + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.regs[cpu_rm].l = cpu_state.MM[cpu_reg].l[0]; + cpu_state.regs[cpu_rm].l = op->l[0]; CLOCK_CYCLES(1); } else { SEG_CHECK_WRITE(cpu_state.ea_seg); CHECK_WRITE_COMMON(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); - writememl(easeg, cpu_state.eaaddr, cpu_state.MM[cpu_reg].l[0]); + writememl(easeg, cpu_state.eaaddr, op->l[0]); if (cpu_state.abrt) return 1; + CLOCK_CYCLES(2); } + return 0; } @@ -91,45 +115,59 @@ opMOVD_mm_l_a32(uint32_t fetchdat) static int opMOVD_mm_l_a16_cx(uint32_t fetchdat) { + MMX_REG *op; + if (in_smm) return opSMINT(fetchdat); MMX_ENTER(); fetch_ea_16(fetchdat); + + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.regs[cpu_rm].l = cpu_state.MM[cpu_reg].l[0]; + cpu_state.regs[cpu_rm].l = op->l[0]; CLOCK_CYCLES(1); } else { SEG_CHECK_WRITE(cpu_state.ea_seg); CHECK_WRITE_COMMON(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); - writememl(easeg, cpu_state.eaaddr, cpu_state.MM[cpu_reg].l[0]); + writememl(easeg, cpu_state.eaaddr, op->l[0]); if (cpu_state.abrt) return 1; + CLOCK_CYCLES(2); } + return 0; } static int opMOVD_mm_l_a32_cx(uint32_t fetchdat) { + MMX_REG *op; + if (in_smm) return opSMINT(fetchdat); MMX_ENTER(); fetch_ea_32(fetchdat); + + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.regs[cpu_rm].l = cpu_state.MM[cpu_reg].l[0]; + cpu_state.regs[cpu_rm].l = op->l[0]; CLOCK_CYCLES(1); } else { SEG_CHECK_WRITE(cpu_state.ea_seg); CHECK_WRITE_COMMON(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); - writememl(easeg, cpu_state.eaaddr, cpu_state.MM[cpu_reg].l[0]); + writememl(easeg, cpu_state.eaaddr, op->l[0]); if (cpu_state.abrt) return 1; + CLOCK_CYCLES(2); } + return 0; } #endif @@ -137,81 +175,121 @@ opMOVD_mm_l_a32_cx(uint32_t fetchdat) static int opMOVQ_q_mm_a16(uint32_t fetchdat) { + uint64_t dst; + MMX_REG src; + MMX_REG *op; MMX_ENTER(); fetch_ea_16(fetchdat); + + src = MMX_GETREG(cpu_rm); + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].q = cpu_state.MM[cpu_rm].q; + op->q = src.q; CLOCK_CYCLES(1); } else { - uint64_t dst; - SEG_CHECK_READ(cpu_state.ea_seg); dst = readmemq(easeg, cpu_state.eaaddr); if (cpu_state.abrt) return 1; - cpu_state.MM[cpu_reg].q = dst; + + op->q = dst; CLOCK_CYCLES(2); } + + MMX_SETEXP(cpu_reg); + return 0; } static int opMOVQ_q_mm_a32(uint32_t fetchdat) { + uint64_t dst; + MMX_REG src; + MMX_REG *op; MMX_ENTER(); fetch_ea_32(fetchdat); + + src = MMX_GETREG(cpu_rm); + op = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].q = cpu_state.MM[cpu_rm].q; + op->q = src.q; CLOCK_CYCLES(1); } else { - uint64_t dst; - SEG_CHECK_READ(cpu_state.ea_seg); dst = readmemq(easeg, cpu_state.eaaddr); if (cpu_state.abrt) return 1; - cpu_state.MM[cpu_reg].q = dst; + + op->q = dst; CLOCK_CYCLES(2); } + + MMX_SETEXP(cpu_reg); + return 0; } static int opMOVQ_mm_q_a16(uint32_t fetchdat) { + MMX_REG src; + MMX_REG *dst; + MMX_ENTER(); fetch_ea_16(fetchdat); + + src = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_rm); + if (cpu_mod == 3) { - cpu_state.MM[cpu_rm].q = cpu_state.MM[cpu_reg].q; + dst->q = src.q; CLOCK_CYCLES(1); + + MMX_SETEXP(cpu_rm); } else { SEG_CHECK_WRITE(cpu_state.ea_seg); CHECK_WRITE_COMMON(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 7); - writememq(easeg, cpu_state.eaaddr, cpu_state.MM[cpu_reg].q); + writememq(easeg, cpu_state.eaaddr, src.q); if (cpu_state.abrt) return 1; + CLOCK_CYCLES(2); } + return 0; } static int opMOVQ_mm_q_a32(uint32_t fetchdat) { + MMX_REG src; + MMX_REG *dst; + MMX_ENTER(); fetch_ea_32(fetchdat); + + src = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_rm); + if (cpu_mod == 3) { - cpu_state.MM[cpu_rm].q = cpu_state.MM[cpu_reg].q; + dst->q = src.q; CLOCK_CYCLES(1); + + MMX_SETEXP(cpu_rm); } else { SEG_CHECK_WRITE(cpu_state.ea_seg); CHECK_WRITE_COMMON(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 7); - writememq(easeg, cpu_state.eaaddr, cpu_state.MM[cpu_reg].q); + writememq(easeg, cpu_state.eaaddr, src.q); if (cpu_state.abrt) return 1; + CLOCK_CYCLES(2); } + return 0; } diff --git a/src/cpu/x86_ops_mmx_pack.h b/src/cpu/x86_ops_mmx_pack.h index f0180db91..90590638b 100644 --- a/src/cpu/x86_ops_mmx_pack.h +++ b/src/cpu/x86_ops_mmx_pack.h @@ -1,45 +1,61 @@ static int opPUNPCKLDQ_a16(uint32_t fetchdat) { + uint32_t usrc; + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + src = MMX_GETREG(cpu_rm); + dst = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].l[1] = cpu_state.MM[cpu_rm].l[0]; + dst->l[1] = src.l[0]; CLOCK_CYCLES(1); } else { - uint32_t src; - SEG_CHECK_READ(cpu_state.ea_seg); - src = readmeml(easeg, cpu_state.eaaddr); + usrc = readmeml(easeg, cpu_state.eaaddr); if (cpu_state.abrt) return 0; - cpu_state.MM[cpu_reg].l[1] = src; + dst->l[1] = usrc; CLOCK_CYCLES(2); } + + MMX_SETEXP(cpu_reg); + return 0; } static int opPUNPCKLDQ_a32(uint32_t fetchdat) { + uint32_t usrc; + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + src = MMX_GETREG(cpu_rm); + dst = MMX_GETREGP(cpu_reg); + if (cpu_mod == 3) { - cpu_state.MM[cpu_reg].l[1] = cpu_state.MM[cpu_rm].l[0]; + dst->l[1] = src.l[0]; CLOCK_CYCLES(1); } else { - uint32_t src; - SEG_CHECK_READ(cpu_state.ea_seg); - src = readmeml(easeg, cpu_state.eaaddr); + usrc = readmeml(easeg, cpu_state.eaaddr); if (cpu_state.abrt) return 0; - cpu_state.MM[cpu_reg].l[1] = src; + dst->l[1] = usrc; CLOCK_CYCLES(2); } + + MMX_SETEXP(cpu_reg); + return 0; } @@ -47,13 +63,19 @@ static int opPUNPCKHDQ_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = cpu_state.MM[cpu_reg].l[1]; - cpu_state.MM[cpu_reg].l[1] = src.l[1]; + dst->l[0] = dst->l[1]; + dst->l[1] = src.l[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -61,13 +83,19 @@ static int opPUNPCKHDQ_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].l[0] = cpu_state.MM[cpu_reg].l[1]; - cpu_state.MM[cpu_reg].l[1] = src.l[1]; + dst->l[0] = dst->l[1]; + dst->l[1] = src.l[1]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -76,19 +104,25 @@ static int opPUNPCKLBW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[7] = src.b[3]; - cpu_state.MM[cpu_reg].b[6] = cpu_state.MM[cpu_reg].b[3]; - cpu_state.MM[cpu_reg].b[5] = src.b[2]; - cpu_state.MM[cpu_reg].b[4] = cpu_state.MM[cpu_reg].b[2]; - cpu_state.MM[cpu_reg].b[3] = src.b[1]; - cpu_state.MM[cpu_reg].b[2] = cpu_state.MM[cpu_reg].b[1]; - cpu_state.MM[cpu_reg].b[1] = src.b[0]; - cpu_state.MM[cpu_reg].b[0] = cpu_state.MM[cpu_reg].b[0]; + dst->b[7] = src.b[3]; + dst->b[6] = dst->b[3]; + dst->b[5] = src.b[2]; + dst->b[4] = dst->b[2]; + dst->b[3] = src.b[1]; + dst->b[2] = dst->b[1]; + dst->b[1] = src.b[0]; + dst->b[0] = dst->b[0]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -96,19 +130,25 @@ static int opPUNPCKLBW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[7] = src.b[3]; - cpu_state.MM[cpu_reg].b[6] = cpu_state.MM[cpu_reg].b[3]; - cpu_state.MM[cpu_reg].b[5] = src.b[2]; - cpu_state.MM[cpu_reg].b[4] = cpu_state.MM[cpu_reg].b[2]; - cpu_state.MM[cpu_reg].b[3] = src.b[1]; - cpu_state.MM[cpu_reg].b[2] = cpu_state.MM[cpu_reg].b[1]; - cpu_state.MM[cpu_reg].b[1] = src.b[0]; - cpu_state.MM[cpu_reg].b[0] = cpu_state.MM[cpu_reg].b[0]; + dst->b[7] = src.b[3]; + dst->b[6] = dst->b[3]; + dst->b[5] = src.b[2]; + dst->b[4] = dst->b[2]; + dst->b[3] = src.b[1]; + dst->b[2] = dst->b[1]; + dst->b[1] = src.b[0]; + dst->b[0] = dst->b[0]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -117,19 +157,25 @@ static int opPUNPCKHBW_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = cpu_state.MM[cpu_reg].b[4]; - cpu_state.MM[cpu_reg].b[1] = src.b[4]; - cpu_state.MM[cpu_reg].b[2] = cpu_state.MM[cpu_reg].b[5]; - cpu_state.MM[cpu_reg].b[3] = src.b[5]; - cpu_state.MM[cpu_reg].b[4] = cpu_state.MM[cpu_reg].b[6]; - cpu_state.MM[cpu_reg].b[5] = src.b[6]; - cpu_state.MM[cpu_reg].b[6] = cpu_state.MM[cpu_reg].b[7]; - cpu_state.MM[cpu_reg].b[7] = src.b[7]; + dst->b[0] = dst->b[4]; + dst->b[1] = src.b[4]; + dst->b[2] = dst->b[5]; + dst->b[3] = src.b[5]; + dst->b[4] = dst->b[6]; + dst->b[5] = src.b[6]; + dst->b[6] = dst->b[7]; + dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -137,19 +183,25 @@ static int opPUNPCKHBW_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].b[0] = cpu_state.MM[cpu_reg].b[4]; - cpu_state.MM[cpu_reg].b[1] = src.b[4]; - cpu_state.MM[cpu_reg].b[2] = cpu_state.MM[cpu_reg].b[5]; - cpu_state.MM[cpu_reg].b[3] = src.b[5]; - cpu_state.MM[cpu_reg].b[4] = cpu_state.MM[cpu_reg].b[6]; - cpu_state.MM[cpu_reg].b[5] = src.b[6]; - cpu_state.MM[cpu_reg].b[6] = cpu_state.MM[cpu_reg].b[7]; - cpu_state.MM[cpu_reg].b[7] = src.b[7]; + dst->b[0] = dst->b[4]; + dst->b[1] = src.b[4]; + dst->b[2] = dst->b[5]; + dst->b[3] = src.b[5]; + dst->b[4] = dst->b[6]; + dst->b[5] = src.b[6]; + dst->b[6] = dst->b[7]; + dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -158,15 +210,21 @@ static int opPUNPCKLWD_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[3] = src.w[1]; - cpu_state.MM[cpu_reg].w[2] = cpu_state.MM[cpu_reg].w[1]; - cpu_state.MM[cpu_reg].w[1] = src.w[0]; - cpu_state.MM[cpu_reg].w[0] = cpu_state.MM[cpu_reg].w[0]; + dst->w[3] = src.w[1]; + dst->w[2] = dst->w[1]; + dst->w[1] = src.w[0]; + dst->w[0] = dst->w[0]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -174,15 +232,21 @@ static int opPUNPCKLWD_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[3] = src.w[1]; - cpu_state.MM[cpu_reg].w[2] = cpu_state.MM[cpu_reg].w[1]; - cpu_state.MM[cpu_reg].w[1] = src.w[0]; - cpu_state.MM[cpu_reg].w[0] = cpu_state.MM[cpu_reg].w[0]; + dst->w[3] = src.w[1]; + dst->w[2] = dst->w[1]; + dst->w[1] = src.w[0]; + dst->w[0] = dst->w[0]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -191,15 +255,21 @@ static int opPUNPCKHWD_a16(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = cpu_state.MM[cpu_reg].w[2]; - cpu_state.MM[cpu_reg].w[1] = src.w[2]; - cpu_state.MM[cpu_reg].w[2] = cpu_state.MM[cpu_reg].w[3]; - cpu_state.MM[cpu_reg].w[3] = src.w[3]; + dst->w[0] = dst->w[2]; + dst->w[1] = src.w[2]; + dst->w[2] = dst->w[3]; + dst->w[3] = src.w[3]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -207,15 +277,21 @@ static int opPUNPCKHWD_a32(uint32_t fetchdat) { MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSRC(); - cpu_state.MM[cpu_reg].w[0] = cpu_state.MM[cpu_reg].w[2]; - cpu_state.MM[cpu_reg].w[1] = src.w[2]; - cpu_state.MM[cpu_reg].w[2] = cpu_state.MM[cpu_reg].w[3]; - cpu_state.MM[cpu_reg].w[3] = src.w[3]; + dst->w[0] = dst->w[2]; + dst->w[1] = src.w[2]; + dst->w[2] = dst->w[3]; + dst->w[3] = src.w[3]; + + MMX_SETEXP(cpu_reg); return 0; } @@ -223,42 +299,52 @@ opPUNPCKHWD_a32(uint32_t fetchdat) static int opPACKSSWB_a16(uint32_t fetchdat) { - MMX_REG src, dst; + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); - MMX_GETSRC(); - dst = cpu_state.MM[cpu_reg]; - cpu_state.MM[cpu_reg].sb[0] = SSATB(dst.sw[0]); - cpu_state.MM[cpu_reg].sb[1] = SSATB(dst.sw[1]); - cpu_state.MM[cpu_reg].sb[2] = SSATB(dst.sw[2]); - cpu_state.MM[cpu_reg].sb[3] = SSATB(dst.sw[3]); - cpu_state.MM[cpu_reg].sb[4] = SSATB(src.sw[0]); - cpu_state.MM[cpu_reg].sb[5] = SSATB(src.sw[1]); - cpu_state.MM[cpu_reg].sb[6] = SSATB(src.sw[2]); - cpu_state.MM[cpu_reg].sb[7] = SSATB(src.sw[3]); + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->sb[0] = SSATB(dst->sw[0]); + dst->sb[1] = SSATB(dst->sw[1]); + dst->sb[2] = SSATB(dst->sw[2]); + dst->sb[3] = SSATB(dst->sw[3]); + dst->sb[4] = SSATB(src.sw[0]); + dst->sb[5] = SSATB(src.sw[1]); + dst->sb[6] = SSATB(src.sw[2]); + dst->sb[7] = SSATB(src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } static int opPACKSSWB_a32(uint32_t fetchdat) { - MMX_REG src, dst; + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); - MMX_GETSRC(); - dst = cpu_state.MM[cpu_reg]; - cpu_state.MM[cpu_reg].sb[0] = SSATB(dst.sw[0]); - cpu_state.MM[cpu_reg].sb[1] = SSATB(dst.sw[1]); - cpu_state.MM[cpu_reg].sb[2] = SSATB(dst.sw[2]); - cpu_state.MM[cpu_reg].sb[3] = SSATB(dst.sw[3]); - cpu_state.MM[cpu_reg].sb[4] = SSATB(src.sw[0]); - cpu_state.MM[cpu_reg].sb[5] = SSATB(src.sw[1]); - cpu_state.MM[cpu_reg].sb[6] = SSATB(src.sw[2]); - cpu_state.MM[cpu_reg].sb[7] = SSATB(src.sw[3]); + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->sb[0] = SSATB(dst->sw[0]); + dst->sb[1] = SSATB(dst->sw[1]); + dst->sb[2] = SSATB(dst->sw[2]); + dst->sb[3] = SSATB(dst->sw[3]); + dst->sb[4] = SSATB(src.sw[0]); + dst->sb[5] = SSATB(src.sw[1]); + dst->sb[6] = SSATB(src.sw[2]); + dst->sb[7] = SSATB(src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -266,42 +352,52 @@ opPACKSSWB_a32(uint32_t fetchdat) static int opPACKUSWB_a16(uint32_t fetchdat) { - MMX_REG src, dst; + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_16(fetchdat); - MMX_GETSRC(); - dst = cpu_state.MM[cpu_reg]; - cpu_state.MM[cpu_reg].b[0] = USATB(dst.sw[0]); - cpu_state.MM[cpu_reg].b[1] = USATB(dst.sw[1]); - cpu_state.MM[cpu_reg].b[2] = USATB(dst.sw[2]); - cpu_state.MM[cpu_reg].b[3] = USATB(dst.sw[3]); - cpu_state.MM[cpu_reg].b[4] = USATB(src.sw[0]); - cpu_state.MM[cpu_reg].b[5] = USATB(src.sw[1]); - cpu_state.MM[cpu_reg].b[6] = USATB(src.sw[2]); - cpu_state.MM[cpu_reg].b[7] = USATB(src.sw[3]); + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->b[0] = USATB(dst->sw[0]); + dst->b[1] = USATB(dst->sw[1]); + dst->b[2] = USATB(dst->sw[2]); + dst->b[3] = USATB(dst->sw[3]); + dst->b[4] = USATB(src.sw[0]); + dst->b[5] = USATB(src.sw[1]); + dst->b[6] = USATB(src.sw[2]); + dst->b[7] = USATB(src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } static int opPACKUSWB_a32(uint32_t fetchdat) { - MMX_REG src, dst; + MMX_REG src; + MMX_REG *dst; MMX_ENTER(); fetch_ea_32(fetchdat); - MMX_GETSRC(); - dst = cpu_state.MM[cpu_reg]; - cpu_state.MM[cpu_reg].b[0] = USATB(dst.sw[0]); - cpu_state.MM[cpu_reg].b[1] = USATB(dst.sw[1]); - cpu_state.MM[cpu_reg].b[2] = USATB(dst.sw[2]); - cpu_state.MM[cpu_reg].b[3] = USATB(dst.sw[3]); - cpu_state.MM[cpu_reg].b[4] = USATB(src.sw[0]); - cpu_state.MM[cpu_reg].b[5] = USATB(src.sw[1]); - cpu_state.MM[cpu_reg].b[6] = USATB(src.sw[2]); - cpu_state.MM[cpu_reg].b[7] = USATB(src.sw[3]); + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->b[0] = USATB(dst->sw[0]); + dst->b[1] = USATB(dst->sw[1]); + dst->b[2] = USATB(dst->sw[2]); + dst->b[3] = USATB(dst->sw[3]); + dst->b[4] = USATB(src.sw[0]); + dst->b[5] = USATB(src.sw[1]); + dst->b[6] = USATB(src.sw[2]); + dst->b[7] = USATB(src.sw[3]); + + MMX_SETEXP(cpu_reg); return 0; } @@ -309,34 +405,48 @@ opPACKUSWB_a32(uint32_t fetchdat) static int opPACKSSDW_a16(uint32_t fetchdat) { - MMX_REG src, dst; + MMX_REG src; + MMX_REG *dst; + MMX_REG dst2; MMX_ENTER(); fetch_ea_16(fetchdat); - MMX_GETSRC(); - dst = cpu_state.MM[cpu_reg]; - cpu_state.MM[cpu_reg].sw[0] = SSATW(dst.sl[0]); - cpu_state.MM[cpu_reg].sw[1] = SSATW(dst.sl[1]); - cpu_state.MM[cpu_reg].sw[2] = SSATW(src.sl[0]); - cpu_state.MM[cpu_reg].sw[3] = SSATW(src.sl[1]); + dst = MMX_GETREGP(cpu_reg); + dst2 = *dst; + + MMX_GETSRC(); + + dst->sw[0] = SSATW(dst2.sl[0]); + dst->sw[1] = SSATW(dst2.sl[1]); + dst->sw[2] = SSATW(src.sl[0]); + dst->sw[3] = SSATW(src.sl[1]); + + MMX_SETEXP(cpu_reg); return 0; } static int opPACKSSDW_a32(uint32_t fetchdat) { - MMX_REG src, dst; + MMX_REG src; + MMX_REG *dst; + MMX_REG dst2; MMX_ENTER(); fetch_ea_32(fetchdat); - MMX_GETSRC(); - dst = cpu_state.MM[cpu_reg]; - cpu_state.MM[cpu_reg].sw[0] = SSATW(dst.sl[0]); - cpu_state.MM[cpu_reg].sw[1] = SSATW(dst.sl[1]); - cpu_state.MM[cpu_reg].sw[2] = SSATW(src.sl[0]); - cpu_state.MM[cpu_reg].sw[3] = SSATW(src.sl[1]); + dst = MMX_GETREGP(cpu_reg); + dst2 = *dst; + + MMX_GETSRC(); + + dst->sw[0] = SSATW(dst2.sl[0]); + dst->sw[1] = SSATW(dst2.sl[1]); + dst->sw[2] = SSATW(src.sl[0]); + dst->sw[3] = SSATW(src.sl[1]); + + MMX_SETEXP(cpu_reg); return 0; } diff --git a/src/cpu/x86_ops_mmx_shift.h b/src/cpu/x86_ops_mmx_shift.h index c9ddc9b93..c0c80e87e 100644 --- a/src/cpu/x86_ops_mmx_shift.h +++ b/src/cpu/x86_ops_mmx_shift.h @@ -1,6 +1,6 @@ #define MMX_GETSHIFT() \ if (cpu_mod == 3) { \ - shift = cpu_state.MM[cpu_rm].b[0]; \ + shift = (MMX_GETREG(cpu_rm)).b[0]; \ CLOCK_CYCLES(1); \ } else { \ SEG_CHECK_READ(cpu_state.ea_seg); \ @@ -16,37 +16,39 @@ opPSxxW_imm(uint32_t fetchdat) int reg = fetchdat & 7; int op = fetchdat & 0x38; int shift = (fetchdat >> 8) & 0xff; + MMX_REG *dst; cpu_state.pc += 2; MMX_ENTER(); + dst = MMX_GETREGP(reg); switch (op) { case 0x10: /*PSRLW*/ if (shift > 15) - cpu_state.MM[reg].q = 0; + dst->q = 0; else { - cpu_state.MM[reg].w[0] >>= shift; - cpu_state.MM[reg].w[1] >>= shift; - cpu_state.MM[reg].w[2] >>= shift; - cpu_state.MM[reg].w[3] >>= shift; + dst->w[0] >>= shift; + dst->w[1] >>= shift; + dst->w[2] >>= shift; + dst->w[3] >>= shift; } break; case 0x20: /*PSRAW*/ if (shift > 15) shift = 15; - cpu_state.MM[reg].sw[0] >>= shift; - cpu_state.MM[reg].sw[1] >>= shift; - cpu_state.MM[reg].sw[2] >>= shift; - cpu_state.MM[reg].sw[3] >>= shift; + dst->sw[0] >>= shift; + dst->sw[1] >>= shift; + dst->sw[2] >>= shift; + dst->sw[3] >>= shift; break; case 0x30: /*PSLLW*/ if (shift > 15) - cpu_state.MM[reg].q = 0; + dst->q = 0; else { - cpu_state.MM[reg].w[0] <<= shift; - cpu_state.MM[reg].w[1] <<= shift; - cpu_state.MM[reg].w[2] <<= shift; - cpu_state.MM[reg].w[3] <<= shift; + dst->w[0] <<= shift; + dst->w[1] <<= shift; + dst->w[2] <<= shift; + dst->w[3] <<= shift; } break; default: @@ -55,6 +57,8 @@ opPSxxW_imm(uint32_t fetchdat) return 0; } + MMX_SETEXP(reg); + CLOCK_CYCLES(1); return 0; } @@ -62,126 +66,162 @@ opPSxxW_imm(uint32_t fetchdat) static int opPSLLW_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 15) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].w[0] <<= shift; - cpu_state.MM[cpu_reg].w[1] <<= shift; - cpu_state.MM[cpu_reg].w[2] <<= shift; - cpu_state.MM[cpu_reg].w[3] <<= shift; + dst->w[0] <<= shift; + dst->w[1] <<= shift; + dst->w[2] <<= shift; + dst->w[3] <<= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSLLW_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 15) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].w[0] <<= shift; - cpu_state.MM[cpu_reg].w[1] <<= shift; - cpu_state.MM[cpu_reg].w[2] <<= shift; - cpu_state.MM[cpu_reg].w[3] <<= shift; + dst->w[0] <<= shift; + dst->w[1] <<= shift; + dst->w[2] <<= shift; + dst->w[3] <<= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSRLW_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 15) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].w[0] >>= shift; - cpu_state.MM[cpu_reg].w[1] >>= shift; - cpu_state.MM[cpu_reg].w[2] >>= shift; - cpu_state.MM[cpu_reg].w[3] >>= shift; + dst->w[0] >>= shift; + dst->w[1] >>= shift; + dst->w[2] >>= shift; + dst->w[3] >>= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSRLW_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 15) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].w[0] >>= shift; - cpu_state.MM[cpu_reg].w[1] >>= shift; - cpu_state.MM[cpu_reg].w[2] >>= shift; - cpu_state.MM[cpu_reg].w[3] >>= shift; + dst->w[0] >>= shift; + dst->w[1] >>= shift; + dst->w[2] >>= shift; + dst->w[3] >>= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSRAW_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 15) shift = 15; - cpu_state.MM[cpu_reg].sw[0] >>= shift; - cpu_state.MM[cpu_reg].sw[1] >>= shift; - cpu_state.MM[cpu_reg].sw[2] >>= shift; - cpu_state.MM[cpu_reg].sw[3] >>= shift; + dst->sw[0] >>= shift; + dst->sw[1] >>= shift; + dst->sw[2] >>= shift; + dst->sw[3] >>= shift; + + MMX_SETEXP(cpu_reg); return 0; } static int opPSRAW_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 15) shift = 15; - cpu_state.MM[cpu_reg].sw[0] >>= shift; - cpu_state.MM[cpu_reg].sw[1] >>= shift; - cpu_state.MM[cpu_reg].sw[2] >>= shift; - cpu_state.MM[cpu_reg].sw[3] >>= shift; + dst->sw[0] >>= shift; + dst->sw[1] >>= shift; + dst->sw[2] >>= shift; + dst->sw[3] >>= shift; + + MMX_SETEXP(cpu_reg); return 0; } @@ -192,31 +232,34 @@ opPSxxD_imm(uint32_t fetchdat) int reg = fetchdat & 7; int op = fetchdat & 0x38; int shift = (fetchdat >> 8) & 0xff; + MMX_REG *dst; cpu_state.pc += 2; MMX_ENTER(); + dst = MMX_GETREGP(reg); + switch (op) { case 0x10: /*PSRLD*/ if (shift > 31) - cpu_state.MM[reg].q = 0; + dst->q = 0; else { - cpu_state.MM[reg].l[0] >>= shift; - cpu_state.MM[reg].l[1] >>= shift; + dst->l[0] >>= shift; + dst->l[1] >>= shift; } break; case 0x20: /*PSRAD*/ if (shift > 31) shift = 31; - cpu_state.MM[reg].sl[0] >>= shift; - cpu_state.MM[reg].sl[1] >>= shift; + dst->sl[0] >>= shift; + dst->sl[1] >>= shift; break; case 0x30: /*PSLLD*/ if (shift > 31) - cpu_state.MM[reg].q = 0; + dst->q = 0; else { - cpu_state.MM[reg].l[0] <<= shift; - cpu_state.MM[reg].l[1] <<= shift; + dst->l[0] <<= shift; + dst->l[1] <<= shift; } break; default: @@ -225,6 +268,8 @@ opPSxxD_imm(uint32_t fetchdat) return 0; } + MMX_SETEXP(reg); + CLOCK_CYCLES(1); return 0; } @@ -232,114 +277,150 @@ opPSxxD_imm(uint32_t fetchdat) static int opPSLLD_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 31) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].l[0] <<= shift; - cpu_state.MM[cpu_reg].l[1] <<= shift; + dst->l[0] <<= shift; + dst->l[1] <<= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSLLD_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 31) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].l[0] <<= shift; - cpu_state.MM[cpu_reg].l[1] <<= shift; + dst->l[0] <<= shift; + dst->l[1] <<= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSRLD_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 31) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].l[0] >>= shift; - cpu_state.MM[cpu_reg].l[1] >>= shift; + dst->l[0] >>= shift; + dst->l[1] >>= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSRLD_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 31) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else { - cpu_state.MM[cpu_reg].l[0] >>= shift; - cpu_state.MM[cpu_reg].l[1] >>= shift; + dst->l[0] >>= shift; + dst->l[1] >>= shift; } + MMX_SETEXP(cpu_reg); + return 0; } static int opPSRAD_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 31) shift = 31; - cpu_state.MM[cpu_reg].sl[0] >>= shift; - cpu_state.MM[cpu_reg].sl[1] >>= shift; + dst->sl[0] >>= shift; + dst->sl[1] >>= shift; + + MMX_SETEXP(cpu_reg); return 0; } static int opPSRAD_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 31) shift = 31; - cpu_state.MM[cpu_reg].sl[0] >>= shift; - cpu_state.MM[cpu_reg].sl[1] >>= shift; + dst->sl[0] >>= shift; + dst->sl[1] >>= shift; + + MMX_SETEXP(cpu_reg); return 0; } @@ -350,27 +431,32 @@ opPSxxQ_imm(uint32_t fetchdat) int reg = fetchdat & 7; int op = fetchdat & 0x38; int shift = (fetchdat >> 8) & 0xff; + MMX_REG *dst; cpu_state.pc += 2; + MMX_ENTER(); + dst = MMX_GETREGP(reg); + switch (op) { case 0x10: /*PSRLW*/ if (shift > 63) - cpu_state.MM[reg].q = 0; + dst->q = 0; else - cpu_state.MM[reg].q >>= shift; + dst->q >>= shift; break; case 0x20: /*PSRAW*/ if (shift > 63) shift = 63; - cpu_state.MM[reg].sq >>= shift; + + dst->sq >>= shift; break; case 0x30: /*PSLLW*/ if (shift > 63) - cpu_state.MM[reg].q = 0; + dst->q = 0; else - cpu_state.MM[reg].q <<= shift; + dst->q <<= shift; break; default: cpu_state.pc = cpu_state.oldpc; @@ -378,6 +464,8 @@ opPSxxQ_imm(uint32_t fetchdat) return 0; } + MMX_SETEXP(reg); + CLOCK_CYCLES(1); return 0; } @@ -385,34 +473,46 @@ opPSxxQ_imm(uint32_t fetchdat) static int opPSLLQ_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 63) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else - cpu_state.MM[cpu_reg].q <<= shift; + dst->q <<= shift; + + MMX_SETEXP(cpu_reg); return 0; } static int opPSLLQ_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 63) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else - cpu_state.MM[cpu_reg].q <<= shift; + dst->q <<= shift; + + MMX_SETEXP(cpu_reg); return 0; } @@ -420,34 +520,46 @@ opPSLLQ_a32(uint32_t fetchdat) static int opPSRLQ_a16(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 63) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else - cpu_state.MM[cpu_reg].q >>= shift; + dst->q >>= shift; + + MMX_SETEXP(cpu_reg); return 0; } static int opPSRLQ_a32(uint32_t fetchdat) { + MMX_REG *dst; int shift; MMX_ENTER(); fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + MMX_GETSHIFT(); if (shift > 63) - cpu_state.MM[cpu_reg].q = 0; + dst->q = 0; else - cpu_state.MM[cpu_reg].q >>= shift; + dst->q >>= shift; + + MMX_SETEXP(cpu_reg); return 0; } diff --git a/src/cpu/x86_ops_mov_ctrl.h b/src/cpu/x86_ops_mov_ctrl.h index d28033d5d..d95116c93 100644 --- a/src/cpu/x86_ops_mov_ctrl.h +++ b/src/cpu/x86_ops_mov_ctrl.h @@ -251,12 +251,12 @@ opMOV_DRx_r_a32(uint32_t fetchdat) static void opMOV_r_TRx(void) { - uint32_t base; + // uint32_t base; - base = _tr[4] & 0xfffff800; + // base = _tr[4] & 0xfffff800; switch (cpu_reg) { case 3: - pclog("[R] %08X cache = %08X\n", base + cache_index, _tr[3]); + // pclog("[R] %08X cache = %08X\n", base + cache_index, _tr[3]); _tr[3] = *(uint32_t *) &(_cache[cache_index]); cache_index = (cache_index + 4) & 0xf; break; @@ -300,35 +300,35 @@ opMOV_TRx_r(void) ctl = _tr[5] & 3; switch (cpu_reg) { case 3: - pclog("[W] %08X cache = %08X\n", base + cache_index, _tr[3]); + // pclog("[W] %08X cache = %08X\n", base + cache_index, _tr[3]); *(uint32_t *) &(_cache[cache_index]) = _tr[3]; cache_index = (cache_index + 4) & 0xf; break; case 4: - if (!(cr0 & 1) && !(_tr[5] & (1 << 19))) - pclog("TAG = %08X, DEST = %08X\n", base, base + cache_index - 16); + // if (!(cr0 & 1) && !(_tr[5] & (1 << 19))) + // pclog("TAG = %08X, DEST = %08X\n", base, base + cache_index - 16); break; case 5: - pclog("[16] EXT = %i (%i), SET = %04X\n", !!(_tr[5] & (1 << 19)), _tr[5] & 0x03, _tr[5] & 0x7f0); + // pclog("[16] EXT = %i (%i), SET = %04X\n", !!(_tr[5] & (1 << 19)), _tr[5] & 0x03, _tr[5] & 0x7f0); if (!(_tr[5] & (1 << 19))) { switch (ctl) { case 0: - pclog(" Cache fill or read...\n", base); + // pclog(" Cache fill or read...\n", base); break; case 1: base += (_tr[5] & 0x7f0); - pclog(" Writing 16 bytes to %08X...\n", base); + // pclog(" Writing 16 bytes to %08X...\n", base); for (i = 0; i < 16; i += 4) mem_writel_phys(base + i, *(uint32_t *) &(_cache[i])); break; case 2: base += (_tr[5] & 0x7f0); - pclog(" Reading 16 bytes from %08X...\n", base); + // pclog(" Reading 16 bytes from %08X...\n", base); for (i = 0; i < 16; i += 4) *(uint32_t *) &(_cache[i]) = mem_readl_phys(base + i); break; case 3: - pclog(" Cache invalidate/flush...\n", base); + // pclog(" Cache invalidate/flush...\n", base); break; } } diff --git a/src/cpu/x86_ops_pmode.h b/src/cpu/x86_ops_pmode.h index 4fee881ea..c8e146450 100644 --- a/src/cpu/x86_ops_pmode.h +++ b/src/cpu/x86_ops_pmode.h @@ -461,7 +461,7 @@ op0F01_common(uint32_t fetchdat, int is32, int is286, int ea32) break; } SEG_CHECK_READ(cpu_state.ea_seg); - mmu_invalidate(ds + cpu_state.eaaddr); + flushmmucache_nopc(); CLOCK_CYCLES(12); PREFETCH_RUN(12, 2, rmdat, 0, 0, 0, 0, ea32); break; diff --git a/src/cpu/x86_ops_rep.h b/src/cpu/x86_ops_rep.h index 67bd8433d..a49db7e81 100644 --- a/src/cpu/x86_ops_rep.h +++ b/src/cpu/x86_ops_rep.h @@ -9,7 +9,7 @@ uint8_t temp; \ \ SEG_CHECK_WRITE(&cpu_state.seg_es); \ - check_io_perm(DX); \ + check_io_perm(DX, 1); \ CHECK_WRITE(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = 0; \ do_mmut_wb(es, DEST_REG, &addr64); \ @@ -48,8 +48,7 @@ uint16_t temp; \ \ SEG_CHECK_WRITE(&cpu_state.seg_es); \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ + check_io_perm(DX, 2); \ CHECK_WRITE(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = 0; \ do_mmut_ww(es, DEST_REG, addr64a); \ @@ -88,10 +87,7 @@ uint32_t temp; \ \ SEG_CHECK_WRITE(&cpu_state.seg_es); \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ - check_io_perm(DX + 2); \ - check_io_perm(DX + 3); \ + check_io_perm(DX, 4); \ CHECK_WRITE(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = 0; \ do_mmut_wl(es, DEST_REG, addr64a); \ @@ -132,7 +128,7 @@ temp = readmemb(cpu_state.ea_seg->base, SRC_REG); \ if (cpu_state.abrt) \ return 1; \ - check_io_perm(DX); \ + check_io_perm(DX, 1); \ outb(DX, temp); \ if (cpu_state.flags & D_FLAG) \ SRC_REG--; \ @@ -163,8 +159,7 @@ temp = readmemw(cpu_state.ea_seg->base, SRC_REG); \ if (cpu_state.abrt) \ return 1; \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ + check_io_perm(DX, 2); \ outw(DX, temp); \ if (cpu_state.flags & D_FLAG) \ SRC_REG -= 2; \ @@ -195,10 +190,7 @@ temp = readmeml(cpu_state.ea_seg->base, SRC_REG); \ if (cpu_state.abrt) \ return 1; \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ - check_io_perm(DX + 2); \ - check_io_perm(DX + 3); \ + check_io_perm(DX, 4); \ outl(DX, temp); \ if (cpu_state.flags & D_FLAG) \ SRC_REG -= 4; \ @@ -234,11 +226,11 @@ uint8_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_wb(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ break; \ @@ -288,11 +280,11 @@ uint16_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_ww(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -342,11 +334,11 @@ uint32_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_wl(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -590,11 +582,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = uncached = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_rb2(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ return 1; \ @@ -644,11 +636,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = uncached = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_rw2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ @@ -698,11 +690,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = uncached = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_rl2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ diff --git a/src/cpu/x86_ops_rep_dyn.h b/src/cpu/x86_ops_rep_dyn.h index 576baa403..cf32209cc 100644 --- a/src/cpu/x86_ops_rep_dyn.h +++ b/src/cpu/x86_ops_rep_dyn.h @@ -7,7 +7,7 @@ uint8_t temp; \ \ SEG_CHECK_WRITE(&cpu_state.seg_es); \ - check_io_perm(DX); \ + check_io_perm(DX, 1); \ CHECK_WRITE(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = 0; \ do_mmut_wb(es, DEST_REG, &addr64); \ @@ -40,8 +40,7 @@ uint16_t temp; \ \ SEG_CHECK_WRITE(&cpu_state.seg_es); \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ + check_io_perm(DX, 2); \ CHECK_WRITE(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = 0; \ do_mmut_ww(es, DEST_REG, addr64a); \ @@ -74,10 +73,7 @@ uint32_t temp; \ \ SEG_CHECK_WRITE(&cpu_state.seg_es); \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ - check_io_perm(DX + 2); \ - check_io_perm(DX + 3); \ + check_io_perm(DX, 4); \ CHECK_WRITE(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = 0; \ do_mmut_wl(es, DEST_REG, addr64a); \ @@ -112,7 +108,7 @@ temp = readmemb(cpu_state.ea_seg->base, SRC_REG); \ if (cpu_state.abrt) \ return 1; \ - check_io_perm(DX); \ + check_io_perm(DX, 1); \ outb(DX, temp); \ if (cpu_state.flags & D_FLAG) \ SRC_REG--; \ @@ -137,8 +133,7 @@ temp = readmemw(cpu_state.ea_seg->base, SRC_REG); \ if (cpu_state.abrt) \ return 1; \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ + check_io_perm(DX, 2); \ outw(DX, temp); \ if (cpu_state.flags & D_FLAG) \ SRC_REG -= 2; \ @@ -163,10 +158,7 @@ temp = readmeml(cpu_state.ea_seg->base, SRC_REG); \ if (cpu_state.abrt) \ return 1; \ - check_io_perm(DX); \ - check_io_perm(DX + 1); \ - check_io_perm(DX + 2); \ - check_io_perm(DX + 3); \ + check_io_perm(DX, 4); \ outl(DX, temp); \ if (cpu_state.flags & D_FLAG) \ SRC_REG -= 4; \ @@ -197,11 +189,11 @@ uint8_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_wb(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ break; \ @@ -246,11 +238,11 @@ uint16_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_ww(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -295,11 +287,11 @@ uint32_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_wl(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -515,11 +507,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = uncached = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_rb2(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ return 1; \ @@ -566,11 +558,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = uncached = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_rw2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ @@ -617,11 +609,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = uncached = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_rl2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ diff --git a/src/cpu/x86_ops_string.h b/src/cpu/x86_ops_string.h index 5cc5f3806..c9ba94760 100644 --- a/src/cpu/x86_ops_string.h +++ b/src/cpu/x86_ops_string.h @@ -6,13 +6,13 @@ opMOVSB_a16(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI); + CHECK_WRITE(&cpu_state.seg_es, DI, DI); high_page = 0; do_mmut_rb(cpu_state.ea_seg->base, SI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, DI, DI); do_mmut_wb(es, DI, &addr64_2); if (cpu_state.abrt) @@ -42,13 +42,13 @@ opMOVSB_a32(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI); + CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); high_page = 0; do_mmut_rb(cpu_state.ea_seg->base, ESI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); do_mmut_wb(es, EDI, &addr64_2); if (cpu_state.abrt) return 1; @@ -79,13 +79,13 @@ opMOVSW_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 1UL); + CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); high_page = 0; do_mmut_rw(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); do_mmut_ww(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -115,13 +115,13 @@ opMOVSW_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 1UL); + CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); high_page = 0; do_mmut_rw(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); do_mmut_ww(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; @@ -152,13 +152,13 @@ opMOVSL_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 3UL); + CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); high_page = 0; do_mmut_rl(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); do_mmut_wl(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -188,13 +188,13 @@ opMOVSL_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 3UL); + CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); high_page = 0; do_mmut_rl(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); do_mmut_wl(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; @@ -224,13 +224,13 @@ opCMPSB_a16(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI); + CHECK_READ(&cpu_state.seg_es, DI, DI); high_page = uncached = 0; do_mmut_rb(cpu_state.ea_seg->base, SI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, DI, DI); do_mmut_rb2(es, DI, &addr64_2); if (cpu_state.abrt) return 1; @@ -264,13 +264,13 @@ opCMPSB_a32(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI); + CHECK_READ(&cpu_state.seg_es, EDI, EDI); high_page = uncached = 0; do_mmut_rb(cpu_state.ea_seg->base, ESI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, EDI, EDI); do_mmut_rb2(es, EDI, &addr64_2); if (cpu_state.abrt) return 1; @@ -306,13 +306,13 @@ opCMPSW_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 1UL); + CHECK_READ(&cpu_state.seg_es, DI, DI + 1UL); high_page = uncached = 0; do_mmut_rw(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, DI, DI + 1UL); do_mmut_rw2(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -347,13 +347,13 @@ opCMPSW_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 1UL); + CHECK_READ(&cpu_state.seg_es, EDI, EDI + 1UL); high_page = uncached = 0; do_mmut_rw(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, EDI, EDI + 1UL); do_mmut_rw2(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; @@ -389,13 +389,13 @@ opCMPSL_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 3UL); + CHECK_READ(&cpu_state.seg_es, DI, DI + 3UL); high_page = uncached = 0; do_mmut_rl(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, DI, DI + 3UL); do_mmut_rl2(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -430,13 +430,13 @@ opCMPSL_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 3UL); + CHECK_READ(&cpu_state.seg_es, EDI, EDI + 3UL); high_page = uncached = 0; do_mmut_rl(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, EDI, EDI + 3UL); do_mmut_rl2(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; @@ -804,7 +804,7 @@ opINSB_a16(uint32_t fetchdat) addr64 = 0x00000000; SEG_CHECK_WRITE(&cpu_state.seg_es); - check_io_perm(DX); + check_io_perm(DX, 1); CHECK_WRITE(&cpu_state.seg_es, DI, DI); high_page = 0; do_mmut_wb(es, DI, &addr64); @@ -830,7 +830,7 @@ opINSB_a32(uint32_t fetchdat) addr64 = 0x00000000; SEG_CHECK_WRITE(&cpu_state.seg_es); - check_io_perm(DX); + check_io_perm(DX, 1); high_page = 0; CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); do_mmut_wb(es, EDI, &addr64); @@ -857,8 +857,7 @@ opINSW_a16(uint32_t fetchdat) addr64a[0] = addr64a[1] = 0x00000000; SEG_CHECK_WRITE(&cpu_state.seg_es); - check_io_perm(DX); - check_io_perm(DX + 1); + check_io_perm(DX, 2); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); high_page = 0; do_mmut_ww(es, DI, addr64a); @@ -885,8 +884,7 @@ opINSW_a32(uint32_t fetchdat) SEG_CHECK_WRITE(&cpu_state.seg_es); high_page = 0; - check_io_perm(DX); - check_io_perm(DX + 1); + check_io_perm(DX, 2); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); do_mmut_ww(es, EDI, addr64a); if (cpu_state.abrt) @@ -912,10 +910,7 @@ opINSL_a16(uint32_t fetchdat) addr64a[0] = addr64a[1] = addr64a[2] = addr64a[3] = 0x00000000; SEG_CHECK_WRITE(&cpu_state.seg_es); - check_io_perm(DX); - check_io_perm(DX + 1); - check_io_perm(DX + 2); - check_io_perm(DX + 3); + check_io_perm(DX, 4); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); high_page = 0; do_mmut_wl(es, DI, addr64a); @@ -941,10 +936,7 @@ opINSL_a32(uint32_t fetchdat) addr64a[0] = addr64a[1] = addr64a[2] = addr64a[3] = 0x00000000; SEG_CHECK_WRITE(&cpu_state.seg_es); - check_io_perm(DX); - check_io_perm(DX + 1); - check_io_perm(DX + 2); - check_io_perm(DX + 3); + check_io_perm(DX, 4); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); high_page = 0; do_mmut_wl(es, DI, addr64a); @@ -973,7 +965,7 @@ opOUTSB_a16(uint32_t fetchdat) temp = readmemb(cpu_state.ea_seg->base, SI); if (cpu_state.abrt) return 1; - check_io_perm(DX); + check_io_perm(DX, 1); if (cpu_state.flags & D_FLAG) SI--; else @@ -993,7 +985,7 @@ opOUTSB_a32(uint32_t fetchdat) temp = readmemb(cpu_state.ea_seg->base, ESI); if (cpu_state.abrt) return 1; - check_io_perm(DX); + check_io_perm(DX, 1); if (cpu_state.flags & D_FLAG) ESI--; else @@ -1014,8 +1006,7 @@ opOUTSW_a16(uint32_t fetchdat) temp = readmemw(cpu_state.ea_seg->base, SI); if (cpu_state.abrt) return 1; - check_io_perm(DX); - check_io_perm(DX + 1); + check_io_perm(DX, 2); if (cpu_state.flags & D_FLAG) SI -= 2; else @@ -1035,8 +1026,7 @@ opOUTSW_a32(uint32_t fetchdat) temp = readmemw(cpu_state.ea_seg->base, ESI); if (cpu_state.abrt) return 1; - check_io_perm(DX); - check_io_perm(DX + 1); + check_io_perm(DX, 2); if (cpu_state.flags & D_FLAG) ESI -= 2; else @@ -1057,10 +1047,7 @@ opOUTSL_a16(uint32_t fetchdat) temp = readmeml(cpu_state.ea_seg->base, SI); if (cpu_state.abrt) return 1; - check_io_perm(DX); - check_io_perm(DX + 1); - check_io_perm(DX + 2); - check_io_perm(DX + 3); + check_io_perm(DX, 4); if (cpu_state.flags & D_FLAG) SI -= 4; else @@ -1080,10 +1067,7 @@ opOUTSL_a32(uint32_t fetchdat) temp = readmeml(cpu_state.ea_seg->base, ESI); if (cpu_state.abrt) return 1; - check_io_perm(DX); - check_io_perm(DX + 1); - check_io_perm(DX + 2); - check_io_perm(DX + 3); + check_io_perm(DX, 4); if (cpu_state.flags & D_FLAG) ESI -= 4; else diff --git a/src/cpu/x86seg.c b/src/cpu/x86seg.c index 5b0d8b73a..7f630275c 100644 --- a/src/cpu/x86seg.c +++ b/src/cpu/x86seg.c @@ -580,7 +580,7 @@ loadcs(uint16_t seg) do_seg_load(&cpu_state.seg_cs, segdat); use32 = (segdat[3] & 0x40) ? 0x300 : 0; if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -609,7 +609,7 @@ loadcs(uint16_t seg) cpu_state.seg_cs.access = (cpu_state.eflags & VM_FLAG) ? 0xe2 : 0x82; cpu_state.seg_cs.ar_high = 0x10; if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -673,7 +673,7 @@ loadcsjmp(uint16_t seg, uint32_t old_pc) do_seg_load(&cpu_state.seg_cs, segdat); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -751,7 +751,7 @@ loadcsjmp(uint16_t seg, uint32_t old_pc) CS = seg2; do_seg_load(&cpu_state.seg_cs, segdat); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -794,7 +794,7 @@ loadcsjmp(uint16_t seg, uint32_t old_pc) cpu_state.seg_cs.access = (cpu_state.eflags & VM_FLAG) ? 0xe2 : 0x82; cpu_state.seg_cs.ar_high = 0x10; if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -957,7 +957,7 @@ loadcscall(uint16_t seg) CS = seg; do_seg_load(&cpu_state.seg_cs, segdat); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1100,7 +1100,7 @@ loadcscall(uint16_t seg) CS = seg2; do_seg_load(&cpu_state.seg_cs, segdat); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1182,7 +1182,7 @@ loadcscall(uint16_t seg) CS = seg2; do_seg_load(&cpu_state.seg_cs, segdat); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1227,7 +1227,7 @@ loadcscall(uint16_t seg) cpu_state.seg_cs.access = (cpu_state.eflags & VM_FLAG) ? 0xe2 : 0x82; cpu_state.seg_cs.ar_high = 0x10; if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1332,7 +1332,7 @@ pmoderetf(int is32, uint16_t off) do_seg_load(&cpu_state.seg_cs, segdat); cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~(3 << 5)) | ((CS & 3) << 5); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1445,7 +1445,7 @@ pmoderetf(int is32, uint16_t off) CS = seg; do_seg_load(&cpu_state.seg_cs, segdat); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1697,7 +1697,7 @@ pmodeint(int num, int soft) CS = (seg & 0xfffc) | new_cpl; cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~0x60) | (new_cpl << 5); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1863,7 +1863,7 @@ pmodeiret(int is32) cpu_state.seg_cs.access = 0xe2; cpu_state.seg_cs.ar_high = 0x10; if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -1948,7 +1948,7 @@ pmodeiret(int is32) do_seg_load(&cpu_state.seg_cs, segdat); cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~0x60) | ((CS & 0x0003) << 5); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -2037,7 +2037,7 @@ pmodeiret(int is32) do_seg_load(&cpu_state.seg_cs, segdat); cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~0x60) | ((CS & 3) << 5); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -2233,7 +2233,7 @@ taskswitch286(uint16_t seg, uint16_t *segdat, int is32) CS = new_cs; do_seg_load(&cpu_state.seg_cs, segdat2); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif @@ -2401,7 +2401,7 @@ taskswitch286(uint16_t seg, uint16_t *segdat, int is32) CS = new_cs; do_seg_load(&cpu_state.seg_cs, segdat2); if ((CPL == 3) && (oldcpl != 3)) - flushmmucache_cr3(); + flushmmucache_nopc(); #ifdef USE_NEW_DYNAREC oldcpl = CPL; #endif diff --git a/src/cpu/x87.c b/src/cpu/x87.c index 0b93af9da..181b7b9ca 100644 --- a/src/cpu/x87.c +++ b/src/cpu/x87.c @@ -15,6 +15,7 @@ #include "x86_ops.h" #include "x87.h" #include "386_common.h" +#include "softfloat/softfloat-specialize.h" uint32_t x87_pc_off, x87_op_off; uint16_t x87_pc_seg, x87_op_seg; @@ -37,11 +38,6 @@ fpu_log(const char *fmt, ...) # define fpu_log(fmt, ...) #endif -#define X87_TAG_VALID 0 -#define X87_TAG_ZERO 1 -#define X87_TAG_INVALID 2 -#define X87_TAG_EMPTY 3 - #ifdef USE_NEW_DYNAREC uint16_t x87_gettag(void) @@ -110,6 +106,413 @@ x87_settag(uint16_t new_tag) } #endif + +static floatx80 +FPU_handle_NaN32_Func(floatx80 a, int aIsNaN, float32 b32, int bIsNaN, struct float_status_t *status) +{ + int aIsSignalingNaN = floatx80_is_signaling_nan(a); + int bIsSignalingNaN = float32_is_signaling_nan(b32); + + if (aIsSignalingNaN | bIsSignalingNaN) + float_raise(status, float_flag_invalid); + + // propagate QNaN to SNaN + a = propagateFloatx80NaNOne(a, status); + + if (aIsNaN & !bIsNaN) return a; + + // float32 is NaN so conversion will propagate SNaN to QNaN and raise + // appropriate exception flags + floatx80 b = float32_to_floatx80(b32, status); + + if (aIsSignalingNaN) { + if (bIsSignalingNaN) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if (aIsNaN) { + if (bIsSignalingNaN) return a; + returnLargerSignificand: + if (a.fraction < b.fraction) return b; + if (b.fraction < a.fraction) return a; + return (a.exp < b.exp) ? a : b; + } + else { + return b; + } +} + +int +FPU_handle_NaN32(floatx80 a, float32 b, floatx80 *r, struct float_status_t *status) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + if (floatx80_is_unsupported(a)) { + float_raise(status, float_flag_invalid); + *r = floatx80_default_nan; + return 1; + } + + int aIsNaN = floatx80_is_nan(a), bIsNaN = float32_is_nan(b); + if (aIsNaN | bIsNaN) { + *r = FPU_handle_NaN32_Func(a, aIsNaN, b, bIsNaN, status); + return 1; + } + return 0; +} + +static floatx80 +FPU_handle_NaN64_Func(floatx80 a, int aIsNaN, float64 b64, int bIsNaN, struct float_status_t *status) +{ + int aIsSignalingNaN = floatx80_is_signaling_nan(a); + int bIsSignalingNaN = float64_is_signaling_nan(b64); + + if (aIsSignalingNaN | bIsSignalingNaN) + float_raise(status, float_flag_invalid); + + // propagate QNaN to SNaN + a = propagateFloatx80NaNOne(a, status); + + if (aIsNaN & !bIsNaN) return a; + + // float64 is NaN so conversion will propagate SNaN to QNaN and raise + // appropriate exception flags + floatx80 b = float64_to_floatx80(b64, status); + + if (aIsSignalingNaN) { + if (bIsSignalingNaN) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if (aIsNaN) { + if (bIsSignalingNaN) return a; + returnLargerSignificand: + if (a.fraction < b.fraction) return b; + if (b.fraction < a.fraction) return a; + return (a.exp < b.exp) ? a : b; + } + else { + return b; + } +} + +int +FPU_handle_NaN64(floatx80 a, float64 b, floatx80 *r, struct float_status_t *status) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + if (floatx80_is_unsupported(a)) { + float_raise(status, float_flag_invalid); + *r = floatx80_default_nan; + return 1; + } + + int aIsNaN = floatx80_is_nan(a), bIsNaN = float64_is_nan(b); + if (aIsNaN | bIsNaN) { + *r = FPU_handle_NaN64_Func(a, aIsNaN, b, bIsNaN, status); + return 1; + } + return 0; +} + +struct float_status_t +i387cw_to_softfloat_status_word(uint16_t control_word) +{ + struct float_status_t status; + int precision = control_word & FPU_CW_PC; + + switch (precision) { + case FPU_PR_32_BITS: + status.float_rounding_precision = 32; + break; + case FPU_PR_64_BITS: + status.float_rounding_precision = 64; + break; + case FPU_PR_80_BITS: + status.float_rounding_precision = 80; + break; + default: + /* With the precision control bits set to 01 "(reserved)", a + real CPU behaves as if the precision control bits were + set to 11 "80 bits" */ + status.float_rounding_precision = 80; + break; + } + + status.float_exception_flags = 0; // clear exceptions before execution + status.float_nan_handling_mode = float_first_operand_nan; + status.float_rounding_mode = (control_word & FPU_CW_RC) >> 10; + status.flush_underflow_to_zero = 0; + status.float_suppress_exception = 0; + status.float_exception_masks = control_word & FPU_CW_Exceptions_Mask; + status.denormals_are_zeros = 0; + return status; +} + + +int +FPU_status_word_flags_fpu_compare(int float_relation) +{ + switch (float_relation) { + case float_relation_unordered: + return (C0 | C2 | C3); + + case float_relation_greater: + return (0); + + case float_relation_less: + return (C0); + + case float_relation_equal: + return (C3); + } + + return (-1); // should never get here +} + +void +FPU_write_eflags_fpu_compare(int float_relation) +{ + switch (float_relation) { + case float_relation_unordered: + cpu_state.flags |= (Z_FLAG | P_FLAG | C_FLAG); + break; + + case float_relation_greater: + break; + + case float_relation_less: + cpu_state.flags |= (C_FLAG); + break; + + case float_relation_equal: + cpu_state.flags |= (Z_FLAG); + break; + + default: + break; + } +} + +uint16_t +FPU_exception(uint32_t fetchdat, uint16_t exceptions, int store) +{ + uint16_t status; + uint16_t unmasked; + + /* Extract only the bits which we use to set the status word */ + exceptions &= FPU_SW_Exceptions_Mask; + status = fpu_state.swd; + + unmasked = (exceptions & ~fpu_state.cwd) & FPU_CW_Exceptions_Mask; + + // if IE or DZ exception happen nothing else will be reported + if (exceptions & (FPU_EX_Invalid | FPU_EX_Zero_Div)) { + unmasked &= (FPU_EX_Invalid | FPU_EX_Zero_Div); + } + + /* Set summary bits if exception isn't masked */ + if (unmasked) { + fpu_state.swd |= (FPU_SW_Summary | FPU_SW_Backward); + } + + if (exceptions & FPU_EX_Invalid) { + // FPU_EX_Invalid cannot come with any other exception but x87 stack fault + fpu_state.swd |= exceptions; + if (exceptions & FPU_SW_Stack_Fault) { + if (!(exceptions & C1)) { + /* This bit distinguishes over- from underflow for a stack fault, + and roundup from round-down for precision loss. */ + fpu_state.swd &= ~C1; + } + } + return unmasked; + } + + if (exceptions & FPU_EX_Zero_Div) { + fpu_state.swd |= FPU_EX_Zero_Div; + if (!(fpu_state.cwd & FPU_EX_Zero_Div)) { +#ifdef FPU_8087 + if (!(fpu_state.cwd & FPU_SW_Summary)) { + fpu_state.cwd |= FPU_SW_Summary; + nmi = 1; + } +#else + picint(1 << 13); +#endif // FPU_8087 + } + return unmasked; + } + + if (exceptions & FPU_EX_Denormal) { + fpu_state.swd |= FPU_EX_Denormal; + if (unmasked & FPU_EX_Denormal) { + return (unmasked & FPU_EX_Denormal); + } + } + + /* Set the corresponding exception bits */ + fpu_state.swd |= exceptions; + + if (exceptions & FPU_EX_Precision) { + if (!(exceptions & C1)) { + /* This bit distinguishes over- from underflow for a stack fault, + and roundup from round-down for precision loss. */ + fpu_state.swd &= ~C1; + } + } + + // If #P unmasked exception occurred the result still has to be + // written to the destination. + unmasked &= ~FPU_EX_Precision; + + if (unmasked & (FPU_EX_Underflow | FPU_EX_Overflow)) { + // If unmasked over- or underflow occurs and dest is a memory location: + // - the TOS and destination operands remain unchanged + // - the inexact-result condition is not reported and C1 flag is cleared + // - no result is stored in the memory + // If the destination is in the register stack, adjusted resulting value + // is stored in the destination operand. + if (!store) + unmasked &= ~(FPU_EX_Underflow | FPU_EX_Overflow); + else { + fpu_state.swd &= ~C1; + if (!(status & FPU_EX_Precision)) + fpu_state.swd &= ~FPU_EX_Precision; + } + } + return unmasked; +} + +void +FPU_stack_overflow(uint32_t fetchdat) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + /* The masked response */ + if (is_IA_masked()) { + FPU_push(); + FPU_save_regi(floatx80_default_nan, 0); + } + FPU_exception(fetchdat, FPU_EX_Stack_Overflow, 0); +} + +void +FPU_stack_underflow(uint32_t fetchdat, int stnr, int pop_stack) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + + /* The masked response */ + if (is_IA_masked()) { + FPU_save_regi(floatx80_default_nan, stnr); + if (pop_stack) + FPU_pop(); + } + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); +} + +/* ----------------------------------------------------------- + * Slimmed down version used to compile against a CPU simulator + * rather than a kernel (ported by Kevin Lawton) + * ------------------------------------------------------------ */ +int +FPU_tagof(const floatx80 reg) +{ + int32_t exp = floatx80_exp(reg); + if (exp == 0) { + if (!floatx80_fraction(reg)) + return X87_TAG_ZERO; + + /* The number is a de-normal or pseudodenormal. */ + return X87_TAG_INVALID; + } + + if (exp == 0x7fff) { + /* Is an Infinity, a NaN, or an unsupported data type. */ + return X87_TAG_INVALID; + } + + if (!(reg.fraction & BX_CONST64(0x8000000000000000))) { + /* Unsupported data type. */ + /* Valid numbers have the ms bit set to 1. */ + return X87_TAG_INVALID; + } + + return X87_TAG_VALID; +} + +uint8_t +pack_FPU_TW(uint16_t twd) +{ + uint8_t tag_byte = 0; + + if ((twd & 0x0003) != 0x0003) tag_byte |= 0x01; + if ((twd & 0x000c) != 0x000c) tag_byte |= 0x02; + if ((twd & 0x0030) != 0x0030) tag_byte |= 0x04; + if ((twd & 0x00c0) != 0x00c0) tag_byte |= 0x08; + if ((twd & 0x0300) != 0x0300) tag_byte |= 0x10; + if ((twd & 0x0c00) != 0x0c00) tag_byte |= 0x20; + if ((twd & 0x3000) != 0x3000) tag_byte |= 0x40; + if ((twd & 0xc000) != 0xc000) tag_byte |= 0x80; + + return tag_byte; +} + +uint16_t +unpack_FPU_TW(uint16_t tag_byte) +{ + uint32_t twd = 0; + + /* FTW + * + * Note that the original format for FTW can be recreated from the stored + * FTW valid bits and the stored 80-bit FP data (assuming the stored data + * was not the contents of MMX registers) using the following table: + + | Exponent | Exponent | Fraction | J,M bits | FTW valid | x87 FTW | + | all 1s | all 0s | all 0s | | | | + ------------------------------------------------------------------- + | 0 | 0 | 0 | 0x | 1 | S 10 | + | 0 | 0 | 0 | 1x | 1 | V 00 | + ------------------------------------------------------------------- + | 0 | 0 | 1 | 00 | 1 | S 10 | + | 0 | 0 | 1 | 10 | 1 | V 00 | + ------------------------------------------------------------------- + | 0 | 1 | 0 | 0x | 1 | S 10 | + | 0 | 1 | 0 | 1x | 1 | S 10 | + ------------------------------------------------------------------- + | 0 | 1 | 1 | 00 | 1 | Z 01 | + | 0 | 1 | 1 | 10 | 1 | S 10 | + ------------------------------------------------------------------- + | 1 | 0 | 0 | 1x | 1 | S 10 | + | 1 | 0 | 0 | 1x | 1 | S 10 | + ------------------------------------------------------------------- + | 1 | 0 | 1 | 00 | 1 | S 10 | + | 1 | 0 | 1 | 10 | 1 | S 10 | + ------------------------------------------------------------------- + | all combinations above | 0 | E 11 | + + * + * The J-bit is defined to be the 1-bit binary integer to the left of + * the decimal place in the significand. + * + * The M-bit is defined to be the most significant bit of the fractional + * portion of the significand (i.e., the bit immediately to the right of + * the decimal place). When the M-bit is the most significant bit of the + * fractional portion of the significand, it must be 0 if the fraction + * is all 0's. + */ + + for (int index = 7; index >= 0; index--, twd <<= 2, tag_byte <<= 1) { + if (tag_byte & 0x80) { + const floatx80 *fpu_reg = &fpu_state.st_space[index & 7]; + twd |= FPU_tagof(*fpu_reg); + } else { + twd |= X87_TAG_EMPTY; + } + } + + return (twd >> 2); +} + #ifdef ENABLE_808X_LOG void x87_dumpregs(void) diff --git a/src/cpu/x87.h b/src/cpu/x87.h index 96ad835c8..66d51dbd9 100644 --- a/src/cpu/x87.h +++ b/src/cpu/x87.h @@ -1,7 +1,7 @@ -#define C0 (1 << 8) -#define C1 (1 << 9) -#define C2 (1 << 10) -#define C3 (1 << 14) +#define X87_TAG_VALID 0 +#define X87_TAG_ZERO 1 +#define X87_TAG_INVALID 2 +#define X87_TAG_EMPTY 3 extern uint32_t x87_pc_off, x87_op_off; extern uint16_t x87_pc_seg, x87_op_seg; @@ -10,9 +10,14 @@ static __inline void x87_set_mmx(void) { uint64_t *p; - cpu_state.TOP = 0; - p = (uint64_t *) cpu_state.tag; - *p = 0x0101010101010101ull; + if (fpu_softfloat) { + fpu_state.tag = 0; + fpu_state.tos = 0; /* reset FPU Top-Of-Stack */ + } else { + cpu_state.TOP = 0; + p = (uint64_t *) cpu_state.tag; + *p = 0x0101010101010101ull; + } cpu_state.ismmx = 1; } @@ -20,8 +25,13 @@ static __inline void x87_emms(void) { uint64_t *p; - p = (uint64_t *) cpu_state.tag; - *p = 0; + if (fpu_softfloat) { + fpu_state.tag = 0xffff; + fpu_state.tos = 0; /* reset FPU Top-Of-Stack */ + } else { + p = (uint64_t *) cpu_state.tag; + *p = 0; + } cpu_state.ismmx = 0; } @@ -46,3 +56,186 @@ void x87_settag(uint16_t new_tag); #define X87_ROUNDING_CHOP 3 void codegen_set_rounding_mode(int mode); + +/* Status Word */ +#define FPU_SW_Backward (0x8000) /* backward compatibility */ +#define FPU_SW_C3 (0x4000) /* condition bit 3 */ +#define FPU_SW_Top (0x3800) /* top of stack */ +#define FPU_SW_C2 (0x0400) /* condition bit 2 */ +#define FPU_SW_C1 (0x0200) /* condition bit 1 */ +#define FPU_SW_C0 (0x0100) /* condition bit 0 */ +#define FPU_SW_Summary (0x0080) /* exception summary */ +#define FPU_SW_Stack_Fault (0x0040) /* stack fault */ +#define FPU_SW_Precision (0x0020) /* loss of precision */ +#define FPU_SW_Underflow (0x0010) /* underflow */ +#define FPU_SW_Overflow (0x0008) /* overflow */ +#define FPU_SW_Zero_Div (0x0004) /* divide by zero */ +#define FPU_SW_Denormal_Op (0x0002) /* denormalized operand */ +#define FPU_SW_Invalid (0x0001) /* invalid operation */ + +#define C0 (1 << 8) +#define C1 (1 << 9) +#define C2 (1 << 10) +#define C3 (1 << 14) + +#define FPU_SW_CC (C0 | C1 | C2 | C3) + +#define FPU_SW_Exceptions_Mask (0x027f) /* status word exceptions bit mask */ + +/* Exception flags: */ +#define FPU_EX_Precision (0x0020) /* loss of precision */ +#define FPU_EX_Underflow (0x0010) /* underflow */ +#define FPU_EX_Overflow (0x0008) /* overflow */ +#define FPU_EX_Zero_Div (0x0004) /* divide by zero */ +#define FPU_EX_Denormal (0x0002) /* denormalized operand */ +#define FPU_EX_Invalid (0x0001) /* invalid operation */ + +/* Special exceptions: */ +#define FPU_EX_Stack_Overflow (0x0041| C1) /* stack overflow */ +#define FPU_EX_Stack_Underflow (0x0041) /* stack underflow */ + +/* precision control */ +#define FPU_EX_Precision_Lost_Up (EX_Precision | C1) +#define FPU_EX_Precision_Lost_Dn (EX_Precision) + +#define setcc(cc) \ + fpu_state.swd = (fpu_state.swd & ~(FPU_SW_CC)) | ((cc) & FPU_SW_CC) + +#define clear_C1() { fpu_state.swd &= ~C1; } +#define clear_C2() { fpu_state.swd &= ~C2; } + +/* ************ */ +/* Control Word */ +/* ************ */ + +#define FPU_CW_Inf (0x1000) /* infinity control, legacy */ + +#define FPU_CW_RC (0x0C00) /* rounding control */ +#define FPU_CW_PC (0x0300) /* precision control */ + +#define FPU_RC_RND (0x0000) /* rounding control */ +#define FPU_RC_DOWN (0x0400) +#define FPU_RC_UP (0x0800) +#define FPU_RC_CHOP (0x0C00) + +#define FPU_CW_Precision (0x0020) /* loss of precision mask */ +#define FPU_CW_Underflow (0x0010) /* underflow mask */ +#define FPU_CW_Overflow (0x0008) /* overflow mask */ +#define FPU_CW_Zero_Div (0x0004) /* divide by zero mask */ +#define FPU_CW_Denormal (0x0002) /* denormalized operand mask */ +#define FPU_CW_Invalid (0x0001) /* invalid operation mask */ + +#define FPU_CW_Exceptions_Mask (0x003f) /* all masks */ + +/* Precision control bits affect only the following: + ADD, SUB(R), MUL, DIV(R), and SQRT */ +#define FPU_PR_32_BITS (0x000) +#define FPU_PR_RESERVED_BITS (0x100) +#define FPU_PR_64_BITS (0x200) +#define FPU_PR_80_BITS (0x300) + +#include "softfloat/softfloatx80.h" + +static __inline const int +is_IA_masked(void) +{ + return (fpu_state.cwd & FPU_CW_Invalid); +} + +struct float_status_t i387cw_to_softfloat_status_word(uint16_t control_word); +uint16_t FPU_exception(uint32_t fetchdat, uint16_t exceptions, int store); +int FPU_status_word_flags_fpu_compare(int float_relation); +void FPU_write_eflags_fpu_compare(int float_relation); +void FPU_stack_overflow(uint32_t fetchdat); +void FPU_stack_underflow(uint32_t fetchdat, int stnr, int pop_stack); +int FPU_handle_NaN32(floatx80 a, float32 b, floatx80 *r, struct float_status_t *status); +int FPU_handle_NaN64(floatx80 a, float64 b, floatx80 *r, struct float_status_t *status); +int FPU_tagof(const floatx80 reg); +uint8_t pack_FPU_TW(uint16_t twd); +uint16_t unpack_FPU_TW(uint16_t tag_byte); + +static __inline uint16_t +i387_get_control_word(void) +{ + return (fpu_state.cwd); +} + +static __inline uint16_t +i387_get_status_word(void) +{ + return (fpu_state.swd & ~FPU_SW_Top & 0xFFFF) | ((fpu_state.tos << 11) & FPU_SW_Top); +} + +#define IS_TAG_EMPTY(i) \ + (FPU_gettagi(i) == X87_TAG_EMPTY) + +static __inline int +FPU_gettagi(int stnr) +{ + return (fpu_state.tag >> (((stnr + fpu_state.tos) & 7) * 2)) & 3; +} + +static __inline void +FPU_settagi_valid(int stnr) +{ + int regnr = (stnr + fpu_state.tos) & 7; + fpu_state.tag &= ~(3 << (regnr * 2)); // FPU_Tag_Valid == '00 +} + +static __inline void +FPU_settagi(int tag, int stnr) +{ + int regnr = (stnr + fpu_state.tos) & 7; + fpu_state.tag &= ~(3 << (regnr * 2)); + fpu_state.tag |= (tag & 3) << (regnr * 2); +} + +static __inline void +FPU_push(void) +{ + fpu_state.tos = (fpu_state.tos - 1) & 7; +} + +static __inline void +FPU_pop(void) +{ + fpu_state.tag |= 3 << (fpu_state.tos * 2); + fpu_state.tos = (fpu_state.tos + 1) & 7; +} + +static __inline floatx80 +FPU_read_regi(int stnr) +{ + return fpu_state.st_space[(stnr + fpu_state.tos) & 7]; +} + +// it is only possible to read FPU tag word through certain +// instructions like FNSAVE, and they update tag word to its +// real value anyway +static __inline void +FPU_save_regi(floatx80 reg, int stnr) +{ + fpu_state.st_space[(stnr + fpu_state.tos) & 7] = reg; + FPU_settagi_valid(stnr); +} + +static __inline void +FPU_save_regi_tag(floatx80 reg, int tag, int stnr) +{ + fpu_state.st_space[(stnr + fpu_state.tos) & 7] = reg; + FPU_settagi(tag, stnr); +} + + +#define FPU_check_pending_exceptions() \ +do { \ + if (fpu_state.swd & FPU_SW_Summary) { \ + if (cr0 & 0x20) { \ + x86_int(16); \ + return 1; \ + } else { \ + picint(1 << 13); \ + return 1; \ + } \ + } \ +} while (0) diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index c00cdff16..b01547314 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -26,6 +26,7 @@ #ifdef _MSC_VER # include #endif +#include "x87_ops_conv.h" #ifdef ENABLE_FPU_LOG extern void fpu_log(const char *fmt, ...); @@ -44,8 +45,24 @@ static int rounding_modes[4] = { FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARD #define C2 (1 << 10) #define C3 (1 << 14) +#define X87_TAG_VALID 0 +#define X87_TAG_ZERO 1 +#define X87_TAG_INVALID 2 +#define X87_TAG_EMPTY 3 + #define STATUS_ZERODIVIDE 4 +typedef union +{ + double d; + + struct { + uint64_t mantissa:52; + uint64_t exponent:11; + uint64_t negative:1; + }; +} double_decompose_t; + #if defined(_MSC_VER) && !defined(__clang__) # if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 # define X87_INLINE_ASM @@ -239,8 +256,6 @@ x87_fround(double b) return 0LL; } -#include "x87_ops_conv.h" - static __inline double x87_ld80(void) { @@ -466,6 +481,16 @@ typedef union { # define FP_TAG_VALID_N cpu_state.tag[(cpu_state.TOP + 1) & 7] &= ~TAG_UINT64 #endif +#include "softfloat/softfloat-specialize.h" + +#include "x87_ops_sf_arith.h" +#include "x87_ops_sf_compare.h" +#include "x87_ops_sf_const.h" +#include "x87_ops_sf_load_store.h" +#include "x87_ops_sf_misc.h" +#include "x87_ops_sf_trans.h" +#include "x87_ops_sf.h" + #include "x87_ops_arith.h" #include "x87_ops_misc.h" #include "x87_ops_loadstore.h" @@ -526,6 +551,264 @@ FPU_ILLEGAL_a32(uint32_t fetchdat) #define ILLEGAL_a16 FPU_ILLEGAL_a16 #ifdef FPU_8087 +const OpFn OP_TABLE(sf_fpu_8087_d8)[32] = { + // clang-format off + sf_FADDs_a16, sf_FMULs_a16, sf_FCOMs_a16, sf_FCOMPs_a16, sf_FSUBs_a16, sf_FSUBRs_a16, sf_FDIVs_a16, sf_FDIVRs_a16, + sf_FADDs_a16, sf_FMULs_a16, sf_FCOMs_a16, sf_FCOMPs_a16, sf_FSUBs_a16, sf_FSUBRs_a16, sf_FDIVs_a16, sf_FDIVRs_a16, + sf_FADDs_a16, sf_FMULs_a16, sf_FCOMs_a16, sf_FCOMPs_a16, sf_FSUBs_a16, sf_FSUBRs_a16, sf_FDIVs_a16, sf_FDIVRs_a16, + sf_FADD_st0_stj, sf_FMUL_st0_stj, sf_FCOM_sti, sf_FCOMP_sti, sf_FSUB_st0_stj, sf_FSUBR_st0_stj, sf_FDIV_st0_stj, sf_FDIVR_st0_stj, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_8087_d9)[256] = { + // clang-format off + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, /*Invalid*/ + sf_FCHS, sf_FABS, ILLEGAL_a16, ILLEGAL_a16, sf_FTST, sf_FXAM, ILLEGAL_a16, ILLEGAL_a16, + sf_FLD1, sf_FLDL2T, sf_FLDL2E, sf_FLDPI, sf_FLDEG2, sf_FLDLN2, sf_FLDZ, ILLEGAL_a16, + sf_F2XM1, sf_FYL2X, sf_FPTAN, sf_FPATAN, sf_FXTRACT, sf_FPREM1, sf_FDECSTP, sf_FINCSTP, + sf_FPREM, sf_FYL2XP1, sf_FSQRT, ILLEGAL_a16, sf_FRNDINT, sf_FSCALE, ILLEGAL_a16, ILLEGAL_a16 + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_8087_da)[256] = { + // clang-format off + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_8087_db)[256] = { + // clang-format off + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FI, sf_FI, sf_FNCLEX, sf_FNINIT, ILLEGAL_a16, sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_8087_dc)[32] = { + // clang-format off + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADD_sti_st0, sf_FMUL_sti_st0, ILLEGAL_a16, ILLEGAL_a16, sf_FSUBR_sti_st0, sf_FSUB_sti_st0, sf_FDIVR_sti_st0, sf_FDIV_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_8087_dd)[256] = { + // clang-format off + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_8087_de)[256] = { + // clang-format off + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, + sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, sf_FCOMPP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, + sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, + sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, + sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_8087_df)[256] = { + // clang-format off + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + const OpFn OP_TABLE(fpu_8087_d8)[32] = { // clang-format off opFADDs_a16, opFMULs_a16, opFCOMs_a16, opFCOMPs_a16, opFSUBs_a16, opFSUBRs_a16, opFDIVs_a16, opFDIVRs_a16, @@ -570,8 +853,8 @@ const OpFn OP_TABLE(fpu_8087_d9)[256] = { ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, /*Invalid*/ opFCHS, opFABS, ILLEGAL_a16, ILLEGAL_a16, opFTST, opFXAM, ILLEGAL_a16, ILLEGAL_a16, opFLD1, opFLDL2T, opFLDL2E, opFLDPI, opFLDEG2, opFLDLN2, opFLDZ, ILLEGAL_a16, - opF2XM1, opFYL2X, opFPTAN, opFPATAN, ILLEGAL_a16, ILLEGAL_a16, opFDECSTP, opFINCSTP, - opFPREM, opFYL2XP1, opFSQRT, ILLEGAL_a16, opFRNDINT, opFSCALE, ILLEGAL_a16, ILLEGAL_a16 + opF2XM1, opFYL2X, opFPTAN, opFPATAN, opFXTRACT, opFPREM1, opFDECSTP, opFINCSTP, + opFPREM, opFYL2XP1, opFSQRT, ILLEGAL_a16, opFRNDINT, opFSCALE, ILLEGAL_a16, ILLEGAL_a16 // clang-format on }; @@ -786,6 +1069,1260 @@ const OpFn OP_TABLE(fpu_8087_df)[256] = { #else # define ILLEGAL_a32 FPU_ILLEGAL_a32 + +const OpFn OP_TABLE(sf_fpu_d8_a16)[32] = { + // clang-format off + sf_FADDs_a16, sf_FMULs_a16, sf_FCOMs_a16, sf_FCOMPs_a16, sf_FSUBs_a16, sf_FSUBRs_a16, sf_FDIVs_a16, sf_FDIVRs_a16, + sf_FADDs_a16, sf_FMULs_a16, sf_FCOMs_a16, sf_FCOMPs_a16, sf_FSUBs_a16, sf_FSUBRs_a16, sf_FDIVs_a16, sf_FDIVRs_a16, + sf_FADDs_a16, sf_FMULs_a16, sf_FCOMs_a16, sf_FCOMPs_a16, sf_FSUBs_a16, sf_FSUBRs_a16, sf_FDIVs_a16, sf_FDIVRs_a16, + sf_FADD_st0_stj, sf_FMUL_st0_stj, sf_FCOM_sti, sf_FCOMP_sti, sf_FSUB_st0_stj, sf_FSUBR_st0_stj, sf_FDIV_st0_stj, sf_FDIVR_st0_stj, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_d8_a32)[32] = { + // clang-format off + sf_FADDs_a32, sf_FMULs_a32, sf_FCOMs_a32, sf_FCOMPs_a32, sf_FSUBs_a32, sf_FSUBRs_a32, sf_FDIVs_a32, sf_FDIVRs_a32, + sf_FADDs_a32, sf_FMULs_a32, sf_FCOMs_a32, sf_FCOMPs_a32, sf_FSUBs_a32, sf_FSUBRs_a32, sf_FDIVs_a32, sf_FDIVRs_a32, + sf_FADDs_a32, sf_FMULs_a32, sf_FCOMs_a32, sf_FCOMPs_a32, sf_FSUBs_a32, sf_FSUBRs_a32, sf_FDIVs_a32, sf_FDIVRs_a32, + sf_FADD_st0_stj, sf_FMUL_st0_stj, sf_FCOM_sti, sf_FCOMP_sti, sf_FSUB_st0_stj, sf_FSUBR_st0_stj, sf_FDIV_st0_stj, sf_FDIVR_st0_stj, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_d9_a16)[256] = { + // clang-format off + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, /*Invalid*/ + sf_FCHS, sf_FABS, ILLEGAL_a16, ILLEGAL_a16, sf_FTST, sf_FXAM, ILLEGAL_a16, ILLEGAL_a16, + sf_FLD1, sf_FLDL2T, sf_FLDL2E, sf_FLDPI, sf_FLDEG2, sf_FLDLN2, sf_FLDZ, ILLEGAL_a16, + sf_F2XM1, sf_FYL2X, sf_FPTAN, sf_FPATAN, sf_FXTRACT, sf_FPREM1, sf_FDECSTP, sf_FINCSTP, + sf_FPREM, sf_FYL2XP1, sf_FSQRT, sf_FSINCOS, sf_FRNDINT, sf_FSCALE, sf_FSIN, sf_FCOS, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_d9_a32)[256] = { + // clang-format off + sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, + sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, + sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, + sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, + sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, + sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, + + sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, + sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, + sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, + sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, + sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, + sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, + + sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, + sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, + sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, + sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, + sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, + sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, + + sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FNOP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, /*Invalid*/ + sf_FCHS, sf_FABS, ILLEGAL_a32, ILLEGAL_a32, sf_FTST, sf_FXAM, ILLEGAL_a32, ILLEGAL_a32, + sf_FLD1, sf_FLDL2T, sf_FLDL2E, sf_FLDPI, sf_FLDEG2, sf_FLDLN2, sf_FLDZ, ILLEGAL_a32, + sf_F2XM1, sf_FYL2X, sf_FPTAN, sf_FPATAN, sf_FXTRACT, sf_FPREM1, sf_FDECSTP, sf_FINCSTP, + sf_FPREM, sf_FYL2XP1, sf_FSQRT, sf_FSINCOS, sf_FRNDINT, sf_FSCALE, sf_FSIN, sf_FCOS, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_d9_a16)[256] = { + // clang-format off + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, /*Invalid*/ + sf_FCHS, sf_FABS, ILLEGAL_a16, ILLEGAL_a16, sf_FTST, sf_FXAM, ILLEGAL_a16, ILLEGAL_a16, + sf_FLD1, sf_FLDL2T, sf_FLDL2E, sf_FLDPI, sf_FLDEG2, sf_FLDLN2, sf_FLDZ, ILLEGAL_a16, + sf_F2XM1, sf_FYL2X, sf_FPTAN, sf_FPATAN, sf_FXTRACT, sf_FPREM1, sf_FDECSTP, sf_FINCSTP, + sf_FPREM, sf_FYL2XP1, sf_FSQRT, sf_FSINCOS, sf_FRNDINT, sf_FSCALE, sf_FSIN, sf_FCOS, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_d9_a32)[256] = { + // clang-format off + sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, + sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, + sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, + sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, + sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, + sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, + + sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, + sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, + sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, + sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, + sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, + sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, + + sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, sf_FLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, sf_FSTs_a32, + sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, sf_FSTPs_a32, + sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, sf_FLDENV_a32, + sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, sf_FLDCW_a32, + sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, sf_FNSTENV_a32, + sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, sf_FNSTCW_a32, + + sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FNOP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, /*Invalid*/ + sf_FCHS, sf_FABS, ILLEGAL_a32, ILLEGAL_a32, sf_FTST, sf_FXAM, ILLEGAL_a32, ILLEGAL_a32, + sf_FLD1, sf_FLDL2T, sf_FLDL2E, sf_FLDPI, sf_FLDEG2, sf_FLDLN2, sf_FLDZ, ILLEGAL_a32, + sf_F2XM1, sf_FYL2X, sf_FPTAN, sf_FPATAN, sf_FXTRACT, sf_FPREM1, sf_FDECSTP, sf_FINCSTP, + sf_FPREM, sf_FYL2XP1, sf_FSQRT, sf_FSINCOS, sf_FRNDINT, sf_FSCALE, sf_FSIN, sf_FCOS, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_da_a16)[256] = { + // clang-format off + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_da_a32)[256] = { + // clang-format off + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_da_a16)[256] = { + // clang-format off + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, sf_FUCOMPP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_da_a32)[256] = { + // clang-format off + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, sf_FUCOMPP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_686_da_a16)[256] = { + // clang-format off + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, sf_FADDil_a16, + sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, sf_FMULil_a16, + sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, sf_FCOMil_a16, + sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, sf_FCOMPil_a16, + sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, sf_FSUBil_a16, + sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, sf_FSUBRil_a16, + sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, sf_FDIVil_a16, + sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, sf_FDIVRil_a16, + + sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, + sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, + sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, + sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, sf_FUCOMPP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_686_da_a32)[256] = { + // clang-format off + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, sf_FADDil_a32, + sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, sf_FMULil_a32, + sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, sf_FCOMil_a32, + sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, sf_FCOMPil_a32, + sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, sf_FSUBil_a32, + sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, sf_FSUBRil_a32, + sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, sf_FDIVil_a32, + sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, sf_FDIVRil_a32, + + sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, sf_FCMOVB, + sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, sf_FCMOVE, + sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, sf_FCMOVBE, + sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, sf_FCMOVU, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, sf_FUCOMPP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_db_a16)[256] = { + // clang-format off + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNOP, sf_FNOP, sf_FNCLEX, sf_FNINIT, sf_FNOP, sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_db_a32)[256] = { + // clang-format off + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNOP, sf_FNOP, sf_FNCLEX, sf_FNINIT, sf_FNOP, sf_FNOP, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_db_a16)[256] = { + // clang-format off + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNOP, sf_FNOP, sf_FNCLEX, sf_FNINIT, sf_FNOP, sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_db_a32)[256] = { + // clang-format off + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNOP, sf_FNOP, sf_FNCLEX, sf_FNINIT, sf_FNOP, sf_FNOP, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_686_db_a16)[256] = { + // clang-format off + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, sf_FILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, sf_FISTil_a16, + sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, sf_FISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, sf_FLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, sf_FSTPe_a16, + + sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, + sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, + sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, + sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, + sf_FNOP, sf_FNOP, sf_FNCLEX, sf_FNINIT, sf_FNOP, sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, + sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, + sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; +const OpFn OP_TABLE(sf_fpu_686_db_a32)[256] = { + // clang-format off + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, sf_FILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, sf_FISTil_a32, + sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, sf_FISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, sf_FLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, sf_FSTPe_a32, + + sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, sf_FCMOVNB, + sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, sf_FCMOVNE, + sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, sf_FCMOVNBE, + sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, sf_FCMOVNU, + sf_FNOP, sf_FNOP, sf_FNCLEX, sf_FNINIT, sf_FNOP, sf_FNOP, ILLEGAL_a32, ILLEGAL_a32, + sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, sf_FUCOMI_st0_stj, + sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, sf_FCOMI_st0_stj, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_dc_a16)[32] = { + // clang-format off + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADD_sti_st0, sf_FMUL_sti_st0, ILLEGAL_a16, ILLEGAL_a16, sf_FSUBR_sti_st0, sf_FSUB_sti_st0, sf_FDIVR_sti_st0, sf_FDIV_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_dc_a32)[32] = { + // clang-format off + sf_FADDd_a32, sf_FMULd_a32, sf_FCOMd_a32, sf_FCOMPd_a32, sf_FSUBd_a32, sf_FSUBRd_a32, sf_FDIVd_a32, sf_FDIVRd_a32, + sf_FADDd_a32, sf_FMULd_a32, sf_FCOMd_a32, sf_FCOMPd_a32, sf_FSUBd_a32, sf_FSUBRd_a32, sf_FDIVd_a32, sf_FDIVRd_a32, + sf_FADDd_a32, sf_FMULd_a32, sf_FCOMd_a32, sf_FCOMPd_a32, sf_FSUBd_a32, sf_FSUBRd_a32, sf_FDIVd_a32, sf_FDIVRd_a32, + sf_FADD_sti_st0, sf_FMUL_sti_st0, ILLEGAL_a32, ILLEGAL_a32, sf_FSUBR_sti_st0, sf_FSUB_sti_st0, sf_FDIVR_sti_st0, sf_FDIV_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_dc_a16)[32] = { + // clang-format off + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADDd_a16, sf_FMULd_a16, sf_FCOMd_a16, sf_FCOMPd_a16, sf_FSUBd_a16, sf_FSUBRd_a16, sf_FDIVd_a16, sf_FDIVRd_a16, + sf_FADD_sti_st0, sf_FMUL_sti_st0, sf_FCOM_sti, sf_FCOMP_sti, sf_FSUBR_sti_st0, sf_FSUB_sti_st0, sf_FDIVR_sti_st0, sf_FDIV_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_dc_a32)[32] = { + // clang-format off + sf_FADDd_a32, sf_FMULd_a32, sf_FCOMd_a32, sf_FCOMPd_a32, sf_FSUBd_a32, sf_FSUBRd_a32, sf_FDIVd_a32, sf_FDIVRd_a32, + sf_FADDd_a32, sf_FMULd_a32, sf_FCOMd_a32, sf_FCOMPd_a32, sf_FSUBd_a32, sf_FSUBRd_a32, sf_FDIVd_a32, sf_FDIVRd_a32, + sf_FADDd_a32, sf_FMULd_a32, sf_FCOMd_a32, sf_FCOMPd_a32, sf_FSUBd_a32, sf_FSUBRd_a32, sf_FDIVd_a32, sf_FDIVRd_a32, + sf_FADD_sti_st0, sf_FMUL_sti_st0, sf_FCOM_sti, sf_FCOMP_sti, sf_FSUBR_sti_st0, sf_FSUB_sti_st0, sf_FDIVR_sti_st0, sf_FDIV_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_dd_a16)[256] = { + // clang-format off + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_dd_a32)[256] = { + // clang-format off + sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, + sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, + sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, + sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, + + sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, + sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, + sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, + sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, + + sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, + sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, + sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, + sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, + + sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_dd_a16)[256] = { + // clang-format off + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, + sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_dd_a32)[256] = { + // clang-format off + sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, + sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, + sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, + sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, + + sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, + sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, + sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, + sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, + + sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, sf_FLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, sf_FSTd_a32, + sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, sf_FSTPd_a32, + sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, sf_FRSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, sf_FNSAVE_a32, + sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, sf_FNSTSW_a32, + + sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, + sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_de_a16)[256] = { + // clang-format off + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, + sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, sf_FCOMPP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, + sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, + sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, + sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_de_a32)[256] = { + // clang-format off + sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, + sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, + sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, + sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, + sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, + sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, + sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, + sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, + + sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, + sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, + sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, + sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, + sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, + sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, + sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, + sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, + + sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, + sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, + sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, + sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, + sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, + sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, + sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, + sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, + + sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, + sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, sf_FCOMPP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, + sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, + sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, + sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_de_a16)[256] = { + // clang-format off + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, sf_FADDiw_a16, + sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, sf_FMULiw_a16, + sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, sf_FCOMiw_a16, + sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, sf_FCOMPiw_a16, + sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, sf_FSUBiw_a16, + sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, sf_FSUBRiw_a16, + sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, sf_FDIViw_a16, + sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, sf_FDIVRiw_a16, + + sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, + sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, + sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, + ILLEGAL_a16, sf_FCOMPP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, + sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, + sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, + sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_de_a32)[256] = { + // clang-format off + sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, + sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, + sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, + sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, + sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, + sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, + sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, + sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, + + sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, + sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, + sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, + sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, + sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, + sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, + sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, + sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, + + sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, sf_FADDiw_a32, + sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, sf_FMULiw_a32, + sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, sf_FCOMiw_a32, + sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, sf_FCOMPiw_a32, + sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, sf_FSUBiw_a32, + sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, sf_FSUBRiw_a32, + sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, sf_FDIViw_a32, + sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, sf_FDIVRiw_a32, + + sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, sf_FADDP_sti_st0, + sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, sf_FMULP_sti_st0, + sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, sf_FCOMP_sti, + ILLEGAL_a32, sf_FCOMPP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, sf_FSUBRP_sti_st0, + sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, sf_FSUBP_sti_st0, + sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, sf_FDIVRP_sti_st0, + sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, sf_FDIVP_sti_st0, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_df_a16)[256] = { + // clang-format off + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FNSTSW_AX, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_287_df_a32)[256] = { + // clang-format off + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FNSTSW_AX, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_df_a16)[256] = { + // clang-format off + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FNSTSW_AX, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_df_a32)[256] = { + // clang-format off + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FNSTSW_AX, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_686_df_a16)[256] = { + // clang-format off + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, sf_FILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, sf_FISTiw_a16, + sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, sf_FISTPiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, sf_FILDiq_a16, + sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, sf_FBSTP_PACKED_BCD_a16, + sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, sf_FISTPiq_a16, + + sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FNSTSW_AX, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, + sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_686_df_a32)[256] = { + // clang-format off + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, sf_FILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, sf_FISTiw_a32, + sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, sf_FISTPiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, sf_FILDiq_a32, + sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, sf_FBSTP_PACKED_BCD_a32, + sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, sf_FISTPiq_a32, + + sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, sf_FFREEP_sti, + sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + sf_FNSTSW_AX, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, sf_FUCOMIP_st0_stj, + sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, sf_FCOMIP_st0_stj, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + const OpFn OP_TABLE(fpu_d8_a16)[32] = { // clang-format off opFADDs_a16, opFMULs_a16, opFCOMs_a16, opFCOMPs_a16, opFSUBs_a16, opFSUBRs_a16, opFDIVs_a16, opFDIVRs_a16, @@ -839,7 +2376,7 @@ const OpFn OP_TABLE(fpu_287_d9_a16)[256] = { ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, /*Invalid*/ opFCHS, opFABS, ILLEGAL_a16, ILLEGAL_a16, opFTST, opFXAM, ILLEGAL_a16, ILLEGAL_a16, opFLD1, opFLDL2T, opFLDL2E, opFLDPI, opFLDEG2, opFLDLN2, opFLDZ, ILLEGAL_a16, - opF2XM1, opFYL2X, opFPTAN, opFPATAN, ILLEGAL_a16, opFPREM1, opFDECSTP, opFINCSTP, + opF2XM1, opFYL2X, opFPTAN, opFPATAN, opFXTRACT, opFPREM1, opFDECSTP, opFINCSTP, opFPREM, opFYL2XP1, opFSQRT, opFSINCOS, opFRNDINT, opFSCALE, opFSIN, opFCOS // clang-format on }; @@ -879,7 +2416,7 @@ const OpFn OP_TABLE(fpu_287_d9_a32)[256] = { ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, /*Invalid*/ opFCHS, opFABS, ILLEGAL_a32, ILLEGAL_a32, opFTST, opFXAM, ILLEGAL_a32, ILLEGAL_a32, opFLD1, opFLDL2T, opFLDL2E, opFLDPI, opFLDEG2, opFLDLN2, opFLDZ, ILLEGAL_a32, - opF2XM1, opFYL2X, opFPTAN, opFPATAN, ILLEGAL_a32, opFPREM1, opFDECSTP, opFINCSTP, + opF2XM1, opFYL2X, opFPTAN, opFPATAN, opFXTRACT, opFPREM1, opFDECSTP, opFINCSTP, opFPREM, opFYL2XP1, opFSQRT, opFSINCOS, opFRNDINT, opFSCALE, opFSIN, opFCOS // clang-format on }; @@ -919,7 +2456,7 @@ const OpFn OP_TABLE(fpu_d9_a16)[256] = { opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, /*Invalid*/ opFCHS, opFABS, ILLEGAL_a16, ILLEGAL_a16, opFTST, opFXAM, ILLEGAL_a16, ILLEGAL_a16, opFLD1, opFLDL2T, opFLDL2E, opFLDPI, opFLDEG2, opFLDLN2, opFLDZ, ILLEGAL_a16, - opF2XM1, opFYL2X, opFPTAN, opFPATAN, ILLEGAL_a16, opFPREM1, opFDECSTP, opFINCSTP, + opF2XM1, opFYL2X, opFPTAN, opFPATAN, opFXTRACT, opFPREM1, opFDECSTP, opFINCSTP, opFPREM, opFYL2XP1, opFSQRT, opFSINCOS, opFRNDINT, opFSCALE, opFSIN, opFCOS // clang-format on }; @@ -959,7 +2496,7 @@ const OpFn OP_TABLE(fpu_d9_a32)[256] = { opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, /*Invalid*/ opFCHS, opFABS, ILLEGAL_a32, ILLEGAL_a32, opFTST, opFXAM, ILLEGAL_a32, ILLEGAL_a32, opFLD1, opFLDL2T, opFLDL2E, opFLDPI, opFLDEG2, opFLDLN2, opFLDZ, ILLEGAL_a32, - opF2XM1, opFYL2X, opFPTAN, opFPATAN, ILLEGAL_a32, opFPREM1, opFDECSTP, opFINCSTP, + opF2XM1, opFYL2X, opFPTAN, opFPATAN, opFXTRACT, opFPREM1, opFDECSTP, opFINCSTP, opFPREM, opFYL2XP1, opFSQRT, opFSINCOS, opFRNDINT, opFSCALE, opFSIN, opFCOS // clang-format on }; diff --git a/src/cpu/x87_ops_misc.h b/src/cpu/x87_ops_misc.h index 091d7cc31..bd2b05c52 100644 --- a/src/cpu/x87_ops_misc.h +++ b/src/cpu/x87_ops_misc.h @@ -33,6 +33,27 @@ opFNOP(uint32_t fetchdat) return 0; } +static int +opFXTRACT(uint32_t fetchdat) +{ + x87_conv_t test; + int64_t exp80, exp80final; + double mant; + + FP_ENTER(); + cpu_state.pc++; + test.eind.d = ST(0); + exp80 = test.eind.ll & (0x7ff0000000000000ll); + exp80final = (exp80 >> 52) - BIAS64; + mant = test.eind.d / (pow(2.0, (double)exp80final)); + ST(0) = (double)exp80final; + FP_TAG_VALID; + x87_push(mant); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fxtract) : (x87_timings.fxtract * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fxtract) : (x87_concurrency.fxtract * cpu_multi)); + return 0; +} + static int opFCLEX(uint32_t fetchdat) { @@ -741,7 +762,7 @@ opFPREM(uint32_t fetchdat) CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fprem) : (x87_concurrency.fprem * cpu_multi)); return 0; } -#ifndef FPU_8087 + static int opFPREM1(uint32_t fetchdat) { @@ -762,7 +783,6 @@ opFPREM1(uint32_t fetchdat) CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fprem1) : (x87_concurrency.fprem1 * cpu_multi)); return 0; } -#endif static int opFSQRT(uint32_t fetchdat) diff --git a/src/cpu/x87_ops_sf.h b/src/cpu/x87_ops_sf.h new file mode 100644 index 000000000..e70556fea --- /dev/null +++ b/src/cpu/x87_ops_sf.h @@ -0,0 +1,593 @@ +static uint32_t +fpu_save_environment(void) +{ + int tag; + unsigned offset = 0; + + /* read all registers in stack order and update x87 tag word */ + for (int n = 0; n < 8; n++) { + // update tag only if it is not empty + if (!IS_TAG_EMPTY(n)) { + tag = FPU_tagof(FPU_read_regi(n)); + FPU_settagi(tag, n); + } + } + + fpu_state.swd = (fpu_state.swd & ~(7 << 11)) | ((fpu_state.tos & 7) << 11); + + switch ((cr0 & 1) | (cpu_state.op32 & 0x100)) { + case 0x000: { /*16-bit real mode*/ + uint16_t tmp; + uint32_t fp_ip, fp_dp; + + fp_ip = ((uint32_t)(fpu_state.fcs << 4)) | fpu_state.fip; + fp_dp = ((uint32_t)(fpu_state.fds << 4)) | fpu_state.fdp; + + tmp = i387_get_control_word(); + writememw(easeg, cpu_state.eaaddr + 0x00, tmp); + tmp = i387_get_status_word(); + writememw(easeg, cpu_state.eaaddr + 0x02, tmp); + tmp = fpu_state.tag; + writememw(easeg, cpu_state.eaaddr + 0x04, tmp); + tmp = fp_ip & 0xffff; + writememw(easeg, cpu_state.eaaddr + 0x06, tmp); + tmp = (uint16_t)((fp_ip & 0xf0000) >> 4) | fpu_state.foo; + writememw(easeg, cpu_state.eaaddr + 0x08, tmp); + tmp = fp_dp & 0xffff; + writememw(easeg, cpu_state.eaaddr + 0x0a, tmp); + tmp = (uint16_t)((fp_dp & 0xf0000) >> 4); + writememw(easeg, cpu_state.eaaddr + 0x0c, tmp); + offset = 0x0e; + } + break; + case 0x001: {/*16-bit protected mode*/ + uint16_t tmp; + tmp = i387_get_control_word(); + writememw(easeg, cpu_state.eaaddr + 0x00, tmp); + tmp = i387_get_status_word(); + writememw(easeg, cpu_state.eaaddr + 0x02, tmp); + tmp = fpu_state.tag; + writememw(easeg, cpu_state.eaaddr + 0x04, tmp); + tmp = (uint16_t)(fpu_state.fip) & 0xffff; + writememw(easeg, cpu_state.eaaddr + 0x06, tmp); + tmp = fpu_state.fcs; + writememw(easeg, cpu_state.eaaddr + 0x08, tmp); + tmp = (uint16_t)(fpu_state.fdp) & 0xffff; + writememw(easeg, cpu_state.eaaddr + 0x0a, tmp); + tmp = fpu_state.fds; + writememw(easeg, cpu_state.eaaddr + 0x0c, tmp); + offset = 0x0e; + } + break; + case 0x100: { /*32-bit real mode*/ + uint32_t tmp, fp_ip, fp_dp; + + fp_ip = ((uint32_t)(fpu_state.fcs << 4)) | fpu_state.fip; + fp_dp = ((uint32_t)(fpu_state.fds << 4)) | fpu_state.fdp; + + tmp = 0xffff0000 | i387_get_control_word(); + writememl(easeg, cpu_state.eaaddr + 0x00, tmp); + tmp = 0xffff0000 | i387_get_status_word(); + writememl(easeg, cpu_state.eaaddr + 0x04, tmp); + tmp = 0xffff0000 | fpu_state.tag; + writememl(easeg, cpu_state.eaaddr + 0x08, tmp); + tmp = 0xffff0000 | (fp_ip & 0xffff); + writememl(easeg, cpu_state.eaaddr + 0x0c, tmp); + tmp = ((fp_ip & 0xffff0000) >> 4) | fpu_state.foo; + writememl(easeg, cpu_state.eaaddr + 0x10, tmp); + tmp = 0xffff0000 | (fp_dp & 0xffff); + writememl(easeg, cpu_state.eaaddr + 0x14, tmp); + tmp = (fp_dp & 0xffff0000) >> 4; + writememl(easeg, cpu_state.eaaddr + 0x18, tmp); + offset = 0x1c; + } + break; + case 0x101: { /*32-bit protected mode*/ + uint32_t tmp; + tmp = 0xffff0000 | i387_get_control_word(); + writememl(easeg, cpu_state.eaaddr + 0x00, tmp); + tmp = 0xffff0000 | i387_get_status_word(); + writememl(easeg, cpu_state.eaaddr + 0x04, tmp); + tmp = 0xffff0000 | fpu_state.tag; + writememl(easeg, cpu_state.eaaddr + 0x08, tmp); + tmp = (uint32_t)(fpu_state.fip); + writememl(easeg, cpu_state.eaaddr + 0x0c, tmp); + tmp = fpu_state.fcs | (((uint32_t)(fpu_state.foo)) << 16); + writememl(easeg, cpu_state.eaaddr + 0x10, tmp); + tmp = (uint32_t)(fpu_state.fdp); + writememl(easeg, cpu_state.eaaddr + 0x14, tmp); + tmp = 0xffff0000 | fpu_state.fds; + writememl(easeg, cpu_state.eaaddr + 0x18, tmp); + offset = 0x1c; + } + break; + } + + return (cpu_state.eaaddr + offset); +} + +static uint32_t +fpu_load_environment(void) +{ + unsigned offset = 0; + + switch ((cr0 & 1) | (cpu_state.op32 & 0x100)) { + case 0x000: { /*16-bit real mode*/ + uint16_t tmp; + uint32_t fp_ip, fp_dp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x0c); + fp_dp = (tmp & 0xf000) << 4; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x0a); + fpu_state.fdp = fp_dp | tmp; + fpu_state.fds = 0; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x08); + fp_ip = (tmp & 0xf000) << 4; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x06); + fpu_state.fip = fp_ip | tmp; + fpu_state.fcs = 0; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x04); + fpu_state.tag = tmp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x02); + fpu_state.swd = tmp; + fpu_state.tos = (tmp >> 11) & 7; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x00); + fpu_state.cwd = tmp; + offset = 0x0e; + } + break; + case 0x001: {/*16-bit protected mode*/ + uint16_t tmp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x0c); + fpu_state.fds = tmp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x0a); + fpu_state.fdp = tmp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x08); + fpu_state.fcs = tmp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x06); + fpu_state.fip = tmp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x04); + fpu_state.tag = tmp; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x02); + fpu_state.swd = tmp; + fpu_state.tos = (tmp >> 11) & 7; + tmp = readmemw(easeg, cpu_state.eaaddr + 0x00); + fpu_state.cwd = tmp; + offset = 0x0e; + } + break; + case 0x100: { /*32-bit real mode*/ + uint32_t tmp, fp_ip, fp_dp; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x18); + fp_dp = (tmp & 0x0ffff000) << 4; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x14); + fp_dp |= (tmp & 0xffff); + fpu_state.fdp = fp_dp; + fpu_state.fds = 0; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x10); + fpu_state.foo = tmp & 0x07ff; + fp_ip = (tmp & 0x0ffff000) << 4; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x0c); + fp_ip |= (tmp & 0xffff); + fpu_state.fip = fp_ip; + fpu_state.fcs = 0; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x08); + fpu_state.tag = tmp & 0xffff; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x04); + fpu_state.swd = tmp & 0xffff; + fpu_state.tos = (tmp >> 11) & 7; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x00); + fpu_state.cwd = tmp & 0xffff; + offset = 0x1c; + } + break; + case 0x101: { /*32-bit protected mode*/ + uint32_t tmp; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x18); + fpu_state.fds = tmp & 0xffff; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x14); + fpu_state.fdp = tmp; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x10); + fpu_state.fcs = tmp & 0xffff; + fpu_state.foo = (tmp >> 16) & 0x07ff; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x0c); + fpu_state.fip = tmp; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x08); + fpu_state.tag = tmp & 0xffff; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x04); + fpu_state.swd = tmp & 0xffff; + fpu_state.tos = (tmp >> 11) & 7; + tmp = readmeml(easeg, cpu_state.eaaddr + 0x00); + fpu_state.cwd = tmp & 0xffff; + offset = 0x1c; + } + break; + } + + /* always set bit 6 as '1 */ + fpu_state.cwd = (fpu_state.cwd & ~FPU_CW_Reserved_Bits) | 0x0040; + + /* check for unmasked exceptions */ + if (fpu_state.swd & ~fpu_state.cwd & FPU_CW_Exceptions_Mask) { + /* set the B and ES bits in the status-word */ + fpu_state.swd |= (FPU_SW_Summary | FPU_SW_Backward); + } else { + /* clear the B and ES bits in the status-word */ + fpu_state.swd &= ~(FPU_SW_Summary | FPU_SW_Backward); + } + + return (cpu_state.eaaddr + offset); +} + +static int +sf_FLDCW_a16(uint32_t fetchdat) +{ + uint16_t tempw; + + FP_ENTER(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + tempw = geteaw(); + if (cpu_state.abrt) + return 1; + fpu_state.cwd = (tempw & ~FPU_CW_Reserved_Bits) | 0x0040; // bit 6 is reserved as '1 + /* check for unmasked exceptions */ + if (fpu_state.swd & (~fpu_state.cwd & FPU_CW_Exceptions_Mask)) { + /* set the B and ES bits in the status-word */ + fpu_state.swd |= (FPU_SW_Summary | FPU_SW_Backward); + } else { + /* clear the B and ES bits in the status-word */ + fpu_state.swd &= ~(FPU_SW_Summary | FPU_SW_Backward); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fldcw) : (x87_timings.fldcw * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fldcw) : (x87_concurrency.fldcw * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FLDCW_a32(uint32_t fetchdat) +{ + uint16_t tempw; + + FP_ENTER(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + tempw = geteaw(); + if (cpu_state.abrt) + return 1; + fpu_state.cwd = (tempw & ~FPU_CW_Reserved_Bits) | 0x0040; // bit 6 is reserved as '1 + /* check for unmasked exceptions */ + if (fpu_state.swd & (~fpu_state.cwd & FPU_CW_Exceptions_Mask)) { + /* set the B and ES bits in the status-word */ + fpu_state.swd |= (FPU_SW_Summary | FPU_SW_Backward); + } else { + /* clear the B and ES bits in the status-word */ + fpu_state.swd &= ~(FPU_SW_Summary | FPU_SW_Backward); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fldcw) : (x87_timings.fldcw * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fldcw) : (x87_concurrency.fldcw * cpu_multi)); + return 0; +} +#endif + +static int +sf_FNSTCW_a16(uint32_t fetchdat) +{ + uint16_t cwd = i387_get_control_word(); + + FP_ENTER(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + seteaw(cwd); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fstcw_sw) : (x87_timings.fstcw_sw * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fstenv) : (x87_concurrency.fstenv * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FNSTCW_a32(uint32_t fetchdat) +{ + uint16_t cwd = i387_get_control_word(); + + FP_ENTER(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + seteaw(cwd); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fstcw_sw) : (x87_timings.fstcw_sw * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fstcw_sw) : (x87_concurrency.fstcw_sw * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FNSTSW_a16(uint32_t fetchdat) +{ + uint16_t swd = i387_get_status_word(); + + FP_ENTER(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + seteaw(swd); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fstcw_sw) : (x87_timings.fstcw_sw * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fstcw_sw) : (x87_concurrency.fstcw_sw * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FNSTSW_a32(uint32_t fetchdat) +{ + uint16_t swd = i387_get_status_word(); + + FP_ENTER(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + seteaw(swd); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fstcw_sw) : (x87_timings.fstcw_sw * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fstcw_sw) : (x87_concurrency.fstcw_sw * cpu_multi)); + return cpu_state.abrt; +} +#endif + +#ifdef FPU_8087 +static int +sf_FI(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + fpu_state.cwd &= ~FPU_SW_Summary; + if (rmdat == 0xe1) + fpu_state.cwd |= FPU_SW_Summary; + wait(3, 0); + return 0; +} +#else +static int +sf_FNSTSW_AX(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + AX = i387_get_status_word(); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fstcw_sw) : (x87_timings.fstcw_sw * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fstcw_sw) : (x87_concurrency.fstcw_sw * cpu_multi)); + return 0; +} +#endif + +static int +sf_FRSTOR_a16(uint32_t fetchdat) +{ + floatx80 tmp; + int offset; + + FP_ENTER(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + offset = fpu_load_environment(); + for (int n = 0; n < 8; n++) { + tmp.fraction = readmemq(easeg, offset + (n * 10)); + tmp.exp = readmemw(easeg, offset + (n * 10) + 8); + FPU_save_regi_tag(tmp, IS_TAG_EMPTY(n) ? X87_TAG_EMPTY : FPU_tagof(tmp), n); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.frstor) : (x87_timings.frstor * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.frstor) : (x87_concurrency.frstor * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FRSTOR_a32(uint32_t fetchdat) +{ + floatx80 tmp; + int offset; + + FP_ENTER(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + offset = fpu_load_environment(); + for (int n = 0; n < 8; n++) { + tmp.fraction = readmemq(easeg, offset + (n * 10)); + tmp.exp = readmemw(easeg, offset + (n * 10) + 8); + FPU_save_regi_tag(tmp, IS_TAG_EMPTY(n) ? X87_TAG_EMPTY : FPU_tagof(tmp), n); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.frstor) : (x87_timings.frstor * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.frstor) : (x87_concurrency.frstor * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FNSAVE_a16(uint32_t fetchdat) +{ + floatx80 stn; + int offset; + + FP_ENTER(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + offset = fpu_save_environment(); + /* save all registers in stack order. */ + for (int m = 0; m < 8; m++) { + stn = FPU_read_regi(m); + writememq(easeg, offset + (m * 10), stn.fraction); + writememw(easeg, offset + (m * 10) + 8, stn.exp); + } + +#ifdef FPU_8087 + fpu_state.swd = 0x3FF; +#else + fpu_state.cwd = 0x37F; +#endif + fpu_state.swd = 0; + fpu_state.tos = 0; + fpu_state.tag = 0xffff; + cpu_state.ismmx = 0; + fpu_state.foo = 0; + fpu_state.fds = 0; + fpu_state.fdp = 0; + fpu_state.fcs = 0; + fpu_state.fip = 0; + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fsave) : (x87_timings.fsave * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fsave) : (x87_concurrency.fsave * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FNSAVE_a32(uint32_t fetchdat) +{ + floatx80 stn; + int offset; + + FP_ENTER(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + offset = fpu_save_environment(); + /* save all registers in stack order. */ + for (int m = 0; m < 8; m++) { + stn = FPU_read_regi(m); + writememq(easeg, offset + (m * 10), stn.fraction); + writememw(easeg, offset + (m * 10) + 8, stn.exp); + } + +#ifdef FPU_8087 + fpu_state.swd = 0x3FF; +#else + fpu_state.cwd = 0x37F; +#endif + fpu_state.swd = 0; + fpu_state.tos = 0; + fpu_state.tag = 0xffff; + cpu_state.ismmx = 0; + fpu_state.foo = 0; + fpu_state.fds = 0; + fpu_state.fdp = 0; + fpu_state.fcs = 0; + fpu_state.fip = 0; + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fsave) : (x87_timings.fsave * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fsave) : (x87_concurrency.fsave * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FNCLEX(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + fpu_state.swd &= ~(FPU_SW_Backward | FPU_SW_Summary | FPU_SW_Stack_Fault | FPU_SW_Precision | + FPU_SW_Underflow | FPU_SW_Overflow | FPU_SW_Zero_Div | FPU_SW_Denormal_Op | + FPU_SW_Invalid); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fnop) : (x87_timings.fnop * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fnop) : (x87_concurrency.fnop * cpu_multi)); + return 0; +} + +static int +sf_FNINIT(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; +#ifdef FPU_8087 + fpu_state.cwd = 0x3FF; +#else + fpu_state.cwd = 0x37F; +#endif + fpu_state.swd = 0; + fpu_state.tos = 0; + fpu_state.tag = 0xffff; + fpu_state.foo = 0; + fpu_state.fds = 0; + fpu_state.fdp = 0; + fpu_state.fcs = 0; + fpu_state.fip = 0; + cpu_state.ismmx = 0; + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.finit) : (x87_timings.finit * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.finit) : (x87_concurrency.finit * cpu_multi)); + CPU_BLOCK_END(); + return 0; +} + +static int +sf_FLDENV_a16(uint32_t fetchdat) +{ + int tag; + + FP_ENTER(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + fpu_load_environment(); + /* read all registers in stack order and update x87 tag word */ + for (int n = 0; n < 8; n++) { + // update tag only if it is not empty + if (!IS_TAG_EMPTY(n)) { + tag = FPU_tagof(FPU_read_regi(n)); + FPU_settagi(tag, n); + } + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fldenv) : (x87_timings.fldenv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fldenv) : (x87_concurrency.fldenv * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FLDENV_a32(uint32_t fetchdat) +{ + int tag; + + FP_ENTER(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + fpu_load_environment(); + /* read all registers in stack order and update x87 tag word */ + for (int n = 0; n < 8; n++) { + // update tag only if it is not empty + if (!IS_TAG_EMPTY(n)) { + tag = FPU_tagof(FPU_read_regi(n)); + FPU_settagi(tag, n); + } + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fldenv) : (x87_timings.fldenv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fldenv) : (x87_concurrency.fldenv * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FNSTENV_a16(uint32_t fetchdat) +{ + FP_ENTER(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + fpu_save_environment(); + /* mask all floating point exceptions */ + fpu_state.cwd |= FPU_CW_Exceptions_Mask; + /* clear the B and ES bits in the status word */ + fpu_state.swd &= ~(FPU_SW_Backward|FPU_SW_Summary); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fstenv) : (x87_timings.fstenv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fstenv) : (x87_concurrency.fstenv * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FNSTENV_a32(uint32_t fetchdat) +{ + FP_ENTER(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + fpu_save_environment(); + /* mask all floating point exceptions */ + fpu_state.cwd |= FPU_CW_Exceptions_Mask; + /* clear the B and ES bits in the status word */ + fpu_state.swd &= ~(FPU_SW_Backward|FPU_SW_Summary); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fstenv) : (x87_timings.fstenv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fstenv) : (x87_concurrency.fstenv * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FNOP(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fnop) : (x87_timings.fnop * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fnop) : (x87_concurrency.fnop * cpu_multi)); + return 0; +} diff --git a/src/cpu/x87_ops_sf_arith.h b/src/cpu/x87_ops_sf_arith.h new file mode 100644 index 000000000..10b100b2a --- /dev/null +++ b/src/cpu/x87_ops_sf_arith.h @@ -0,0 +1,750 @@ +#define sf_FPU(name, optype, a_size, load_var, rw, use_var, is_nan, cycle_postfix) \ + static int sf_FADD##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a, result; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + FPU_check_pending_exceptions(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_stack_underflow(fetchdat, 0, 0); \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (!is_nan) \ + result = floatx80_add(a, use_var, &status); \ + \ + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) \ + FPU_save_regi(result, 0); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd##cycle_postfix) : ((x87_timings.fadd##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ + return 0; \ + } \ + static int sf_FDIV##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a, result; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + FPU_check_pending_exceptions(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_stack_underflow(fetchdat, 0, 0); \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (!is_nan) { \ + result = floatx80_div(a, use_var, &status); \ + } \ + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) \ + FPU_save_regi(result, 0); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv##cycle_postfix) : ((x87_timings.fdiv##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ + return 0; \ + } \ + static int sf_FDIVR##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a, result; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + FPU_check_pending_exceptions(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_stack_underflow(fetchdat, 0, 0); \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (!is_nan) { \ + result = floatx80_div(use_var, a, &status); \ + } \ + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) \ + FPU_save_regi(result, 0); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv##cycle_postfix) : ((x87_timings.fdiv##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv##cycle_postfix) : ((x87_concurrency.fdiv##cycle_postfix) * cpu_multi)); \ + return 0; \ + } \ + static int sf_FMUL##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a, result; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + FPU_check_pending_exceptions(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_stack_underflow(fetchdat, 0, 0); \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (!is_nan) { \ + result = floatx80_mul(a, use_var, &status); \ + } \ + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) \ + FPU_save_regi(result, 0); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fmul##cycle_postfix) : ((x87_timings.fmul##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fmul##cycle_postfix) : ((x87_concurrency.fmul##cycle_postfix) * cpu_multi)); \ + return 0; \ + } \ + static int sf_FSUB##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a, result; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + FPU_check_pending_exceptions(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_stack_underflow(fetchdat, 0, 0); \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (!is_nan) \ + result = floatx80_sub(a, use_var, &status); \ + \ + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) \ + FPU_save_regi(result, 0); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd##cycle_postfix) : ((x87_timings.fadd##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ + return 0; \ + } \ + static int sf_FSUBR##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a, result; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + FPU_check_pending_exceptions(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_stack_underflow(fetchdat, 0, 0); \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (!is_nan) \ + result = floatx80_sub(use_var, a, &status); \ + \ + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) \ + FPU_save_regi(result, 0); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd##cycle_postfix) : ((x87_timings.fadd##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ + return 0; \ + } + +// clang-format off +sf_FPU(s, float32, 16, temp, geteal(), float32_to_floatx80(temp, &status), FPU_handle_NaN32(a, temp, &result, &status), _32) +#ifndef FPU_8087 +sf_FPU(s, float32, 32, temp, geteal(), float32_to_floatx80(temp, &status), FPU_handle_NaN32(a, temp, &result, &status), _32) +#endif +sf_FPU(d, float64, 16, temp, geteaq(), float64_to_floatx80(temp, &status), FPU_handle_NaN64(a, temp, &result, &status), _64) +#ifndef FPU_8087 +sf_FPU(d, float64, 32, temp, geteaq(), float64_to_floatx80(temp, &status), FPU_handle_NaN64(a, temp, &result, &status), _64) +#endif + +sf_FPU(iw, uint16_t, 16, temp, geteaw(), int32_to_floatx80((int16_t)temp), 0, _i16) +#ifndef FPU_8087 +sf_FPU(iw, uint16_t, 32, temp, geteaw(), int32_to_floatx80((int16_t)temp), 0, _i16) +#endif +sf_FPU(il, uint32_t, 16, temp, geteal(), int32_to_floatx80((int32_t)temp), 0, _i32) +#ifndef FPU_8087 +sf_FPU(il, uint32_t, 32, temp, geteal(), int32_to_floatx80((int32_t)temp), 0, _i32) +#endif +// clang-format on + +static int +sf_FADD_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_add(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} +static int +sf_FADD_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_add(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, fetchdat & 7); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} + +static int +sf_FADDP_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_add(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} + +static int +sf_FDIV_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_div(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv) : (x87_timings.fdiv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv) : (x87_concurrency.fdiv * cpu_multi)); + return 0; +} + +static int +sf_FDIV_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_div(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, fetchdat & 7); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv) : (x87_timings.fdiv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv) : (x87_concurrency.fdiv * cpu_multi)); + return 0; +} +static int +sf_FDIVP_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_div(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv) : (x87_timings.fdiv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv) : (x87_concurrency.fdiv * cpu_multi)); + return 0; +} + +static int +sf_FDIVR_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_div(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv) : (x87_timings.fdiv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv) : (x87_concurrency.fdiv * cpu_multi)); + return 0; +} +static int +sf_FDIVR_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_div(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, fetchdat & 7); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv) : (x87_timings.fdiv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv) : (x87_concurrency.fdiv * cpu_multi)); + return 0; +} +static int +sf_FDIVRP_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_div(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fdiv) : (x87_timings.fdiv * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv) : (x87_concurrency.fdiv * cpu_multi)); + return 0; +} + +static int +sf_FMUL_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_mul(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fmul) : (x87_timings.fmul * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fmul) : (x87_concurrency.fmul * cpu_multi)); + return 0; +} +static int +sf_FMUL_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_mul(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fmul) : (x87_timings.fmul * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fmul) : (x87_concurrency.fmul * cpu_multi)); + return 0; +} +static int +sf_FMULP_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_mul(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fmul) : (x87_timings.fmul * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fmul) : (x87_concurrency.fmul * cpu_multi)); + return 0; +} + +static int +sf_FSUB_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_sub(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} +static int +sf_FSUB_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_sub(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} +static int +sf_FSUBP_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_sub(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} + +static int +sf_FSUBR_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(fetchdat & 7); + b = FPU_read_regi(0); + result = floatx80_sub(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} +static int +sf_FSUBR_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_sub(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} +static int +sf_FSUBRP_sti_st0(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + result = floatx80_sub(a, b, &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, fetchdat & 7); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fadd) : (x87_timings.fadd * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd) : (x87_concurrency.fadd * cpu_multi)); + return 0; +} + +static int +sf_FSQRT(uint32_t fetchdat) +{ + floatx80 result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + result = floatx80_sqrt(FPU_read_regi(0), &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fsqrt) : (x87_timings.fsqrt * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fsqrt) : (x87_concurrency.fsqrt * cpu_multi)); + return 0; +} + +static int +sf_FRNDINT(uint32_t fetchdat) +{ + floatx80 result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + result = floatx80_round_to_int(FPU_read_regi(0), &status); + + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.frndint) : (x87_timings.frndint * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.frndint) : (x87_concurrency.frndint * cpu_multi)); + return 0; +} diff --git a/src/cpu/x87_ops_sf_compare.h b/src/cpu/x87_ops_sf_compare.h new file mode 100644 index 000000000..59135c05b --- /dev/null +++ b/src/cpu/x87_ops_sf_compare.h @@ -0,0 +1,489 @@ +#define cmp_FPU(name, optype, a_size, load_var, rw, use_var, is_nan, cycle_postfix) \ + static int sf_FCOM##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a; \ + int rc; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); \ + setcc(C0 | C2 | C3); \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (is_nan) { \ + rc = float_relation_unordered; \ + float_raise(&status, float_flag_invalid); \ + } else { \ + rc = floatx80_compare_two(a, use_var, &status); \ + } \ + setcc(FPU_status_word_flags_fpu_compare(rc)); \ + FPU_exception(fetchdat, status.float_exception_flags, 0); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom##cycle_postfix) : ((x87_timings.fcom##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom##cycle_postfix) : ((x87_concurrency.fcom##cycle_postfix) * cpu_multi)); \ + return 0; \ + } \ + static int sf_FCOMP##name##_a##a_size(uint32_t fetchdat) \ + { \ + floatx80 a; \ + int rc; \ + struct float_status_t status; \ + optype temp; \ + FP_ENTER(); \ + fetch_ea_##a_size(fetchdat); \ + SEG_CHECK_READ(cpu_state.ea_seg); \ + load_var = rw; \ + if (cpu_state.abrt) \ + return 1;\ + clear_C1(); \ + if (IS_TAG_EMPTY(0)) { \ + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); \ + setcc(C0 | C2 | C3); \ + if (is_IA_masked()) \ + FPU_pop(); \ + \ + goto next_ins; \ + } \ + status = i387cw_to_softfloat_status_word(i387_get_control_word()); \ + a = FPU_read_regi(0); \ + if (is_nan) { \ + rc = float_relation_unordered; \ + float_raise(&status, float_flag_invalid); \ + } else { \ + rc = floatx80_compare_two(a, use_var, &status); \ + } \ + setcc(FPU_status_word_flags_fpu_compare(rc)); \ + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) \ + FPU_pop(); \ + \ +next_ins: \ + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom##cycle_postfix) : ((x87_timings.fcom##cycle_postfix) * cpu_multi)); \ + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom##cycle_postfix) : ((x87_concurrency.fcom##cycle_postfix) * cpu_multi)); \ + return 0; \ + } \ + +// clang-format off +cmp_FPU(s, float32, 16, temp, geteal(), float32_to_floatx80(temp, &status), floatx80_is_nan(a) || floatx80_is_unsupported(a) || float32_is_nan(temp), _32) +#ifndef FPU_8087 +cmp_FPU(s, float32, 32, temp, geteal(), float32_to_floatx80(temp, &status), floatx80_is_nan(a) || floatx80_is_unsupported(a) || float32_is_nan(temp), _32) +#endif +cmp_FPU(d, float64, 16, temp, geteaq(), float64_to_floatx80(temp, &status), floatx80_is_nan(a) || floatx80_is_unsupported(a) || float64_is_nan(temp), _64) +#ifndef FPU_8087 +cmp_FPU(d, float64, 32, temp, geteaq(), float64_to_floatx80(temp, &status), floatx80_is_nan(a) || floatx80_is_unsupported(a) || float64_is_nan(temp), _64) +#endif + +cmp_FPU(iw, int16_t, 16, temp, (int16_t)geteaw(), int32_to_floatx80((int32_t)temp), 0, _i16) +#ifndef FPU_8087 +cmp_FPU(iw, int16_t, 32, temp, (int16_t)geteaw(), int32_to_floatx80((int32_t)temp), 0, _i16) +#endif +cmp_FPU(il, int32_t, 16, temp, (int32_t)geteal(), int32_to_floatx80(temp), 0, _i32) +#ifndef FPU_8087 +cmp_FPU(il, int32_t, 32, temp, (int32_t)geteal(), int32_to_floatx80(temp), 0, _i32) +#endif +// clang-format on + +static int +sf_FCOM_sti(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(C0 | C2 | C3); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_two(a, b, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + FPU_exception(fetchdat, status.float_exception_flags, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom) : (x87_timings.fcom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom) : (x87_concurrency.fcom * cpu_multi)); + return 0; +} + +static int +sf_FCOMP_sti(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(C0 | C2 | C3); + if (is_IA_masked()) { + FPU_pop(); + } + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_two(a, b, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom) : (x87_timings.fcom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom) : (x87_concurrency.fcom * cpu_multi)); + return 0; +} + +static int +sf_FCOMPP(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(C0 | C2 | C3); + if (is_IA_masked()) { + FPU_pop(); + FPU_pop(); + } + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(1); + rc = floatx80_compare_two(a, b, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_pop(); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom) : (x87_timings.fcom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom) : (x87_concurrency.fcom * cpu_multi)); + return 0; +} + +#ifndef FPU_8087 +static int +sf_FUCOMPP(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(C0 | C2 | C3); + if (is_IA_masked()) { + FPU_pop(); + FPU_pop(); + } + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(1); + rc = floatx80_compare_quiet(a, b, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_pop(); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fucom) : (x87_timings.fucom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fucom) : (x87_concurrency.fucom * cpu_multi)); + return 0; +} + +static int +sf_FCOMI_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + flags_rebuild(); + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + cpu_state.flags |= (Z_FLAG | P_FLAG | C_FLAG); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_two(a, b, &status); + FPU_write_eflags_fpu_compare(rc); + FPU_exception(fetchdat, status.float_exception_flags, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom) : (x87_timings.fcom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom) : (x87_concurrency.fcom * cpu_multi)); + return 0; +} +static int +sf_FCOMIP_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + flags_rebuild(); + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + cpu_state.flags |= (Z_FLAG | P_FLAG | C_FLAG); + if (is_IA_masked()) { + FPU_pop(); + } + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_two(a, b, &status); + FPU_write_eflags_fpu_compare(rc); + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fcom) : (x87_timings.fcom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fcom) : (x87_concurrency.fcom * cpu_multi)); + return 0; +} + +static int +sf_FUCOM_sti(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(C0 | C2 | C3); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_quiet(a, b, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + FPU_exception(fetchdat, status.float_exception_flags, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fucom) : (x87_timings.fucom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fucom) : (x87_concurrency.fucom * cpu_multi)); + return 0; +} + +static int +sf_FUCOMP_sti(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(C0 | C2 | C3); + if (is_IA_masked()) + FPU_pop(); + + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_quiet(a, b, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fucom) : (x87_timings.fucom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fucom) : (x87_concurrency.fucom * cpu_multi)); + return 0; +} + +static int +sf_FUCOMI_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + flags_rebuild(); + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + cpu_state.flags |= (Z_FLAG | P_FLAG | C_FLAG); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_quiet(a, b, &status); + FPU_write_eflags_fpu_compare(rc); + FPU_exception(fetchdat, status.float_exception_flags, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fucom) : (x87_timings.fucom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fucom) : (x87_concurrency.fucom * cpu_multi)); + return 0; +} +static int +sf_FUCOMIP_st0_stj(uint32_t fetchdat) +{ + floatx80 a, b; + struct float_status_t status; + int rc; + + FP_ENTER(); + cpu_state.pc++; + flags_rebuild(); + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + cpu_state.flags |= (Z_FLAG | P_FLAG | C_FLAG); + if (is_IA_masked()) + FPU_pop(); + + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(fetchdat & 7); + rc = floatx80_compare_quiet(a, b, &status); + FPU_write_eflags_fpu_compare(rc); + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fucom) : (x87_timings.fucom * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fucom) : (x87_concurrency.fucom * cpu_multi)); + return 0; +} +#endif + +static int +sf_FTST(uint32_t fetchdat) +{ + int rc; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(C0 | C2 | C3); + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + rc = floatx80_compare_two(FPU_read_regi(0), Const_Z, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + FPU_exception(fetchdat, status.float_exception_flags, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.ftst) : (x87_timings.ftst * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.ftst) : (x87_concurrency.ftst * cpu_multi)); + return 0; +} + +static int +sf_FXAM(uint32_t fetchdat) +{ + floatx80 reg; + int sign; + float_class_t aClass; + + FP_ENTER(); + cpu_state.pc++; + reg = FPU_read_regi(0); + sign = floatx80_sign(reg); + /* + * Examine the contents of the ST(0) register and sets the condition + * code flags C0, C2 and C3 in the FPU status word to indicate the + * class of value or number in the register. + */ + if (IS_TAG_EMPTY(0)) { + setcc(C3 | C1 | C0); + } else { + aClass = floatx80_class(reg); + switch (aClass) { + case float_zero: + setcc(C3 | C1); + break; + case float_SNaN: + case float_QNaN: + // unsupported handled as NaNs + if (floatx80_is_unsupported(reg)) { + setcc(C1); + } else { + setcc(C1 | C0); + } + break; + case float_negative_inf: + case float_positive_inf: + setcc(C2 | C1 | C0); + break; + case float_denormal: + setcc(C3 | C2 | C1); + break; + case float_normalized: + setcc(C2 | C1); + break; + } + } + /* + * The C1 flag is set to the sign of the value in ST(0), regardless + * of whether the register is empty or full. + */ + if (!sign) + clear_C1(); + + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fxam) : (x87_timings.fxam * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fxam) : (x87_concurrency.fxam * cpu_multi)); + return 0; +} diff --git a/src/cpu/x87_ops_sf_const.h b/src/cpu/x87_ops_sf_const.h new file mode 100644 index 000000000..708c6ff7a --- /dev/null +++ b/src/cpu/x87_ops_sf_const.h @@ -0,0 +1,131 @@ +/* A fast way to find out whether x is one of RC_DOWN or RC_CHOP + (and not one of RC_RND or RC_UP). + */ +#define DOWN_OR_CHOP() (fpu_state.cwd & FPU_CW_RC & FPU_RC_DOWN) + +static __inline floatx80 +FPU_round_const(const floatx80 a, int adj) +{ + floatx80 result = a; + result.fraction += adj; + return result; +} + +static int +sf_FLDL2T(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) + FPU_stack_overflow(fetchdat); + else { + FPU_push(); + FPU_save_regi(FPU_round_const(Const_L2T, (fpu_state.cwd & FPU_CW_RC) == FPU_RC_UP), 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_const) : (x87_timings.fld_const * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_const) : (x87_concurrency.fld_const * cpu_multi)); + return 0; +} + +static int +sf_FLDL2E(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) + FPU_stack_overflow(fetchdat); + else { + FPU_push(); + FPU_save_regi(FPU_round_const(Const_L2E, DOWN_OR_CHOP() ? -1 : 0), 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_const) : (x87_timings.fld_const * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_const) : (x87_concurrency.fld_const * cpu_multi)); + return 0; +} + +static int +sf_FLDPI(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) + FPU_stack_overflow(fetchdat); + else { + FPU_push(); + FPU_save_regi(FPU_round_const(Const_PI, DOWN_OR_CHOP() ? -1 : 0), 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_const) : (x87_timings.fld_const * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_const) : (x87_concurrency.fld_const * cpu_multi)); + return 0; +} + +static int +sf_FLDEG2(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) + FPU_stack_overflow(fetchdat); + else { + FPU_push(); + FPU_save_regi(FPU_round_const(Const_LG2, DOWN_OR_CHOP() ? -1 : 0), 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_const) : (x87_timings.fld_const * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_const) : (x87_concurrency.fld_const * cpu_multi)); + return 0; +} + +static int +sf_FLDLN2(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) + FPU_stack_overflow(fetchdat); + else { + FPU_push(); + FPU_save_regi(FPU_round_const(Const_LN2, DOWN_OR_CHOP() ? -1 : 0), 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_const) : (x87_timings.fld_const * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_const) : (x87_concurrency.fld_const * cpu_multi)); + return 0; +} + +static int +sf_FLD1(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) + FPU_stack_overflow(fetchdat); + else { + FPU_push(); + FPU_save_regi(Const_1, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_z1) : (x87_timings.fld_z1 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_z1) : (x87_concurrency.fld_z1 * cpu_multi)); + return 0; +} + +static int +sf_FLDZ(uint32_t fetchdat) +{ + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) + FPU_stack_overflow(fetchdat); + else { + FPU_push(); + FPU_save_regi(Const_Z, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_z1) : (x87_timings.fld_z1 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_z1) : (x87_concurrency.fld_z1 * cpu_multi)); + return 0; +} diff --git a/src/cpu/x87_ops_sf_load_store.h b/src/cpu/x87_ops_sf_load_store.h new file mode 100644 index 000000000..69bc5598c --- /dev/null +++ b/src/cpu/x87_ops_sf_load_store.h @@ -0,0 +1,1312 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * x87 FPU instructions core. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + */ + +#define swap_values16u(a, b) { uint16_t tmp = a; a = b; b = tmp; } + +static int +sf_FILDiw_a16(uint32_t fetchdat) +{ + floatx80 result; + int16_t temp; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + temp = geteaw(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + result = int32_to_floatx80(temp); + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fild_16) : (x87_timings.fild_16 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fild_16) : (x87_concurrency.fild_16 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FILDiw_a32(uint32_t fetchdat) +{ + floatx80 result; + int16_t temp; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + temp = geteaw(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + result = int32_to_floatx80(temp); + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fild_16) : (x87_timings.fild_16 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fild_16) : (x87_concurrency.fild_16 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FILDil_a16(uint32_t fetchdat) +{ + floatx80 result; + int32_t templ; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + templ = geteal(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + result = int32_to_floatx80(templ); + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fild_32) : (x87_timings.fild_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fild_32) : (x87_concurrency.fild_32 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FILDil_a32(uint32_t fetchdat) +{ + floatx80 result; + int32_t templ; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + templ = geteal(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + result = int32_to_floatx80(templ); + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fild_32) : (x87_timings.fild_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fild_32) : (x87_concurrency.fild_32 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FILDiq_a16(uint32_t fetchdat) +{ + floatx80 result; + int64_t temp64; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + temp64 = geteaq(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + result = int64_to_floatx80(temp64); + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fild_64) : (x87_timings.fild_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fild_64) : (x87_concurrency.fild_64 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FILDiq_a32(uint32_t fetchdat) +{ + floatx80 result; + int64_t temp64; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + temp64 = geteaq(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + result = int64_to_floatx80(temp64); + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fild_64) : (x87_timings.fild_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fild_64) : (x87_concurrency.fild_64 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FLDs_a16(uint32_t fetchdat) +{ + struct float_status_t status; + floatx80 result; + float32 load_reg; + unsigned unmasked; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + load_reg = geteal(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + result = float32_to_floatx80(load_reg, &status); + unmasked = FPU_exception(fetchdat, status.float_exception_flags, 0); + if (!(unmasked & FPU_CW_Invalid)) { + FPU_push(); + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_32) : (x87_timings.fst_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_32) : (x87_concurrency.fst_32 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FLDs_a32(uint32_t fetchdat) +{ + struct float_status_t status; + floatx80 result; + float32 load_reg; + unsigned unmasked; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + load_reg = geteal(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + result = float32_to_floatx80(load_reg, &status); + unmasked = FPU_exception(fetchdat, status.float_exception_flags, 0); + if (!(unmasked & FPU_CW_Invalid)) { + FPU_push(); + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_32) : (x87_timings.fst_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_32) : (x87_concurrency.fst_32 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FLDd_a16(uint32_t fetchdat) +{ + struct float_status_t status; + floatx80 result; + float64 load_reg; + unsigned unmasked; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + load_reg = geteaq(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + result = float64_to_floatx80(load_reg, &status); + unmasked = FPU_exception(fetchdat, status.float_exception_flags, 0); + if (!(unmasked & FPU_CW_Invalid)) { + FPU_push(); + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_64) : (x87_timings.fld_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_64) : (x87_concurrency.fld_64 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FLDd_a32(uint32_t fetchdat) +{ + struct float_status_t status; + floatx80 result; + float64 load_reg; + unsigned unmasked; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + load_reg = geteaq(); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + result = float64_to_floatx80(load_reg, &status); + unmasked = FPU_exception(fetchdat, status.float_exception_flags, 0); + if (!(unmasked & FPU_CW_Invalid)) { + FPU_push(); + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_64) : (x87_timings.fld_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_64) : (x87_concurrency.fld_64 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FLDe_a16(uint32_t fetchdat) +{ + floatx80 result; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + result.fraction = readmemq(easeg, cpu_state.eaaddr); + result.exp = readmemw(easeg, cpu_state.eaaddr + 8); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_80) : (x87_timings.fld_80 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_80) : (x87_concurrency.fld_80 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FLDe_a32(uint32_t fetchdat) +{ + floatx80 result; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_READ(cpu_state.ea_seg); + result.fraction = readmemq(easeg, cpu_state.eaaddr); + result.exp = readmemw(easeg, cpu_state.eaaddr + 8); + if (cpu_state.abrt) + return 1; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + } else { + FPU_push(); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld_80) : (x87_timings.fld_80 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld_80) : (x87_concurrency.fld_80 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FLD_sti(uint32_t fetchdat) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + floatx80 sti_reg; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + if (!IS_TAG_EMPTY(-1)) { + FPU_stack_overflow(fetchdat); + goto next_ins; + } + sti_reg = floatx80_default_nan; + if (IS_TAG_EMPTY(fetchdat & 7)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + sti_reg = FPU_read_regi(fetchdat & 7); + } + + FPU_push(); + FPU_save_regi(sti_reg, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fld) : (x87_timings.fld * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fld) : (x87_concurrency.fld * cpu_multi)); + return 0; +} + +static int +sf_FISTiw_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int16_t save_reg = int16_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) { + goto next_ins; + } + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int16(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaw(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_16) : (x87_timings.fist_16 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_16) : (x87_concurrency.fist_16 * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FISTiw_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int16_t save_reg = int16_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int16(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaw(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_16) : (x87_timings.fist_16 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_16) : (x87_concurrency.fist_16 * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FISTPiw_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int16_t save_reg = int16_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int16(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaw(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_16) : (x87_timings.fist_16 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_16) : (x87_concurrency.fist_16 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FISTPiw_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int16_t save_reg = int16_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int16(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaw(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_16) : (x87_timings.fist_16 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_16) : (x87_concurrency.fist_16 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FISTil_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int32_t save_reg = int32_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_32) : (x87_timings.fist_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_32) : (x87_concurrency.fist_32 * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FISTil_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int32_t save_reg = int32_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_32) : (x87_timings.fist_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_32) : (x87_concurrency.fist_32 * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FISTPil_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int32_t save_reg = int32_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_32) : (x87_timings.fist_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_32) : (x87_concurrency.fist_32 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FISTPil_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int32_t save_reg = int32_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_32) : (x87_timings.fist_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_32) : (x87_concurrency.fist_32 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FISTPiq_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int64_t save_reg = int64_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int64(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case origial FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaq(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_64) : (x87_timings.fist_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_64) : (x87_concurrency.fist_64 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FISTPiq_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + int64_t save_reg = int64_indefinite; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_int64(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case origial FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaq(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fist_64) : (x87_timings.fist_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fist_64) : (x87_concurrency.fist_64 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FBSTP_PACKED_BCD_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + uint16_t save_reg_hi = 0xffff; + uint64_t save_reg_lo = BX_CONST64(0xC000000000000000); + floatx80 reg; + int64_t save_val; + int sign; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + reg = FPU_read_regi(0); + save_val = floatx80_to_int64(reg, &status); + sign = (reg.exp & 0x8000) != 0; + if (sign) + save_val = -save_val; + + if (save_val > BX_CONST64(999999999999999999)) + status.float_exception_flags = float_flag_invalid; // throw away other flags + + if (!(status.float_exception_flags & float_flag_invalid)) { + save_reg_hi = sign ? 0x8000 : 0; + save_reg_lo = 0; + for (int i = 0; i < 16; i++) { + save_reg_lo += ((uint64_t)(save_val % 10)) << (4 * i); + save_val /= 10; + } + save_reg_hi += (uint16_t)(save_val % 10); + save_val /= 10; + save_reg_hi += (uint16_t)(save_val % 10) << 4; + } + /* check for fpu arithmetic exceptions */ + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + + // write packed bcd to memory + writememq(easeg, cpu_state.eaaddr, save_reg_lo); + writememw(easeg, cpu_state.eaaddr + 8, save_reg_hi); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fbstp) : (x87_timings.fbstp * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fbstp) : (x87_concurrency.fbstp * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FBSTP_PACKED_BCD_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + uint16_t save_reg_hi = 0xffff; + uint64_t save_reg_lo = BX_CONST64(0xC000000000000000); + floatx80 reg; + int64_t save_val; + int sign; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + reg = FPU_read_regi(0); + save_val = floatx80_to_int64(reg, &status); + sign = (reg.exp & 0x8000) != 0; + if (sign) + save_val = -save_val; + + if (save_val > BX_CONST64(999999999999999999)) + status.float_exception_flags = float_flag_invalid; // throw away other flags + + if (!(status.float_exception_flags & float_flag_invalid)) { + save_reg_hi = sign ? 0x8000 : 0; + save_reg_lo = 0; + for (int i = 0; i < 16; i++) { + save_reg_lo += ((uint64_t)(save_val % 10)) << (4 * i); + save_val /= 10; + } + save_reg_hi += (uint16_t)(save_val % 10); + save_val /= 10; + save_reg_hi += (uint16_t)(save_val % 10) << 4; + } + /* check for fpu arithmetic exceptions */ + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + + // write packed bcd to memory + writememq(easeg, cpu_state.eaaddr, save_reg_lo); + writememw(easeg, cpu_state.eaaddr + 8, save_reg_hi); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fbstp) : (x87_timings.fbstp * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fbstp) : (x87_concurrency.fbstp * cpu_multi)); + return 0; +} +#endif + +static int +sf_FSTs_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float32 save_reg = float32_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_32) : (x87_timings.fst_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_32) : (x87_concurrency.fst_32 * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FSTs_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float32 save_reg = float32_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_32) : (x87_timings.fst_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_32) : (x87_concurrency.fst_32 * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FSTPs_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float32 save_reg = float32_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + if (cpu_state.abrt) { + return 1; + } + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_32) : (x87_timings.fst_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_32) : (x87_concurrency.fst_32 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FSTPs_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float32 save_reg = float32_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float32(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteal(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_32) : (x87_timings.fst_32 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_32) : (x87_concurrency.fst_32 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FSTd_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float64 save_reg = float64_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float64(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaq(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_64) : (x87_timings.fst_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_64) : (x87_concurrency.fst_64 * cpu_multi)); + return cpu_state.abrt; +} +#ifndef FPU_8087 +static int +sf_FSTd_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float64 save_reg = float64_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float64(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaq(save_reg); + fpu_state.swd = sw; + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_64) : (x87_timings.fst_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_64) : (x87_concurrency.fst_64 * cpu_multi)); + return cpu_state.abrt; +} +#endif + +static int +sf_FSTPd_a16(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float64 save_reg = float64_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) { + goto next_ins; + } + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float64(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) { + goto next_ins; + } + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaq(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_64) : (x87_timings.fst_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_64) : (x87_concurrency.fst_64 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FSTPd_a32(uint32_t fetchdat) +{ + struct float_status_t status; + uint16_t sw = fpu_state.swd; + float64 save_reg = float64_default_nan; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + save_reg = floatx80_to_float64(FPU_read_regi(0), &status); + if (FPU_exception(fetchdat, status.float_exception_flags, 1)) + goto next_ins; + } + // store to the memory might generate an exception, in this case original FPU_SW must be kept + swap_values16u(sw, fpu_state.swd); + seteaq(save_reg); + if (cpu_state.abrt) + return 1; + fpu_state.swd = sw; + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_64) : (x87_timings.fst_64 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_64) : (x87_concurrency.fst_64 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FSTPe_a16(uint32_t fetchdat) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + floatx80 save_reg; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_16(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + if (cpu_state.abrt) + return 1; + save_reg = floatx80_default_nan; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) { + goto next_ins; + } + } else { + save_reg = FPU_read_regi(0); + } + writememq(easeg, cpu_state.eaaddr, save_reg.fraction); + writememw(easeg, cpu_state.eaaddr + 8, save_reg.exp); + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_80) : (x87_timings.fst_80 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_80) : (x87_concurrency.fst_80 * cpu_multi)); + return 0; +} +#ifndef FPU_8087 +static int +sf_FSTPe_a32(uint32_t fetchdat) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + floatx80 save_reg; + + FP_ENTER(); + FPU_check_pending_exceptions(); + fetch_ea_32(fetchdat); + SEG_CHECK_WRITE(cpu_state.ea_seg); + if (cpu_state.abrt) + return 1; + save_reg = floatx80_default_nan; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (!is_IA_masked()) + goto next_ins; + } else { + save_reg = FPU_read_regi(0); + } + writememq(easeg, cpu_state.eaaddr, save_reg.fraction); + writememw(easeg, cpu_state.eaaddr + 8, save_reg.exp); + FPU_pop(); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst_80) : (x87_timings.fst_80 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst_80) : (x87_concurrency.fst_80 * cpu_multi)); + return 0; +} +#endif + +static int +sf_FST_sti(uint32_t fetchdat) +{ + floatx80 st0_reg; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 0); + } else { + st0_reg = FPU_read_regi(0); + FPU_save_regi(st0_reg, fetchdat & 7); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst) : (x87_timings.fst * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst) : (x87_concurrency.fst * cpu_multi)); + return 0; +} + +static int +sf_FSTP_sti(uint32_t fetchdat) +{ + floatx80 st0_reg; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_stack_underflow(fetchdat, fetchdat & 7, 1); + } else { + st0_reg = FPU_read_regi(0); + FPU_save_regi(st0_reg, fetchdat & 7); + FPU_pop(); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fst) : (x87_timings.fst * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fst) : (x87_concurrency.fst * cpu_multi)); + return 0; +} + +#ifndef FPU_8087 +# define sf_FCMOV(condition) \ + static int sf_FCMOV##condition(uint32_t fetchdat) \ + { \ + FP_ENTER(); \ + FPU_check_pending_exceptions(); \ + cpu_state.pc++; \ + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(fetchdat & 7)) \ + FPU_stack_underflow(fetchdat, 0, 0); \ + else { \ + if (cond_##condition) { \ + FPU_save_regi(FPU_read_regi(fetchdat & 7), 0); \ + } \ + } \ + CLOCK_CYCLES_FPU(4); \ + return 0; \ + } + +# define cond_U (PF_SET()) +# define cond_NU (!PF_SET()) + +// clang-format off +sf_FCMOV(B) +sf_FCMOV(E) +sf_FCMOV(BE) +sf_FCMOV(U) +sf_FCMOV(NB) +sf_FCMOV(NE) +sf_FCMOV(NBE) +sf_FCMOV(NU) +// clang-format on +#endif diff --git a/src/cpu/x87_ops_sf_misc.h b/src/cpu/x87_ops_sf_misc.h new file mode 100644 index 000000000..d8a3d7368 --- /dev/null +++ b/src/cpu/x87_ops_sf_misc.h @@ -0,0 +1,134 @@ +static int +sf_FXCH_sti(uint32_t fetchdat) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + floatx80 st0_reg, sti_reg; + int st0_tag, sti_tag; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + st0_tag = FPU_gettagi(0); + sti_tag = FPU_gettagi(fetchdat & 7); + st0_reg = FPU_read_regi(0); + sti_reg = FPU_read_regi(fetchdat & 7); + + clear_C1(); + if ((st0_tag == X87_TAG_EMPTY) || (sti_tag == X87_TAG_EMPTY)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + if (is_IA_masked()) { + /* Masked response */ + if (st0_tag == X87_TAG_EMPTY) + st0_reg = floatx80_default_nan; + if (sti_tag == X87_TAG_EMPTY) + sti_reg = floatx80_default_nan; + } else + goto next_ins; + } + FPU_save_regi(st0_reg, fetchdat & 7); + FPU_save_regi(sti_reg, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fxch) : (x87_timings.fxch * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fxch) : (x87_concurrency.fxch * cpu_multi)); + return 0; +} + +static int +sf_FCHS(uint32_t fetchdat) +{ + floatx80 st0_reg; + floatx80 result; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + if (IS_TAG_EMPTY(0)) + FPU_stack_underflow(fetchdat, 0, 0); + else { + clear_C1(); + st0_reg = FPU_read_regi(0); + result = floatx80_chs(st0_reg); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fchs) : (x87_timings.fchs * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fchs) : (x87_concurrency.fchs * cpu_multi)); + return 0; +} + +static int +sf_FABS(uint32_t fetchdat) +{ + floatx80 st0_reg; + floatx80 result; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + if (IS_TAG_EMPTY(0)) + FPU_stack_underflow(fetchdat, 0, 0); + else { + clear_C1(); + st0_reg = FPU_read_regi(0); + result = floatx80_abs(st0_reg); + FPU_save_regi(result, 0); + } + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fabs) : (x87_timings.fabs * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fabs) : (x87_concurrency.fabs * cpu_multi)); + return 0; +} + +static int +sf_FDECSTP(uint32_t fetchdat) +{ + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + fpu_state.tos = (fpu_state.tos - 1) & 7; + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fincdecstp) : (x87_timings.fincdecstp * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fincdecstp) : (x87_concurrency.fincdecstp * cpu_multi)); + return 0; +} + +static int +sf_FINCSTP(uint32_t fetchdat) +{ + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + fpu_state.tos = (fpu_state.tos + 1) & 7; + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fincdecstp) : (x87_timings.fincdecstp * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fincdecstp) : (x87_concurrency.fincdecstp * cpu_multi)); + return 0; +} + +static int +sf_FFREE_sti(uint32_t fetchdat) +{ + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + FPU_settagi(X87_TAG_EMPTY, fetchdat & 7); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.ffree) : (x87_timings.ffree * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.ffree) : (x87_concurrency.ffree * cpu_multi)); + return 0; +} + +static int +sf_FFREEP_sti(uint32_t fetchdat) +{ + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + FPU_settagi(X87_TAG_EMPTY, fetchdat & 7); + if (cpu_state.abrt) + return 1; + FPU_pop(); + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.ffree) : (x87_timings.ffree * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.ffree) : (x87_concurrency.ffree * cpu_multi)); + return 0; +} diff --git a/src/cpu/x87_ops_sf_trans.h b/src/cpu/x87_ops_sf_trans.h new file mode 100644 index 000000000..5289b2bbf --- /dev/null +++ b/src/cpu/x87_ops_sf_trans.h @@ -0,0 +1,417 @@ +static int +sf_F2XM1(uint32_t fetchdat) +{ + floatx80 result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + result = f2xm1(FPU_read_regi(0), &status); + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.f2xm1) : (x87_timings.f2xm1 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.f2xm1) : (x87_concurrency.f2xm1 * cpu_multi)); + return 0; +} + +static int +sf_FYL2X(uint32_t fetchdat) +{ + floatx80 result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_stack_underflow(fetchdat, 1, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + result = fyl2x(FPU_read_regi(0), FPU_read_regi(1), &status); + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_pop(); + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fyl2x) : (x87_timings.fyl2x * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fyl2x) : (x87_concurrency.fyl2x * cpu_multi)); + return 0; +} + +static int +sf_FPTAN(uint32_t fetchdat) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + floatx80 y; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + clear_C2(); + if (IS_TAG_EMPTY(0) || !IS_TAG_EMPTY(-1)) { + if (IS_TAG_EMPTY(0)) + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + else + FPU_exception(fetchdat, FPU_EX_Stack_Overflow, 0); + + /* The masked response */ + if (is_IA_masked()) { + FPU_save_regi(floatx80_default_nan, 0); + FPU_push(); + FPU_save_regi(floatx80_default_nan, 0); + } + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + y = FPU_read_regi(0); + if (ftan(&y, &status) == -1) { + fpu_state.swd |= C2; + goto next_ins; + } + + if (floatx80_is_nan(y)) { + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(y, 0); + FPU_push(); + FPU_save_regi(y, 0); + } + goto next_ins; + } + + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(y, 0); + FPU_push(); + FPU_save_regi(Const_1, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fptan) : (x87_timings.fptan * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fptan) : (x87_concurrency.fptan * cpu_multi)); + return 0; +} + +static int +sf_FPATAN(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_stack_underflow(fetchdat, 1, 1); + goto next_ins; + } + a = FPU_read_regi(0); + b = FPU_read_regi(1); + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + result = fpatan(a, b, &status); + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_pop(); + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fpatan) : (x87_timings.fpatan * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fpatan) : (x87_concurrency.fpatan * cpu_multi)); + return 0; +} + +static int +sf_FXTRACT(uint32_t fetchdat) +{ + struct float_status_t status; + floatx80 a, b; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + +#if 0 //TODO + if ((IS_TAG_EMPTY(0) || IS_TAG_EMPTY(-1))) { + if (IS_TAG_EMPTY(0)) + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + else + FPU_exception(fetchdat, FPU_EX_Stack_Overflow, 0); + + /* The masked response */ + if (is_IA_masked()) { + FPU_save_regi(floatx80_default_nan, 0); + FPU_push(); + FPU_save_regi(floatx80_default_nan, 0); + } + goto next_ins; + } +#endif + + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = floatx80_extract(&a, &status); + if (!FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(b, 0); // exponent + FPU_push(); + FPU_save_regi(a, 0); // fraction + } + +#if 0 //TODO. +next_ins: +#endif + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fxtract) : (x87_timings.fxtract * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fxtract) : (x87_concurrency.fxtract * cpu_multi)); + return 0; +} + +static int +sf_FPREM1(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + uint64_t quotient = 0; + int flags, cc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + clear_C2(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(1); + flags = floatx80_ieee754_remainder(a, b, &result, "ient, &status); + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + if (flags >= 0) { + cc = 0; + if (flags) + cc = C2; + else { + if (quotient & 1) + cc |= C1; + if (quotient & 2) + cc |= C3; + if (quotient & 4) + cc |= C0; + } + setcc(cc); + } + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fprem1) : (x87_timings.fprem1 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fprem1) : (x87_concurrency.fprem1 * cpu_multi)); + return 0; +} + +static int +sf_FPREM(uint32_t fetchdat) +{ + floatx80 a, b, result; + struct float_status_t status; + uint64_t quotient = 0; + int flags, cc; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + clear_C2(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + a = FPU_read_regi(0); + b = FPU_read_regi(1); + // handle unsupported extended double-precision floating encodings + flags = floatx80_remainder(a, b, &result, "ient, &status); + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + if (flags >= 0) { + cc = 0; + if (flags) + cc = C2; + else { + if (quotient & 1) + cc |= C1; + if (quotient & 2) + cc |= C3; + if (quotient & 4) + cc |= C0; + } + setcc(cc); + } + FPU_save_regi(result, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fprem) : (x87_timings.fprem * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fprem) : (x87_concurrency.fprem * cpu_multi)); + return 0; +} + +static int +sf_FYL2XP1(uint32_t fetchdat) +{ + floatx80 result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_stack_underflow(fetchdat, 1, 1); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + result = fyl2xp1(FPU_read_regi(0), FPU_read_regi(1), &status); + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(result, 1); + FPU_pop(); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fyl2xp1) : (x87_timings.fyl2xp1 * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fyl2xp1) : (x87_concurrency.fyl2xp1 * cpu_multi)); + return 0; +} + +#ifndef FPU_8087 +static int +sf_FSINCOS(uint32_t fetchdat) +{ + const floatx80 floatx80_default_nan = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); + struct float_status_t status; + floatx80 y, sin_y, cos_y; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + clear_C2(); + if (IS_TAG_EMPTY(0) || !IS_TAG_EMPTY(-1)) { + if (IS_TAG_EMPTY(0)) + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + else + FPU_exception(fetchdat, FPU_EX_Stack_Overflow, 0); + + /* The masked response */ + if (is_IA_masked()) { + FPU_save_regi(floatx80_default_nan, 0); + FPU_push(); + FPU_save_regi(floatx80_default_nan, 0); + } + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + y = FPU_read_regi(0); + if (fsincos(y, &sin_y, &cos_y, &status) == -1) { + fpu_state.swd |= C2; + goto next_ins; + } + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) { + FPU_save_regi(sin_y, 0); + FPU_push(); + FPU_save_regi(cos_y, 0); + } + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fsincos) : (x87_timings.fsincos * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fsincos) : (x87_concurrency.fsincos * cpu_multi)); + return 0; +} +#endif + +static int +sf_FSCALE(uint32_t fetchdat) +{ + floatx80 result; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0) || IS_TAG_EMPTY(1)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + result = floatx80_scale(FPU_read_regi(0), FPU_read_regi(1), &status); + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(result, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fscale) : (x87_timings.fscale * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fscale) : (x87_concurrency.fscale * cpu_multi)); + return 0; +} + +#ifndef FPU_8087 +static int +sf_FSIN(uint32_t fetchdat) +{ + floatx80 y; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + clear_C2(); + if (IS_TAG_EMPTY(0)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + y = FPU_read_regi(0); + if (fsin(&y, &status) == -1) { + fpu_state.swd |= C2; + goto next_ins; + } + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(y, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fsin_cos) : (x87_timings.fsin_cos * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fsin_cos) : (x87_concurrency.fsin_cos * cpu_multi)); + return 0; +} + +static int +sf_FCOS(uint32_t fetchdat) +{ + floatx80 y; + struct float_status_t status; + + FP_ENTER(); + cpu_state.pc++; + clear_C1(); + clear_C2(); + if (IS_TAG_EMPTY(0)) { + FPU_stack_underflow(fetchdat, 0, 0); + goto next_ins; + } + status = i387cw_to_softfloat_status_word(i387_get_control_word() | FPU_PR_80_BITS); + y = FPU_read_regi(0); + if (fcos(&y, &status) == -1) { + fpu_state.swd |= C2; + goto next_ins; + } + if (! FPU_exception(fetchdat, status.float_exception_flags, 0)) + FPU_save_regi(y, 0); + +next_ins: + CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fsin_cos) : (x87_timings.fsin_cos * cpu_multi)); + CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fsin_cos) : (x87_concurrency.fsin_cos * cpu_multi)); + return 0; +} +#endif diff --git a/src/crcspeed/crc64speed.c b/src/crcspeed/crc64speed.c index e4cccdc69..b32990b12 100644 --- a/src/crcspeed/crc64speed.c +++ b/src/crcspeed/crc64speed.c @@ -36,7 +36,8 @@ * each 8x256 lookup table is 16k. */ #ifndef CRC64SPEED_DUAL static uint64_t crc64_table[8][256] = {{0}}; -static void *crc64_table_little = NULL, *crc64_table_big = NULL; +static void *crc64_table_little = NULL; +static void *crc64_table_big = NULL; static const bool dual = false; #else static uint64_t crc64_table_little[8][256] = {{0}}; diff --git a/src/ddma.c b/src/ddma.c index 7904163da..7cbe2831e 100644 --- a/src/ddma.c +++ b/src/ddma.c @@ -34,6 +34,7 @@ #include <86box/pit.h> #include <86box/dma.h> #include <86box/ddma.h> +#include <86box/plat_unused.h> #ifdef ENABLE_DDMA_LOG int ddma_do_log = ENABLE_DDMA_LOG; @@ -54,12 +55,12 @@ ddma_log(const char *fmt, ...) #endif static uint8_t -ddma_reg_read(uint16_t addr, void *p) +ddma_reg_read(uint16_t addr, void *priv) { - ddma_channel_t *dev = (ddma_channel_t *) p; - uint8_t ret = 0xff; - int ch = dev->channel; - int dmab = (ch >= 4) ? 0xc0 : 0x00; + const ddma_channel_t *dev = (ddma_channel_t *) priv; + uint8_t ret = 0xff; + int ch = dev->channel; + uint8_t dmab = (ch >= 4) ? 0xc0 : 0x00; switch (addr & 0x0f) { case 0x00: @@ -80,18 +81,21 @@ ddma_reg_read(uint16_t addr, void *p) case 0x09: ret = inb(dmab + 0x08); break; + + default: + break; } return ret; } static void -ddma_reg_write(uint16_t addr, uint8_t val, void *p) +ddma_reg_write(uint16_t addr, uint8_t val, void *priv) { - ddma_channel_t *dev = (ddma_channel_t *) p; - int ch = dev->channel; - int page_regs[4] = { 7, 3, 1, 2 }; - int i, dmab = (ch >= 4) ? 0xc0 : 0x00; + const ddma_channel_t *dev = (ddma_channel_t *) priv; + int ch = dev->channel; + uint8_t page_regs[4] = { 7, 3, 1, 2 }; + uint8_t dmab = (ch >= 4) ? 0xc0 : 0x00; switch (addr & 0x0f) { case 0x00: @@ -132,12 +136,15 @@ ddma_reg_write(uint16_t addr, uint8_t val, void *p) outb(dmab + 0x0d, val); break; case 0x0e: - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) outb(dmab + 0x0a, i); break; case 0x0f: outb(dmab + 0x0a, (val << 2) | (ch & 3)); break; + + default: + break; } } @@ -163,17 +170,16 @@ ddma_close(void *priv) } static void * -ddma_init(const device_t *info) +ddma_init(UNUSED(const device_t *info)) { ddma_t *dev; - int i; dev = (ddma_t *) malloc(sizeof(ddma_t)); if (dev == NULL) return (NULL); memset(dev, 0x00, sizeof(ddma_t)); - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) dev->channels[i].channel = i; return dev; diff --git a/src/device.c b/src/device.c index 5d739b13c..e9d0a094a 100644 --- a/src/device.c +++ b/src/device.c @@ -59,7 +59,8 @@ static device_t *devices[DEVICE_MAX]; static void *device_priv[DEVICE_MAX]; -static device_context_t device_current, device_prev; +static device_context_t device_current; +static device_context_t device_prev; #ifdef ENABLE_DEVICE_LOG int device_do_log = ENABLE_DEVICE_LOG; @@ -87,45 +88,46 @@ device_init(void) } void -device_set_context(device_context_t *c, const device_t *d, int inst) +device_set_context(device_context_t *c, const device_t *dev, int inst) { - void *sec, *single_sec; + const void *sec; + void *single_sec; memset(c, 0, sizeof(device_context_t)); - c->dev = d; + c->dev = dev; c->instance = inst; if (inst) { - sprintf(c->name, "%s #%i", d->name, inst); + sprintf(c->name, "%s #%i", dev->name, inst); /* If this is the first instance and a numbered section is not present, but a non-numbered section of the same name is, rename the non-numbered section to numbered. */ if (inst == 1) { sec = config_find_section(c->name); - single_sec = config_find_section((char *) d->name); + single_sec = config_find_section((char *) dev->name); if ((sec == NULL) && (single_sec != NULL)) config_rename_section(single_sec, c->name); } } else - sprintf(c->name, "%s", d->name); + sprintf(c->name, "%s", dev->name); } static void -device_context_common(const device_t *d, int inst) +device_context_common(const device_t *dev, int inst) { memcpy(&device_prev, &device_current, sizeof(device_context_t)); - device_set_context(&device_current, d, inst); + device_set_context(&device_current, dev, inst); } void -device_context(const device_t *d) +device_context(const device_t *dev) { - device_context_common(d, 0); + device_context_common(dev, 0); } void -device_context_inst(const device_t *d, int inst) +device_context_inst(const device_t *dev, int inst) { - device_context_common(d, inst); + device_context_common(dev, inst); } void @@ -135,35 +137,37 @@ device_context_restore(void) } static void * -device_add_common(const device_t *d, const device_t *cd, void *p, void *params, int inst) +device_add_common(const device_t *dev, const device_t *cd, void *p, void *params, int inst) { void *priv = NULL; int c; for (c = 0; c < 256; c++) { - if (!inst && (devices[c] == (device_t *) d)) { + if (!inst && (devices[c] == dev)) { device_log("DEVICE: device already exists!\n"); return (NULL); } if (devices[c] == NULL) break; } - if (c >= DEVICE_MAX) + if ((c >= DEVICE_MAX) || (c >= 256)) { fatal("DEVICE: too many devices\n"); + return NULL; + } /* Do this so that a chained device_add will not identify the same ID its master device is already trying to assign. */ - devices[c] = (device_t *) d; + devices[c] = (device_t *) dev; if (p == NULL) { memcpy(&device_prev, &device_current, sizeof(device_context_t)); device_set_context(&device_current, cd, inst); - if (d->init != NULL) { - priv = (d->flags & DEVICE_EXTPARAMS) ? d->init_ext(d, params) : d->init(d); + if (dev->init != NULL) { + priv = (dev->flags & DEVICE_EXTPARAMS) ? dev->init_ext(dev, params) : dev->init(dev); if (priv == NULL) { - if (d->name) - device_log("DEVICE: device '%s' init failed\n", d->name); + if (dev->name) + device_log("DEVICE: device '%s' init failed\n", dev->name); else device_log("DEVICE: device init failed\n"); @@ -174,8 +178,8 @@ device_add_common(const device_t *d, const device_t *cd, void *p, void *params, } } - if (d->name) - device_log("DEVICE: device '%s' init successful\n", d->name); + if (dev->name) + device_log("DEVICE: device '%s' init successful\n", dev->name); else device_log("DEVICE: device init successful\n"); @@ -184,126 +188,124 @@ device_add_common(const device_t *d, const device_t *cd, void *p, void *params, } else device_priv[c] = p; - return (priv); + return priv; } char * -device_get_internal_name(const device_t *d) +device_get_internal_name(const device_t *dev) { - if (d == NULL) + if (dev == NULL) return ""; - return (char *) d->internal_name; + return (char *) dev->internal_name; } void * -device_add(const device_t *d) +device_add(const device_t *dev) { - return device_add_common(d, d, NULL, NULL, 0); + return device_add_common(dev, dev, NULL, NULL, 0); } void * -device_add_parameters(const device_t *d, void *params) +device_add_parameters(const device_t *dev, void *params) { - return device_add_common(d, d, NULL, params, 0); + return device_add_common(dev, dev, NULL, params, 0); } /* For devices that do not have an init function (internal video etc.) */ void -device_add_ex(const device_t *d, void *priv) +device_add_ex(const device_t *dev, void *priv) { - device_add_common(d, d, priv, NULL, 0); + device_add_common(dev, dev, priv, NULL, 0); } void -device_add_ex_parameters(const device_t *d, void *priv, void *params) +device_add_ex_parameters(const device_t *dev, void *priv, void *params) { - device_add_common(d, d, priv, params, 0); + device_add_common(dev, dev, priv, params, 0); } void * -device_add_inst(const device_t *d, int inst) +device_add_inst(const device_t *dev, int inst) { - return device_add_common(d, d, NULL, NULL, inst); + return device_add_common(dev, dev, NULL, NULL, inst); } void * -device_add_inst_parameters(const device_t *d, int inst, void *params) +device_add_inst_parameters(const device_t *dev, int inst, void *params) { - return device_add_common(d, d, NULL, params, inst); + return device_add_common(dev, dev, NULL, params, inst); } /* For devices that do not have an init function (internal video etc.) */ void -device_add_inst_ex(const device_t *d, void *priv, int inst) +device_add_inst_ex(const device_t *dev, void *priv, int inst) { - device_add_common(d, d, priv, NULL, inst); + device_add_common(dev, dev, priv, NULL, inst); } void -device_add_inst_ex_parameters(const device_t *d, void *priv, int inst, void *params) +device_add_inst_ex_parameters(const device_t *dev, void *priv, int inst, void *params) { - device_add_common(d, d, priv, params, inst); + device_add_common(dev, dev, priv, params, inst); } /* These eight are to add a device with another device's context - will be used to add machines' internal devices. */ void * -device_cadd(const device_t *d, const device_t *cd) +device_cadd(const device_t *dev, const device_t *cd) { - return device_add_common(d, cd, NULL, NULL, 0); + return device_add_common(dev, cd, NULL, NULL, 0); } void * -device_cadd_parameters(const device_t *d, const device_t *cd, void *params) +device_cadd_parameters(const device_t *dev, const device_t *cd, void *params) { - return device_add_common(d, cd, NULL, params, 0); + return device_add_common(dev, cd, NULL, params, 0); } /* For devices that do not have an init function (internal video etc.) */ void -device_cadd_ex(const device_t *d, const device_t *cd, void *priv) +device_cadd_ex(const device_t *dev, const device_t *cd, void *priv) { - device_add_common(d, cd, priv, NULL, 0); + device_add_common(dev, cd, priv, NULL, 0); } void -device_cadd_ex_parameters(const device_t *d, const device_t *cd, void *priv, void *params) +device_cadd_ex_parameters(const device_t *dev, const device_t *cd, void *priv, void *params) { - device_add_common(d, cd, priv, params, 0); + device_add_common(dev, cd, priv, params, 0); } void * -device_cadd_inst(const device_t *d, const device_t *cd, int inst) +device_cadd_inst(const device_t *dev, const device_t *cd, int inst) { - return device_add_common(d, cd, NULL, NULL, inst); + return device_add_common(dev, cd, NULL, NULL, inst); } void * -device_cadd_inst_parameters(const device_t *d, const device_t *cd, int inst, void *params) +device_cadd_inst_parameters(const device_t *dev, const device_t *cd, int inst, void *params) { - return device_add_common(d, cd, NULL, params, inst); + return device_add_common(dev, cd, NULL, params, inst); } /* For devices that do not have an init function (internal video etc.) */ void -device_cadd_inst_ex(const device_t *d, const device_t *cd, void *priv, int inst) +device_cadd_inst_ex(const device_t *dev, const device_t *cd, void *priv, int inst) { - device_add_common(d, cd, priv, NULL, inst); + device_add_common(dev, cd, priv, NULL, inst); } void -device_cadd_inst_ex_parameters(const device_t *d, const device_t *cd, void *priv, int inst, void *params) +device_cadd_inst_ex_parameters(const device_t *dev, const device_t *cd, void *priv, int inst, void *params) { - device_add_common(d, cd, priv, params, inst); + device_add_common(dev, cd, priv, params, inst); } void device_close_all(void) { - int c; - - for (c = (DEVICE_MAX - 1); c >= 0; c--) { + for (int16_t c = (DEVICE_MAX - 1); c >= 0; c--) { if (devices[c] != NULL) { if (devices[c]->name) device_log("Closing device: \"%s\"...\n", devices[c]->name); @@ -315,40 +317,22 @@ device_close_all(void) } void -device_reset_all(void) +device_reset_all(uint32_t match_flags) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { - if (devices[c]->reset != NULL) - devices[c]->reset(device_priv[c]); - } - } -} - -/* Reset all attached PCI devices - needed for PCI turbo reset control. */ -void -device_reset_all_pci(void) -{ - int c; - - for (c = 0; c < DEVICE_MAX; c++) { - if (devices[c] != NULL) { - if ((devices[c]->reset != NULL) && (devices[c]->flags & DEVICE_PCI)) + if ((devices[c]->reset != NULL) && (devices[c]->flags & match_flags)) devices[c]->reset(device_priv[c]); } } } void * -device_get_priv(const device_t *d) +device_get_priv(const device_t *dev) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { - if (devices[c] == d) + if (devices[c] == dev) return (device_priv[c]); } } @@ -357,25 +341,25 @@ device_get_priv(const device_t *d) } int -device_available(const device_t *d) +device_available(const device_t *dev) { - device_config_t *config = NULL; - device_config_bios_t *bios = NULL; - int bf, roms_present = 0; - int i = 0; + const device_config_t *config = NULL; + const device_config_bios_t *bios = NULL; + int roms_present = 0; + int i = 0; - if (d != NULL) { - config = (device_config_t *) d->config; + if (dev != NULL) { + config = dev->config; if (config != NULL) { while (config->type != -1) { if (config->type == CONFIG_BIOS) { - bios = (device_config_bios_t *) config->bios; + bios = (const device_config_bios_t *) config->bios; /* Go through the ROM's in the device configuration. */ while (bios->files_no != 0) { i = 0; - for (bf = 0; bf < bios->files_no; bf++) - i += !!rom_present((char *) bios->files[bf]); + for (int bf = 0; bf < bios->files_no; bf++) + i += !!rom_present(bios->files[bf]); if (i == bios->files_no) roms_present++; bios++; @@ -388,28 +372,28 @@ device_available(const device_t *d) } /* No CONFIG_BIOS field present, use the classic available(). */ - if (d->available != NULL) - return (d->available()); + if (dev->available != NULL) + return (dev->available()); else - return (1); + return 1; } /* A NULL device is never available. */ - return (0); + return 0; } const char * -device_get_bios_file(const device_t *d, const char *internal_name, int file_no) +device_get_bios_file(const device_t *dev, const char *internal_name, int file_no) { - device_config_t *config = NULL; - device_config_bios_t *bios = NULL; + const device_config_t *config = NULL; + const device_config_bios_t *bios = NULL; - if (d != NULL) { - config = (device_config_t *) d->config; + if (dev != NULL) { + config = dev->config; if (config != NULL) { while (config->type != -1) { if (config->type == CONFIG_BIOS) { - bios = (device_config_bios_t *) config->bios; + bios = config->bios; /* Go through the ROM's in the device configuration. */ while (bios->files_no != 0) { @@ -432,18 +416,18 @@ device_get_bios_file(const device_t *d, const char *internal_name, int file_no) } int -device_has_config(const device_t *d) +device_has_config(const device_t *dev) { - int c = 0; - device_config_t *config; + int c = 0; + const device_config_t *config; - if (d == NULL) + if (dev == NULL) return 0; - if (d->config == NULL) + if (dev->config == NULL) return 0; - config = (device_config_t *) d->config; + config = dev->config; while (config->type != -1) { if (config->type != CONFIG_MAC) @@ -455,30 +439,26 @@ device_has_config(const device_t *d) } int -device_poll(const device_t *d, int x, int y, int z, int b) +device_poll(const device_t *dev, int x, int y, int z, int b) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { - if (devices[c] == d) { + if (devices[c] == dev) { if (devices[c]->poll) return (devices[c]->poll(x, y, z, b, 0, 0, device_priv[c])); } } } - return (0); + return 0; } void -device_register_pci_slot(const device_t *d, int device, int type, int inta, int intb, int intc, int intd) +device_register_pci_slot(const device_t *dev, int device, int type, int inta, int intb, int intc, int intd) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { - if (devices[c] == d) { + if (devices[c] == dev) { if (devices[c]->register_pci_slot) devices[c]->register_pci_slot(device, type, inta, intb, intc, intd, device_priv[c]); return; @@ -490,36 +470,38 @@ device_register_pci_slot(const device_t *d, int device, int type, int inta, int } void -device_get_name(const device_t *d, int bus, char *name) +device_get_name(const device_t *dev, int bus, char *name) { - char *sbus = NULL, *fbus; - char *tname, pbus[8] = { 0 }; + const char *sbus = NULL; + const char *fbus; + char *tname; + char pbus[8] = { 0 }; - if (d == NULL) + if (dev == NULL) return; name[0] = 0x00; if (bus) { - if (d->flags & DEVICE_ISA) - sbus = (d->flags & DEVICE_AT) ? "ISA16" : "ISA"; - else if (d->flags & DEVICE_CBUS) + if (dev->flags & DEVICE_ISA) + sbus = (dev->flags & DEVICE_AT) ? "ISA16" : "ISA"; + else if (dev->flags & DEVICE_CBUS) sbus = "C-BUS"; - else if (d->flags & DEVICE_MCA) + else if (dev->flags & DEVICE_MCA) sbus = "MCA"; - else if (d->flags & DEVICE_EISA) + else if (dev->flags & DEVICE_EISA) sbus = "EISA"; - else if (d->flags & DEVICE_VLB) + else if (dev->flags & DEVICE_VLB) sbus = "VLB"; - else if (d->flags & DEVICE_PCI) + else if (dev->flags & DEVICE_PCI) sbus = "PCI"; - else if (d->flags & DEVICE_AGP) + else if (dev->flags & DEVICE_AGP) sbus = "AGP"; - else if (d->flags & DEVICE_AC97) + else if (dev->flags & DEVICE_AC97) sbus = "AMR"; - else if (d->flags & DEVICE_COM) + else if (dev->flags & DEVICE_COM) sbus = "COM"; - else if (d->flags & DEVICE_LPT) + else if (dev->flags & DEVICE_LPT) sbus = "LPT"; if (sbus != NULL) { @@ -533,7 +515,7 @@ device_get_name(const device_t *d, int bus, char *name) sbus = "ISA"; else if (!strcmp(sbus, "COM") || !strcmp(sbus, "LPT")) { sbus = NULL; - strcat(name, d->name); + strcat(name, dev->name); return; } @@ -543,17 +525,17 @@ device_get_name(const device_t *d, int bus, char *name) strcat(pbus, ")"); /* Allocate the temporary device name string and set it to all zeroes. */ - tname = (char *) malloc(strlen(d->name) + 1); - memset(tname, 0x00, strlen(d->name) + 1); + tname = (char *) malloc(strlen(dev->name) + 1); + memset(tname, 0x00, strlen(dev->name) + 1); /* First strip the bus string with parentheses. */ - fbus = strstr(d->name, pbus); - if (fbus == d->name) - strcat(tname, d->name + strlen(pbus) + 1); + fbus = strstr(dev->name, pbus); + if (fbus == dev->name) + strcat(tname, dev->name + strlen(pbus) + 1); else if (fbus == NULL) - strcat(tname, d->name); + strcat(tname, dev->name); else { - strncat(tname, d->name, fbus - d->name - 1); + strncat(tname, dev->name, fbus - dev->name - 1); strcat(tname, fbus + strlen(pbus)); } @@ -574,17 +556,15 @@ device_get_name(const device_t *d, int bus, char *name) free(tname); tname = NULL; } else - strcat(name, d->name); + strcat(name, dev->name); } else - strcat(name, d->name); + strcat(name, dev->name); } void device_speed_changed(void) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if (devices[c]->speed_changed != NULL) devices[c]->speed_changed(device_priv[c]); @@ -597,9 +577,7 @@ device_speed_changed(void) void device_force_redraw(void) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if (devices[c]->force_redraw != NULL) devices[c]->force_redraw(device_priv[c]); @@ -640,7 +618,7 @@ device_get_config_int(const char *s) c++; } - return (0); + return 0; } int @@ -655,7 +633,7 @@ device_get_config_int_ex(const char *s, int def) c++; } - return (def); + return def; } int @@ -670,7 +648,7 @@ device_get_config_hex16(const char *s) c++; } - return (0); + return 0; } int @@ -685,7 +663,7 @@ device_get_config_hex20(const char *s) c++; } - return (0); + return 0; } int @@ -700,7 +678,7 @@ device_get_config_mac(const char *s, int def) c++; } - return (def); + return def; } void @@ -767,39 +745,39 @@ int device_is_valid(const device_t *device, int m) { if (device == NULL) - return (1); + return 1; if ((device->flags & DEVICE_AT) && !machine_has_bus(m, MACHINE_BUS_ISA16)) - return (0); + return 0; if ((device->flags & DEVICE_CBUS) && !machine_has_bus(m, MACHINE_BUS_CBUS)) - return (0); + return 0; if ((device->flags & DEVICE_ISA) && !machine_has_bus(m, MACHINE_BUS_ISA)) - return (0); + return 0; if ((device->flags & DEVICE_MCA) && !machine_has_bus(m, MACHINE_BUS_MCA)) - return (0); + return 0; if ((device->flags & DEVICE_EISA) && !machine_has_bus(m, MACHINE_BUS_EISA)) - return (0); + return 0; if ((device->flags & DEVICE_VLB) && !machine_has_bus(m, MACHINE_BUS_VLB)) - return (0); + return 0; if ((device->flags & DEVICE_PCI) && !machine_has_bus(m, MACHINE_BUS_PCI)) - return (0); + return 0; if ((device->flags & DEVICE_AGP) && !machine_has_bus(m, MACHINE_BUS_AGP)) - return (0); + return 0; - if ((device->flags & DEVICE_PS2) && !machine_has_bus(m, MACHINE_BUS_PS2)) - return (0); + if ((device->flags & DEVICE_PS2) && !machine_has_bus(m, MACHINE_BUS_PS2_PORTS)) + return 0; if ((device->flags & DEVICE_AC97) && !machine_has_bus(m, MACHINE_BUS_AC97)) - return (0); + return 0; - return (1); + return 1; } int @@ -809,7 +787,7 @@ machine_get_config_int(char *s) const device_config_t *c; if (d == NULL) - return (0); + return 0; c = d->config; while (c && c->type != -1) { @@ -819,7 +797,7 @@ machine_get_config_int(char *s) c++; } - return (0); + return 0; } char * @@ -829,7 +807,7 @@ machine_get_config_string(char *s) const device_config_t *c; if (d == NULL) - return (0); + return 0; c = d->config; while (c && c->type != -1) { @@ -839,5 +817,5 @@ machine_get_config_string(char *s) c++; } - return (NULL); + return NULL; } diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index e60856293..ef3a392ee 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -18,7 +18,9 @@ add_library(dev OBJECT bugger.c cassette.c cartridge.c hasp.c hwm.c hwm_lm75.c hwm_lm78.c hwm_gl518sm.c hwm_vt82c686.c ibm_5161.c isamem.c isartc.c ../lpt.c pci_bridge.c postcard.c serial.c clock_ics9xxx.c isapnp.c i2c.c i2c_gpio.c - smbus_piix4.c smbus_ali7101.c keyboard.c keyboard_xt.c keyboard_at.c + smbus_piix4.c smbus_ali7101.c keyboard.c keyboard_xt.c + kbc_at.c kbc_at_dev.c + keyboard_at.c mouse.c mouse_bus.c mouse_serial.c mouse_ps2.c phoenix_486_jumper.c mouse_wacom_tablet.c serial_passthrough.c) diff --git a/src/device/bugger.c b/src/device/bugger.c index 920fc4cef..c2678d66a 100644 --- a/src/device/bugger.c +++ b/src/device/bugger.c @@ -74,14 +74,16 @@ #define CTRL_RESET 0xff /* this resets the board */ #define BUG_DATA 1 -static uint8_t bug_ctrl, /* control register */ - bug_data, /* data register */ - bug_ledr, bug_ledg, /* RED and GREEN LEDs */ - bug_seg1, bug_seg2, /* LEFT and RIGHT 7SEG displays */ - bug_spcfg; /* serial port configuration */ +static uint8_t bug_ctrl; /* control register */ +static uint8_t bug_data; /* data register */ +static uint8_t bug_ledr; /* RED LEDs */ +static uint8_t bug_ledg; /* GREEN LEDs */ +static uint8_t bug_seg1; +static uint8_t bug_seg2; /* LEFT and RIGHT 7SEG displays */ +static uint8_t bug_spcfg; /* serial port configuration */ #define FIFO_LEN 256 -static uint8_t bug_buff[FIFO_LEN], /* serial port data buffer */ - *bug_bptr; +static uint8_t bug_buff[FIFO_LEN]; /* serial port data buffer */ +static uint8_t *bug_bptr; #define UISTR_LEN 24 static char bug_str[UISTR_LEN]; /* UI output string */ @@ -264,7 +266,7 @@ bug_reset(void) /* Handle a WRITE operation to one of our registers. */ static void -bug_write(uint16_t port, uint8_t val, void *priv) +bug_write(uint16_t port, uint8_t val, UNUSED(void *priv)) { switch (port - BUGGER_ADDR) { case BUG_CTRL: /* control register */ @@ -282,12 +284,14 @@ bug_write(uint16_t port, uint8_t val, void *priv) bug_wdata(val); } break; + default: + break; } } /* Handle a READ operation from one of our registers. */ static uint8_t -bug_read(uint16_t port, void *priv) +bug_read(uint16_t port, UNUSED(void *priv)) { uint8_t ret = 0xff; @@ -312,12 +316,12 @@ bug_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } /* Initialize the ISA BusBugger emulator. */ static void * -bug_init(const device_t *info) +bug_init(UNUSED(const device_t *info)) { bugger_log("%s, I/O=%04x\n", info->name, BUGGER_ADDR); diff --git a/src/device/cartridge.c b/src/device/cartridge.c index 943ca2cb9..5d8e6cc4c 100644 --- a/src/device/cartridge.c +++ b/src/device/cartridge.c @@ -29,8 +29,7 @@ #include <86box/machine.h> #include <86box/cartridge.h> -typedef struct -{ +typedef struct cart_t { uint8_t *buf; uint32_t base; } cart_t; @@ -62,13 +61,13 @@ cartridge_log(const char *fmt, ...) static uint8_t cart_read(uint32_t addr, void *priv) { - cart_t *dev = (cart_t *) priv; + const cart_t *dev = (cart_t *) priv; return dev->buf[addr - dev->base]; } static void -cart_load_error(int drive, char *fn) +cart_load_error(int drive, UNUSED(char *fn)) { cartridge_log("Cartridge: could not load '%s'\n", fn); memset(cart_fns[drive], 0, sizeof(cart_fns[drive])); @@ -175,15 +174,13 @@ cart_close(int drive) void cart_reset(void) { - int i; - cart_image_close(1); cart_image_close(0); if (!machine_has_cartridge(machine)) return; - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { mem_mapping_add(&cart_mappings[i], 0x000d0000, 0x00002000, cart_read, NULL, NULL, NULL, NULL, NULL, diff --git a/src/device/cassette.c b/src/device/cassette.c index 8d8f15c80..17b650e81 100644 --- a/src/device/cassette.c +++ b/src/device/cassette.c @@ -45,9 +45,11 @@ pc_cassette_t *cassette; char cassette_fname[512]; char cassette_mode[512]; -unsigned long cassette_pos, cassette_srate; +unsigned long cassette_pos; +unsigned long cassette_srate; int cassette_enable; -int cassette_append, cassette_pcm; +int cassette_append; +int cassette_pcm; int cassette_ui_writeprot; static int cassette_cycles = -1; @@ -138,7 +140,7 @@ pc_cas_new(void) pc_cas_init(cas); - return (cas); + return cas; } void @@ -172,7 +174,7 @@ pc_cas_set_fname(pc_cassette_t *cas, const char *fname) if (fname == NULL) { ui_sb_update_icon_state(SB_CASSETTE, 1); - return (0); + return 0; } cas->fp = plat_fopen(fname, "r+b"); @@ -182,7 +184,7 @@ pc_cas_set_fname(pc_cassette_t *cas, const char *fname) if (cas->fp == NULL) { ui_sb_update_icon_state(SB_CASSETTE, 1); - return (1); + return 1; } cas->close = 1; @@ -215,14 +217,12 @@ pc_cas_set_fname(pc_cassette_t *cas, const char *fname) pc_cas_set_pcm(cas, 0); } - return (0); + return 0; } static void pc_cas_reset(pc_cassette_t *cas) { - unsigned i; - cas->clk_pcm = 0; cas->clk_out = cas->clk; @@ -237,7 +237,7 @@ pc_cas_reset(pc_cassette_t *cas) cas->cas_inp_buf = 0; cas->cas_inp_bit = 0; - for (i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { cas->pcm_inp_fir[i] = 0; } } @@ -344,18 +344,18 @@ int pc_cas_set_position(pc_cassette_t *cas, unsigned long pos) { if (cas->fp == NULL) { - return (1); + return 1; } if (fseek(cas->fp, pos, SEEK_SET) != 0) { - return (1); + return 1; } cas->position = pos; pc_cas_reset(cas); - return (0); + return 0; } static void @@ -394,17 +394,18 @@ pc_cas_read_bit(pc_cassette_t *cas) static int pc_cas_read_smp(pc_cassette_t *cas) { - int smp, *fir; + int smp; + int *fir; if (feof(cas->fp)) { - return (0); + return 0; } smp = fgetc(cas->fp); if (smp == EOF) { cassette_log("cassette EOF at %lu\n", cas->position); - return (0); + return 0; } cas->position += 1; @@ -417,7 +418,7 @@ pc_cas_read_smp(pc_cassette_t *cas) smp = (fir[0] + 2 * fir[1] + fir[2]) / 4; - return (smp); + return smp; } static void @@ -461,8 +462,6 @@ pc_cas_write_smp(pc_cassette_t *cas, int val) void pc_cas_set_motor(pc_cassette_t *cas, unsigned char val) { - unsigned i; - val = (val != 0); if (val == cas->motor) { @@ -470,7 +469,7 @@ pc_cas_set_motor(pc_cassette_t *cas, unsigned char val) } if ((val == 0) && cas->save && cas->pcm) { - for (i = 0; i < (cas->srate / 16); i++) { + for (unsigned long i = 0; i < (cas->srate / 16); i++) { pc_cas_write_smp(cas, 0); } } @@ -545,7 +544,7 @@ pc_cas_set_out(pc_cassette_t *cas, unsigned char val) } void -pc_cas_print_state(const pc_cassette_t *cas) +pc_cas_print_state(UNUSED(const pc_cassette_t *cas)) { cassette_log("%s %s %lu %s %lu\n", (cas->fname != NULL) ? cas->fname : "", cas->pcm ? "pcm" : "cas", cas->srate, cas->save ? "save" : "load", cas->position); } @@ -553,8 +552,8 @@ pc_cas_print_state(const pc_cassette_t *cas) static void pc_cas_clock_pcm(pc_cassette_t *cas, unsigned long cnt) { - unsigned long i, n; - int v = 0; + uint64_t n; + int v = 0; n = cas->srate * cnt + cas->clk_pcm; @@ -567,11 +566,11 @@ pc_cas_clock_pcm(pc_cassette_t *cas, unsigned long cnt) } if (cas->save) { - for (i = 0; i < n; i++) { + for (uint64_t i = 0; i < n; i++) { pc_cas_write_smp(cas, cas->pcm_out_val); } } else { - for (i = 0; i < n; i++) { + for (uint64_t i = 0; i < n; i++) { v = pc_cas_read_smp(cas); } @@ -642,7 +641,7 @@ pc_cas_advance(pc_cassette_t *cas) } static void -cassette_close(void *p) +cassette_close(UNUSED(void *priv)) { if (cassette != NULL) { free(cassette); @@ -664,7 +663,7 @@ cassette_callback(void *p) } static void * -cassette_init(const device_t *info) +cassette_init(UNUSED(const device_t *info)) { cassette = NULL; diff --git a/src/device/clock_ics9xxx.c b/src/device/clock_ics9xxx.c index 7b04c5688..21a4c14ba 100644 --- a/src/device/clock_ics9xxx.c +++ b/src/device/clock_ics9xxx.c @@ -26,6 +26,7 @@ #include <86box/i2c.h> #include "cpu.h" #include <86box/clock.h> +#include <86box/plat_unused.h> #ifdef ENABLE_ICS9xxx_LOG int ics9xxx_do_log = ENABLE_ICS9xxx_LOG; @@ -51,26 +52,26 @@ ics9xxx_log(const char *fmt, ...) , #define agp_div ram_mult /* temporarily saves space while neither field matters */ -typedef struct { +typedef struct ics9xxx_frequency_t { uint16_t bus : 15; uint8_t ram_mult : 2; /* change to full float when this becomes useful */ uint8_t pci_div : 3; } ics9xxx_frequency_t; -typedef struct { +typedef struct ics9xxx_model_t { #if defined(ENABLE_ICS9xxx_LOG) || defined(ENABLE_ICS9xxx_DETECT) const char *name; /* populated by macro */ #endif uint8_t max_reg : 3; /* largest register index */ uint8_t regs[7]; /* default registers */ - struct { /* for each hardware frequency select bit [FS0:FS4]: */ + struct fs_regs { /* for each hardware frequency select bit [FS0:FS4]: */ uint8_t normal_reg : 3; /* which register (or -1) for non-inverted input (FSn) */ uint8_t normal_bit : 3; /* which bit (0-7) for non-inverted input (FSn) */ uint8_t inv_reg : 3; /* which register (or -1) for inverted input (FSn#) */ uint8_t inv_bit : 3; /* which bit (0-7) for inverted input (FSn#) */ } fs_regs[5]; uint8_t normal_bits_fixed : 1; /* set to 1 if the non-inverted bits are straps (hardware select only) */ - struct { /* hardware select bit, which should be cleared for hardware select (latched inputs), or set for programming */ + struct hw_select { /* hardware select bit, which should be cleared for hardware select (latched inputs), or set for programming */ uint8_t normal_reg : 3; /* which register (or -1) */ uint8_t normal_bit : 3; /* which bit (0-7) */ } hw_select; @@ -79,7 +80,7 @@ typedef struct { const ics9xxx_frequency_t *frequencies; /* frequency table, if not using another model's table */ } ics9xxx_model_t; -typedef struct { +typedef struct ics9xxx_t { uint8_t model_idx; ics9xxx_model_t *model; device_t *dyn_device; @@ -941,7 +942,10 @@ ics9xxx_detect(ics9xxx_t *dev) if (!(dev->regs[detect_reg] & 0x40)) pclog("Bit 3 of register %d is clear, probably in hardware select mode!\n", detect_reg); - uint8_t i = 0, matches = 0, val, bitmask; + uint8_t i = 0; + uint8_t matches = 0; + uint8_t val; + uint8_t bitmask; ics9xxx_frequency_t *frequencies_ptr; uint32_t delta; for (uint8_t j = 0; j < ICS9xxx_MAX; j++) { @@ -983,7 +987,7 @@ ics9xxx_detect(ics9xxx_t *dev) #endif static uint8_t -ics9xxx_start(void *bus, uint8_t addr, uint8_t read, void *priv) +ics9xxx_start(UNUSED(void *bus), UNUSED(uint8_t addr), UNUSED(uint8_t read), void *priv) { ics9xxx_t *dev = (ics9xxx_t *) priv; @@ -995,7 +999,7 @@ ics9xxx_start(void *bus, uint8_t addr, uint8_t read, void *priv) } static uint8_t -ics9xxx_read(void *bus, uint8_t addr, void *priv) +ics9xxx_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { ics9xxx_t *dev = (ics9xxx_t *) priv; uint8_t ret = 0xff; @@ -1049,7 +1053,7 @@ ics9xxx_set(ics9xxx_t *dev, uint8_t val) } static uint8_t -ics9xxx_write(void *bus, uint8_t addr, uint8_t data, void *priv) +ics9xxx_write(UNUSED(void *bus), UNUSED(uint8_t addr), uint8_t data, void *priv) { ics9xxx_t *dev = (ics9xxx_t *) priv; @@ -1147,7 +1151,8 @@ static uint8_t ics9xxx_find_bus_match(ics9xxx_t *dev, uint32_t bus, uint8_t preset_mask, uint8_t preset) { uint8_t best_match = 0; - uint32_t delta, best_delta = -1; + uint32_t delta; + uint32_t best_delta = -1; #ifdef ENABLE_ICS9xxx_DETECT if (dev->model_idx == ICS9xxx_xx) diff --git a/src/device/hasp.c b/src/device/hasp.c index 8c71e1f3f..9873c3460 100644 --- a/src/device/hasp.c +++ b/src/device/hasp.c @@ -52,9 +52,11 @@ enum { HASP_TYPE_SAVQUEST = 0 }; -typedef struct { - const uint8_t *password, *prodinfo; - const uint8_t password_size, prodinfo_size; +typedef struct hasp_type_t { + const uint8_t *password; + const uint8_t *prodinfo; + const uint8_t password_size; + const uint8_t prodinfo_size; } hasp_type_t; typedef struct @@ -62,8 +64,13 @@ typedef struct void *lpt; const hasp_type_t *type; - int index, state, passindex, passmode, prodindex; - uint8_t tmppass[0x29], status; + int index; + int state; + int passindex; + int passmode; + int prodindex; + uint8_t tmppass[0x29]; + uint8_t status; } hasp_t; static const hasp_type_t hasp_types[] = { @@ -131,6 +138,8 @@ hasp_write_data(uint8_t val, void *priv) return; } break; + default: + break; } dev->status = 0; @@ -163,6 +172,8 @@ hasp_write_data(uint8_t val, void *priv) I guessed the implicit ones with a bit of trial and error */ dev->status = 0x20; return; + default: + break; } } @@ -199,6 +210,8 @@ hasp_write_data(uint8_t val, void *priv) /* again, just the relevant bits instead of the true values */ dev->status = 0x20; break; + default: + break; } } else if (dev->state == HASP_STATE_PASSWORD_END) { if (val & 1) { diff --git a/src/device/hwm_gl518sm.c b/src/device/hwm_gl518sm.c index 730e2f2ce..01f917b32 100644 --- a/src/device/hwm_gl518sm.c +++ b/src/device/hwm_gl518sm.c @@ -27,6 +27,8 @@ #include <86box/io.h> #include <86box/i2c.h> #include <86box/hwm.h> +#include <86box/plat_unused.h> + #define CLAMP(a, min, max) (((a) < (min)) ? (min) : (((a) > (max)) ? (max) : (a))) /* Formulas and factors derived from Linux's gl518sm.c driver. */ @@ -34,14 +36,16 @@ #define GL518SM_VOLTAGE_TO_REG(v) ((uint8_t) round((v) / 19.0)) #define GL518SM_VDD_TO_REG(v) ((uint8_t) (((v) *4) / 95.0)) -typedef struct { +typedef struct gl518sm_t { uint32_t local; hwm_values_t *values; uint16_t regs[32]; uint8_t addr_register : 5; - uint8_t i2c_addr : 7, i2c_state : 2, i2c_enabled : 1; + uint8_t i2c_addr : 7; + uint8_t i2c_state : 2; + uint8_t i2c_enabled : 1; } gl518sm_t; static uint8_t gl518sm_i2c_start(void *bus, uint8_t addr, uint8_t read, void *priv); @@ -85,7 +89,7 @@ gl518sm_remap(gl518sm_t *dev, uint8_t addr) } static uint8_t -gl518sm_i2c_start(void *bus, uint8_t addr, uint8_t read, void *priv) +gl518sm_i2c_start(UNUSED(void *bus), UNUSED(uint8_t addr), UNUSED(uint8_t read), void *priv) { gl518sm_t *dev = (gl518sm_t *) priv; @@ -95,7 +99,7 @@ gl518sm_i2c_start(void *bus, uint8_t addr, uint8_t read, void *priv) } static uint8_t -gl518sm_i2c_read(void *bus, uint8_t addr, void *priv) +gl518sm_i2c_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { gl518sm_t *dev = (gl518sm_t *) priv; uint16_t read = gl518sm_read(dev, dev->addr_register); @@ -159,7 +163,7 @@ gl518sm_read(gl518sm_t *dev, uint8_t reg) } static uint8_t -gl518sm_i2c_write(void *bus, uint8_t addr, uint8_t data, void *priv) +gl518sm_i2c_write(UNUSED(void *bus), UNUSED(uint8_t addr), uint8_t data, void *priv) { gl518sm_t *dev = (gl518sm_t *) priv; diff --git a/src/device/hwm_lm75.c b/src/device/hwm_lm75.c index fdfff0e44..14b638365 100644 --- a/src/device/hwm_lm75.c +++ b/src/device/hwm_lm75.c @@ -25,6 +25,7 @@ #include <86box/device.h> #include <86box/i2c.h> #include <86box/hwm.h> +#include <86box/plat_unused.h> #define LM75_TEMP_TO_REG(t) ((t) << 8) @@ -47,7 +48,7 @@ lm75_log(const char *fmt, ...) #endif static uint8_t -lm75_i2c_start(void *bus, uint8_t addr, uint8_t read, void *priv) +lm75_i2c_start(UNUSED(void *bus), UNUSED(uint8_t addr), UNUSED(uint8_t read), void *priv) { lm75_t *dev = (lm75_t *) priv; @@ -74,7 +75,7 @@ lm75_read(lm75_t *dev, uint8_t reg) } static uint8_t -lm75_i2c_read(void *bus, uint8_t addr, void *priv) +lm75_i2c_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { lm75_t *dev = (lm75_t *) priv; uint8_t ret = 0; @@ -103,6 +104,8 @@ lm75_i2c_read(void *bus, uint8_t addr, void *priv) case 0x3: /* Tos */ ret = lm75_read(dev, (dev->i2c_state == 1) ? 0x5 : 0x6); break; + default: + break; } } @@ -128,7 +131,7 @@ lm75_write(lm75_t *dev, uint8_t reg, uint8_t val) } static uint8_t -lm75_i2c_write(void *bus, uint8_t addr, uint8_t data, void *priv) +lm75_i2c_write(UNUSED(void *bus), UNUSED(uint8_t addr), uint8_t data, void *priv) { lm75_t *dev = (lm75_t *) priv; @@ -164,6 +167,9 @@ lm75_i2c_write(void *bus, uint8_t addr, uint8_t data, void *priv) case 0x3: /* Tos */ lm75_write(dev, (dev->i2c_state == 1) ? 0x5 : 0x6, data); break; + + default: + break; } } diff --git a/src/device/hwm_lm78.c b/src/device/hwm_lm78.c index f7585945a..74752a089 100644 --- a/src/device/hwm_lm78.c +++ b/src/device/hwm_lm78.c @@ -27,6 +27,7 @@ #include <86box/timer.h> #include <86box/machine.h> #include <86box/nvr.h> +#include <86box/plat_unused.h> #include "cpu.h" #include <86box/i2c.h> #include <86box/hwm.h> @@ -48,7 +49,7 @@ #define LM78_NEG_VOLTAGE(v, r) (v * (604.0 / ((double) r))) /* negative voltage formula from the W83781D datasheet */ #define LM78_NEG_VOLTAGE2(v, r) (((3600 + v) * (((double) r) / (((double) r) + 56.0))) - v) /* negative voltage formula from the W83782D datasheet */ -typedef struct { +typedef struct lm78_t { uint32_t local; hwm_values_t *values; device_t *lm75[2]; @@ -56,10 +57,10 @@ typedef struct { uint8_t regs[256]; union { - struct { + struct w83782d { uint8_t regs[2][16]; } w83782d; - struct { + struct as99127f { uint8_t regs[3][128]; uint8_t nvram[1024], nvram_i2c_state : 2, nvram_updated : 1; @@ -69,9 +70,12 @@ typedef struct { uint8_t security_i2c_state : 1, security_addr_register : 7; } as99127f; }; - uint8_t addr_register, data_register; + uint8_t addr_register; + uint8_t data_register; - uint8_t i2c_addr : 7, i2c_state : 1, i2c_enabled : 1; + uint8_t i2c_addr : 7; + uint8_t i2c_state : 1; + uint8_t i2c_enabled : 1; } lm78_t; static void lm78_remap(lm78_t *dev, uint8_t addr); @@ -114,7 +118,7 @@ lm78_nvram(lm78_t *dev, uint8_t save) } static uint8_t -lm78_nvram_start(void *bus, uint8_t addr, uint8_t read, void *priv) +lm78_nvram_start(UNUSED(void *bus), UNUSED(uint8_t addr), UNUSED(uint8_t read), void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -124,7 +128,7 @@ lm78_nvram_start(void *bus, uint8_t addr, uint8_t read, void *priv) } static uint8_t -lm78_nvram_read(void *bus, uint8_t addr, void *priv) +lm78_nvram_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { lm78_t *dev = (lm78_t *) priv; uint8_t ret = 0xff; @@ -158,7 +162,7 @@ lm78_nvram_read(void *bus, uint8_t addr, void *priv) } static uint8_t -lm78_nvram_write(void *bus, uint8_t addr, uint8_t val, void *priv) +lm78_nvram_write(UNUSED(void *bus), uint8_t addr, uint8_t val, void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -195,7 +199,7 @@ lm78_nvram_write(void *bus, uint8_t addr, uint8_t val, void *priv) } static uint8_t -lm78_security_start(void *bus, uint8_t addr, uint8_t read, void *priv) +lm78_security_start(UNUSED(void *bus), UNUSED(uint8_t addr), UNUSED(uint8_t read), void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -205,7 +209,7 @@ lm78_security_start(void *bus, uint8_t addr, uint8_t read, void *priv) } static uint8_t -lm78_security_read(void *bus, uint8_t addr, void *priv) +lm78_security_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -213,7 +217,7 @@ lm78_security_read(void *bus, uint8_t addr, void *priv) } static uint8_t -lm78_security_write(void *bus, uint8_t addr, uint8_t val, void *priv) +lm78_security_write(UNUSED(void *bus), UNUSED(uint8_t addr), uint8_t val, void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -229,6 +233,8 @@ lm78_security_write(void *bus, uint8_t addr, uint8_t val, void *priv) case 0xe7: /* read-only registers */ return 1; + default: + break; } dev->as99127f.regs[2][dev->as99127f.security_addr_register++] = val; @@ -316,7 +322,7 @@ lm78_reset(void *priv) } static uint8_t -lm78_i2c_start(void *bus, uint8_t addr, uint8_t read, void *priv) +lm78_i2c_start(UNUSED(void *bus), UNUSED(uint8_t addr), UNUSED(uint8_t read), void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -328,7 +334,9 @@ lm78_i2c_start(void *bus, uint8_t addr, uint8_t read, void *priv) static uint8_t lm78_read(lm78_t *dev, uint8_t reg, uint8_t bank) { - uint8_t ret = 0, masked_reg = reg, bankswitched = ((reg & 0xf8) == 0x50); + uint8_t ret = 0; + uint8_t masked_reg = reg; + uint8_t bankswitched = ((reg & 0xf8) == 0x50); lm75_t *lm75; if ((dev->local & LM78_AS99127F) && (bank == 3) && (reg != 0x4e)) { @@ -403,7 +411,7 @@ lm78_isa_read(uint16_t port, void *priv) } static uint8_t -lm78_i2c_read(void *bus, uint8_t addr, void *priv) +lm78_i2c_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -413,8 +421,8 @@ lm78_i2c_read(void *bus, uint8_t addr, void *priv) uint8_t lm78_as99127f_read(void *priv, uint8_t reg) { - lm78_t *dev = (lm78_t *) priv; - uint8_t ret = dev->as99127f.regs[1][reg & 0x7f]; + const lm78_t *dev = (lm78_t *) priv; + uint8_t ret = dev->as99127f.regs[1][reg & 0x7f]; lm78_log("LM78: read(%02X, AS99127F) = %02X\n", reg, ret); @@ -444,6 +452,8 @@ lm78_write(lm78_t *dev, uint8_t reg, uint8_t val, uint8_t bank) case 0x20: val &= 0x7f; break; + default: + break; } dev->as99127f.regs[0][reg] = val; @@ -475,6 +485,8 @@ lm78_write(lm78_t *dev, uint8_t reg, uint8_t val, uint8_t bank) case 0x5f: /* read-only registers */ return 0; + default: + break; } dev->w83782d.regs[0][reg & 0x0f] = val; @@ -495,6 +507,8 @@ lm78_write(lm78_t *dev, uint8_t reg, uint8_t val, uint8_t bank) case 0x5f: /* read-only registers */ return 0; + default: + break; } dev->w83782d.regs[1][reg & 0x0f] = val; @@ -557,6 +571,8 @@ lm78_write(lm78_t *dev, uint8_t reg, uint8_t val, uint8_t bank) if (!(dev->local & LM78_WINBOND)) return 0; break; + default: + break; } if ((reg >= 0x60) && (reg <= 0x94)) /* write auto-increment value RAM registers to their non-auto-increment locations */ @@ -611,6 +627,9 @@ lm78_write(lm78_t *dev, uint8_t reg, uint8_t val, uint8_t bank) i2c_sethandler(i2c_smbus, (val & 0xf8) >> 1, 4, lm78_nvram_start, lm78_nvram_read, lm78_nvram_write, NULL, dev); } break; + + default: + break; } return 1; @@ -642,7 +661,7 @@ lm78_isa_write(uint16_t port, uint8_t val, void *priv) } static uint8_t -lm78_i2c_write(void *bus, uint8_t addr, uint8_t val, void *priv) +lm78_i2c_write(UNUSED(void *bus), UNUSED(uint8_t addr), uint8_t val, void *priv) { lm78_t *dev = (lm78_t *) priv; @@ -692,13 +711,16 @@ lm78_as99127f_write(void *priv, uint8_t reg, uint8_t val) resetx86(); } break; + + default: + break; } return 1; } static void -lm78_reset_timer(void *priv) +lm78_reset_timer(UNUSED(void *priv)) { pc_reset_hard(); } diff --git a/src/device/hwm_vt82c686.c b/src/device/hwm_vt82c686.c index 877138a4a..b6a0dddda 100644 --- a/src/device/hwm_vt82c686.c +++ b/src/device/hwm_vt82c686.c @@ -25,6 +25,7 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/hwm.h> +#include <86box/plat_unused.h> #define CLAMP(a, min, max) (((a) < (min)) ? (min) : (((a) > (max)) ? (max) : (a))) /* Formulas and factors derived from Linux's via686a.c driver. */ @@ -32,7 +33,7 @@ #define VT82C686_TEMP_TO_REG(t) (-1.160370e-10 * (t * t * t * t * t * t) + 3.193693e-08 * (t * t * t * t * t) - 1.464447e-06 * (t * t * t * t) - 2.525453e-04 * (t * t * t) + 1.424593e-02 * (t * t) + 2.148941e+00 * t + 7.275808e+01) #define VT82C686_VOLTAGE_TO_REG(v, f) CLAMP((((v) * (2.628 / (f))) - 120.5) / 25, 0, 255) -typedef struct { +typedef struct vt82c686_t { hwm_values_t *values; uint8_t enable; @@ -47,8 +48,8 @@ static void vt82c686_reset(vt82c686_t *dev, uint8_t initialization); static uint8_t vt82c686_read(uint16_t addr, void *priv) { - vt82c686_t *dev = (vt82c686_t *) priv; - uint8_t ret; + const vt82c686_t *dev = (vt82c686_t *) priv; + uint8_t ret; addr -= dev->io_base; @@ -113,6 +114,9 @@ vt82c686_write(uint16_t port, uint8_t val, void *priv) case 0x48: val &= 0x7f; break; + + default: + break; } dev->regs[reg] = val; @@ -143,6 +147,9 @@ vt82c686_hwm_write(uint8_t addr, uint8_t val, void *priv) case 0x74: dev->enable = val & 0x01; break; + + default: + break; } if (dev->enable && dev->io_base) @@ -174,7 +181,7 @@ vt82c686_close(void *priv) } static void * -vt82c686_init(const device_t *info) +vt82c686_init(UNUSED(const device_t *info)) { vt82c686_t *dev = (vt82c686_t *) malloc(sizeof(vt82c686_t)); memset(dev, 0, sizeof(vt82c686_t)); diff --git a/src/device/i2c.c b/src/device/i2c.c index 17e795e74..56e6f8f4c 100644 --- a/src/device/i2c.c +++ b/src/device/i2c.c @@ -38,9 +38,10 @@ typedef struct _i2c_ { struct _i2c_ *prev, *next; } i2c_t; -typedef struct { +typedef struct i2c_bus_t { char *name; - i2c_t *devices[NADDRS], *last[NADDRS]; + i2c_t *devices[NADDRS]; + i2c_t *last[NADDRS]; } i2c_bus_t; void *i2c_smbus; @@ -77,14 +78,14 @@ i2c_addbus(char *name) void i2c_removebus(void *bus_handle) { - int c; - i2c_t *p, *q; + i2c_t *p; + i2c_t *q; i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus_handle) return; - for (c = 0; c < NADDRS; c++) { + for (uint8_t c = 0; c < NADDRS; c++) { p = bus->devices[c]; if (!p) continue; @@ -117,14 +118,14 @@ i2c_sethandler(void *bus_handle, uint8_t base, int size, void (*stop)(void *bus, uint8_t addr, void *priv), void *priv) { - int c; - i2c_t *p, *q = NULL; + i2c_t *p; + i2c_t *q = NULL; i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus_handle || ((base + size) > NADDRS)) return; - for (c = 0; c < size; c++) { + for (int c = 0; c < size; c++) { p = bus->last[base + c]; q = (i2c_t *) malloc(sizeof(i2c_t)); memset(q, 0, sizeof(i2c_t)); @@ -156,14 +157,14 @@ i2c_removehandler(void *bus_handle, uint8_t base, int size, void (*stop)(void *bus, uint8_t addr, void *priv), void *priv) { - int c; - i2c_t *p, *q; + i2c_t *p; + i2c_t *q; i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus_handle || ((base + size) > NADDRS)) return; - for (c = 0; c < size; c++) { + for (int c = 0; c < size; c++) { p = bus->devices[base + c]; if (!p) continue; @@ -204,12 +205,12 @@ i2c_handler(int set, void *bus_handle, uint8_t base, int size, uint8_t i2c_start(void *bus_handle, uint8_t addr, uint8_t read) { - uint8_t ret = 0; - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; - i2c_t *p; + uint8_t ret = 0; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + i2c_t *p; if (!bus) - return (ret); + return ret; p = bus->devices[addr]; if (p) { @@ -223,18 +224,18 @@ i2c_start(void *bus_handle, uint8_t addr, uint8_t read) i2c_log("I2C %s: start(%02X) = %d\n", bus->name, addr, ret); - return (ret); + return ret; } uint8_t i2c_read(void *bus_handle, uint8_t addr) { - uint8_t ret = 0; - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; - i2c_t *p; + uint8_t ret = 0; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + i2c_t *p; if (!bus) - return (ret); + return ret; p = bus->devices[addr]; if (p) { @@ -249,18 +250,18 @@ i2c_read(void *bus_handle, uint8_t addr) i2c_log("I2C %s: read(%02X) = %02X\n", bus->name, addr, ret); - return (ret); + return ret; } uint8_t i2c_write(void *bus_handle, uint8_t addr, uint8_t data) { - uint8_t ret = 0; - i2c_t *p; - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + uint8_t ret = 0; + i2c_t *p; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus) - return (ret); + return ret; p = bus->devices[addr]; if (p) { @@ -274,14 +275,14 @@ i2c_write(void *bus_handle, uint8_t addr, uint8_t data) i2c_log("I2C %s: write(%02X, %02X) = %d\n", bus->name, addr, data, ret); - return (ret); + return ret; } void i2c_stop(void *bus_handle, uint8_t addr) { - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; - i2c_t *p; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + i2c_t *p; if (!bus) return; diff --git a/src/device/i2c_gpio.c b/src/device/i2c_gpio.c index cb7cf6147..22bdaffd3 100644 --- a/src/device/i2c_gpio.c +++ b/src/device/i2c_gpio.c @@ -24,11 +24,18 @@ #include <86box/86box.h> #include <86box/i2c.h> -typedef struct { +typedef struct i2c_gpio_t { char *bus_name; void *i2c; - uint8_t prev_scl, prev_sda, slave_sda, started, - slave_addr_received, slave_addr, slave_read, pos, byte; + uint8_t prev_scl; + uint8_t prev_sda; + uint8_t slave_sda; + uint8_t started; + uint8_t slave_addr_received; + uint8_t slave_addr; + uint8_t slave_read; + uint8_t pos; + uint8_t byte; } i2c_gpio_t; #ifdef ENABLE_I2C_GPIO_LOG @@ -136,6 +143,9 @@ i2c_gpio_set(void *dev_handle, uint8_t scl, uint8_t sda) dev->slave_sda = !i2c_write(dev->i2c, dev->slave_addr, dev->byte); i2c_gpio_log(2, "I2C GPIO %s: Write %02X %sACK\n", dev->bus_name, dev->byte, dev->slave_sda ? "N" : ""); break; + + default: + break; } } else if (dev->pos == 9) { switch (dev->slave_read) { @@ -161,14 +171,16 @@ i2c_gpio_set(void *dev_handle, uint8_t scl, uint8_t sda) uint8_t i2c_gpio_get_scl(void *dev_handle) { - i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + const i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + return dev->prev_scl; } uint8_t i2c_gpio_get_sda(void *dev_handle) { - i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + const i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + i2c_gpio_log(3, "I2C GPIO %s: read myscl=%d mysda=%d slavesda=%d\n", dev->bus_name, dev->prev_scl, dev->prev_sda, dev->slave_sda); return dev->prev_sda && dev->slave_sda; } diff --git a/src/device/ibm_5161.c b/src/device/ibm_5161.c index ea62c2abf..07083873e 100644 --- a/src/device/ibm_5161.c +++ b/src/device/ibm_5161.c @@ -26,11 +26,11 @@ #include <86box/pci.h> #include <86box/timer.h> #include <86box/pit.h> +#include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/machine.h> -typedef struct -{ +typedef struct ibm_5161_t { uint8_t regs[8]; } ibm_5161_t; @@ -45,8 +45,8 @@ ibm_5161_out(uint16_t port, uint8_t val, void *priv) static uint8_t ibm_5161_in(uint16_t port, void *priv) { - ibm_5161_t *dev = (ibm_5161_t *) priv; - uint8_t ret = 0xff; + const ibm_5161_t *dev = (ibm_5161_t *) priv; + uint8_t ret = 0xff; ret = dev->regs[port & 0x0007]; @@ -76,21 +76,24 @@ ibm_5161_in(uint16_t port, void *priv) 0 =On */ ret = dev->regs[3] & 0x01; break; + + default: + break; } return ret; } static void -ibm_5161_close(void *p) +ibm_5161_close(void *priv) { - ibm_5161_t *dev = (ibm_5161_t *) p; + ibm_5161_t *dev = (ibm_5161_t *) priv; free(dev); } static void * -ibm_5161_init(const device_t *info) +ibm_5161_init(UNUSED(const device_t *info)) { ibm_5161_t *dev = (ibm_5161_t *) malloc(sizeof(ibm_5161_t)); memset(dev, 0, sizeof(ibm_5161_t)); diff --git a/src/device/isamem.c b/src/device/isamem.c index 52327ad2c..5b880d6eb 100644 --- a/src/device/isamem.c +++ b/src/device/isamem.c @@ -112,7 +112,7 @@ #define EXTRAM_HIGH 1 #define EXTRAM_XMS 2 -typedef struct { +typedef struct emsreg_t { int8_t enabled; /* 1=ENABLED */ uint8_t page; /* page# in EMS RAM */ uint8_t frame; /* (varies with board) */ @@ -121,15 +121,15 @@ typedef struct { mem_mapping_t mapping; /* mapping entry for page */ } emsreg_t; -typedef struct { +typedef struct ext_ram_t { uint32_t base; uint8_t *ptr; } ext_ram_t; -typedef struct { +typedef struct memdev_t { const char *name; - uint8_t board : 6, /* board type */ - reserved : 2; + uint8_t board : 6; /* board type */ + uint8_t reserved : 2; uint8_t flags; #define FLAG_CONFIG 0x01 /* card is configured */ @@ -138,12 +138,12 @@ typedef struct { #define FLAG_EMS 0x40 /* card has EMS mode enabled */ uint16_t total_size; /* configured size in KB */ - uint32_t base_addr, /* configured I/O address */ - start_addr, /* configured memory start */ - frame_addr; /* configured frame address */ + uint32_t base_addr; /* configured I/O address */ + uint32_t start_addr; /* configured memory start */ + uint32_t frame_addr; /* configured frame address */ - uint16_t ems_size, /* EMS size in KB */ - ems_pages; /* EMS size in pages */ + uint16_t ems_size; /* EMS size in KB */ + uint16_t ems_pages; /* EMS size in pages */ uint32_t ems_start; /* start of EMS in RAM */ uint8_t *ram; /* allocated RAM buffer */ @@ -186,7 +186,7 @@ ram_readb(uint32_t addr, void *priv) /* Grab the data. */ ret = *(uint8_t *) (dev->ptr + (addr - dev->base)); - return (ret); + return ret; } /* Read one word from onboard RAM. */ @@ -199,7 +199,7 @@ ram_readw(uint32_t addr, void *priv) /* Grab the data. */ ret = *(uint16_t *) (dev->ptr + (addr - dev->base)); - return (ret); + return ret; } /* Write one byte to onboard RAM. */ @@ -230,13 +230,13 @@ ems_readb(uint32_t addr, void *priv) uint8_t ret = 0xff; /* Grab the data. */ - ret = *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); #if ISAMEM_DEBUG if ((addr % 4096) == 0) isamem_log("EMS readb(%06x) = %02x\n", addr - dev & 0x3fff, ret); #endif - return (ret); + return ret; } /* Read one word from onboard paged RAM. */ @@ -247,13 +247,13 @@ ems_readw(uint32_t addr, void *priv) uint16_t ret = 0xffff; /* Grab the data. */ - ret = *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); #if ISAMEM_DEBUG if ((addr % 4096) == 0) isamem_log("EMS readw(%06x) = %04x\n", addr - dev & 0x3fff, ret); #endif - return (ret); + return ret; } /* Write one byte to onboard paged RAM. */ @@ -267,7 +267,7 @@ ems_writeb(uint32_t addr, uint8_t val, void *priv) if ((addr % 4096) == 0) isamem_log("EMS writeb(%06x, %02x)\n", addr - dev & 0x3fff, val); #endif - *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Write one word to onboard paged RAM. */ @@ -281,16 +281,16 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) if ((addr % 4096) == 0) isamem_log("EMS writew(%06x, %04x)\n", addr & 0x3fff, val); #endif - *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Handle a READ operation from one of our registers. */ static uint8_t ems_read(uint16_t port, void *priv) { - memdev_t *dev = (memdev_t *) priv; - uint8_t ret = 0xff; - int vpage; + const memdev_t *dev = (memdev_t *) priv; + uint8_t ret = 0xff; + int vpage; /* Get the viewport page number. */ vpage = (port / EMS_PGSIZE); @@ -305,13 +305,16 @@ ems_read(uint16_t port, void *priv) case 0x0001: /* W/O */ break; + + default: + break; } #if ISAMEM_DEBUG isamem_log("ISAMEM: read(%04x) = %02x)\n", port, ret); #endif - return (ret); + return ret; } /* Handle a WRITE operation to one of our registers. */ @@ -383,6 +386,9 @@ ems_write(uint16_t port, uint8_t val, void *priv) if (val) dev->flags |= FLAG_CONFIG; break; + + default: + break; } } @@ -391,11 +397,11 @@ static void * isamem_init(const device_t *info) { memdev_t *dev; - uint32_t k, t; + uint32_t k; + uint32_t t; uint32_t addr; uint32_t tot; uint8_t *ptr; - int i; /* Find our device and create an instance. */ dev = (memdev_t *) malloc(sizeof(memdev_t)); @@ -458,6 +464,9 @@ isamem_init(const device_t *info) if (!!device_get_config_int("speed")) dev->flags |= FLAG_FAST; break; + + default: + break; } /* Fix up the memory start address. */ @@ -471,6 +480,7 @@ isamem_init(const device_t *info) isamem_log(", FAST"); if (dev->flags & FLAG_WIDE) isamem_log(", 16BIT"); + isamem_log(")\n"); /* Force (back to) 8-bit bus if needed. */ @@ -617,6 +627,7 @@ isamem_init(const device_t *info) dev->base_addr, dev->ems_size, dev->ems_pages); if (dev->frame_addr > 0) isamem_log(", Frame=%05XH", dev->frame_addr); + isamem_log("\n"); /* @@ -624,7 +635,7 @@ isamem_init(const device_t *info) * create, initialize and disable the mappings, and set * up the I/O control handler. */ - for (i = 0; i < EMS_MAXPAGE; i++) { + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { /* Create and initialize a page mapping. */ mem_mapping_add(&dev->ems[i].mapping, dev->frame_addr + (EMS_PGSIZE * i), EMS_PGSIZE, @@ -655,10 +666,9 @@ static void isamem_close(void *priv) { memdev_t *dev = (memdev_t *) priv; - int i; if (dev->flags & FLAG_EMS) { - for (i = 0; i < EMS_MAXPAGE; i++) { + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { io_removehandler(dev->base_addr + (EMS_PGSIZE * i), 2, ems_read, NULL, NULL, ems_write, NULL, NULL, dev); } @@ -1566,12 +1576,12 @@ static const struct { void isamem_reset(void) { - int k, i; + int k; /* We explicitly set to zero here or bad things happen */ isa_mem_size = 0; - for (i = 0; i < ISAMEM_MAX; i++) { + for (uint8_t i = 0; i < ISAMEM_MAX; i++) { k = isamem_type[i]; if (k == 0) continue; @@ -1603,12 +1613,12 @@ isamem_get_from_internal_name(const char *s) while (boards[c].dev != NULL) { if (!strcmp(boards[c].dev->internal_name, s)) - return (c); + return c; c++; } /* Not found. */ - return (0); + return 0; } const device_t * diff --git a/src/device/isapnp.c b/src/device/isapnp.c index 69d5e26ab..22b22dfcc 100644 --- a/src/device/isapnp.c +++ b/src/device/isapnp.c @@ -26,6 +26,7 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/isapnp.h> +#include <86box/plat_unused.h> #define CHECK_CURRENT_LD() \ if (!dev->current_ld) { \ @@ -81,34 +82,48 @@ enum { typedef struct _isapnp_device_ { uint8_t number; uint8_t regs[256]; - uint8_t mem_upperlimit, irq_types, io_16bit, io_len[8]; + uint8_t mem_upperlimit; + uint8_t irq_types; + uint8_t io_16bit; + uint8_t io_len[8]; const isapnp_device_config_t *defaults; struct _isapnp_device_ *next; } isapnp_device_t; typedef struct _isapnp_card_ { - uint8_t enable, state, csn, id_checksum, serial_read, serial_read_pair, serial_read_pos, *rom; - uint16_t rom_pos, rom_size; + uint8_t enable; + uint8_t state; + uint8_t csn; + uint8_t id_checksum; + uint8_t serial_read; + uint8_t serial_read_pair; + uint8_t serial_read_pos; + uint8_t *rom; + uint16_t rom_pos; + uint16_t rom_size; void *priv; /* ISAPnP memory and I/O addresses are awkwardly big endian, so we populate this structure whenever something on some device changes, and pass it on instead. */ isapnp_device_config_t config; - void (*config_changed)(uint8_t ld, isapnp_device_config_t *config, void *priv); - void (*csn_changed)(uint8_t csn, void *priv); + void (*config_changed)(uint8_t ld, isapnp_device_config_t *config, void *priv); + void (*csn_changed)(uint8_t csn, void *priv); uint8_t (*read_vendor_reg)(uint8_t ld, uint8_t reg, void *priv); - void (*write_vendor_reg)(uint8_t ld, uint8_t reg, uint8_t val, void *priv); + void (*write_vendor_reg)(uint8_t ld, uint8_t reg, uint8_t val, void *priv); isapnp_device_t *first_ld; struct _isapnp_card_ *next; } isapnp_card_t; typedef struct { - uint8_t reg, key_pos : 5; + uint8_t reg; + uint8_t key_pos : 5; uint16_t read_data_addr; - isapnp_card_t *first_card, *isolated_card, *current_ld_card; + isapnp_card_t *first_card; + isapnp_card_t *isolated_card; + isapnp_card_t *current_ld_card; isapnp_device_t *current_ld; } isapnp_t; @@ -121,35 +136,35 @@ isapnp_device_config_changed(isapnp_card_t *card, isapnp_device_t *ld) /* Populate config structure, performing endianness conversion as needed. */ card->config.activate = ld->regs[0x30] & 0x01; - uint8_t i, reg_base; - for (i = 0; i < 4; i++) { + uint8_t reg_base; + for (uint8_t i = 0; i < 4; i++) { reg_base = 0x40 + (8 * i); card->config.mem[i].base = (ld->regs[reg_base] << 16) | (ld->regs[reg_base + 1] << 8); card->config.mem[i].size = (ld->regs[reg_base + 3] << 16) | (ld->regs[reg_base + 4] << 8); if (ld->regs[reg_base + 2] & 0x01) /* upper limit */ card->config.mem[i].size -= card->config.mem[i].base; } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { reg_base = (i == 0) ? 0x76 : (0x80 + (16 * i)); card->config.mem32[i].base = (ld->regs[reg_base] << 24) | (ld->regs[reg_base + 1] << 16) | (ld->regs[reg_base + 2] << 8) | ld->regs[reg_base + 3]; card->config.mem32[i].size = (ld->regs[reg_base + 5] << 24) | (ld->regs[reg_base + 6] << 16) | (ld->regs[reg_base + 7] << 8) | ld->regs[reg_base + 8]; if (ld->regs[reg_base + 4] & 0x01) /* upper limit */ card->config.mem32[i].size -= card->config.mem32[i].base; } - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { reg_base = 0x60 + (2 * i); if (ld->regs[0x31] & 0x02) card->config.io[i].base = 0; /* let us handle I/O range check reads */ else card->config.io[i].base = (ld->regs[reg_base] << 8) | ld->regs[reg_base + 1]; } - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { reg_base = 0x70 + (2 * i); card->config.irq[i].irq = ld->regs[reg_base]; card->config.irq[i].level = ld->regs[reg_base + 1] & 0x02; card->config.irq[i].type = ld->regs[reg_base + 1] & 0x01; } - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { reg_base = 0x74 + i; card->config.dma[i].dma = ld->regs[reg_base]; } @@ -168,9 +183,9 @@ isapnp_reset_ld_config(isapnp_device_t *ld) /* Populate configuration registers. */ ld->regs[0x30] = !!config->activate; - uint8_t i, reg_base; + uint8_t reg_base; uint32_t size; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { reg_base = 0x40 + (8 * i); ld->regs[reg_base] = config->mem[i].base >> 16; ld->regs[reg_base + 1] = config->mem[i].base >> 8; @@ -180,7 +195,7 @@ isapnp_reset_ld_config(isapnp_device_t *ld) ld->regs[reg_base + 3] = size >> 16; ld->regs[reg_base + 4] = size >> 8; } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { reg_base = (i == 0) ? 0x76 : (0x80 + (16 * i)); ld->regs[reg_base] = config->mem32[i].base >> 24; ld->regs[reg_base + 1] = config->mem32[i].base >> 16; @@ -194,17 +209,17 @@ isapnp_reset_ld_config(isapnp_device_t *ld) ld->regs[reg_base + 7] = size >> 8; ld->regs[reg_base + 8] = size; } - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { reg_base = 0x60 + (2 * i); ld->regs[reg_base] = config->io[i].base >> 8; ld->regs[reg_base + 1] = config->io[i].base; } - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { reg_base = 0x70 + (2 * i); ld->regs[reg_base] = config->irq[i].irq; ld->regs[reg_base + 1] = (!!config->irq[i].level << 1) | !!config->irq[i].type; } - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { reg_base = 0x74 + i; ld->regs[reg_base] = config->dma[i].dma; } @@ -219,15 +234,14 @@ isapnp_reset_ld_regs(isapnp_device_t *ld) ld->regs[0x74] = ld->regs[0x75] = ISAPNP_DMA_DISABLED; /* Set the upper limit bit on memory ranges which require it. */ - uint8_t i; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) ld->regs[0x42 + (8 * i)] |= !!(ld->mem_upperlimit & (1 << i)); ld->regs[0x7a] |= !!(ld->mem_upperlimit & (1 << 4)); - for (i = 1; i < 4; i++) + for (uint8_t i = 1; i < 4; i++) ld->regs[0x84 + (16 * i)] |= !!(ld->mem_upperlimit & (1 << (4 + i))); /* Set the default IRQ type bits. */ - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { if (ld->irq_types & (0x1 << (4 * i))) ld->regs[0x70 + (2 * i)] = 0x02; else if (ld->irq_types & (0x2 << (4 * i))) @@ -243,17 +257,20 @@ isapnp_reset_ld_regs(isapnp_device_t *ld) } static uint8_t -isapnp_read_rangecheck(uint16_t addr, void *priv) +isapnp_read_rangecheck(UNUSED(uint16_t addr), void *priv) { - isapnp_device_t *dev = (isapnp_device_t *) priv; + const isapnp_device_t *dev = (isapnp_device_t *) priv; + return (dev->regs[0x31] & 0x01) ? 0x55 : 0xaa; } static uint8_t -isapnp_read_data(uint16_t addr, void *priv) +isapnp_read_data(UNUSED(uint16_t addr), void *priv) { isapnp_t *dev = (isapnp_t *) priv; - uint8_t ret = 0xff, bit, next_shift; + uint8_t ret = 0xff; + uint8_t bit; + uint8_t next_shift; isapnp_card_t *card; switch (dev->reg) { @@ -414,7 +431,7 @@ isapnp_set_read_data(uint16_t addr, isapnp_t *dev) } static void -isapnp_write_addr(uint16_t addr, uint8_t val, void *priv) +isapnp_write_addr(UNUSED(uint16_t addr), uint8_t val, void *priv) { isapnp_t *dev = (isapnp_t *) priv; isapnp_card_t *card = dev->first_card; @@ -445,12 +462,13 @@ isapnp_write_addr(uint16_t addr, uint8_t val, void *priv) } static void -isapnp_write_data(uint16_t addr, uint8_t val, void *priv) +isapnp_write_data(UNUSED(uint16_t addr), uint8_t val, void *priv) { isapnp_t *dev = (isapnp_t *) priv; isapnp_card_t *card; isapnp_device_t *ld; - uint16_t io_addr, reset_cards = 0; + uint16_t io_addr; + uint16_t reset_cards = 0; isapnp_log("ISAPnP: write_data(%02X)\n", val); @@ -676,6 +694,9 @@ isapnp_write_data(uint16_t addr, uint8_t val, void *priv) val |= 0x02; break; + + default: + break; } dev->current_ld->regs[dev->reg] = val; @@ -686,7 +707,7 @@ isapnp_write_data(uint16_t addr, uint8_t val, void *priv) } static void * -isapnp_init(const device_t *info) +isapnp_init(UNUSED(const device_t *info)) { isapnp_t *dev = (isapnp_t *) malloc(sizeof(isapnp_t)); memset(dev, 0, sizeof(isapnp_t)); @@ -701,8 +722,10 @@ static void isapnp_close(void *priv) { isapnp_t *dev = (isapnp_t *) priv; - isapnp_card_t *card = dev->first_card, *next_card; - isapnp_device_t *ld, *next_ld; + isapnp_card_t *card = dev->first_card; + isapnp_card_t *next_card; + isapnp_device_t *ld; + isapnp_device_t *next_ld; while (card) { ld = card->first_ld; @@ -773,11 +796,22 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) uint16_t vendor = (card->rom[0] << 8) | card->rom[1]; isapnp_log("ISAPnP: Parsing ROM resources for card %c%c%c%02X%02X (serial %08X)\n", '@' + ((vendor >> 10) & 0x1f), '@' + ((vendor >> 5) & 0x1f), '@' + (vendor & 0x1f), card->rom[2], card->rom[3], (card->rom[7] << 24) | (card->rom[6] << 16) | (card->rom[5] << 8) | card->rom[4]); #endif - uint16_t i = 9, j; - uint8_t existing = 0, ldn = 0, res, in_df = 0; - uint8_t irq = 0, io = 0, mem_range = 0, mem_range_32 = 0, irq_df = 0, io_df = 0, mem_range_df = 0, mem_range_32_df = 0; + uint16_t i = 9; + uint8_t existing = 0; + uint8_t ldn = 0; + uint8_t res; + uint8_t in_df = 0; + uint8_t irq = 0; + uint8_t io = 0; + uint8_t mem_range = 0; + uint8_t mem_range_32 = 0; + uint8_t irq_df = 0; + uint8_t io_df = 0; + uint8_t mem_range_df = 0; + uint8_t mem_range_32_df = 0; uint32_t len; - isapnp_device_t *ld = NULL, *prev_ld = NULL; + isapnp_device_t *ld = NULL; + isapnp_device_t *prev_ld = NULL; /* Check if this is an existing card which already has logical devices. Any new logical devices will be added to the list after existing ones. @@ -844,6 +878,9 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) default: isapnp_log("ISAPnP: >%s%s Large resource %02X (length %d)\n", ldn ? ">" : "", in_df ? ">" : "", res, (card->rom[i + 2] << 8) | card->rom[i + 1]); break; +#else + default: + break; #endif } @@ -994,7 +1031,7 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) case 0x0f: /* end tag */ /* Calculate checksum. */ res = 0x00; - for (j = 9; j <= i; j++) + for (uint16_t j = 9; j <= i; j++) res += card->rom[j]; card->rom[i + 1] = -res; @@ -1004,11 +1041,11 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) card->rom_size = i + 2; break; -#ifdef ENABLE_ISAPNP_LOG default: +#ifdef ENABLE_ISAPNP_LOG isapnp_log("ISAPnP: >%s%s Small resource %02X (length %d)\n", ldn ? ">" : "", in_df ? ">" : "", res, card->rom[i] & 0x07); - break; #endif + break; } i++; /* header */ diff --git a/src/device/isartc.c b/src/device/isartc.c index 67b5b94c2..ce0fcd7c6 100644 --- a/src/device/isartc.c +++ b/src/device/isartc.c @@ -90,7 +90,7 @@ #define ISARTC_DEBUG 0 -typedef struct { +typedef struct rtcdev_t { const char *name; /* board name */ uint8_t board; /* board type */ @@ -103,18 +103,18 @@ typedef struct { uint32_t base_addr; /* configured I/O address */ /* Fields for the specific driver. */ - void (*f_wr)(uint16_t, uint8_t, void *); + void (*f_wr)(uint16_t, uint8_t, void *); uint8_t (*f_rd)(uint16_t, void *); - int8_t year; /* register for YEAR value */ - char pad[3]; + int8_t year; /* register for YEAR value */ + char pad[3]; nvr_t nvr; /* RTC/NVR */ } rtcdev_t; /************************************************************************ - * * - * Driver for the NatSemi MM58167 chip. * - * * + * * + * Driver for the NatSemi MM58167 chip. * + * * ************************************************************************/ #define MM67_REGS 32 @@ -191,9 +191,11 @@ mm67_chkalrm(nvr_t *nvr, int8_t addr) static void mm67_tick(nvr_t *nvr) { - rtcdev_t *dev = (rtcdev_t *) nvr->data; - uint8_t *regs = nvr->regs; - int mon, year, f = 0; + const rtcdev_t *dev = (rtcdev_t *) nvr->data; + uint8_t *regs = nvr->regs; + int mon; + int year; + int f = 0; /* Update and set interrupt if needed. */ regs[MM67_SEC] = RTC_BCDINC(nvr->regs[MM67_SEC], 1); @@ -236,7 +238,10 @@ mm67_tick(nvr_t *nvr) regs[MM67_DOM] = RTC_BCDINC(regs[MM67_DOM], 1); mon = RTC_DCB(regs[MM67_MON]); if (dev->year != -1) { - year = RTC_DCB(regs[dev->year]); + if (dev->flags & FLAG_YEARBCD) + year = RTC_DCB(regs[dev->year]); + else + year = regs[dev->year]; if (dev->flags & FLAG_YEAR80) year += 80; } else @@ -290,8 +295,8 @@ mm67_tick(nvr_t *nvr) static void mm67_time_get(nvr_t *nvr, struct tm *tm) { - rtcdev_t *dev = (rtcdev_t *) nvr->data; - uint8_t *regs = nvr->regs; + const rtcdev_t *dev = (rtcdev_t *) nvr->data; + const uint8_t *regs = nvr->regs; /* NVR is in BCD data mode. */ tm->tm_sec = RTC_DCB(regs[MM67_SEC]); @@ -320,9 +325,9 @@ mm67_time_get(nvr_t *nvr, struct tm *tm) static void mm67_time_set(nvr_t *nvr, struct tm *tm) { - rtcdev_t *dev = (rtcdev_t *) nvr->data; - uint8_t *regs = nvr->regs; - int year; + const rtcdev_t *dev = (rtcdev_t *) nvr->data; + uint8_t *regs = nvr->regs; + int year; /* NVR is in BCD data mode. */ regs[MM67_SEC] = RTC_BCD(tm->tm_sec); @@ -369,10 +374,8 @@ mm67_start(nvr_t *nvr) static void mm67_reset(nvr_t *nvr) { - int i; - /* Initialize the RTC to a known state. */ - for (i = MM67_MSEC; i <= MM67_MON; i++) + for (uint8_t i = MM67_MSEC; i <= MM67_MON; i++) nvr->regs[i] = RTC_BCD(0); nvr->regs[MM67_DOW] = RTC_BCD(1); nvr->regs[MM67_DOM] = RTC_BCD(1); @@ -398,6 +401,14 @@ mm67_read(uint16_t port, void *priv) picintc(1 << dev->irq); break; + case MM67_AL_MSEC: + ret = dev->nvr.regs[reg] & 0xf0; + break; + + case MM67_AL_DOW: + ret = dev->nvr.regs[reg] & 0x0f; + break; + default: ret = dev->nvr.regs[reg]; break; @@ -407,7 +418,7 @@ mm67_read(uint16_t port, void *priv) isartc_log("ISARTC: read(%04x) = %02x\n", port - dev->base_addr, ret); #endif - return (ret); + return ret; } /* Handle a WRITE operation to one of our registers. */ @@ -416,7 +427,6 @@ mm67_write(uint16_t port, uint8_t val, void *priv) { rtcdev_t *dev = (rtcdev_t *) priv; int reg = port - dev->base_addr; - int i; #if ISARTC_DEBUG isartc_log("ISARTC: write(%04x, %02x)\n", port - dev->base_addr, val); @@ -441,7 +451,7 @@ mm67_write(uint16_t port, uint8_t val, void *priv) case MM67_RSTRAM: if (val == 0xff) { - for (i = MM67_AL_MSEC; i <= MM67_AL_MON; i++) + for (uint8_t i = MM67_AL_MSEC; i <= MM67_AL_MON; i++) dev->nvr.regs[i] = RTC_BCD(0); dev->nvr.regs[MM67_DOW] = RTC_BCD(1); dev->nvr.regs[MM67_DOM] = RTC_BCD(1); @@ -474,6 +484,14 @@ mm67_write(uint16_t port, uint8_t val, void *priv) isartc_log("RTC: write test=%02x\n", val); break; + case MM67_AL_MSEC: + dev->nvr.regs[reg] = val & 0xf0; + break; + + case MM67_AL_DOW: + dev->nvr.regs[reg] = val & 0x0f; + break; + default: dev->nvr.regs[reg] = val; break; @@ -481,9 +499,9 @@ mm67_write(uint16_t port, uint8_t val, void *priv) } /************************************************************************ - * * - * Generic code for all supported chips. * - * * + * * + * Generic code for all supported chips. * + * * ************************************************************************/ /* Initialize the device for use. */ @@ -590,9 +608,6 @@ isartc_close(void *priv) io_removehandler(dev->base_addr, dev->base_addrsz, dev->f_rd, NULL, NULL, dev->f_wr, NULL, NULL, dev); - if (dev->nvr.fn != NULL) - free(dev->nvr.fn); - free(dev); } @@ -787,12 +802,12 @@ isartc_get_from_internal_name(char *s) while (boards[c].dev != NULL) { if (!strcmp(boards[c].dev->internal_name, s)) - return (c); + return c; c++; } /* Not found. */ - return (0); + return 0; } const device_t * diff --git a/src/device/kbc_at.c b/src/device/kbc_at.c new file mode 100644 index 000000000..39398f996 --- /dev/null +++ b/src/device/kbc_at.c @@ -0,0 +1,2365 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Intel 8042 (AT keyboard controller) emulation. + * + * + * + * Authors: Miran Grca, + * EngiNerd, + * + * Copyright 2023 Miran Grca. + * Copyright 2023 EngiNerd. + */ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> +#include <86box/ppi.h> +#include <86box/mem.h> +#include <86box/device.h> +#include <86box/machine.h> +#include <86box/m_at_t3100e.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/sound.h> +#include <86box/snd_speaker.h> +#include <86box/video.h> +#include <86box/keyboard.h> + +#define STAT_PARITY 0x80 +#define STAT_RTIMEOUT 0x40 +#define STAT_TTIMEOUT 0x20 +#define STAT_MFULL 0x20 +#define STAT_UNLOCKED 0x10 +#define STAT_CD 0x08 +#define STAT_SYSFLAG 0x04 +#define STAT_IFULL 0x02 +#define STAT_OFULL 0x01 + +#define CCB_UNUSED 0x80 +#define CCB_TRANSLATE 0x40 +#define CCB_PCMODE 0x20 +#define CCB_ENABLEKBD 0x10 +#define CCB_IGNORELOCK 0x08 +#define CCB_SYSTEM 0x04 +#define CCB_ENABLEMINT 0x02 +#define CCB_ENABLEKINT 0x01 + +#define CCB_MASK 0x68 +#define MODE_MASK 0x6c + +#define KBC_TYPE_ISA 0x00 /* AT ISA-based chips */ +#define KBC_TYPE_PS2_1 0x01 /* PS2 on PS/2, type 1 */ +#define KBC_TYPE_PS2_2 0x02 /* PS2 on PS/2, type 2 */ +#define KBC_TYPE_GREEN 0x03 /* PS2 green controller */ +#define KBC_TYPE_MASK 0x03 + +#define KBC_VEN_GENERIC 0x00 +#define KBC_VEN_IBM_PS1 0x04 +#define KBC_VEN_TOSHIBA 0x08 +#define KBC_VEN_OLIVETTI 0x0c +#define KBC_VEN_AMI 0x10 +#define KBC_VEN_TRIGEM_AMI 0x14 +#define KBC_VEN_QUADTEL 0x18 +#define KBC_VEN_PHOENIX 0x1c +#define KBC_VEN_ACER 0x20 +#define KBC_VEN_NCR 0x24 +#define KBC_VEN_ALI 0x28 +#define KBC_VEN_SIEMENS 0x2c +#define KBC_VEN_COMPAQ 0x30 +#define KBC_VEN_MASK 0x7c + +#define FLAG_CLOCK 0x01 +#define FLAG_CACHE 0x02 +#define FLAG_PS2 0x04 +#define FLAG_PCI 0x08 + +enum { + STATE_RESET = 0, /* KBC reset state, only accepts command AA. */ + STATE_KBC_DELAY_OUT, /* KBC is sending one single byte. */ + STATE_KBC_AMI_OUT, /* KBC waiting for OBF - needed for AMIKey commands that require clearing of the output byte. */ + STATE_MAIN_IBF, /* KBC checking if the input buffer is full. */ + STATE_MAIN_KBD, /* KBC checking if the keyboard has anything to send. */ + STATE_MAIN_AUX, /* KBC checking if the auxiliary has anything to send. */ + STATE_MAIN_BOTH, /* KBC checking if either device has anything to send. */ + STATE_KBC_OUT, /* KBC is sending multiple bytes. */ + STATE_KBC_PARAM, /* KBC wants a parameter. */ + STATE_SEND_KBD, /* KBC is sending command to the keyboard. */ + STATE_SCAN_KBD, /* KBC is waiting for the keyboard command response. */ + STATE_SEND_AUX, /* KBC is sending command to the auxiliary device. */ + STATE_SCAN_AUX /* KBC is waiting for the auxiliary command response. */ +}; + +typedef struct atkbc_t { + uint8_t state; + uint8_t command; + uint8_t command_phase; + uint8_t status; + uint8_t wantdata; + uint8_t ib; + uint8_t ob; + uint8_t sc_or; + uint8_t mem_addr; + uint8_t p1; + uint8_t p2; + uint8_t old_p2; + uint8_t misc_flags; + uint8_t ami_flags; + uint8_t key_ctrl_queue_start; + uint8_t key_ctrl_queue_end; + uint8_t val; + uint8_t channel; + uint8_t stat_hi; + uint8_t pending; + + uint8_t mem[0x100]; + + /* Internal FIFO for the purpose of commands with multi-byte output. */ + uint8_t key_ctrl_queue[64]; + + uint32_t flags; + + /* Main timer. */ + pc_timer_t send_delay_timer; + + /* P2 pulse callback timer. */ + pc_timer_t pulse_cb; + + /* Local copies of the pointers to both ports for easier swapping (AMI '5' MegaKey). */ + kbc_at_port_t *ports[2]; + + uint8_t (*write60_ven)(void *p, uint8_t val); + uint8_t (*write64_ven)(void *p, uint8_t val); +} atkbc_t; + +/* Keyboard controller ports. */ +kbc_at_port_t *kbc_at_ports[2] = { NULL, NULL }; + +static uint8_t kbc_ami_revision = '8'; +static uint8_t kbc_award_revision = 0x42; + +static void (*kbc_at_do_poll)(atkbc_t *dev); + +/* Non-translated to translated scan codes. */ +static const uint8_t nont_to_t[256] = { + 0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58, + 0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59, + 0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a, + 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b, + 0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c, + 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d, + 0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e, + 0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f, + 0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60, + 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61, + 0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e, + 0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76, + 0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b, + 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f, + 0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45, + 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54, + 0x80, 0x81, 0x82, 0x41, 0x54, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff +}; + +#ifdef ENABLE_KBC_AT_LOG +int kbc_at_do_log = ENABLE_KBC_AT_LOG; + +static void +kbc_at_log(const char *fmt, ...) +{ + va_list ap; + + if (kbc_at_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define kbc_at_log(fmt, ...) +#endif + +static void +kbc_at_queue_reset(atkbc_t *dev) +{ + dev->key_ctrl_queue_start = dev->key_ctrl_queue_end = 0; + memset(dev->key_ctrl_queue, 0x00, sizeof(dev->key_ctrl_queue)); +} + +static void +kbc_at_queue_add(atkbc_t *dev, uint8_t val) +{ + kbc_at_log("ATkbc: dev->key_ctrl_queue[%02X] = %02X;\n", dev->key_ctrl_queue_end, val); + dev->key_ctrl_queue[dev->key_ctrl_queue_end] = val; + dev->key_ctrl_queue_end = (dev->key_ctrl_queue_end + 1) & 0x3f; + dev->state = STATE_KBC_OUT; +} + +static int +kbc_translate(atkbc_t *dev, uint8_t val) +{ + int xt_mode = (dev->mem[0x20] & 0x20) && !(dev->misc_flags & FLAG_PS2); + /* The IBM AT keyboard controller firmware does not apply translation in XT mode. */ + int translate = !xt_mode && ((dev->mem[0x20] & 0x40) || ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2)); + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + int ret = - 1; + + /* Allow for scan code translation. */ + if (translate && (val == 0xf0)) { + kbc_at_log("ATkbc: translate is on, F0 prefix detected\n"); + dev->sc_or = 0x80; + return ret; + } + + /* Skip break code if translated make code has bit 7 set. */ + if (translate && (dev->sc_or == 0x80) && (nont_to_t[val] & 0x80)) { + kbc_at_log("ATkbc: translate is on, skipping scan code: %02X (original: F0 %02X)\n", nont_to_t[val], val); + dev->sc_or = 0; + return ret; + } + + /* Test for T3100E 'Fn' key (Right Alt / Right Ctrl) */ + if ((dev != NULL) && (kbc_ven == KBC_VEN_TOSHIBA) && + (keyboard_recv(0x138) || keyboard_recv(0x11d))) switch (val) { + case 0x4f: + t3100e_notify_set(0x01); + break; /* End */ + case 0x50: + t3100e_notify_set(0x02); + break; /* Down */ + case 0x51: + t3100e_notify_set(0x03); + break; /* PgDn */ + case 0x52: + t3100e_notify_set(0x04); + break; /* Ins */ + case 0x53: + t3100e_notify_set(0x05); + break; /* Del */ + case 0x54: + t3100e_notify_set(0x06); + break; /* SysRQ */ + case 0x45: + t3100e_notify_set(0x07); + break; /* NumLock */ + case 0x46: + t3100e_notify_set(0x08); + break; /* ScrLock */ + case 0x47: + t3100e_notify_set(0x09); + break; /* Home */ + case 0x48: + t3100e_notify_set(0x0a); + break; /* Up */ + case 0x49: + t3100e_notify_set(0x0b); + break; /* PgUp */ + case 0x4a: + t3100e_notify_set(0x0c); + break; /* Keypad - */ + case 0x4b: + t3100e_notify_set(0x0d); + break; /* Left */ + case 0x4c: + t3100e_notify_set(0x0e); + break; /* KP 5 */ + case 0x4d: + t3100e_notify_set(0x0f); + break; /* Right */ + default: + break; + } + + kbc_at_log("ATkbc: translate is %s, ", translate ? "on" : "off"); +#ifdef ENABLE_KEYBOARD_AT_LOG + kbc_at_log("scan code: "); + if (translate) { + kbc_at_log("%02X (original: ", (nont_to_t[val] | dev->sc_or)); + if (dev->sc_or == 0x80) + kbc_at_log("F0 "); + kbc_at_log("%02X)\n", val); + } else + kbc_at_log("%02X\n", val); +#endif + + ret = translate ? (nont_to_t[val] | dev->sc_or) : val; + + if (dev->sc_or == 0x80) + dev->sc_or = 0; + + return ret; +} + +static void +kbc_send_to_ob(atkbc_t *dev, uint8_t val, uint8_t channel, uint8_t stat_hi) +{ + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + int temp = (channel == 1) ? kbc_translate(dev, val) : ((int) val); + + if (temp == -1) + return; + + if ((kbc_ven == KBC_VEN_AMI) || (kbc_ven == KBC_VEN_TRIGEM_AMI) || + (dev->misc_flags & FLAG_PS2)) + stat_hi |= ((dev->p1 & 0x80) ? 0x10 : 0x00); + else + stat_hi |= 0x10; + + kbc_at_log("ATkbc: Sending %02X to the output buffer on channel %i...\n", temp, channel); + dev->status = (dev->status & ~0xf0) | STAT_OFULL | stat_hi; + + /* WARNING: On PS/2, all IRQ's are level-triggered, but the IBM PS/2 KBC firmware is explicitly + written to pulse its P2 IRQ bits, so they should be kept as as edge-triggered here. */ + if (dev->misc_flags & FLAG_PS2) { + if (channel >= 2) { + dev->status |= STAT_MFULL; + + if (dev->mem[0x20] & 0x02) + picint_common(1 << 12, 0, 1); + picint_common(1 << 1, 0, 0); + } else { + if (dev->mem[0x20] & 0x01) + picint_common(1 << 1, 0, 1); + picint_common(1 << 12, 0, 0); + } + } else if (dev->mem[0x20] & 0x01) + picintlevel(1 << 1); /* AT KBC: IRQ 1 is level-triggered because it is tied to OBF. */ + + dev->ob = temp; +} + +static void +kbc_delay_to_ob(atkbc_t *dev, uint8_t val, uint8_t channel, uint8_t stat_hi) +{ + dev->val = val; + dev->channel = channel; + dev->stat_hi = stat_hi; + dev->pending = 1; + dev->state = STATE_KBC_DELAY_OUT; +} + +static void kbc_at_process_cmd(void *priv); + +static void +set_enable_kbd(atkbc_t *dev, uint8_t enable) +{ + dev->mem[0x20] &= 0xef; + dev->mem[0x20] |= (enable ? 0x00 : 0x10); +} + +static void +set_enable_aux(atkbc_t *dev, uint8_t enable) +{ + dev->mem[0x20] &= 0xdf; + dev->mem[0x20] |= (enable ? 0x00 : 0x20); +} + +static void +kbc_ibf_process(atkbc_t *dev) +{ + /* IBF set, process both commands and data. */ + dev->status &= ~STAT_IFULL; + dev->state = STATE_MAIN_IBF; + if (dev->status & STAT_CD) + kbc_at_process_cmd(dev); + else { + set_enable_kbd(dev, 1); + if ((dev->ports[0] != NULL) && (dev->ports[0]->priv != NULL)) { + dev->ports[0]->wantcmd = 1; + dev->ports[0]->dat = dev->ib; + dev->state = STATE_SEND_KBD; + } else + kbc_delay_to_ob(dev, 0xfe, 1, 0x40); + } +} + +static void +kbc_scan_kbd_at(atkbc_t *dev) +{ + if (!(dev->mem[0x20] & 0x10)) { + /* Both OBF and IBF clear and keyboard is enabled. */ + /* XT mode. */ + if (dev->mem[0x20] & 0x20) { + if ((dev->ports[0] != NULL) && (dev->ports[0]->out_new != -1)) { + kbc_send_to_ob(dev, dev->ports[0]->out_new, 1, 0x00); + dev->ports[0]->out_new = -1; + dev->state = STATE_MAIN_IBF; + } else if (dev->status & STAT_IFULL) + kbc_ibf_process(dev); + /* AT mode. */ + } else { +#if 0 + dev->t = dev->mem[0x28]; +#endif + if (dev->mem[0x2e] != 0x00) { +#if 0 + if (!(dev->t & 0x02)) + return; +#endif + dev->mem[0x2e] = 0x00; + } + dev->p2 &= 0xbf; + if ((dev->ports[0] != NULL) && (dev->ports[0]->out_new != -1)) { + /* In our case, we never have noise on the line, so we can simplify this. */ + /* Read data from the keyboard. */ + if (dev->mem[0x20] & 0x40) { + if ((dev->mem[0x20] & 0x08) || (dev->p1 & 0x80)) + kbc_send_to_ob(dev, dev->ports[0]->out_new, 1, 0x00); + dev->mem[0x2d] = (dev->ports[0]->out_new == 0xf0) ? 0x80 : 0x00; + } else + kbc_send_to_ob(dev, dev->ports[0]->out_new, 1, 0x00); + dev->ports[0]->out_new = -1; + dev->state = STATE_MAIN_IBF; + } + } + } +} + +static void +write_p2(atkbc_t *dev, uint8_t val); + +static void +kbc_at_poll_at(atkbc_t *dev) +{ + switch (dev->state) { + case STATE_RESET: + if (dev->status & STAT_IFULL) { + dev->status = ((dev->status & 0x0f) | 0x10) & ~STAT_IFULL; + if ((dev->status & STAT_CD) && (dev->ib == 0xaa)) + kbc_at_process_cmd(dev); + } + break; + case STATE_KBC_AMI_OUT: + if (dev->status & STAT_OFULL) + break; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case STATE_MAIN_IBF: + default: +at_main_ibf: + if (dev->status & STAT_OFULL) { + /* OBF set, wait until it is cleared but still process commands. */ + if ((dev->status & STAT_IFULL) && (dev->status & STAT_CD)) { + dev->status &= ~STAT_IFULL; + kbc_at_process_cmd(dev); + } + } else if (dev->status & STAT_IFULL) + kbc_ibf_process(dev); + else if (!(dev->mem[0x20] & 0x10)) + dev->state = STATE_MAIN_KBD; + break; + case STATE_MAIN_KBD: + case STATE_MAIN_BOTH: + if (dev->status & STAT_IFULL) + kbc_ibf_process(dev); + else { + (void) kbc_scan_kbd_at(dev); + dev->state = STATE_MAIN_IBF; + } + break; + case STATE_KBC_DELAY_OUT: + /* Keyboard controller command want to output a single byte. */ + kbc_at_log("ATkbc: %02X coming from channel %i with high status %02X\n", dev->val, dev->channel, dev->stat_hi); + kbc_send_to_ob(dev, dev->val, dev->channel, dev->stat_hi); +#if 0 + dev->state = (dev->pending == 2) ? STATE_KBC_AMI_OUT : STATE_MAIN_IBF; +#endif + dev->state = STATE_MAIN_IBF; + dev->pending = 0; + goto at_main_ibf; + break; + case STATE_KBC_OUT: + /* Keyboard controller command want to output multiple bytes. */ + if (dev->status & STAT_IFULL) { + /* Data from host aborts dumping. */ + dev->state = STATE_MAIN_IBF; + kbc_ibf_process(dev); + } + /* Do not continue dumping until OBF is clear. */ + if (!(dev->status & STAT_OFULL)) { + kbc_at_log("ATkbc: %02X coming from channel 0\n", dev->key_ctrl_queue[dev->key_ctrl_queue_start]); + kbc_send_to_ob(dev, dev->key_ctrl_queue[dev->key_ctrl_queue_start], 0, 0x00); + dev->key_ctrl_queue_start = (dev->key_ctrl_queue_start + 1) & 0x3f; + if (dev->key_ctrl_queue_start == dev->key_ctrl_queue_end) + dev->state = STATE_MAIN_IBF; + } + break; + case STATE_KBC_PARAM: + /* Keyboard controller command wants data, wait for said data. */ + if (dev->status & STAT_IFULL) { + /* Command written, abort current command. */ + if (dev->status & STAT_CD) + dev->state = STATE_MAIN_IBF; + + dev->status &= ~STAT_IFULL; + kbc_at_process_cmd(dev); + } + break; + case STATE_SEND_KBD: + if (!dev->ports[0]->wantcmd) + dev->state = STATE_SCAN_KBD; + break; + case STATE_SCAN_KBD: + kbc_scan_kbd_at(dev); + break; + } +} + +/* + Correct Procedure: + 1. Controller asks the device (keyboard or auxiliary device) for a byte. + 2. The device, unless it's in the reset or command states, sees if there's anything to give it, + and if yes, begins the transfer. + 3. The controller checks if there is a transfer, if yes, transfers the byte and sends it to the host, + otherwise, checks the next device, or if there is no device left to check, checks if IBF is full + and if yes, processes it. + */ +static int +kbc_scan_kbd_ps2(atkbc_t *dev) +{ + if ((dev->ports[0] != NULL) && (dev->ports[0]->out_new != -1)) { + kbc_at_log("ATkbc: %02X coming from channel 1\n", dev->ports[0]->out_new & 0xff); + kbc_send_to_ob(dev, dev->ports[0]->out_new, 1, 0x00); + dev->ports[0]->out_new = -1; + dev->state = STATE_MAIN_IBF; + return 1; + } + + return 0; +} + +static int +kbc_scan_aux_ps2(atkbc_t *dev) +{ + if ((dev->ports[1] != NULL) && (dev->ports[1]->out_new != -1)) { + kbc_at_log("ATkbc: %02X coming from channel 2\n", dev->ports[1]->out_new & 0xff); + kbc_send_to_ob(dev, dev->ports[1]->out_new, 2, 0x00); + dev->ports[1]->out_new = -1; + dev->state = STATE_MAIN_IBF; + return 1; + } + + return 0; +} + +static void +kbc_at_poll_ps2(atkbc_t *dev) +{ + switch (dev->state) { + case STATE_RESET: + if (dev->status & STAT_IFULL) { + dev->status = ((dev->status & 0x0f) | 0x10) & ~STAT_IFULL; + if ((dev->status & STAT_CD) && (dev->ib == 0xaa)) + kbc_at_process_cmd(dev); + } + break; + case STATE_KBC_AMI_OUT: + if (dev->status & STAT_OFULL) + break; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case STATE_MAIN_IBF: + default: +ps2_main_ibf: + if (dev->status & STAT_IFULL) + kbc_ibf_process(dev); + else if (!(dev->status & STAT_OFULL)) { + if (dev->mem[0x20] & 0x20) { + if (!(dev->mem[0x20] & 0x10)) { + dev->p2 &= 0xbf; + dev->state = STATE_MAIN_KBD; + } + } else { + dev->p2 &= 0xf7; + if (dev->mem[0x20] & 0x10) + dev->state = STATE_MAIN_AUX; + else { + dev->p2 &= 0xbf; + dev->state = STATE_MAIN_BOTH; + } + } + } + break; + case STATE_MAIN_KBD: + if (dev->status & STAT_IFULL) + kbc_ibf_process(dev); + else { + (void) kbc_scan_kbd_ps2(dev); + dev->state = STATE_MAIN_IBF; + } + break; + case STATE_MAIN_AUX: + if (dev->status & STAT_IFULL) + kbc_ibf_process(dev); + else { + (void) kbc_scan_aux_ps2(dev); + dev->state = STATE_MAIN_IBF; + } + break; + case STATE_MAIN_BOTH: + if (kbc_scan_kbd_ps2(dev)) + dev->state = STATE_MAIN_IBF; + else + dev->state = STATE_MAIN_AUX; + break; + case STATE_KBC_DELAY_OUT: + /* Keyboard controller command want to output a single byte. */ + kbc_at_log("ATkbc: %02X coming from channel %i with high status %02X\n", dev->val, dev->channel, dev->stat_hi); + kbc_send_to_ob(dev, dev->val, dev->channel, dev->stat_hi); +#if 0 + dev->state = (dev->pending == 2) ? STATE_KBC_AMI_OUT : STATE_MAIN_IBF; +#endif + dev->state = STATE_MAIN_IBF; + dev->pending = 0; + goto ps2_main_ibf; + break; + case STATE_KBC_OUT: + /* Keyboard controller command want to output multiple bytes. */ + if (dev->status & STAT_IFULL) { + /* Data from host aborts dumping. */ + dev->state = STATE_MAIN_IBF; + kbc_ibf_process(dev); + } + /* Do not continue dumping until OBF is clear. */ + if (!(dev->status & STAT_OFULL)) { + kbc_at_log("ATkbc: %02X coming from channel 0\n", dev->key_ctrl_queue[dev->key_ctrl_queue_start] & 0xff); + kbc_send_to_ob(dev, dev->key_ctrl_queue[dev->key_ctrl_queue_start], 0, 0x00); + dev->key_ctrl_queue_start = (dev->key_ctrl_queue_start + 1) & 0x3f; + if (dev->key_ctrl_queue_start == dev->key_ctrl_queue_end) + dev->state = STATE_MAIN_IBF; + } + break; + case STATE_KBC_PARAM: + /* Keyboard controller command wants data, wait for said data. */ + if (dev->status & STAT_IFULL) { + /* Command written, abort current command. */ + if (dev->status & STAT_CD) + dev->state = STATE_MAIN_IBF; + + dev->status &= ~STAT_IFULL; + kbc_at_process_cmd(dev); + } + break; + case STATE_SEND_KBD: + if (!dev->ports[0]->wantcmd) + dev->state = STATE_SCAN_KBD; + break; + case STATE_SCAN_KBD: + (void) kbc_scan_kbd_ps2(dev); + break; + case STATE_SEND_AUX: + if (!dev->ports[1]->wantcmd) + dev->state = STATE_SCAN_AUX; + break; + case STATE_SCAN_AUX: + (void) kbc_scan_aux_ps2(dev); + break; + } +} + +static void +kbc_at_poll(void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + + timer_advance_u64(&dev->send_delay_timer, (100ULL * TIMER_USEC)); + + /* TODO: Implement the password security state. */ + kbc_at_do_poll(dev); + + if ((kbc_at_ports[0] != NULL) && (kbc_at_ports[0]->priv != NULL)) + kbc_at_ports[0]->poll(kbc_at_ports[0]->priv); + + if ((kbc_at_ports[1] != NULL) && (kbc_at_ports[1]->priv != NULL)) + kbc_at_ports[1]->poll(kbc_at_ports[1]->priv); +} + +static void +write_p2(atkbc_t *dev, uint8_t val) +{ + uint8_t old = dev->p2; + kbc_at_log("ATkbc: write P2: %02X (old: %02X)\n", val, dev->p2); + + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + +#if 0 + /* PS/2: Handle IRQ's. */ + if (dev->misc_flags & FLAG_PS2) { + /* IRQ 12 */ + picint_common(1 << 12, 0, val & 0x20); + + /* IRQ 1 */ + picint_common(1 << 1, 0, val & 0x10); + } +#endif + + /* AT, PS/2: Handle A20. */ + if ((mem_a20_key ^ val) & 0x02) { /* A20 enable change */ + mem_a20_key = val & 0x02; + mem_a20_recalc(); + flushmmucache(); + } + + /* AT, PS/2: Handle reset. */ + /* 0 holds the CPU in the RESET state, 1 releases it. To simplify this, + we just do everything on release. */ + if ((old ^ val) & 0x01) { /*Reset*/ + if (!(val & 0x01)) { /* Pin 0 selected. */ + /* Pin 0 selected. */ + kbc_at_log("write_p2(): Pulse reset!\n"); + if (machines[machine].flags & MACHINE_COREBOOT) { + /* The SeaBIOS hard reset code attempts a KBC reset if ACPI RESET_REG + is not available. However, the KBC reset is normally a soft reset, so + SeaBIOS gets caught in a soft reset loop as it tries to hard reset the + machine. Hack around this by making the KBC reset a hard reset only on + coreboot machines. */ + pc_reset_hard(); + } else { + softresetx86(); /* Pulse reset! */ + cpu_set_edx(); + flushmmucache(); + if (kbc_ven == KBC_VEN_ALI) + smbase = 0x00030000; + /* Yes, this is a hack, but until someone gets ahold of the real PCD-2L + and can find out what they actually did to make it boot from FFFFF0 + correctly despite A20 being gated when the CPU is reset, this will + have to do. */ + else if (kbc_ven == KBC_VEN_SIEMENS) + loadcs(0xF000); + } + } + } + + /* Do this here to avoid an infinite reset loop. */ + dev->p2 = val; +} + +static void +write_p2_fast_a20(atkbc_t *dev, uint8_t val) +{ + uint8_t old = dev->p2; + kbc_at_log("ATkbc: write P2 in fast A20 mode: %02X (old: %02X)\n", val, dev->p2); + + /* AT, PS/2: Handle A20. */ + if ((old ^ val) & 0x02) { /* A20 enable change */ + mem_a20_key = val & 0x02; + mem_a20_recalc(); + flushmmucache(); + } + + /* Do this here to avoid an infinite reset loop. */ + dev->p2 = val; +} + +static void +write_cmd(atkbc_t *dev, uint8_t val) +{ + kbc_at_log("ATkbc: write command byte: %02X (old: %02X)\n", val, dev->mem[0x20]); + + /* PS/2 type 2 keyboard controllers always force the XLAT bit to 0. */ + if ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2) { + val &= ~CCB_TRANSLATE; + dev->mem[0x20] &= ~CCB_TRANSLATE; + } else if (!(dev->misc_flags & FLAG_PS2)) { + if (val & 0x10) + dev->mem[0x2e] = 0x01; + } + + kbc_at_log("ATkbc: keyboard interrupt is now %s\n", (val & 0x01) ? "enabled" : "disabled"); + + if (!(dev->misc_flags & FLAG_PS2)) { + /* Update P2 to mirror the IBF and OBF bits, if active. */ + write_p2(dev, (dev->p2 & 0x0f) | ((val & 0x03) << 4) | ((val & 0x20) ? 0xc0 : 0x00)); + } + + kbc_at_log("ATkbc: Command byte now: %02X (%02X)\n", dev->mem[0x20], val); + + dev->status = (dev->status & ~STAT_SYSFLAG) | (val & STAT_SYSFLAG); +} + +static void +pulse_output(atkbc_t *dev, uint8_t mask) +{ + if (mask != 0x0f) { + dev->old_p2 = dev->p2 & ~(0xf0 | mask); + kbc_at_log("ATkbc: pulse_output(): P2 now: %02X\n", dev->p2 & (0xf0 | mask)); + write_p2(dev, dev->p2 & (0xf0 | mask)); + timer_set_delay_u64(&dev->pulse_cb, 6ULL * TIMER_USEC); + } +} + +static void +pulse_poll(void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + + kbc_at_log("ATkbc: pulse_poll(): P2 now: %02X\n", dev->p2 | dev->old_p2); + write_p2(dev, dev->p2 | dev->old_p2); +} + +static uint8_t +write64_generic(void *priv, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + uint8_t current_drive; + uint8_t fixed_bits; + uint8_t kbc_ven = 0x0; + kbc_ven = dev->flags & KBC_VEN_MASK; + + switch (val) { + case 0xa4: /* check if password installed */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: check if password installed\n"); + kbc_delay_to_ob(dev, 0xf1, 0, 0x00); + return 0; + } + break; + + case 0xa5: /* load security */ + kbc_at_log("ATkbc: load security\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + return 0; + + case 0xa7: /* disable auxiliary port */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: disable auxiliary port\n"); + set_enable_aux(dev, 0); + return 0; + } + break; + + case 0xa8: /* Enable auxiliary port */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: enable auxiliary port\n"); + set_enable_aux(dev, 1); + return 0; + } + break; + + case 0xa9: /* Test auxiliary port */ + kbc_at_log("ATkbc: test auxiliary port\n"); + if (dev->misc_flags & FLAG_PS2) { + kbc_delay_to_ob(dev, 0x00, 0, 0x00); /* no error, this is testing the channel 2 interface */ + return 0; + } + break; + + case 0xaf: /* read keyboard version */ + kbc_at_log("ATkbc: read keyboard version\n"); + kbc_delay_to_ob(dev, kbc_award_revision, 0, 0x00); + return 0; + + /* + P1 bits: 76543210 + ----------------- + IBM PS/1: xxxxxxxx + IBM PS/2 MCA: xxxxx1xx + Intel AMI Pentium BIOS'es with AMI MegaKey KB-5 keyboard controller: x1x1xxxx + Acer: xxxxx0xx + Packard Bell PB450: xxxxx1xx + P6RP4: xx1xx1xx + Epson Action Tower 2600: xxxx01xx + TriGem Hawk: xxxx11xx + + Machine input based on current code: 11111111 + Everything non-Green: Pull down bit 7 if not PS/2 and keyboard is inhibited. + Pull down bit 6 if primary display is CGA. + Xi8088: Pull down bit 6 if primary display is MDA. + Acer: Pull down bit 6 if primary display is MDA. + Pull down bit 2 always (must be so to enable CMOS Setup). + IBM PS/1: Pull down bit 6 if current floppy drive is 3.5". + Epson Action Tower 2600: Pull down bit 3 always (for Epson logo). + NCR: Pull down bit 5 always (power-on default speed = high). + Pull down bit 3 if there is no FPU. + Pull down bits 1 and 0 always? + Compaq: Pull down bit 6 if Compaq dual-scan display is in use. + Pull down bit 5 if system board DIP switch is ON. + Pull down bit 4 if CPU speed selected is auto. + Pull down bit 3 if CPU speed selected is slow (4 MHz). + Pull down bit 2 if FPU is present. + Pull down bits 1 and 0 always? + + Bit 7: AT KBC only - keyboard inhibited (often physical lock): 0 = yes, 1 = no (also Compaq); + Bit 6: Mostly, display: 0 = CGA, 1 = MDA, inverted on Xi8088 and Acer KBC's; + Intel AMI MegaKey KB-5: Used for green features, SMM handler expects it to be set; + IBM PS/1 Model 2011: 0 = current FDD is 3.5", 1 = current FDD is 5.25"; + Comapq: 0 = Compaq dual-scan display, 1 = non-Compaq display. + Bit 5: Mostly, manufacturing jumper: 0 = installed (infinite loop at POST), 1 = not installed; + NCR: power-on default speed: 0 = high, 1 = low; + Compaq: System board DIP switch 5: 0 = ON, 1 = OFF. + Bit 4: (Which board?): RAM on motherboard: 0 = 512 kB, 1 = 256 kB; + NCR: RAM on motherboard: 0 = unsupported, 1 = 512 kB; + Intel AMI MegaKey KB-5: Must be 1; + IBM PS/1: Ignored; + Compaq: 0 = Auto speed selected, 1 = High speed selected. + Bit 3: TriGem AMIKey: most significant bit of 2-bit OEM ID; + NCR: Coprocessor detect (1 = yes, 0 = no); + Compaq: 0 = Slow (4 MHz), 1 = Fast (8 MHz); + Sometimes configured for clock switching; + Bit 2: TriGem AMIKey: least significant bit of 2-bit OEM ID; + Bit 3, 2: + 1, 1: TriGem logo; + 1, 0: Garbled logo; + 0, 1: Epson logo; + 0, 0: Generic AMI logo. + NCR: Unused; + IBM PS/2: Keyboard power: 0 = no power (fuse error), 1 = OK + (for some reason, www.win.tue.nl has this in reverse); + Compaq: FPU: 0 = 80287, 1 = none; + Sometimes configured for clock switching; + Bit 1: PS/2: Auxiliary device data in; + Compaq: Reserved; + NCR: High/auto speed. + Bit 0: PS/2: Keyboard device data in; + Compaq: Reserved; + NCR: DMA mode. + */ + case 0xc0: /* read P1 */ + kbc_at_log("ATkbc: read P1\n"); + fixed_bits = 4; + /* The SMM handlers of Intel AMI Pentium BIOS'es expect bit 6 to be set. */ + if ((kbc_ven == KBC_VEN_AMI) && ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_GREEN)) + fixed_bits |= 0x40; + if (kbc_ven == KBC_VEN_IBM_PS1) { + current_drive = fdc_get_current_drive(); + /* (B0 or F0) | (fdd_is_525(current_drive) on bit 6) */ + kbc_delay_to_ob(dev, dev->p1 | fixed_bits | (fdd_is_525(current_drive) ? 0x40 : 0x00), + 0, 0x00); + } else if (kbc_ven == KBC_VEN_NCR) { + /* switch settings + * bit 7: keyboard disable + * bit 6: display type (0 color, 1 mono) + * bit 5: power-on default speed (0 high, 1 low) + * bit 4: sense RAM size (0 unsupported, 1 512k on system board) + * bit 3: coprocessor detect + * bit 2: unused + * bit 1: high/auto speed + * bit 0: dma mode + */ + /* (B0 or F0) | 0x04 | (display on bit 6) | (fpu on bit 3) */ + kbc_delay_to_ob(dev, (dev->p1 | fixed_bits | (video_is_mda() ? 0x40 : 0x00) | (hasfpu ? 0x08 : 0x00)) & 0xdf, + 0, 0x00); + } else if (kbc_ven == KBC_VEN_TRIGEM_AMI) { + /* Bit 3, 2: + 1, 1: TriGem logo; + 1, 0: Garbled logo; + 0, 1: Epson logo; + 0, 0: Generic AMI logo. */ + if (dev->misc_flags & FLAG_PCI) + fixed_bits |= 8; + /* (B0 or F0) | (0x04 or 0x0c) */ + kbc_delay_to_ob(dev, dev->p1 | fixed_bits, 0, 0x00); + } else if (((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) && ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_GREEN)) + /* (B0 or F0) | (0x08 or 0x0c) */ + kbc_delay_to_ob(dev, ((dev->p1 | fixed_bits) & 0xf0) | (((dev->flags & KBC_VEN_MASK) == KBC_VEN_ACER) ? 0x08 : 0x0c), 0, 0x00); + else if (kbc_ven == KBC_VEN_COMPAQ) + kbc_delay_to_ob(dev, dev->p1 | (hasfpu ? 0x00 : 0x04), 0, 0x00); + else + /* (B0 or F0) | (0x04 or 0x44) */ + kbc_delay_to_ob(dev, dev->p1 | fixed_bits, 0, 0x00); + dev->p1 = ((dev->p1 + 1) & 3) | (dev->p1 & 0xfc); + return 0; + + case 0xc1: /*Copy bits 0 to 3 of P1 to status bits 4 to 7*/ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: copy bits 0 to 3 of P1 to status bits 4 to 7\n"); + dev->status &= 0x0f; + dev->status |= (dev->p1 << 4); + return 0; + } + break; + + case 0xc2: /*Copy bits 4 to 7 of P1 to status bits 4 to 7*/ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: copy bits 4 to 7 of P1 to status bits 4 to 7\n"); + dev->status &= 0x0f; + dev->status |= (dev->p1 & 0xf0); + return 0; + } + break; + + case 0xd3: /* write auxiliary output buffer */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: write auxiliary output buffer\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + return 0; + } + break; + + case 0xd4: /* write to auxiliary port */ + kbc_at_log("ATkbc: write to auxiliary port\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + return 0; + + case 0xf0 ... 0xff: + kbc_at_log("ATkbc: pulse %01X\n", val & 0x0f); + pulse_output(dev, val & 0x0f); + return 0; + + default: + break; + } + + kbc_at_log("ATkbc: bad command %02X\n", val); + return 1; +} + +static uint8_t +write60_ami(void *priv, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + + switch (dev->command) { + /* 0x40 - 0x5F are aliases for 0x60-0x7F */ + case 0x40 ... 0x5f: + kbc_at_log("ATkbc: AMI - alias write to %02X\n", dev->command & 0x1f); + dev->mem[(dev->command & 0x1f) + 0x20] = val; + if (dev->command == 0x60) + write_cmd(dev, val); + return 0; + + case 0xaf: /* set extended controller RAM */ + kbc_at_log("ATkbc: AMI - set extended controller RAM\n"); + if (dev->command_phase == 1) { + dev->mem_addr = val; + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + dev->command_phase = 2; + } else if (dev->command_phase == 2) { + dev->mem[dev->mem_addr] = val; + dev->command_phase = 0; + } + return 0; + + case 0xc1: + kbc_at_log("ATkbc: AMI MegaKey - write %02X to P1\n", val); + dev->p1 = val; + return 0; + + case 0xcb: /* set keyboard mode */ + kbc_at_log("ATkbc: AMI - set keyboard mode\n"); + dev->ami_flags = val; + dev->misc_flags &= ~FLAG_PS2; + if (val & 0x01) { + kbc_at_log("ATkbc: AMI: Emulate PS/2 keyboard\n"); + dev->misc_flags |= FLAG_PS2; + kbc_at_do_poll = kbc_at_poll_ps2; + } else { + kbc_at_log("ATkbc: AMI: Emulate AT keyboard\n"); + kbc_at_do_poll = kbc_at_poll_at; + } + return 0; + + default: + break; + } + + return 1; +} + +static uint8_t +write64_ami(void *priv, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + + switch (val) { + case 0x00 ... 0x1f: + kbc_at_log("ATkbc: AMI - alias read from %08X\n", val); + kbc_delay_to_ob(dev, dev->mem[val + 0x20], 0, 0x00); + return 0; + + case 0x40 ... 0x5f: + kbc_at_log("ATkbc: AMI - alias write to %08X\n", dev->command); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + return 0; + + case 0xa0: /* copyright message */ + kbc_at_queue_add(dev, 0x28); + kbc_at_queue_add(dev, 0x00); + return 0; + + case 0xa1: /* get controller version */ + kbc_at_log("ATkbc: AMI - get controller version\n"); + kbc_delay_to_ob(dev, kbc_ami_revision, 0, 0x00); + return 0; + + case 0xa2: /* clear keyboard controller lines P22/P23 */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - clear KBC lines P22 and P23\n"); + write_p2(dev, dev->p2 & 0xf3); + kbc_delay_to_ob(dev, 0x00, 0, 0x00); + return 0; + } + break; + + case 0xa3: /* set keyboard controller lines P22/P23 */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - set KBC lines P22 and P23\n"); + write_p2(dev, dev->p2 | 0x0c); + kbc_delay_to_ob(dev, 0x00, 0, 0x00); + return 0; + } + break; + + case 0xa4: /* write clock = low */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - write clock = low\n"); + dev->misc_flags &= ~FLAG_CLOCK; + return 0; + } + break; + + case 0xa5: /* write clock = high */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - write clock = high\n"); + dev->misc_flags |= FLAG_CLOCK; + return 0; + } + + case 0xa6: /* read clock */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - read clock\n"); + kbc_delay_to_ob(dev, (dev->misc_flags & FLAG_CLOCK) ? 0xff : 0x00, 0, 0x00); + return 0; + } + break; + + case 0xa7: /* write cache bad */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - write cache bad\n"); + dev->misc_flags &= FLAG_CACHE; + return 0; + } + break; + + case 0xa8: /* write cache good */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - write cache good\n"); + dev->misc_flags |= FLAG_CACHE; + return 0; + } + break; + + case 0xa9: /* read cache */ + if (!(dev->misc_flags & FLAG_PS2)) { + kbc_at_log("ATkbc: AMI - read cache\n"); + kbc_delay_to_ob(dev, (dev->misc_flags & FLAG_CACHE) ? 0xff : 0x00, 0, 0x00); + return 0; + } + break; + + case 0xaf: /* set extended controller RAM */ + if ((kbc_ven != KBC_VEN_SIEMENS) && (kbc_ven != KBC_VEN_ALI)) { + kbc_at_log("ATkbc: set extended controller RAM\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + dev->command_phase = 1; + return 0; + } + break; + + case 0xb0 ... 0xb3: + /* set KBC lines P10-P13 (P1 bits 0-3) low */ + kbc_at_log("ATkbc: set KBC lines P10-P13 (P1 bits 0-3) low\n"); + if (!(dev->flags & DEVICE_PCI) || (val > 0xb1)) + dev->p1 &= ~(1 << (val & 0x03)); + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + return 0; + + /* TODO: The ICS SB486PV sends command B4 but expects to read *TWO* bytes. */ + case 0xb4: case 0xb5: + /* set KBC lines P22-P23 (P2 bits 2-3) low */ + kbc_at_log("ATkbc: set KBC lines P22-P23 (P2 bits 2-3) low\n"); + if (!(dev->flags & DEVICE_PCI)) + write_p2(dev, dev->p2 & ~(4 << (val & 0x01))); + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + return 0; + + case 0xb8 ... 0xbb: + /* set KBC lines P10-P13 (P1 bits 0-3) high */ + kbc_at_log("ATkbc: set KBC lines P10-P13 (P1 bits 0-3) high\n"); + if (!(dev->flags & DEVICE_PCI) || (val > 0xb9)) { + dev->p1 |= (1 << (val & 0x03)); + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + } + return 0; + + case 0xbc: case 0xbd: + /* set KBC lines P22-P23 (P2 bits 2-3) high */ + kbc_at_log("ATkbc: set KBC lines P22-P23 (P2 bits 2-3) high\n"); + if (!(dev->flags & DEVICE_PCI)) + write_p2(dev, dev->p2 | (4 << (val & 0x01))); + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + return 0; + + case 0xc1: /* write P1 */ + kbc_at_log("ATkbc: AMI MegaKey - write P1\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + return 0; + + case 0xc4: + /* set KBC line P14 low */ + kbc_at_log("ATkbc: set KBC line P14 (P1 bit 4) low\n"); + dev->p1 &= 0xef; + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + return 0; + case 0xc5: + /* set KBC line P15 low */ + kbc_at_log("ATkbc: set KBC line P15 (P1 bit 5) low\n"); + dev->p1 &= 0xdf; + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + return 0; + + case 0xc8: + /* + * unblock KBC lines P22/P23 + * (allow command D1 to change bits 2/3 of P2) + */ + kbc_at_log("ATkbc: AMI - unblock KBC lines P22 and P23\n"); + dev->ami_flags &= 0xfb; + return 0; + + case 0xc9: + /* + * block KBC lines P22/P23 + * (disallow command D1 from changing bits 2/3 of the port) + */ + kbc_at_log("ATkbc: AMI - block KBC lines P22 and P23\n"); + dev->ami_flags |= 0x04; + return 0; + + case 0xcc: + /* set KBC line P14 high */ + kbc_at_log("ATkbc: set KBC line P14 (P1 bit 4) high\n"); + dev->p1 |= 0x10; + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + return 0; + case 0xcd: + /* set KBC line P15 high */ + kbc_at_log("ATkbc: set KBC line P15 (P1 bit 5) high\n"); + dev->p1 |= 0x20; + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); + dev->pending++; + return 0; + + case 0xef: /* ??? - sent by AMI486 */ + kbc_at_log("ATkbc: ??? - sent by AMI486\n"); + return 0; + + default: + break; + } + + return write64_generic(dev, val); +} + +static uint8_t +write64_siemens(void *priv, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + + switch (val) { + case 0x92: /*Siemens Award - 92 sent by PCD-2L BIOS*/ + kbc_at_log("Siemens Award - 92 sent by PCD-2L BIOS\n"); + return 0; + + case 0x94: /*Siemens Award - 94 sent by PCD-2L BIOS*/ + kbc_at_log("Siemens Award - 94 sent by PCD-2L BIOS\n"); + return 0; + + case 0x9a: /*Siemens Award - 9A sent by PCD-2L BIOS*/ + kbc_at_log("Siemens Award - 9A sent by PCD-2L BIOS\n"); + return 0; + + case 0x9c: /*Siemens Award - 9C sent by PCD-2L BIOS*/ + kbc_at_log("Siemens Award - 9C sent by PCD-2L BIOS\n"); + return 0; + + case 0xa9: /*Siemens Award - A9 sent by PCD-2L BIOS*/ + kbc_at_log("Siemens Award - A9 sent by PCD-2L BIOS\n"); + return 0; + + default: + break; + } + + return write64_ami(dev, val); +} + +static uint8_t +write60_quadtel(void *priv, UNUSED(uint8_t val)) +{ + const atkbc_t *dev = (atkbc_t *) priv; + + switch (dev->command) { + case 0xcf: /*??? - sent by MegaPC BIOS*/ + kbc_at_log("ATkbc: ??? - sent by MegaPC BIOS\n"); + return 0; + + default: + break; + } + + return 1; +} + +static uint8_t +write64_olivetti(void *priv, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + + switch (val) { + case 0x80: /* Olivetti-specific command */ + /* + * bit 7: bus expansion board present (M300) / keyboard unlocked (M290) + * bits 4-6: ??? + * bit 3: fast ram check (if inactive keyboard works erratically) + * bit 2: keyboard fuse present + * bits 0-1: ??? + */ + kbc_delay_to_ob(dev, (0x0c | (is386 ? 0x00 : 0x80)) & 0xdf, 0, 0x00); + dev->p1 = ((dev->p1 + 1) & 3) | (dev->p1 & 0xfc); + return 0; + + default: + break; + } + + return write64_generic(dev, val); +} + +static uint8_t +write64_quadtel(void *priv, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + + switch (val) { + case 0xaf: + kbc_at_log("ATkbc: bad KBC command AF\n"); + return 1; + + case 0xcf: /*??? - sent by MegaPC BIOS*/ + kbc_at_log("ATkbc: ??? - sent by MegaPC BIOS\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + return 0; + + default: + break; + } + + return write64_generic(dev, val); +} + +static uint8_t +write60_toshiba(void *priv, uint8_t val) +{ + const atkbc_t *dev = (atkbc_t *) priv; + + switch (dev->command) { + case 0xb6: /* T3100e - set color/mono switch */ + kbc_at_log("ATkbc: T3100e - set color/mono switch\n"); + t3100e_mono_set(val); + return 0; + + default: + break; + } + + return 1; +} + +static uint8_t +write64_toshiba(void *priv, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + + switch (val) { + case 0xaf: + kbc_at_log("ATkbc: bad KBC command AF\n"); + return 1; + + case 0xb0: /* T3100e: Turbo on */ + kbc_at_log("ATkbc: T3100e: Turbo on\n"); + t3100e_turbo_set(1); + return 0; + + case 0xb1: /* T3100e: Turbo off */ + kbc_at_log("ATkbc: T3100e: Turbo off\n"); + t3100e_turbo_set(0); + return 0; + + case 0xb2: /* T3100e: Select external display */ + kbc_at_log("ATkbc: T3100e: Select external display\n"); + t3100e_display_set(0x00); + return 0; + + case 0xb3: /* T3100e: Select internal display */ + kbc_at_log("ATkbc: T3100e: Select internal display\n"); + t3100e_display_set(0x01); + return 0; + + case 0xb4: /* T3100e: Get configuration / status */ + kbc_at_log("ATkbc: T3100e: Get configuration / status\n"); + kbc_delay_to_ob(dev, t3100e_config_get(), 0, 0x00); + return 0; + + case 0xb5: /* T3100e: Get colour / mono byte */ + kbc_at_log("ATkbc: T3100e: Get colour / mono byte\n"); + kbc_delay_to_ob(dev, t3100e_mono_get(), 0, 0x00); + return 0; + + case 0xb6: /* T3100e: Set colour / mono byte */ + kbc_at_log("ATkbc: T3100e: Set colour / mono byte\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + return 0; + + /* TODO: Toshiba KBC mode switching. */ + case 0xb7: /* T3100e: Emulate PS/2 keyboard */ + case 0xb8: /* T3100e: Emulate AT keyboard */ + dev->misc_flags &= ~FLAG_PS2; + if (val == 0xb7) { + kbc_at_log("ATkbc: T3100e: Emulate PS/2 keyboard\n"); + dev->misc_flags |= FLAG_PS2; + kbc_at_do_poll = kbc_at_poll_ps2; + } else { + kbc_at_log("ATkbc: T3100e: Emulate AT keyboard\n"); + kbc_at_do_poll = kbc_at_poll_at; + } + return 0; + + case 0xbb: /* T3100e: Read 'Fn' key. + Return it for right Ctrl and right Alt; on the real + T3100e, these keystrokes could only be generated + using 'Fn'. */ + kbc_at_log("ATkbc: T3100e: Read 'Fn' key\n"); + if (keyboard_recv(0xb8) || /* Right Alt */ + keyboard_recv(0x9d)) /* Right Ctrl */ + kbc_delay_to_ob(dev, 0x04, 0, 0x00); + else + kbc_delay_to_ob(dev, 0x00, 0, 0x00); + return 0; + + case 0xbc: /* T3100e: Reset Fn+Key notification */ + kbc_at_log("ATkbc: T3100e: Reset Fn+Key notification\n"); + t3100e_notify_set(0x00); + return 0; + + case 0xc0: /* Read P1 */ + kbc_at_log("ATkbc: read P1\n"); + + /* The T3100e returns all bits set except bit 6 which + * is set by t3100e_mono_set() */ + dev->p1 = (t3100e_mono_get() & 1) ? 0xff : 0xbf; + kbc_delay_to_ob(dev, dev->p1, 0, 0x00); + return 0; + + default: + break; + } + + return write64_generic(dev, val); +} + +static void +kbc_at_process_cmd(void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + int bad = 1; + uint8_t mask; + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + uint8_t cmd_ac_conv[16] = { 0x0b, 2, 3, 4, 5, 6, 7, 8, 9, 0x0a, 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21 }; + + if (dev->status & STAT_CD) { + /* Controller command. */ + dev->wantdata = 0; + dev->state = STATE_MAIN_IBF; + + /* Clear the keyboard controller queue. */ + kbc_at_queue_reset(dev); + + switch (dev->ib) { + /* Read data from KBC memory. */ + case 0x20 ... 0x3f: + kbc_delay_to_ob(dev, dev->mem[dev->ib], 0, 0x00); + if (dev->ib == 0x20) + dev->pending++; + break; + + /* Write data to KBC memory. */ + case 0x60 ... 0x7f: + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + break; + + case 0xaa: /* self-test */ + kbc_at_log("ATkbc: self-test\n"); + + if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) { + if (dev->state != STATE_RESET) { + kbc_at_log("ATkbc: self-test reinitialization\n"); + /* Yes, the firmware has an OR, but we need to make sure to keep any forcibly lowered bytes lowered. */ + /* TODO: Proper P1 implementation, with OR and AND flags in the machine table. */ + dev->p1 = dev->p1 & 0xff; + write_p2(dev, 0x4b); + picintc(0x1002); + } + + dev->status = (dev->status & 0x0f) | 0x60; + + dev->mem[0x20] = 0x30; + dev->mem[0x22] = 0x0b; + dev->mem[0x25] = 0x02; + dev->mem[0x27] = 0xf8; + dev->mem[0x28] = 0xce; + dev->mem[0x29] = 0x0b; + dev->mem[0x30] = 0x0b; + } else { + if (dev->state != STATE_RESET) { + kbc_at_log("ATkbc: self-test reinitialization\n"); + /* Yes, the firmware has an OR, but we need to make sure to keep any forcibly lowered bytes lowered. */ + /* TODO: Proper P1 implementation, with OR and AND flags in the machine table. */ + dev->p1 = dev->p1 & 0xff; + write_p2(dev, 0xcf); + picintc(0x0002); + } + + dev->status = (dev->status & 0x0f) | 0x60; + + dev->mem[0x20] = 0x10; + dev->mem[0x22] = 0x06; + dev->mem[0x25] = 0x01; + dev->mem[0x27] = 0xfb; + dev->mem[0x28] = 0xe0; + dev->mem[0x29] = 0x06; + } + + dev->mem[0x21] = 0x01; + dev->mem[0x2a] = 0x10; + dev->mem[0x2b] = 0x20; + dev->mem[0x2c] = 0x15; + + if (dev->ports[0] != NULL) + dev->ports[0]->out_new = -1; + if (dev->ports[1] != NULL) + dev->ports[1]->out_new = -1; + kbc_at_queue_reset(dev); + + kbc_at_queue_add(dev, 0x55); + break; + + case 0xab: /* interface test */ + kbc_at_log("ATkbc: interface test\n"); + kbc_delay_to_ob(dev, 0x00, 0, 0x00); /*no error*/ + break; + + case 0xac: /* diagnostic dump */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: diagnostic dump\n"); + dev->mem[0x30] = (dev->p1 & 0xf0) | 0x80; + dev->mem[0x31] = dev->p2; + dev->mem[0x32] = 0x00; /* T0 and T1. */ + dev->mem[0x33] = 0x00; /* PSW - Program Status Word - always return 0x00 because we do not emulate this byte. */ + /* 20 bytes in high nibble in set 1, low nibble in set 1, set 1 space format = 60 bytes. */ + for (uint8_t i = 0; i < 20; i++) { + kbc_at_queue_add(dev, cmd_ac_conv[dev->mem[i + 0x20] >> 4]); + kbc_at_queue_add(dev, cmd_ac_conv[dev->mem[i + 0x20] & 0x0f]); + kbc_at_queue_add(dev, 0x39); + } + } + break; + + case 0xad: /* disable keyboard */ + kbc_at_log("ATkbc: disable keyboard\n"); + set_enable_kbd(dev, 0); + break; + + case 0xae: /* enable keyboard */ + kbc_at_log("ATkbc: enable keyboard\n"); + set_enable_kbd(dev, 1); + break; + + case 0xc7: /* set port1 bits */ + kbc_at_log("ATkbc: Phoenix - set port1 bits\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + break; + + case 0xca: /* read keyboard mode */ + kbc_at_log("ATkbc: AMI - read keyboard mode\n"); + kbc_delay_to_ob(dev, dev->ami_flags, 0, 0x00); + break; + + case 0xcb: /* set keyboard mode */ + kbc_at_log("ATkbc: AMI - set keyboard mode\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + break; + + case 0xd0: /* read P2 */ + kbc_at_log("ATkbc: read P2\n"); + mask = 0xff; + if ((kbc_ven != KBC_VEN_OLIVETTI) && !(dev->misc_flags & FLAG_PS2) && (dev->mem[0x20] & 0x10)) + mask &= 0xbf; + kbc_delay_to_ob(dev, ((dev->p2 & 0xfd) | mem_a20_key) & mask, 0, 0x00); + break; + + case 0xd1: /* write P2 */ + kbc_at_log("ATkbc: write P2\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + break; + + case 0xd2: /* write keyboard output buffer */ + kbc_at_log("ATkbc: write keyboard output buffer\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + break; + + case 0xdd: /* disable A20 address line */ + case 0xdf: /* enable A20 address line */ + kbc_at_log("ATkbc: %sable A20\n", (dev->ib == 0xdd) ? "dis" : "en"); + write_p2_fast_a20(dev, (dev->p2 & 0xfd) | (dev->ib & 0x02)); + break; + + case 0xe0: /* read test inputs */ + kbc_at_log("ATkbc: read test inputs\n"); + kbc_delay_to_ob(dev, 0x00, 0, 0x00); + break; + + default: + /* + * Unrecognized controller command. + * + * If we have a vendor-specific handler, run + * that. Otherwise, or if that handler fails, + * log a bad command. + */ + if (dev->write64_ven) + bad = dev->write64_ven(dev, dev->ib); + + kbc_at_log(bad ? "ATkbc: bad controller command %02X\n" : "", dev->ib); + } + + /* If the command needs data, remember the command. */ + if (dev->wantdata) + dev->command = dev->ib; + } else if (dev->wantdata) { + /* Write data to controller. */ + dev->wantdata = 0; + dev->state = STATE_MAIN_IBF; + + switch (dev->command) { + case 0x60 ... 0x7f: + dev->mem[(dev->command & 0x1f) + 0x20] = dev->ib; + if (dev->command == 0x60) + write_cmd(dev, dev->ib); + break; + + case 0xa5: /* load security */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: load security (%02X)\n", dev->ib); + + if (dev->ib != 0x00) { + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + } + } + break; + + case 0xc7: /* set port1 bits */ + kbc_at_log("ATkbc: Phoenix - set port1 bits\n"); + dev->p1 |= dev->ib; + break; + + case 0xd1: /* write P2 */ + kbc_at_log("ATkbc: write P2\n"); + /* Bit 2 of AMI flags is P22-P23 blocked (1 = yes, 0 = no), + discovered by reverse-engineering the AOpen Vi15G BIOS. */ + if (dev->ami_flags & 0x04) { + /* If keyboard controller lines P22-P23 are blocked, + we force them to remain unchanged. */ + dev->ib &= ~0x0c; + dev->ib |= (dev->p2 & 0x0c); + } + write_p2(dev, dev->ib | 0x01); + break; + + case 0xd2: /* write to keyboard output buffer */ + kbc_at_log("ATkbc: write to keyboard output buffer\n"); + kbc_delay_to_ob(dev, dev->ib, 0, 0x00); + break; + + case 0xd3: /* write to auxiliary output buffer */ + kbc_at_log("ATkbc: write to auxiliary output buffer\n"); + kbc_delay_to_ob(dev, dev->ib, 2, 0x00); + break; + + case 0xd4: /* write to auxiliary port */ + kbc_at_log("ATkbc: write to auxiliary port (%02X)\n", dev->ib); + + if (dev->ib == 0xbb) + break; + + if (dev->misc_flags & FLAG_PS2) { + set_enable_aux(dev, 1); + if ((dev->ports[1] != NULL) && (dev->ports[1]->priv != NULL)) { + dev->ports[1]->wantcmd = 1; + dev->ports[1]->dat = dev->ib; + dev->state = STATE_SEND_AUX; + } else + kbc_delay_to_ob(dev, 0xfe, 2, 0x40); + } + break; + + default: + /* + * Run the vendor-specific handler + * if we have one. Otherwise, or if + * it returns an error, log a bad + * controller command. + */ + if (dev->write60_ven) + bad = dev->write60_ven(dev, dev->ib); + + if (bad) { + kbc_at_log("ATkbc: bad controller command %02x data %02x\n", dev->command, dev->ib); + } + } + } +} + +static void +kbc_at_write(uint16_t port, uint8_t val, void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + uint8_t fast_a20 = (kbc_ven != KBC_VEN_SIEMENS); + + kbc_at_log("ATkbc: [%04X:%08X] write(%04X) = %02X\n", CS, cpu_state.pc, port, val); + + switch (port) { + case 0x60: + dev->status &= ~STAT_CD; + if (fast_a20 && dev->wantdata && (dev->command == 0xd1)) { + kbc_at_log("ATkbc: write P2\n"); + +#if 0 + /* Fast A20 - ignore all other bits. */ + val = (val & 0x02) | (dev->p2 & 0xfd); + + /* Bit 2 of AMI flags is P22-P23 blocked (1 = yes, 0 = no), + discovered by reverse-engineering the AOpeN Vi15G BIOS. */ + if (dev->ami_flags & 0x04) { + /* If keyboard controller lines P22-P23 are blocked, + we force them to remain unchanged. */ + val &= ~0x0c; + val |= (dev->p2 & 0x0c); + } + + write_p2_fast_a20(dev, val | 0x01); +#else + /* Fast A20 - ignore all other bits. */ + write_p2_fast_a20(dev, (dev->p2 & 0xfd) | (val & 0x02)); +#endif + + dev->wantdata = 0; + dev->state = STATE_MAIN_IBF; + return; + } + break; + + case 0x64: + dev->status |= STAT_CD; + if (fast_a20 && (val == 0xd1)) { + kbc_at_log("ATkbc: write P2\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + dev->command = 0xd1; + return; + } + break; + + default: + break; + } + + dev->ib = val; + dev->status |= STAT_IFULL; +} + +static uint8_t +kbc_at_read(uint16_t port, void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 0xff; + + if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) + cycles -= ISA_CYCLES(8); + + switch (port) { + case 0x60: + ret = dev->ob; + dev->status &= ~STAT_OFULL; + /* TODO: IRQ is only tied to OBF on the AT KBC, on the PS/2 KBC, it is controlled by a P2 bit. + This also means that in AT mode, the IRQ is level-triggered. */ + if (!(dev->misc_flags & FLAG_PS2)) + picintc(1 << 1); + break; + + case 0x64: + ret = dev->status; + break; + + default: + kbc_at_log("ATkbc: read(%04x) invalid!\n",port); + break; + } + + kbc_at_log("ATkbc: [%04X:%08X] read (%04X) = %02X\n", CS, cpu_state.pc, port, ret); + + return ret; +} + +static void +kbc_at_reset(void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + + dev->status = STAT_UNLOCKED; + dev->mem[0x20] = 0x01; + dev->mem[0x20] |= CCB_TRANSLATE; + dev->command_phase = 0; + + /* Set up the correct Video Type bits. */ + if (!is286 || (kbc_ven == KBC_VEN_ACER)) + dev->p1 = video_is_mda() ? 0xb0 : 0xf0; + else + dev->p1 = video_is_mda() ? 0xf0 : 0xb0; + kbc_at_log("ATkbc: P1 = %02x\n", dev->p1); + + /* Disabled both the keyboard and auxiliary ports. */ + set_enable_kbd(dev, 0); + set_enable_aux(dev, 0); + + kbc_at_queue_reset(dev); + + dev->sc_or = 0; + + dev->ami_flags = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) ? 0x01 : 0x00; + dev->misc_flags &= FLAG_PCI; + + if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) { + dev->misc_flags |= FLAG_PS2; + kbc_at_do_poll = kbc_at_poll_ps2; + } else + kbc_at_do_poll = kbc_at_poll_at; + + dev->misc_flags |= FLAG_CACHE; + + dev->p2 = 0xcd; + if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) { + write_p2(dev, 0x4b); + } else { + /* The real thing writes CF and then AND's it with BF. */ + write_p2(dev, 0x8f); + } + + /* Stage 1. */ + dev->status = (dev->status & 0x0f) | (dev->p1 & 0xf0); +} + +static void +kbc_at_close(void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + int max_ports = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) ? 2 : 1; + + kbc_at_reset(dev); + + /* Stop timers. */ + timer_disable(&dev->send_delay_timer); + + for (int i = 0; i < max_ports; i++) { + if (kbc_at_ports[i] != NULL) { + free(kbc_at_ports[i]); + kbc_at_ports[i] = NULL; + } + } + + free(dev); +} + +static void * +kbc_at_init(const device_t *info) +{ + atkbc_t *dev; + int max_ports; + + dev = (atkbc_t *) malloc(sizeof(atkbc_t)); + memset(dev, 0x00, sizeof(atkbc_t)); + + dev->flags = info->local; + + video_reset(gfxcard[0]); + kbc_at_reset(dev); + + if (info->flags & DEVICE_PCI) + dev->misc_flags |= FLAG_PCI; + + io_sethandler(0x0060, 1, kbc_at_read, NULL, NULL, kbc_at_write, NULL, NULL, dev); + io_sethandler(0x0064, 1, kbc_at_read, NULL, NULL, kbc_at_write, NULL, NULL, dev); + + timer_add(&dev->send_delay_timer, kbc_at_poll, dev, 1); + timer_add(&dev->pulse_cb, pulse_poll, dev, 0); + + dev->write60_ven = NULL; + dev->write64_ven = NULL; + + kbc_ami_revision = '8'; + kbc_award_revision = 0x42; + + switch (dev->flags & KBC_VEN_MASK) { + case KBC_VEN_SIEMENS: + kbc_ami_revision = '8'; + kbc_award_revision = 0x42; + dev->write60_ven = write60_ami; + dev->write64_ven = write64_siemens; + break; + + case KBC_VEN_ACER: + case KBC_VEN_GENERIC: + case KBC_VEN_NCR: + case KBC_VEN_IBM_PS1: + case KBC_VEN_COMPAQ: + dev->write64_ven = write64_generic; + break; + + case KBC_VEN_OLIVETTI: + dev->write64_ven = write64_olivetti; + break; + + case KBC_VEN_ALI: + kbc_ami_revision = 'F'; + kbc_award_revision = 0x43; + dev->write60_ven = write60_ami; + dev->write64_ven = write64_ami; + break; + + case KBC_VEN_TRIGEM_AMI: + kbc_ami_revision = 'Z'; + dev->write60_ven = write60_ami; + dev->write64_ven = write64_ami; + break; + + case KBC_VEN_AMI: + if ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_GREEN) + kbc_ami_revision = '5'; + else if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) { + if (cpu_64bitbus) + kbc_ami_revision = 'R'; + else if (is486) + kbc_ami_revision = 'P'; + else + kbc_ami_revision = 'H'; + } else if (is386 && !is486) { + if (cpu_16bitbus) + kbc_ami_revision = 'D'; + else + kbc_ami_revision = 'B'; + } else if (!is386) + kbc_ami_revision = '8'; + else + kbc_ami_revision = 'F'; + + dev->write60_ven = write60_ami; + dev->write64_ven = write64_ami; + break; + + case KBC_VEN_QUADTEL: + dev->write60_ven = write60_quadtel; + dev->write64_ven = write64_quadtel; + break; + + case KBC_VEN_TOSHIBA: + dev->write60_ven = write60_toshiba; + dev->write64_ven = write64_toshiba; + break; + + default: + break; + } + + max_ports = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) ? 2 : 1; + + for (int i = 0; i < max_ports; i++) { + kbc_at_ports[i] = (kbc_at_port_t *) malloc(sizeof(kbc_at_port_t)); + memset(kbc_at_ports[i], 0x00, sizeof(kbc_at_port_t)); + kbc_at_ports[i]->out_new = -1; + } + + dev->ports[0] = kbc_at_ports[0]; + dev->ports[1] = kbc_at_ports[1]; + + /* The actual keyboard. */ + device_add(&keyboard_at_generic_device); + + return dev; +} + +const device_t keyboard_at_device = { + .name = "PC/AT Keyboard", + .internal_name = "keyboard_at", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_GENERIC, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_siemens_device = { + .name = "PC/AT Keyboard", + .internal_name = "keyboard_at", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_SIEMENS, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_ami_device = { + .name = "PC/AT Keyboard (AMI)", + .internal_name = "keyboard_at_ami", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_AMI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_tg_ami_device = { + .name = "PC/AT Keyboard (TriGem AMI)", + .internal_name = "keyboard_at_tg_ami", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_TRIGEM_AMI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_toshiba_device = { + .name = "PC/AT Keyboard (Toshiba)", + .internal_name = "keyboard_at_toshiba", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_TOSHIBA, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_olivetti_device = { + .name = "PC/AT Keyboard (Olivetti)", + .internal_name = "keyboard_at_olivetti", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_OLIVETTI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_ncr_device = { + .name = "PC/AT Keyboard (NCR)", + .internal_name = "keyboard_at_ncr", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_NCR, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_compaq_device = { + .name = "PC/AT Keyboard (Compaq)", + .internal_name = "keyboard_at_compaq", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_COMPAQ, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_device = { + .name = "PS/2 Keyboard", + .internal_name = "keyboard_ps2", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_1 | KBC_VEN_GENERIC, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_ps1_device = { + .name = "PS/2 Keyboard (IBM PS/1)", + .internal_name = "keyboard_ps2_ps1", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_1 | KBC_VEN_IBM_PS1, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_ps1_pci_device = { + .name = "PS/2 Keyboard (IBM PS/1)", + .internal_name = "keyboard_ps2_ps1_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_PS2_1 | KBC_VEN_IBM_PS1, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_xi8088_device = { + .name = "PS/2 Keyboard (Xi8088)", + .internal_name = "keyboard_ps2_xi8088", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_1 | KBC_VEN_GENERIC, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_ami_device = { + .name = "PS/2 Keyboard (AMI)", + .internal_name = "keyboard_ps2_ami", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_1 | KBC_VEN_AMI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_tg_ami_device = { + .name = "PS/2 Keyboard (TriGem AMI)", + .internal_name = "keyboard_ps2_tg_ami", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_1 | KBC_VEN_TRIGEM_AMI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_mca_2_device = { + .name = "PS/2 Keyboard", + .internal_name = "keyboard_ps2_mca_2", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_2 | KBC_VEN_GENERIC, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_quadtel_device = { + .name = "PS/2 Keyboard (Quadtel/MegaPC)", + .internal_name = "keyboard_ps2_quadtel", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_1 | KBC_VEN_QUADTEL, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_pci_device = { + .name = "PS/2 Keyboard", + .internal_name = "keyboard_ps2_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_PS2_1 | KBC_VEN_GENERIC, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_ami_pci_device = { + .name = "PS/2 Keyboard (AMI)", + .internal_name = "keyboard_ps2_ami_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_PS2_1 | KBC_VEN_AMI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_ali_pci_device = { + .name = "PS/2 Keyboard (ALi M5123/M1543C)", + .internal_name = "keyboard_ps2_ali_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_PS2_1 | KBC_VEN_ALI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_intel_ami_pci_device = { + .name = "PS/2 Keyboard (AMI)", + .internal_name = "keyboard_ps2_intel_ami_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_GREEN | KBC_VEN_AMI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_tg_ami_pci_device = { + .name = "PS/2 Keyboard (TriGem AMI)", + .internal_name = "keyboard_ps2_tg_ami_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_PS2_1 | KBC_VEN_TRIGEM_AMI, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_acer_pci_device = { + .name = "PS/2 Keyboard (Acer 90M002A)", + .internal_name = "keyboard_ps2_acer_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_PS2_1 | KBC_VEN_ACER, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/device/kbc_at_dev.c b/src/device/kbc_at_dev.c new file mode 100644 index 000000000..894b5f08a --- /dev/null +++ b/src/device/kbc_at_dev.c @@ -0,0 +1,216 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * AT / PS/2 attached device emulation. + * + * + * + * Authors: Miran Grca, + * + * Copyright 2023 Miran Grca. + */ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/ppi.h> +#include <86box/mem.h> +#include <86box/device.h> +#include <86box/machine.h> +#include <86box/m_at_t3100e.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/sound.h> +#include <86box/snd_speaker.h> +#include <86box/video.h> +#include <86box/keyboard.h> +#include <86box/plat_fallthrough.h> + +#ifdef ENABLE_KBC_AT_DEV_LOG +int kbc_at_dev_do_log = ENABLE_KBC_AT_DEV_LOG; + +static void +kbc_at_dev_log(const char *fmt, ...) +{ + va_list ap; + + if (kbc_at_dev_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define kbc_at_dev_log(fmt, ...) +#endif + +static void +kbc_at_dev_queue_reset(atkbc_dev_t *dev, uint8_t reset_main) +{ + if (reset_main) { + dev->queue_start = dev->queue_end = 0; + memset(dev->queue, 0x00, sizeof(dev->queue)); + } + + dev->cmd_queue_start = dev->cmd_queue_end = 0; + memset(dev->cmd_queue, 0x00, sizeof(dev->cmd_queue)); +} + +uint8_t +kbc_at_dev_queue_pos(atkbc_dev_t *dev, uint8_t main) +{ + uint8_t ret; + + if (main) + ret = ((dev->queue_end - dev->queue_start) & dev->fifo_mask); + else + ret = ((dev->cmd_queue_end - dev->cmd_queue_start) & 0xf); + + return ret; +} + +void +kbc_at_dev_queue_add(atkbc_dev_t *dev, uint8_t val, uint8_t main) +{ + if (main) { + kbc_at_dev_log("%s: dev->queue[%02X] = %02X;\n", dev->name, dev->queue_end, val); + dev->queue[dev->queue_end] = val; + dev->queue_end = (dev->queue_end + 1) & dev->fifo_mask; + } else { + kbc_at_dev_log("%s: dev->cmd_queue[%02X] = %02X;\n", dev->name, dev->cmd_queue_end, val); + dev->cmd_queue[dev->cmd_queue_end] = val; + dev->cmd_queue_end = (dev->cmd_queue_end + 1) & 0xf; + } + + /* TODO: This should be done on actual send to host. */ + if (val != 0xfe) + dev->last_scan_code = val; +} + +static void +kbc_at_dev_poll(void *priv) +{ + atkbc_dev_t *dev = (atkbc_dev_t *) priv; + + switch (dev->state) { + case DEV_STATE_MAIN_1: + /* Process the command if needed and then return to main loop #2. */ + if (dev->port->wantcmd) { + kbc_at_dev_log("%s: Processing keyboard command %02X...\n", dev->name, dev->port->dat); + kbc_at_dev_queue_reset(dev, 0); + dev->process_cmd(dev); + dev->port->wantcmd = 0; + } else + dev->state = DEV_STATE_MAIN_2; + break; + case DEV_STATE_MAIN_2: + /* Output from scan queue if needed and then return to main loop #1. */ + if (*dev->scan && (dev->port->out_new == -1) && (dev->queue_start != dev->queue_end)) { + kbc_at_dev_log("%s: %02X (DATA) on channel 1\n", dev->name, dev->queue[dev->queue_start]); + dev->port->out_new = dev->queue[dev->queue_start]; + dev->queue_start = (dev->queue_start + 1) & dev->fifo_mask; + } + if (!(*dev->scan) || dev->port->wantcmd) + dev->state = DEV_STATE_MAIN_1; + break; + case DEV_STATE_MAIN_OUT: + /* If host wants to send command while we're sending a byte to host, process the command. */ + if (dev->port->wantcmd) { + kbc_at_dev_log("%s: Processing keyboard command %02X...\n", dev->name, dev->port->dat); + kbc_at_dev_queue_reset(dev, 0); + dev->process_cmd(dev); + dev->port->wantcmd = 0; + break; + } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case DEV_STATE_MAIN_WANT_IN: + /* Output command response and then return to main loop #2. */ + if ((dev->port->out_new == -1) && (dev->cmd_queue_start != dev->cmd_queue_end)) { + kbc_at_dev_log("%s: %02X (CMD ) on channel 1\n", dev->name, dev->cmd_queue[dev->cmd_queue_start]); + dev->port->out_new = dev->cmd_queue[dev->cmd_queue_start]; + dev->cmd_queue_start = (dev->cmd_queue_start + 1) & 0xf; + } + if (dev->cmd_queue_start == dev->cmd_queue_end) + dev->state++; + break; + case DEV_STATE_MAIN_IN: + /* Wait for host data. */ + if (dev->port->wantcmd) { + kbc_at_dev_log("%s: Processing keyboard command %02X parameter %02X...\n", dev->name, dev->command, dev->port->dat); + kbc_at_dev_queue_reset(dev, 0); + dev->process_cmd(dev); + dev->port->wantcmd = 0; + } + break; + case DEV_STATE_EXECUTE_BAT: + dev->state = DEV_STATE_MAIN_OUT; + dev->execute_bat(dev); + break; + case DEV_STATE_MAIN_WANT_EXECUTE_BAT: + /* Output command response and then return to main loop #2. */ + if ((dev->port->out_new == -1) && (dev->cmd_queue_start != dev->cmd_queue_end)) { + kbc_at_dev_log("%s: %02X (CMD ) on channel 1\n", dev->name, dev->cmd_queue[dev->cmd_queue_start]); + dev->port->out_new = dev->cmd_queue[dev->cmd_queue_start]; + dev->cmd_queue_start = (dev->cmd_queue_start + 1) & 0xf; + } + if (dev->cmd_queue_start == dev->cmd_queue_end) + dev->state = DEV_STATE_EXECUTE_BAT; + break; + default: + break; + } +} + +void +kbc_at_dev_reset(atkbc_dev_t *dev, int do_fa) +{ + dev->port->out_new = -1; + dev->port->wantcmd = 0; + + kbc_at_dev_queue_reset(dev, 1); + + dev->last_scan_code = 0x00; + + *dev->scan = 1; + + if (do_fa) { + kbc_at_dev_queue_add(dev, 0xfa, 0); + dev->state = DEV_STATE_MAIN_WANT_EXECUTE_BAT; + } else + dev->state = DEV_STATE_EXECUTE_BAT; +} + +atkbc_dev_t * +kbc_at_dev_init(uint8_t inst) +{ + atkbc_dev_t *dev; + + dev = (atkbc_dev_t *) malloc(sizeof(atkbc_dev_t)); + memset(dev, 0x00, sizeof(atkbc_dev_t)); + + dev->port = kbc_at_ports[inst]; + + if (dev->port != NULL) { + dev->port->priv = dev; + dev->port->poll = kbc_at_dev_poll; + } + + /* Return our private data to the I/O layer. */ + return dev; +} diff --git a/src/device/keyboard.c b/src/device/keyboard.c index 74bf3f67e..e788ff23f 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -66,6 +66,7 @@ static uint8_t fake_shift_needed(uint16_t scan) { switch (scan) { + case 0x137: /* Yes, Print Screen requires the fake shifts. */ case 0x147: case 0x148: case 0x149: @@ -86,17 +87,21 @@ fake_shift_needed(uint16_t scan) void key_process(uint16_t scan, int down) { - scancode *codes = scan_table; - int c; + const scancode *codes = scan_table; + int c; + + if (!codes) + return; if (!keyboard_scan || (keyboard_send == NULL)) return; oldkey[scan] = down; - if (down && codes[scan].mk[0] == 0) + + if (down && (codes[scan].mk[0] == 0)) return; - if (!down && codes[scan].brk[0] == 0) + if (!down && (codes[scan].brk[0] == 0)) return; /* TODO: The keyboard controller needs to report the AT flag to us here. */ @@ -125,9 +130,13 @@ key_process(uint16_t scan, int down) void keyboard_input(int down, uint16_t scan) { + /* Special case for E1 1D, translate it to 0100 - special case. */ + if ((scan >> 8) == 0xe1) { + if ((scan & 0xff) == 0x1d) + scan = 0x0100; /* Translate E0 xx scan codes to 01xx because we use 512-byte arrays for states and scan code sets. */ - if ((scan >> 8) == 0xe0) { + } else if ((scan >> 8) == 0xe0) { scan &= 0x00ff; scan |= 0x0100; /* extended key code */ } else if ((scan >> 8) != 0x01) @@ -158,6 +167,9 @@ keyboard_input(int down, uint16_t scan) case 0x138: /* Right Alt */ shift |= 0x40; break; + + default: + break; } } else { switch (scan & 0x1ff) { @@ -188,13 +200,18 @@ keyboard_input(int down, uint16_t scan) case 0x046: scroll_lock ^= 1; break; + + default: + break; } } } /* NOTE: Shouldn't this be some sort of bit shift? An array of 8 unsigned 64-bit integers should be enough. */ - /* recv_key[scan >> 6] |= ((uint64_t) down << ((uint64_t) scan & 0x3fLL)); */ +#if 0 + recv_key[scan >> 6] |= ((uint64_t) down << ((uint64_t) scan & 0x3fLL)); +#endif /* pclog("Received scan code: %03X (%s)\n", scan & 0x1ff, down ? "down" : "up"); */ recv_key[scan & 0x1ff] = down; @@ -205,7 +222,7 @@ keyboard_input(int down, uint16_t scan) static uint8_t keyboard_do_break(uint16_t scan) { - scancode *codes = scan_table; + const scancode *codes = scan_table; /* TODO: The keyboard controller needs to report the AT flag to us here. */ if (is286 && ((keyboard_mode & 3) == 3)) { @@ -249,7 +266,7 @@ keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl) void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl) { - scancode *codes = scan_table; + const scancode *codes = scan_table; int i; @@ -295,11 +312,30 @@ keyboard_recv(uint16_t key) return recv_key[key]; } +/* Do we have Control-Alt-PgDn in the keyboard buffer? */ +int +keyboard_isfsenter(void) +{ + return ((recv_key[0x01d] || recv_key[0x11d]) && (recv_key[0x038] || recv_key[0x138]) && (recv_key[0x049] || recv_key[0x149])); +} + +int +keyboard_isfsenter_up(void) +{ + return (!recv_key[0x01d] && !recv_key[0x11d] && !recv_key[0x038] && !recv_key[0x138] && !recv_key[0x049] && !recv_key[0x149]); +} + /* Do we have Control-Alt-PgDn in the keyboard buffer? */ int keyboard_isfsexit(void) { - return ((recv_key[0x01D] || recv_key[0x11D]) && (recv_key[0x038] || recv_key[0x138]) && (recv_key[0x051] || recv_key[0x151])); + return ((recv_key[0x01d] || recv_key[0x11d]) && (recv_key[0x038] || recv_key[0x138]) && (recv_key[0x051] || recv_key[0x151])); +} + +int +keyboard_isfsexit_up(void) +{ + return (!recv_key[0x01d] && !recv_key[0x11d] && !recv_key[0x038] && !recv_key[0x138] && !recv_key[0x051] && !recv_key[0x151]); } /* Do we have F8-F12 in the keyboard buffer? */ diff --git a/src/device/keyboard_at.c b/src/device/keyboard_at.c index c71213aa6..3b167d66f 100644 --- a/src/device/keyboard_at.c +++ b/src/device/keyboard_at.c @@ -6,170 +6,73 @@ * * This file is part of the 86Box distribution. * - * Intel 8042 (AT keyboard controller) emulation. + * Implementation of PS/2 series Mouse devices. * * * - * Authors: Sarah Walker, - * Miran Grca, - * Fred N. van Kempen, - * EngiNerd, - * - * Copyright 2008-2020 Sarah Walker. - * Copyright 2016-2020 Miran Grca. - * Copyright 2017-2020 Fred N. van Kempen. - * Copyright 2020 EngiNerd. + * Authors: Fred N. van Kempen, */ +#include #include #include -#include #include -#include -#define HAVE_STDARG_H +#include #include +#define HAVE_STDARG_H #include <86box/86box.h> -#include "cpu.h" -#include <86box/timer.h> -#include <86box/io.h> -#include <86box/pic.h> -#include <86box/pit.h> -#include <86box/ppi.h> -#include <86box/mem.h> #include <86box/device.h> -#include <86box/machine.h> -#include <86box/m_xt_xi8088.h> -#include <86box/m_at_t3100e.h> -#include <86box/fdd.h> -#include <86box/fdc.h> -#include <86box/sound.h> -#include <86box/snd_speaker.h> -#include <86box/video.h> #include <86box/keyboard.h> +#include <86box/mouse.h> -#define STAT_PARITY 0x80 -#define STAT_RTIMEOUT 0x40 -#define STAT_TTIMEOUT 0x20 -#define STAT_MFULL 0x20 -#define STAT_UNLOCKED 0x10 -#define STAT_CD 0x08 -#define STAT_SYSFLAG 0x04 -#define STAT_IFULL 0x02 -#define STAT_OFULL 0x01 +#define FLAG_PS2 0x08 /* dev is AT or PS/2 */ +#define FLAG_AT 0x00 /* dev is AT or PS/2 */ +#define FLAG_TYPE_MASK 0x07 /* mask for type */ -#define RESET_DELAY_TIME (100 * 10) /* 600ms */ +#define FIFO_SIZE 16 -#define CCB_UNUSED 0x80 -#define CCB_TRANSLATE 0x40 -#define CCB_PCMODE 0x20 -#define CCB_ENABLEKBD 0x10 -#define CCB_IGNORELOCK 0x08 -#define CCB_SYSTEM 0x04 -#define CCB_ENABLEMINT 0x02 -#define CCB_ENABLEKINT 0x01 +enum { + KBD_84_KEY = 0, + KBD_101_KEY, + KBD_102_KEY, + KBD_JIS, + KBD_KOREAN +}; -#define CCB_MASK 0x68 -#define MODE_MASK 0x6c +#define FLAG_ENABLED 0x10 /* dev is enabled for use */ +#define FLAG_CTRLDAT 0x08 /* ctrl or data mode */ -#define KBC_TYPE_ISA 0x00 /* AT ISA-based chips */ -#define KBC_TYPE_PS2_NOREF 0x01 /* PS2 type, no refresh */ -#define KBC_TYPE_PS2_1 0x02 /* PS2 on PS/2, type 1 */ -#define KBC_TYPE_PS2_2 0x03 /* PS2 on PS/2, type 2 */ -#define KBC_TYPE_MASK 0x03 +const uint8_t id_bytes[16][4] = { { 0x00, 0x00, 0x00, 0x00 }, /* AT 84-key */ + { 0x00, 0x00, 0x00, 0x00 }, /* AT 101/102/106-key */ + { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 }, /* AT Korean */ + { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 }, + { 0xab, 0x83, 0x00, 0x00 }, /* PS/2 101-key */ + { 0xab, 0x83, 0x00, 0x00 }, /* PS/2 102-key */ + { 0xab, 0x90, 0x00, 0x00 }, /* PS/2 106-key JIS */ + /* Japanese keyboard ID - TODO: Find the actual Korean one. */ + { 0xab, 0x90, 0x00, 0x00 }, /* PS/2 Korean */ + { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 } }; -#define KBC_VEN_GENERIC 0x00 -#define KBC_VEN_AMI 0x04 -#define KBC_VEN_IBM_MCA 0x08 -#define KBC_VEN_QUADTEL 0x0c -#define KBC_VEN_TOSHIBA 0x10 -#define KBC_VEN_XI8088 0x14 -#define KBC_VEN_IBM_PS1 0x18 -#define KBC_VEN_ACER 0x1c -#define KBC_VEN_INTEL_AMI 0x20 -#define KBC_VEN_OLIVETTI 0x24 -#define KBC_VEN_NCR 0x28 -#define KBC_VEN_SAMSUNG 0x2c -#define KBC_VEN_ALI 0x30 -#define KBC_VEN_MASK 0x3c - -typedef struct { - uint8_t command, status, old_status, out, old_out, secr_phase, - mem_addr, input_port, output_port, old_output_port, - key_command, output_locked, ami_stat, want60, - wantirq, key_wantdata, ami_flags, first_write; - - uint8_t mem[0x100]; - - int last_irq, old_last_irq, - reset_delay, - out_new, out_delayed; - - uint32_t flags; - - pc_timer_t pulse_cb; - - uint8_t (*write60_ven)(void *p, uint8_t val); - uint8_t (*write64_ven)(void *p, uint8_t val); - - pc_timer_t send_delay_timer; -} atkbd_t; - -/* bit 0 = repeat, bit 1 = makes break code? */ +/* Global keyboard flags for scan code set 3: + bit 0 = repeat, bit 1 = makes break code? */ uint8_t keyboard_set3_flags[512]; uint8_t keyboard_set3_all_repeat; uint8_t keyboard_set3_all_break; -/* Bits 0 - 1 = scan code set, bit 6 = translate or not. */ -uint8_t keyboard_mode = 0x42; +/* Global keyboard mode: + Bits 0 - 1 = scan code set. */ +uint8_t keyboard_mode = 0x02; -static uint8_t key_ctrl_queue[16]; -static int key_ctrl_queue_start = 0, key_ctrl_queue_end = 0; -static uint8_t key_queue[16]; -static int key_queue_start = 0, key_queue_end = 0; -uint8_t mouse_queue[16]; -int mouse_queue_start = 0, mouse_queue_end = 0; -static uint8_t kbd_last_scan_code; -static void (*mouse_write)(uint8_t val, void *priv) = NULL; -static void *mouse_p = NULL; -static uint8_t sc_or = 0; -static atkbd_t *SavedKbd = NULL; // FIXME: remove!!! --FvK +static atkbc_dev_t *SavedKbd = NULL; -/* Non-translated to translated scan codes. */ -static const uint8_t nont_to_t[256] = { - 0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58, - 0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59, - 0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a, - 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b, - 0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c, - 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d, - 0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e, - 0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f, - 0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60, - 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61, - 0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e, - 0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76, - 0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b, - 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f, - 0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45, - 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54, - 0x80, 0x81, 0x82, 0x41, 0x54, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff -}; +static uint8_t inv_cmd_response = 0xfa; -#ifdef USE_SET1 static const scancode scancode_set1[512] = { // clang-format off { { 0},{ 0} }, { { 0x01,0},{ 0x81,0} }, { { 0x02,0},{ 0x82,0} }, { { 0x03,0},{ 0x83,0} }, /*000*/ @@ -301,7 +204,6 @@ static const scancode scancode_set1[512] = { { { 0},{ 0} }, { { 0},{ 0} }, { {0xe0,0xfe,0},{ 0} }, { {0xe0,0xff,0},{ 0} } /*1fc*/ // clang-format on }; -#endif static const scancode scancode_set2[512] = { // clang-format off @@ -567,13 +469,11 @@ static const scancode scancode_set3[512] = { // clang-format on }; -static void add_data_kbd(uint16_t val); - #ifdef ENABLE_KEYBOARD_AT_LOG int keyboard_at_do_log = ENABLE_KEYBOARD_AT_LOG; static void -kbd_log(const char *fmt, ...) +keyboard_at_log(const char *fmt, ...) { va_list ap; @@ -584,344 +484,52 @@ kbd_log(const char *fmt, ...) } } #else -# define kbd_log(fmt, ...) +# define keyboard_at_log(fmt, ...) #endif static void -set_scancode_map(atkbd_t *dev) +keyboard_at_set_scancode_set(void) { - switch (keyboard_mode & 3) { -#ifdef USE_SET1 - case 1: + switch (keyboard_mode) { default: + case 0x01: keyboard_set_table(scancode_set1); break; -#else - default: -#endif - case 2: + + case 0x02: keyboard_set_table(scancode_set2); break; - case 3: + case 0x03: keyboard_set_table(scancode_set3); break; } - - if (keyboard_mode & 0x20) -#ifdef USE_SET1 - keyboard_set_table(scancode_set1); -#else - keyboard_set_table(scancode_set2); -#endif } static void -kbc_queue_reset(uint8_t channel) +add_data_vals(atkbc_dev_t *dev, uint8_t *val, uint8_t len) { - if (channel == 2) { - mouse_queue_start = mouse_queue_end = 0; - memset(mouse_queue, 0x00, sizeof(mouse_queue)); - } else if (channel == 1) { - key_queue_start = key_queue_end = 0; - memset(key_queue, 0x00, sizeof(key_queue)); - } else { - key_ctrl_queue_start = key_ctrl_queue_end = 0; - memset(key_ctrl_queue, 0x00, sizeof(key_ctrl_queue)); - } -} - -static void -kbc_queue_add(atkbd_t *dev, uint8_t val, uint8_t channel, uint8_t stat_hi) -{ - uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; - - if ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) - stat_hi |= ((dev->input_port & 0x80) ? 0x10 : 0x00); - else - stat_hi |= 0x10; - - dev->status = (dev->status & 0x0f) | stat_hi; - - if (channel == 2) { - kbd_log("ATkbc: mouse_queue[%02X] = %02X;\n", mouse_queue_end, val); - mouse_queue[mouse_queue_end] = val; - mouse_queue_end = (mouse_queue_end + 1) & 0xf; - } else if (channel == 1) { - kbd_log("ATkbc: key_queue[%02X] = %02X;\n", key_queue_end, val); - key_queue[key_queue_end] = val; - key_queue_end = (key_queue_end + 1) & 0xf; - } else { - kbd_log("ATkbc: key_ctrl_queue[%02X] = %02X;\n", key_ctrl_queue_end, val); - key_ctrl_queue[key_ctrl_queue_end] = val; - key_ctrl_queue_end = (key_ctrl_queue_end + 1) & 0xf; - } -} - -static void -add_to_kbc_queue_front(atkbd_t *dev, uint8_t val, uint8_t channel, uint8_t stat_hi) -{ - uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; - - if ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) - stat_hi |= ((dev->input_port & 0x80) ? 0x10 : 0x00); - else - stat_hi |= 0x10; - - kbd_log("ATkbc: Adding %02X to front...\n", val); - dev->wantirq = 0; - if (channel == 2) { - if (dev->mem[0] & 0x02) - picint(0x1000); - if (kbc_ven != KBC_VEN_OLIVETTI) - dev->last_irq = 0x1000; - } else { - if (dev->mem[0] & 0x01) - picint(2); - if (kbc_ven != KBC_VEN_OLIVETTI) - dev->last_irq = 2; - } - dev->out = val; - if (channel == 2) - dev->status = (dev->status & ~STAT_IFULL) | (STAT_OFULL | STAT_MFULL) | stat_hi; - else - dev->status = (dev->status & ~(STAT_IFULL | STAT_MFULL)) | STAT_OFULL | stat_hi; - if (kbc_ven == KBC_VEN_OLIVETTI) - dev->last_irq = 0x0000; -} - -static void -add_data_kbd_queue(atkbd_t *dev, int direct, uint8_t val) -{ - if ((!keyboard_scan && !direct) || (dev->reset_delay > 0) || (key_queue_end >= 16)) { - kbd_log("ATkbc: Unable to add to queue, conditions: %i, %i, %i\n", !keyboard_scan, (dev->reset_delay > 0), (key_queue_end >= 16)); - return; - } - kbd_log("ATkbc: key_queue[%02X] = %02X;\n", key_queue_end, val); - kbc_queue_add(dev, val, 1, 0x00); - kbd_last_scan_code = val; -} - -static void -add_data_kbd_direct(atkbd_t *dev, uint8_t val) -{ - int xt_mode = (keyboard_mode & 0x20) && ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF); - int translate = (keyboard_mode & 0x40); - uint8_t send; - - if (dev->reset_delay) - return; - - translate = translate || (keyboard_mode & 0x40) || xt_mode; - translate = translate || ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2); - - if (translate) - send = nont_to_t[val]; - else - send = val; - - add_data_kbd_queue(dev, 1, send); -} - -static void -add_data_kbd_raw(atkbd_t *dev, uint8_t val) -{ - add_data_kbd_queue(dev, 1, val); -} - -static void -kbd_poll(void *priv) -{ - atkbd_t *dev = (atkbd_t *) priv; -#ifdef ENABLE_KEYBOARD_AT_LOG - const uint8_t channels[4] = { 1, 2, 0, 0 }; -#endif - - timer_advance_u64(&dev->send_delay_timer, (100ULL * TIMER_USEC)); - - if (dev->out_new != -1 && !dev->last_irq) { - dev->wantirq = 0; - if (dev->out_new & 0x100) { - if (dev->mem[0] & 0x02) - picint(0x1000); - kbd_log("ATkbc: %02X coming from channel 2\n"); - dev->out = dev->out_new & 0xff; - dev->out_new = -1; - dev->status = (dev->status & ~STAT_IFULL) | (STAT_OFULL | STAT_MFULL); - dev->last_irq = 0x1000; - } else { - if (dev->mem[0] & 0x01) - picint(2); - kbd_log("ATkbc: %02X coming from channel %i\n", dev->out_new & 0xff, channels[(dev->out_new >> 8) & 0x03]); - dev->out = dev->out_new & 0xff; - dev->out_new = -1; - dev->status = (dev->status & ~(STAT_IFULL | STAT_MFULL)) | STAT_OFULL; - dev->last_irq = 2; - } - } - - if (dev->out_new == -1 && !(dev->status & STAT_OFULL) && key_ctrl_queue_start != key_ctrl_queue_end) { - kbd_log("ATkbc: %02X on channel 0\n", key_ctrl_queue[key_ctrl_queue_start]); - dev->out_new = key_ctrl_queue[key_ctrl_queue_start] | 0x200; - key_ctrl_queue_start = (key_ctrl_queue_start + 1) & 0xf; - } else if (!(dev->status & STAT_OFULL) && dev->out_new == -1 && dev->out_delayed != -1) { - kbd_log("ATkbc: %02X delayed on channel %i\n", dev->out_delayed & 0xff, channels[(dev->out_delayed >> 8) & 0x03]); - dev->out_new = dev->out_delayed; - dev->out_delayed = -1; - } else if (!(dev->status & STAT_OFULL) && dev->out_new == -1 && mouse_queue_start != mouse_queue_end) { - kbd_log("ATkbc: %02X on channel 2\n", mouse_queue[mouse_queue_start]); - dev->out_new = mouse_queue[mouse_queue_start] | 0x100; - mouse_queue_start = (mouse_queue_start + 1) & 0xf; - } else if (!(dev->status & STAT_OFULL) && dev->out_new == -1 && !(dev->mem[0] & 0x10) && key_queue_start != key_queue_end) { - kbd_log("ATkbc: %02X on channel 1\n", key_queue[key_queue_start]); - dev->out_new = key_queue[key_queue_start]; - key_queue_start = (key_queue_start + 1) & 0xf; - } - - if (dev->reset_delay) { - dev->reset_delay--; - if (!dev->reset_delay) { - kbd_log("ATkbc: Sending AA on keyboard reset...\n"); - add_data_kbd_direct(dev, 0xaa); - } - } -} - -static void -add_data(atkbd_t *dev, uint8_t val) -{ - kbd_log("ATkbc: add to queue\n"); - - kbd_log("ATkbc: key_ctrl_queue[%02X] = %02X;\n", key_ctrl_queue_end, val); - kbc_queue_add(dev, val, 0, 0x00); - - if (!(dev->out_new & 0x300)) { - dev->out_delayed = dev->out_new; - dev->out_new = -1; - } -} - -static void -add_data_vals(atkbd_t *dev, uint8_t *val, uint8_t len) -{ - int xt_mode = (keyboard_mode & 0x20) && ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF); - int translate = (keyboard_mode & 0x40); - int i; - uint8_t or = 0; - uint8_t send; - - if (dev->reset_delay) - return; - - translate = translate || (keyboard_mode & 0x40) || xt_mode; - translate = translate || ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2); - - for (i = 0; i < len; i++) { - if (translate) { - if (val[i] == 0xf0) { - or = 0x80; - continue; - } - send = nont_to_t[val[i]] | or ; - if (or == 0x80) - or = 0; - } else - send = val[i]; - - add_data_kbd_queue(dev, 0, send); - } + for (uint8_t i = 0; i < len; i++) + kbc_at_dev_queue_add(dev, val[i], 1); } static void add_data_kbd(uint16_t val) { - atkbd_t *dev = SavedKbd; - int xt_mode = (keyboard_mode & 0x20) && ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF); - int translate = (keyboard_mode & 0x40); + atkbc_dev_t *dev = SavedKbd; uint8_t fake_shift[4]; - uint8_t num_lock = 0, shift_states = 0; - uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; - - if (dev->reset_delay) - return; - - translate = translate || (keyboard_mode & 0x40) || xt_mode; - translate = translate || ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2); + uint8_t num_lock = 0; + uint8_t shift_states = 0; keyboard_get_states(NULL, &num_lock, NULL); shift_states = keyboard_get_shift() & STATE_SHIFT_MASK; - /* Allow for scan code translation. */ - if (translate && (val == 0xf0)) { - kbd_log("ATkbd: translate is on, F0 prefix detected\n"); - sc_or = 0x80; - return; - } - - /* Skip break code if translated make code has bit 7 set. */ - if (translate && (sc_or == 0x80) && (val & 0x80)) { - kbd_log("ATkbd: translate is on, skipping scan code: %02X (original: F0 %02X)\n", nont_to_t[val], val); - sc_or = 0; - return; - } - - /* Test for T3100E 'Fn' key (Right Alt / Right Ctrl) */ - if ((dev != NULL) && (kbc_ven == KBC_VEN_TOSHIBA) && (keyboard_recv(0x138) || keyboard_recv(0x11d))) - switch (val) { - case 0x4f: - t3100e_notify_set(0x01); - break; /* End */ - case 0x50: - t3100e_notify_set(0x02); - break; /* Down */ - case 0x51: - t3100e_notify_set(0x03); - break; /* PgDn */ - case 0x52: - t3100e_notify_set(0x04); - break; /* Ins */ - case 0x53: - t3100e_notify_set(0x05); - break; /* Del */ - case 0x54: - t3100e_notify_set(0x06); - break; /* SysRQ */ - case 0x45: - t3100e_notify_set(0x07); - break; /* NumLock */ - case 0x46: - t3100e_notify_set(0x08); - break; /* ScrLock */ - case 0x47: - t3100e_notify_set(0x09); - break; /* Home */ - case 0x48: - t3100e_notify_set(0x0a); - break; /* Up */ - case 0x49: - t3100e_notify_set(0x0b); - break; /* PgUp */ - case 0x4A: - t3100e_notify_set(0x0c); - break; /* Keypad -*/ - case 0x4B: - t3100e_notify_set(0x0d); - break; /* Left */ - case 0x4C: - t3100e_notify_set(0x0e); - break; /* KP 5 */ - case 0x4D: - t3100e_notify_set(0x0f); - break; /* Right */ - } - - kbd_log("ATkbd: translate is %s, ", translate ? "on" : "off"); switch (val) { case FAKE_LSHIFT_ON: - kbd_log("fake left shift on, scan code: "); + keyboard_at_log("%s: Fake left shift on, scan code: ", dev->name); if (num_lock) { if (shift_states) { - kbd_log("N/A (one or both shifts on)\n"); + keyboard_at_log("N/A (one or both shifts on)\n"); break; } else { /* Num lock on and no shifts are pressed, send non-inverted fake shift. */ @@ -939,7 +547,7 @@ add_data_kbd(uint16_t val) break; default: - kbd_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); + keyboard_at_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); break; } } @@ -961,7 +569,7 @@ add_data_kbd(uint16_t val) break; default: - kbd_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); + keyboard_at_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); break; } } @@ -982,19 +590,19 @@ add_data_kbd(uint16_t val) break; default: - kbd_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); + keyboard_at_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); break; } } - kbd_log(shift_states ? "" : "N/A (both shifts off)\n"); + keyboard_at_log(shift_states ? "" : "N/A (both shifts off)\n"); } break; case FAKE_LSHIFT_OFF: - kbd_log("fake left shift on, scan code: "); + keyboard_at_log("%s: Fake left shift on, scan code: ", dev->name); if (num_lock) { if (shift_states) { - kbd_log("N/A (one or both shifts on)\n"); + keyboard_at_log("N/A (one or both shifts on)\n"); break; } else { /* Num lock on and no shifts are pressed, send non-inverted fake shift. */ @@ -1013,7 +621,7 @@ add_data_kbd(uint16_t val) break; default: - kbd_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); + keyboard_at_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); break; } } @@ -1034,7 +642,7 @@ add_data_kbd(uint16_t val) break; default: - kbd_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); + keyboard_at_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); break; } } @@ -1054,1422 +662,323 @@ add_data_kbd(uint16_t val) break; default: - kbd_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); + keyboard_at_log("N/A (scan code set %i)\n", keyboard_mode & 0x02); break; } } - kbd_log(shift_states ? "" : "N/A (both shifts off)\n"); + keyboard_at_log(shift_states ? "" : "N/A (both shifts off)\n"); } break; default: -#ifdef ENABLE_KEYBOARD_AT_LOG - kbd_log("scan code: "); - if (translate) { - kbd_log("%02X (original: ", (nont_to_t[val] | sc_or)); - if (sc_or == 0x80) - kbd_log("F0 "); - kbd_log("%02X)\n", val); - } else - kbd_log("%02X\n", val); -#endif - - add_data_kbd_queue(dev, 0, translate ? (nont_to_t[val] | sc_or) : val); + kbc_at_dev_queue_add(dev, val, 1); break; } +} - if (sc_or == 0x80) - sc_or = 0; +void +keyboard_at_clear_data(void *priv) +{ + atkbc_dev_t *dev = (atkbc_dev_t *) priv; + + dev->flags &= ~FLAG_CTRLDAT; } static void -write_output(atkbd_t *dev, uint8_t val) +keyboard_at_set_defaults(atkbc_dev_t *dev) { - uint8_t old = dev->output_port; - kbd_log("ATkbc: write output port: %02X (old: %02X)\n", val, dev->output_port); - - uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; - if ((kbc_ven != KBC_VEN_OLIVETTI) && ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF))) - val |= ((dev->mem[0] << 4) & 0x10); - - /*IRQ 12*/ - if ((old ^ val) & 0x20) { - if (val & 0x20) - picint(1 << 12); - else - picintc(1 << 12); - } - - /*IRQ 1*/ - if ((old ^ val) & 0x10) { - if (val & 0x10) - picint(1 << 1); - else - picintc(1 << 1); - } - - if ((old ^ val) & 0x02) { /*A20 enable change*/ - mem_a20_key = val & 0x02; - mem_a20_recalc(); - flushmmucache(); - } - - /* 0 holds the CPU in the RESET state, 1 releases it. To simplify this, - we just do everything on release. */ - if ((old ^ val) & 0x01) { /*Reset*/ - if (!(val & 0x01)) { /* Pin 0 selected. */ - /* Pin 0 selected. */ - kbd_log("write_output(): Pulse reset!\n"); - if (machines[machine].flags & MACHINE_COREBOOT) { - /* The SeaBIOS hard reset code attempts a KBC reset if ACPI RESET_REG - is not available. However, the KBC reset is normally a soft reset, so - SeaBIOS gets caught in a soft reset loop as it tries to hard reset the - machine. Hack around this by making the KBC reset a hard reset only on - coreboot machines. */ - pc_reset_hard(); - } else { - softresetx86(); /*Pulse reset!*/ - cpu_set_edx(); - flushmmucache(); - if (kbc_ven == KBC_VEN_ALI) - smbase = 0x00030000; - } - } - } - - /* Do this here to avoid an infinite reset loop. */ - dev->output_port = val; -} - -static void -write_cmd(atkbd_t *dev, uint8_t val) -{ - uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; - kbd_log("ATkbc: write command byte: %02X (old: %02X)\n", val, dev->mem[0]); - - if ((val & 1) && (dev->status & STAT_OFULL)) - dev->wantirq = 1; - if (!(val & 1) && dev->wantirq) - dev->wantirq = 0; - - /* PS/2 type 2 keyboard controllers always force the XLAT bit to 0. */ - if ((dev->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2) { - val &= ~CCB_TRANSLATE; - dev->mem[0] &= ~CCB_TRANSLATE; - } - - /* Scan code translate ON/OFF. */ - keyboard_mode &= 0x93; - keyboard_mode |= (val & MODE_MASK); - - kbd_log("ATkbc: keyboard interrupt is now %s\n", (val & 0x01) ? "enabled" : "disabled"); - - /* ISA AT keyboard controllers use bit 5 for keyboard mode (1 = PC/XT, 2 = AT); - PS/2 (and EISA/PCI) keyboard controllers use it as the PS/2 mouse enable switch. - The AMIKEY firmware apparently uses this bit for something else. */ - if ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) { - keyboard_mode &= ~CCB_PCMODE; - - kbd_log("ATkbc: mouse interrupt is now %s\n", (val & 0x02) ? "enabled" : "disabled"); - } - - if ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF)) { - /* Update the output port to mirror the KBD DIS and AUX DIS bits, if active. */ - write_output(dev, dev->output_port); - } - - kbd_log("Command byte now: %02X (%02X)\n", dev->mem[0], val); - - dev->status = (dev->status & ~STAT_SYSFLAG) | (val & STAT_SYSFLAG); -} - -static void -pulse_output(atkbd_t *dev, uint8_t mask) -{ - if (mask != 0x0f) { - dev->old_output_port = dev->output_port & ~(0xf0 | mask); - kbd_log("pulse_output(): Output port now: %02X\n", dev->output_port & (0xf0 | mask)); - write_output(dev, dev->output_port & (0xf0 | mask)); - timer_set_delay_u64(&dev->pulse_cb, 6ULL * TIMER_USEC); - } -} - -static void -pulse_poll(void *priv) -{ - atkbd_t *dev = (atkbd_t *) priv; - - kbd_log("pulse_poll(): Output port now: %02X\n", dev->output_port | dev->old_output_port); - write_output(dev, dev->output_port | dev->old_output_port); -} - -static void -set_enable_kbd(atkbd_t *dev, uint8_t enable) -{ - dev->mem[0] &= 0xef; - dev->mem[0] |= (enable ? 0x00 : 0x10); -} - -static void -set_enable_mouse(atkbd_t *dev, uint8_t enable) -{ - dev->mem[0] &= 0xdf; - dev->mem[0] |= (enable ? 0x00 : 0x20); -} - -static uint8_t -write64_generic(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - uint8_t current_drive, fixed_bits; - uint8_t kbc_ven = 0x0; - kbc_ven = dev->flags & KBC_VEN_MASK; - - switch (val) { - case 0xa4: /* check if password installed */ - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: check if password installed\n"); - add_data(dev, 0xf1); - return 0; - } - break; - - case 0xa7: /* disable mouse port */ - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: disable mouse port\n"); - set_enable_mouse(dev, 0); - return 0; - } - break; - - case 0xa8: /*Enable mouse port*/ - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: enable mouse port\n"); - set_enable_mouse(dev, 1); - return 0; - } - break; - - case 0xa9: /*Test mouse port*/ - kbd_log("ATkbc: test mouse port\n"); - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) { - add_data(dev, 0x00); /* no error, this is testing the channel 2 interface */ - return 0; - } - break; - - case 0xaf: /* read keyboard version */ - kbd_log("ATkbc: read keyboard version\n"); - add_data(dev, 0x00); - return 0; - - case 0xc0: /* read input port */ - kbd_log("ATkbc: read input port\n"); - fixed_bits = 4; - /* The SMM handlers of Intel AMI Pentium BIOS'es expect bit 6 to be set. */ - if (kbc_ven == KBC_VEN_INTEL_AMI) - fixed_bits |= 0x40; - if (kbc_ven == KBC_VEN_IBM_PS1) { - current_drive = fdc_get_current_drive(); - add_to_kbc_queue_front(dev, dev->input_port | fixed_bits | (fdd_is_525(current_drive) ? 0x40 : 0x00), - 0, 0x00); - dev->input_port = ((dev->input_port + 1) & 3) | (dev->input_port & 0xfc) | (fdd_is_525(current_drive) ? 0x40 : 0x00); - } else if (kbc_ven == KBC_VEN_NCR) { - /* switch settings - * bit 7: keyboard disable - * bit 6: display type (0 color, 1 mono) - * bit 5: power-on default speed (0 high, 1 low) - * bit 4: sense RAM size (0 unsupported, 1 512k on system board) - * bit 3: coprocessor detect - * bit 2: unused - * bit 1: high/auto speed - * bit 0: dma mode - */ - add_to_kbc_queue_front(dev, (dev->input_port | fixed_bits | (video_is_mda() ? 0x40 : 0x00) | (hasfpu ? 0x08 : 0x00)) & 0xdf, - 0, 0x00); - dev->input_port = ((dev->input_port + 1) & 3) | (dev->input_port & 0xfc); - } else { - if (((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) && ((dev->flags & KBC_VEN_MASK) != KBC_VEN_INTEL_AMI)) -#if 0 - add_to_kbc_queue_front(dev, (dev->input_port | fixed_bits) & - (((dev->flags & KBC_VEN_MASK) == KBC_VEN_ACER) ? 0xeb : 0xef), 0, 0x00); -#else - add_to_kbc_queue_front(dev, ((dev->input_port | fixed_bits) & 0xf0) | (((dev->flags & KBC_VEN_MASK) == KBC_VEN_ACER) ? 0x08 : 0x0c), 0, 0x00); -#endif - else add_to_kbc_queue_front(dev, dev->input_port | fixed_bits, 0, 0x00); - dev->input_port = ((dev->input_port + 1) & 3) | (dev->input_port & 0xfc); - } - return 0; - - case 0xd3: /* write mouse output buffer */ - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: write mouse output buffer\n"); - dev->want60 = 1; - return 0; - } - break; - - case 0xd4: /* write to mouse */ - kbd_log("ATkbc: write to mouse\n"); - dev->want60 = 1; - return 0; - - case 0xf0: - case 0xf1: - case 0xf2: - case 0xf3: - case 0xf4: - case 0xf5: - case 0xf6: - case 0xf7: - case 0xf8: - case 0xf9: - case 0xfa: - case 0xfb: - case 0xfc: - case 0xfd: - case 0xfe: - case 0xff: - kbd_log("ATkbc: pulse %01X\n", val & 0x0f); - pulse_output(dev, val & 0x0f); - return 0; - } - - kbd_log("ATkbc: bad command %02X\n", val); - return 1; -} - -static uint8_t -write60_ami(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - - switch (dev->command) { - /* 0x40 - 0x5F are aliases for 0x60-0x7F */ - case 0x40: - case 0x41: - case 0x42: - case 0x43: - case 0x44: - case 0x45: - case 0x46: - case 0x47: - case 0x48: - case 0x49: - case 0x4a: - case 0x4b: - case 0x4c: - case 0x4d: - case 0x4e: - case 0x4f: - case 0x50: - case 0x51: - case 0x52: - case 0x53: - case 0x54: - case 0x55: - case 0x56: - case 0x57: - case 0x58: - case 0x59: - case 0x5a: - case 0x5b: - case 0x5c: - case 0x5d: - case 0x5e: - case 0x5f: - kbd_log("ATkbc: AMI - alias write to %08X\n", dev->command); - dev->mem[dev->command & 0x1f] = val; - if (dev->command == 0x60) - write_cmd(dev, val); - return 0; - - case 0xaf: /* set extended controller RAM */ - kbd_log("ATkbc: AMI - set extended controller RAM\n"); - if (dev->secr_phase == 1) { - dev->mem_addr = val; - dev->want60 = 1; - dev->secr_phase = 2; - } else if (dev->secr_phase == 2) { - dev->mem[dev->mem_addr] = val; - dev->secr_phase = 0; - } - return 0; - - case 0xc1: - kbd_log("ATkbc: AMI MegaKey - write %02X to input port\n", val); - dev->input_port = val; - return 0; - - case 0xcb: /* set keyboard mode */ - kbd_log("ATkbc: AMI - set keyboard mode\n"); - dev->ami_flags = val; - return 0; - } - - return 1; -} - -static uint8_t -write64_ami(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; - - switch (val) { - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x08: - case 0x09: - case 0x0a: - case 0x0b: - case 0x0c: - case 0x0d: - case 0x0e: - case 0x0f: - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - case 0x16: - case 0x17: - case 0x18: - case 0x19: - case 0x1a: - case 0x1b: - case 0x1c: - case 0x1d: - case 0x1e: - case 0x1f: - kbd_log("ATkbc: AMI - alias read from %08X\n", val); - add_data(dev, dev->mem[val]); - return 0; - - case 0x40: - case 0x41: - case 0x42: - case 0x43: - case 0x44: - case 0x45: - case 0x46: - case 0x47: - case 0x48: - case 0x49: - case 0x4a: - case 0x4b: - case 0x4c: - case 0x4d: - case 0x4e: - case 0x4f: - case 0x50: - case 0x51: - case 0x52: - case 0x53: - case 0x54: - case 0x55: - case 0x56: - case 0x57: - case 0x58: - case 0x59: - case 0x5a: - case 0x5b: - case 0x5c: - case 0x5d: - case 0x5e: - case 0x5f: - kbd_log("ATkbc: AMI - alias write to %08X\n", dev->command); - dev->want60 = 1; - return 0; - - case 0xa0: /* copyright message */ - add_data(dev, 0x28); - add_data(dev, 0x00); - break; - - case 0xa1: /* get controller version */ - kbd_log("ATkbc: AMI - get controller version\n"); - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) { - if (kbc_ven == KBC_VEN_ALI) - add_data(dev, 'F'); - else if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_INTEL_AMI) - add_data(dev, '5'); - else - add_data(dev, 'H'); - } else - add_data(dev, 'F'); - return 0; - - case 0xa2: /* clear keyboard controller lines P22/P23 */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - clear KBC lines P22 and P23\n"); - write_output(dev, dev->output_port & 0xf3); - add_data(dev, 0x00); - return 0; - } - break; - - case 0xa3: /* set keyboard controller lines P22/P23 */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - set KBC lines P22 and P23\n"); - write_output(dev, dev->output_port | 0x0c); - add_data(dev, 0x00); - return 0; - } - break; - - case 0xa4: /* write clock = low */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - write clock = low\n"); - dev->ami_stat &= 0xfe; - return 0; - } - break; - - case 0xa5: /* write clock = high */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - write clock = high\n"); - dev->ami_stat |= 0x01; - return 0; - } - break; - - case 0xa6: /* read clock */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - read clock\n"); - add_to_kbc_queue_front(dev, (dev->ami_stat & 1) ? 0xff : 0x00, 0, 0x00); - return 0; - } - break; - - case 0xa7: /* write cache bad */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - write cache bad\n"); - dev->ami_stat &= 0xfd; - return 0; - } - break; - - case 0xa8: /* write cache good */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - write cache good\n"); - dev->ami_stat |= 0x02; - return 0; - } - break; - - case 0xa9: /* read cache */ - if ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) { - kbd_log("ATkbc: AMI - read cache\n"); - add_to_kbc_queue_front(dev, (dev->ami_stat & 2) ? 0xff : 0x00, 0, 0x00); - return 0; - } - break; - - case 0xaf: /* set extended controller RAM */ - if (kbc_ven == KBC_VEN_ALI) { - kbd_log("ATkbc: Award/ALi/VIA keyboard controller revision\n"); - add_to_kbc_queue_front(dev, 0x43, 0, 0x00); - } else { - kbd_log("ATkbc: set extended controller RAM\n"); - dev->want60 = 1; - dev->secr_phase = 1; - } - return 0; - - case 0xb0: - case 0xb1: - case 0xb2: - case 0xb3: - /* set KBC lines P10-P13 (input port bits 0-3) low */ - kbd_log("ATkbc: set KBC lines P10-P13 (input port bits 0-3) low\n"); - if (!(dev->flags & DEVICE_PCI) || (val > 0xb1)) - dev->input_port &= ~(1 << (val & 0x03)); - add_data(dev, 0x00); - return 0; - - case 0xb4: - case 0xb5: - /* set KBC lines P22-P23 (output port bits 2-3) low */ - kbd_log("ATkbc: set KBC lines P22-P23 (output port bits 2-3) low\n"); - if (!(dev->flags & DEVICE_PCI)) - write_output(dev, dev->output_port & ~(4 << (val & 0x01))); - add_data(dev, 0x00); - return 0; - - case 0xb8: - case 0xb9: - case 0xba: - case 0xbb: - /* set KBC lines P10-P13 (input port bits 0-3) high */ - kbd_log("ATkbc: set KBC lines P10-P13 (input port bits 0-3) high\n"); - if (!(dev->flags & DEVICE_PCI) || (val > 0xb9)) { - dev->input_port |= (1 << (val & 0x03)); - add_data(dev, 0x00); - } - return 0; - - case 0xbc: - case 0xbd: - /* set KBC lines P22-P23 (output port bits 2-3) high */ - kbd_log("ATkbc: set KBC lines P22-P23 (output port bits 2-3) high\n"); - if (!(dev->flags & DEVICE_PCI)) - write_output(dev, dev->output_port | (4 << (val & 0x01))); - add_data(dev, 0x00); - return 0; - - case 0xc1: /* write input port */ - kbd_log("ATkbc: AMI MegaKey - write input port\n"); - dev->want60 = 1; - return 0; - - case 0xc4: - /* set KBC line P14 low */ - kbd_log("ATkbc: set KBC line P14 (input port bit 4) low\n"); - dev->input_port &= 0xef; - add_data(dev, 0x00); - return 0; - case 0xc5: - /* set KBC line P15 low */ - kbd_log("ATkbc: set KBC line P15 (input port bit 5) low\n"); - dev->input_port &= 0xdf; - add_data(dev, 0x00); - return 0; - - case 0xc8: - /* - * unblock KBC lines P22/P23 - * (allow command D1 to change bits 2/3 of the output port) - */ - kbd_log("ATkbc: AMI - unblock KBC lines P22 and P23\n"); - dev->ami_flags &= 0xfb; - return 0; - - case 0xc9: - /* - * block KBC lines P22/P23 - * (disallow command D1 from changing bits 2/3 of the port) - */ - kbd_log("ATkbc: AMI - block KBC lines P22 and P23\n"); - dev->ami_flags |= 0x04; - return 0; - - case 0xcc: - /* set KBC line P14 high */ - kbd_log("ATkbc: set KBC line P14 (input port bit 4) high\n"); - dev->input_port |= 0x10; - add_data(dev, 0x00); - return 0; - case 0xcd: - /* set KBC line P15 high */ - kbd_log("ATkbc: set KBC line P15 (input port bit 5) high\n"); - dev->input_port |= 0x20; - add_data(dev, 0x00); - return 0; - - case 0xef: /* ??? - sent by AMI486 */ - kbd_log("ATkbc: ??? - sent by AMI486\n"); - return 0; - } - - return write64_generic(dev, val); -} - -static uint8_t -write64_ibm_mca(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - - switch (val) { - case 0xc1: /*Copy bits 0 to 3 of input port to status bits 4 to 7*/ - kbd_log("ATkbc: copy bits 0 to 3 of input port to status bits 4 to 7\n"); - dev->status &= 0x0f; - dev->status |= ((((dev->input_port & 0xfc) | 0x84) & 0x0f) << 4); - return 0; - - case 0xc2: /*Copy bits 4 to 7 of input port to status bits 4 to 7*/ - kbd_log("ATkbc: copy bits 4 to 7 of input port to status bits 4 to 7\n"); - dev->status &= 0x0f; - dev->status |= (((dev->input_port & 0xfc) | 0x84) & 0xf0); - return 0; - - case 0xaf: - kbd_log("ATkbc: bad KBC command AF\n"); - return 1; - - case 0xf0: - case 0xf1: - case 0xf2: - case 0xf3: - case 0xf4: - case 0xf5: - case 0xf6: - case 0xf7: - case 0xf8: - case 0xf9: - case 0xfa: - case 0xfb: - case 0xfc: - case 0xfd: - case 0xfe: - case 0xff: - kbd_log("ATkbc: pulse: %01X\n", (val & 0x03) | 0x0c); - pulse_output(dev, (val & 0x03) | 0x0c); - return 0; - } - - return write64_generic(dev, val); -} - -static uint8_t -write60_quadtel(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - - switch (dev->command) { - case 0xcf: /*??? - sent by MegaPC BIOS*/ - kbd_log("ATkbc: ??? - sent by MegaPC BIOS\n"); - return 0; - } - - return 1; -} - -static uint8_t -write64_olivetti(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - - switch (val) { - case 0x80: /* Olivetti-specific command */ - /* - * bit 7: bus expansion board present (M300) / keyboard unlocked (M290) - * bits 4-6: ??? - * bit 3: fast ram check (if inactive keyboard works erratically) - * bit 2: keyboard fuse present - * bits 0-1: ??? - */ - add_to_kbc_queue_front(dev, (0x0c | ((is386) ? 0x00 : 0x80)) & 0xdf, 0, 0x00); - dev->input_port = ((dev->input_port + 1) & 3) | (dev->input_port & 0xfc); - return 0; - } - - return write64_generic(dev, val); -} - -static uint8_t -write64_quadtel(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - - switch (val) { - case 0xaf: - kbd_log("ATkbc: bad KBC command AF\n"); - return 1; - - case 0xcf: /*??? - sent by MegaPC BIOS*/ - kbd_log("ATkbc: ??? - sent by MegaPC BIOS\n"); - dev->want60 = 1; - return 0; - } - - return write64_generic(dev, val); -} - -static uint8_t -write60_toshiba(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - - switch (dev->command) { - case 0xb6: /* T3100e - set color/mono switch */ - kbd_log("ATkbc: T3100e - set color/mono switch\n"); - t3100e_mono_set(val); - return 0; - } - - return 1; -} - -static uint8_t -write64_toshiba(void *priv, uint8_t val) -{ - atkbd_t *dev = (atkbd_t *) priv; - - switch (val) { - case 0xaf: - kbd_log("ATkbc: bad KBC command AF\n"); - return 1; - - case 0xb0: /* T3100e: Turbo on */ - kbd_log("ATkbc: T3100e: Turbo on\n"); - t3100e_turbo_set(1); - return 0; - - case 0xb1: /* T3100e: Turbo off */ - kbd_log("ATkbc: T3100e: Turbo off\n"); - t3100e_turbo_set(0); - return 0; - - case 0xb2: /* T3100e: Select external display */ - kbd_log("ATkbc: T3100e: Select external display\n"); - t3100e_display_set(0x00); - return 0; - - case 0xb3: /* T3100e: Select internal display */ - kbd_log("ATkbc: T3100e: Select internal display\n"); - t3100e_display_set(0x01); - return 0; - - case 0xb4: /* T3100e: Get configuration / status */ - kbd_log("ATkbc: T3100e: Get configuration / status\n"); - add_data(dev, t3100e_config_get()); - return 0; - - case 0xb5: /* T3100e: Get colour / mono byte */ - kbd_log("ATkbc: T3100e: Get colour / mono byte\n"); - add_data(dev, t3100e_mono_get()); - return 0; - - case 0xb6: /* T3100e: Set colour / mono byte */ - kbd_log("ATkbc: T3100e: Set colour / mono byte\n"); - dev->want60 = 1; - return 0; - - case 0xb7: /* T3100e: Emulate PS/2 keyboard */ - case 0xb8: /* T3100e: Emulate AT keyboard */ - dev->flags &= ~KBC_TYPE_MASK; - if (val == 0xb7) { - kbd_log("ATkbc: T3100e: Emulate PS/2 keyboard\n"); - dev->flags |= KBC_TYPE_PS2_NOREF; - } else { - kbd_log("ATkbc: T3100e: Emulate AT keyboard\n"); - dev->flags |= KBC_TYPE_ISA; - } - return 0; - - case 0xbb: /* T3100e: Read 'Fn' key. - Return it for right Ctrl and right Alt; on the real - T3100e, these keystrokes could only be generated - using 'Fn'. */ - kbd_log("ATkbc: T3100e: Read 'Fn' key\n"); - if (keyboard_recv(0xb8) || /* Right Alt */ - keyboard_recv(0x9d)) /* Right Ctrl */ - add_data(dev, 0x04); - else - add_data(dev, 0x00); - return 0; - - case 0xbc: /* T3100e: Reset Fn+Key notification */ - kbd_log("ATkbc: T3100e: Reset Fn+Key notification\n"); - t3100e_notify_set(0x00); - return 0; - - case 0xc0: /*Read input port*/ - kbd_log("ATkbc: read input port\n"); - - /* The T3100e returns all bits set except bit 6 which - * is set by t3100e_mono_set() */ - dev->input_port = (t3100e_mono_get() & 1) ? 0xff : 0xbf; - add_data(dev, dev->input_port); - return 0; - } - - return write64_generic(dev, val); -} - -static void -kbd_write(uint16_t port, uint8_t val, void *priv) -{ - atkbd_t *dev = (atkbd_t *) priv; - int i = 0, bad = 1; - uint8_t mask, kbc_ven = dev->flags & KBC_VEN_MASK; - - switch (port) { - case 0x60: - dev->status &= ~STAT_CD; - if (dev->want60) { - /* Write data to controller. */ - dev->want60 = 0; - - switch (dev->command) { - case 0x60: - case 0x61: - case 0x62: - case 0x63: - case 0x64: - case 0x65: - case 0x66: - case 0x67: - case 0x68: - case 0x69: - case 0x6a: - case 0x6b: - case 0x6c: - case 0x6d: - case 0x6e: - case 0x6f: - case 0x70: - case 0x71: - case 0x72: - case 0x73: - case 0x74: - case 0x75: - case 0x76: - case 0x77: - case 0x78: - case 0x79: - case 0x7a: - case 0x7b: - case 0x7c: - case 0x7d: - case 0x7e: - case 0x7f: - dev->mem[dev->command & 0x1f] = val; - if (dev->command == 0x60) - write_cmd(dev, val); - break; - - case 0xd1: /* write output port */ - kbd_log("ATkbc: write output port\n"); - /* Bit 2 of AMI flags is P22-P23 blocked (1 = yes, 0 = no), - discovered by reverse-engineering the AOpeN Vi15G BIOS. */ - if (dev->ami_flags & 0x04) { - /*If keyboard controller lines P22-P23 are blocked, - we force them to remain unchanged.*/ - val &= ~0x0c; - val |= (dev->output_port & 0x0c); - } - write_output(dev, val | 0x01); - break; - - case 0xd2: /* write to keyboard output buffer */ - kbd_log("ATkbc: write to keyboard output buffer\n"); - add_to_kbc_queue_front(dev, val, 0, 0x00); - break; - - case 0xd3: /* write to mouse output buffer */ - kbd_log("ATkbc: write to mouse output buffer\n"); - if (mouse_write && ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) - keyboard_at_adddata_mouse(val); - break; - - case 0xd4: /* write to mouse */ - kbd_log("ATkbc: write to mouse (%02X)\n", val); - - if (val == 0xbb) - break; - - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) { - set_enable_mouse(dev, 1); - if (mouse_write) - mouse_write(val, mouse_p); - else - add_to_kbc_queue_front(dev, 0xfe, 2, 0x40); - } - break; - - default: - /* - * Run the vendor-specific handler - * if we have one. Otherwise, or if - * it returns an error, log a bad - * controller command. - */ - if (dev->write60_ven) - bad = dev->write60_ven(dev, val); - - if (bad) { - kbd_log("ATkbc: bad controller command %02x data %02x\n", dev->command, val); - add_data_kbd(0xfe); - } - } - } else { - /* Write data to keyboard. */ - dev->mem[0] &= ~0x10; - - if (dev->key_wantdata) { - dev->key_wantdata = 0; - - /* - * Several system BIOSes and OS device drivers - * mess up with this, and repeat the command - * code many times. Fun! - */ - if (val == dev->key_command) { - /* Respond NAK and ignore it. */ - add_data_kbd(0xfe); - dev->key_command = 0x00; - break; - } - - switch (dev->key_command) { - case 0xed: /* set/reset LEDs */ - add_data_kbd_direct(dev, 0xfa); - kbd_log("ATkbd: set LEDs [%02x]\n", val); - break; - - case 0xf0: /* get/set scancode set */ - add_data_kbd_direct(dev, 0xfa); - if (val == 0) { - kbd_log("Get scan code set: %02X\n", keyboard_mode & 3); - add_data_kbd_direct(dev, keyboard_mode & 3); - } else { - if ((val <= 3) && (val != 1)) { - keyboard_mode &= 0xfc; - keyboard_mode |= (val & 3); - kbd_log("Scan code set now: %02X\n", val); - } - set_scancode_map(dev); - } - break; - - case 0xf3: /* set typematic rate/delay */ - add_data_kbd_direct(dev, 0xfa); - break; - - default: - kbd_log("ATkbd: bad keyboard 0060 write %02X command %02X\n", val, dev->key_command); - add_data_kbd_direct(dev, 0xfe); - break; - } - - /* Keyboard command is now done. */ - dev->key_command = 0x00; - } else { - /* No keyboard command in progress. */ - dev->key_command = 0x00; - - set_enable_kbd(dev, 1); - - switch (val) { - case 0x00: - kbd_log("ATkbd: command 00\n"); - add_data_kbd_direct(dev, 0xfa); - break; - - case 0x05: /*??? - sent by NT 4.0*/ - kbd_log("ATkbd: command 05 (NT 4.0)\n"); - add_data_kbd_direct(dev, 0xfe); - break; - - /* Sent by Pentium-era AMI BIOS'es.*/ - case 0x71: - case 0x82: - kbd_log("ATkbd: Pentium-era AMI BIOS command %02X\n", val); - break; - - case 0xed: /* set/reset LEDs */ - kbd_log("ATkbd: set/reset leds\n"); - add_data_kbd_direct(dev, 0xfa); - - dev->key_wantdata = 1; - break; - - case 0xee: /* diagnostic echo */ - kbd_log("ATkbd: ECHO\n"); - add_data_kbd_direct(dev, 0xee); - break; - - case 0xef: /* NOP (reserved for future use) */ - kbd_log("ATkbd: NOP\n"); - break; - - case 0xf0: /* get/set scan code set */ - kbd_log("ATkbd: scan code set\n"); - add_data_kbd_direct(dev, 0xfa); - dev->key_wantdata = 1; - break; - - case 0xf2: /* read ID */ - /* Fixed as translation will be done in add_data_kbd(). */ - kbd_log("ATkbd: read keyboard id\n"); - /* TODO: After keyboard type selection is implemented, make this - return the correct keyboard ID for the selected type. */ - add_data_kbd_direct(dev, 0xfa); - add_data_kbd_direct(dev, 0xab); - add_data_kbd_direct(dev, 0x83); - break; - - case 0xf3: /* set typematic rate/delay */ - kbd_log("ATkbd: set typematic rate/delay\n"); - add_data_kbd_direct(dev, 0xfa); - dev->key_wantdata = 1; - break; - - case 0xf4: /* enable keyboard */ - kbd_log("ATkbd: enable keyboard\n"); - add_data_kbd_direct(dev, 0xfa); - keyboard_scan = 1; - break; - - case 0xf5: /* set defaults and disable keyboard */ - case 0xf6: /* set defaults */ - kbd_log("ATkbd: set defaults%s\n", (val == 0xf6) ? "" : " and disable keyboard"); - keyboard_scan = (val == 0xf6); - kbd_log("val = %02X, keyboard_scan = %i, dev->mem[0] = %02X\n", - val, keyboard_scan, dev->mem[0]); - add_data_kbd_direct(dev, 0xfa); - - keyboard_set3_all_break = 0; - keyboard_set3_all_repeat = 0; - memset(keyboard_set3_flags, 0, 512); - keyboard_mode = (keyboard_mode & 0xfc) | 0x02; - set_scancode_map(dev); - break; - - case 0xf7: /* set all keys to repeat */ - kbd_log("ATkbd: set all keys to repeat\n"); - add_data_kbd_direct(dev, 0xfa); - keyboard_set3_all_break = 1; - break; - - case 0xf8: /* set all keys to give make/break codes */ - kbd_log("ATkbd: set all keys to give make/break codes\n"); - add_data_kbd_direct(dev, 0xfa); - keyboard_set3_all_break = 1; - break; - - case 0xf9: /* set all keys to give make codes only */ - kbd_log("ATkbd: set all keys to give make codes only\n"); - add_data_kbd_direct(dev, 0xfa); - keyboard_set3_all_break = 0; - break; - - case 0xfa: /* set all keys to repeat and give make/break codes */ - kbd_log("ATkbd: set all keys to repeat and give make/break codes\n"); - add_data_kbd_direct(dev, 0xfa); - keyboard_set3_all_repeat = 1; - keyboard_set3_all_break = 1; - break; - - case 0xfe: /* resend last scan code */ - kbd_log("ATkbd: reset last scan code\n"); - add_data_kbd_raw(dev, kbd_last_scan_code); - break; - - case 0xff: /* reset */ - kbd_log("ATkbd: kbd reset\n"); - kbc_queue_reset(1); - kbd_last_scan_code = 0x00; - add_data_kbd_direct(dev, 0xfa); - - /* Set scan code set to 2. */ - keyboard_mode = (keyboard_mode & 0xfc) | 0x02; - set_scancode_map(dev); - - dev->reset_delay = RESET_DELAY_TIME; - break; - - default: - kbd_log("ATkbd: bad keyboard command %02X\n", val); - add_data_kbd_direct(dev, 0xfe); - } - - /* If command needs data, remember command. */ - if (dev->key_wantdata == 1) - dev->key_command = val; - } - } - break; - - case 0x64: - /* Controller command. */ - dev->want60 = 0; - dev->status |= STAT_CD; - - switch (val) { - /* Read data from KBC memory. */ - case 0x20: - case 0x21: - case 0x22: - case 0x23: - case 0x24: - case 0x25: - case 0x26: - case 0x27: - case 0x28: - case 0x29: - case 0x2a: - case 0x2b: - case 0x2c: - case 0x2d: - case 0x2e: - case 0x2f: - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - case 0x36: - case 0x37: - case 0x38: - case 0x39: - case 0x3a: - case 0x3b: - case 0x3c: - case 0x3d: - case 0x3e: - case 0x3f: - add_data(dev, dev->mem[val & 0x1f]); - break; - - /* Write data to KBC memory. */ - case 0x60: - case 0x61: - case 0x62: - case 0x63: - case 0x64: - case 0x65: - case 0x66: - case 0x67: - case 0x68: - case 0x69: - case 0x6a: - case 0x6b: - case 0x6c: - case 0x6d: - case 0x6e: - case 0x6f: - case 0x70: - case 0x71: - case 0x72: - case 0x73: - case 0x74: - case 0x75: - case 0x76: - case 0x77: - case 0x78: - case 0x79: - case 0x7a: - case 0x7b: - case 0x7c: - case 0x7d: - case 0x7e: - case 0x7f: - dev->want60 = 1; - break; - - case 0xaa: /* self-test */ - kbd_log("ATkbc: self-test\n"); - if ((kbc_ven == KBC_VEN_TOSHIBA) || (kbc_ven == KBC_VEN_SAMSUNG)) - dev->status |= STAT_IFULL; - write_output(dev, ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) ? 0x4b : 0xcf); - - /* Always reinitialize all queues - the real hardware pulls keyboard and mouse - clocks high, which stops keyboard scanning. */ - kbd_log("ATkbc: self-test reinitialization\n"); - dev->out_new = dev->out_delayed = -1; - for (i = 0; i < 3; i++) - kbc_queue_reset(i); - kbd_last_scan_code = 0x00; - dev->status &= ~STAT_OFULL; - dev->last_irq = dev->old_last_irq = 0; - - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) - write_cmd(dev, 0x30 | STAT_SYSFLAG); - else - write_cmd(dev, 0x10 | STAT_SYSFLAG); - add_data(dev, 0x55); - break; - - case 0xab: /* interface test */ - kbd_log("ATkbc: interface test\n"); - add_data(dev, 0x00); /*no error*/ - break; - - case 0xac: /* diagnostic dump */ - kbd_log("ATkbc: diagnostic dump\n"); - for (i = 0; i < 16; i++) - add_data(dev, dev->mem[i]); - add_data(dev, (dev->input_port & 0xf0) | 0x80); - add_data(dev, dev->output_port); - add_data(dev, dev->status); - break; - - case 0xad: /* disable keyboard */ - kbd_log("ATkbc: disable keyboard\n"); - set_enable_kbd(dev, 0); - break; - - case 0xae: /* enable keyboard */ - kbd_log("ATkbc: enable keyboard\n"); - set_enable_kbd(dev, 1); - break; - - case 0xca: /* read keyboard mode */ - kbd_log("ATkbc: AMI - read keyboard mode\n"); - add_data(dev, dev->ami_flags); - break; - - case 0xcb: /* set keyboard mode */ - kbd_log("ATkbc: AMI - set keyboard mode\n"); - dev->want60 = 1; - break; - - case 0xd0: /* read output port */ - kbd_log("ATkbc: read output port\n"); - mask = 0xff; - if ((kbc_ven != KBC_VEN_OLIVETTI) && ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) && (dev->mem[0] & 0x10)) - mask &= 0xbf; - add_to_kbc_queue_front(dev, dev->output_port & mask, 0, 0x00); - break; - - case 0xd1: /* write output port */ - kbd_log("ATkbc: write output port\n"); - dev->want60 = 1; - break; - - case 0xd2: /* write keyboard output buffer */ - kbd_log("ATkbc: write keyboard output buffer\n"); - dev->want60 = 1; - break; - - case 0xdd: /* disable A20 address line */ - case 0xdf: /* enable A20 address line */ - kbd_log("ATkbc: %sable A20\n", (val == 0xdd) ? "dis" : "en"); - write_output(dev, (dev->output_port & 0xfd) | (val & 0x02)); - break; - - case 0xe0: /* read test inputs */ - kbd_log("ATkbc: read test inputs\n"); - add_data(dev, 0x00); - break; - - default: - /* - * Unrecognized controller command. - * - * If we have a vendor-specific handler, run - * that. Otherwise, or if that handler fails, - * log a bad command. - */ - if (dev->write64_ven) - bad = dev->write64_ven(dev, val); - - kbd_log(bad ? "ATkbc: bad controller command %02X\n" : "", val); - } - - /* If the command needs data, remember the command. */ - if (dev->want60) - dev->command = val; - break; - } -} - -static uint8_t -kbd_read(uint16_t port, void *priv) -{ - atkbd_t *dev = (atkbd_t *) priv; - uint8_t ret = 0xff; - uint8_t kbc_ven = 0x0; - kbc_ven = dev->flags & KBC_VEN_MASK; - - if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) - cycles -= ISA_CYCLES(8); - - switch (port) { - case 0x60: - ret = dev->out; - dev->status &= ~STAT_OFULL; - picintc(dev->last_irq); - dev->last_irq = 0; - break; - - case 0x64: - ret = (dev->status & 0xfb); - if (dev->mem[0] & STAT_SYSFLAG) - ret |= STAT_SYSFLAG; - /* Only clear the transmit timeout flag on non-PS/2 controllers, as on - PS/2 controller, it is the keyboard/mouse output source bit. */ - // dev->status &= ~STAT_RTIMEOUT; - if (((dev->flags & KBC_TYPE_MASK) > KBC_TYPE_PS2_NOREF) && (kbc_ven != KBC_VEN_IBM_MCA)) - dev->status &= ~STAT_TTIMEOUT; - break; - - default: - kbd_log("ATkbc: read(%04x) invalid!\n", port); - break; - } - - kbd_log((port == 0x61) ? "" : "ATkbc: read(%04X) = %02X\n", port, ret); - - return (ret); -} - -static void -kbd_reset(void *priv) -{ - atkbd_t *dev = (atkbd_t *) priv; - int i; - uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; - - dev->first_write = 1; - // dev->status = STAT_UNLOCKED | STAT_CD; - dev->status = STAT_UNLOCKED; - dev->mem[0] = 0x01; - dev->mem[0] |= CCB_TRANSLATE; - dev->wantirq = 0; - write_output(dev, 0xcf); - dev->last_irq = dev->old_last_irq = 0; - dev->secr_phase = 0; - dev->key_wantdata = 0; - - /* Set up the correct Video Type bits. */ - if ((kbc_ven == KBC_VEN_XI8088) || (kbc_ven == KBC_VEN_ACER)) - dev->input_port = video_is_mda() ? 0xb0 : 0xf0; - else - dev->input_port = video_is_mda() ? 0xf0 : 0xb0; - kbd_log("ATkbc: input port = %02x\n", dev->input_port); - - keyboard_mode = 0x02 | (dev->mem[0] & CCB_TRANSLATE); - - /* Enable keyboard, disable mouse. */ - set_enable_kbd(dev, 1); - keyboard_scan = 1; - set_enable_mouse(dev, 0); - mouse_scan = 0; - - dev->out_new = dev->out_delayed = -1; - for (i = 0; i < 3; i++) - kbc_queue_reset(i); - kbd_last_scan_code = 0; - - sc_or = 0; + dev->rate = 1; + keyboard_set3_all_break = 0; + keyboard_set3_all_repeat = 0; memset(keyboard_set3_flags, 0, 512); - set_scancode_map(dev); - - dev->ami_flags = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) ? 0x01 : 0x00; - dev->ami_stat |= 0x02; -} - -/* Reset the AT keyboard - this is needed for the PCI TRC and is done - until a better solution is found. */ -void -keyboard_at_reset(void) -{ - kbd_reset(SavedKbd); + keyboard_mode = 0x02; + keyboard_at_set_scancode_set(); } static void -kbd_close(void *priv) +keyboard_at_bat(void *priv) { - atkbd_t *dev = (atkbd_t *) priv; + atkbc_dev_t *dev = (atkbc_dev_t *) priv; - kbd_reset(dev); + keyboard_at_set_defaults(dev); - /* Stop timers. */ - timer_disable(&dev->send_delay_timer); + keyboard_scan = 1; + + kbc_at_dev_queue_add(dev, 0xaa, 0); +} + +static void +keyboard_at_invalid_cmd(atkbc_dev_t *dev) +{ + keyboard_at_log("%s: Invalid command [%02X]\n", dev->name, dev->port->dat); + kbc_at_dev_queue_add(dev, inv_cmd_response, 0); +} + + +static void +keyboard_at_write(void *priv) +{ + atkbc_dev_t *dev = (atkbc_dev_t *) priv; + uint8_t val; + + if (dev->port == NULL) + return; + + val = dev->port->dat; + + dev->state = DEV_STATE_MAIN_OUT; + + if ((val < 0xed) && (dev->flags & FLAG_CTRLDAT)) { + dev->flags &= ~FLAG_CTRLDAT; + + switch (dev->command) { + case 0xed: /* Set/reset LEDs */ + kbc_at_dev_queue_add(dev, 0xfa, 0); + keyboard_at_log("%s: Set/reset LEDs [%02X]\n", dev->name, val); + break; + + case 0xf0: /* Get/set scancode set */ + kbc_at_dev_queue_add(dev, (val > 3) ? 0xfe : 0xfa, 0); + switch (val) { + case 0x00: + keyboard_at_log("%s: Get scan code set [%02X]\n", dev->name, keyboard_mode); + kbc_at_dev_queue_add(dev, keyboard_mode, 0); + break; + case 0x01 ... 0x03: + keyboard_mode = val; + keyboard_at_log("%s: Set scan code set [%02X]\n", dev->name, keyboard_mode); + keyboard_at_set_scancode_set(); + break; + default: + /* Fatal so any instance of anything attempting to set scan code > 3 can be reported to us. */ + fatal("%s: Scan code set [%02X] invalid, resend\n", dev->name, val); + dev->flags |= FLAG_CTRLDAT; + dev->state = DEV_STATE_MAIN_WANT_IN; + break; + } + break; + + case 0xf3: /* set typematic rate/delay */ + if (val & 0x80) { + keyboard_at_log("%s: Set typematic rate/delay [%02X] has bit 7 set - invalid\n", dev->name, val); + dev->flags |= FLAG_CTRLDAT; /* Resend = keep waiting for parameter. */ + kbc_at_dev_queue_add(dev, 0xfe, 0); /* Command response */ + dev->state = DEV_STATE_MAIN_WANT_IN; + } else { + dev->rate = val; + kbc_at_dev_queue_add(dev, 0xfa, 0); /* Command response */ + keyboard_at_log("%s: Set typematic rate/delay [%02X]\n", dev->name, val); + } + break; + + default: + fatal("%s: Parameter [%02X] for invalid command [%02X] - possibly memory corruption!\n", dev->name, val, dev->command); + kbc_at_dev_queue_add(dev, 0xfe, 0); + } + } else { + if (dev->flags & FLAG_CTRLDAT) { + /* Special case - another command during another command that wants input - proceed + as normal but do not cancel the command (so keep waiting for input), unless the + command in progress is ED (Set/reset LEDs). */ + if (val == 0xed) { + keyboard_scan = 1; + dev->flags &= ~FLAG_CTRLDAT; + } else + dev->state = DEV_STATE_MAIN_WANT_IN; + } + + switch (val) { + case 0xed: /* set/reset LEDs */ + dev->command = val; + keyboard_at_log("%s: set/reset LEDs\n", dev->name); + dev->flags |= FLAG_CTRLDAT; + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK for command byte */ + dev->state = DEV_STATE_MAIN_WANT_IN; + break; + + case 0xee: /* diagnostic echo */ + keyboard_at_log("%s: ECHO\n", dev->name); + kbc_at_dev_queue_add(dev, 0xee, 0); + break; + + case 0xef: /* Invalid command */ + case 0xf1: /* Invalid command */ + keyboard_at_log("%s: Invalid command [%02X]\n", dev->name, dev->port->dat); + kbc_at_dev_queue_add(dev, inv_cmd_response, 0); + break; + + case 0xf0: /* get/set scan code set */ + if (dev->type & FLAG_PS2) { + dev->command = val; + keyboard_at_log("%s: scan code set\n", dev->name); + dev->flags |= FLAG_CTRLDAT; + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK for command byte */ + dev->state = DEV_STATE_MAIN_WANT_IN; + } else + keyboard_at_invalid_cmd(dev); + break; + + case 0xf2: /* read ID */ + keyboard_at_log("%s: read keyboard id\n", dev->name); + /* TODO: After keyboard type selection is implemented, make this + return the correct keyboard ID for the selected type. */ + kbc_at_dev_queue_add(dev, 0xfa, 0); + for (uint8_t i = 0; i < 4; i++) { + if (id_bytes[dev->type][i] == 0) + break; + + kbc_at_dev_queue_add(dev, id_bytes[dev->type][i], 0); + } + break; + + case 0xf3: /* set command mode */ + dev->command = val; + keyboard_at_log("%s: set typematic rate/delay\n", dev->name); + dev->flags |= FLAG_CTRLDAT; + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK for command byte */ + dev->state = DEV_STATE_MAIN_WANT_IN; + break; + + case 0xf4: /* enable */ + keyboard_at_log("%s: enable keyboard\n", dev->name); + keyboard_scan = 1; + kbc_at_dev_queue_add(dev, 0xfa, 0); + break; + + case 0xf5: /* set defaults and disable keyboard */ + case 0xf6: /* set defaults */ + keyboard_at_log("%s: set defaults%s\n", (val == 0xf6) ? "" : " and disable keyboard"); + keyboard_scan = !(val & 0x01); + keyboard_at_log("%s: val = %02X, keyboard_scan = %i\n", + dev->name, val, keyboard_scan); + kbc_at_dev_queue_add(dev, 0xfa, 0); + + keyboard_set3_all_break = 0; + keyboard_set3_all_repeat = 0; + memset(keyboard_set3_flags, 0, 512); + + keyboard_mode = 0x02; + keyboard_at_set_scancode_set(); + break; + + case 0xf7: /* set all keys to repeat */ + if (dev->type & FLAG_PS2) { + keyboard_at_log("%s: set all keys to repeat\n", dev->name); + kbc_at_dev_queue_add(dev, 0xfa, 0); + keyboard_set3_all_break = 1; + } else + keyboard_at_invalid_cmd(dev); + break; + + case 0xf8: /* set all keys to give make/break codes */ + if (dev->type & FLAG_PS2) { + keyboard_at_log("%s: set all keys to give make/break codes\n", dev->name); + kbc_at_dev_queue_add(dev, 0xfa, 0); + keyboard_set3_all_break = 1; + } else + keyboard_at_invalid_cmd(dev); + break; + + case 0xf9: /* set all keys to give make codes only */ + if (dev->type & FLAG_PS2) { + keyboard_at_log("%s: set all keys to give make codes only\n", dev->name); + kbc_at_dev_queue_add(dev, 0xfa, 0); + keyboard_set3_all_break = 0; + } else + keyboard_at_invalid_cmd(dev); + break; + + case 0xfa: /* set all keys to repeat and give make/break codes */ + if (dev->type & FLAG_PS2) { + keyboard_at_log("%s: set all keys to repeat and give make/break codes\n", dev->name); + kbc_at_dev_queue_add(dev, 0xfa, 0); + keyboard_set3_all_repeat = 1; + keyboard_set3_all_break = 1; + } else + keyboard_at_invalid_cmd(dev); + break; + + /* TODO: Actually implement these commands. */ + case 0xfb: /* set some keys to repeat */ + keyboard_at_log("%s: set some keys to repeat\n", dev->name); + kbc_at_dev_queue_add(dev, inv_cmd_response, 0); + break; + + case 0xfc: /* set some keys to give make/break codes */ + keyboard_at_log("%s: set some keys to give make/break codes\n", dev->name); + kbc_at_dev_queue_add(dev, inv_cmd_response, 0); + break; + + case 0xfd: /* set some keys to give make codes only */ + keyboard_at_log("%s: set some keys to give make codes only\n", dev->name); + kbc_at_dev_queue_add(dev, inv_cmd_response, 0); + break; + + /* TODO: This is supposed to resend multiple bytes after some commands. */ + case 0xfe: /* resend last scan code */ + keyboard_at_log("%s: resend last scan code\n", dev->name); + kbc_at_dev_queue_add(dev, dev->last_scan_code, 0); + break; + + case 0xff: /* reset */ + kbc_at_dev_reset(dev, 1); + break; + + default: + kbc_at_dev_queue_add(dev, 0xfe, 0); + } + } +} + +/* + * Initialize the device for use by the user. + * + * We also get called from the various machines. + */ +void * +keyboard_at_init(const device_t *info) +{ + atkbc_dev_t *dev = kbc_at_dev_init(DEV_KBD); + + dev->name = info->name; + /* Key 14 = Japanese key next to backspace, scan code: 13 (Yen 7D); + Key 29 = US backslash, scan code: 5C (Backslash 2B); + Key 42 = European backslash, scan code: 53 (Backslash 2B); + Key 45 = European key next to left shift, scan code: 13 (Key 56); + Key 56 = Japanese key next to right shift, scan code: 5C (Backslash 73); + Key 59 = Japanese key between left Ctrl and left Alt, scan code: 85 (Muhenkan 7B); + Key 63 = Japanese key between right Ctrl and right Alt, scan code: 86 (Henkan/Zenkouho 79); + Key 65? = Japanese key between right Ctrl and right Alt, scan code: 87 (Hiragana/Katakana 70). + */ + dev->type = FLAG_PS2 | KBD_102_KEY /* device_get_config_int("type") */; + + keyboard_at_log("%s: type=%d\n", dev->name, dev->type); + + dev->process_cmd = keyboard_at_write; + dev->execute_bat = keyboard_at_bat; + + dev->scan = &keyboard_scan; + + dev->fifo_mask = FIFO_SIZE - 1; + + if (dev->port != NULL) + kbc_at_dev_reset(dev, 0); + + keyboard_send = add_data_kbd; + SavedKbd = dev; + + inv_cmd_response = (dev->type & FLAG_PS2) ? 0xfe : 0xfa; + + /* Return our private data to the I/O layer. */ + return dev; +} + +static void +keyboard_at_close(void *priv) +{ + atkbc_dev_t *dev = (atkbc_dev_t *) priv; keyboard_scan = 0; keyboard_send = NULL; @@ -2478,429 +987,48 @@ kbd_close(void *priv) keyboard_set_table(NULL); SavedKbd = NULL; + free(dev); } -static void * -kbd_init(const device_t *info) -{ - atkbd_t *dev; - - dev = (atkbd_t *) malloc(sizeof(atkbd_t)); - memset(dev, 0x00, sizeof(atkbd_t)); - - dev->flags = info->local; - - video_reset(gfxcard[0]); - kbd_reset(dev); - - io_sethandler(0x0060, 1, kbd_read, NULL, NULL, kbd_write, NULL, NULL, dev); - io_sethandler(0x0064, 1, kbd_read, NULL, NULL, kbd_write, NULL, NULL, dev); - keyboard_send = add_data_kbd; - - timer_add(&dev->send_delay_timer, kbd_poll, dev, 1); - timer_add(&dev->pulse_cb, pulse_poll, dev, 0); - - dev->write60_ven = NULL; - dev->write64_ven = NULL; - - switch (dev->flags & KBC_VEN_MASK) { - case KBC_VEN_ACER: - case KBC_VEN_GENERIC: - case KBC_VEN_NCR: - case KBC_VEN_IBM_PS1: - case KBC_VEN_XI8088: - dev->write64_ven = write64_generic; - break; - - case KBC_VEN_OLIVETTI: - dev->write64_ven = write64_olivetti; - break; - - case KBC_VEN_AMI: - case KBC_VEN_INTEL_AMI: - case KBC_VEN_SAMSUNG: - case KBC_VEN_ALI: - dev->write60_ven = write60_ami; - dev->write64_ven = write64_ami; - break; - - case KBC_VEN_IBM_MCA: - dev->write64_ven = write64_ibm_mca; - break; - - case KBC_VEN_QUADTEL: - dev->write60_ven = write60_quadtel; - dev->write64_ven = write64_quadtel; - break; - - case KBC_VEN_TOSHIBA: - dev->write60_ven = write60_toshiba; - dev->write64_ven = write64_toshiba; - break; +static const device_config_t keyboard_at_config[] = { + // clang-format off + { + .name = "type", + .description = "Type", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 2, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "AT 84-key", .value = FLAG_AT | KBD_84_KEY }, + { .description = "AT 101/102/106-key", .value = FLAG_AT | KBD_101_KEY }, + { .description = "AT Korean", .value = FLAG_AT | KBD_KOREAN }, + { .description = "PS/2 101-key", .value = FLAG_PS2 | KBD_101_KEY }, + { .description = "PS/2 102-key", .value = FLAG_PS2 | KBD_102_KEY }, + { .description = "PS/2 106-key JIS", .value = FLAG_PS2 | KBD_JIS }, + { .description = "PS/2 Korean", .value = FLAG_PS2 | KBD_KOREAN }, + { .description = "" } + } + }, + { + .name = "", .description = "", .type = CONFIG_END } - - /* We need this, sadly. */ - SavedKbd = dev; - - return (dev); -} - -const device_t keyboard_at_device = { - .name = "PC/AT Keyboard", - .internal_name = "keyboard_at", - .flags = 0, - .local = KBC_TYPE_ISA | KBC_VEN_GENERIC, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL + // clang-format on }; -const device_t keyboard_at_ami_device = { - .name = "PC/AT Keyboard (AMI)", - .internal_name = "keyboard_at_ami", - .flags = 0, - .local = KBC_TYPE_ISA | KBC_VEN_AMI, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, +/* TODO: Add more keyboard types. */ +const device_t keyboard_at_generic_device = { + .name = "Standard AT or PS/2 Keyboard", + .internal_name = "ps2", + .flags = DEVICE_PS2, + .local = 0, + .init = keyboard_at_init, + .close = keyboard_at_close, + .reset = NULL, + { .poll = NULL }, .speed_changed = NULL, .force_redraw = NULL, - .config = NULL + .config = keyboard_at_config }; - -const device_t keyboard_at_samsung_device = { - .name = "PC/AT Keyboard (Samsung)", - .internal_name = "keyboard_at_samsung", - .flags = 0, - .local = KBC_TYPE_ISA | KBC_VEN_SAMSUNG, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_at_toshiba_device = { - .name = "PC/AT Keyboard (Toshiba)", - .internal_name = "keyboard_at_toshiba", - .flags = 0, - .local = KBC_TYPE_ISA | KBC_VEN_TOSHIBA, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_at_olivetti_device = { - .name = "PC/AT Keyboard (Olivetti)", - .internal_name = "keyboard_at_olivetti", - .flags = 0, - .local = KBC_TYPE_ISA | KBC_VEN_OLIVETTI, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_at_ncr_device = { - .name = "PC/AT Keyboard (NCR)", - .internal_name = "keyboard_at_ncr", - .flags = 0, - .local = KBC_TYPE_ISA | KBC_VEN_NCR, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_device = { - .name = "PS/2 Keyboard", - .internal_name = "keyboard_ps2", - .flags = 0, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_GENERIC, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_ps2_device = { - .name = "PS/2 Keyboard", - .internal_name = "keyboard_ps2_ps2", - .flags = 0, - .local = KBC_TYPE_PS2_1 | KBC_VEN_GENERIC, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_ps1_device = { - .name = "PS/2 Keyboard (IBM PS/1)", - .internal_name = "keyboard_ps2_ps1", - .flags = 0, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_IBM_PS1, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_ps1_pci_device = { - .name = "PS/2 Keyboard (IBM PS/1)", - .internal_name = "keyboard_ps2_ps1_pci", - .flags = DEVICE_PCI, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_IBM_PS1, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_xi8088_device = { - .name = "PS/2 Keyboard (Xi8088)", - .internal_name = "keyboard_ps2_xi8088", - .flags = 0, - .local = KBC_TYPE_PS2_1 | KBC_VEN_XI8088, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_ami_device = { - .name = "PS/2 Keyboard (AMI)", - .internal_name = "keyboard_ps2_ami", - .flags = 0, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_AMI, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_olivetti_device = { - .name = "PS/2 Keyboard (Olivetti)", - .internal_name = "keyboard_ps2_olivetti", - .flags = 0, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_OLIVETTI, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_mca_device = { - .name = "PS/2 Keyboard", - .internal_name = "keyboard_ps2_mca", - .flags = 0, - .local = KBC_TYPE_PS2_1 | KBC_VEN_IBM_MCA, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_mca_2_device = { - .name = "PS/2 Keyboard", - .internal_name = "keyboard_ps2_mca_2", - .flags = 0, - .local = KBC_TYPE_PS2_2 | KBC_VEN_IBM_MCA, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_quadtel_device = { - .name = "PS/2 Keyboard (Quadtel/MegaPC)", - .internal_name = "keyboard_ps2_quadtel", - .flags = 0, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_QUADTEL, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_pci_device = { - .name = "PS/2 Keyboard", - .internal_name = "keyboard_ps2_pci", - .flags = DEVICE_PCI, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_GENERIC, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_ami_pci_device = { - .name = "PS/2 Keyboard (AMI)", - .internal_name = "keyboard_ps2_ami_pci", - .flags = DEVICE_PCI, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_AMI, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_ali_pci_device = { - .name = "PS/2 Keyboard (ALi M5123/M1543C)", - .internal_name = "keyboard_ps2_ali_pci", - .flags = DEVICE_PCI, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_ALI, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_intel_ami_pci_device = { - .name = "PS/2 Keyboard (AMI)", - .internal_name = "keyboard_ps2_intel_ami_pci", - .flags = DEVICE_PCI, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_INTEL_AMI, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t keyboard_ps2_acer_pci_device = { - .name = "PS/2 Keyboard (Acer 90M002A)", - .internal_name = "keyboard_ps2_acer_pci", - .flags = DEVICE_PCI, - .local = KBC_TYPE_PS2_NOREF | KBC_VEN_ACER, - .init = kbd_init, - .close = kbd_close, - .reset = kbd_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -void -keyboard_at_set_mouse(void (*func)(uint8_t val, void *priv), void *priv) -{ - mouse_write = func; - mouse_p = priv; -} - -void -keyboard_at_adddata_keyboard_raw(uint8_t val) -{ - atkbd_t *dev = SavedKbd; - - add_data_kbd_queue(dev, 0, val); -} - -void -keyboard_at_adddata_mouse(uint8_t val) -{ - atkbd_t *dev = SavedKbd; - - kbc_queue_add(dev, val, 2, 0x00); -} - -void -keyboard_at_mouse_reset(void) -{ - kbc_queue_reset(2); -} - -uint8_t -keyboard_at_mouse_pos(void) -{ - return ((mouse_queue_end - mouse_queue_start) & 0xf); -} - -void -keyboard_at_set_mouse_scan(uint8_t val) -{ - atkbd_t *dev = SavedKbd; - uint8_t temp_mouse_scan = val ? 1 : 0; - - if (temp_mouse_scan == !(dev->mem[0] & 0x20)) - return; - - set_enable_mouse(dev, val ? 1 : 0); - - kbd_log("ATkbc: mouse scan %sabled via PCI\n", mouse_scan ? "en" : "dis"); -} - -uint8_t -keyboard_at_get_mouse_scan(void) -{ - atkbd_t *dev = SavedKbd; - - return ((dev->mem[0] & 0x20) ? 0x00 : 0x10); -} - -void -keyboard_at_set_a20_key(int state) -{ - atkbd_t *dev = SavedKbd; - - write_output(dev, (dev->output_port & 0xfd) | ((!!state) << 1)); -} diff --git a/src/device/keyboard_xt.c b/src/device/keyboard_xt.c index fe523cd2f..a5b5579a6 100644 --- a/src/device/keyboard_xt.c +++ b/src/device/keyboard_xt.c @@ -68,14 +68,18 @@ #define KBD_TYPE_PRAVETZ 10 #define KBD_TYPE_XTCLONE 11 -typedef struct { +typedef struct xtkbd_t { int want_irq; int blocked; int tandy; - uint8_t pa, pb, pd, clock; + uint8_t pa; + uint8_t pb; + uint8_t pd; + uint8_t clock; uint8_t key_waiting; - uint8_t type, pravetz_flags; + uint8_t type; + uint8_t pravetz_flags; pc_timer_t send_delay_timer; } xtkbd_t; @@ -343,10 +347,11 @@ const scancode scancode_xt[512] = { }; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; -static int is_tandy = 0, is_t1x00 = 0, - is_amstrad = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; +static int is_tandy = 0; +static int is_t1x00 = 0; +static int is_amstrad = 0; #ifdef ENABLE_KEYBOARD_XT_LOG int keyboard_xt_do_log = ENABLE_KEYBOARD_XT_LOG; @@ -370,9 +375,9 @@ static uint8_t get_fdd_switch_settings(void) { - int i, fdd_count = 0; + uint8_t fdd_count = 0; - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -453,6 +458,9 @@ kbd_adddata(uint16_t val) case 0x54: /* SysRQ => toggle window */ t1000_syskey(0x00, 0x00, 0x08); break; + + default: + break; } } else t1000_syskey(0x04, 0x00, 0x00); /* Reset 'Fn' indicator */ @@ -467,7 +475,8 @@ kbd_adddata(uint16_t val) void kbd_adddata_process(uint16_t val, void (*adddata)(uint16_t val)) { - uint8_t num_lock = 0, shift_states = 0; + uint8_t num_lock = 0; + uint8_t shift_states = 0; if (!adddata) return; @@ -515,7 +524,9 @@ static void kbd_write(uint16_t port, uint8_t val, void *priv) { xtkbd_t *kbd = (xtkbd_t *) priv; - uint8_t bit, set, new_clock; + uint8_t bit; + uint8_t set; + uint8_t new_clock; switch (port) { case 0x61: /* Keyboard Control Register (aka Port B) */ @@ -574,14 +585,17 @@ kbd_write(uint16_t port, uint8_t val, void *priv) kbd->pravetz_flags = (kbd->pravetz_flags & ~(1 << bit)) | set; } break; + + default: + break; } } static uint8_t kbd_read(uint16_t port, void *priv) { - xtkbd_t *kbd = (xtkbd_t *) priv; - uint8_t ret = 0xff; + const xtkbd_t *kbd = (xtkbd_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x60: /* Keyboard Data Register (aka Port A) */ @@ -682,9 +696,12 @@ kbd_read(uint16_t port, void *priv) ret = kbd->pravetz_flags; kbd_log("XTkbd: Port %02X in : %02X\n", port, ret); break; + + default: + break; } - return (ret); + return ret; } static void @@ -700,7 +717,7 @@ kbd_reset(void *priv) keyboard_scan = 1; - key_queue_start = 0, + key_queue_start = 0; key_queue_end = 0; } @@ -873,7 +890,7 @@ kbd_init(const device_t *info) is_amstrad = 0; - return (kbd); + return kbd; } static void diff --git a/src/device/mouse.c b/src/device/mouse.c index 98ce0eaf4..2acfd905e 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -27,23 +27,28 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> +#include <86box/timer.h> +#include <86box/gdbstub.h> #include <86box/mouse.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct mouse_t { const device_t *device; } mouse_t; int mouse_type = 0; -int mouse_x, - mouse_y, - mouse_z, - mouse_buttons, - mouse_mode, - mouse_tablet_in_proximity = 0, - tablet_tool_type = 1; /* 0 = Puck/Cursor, 1 = Pen */ +int mouse_x; +int mouse_y; +int mouse_z; +int mouse_buttons; +int mouse_mode; +int mouse_tablet_in_proximity = 0; +int tablet_tool_type = 1; /* 0 = Puck/Cursor, 1 = Pen */ -double mouse_x_abs, - mouse_y_abs; +double mouse_x_abs; +double mouse_y_abs; + +pc_timer_t mouse_timer; /* mouse event timer */ static const device_t mouse_none_device = { .name = "None", @@ -75,19 +80,20 @@ static const device_t mouse_internal_device = { static mouse_t mouse_devices[] = { // clang-format off - { &mouse_none_device }, - { &mouse_internal_device }, - { &mouse_logibus_device }, - { &mouse_msinport_device }, + { &mouse_none_device }, + { &mouse_internal_device }, + { &mouse_logibus_device }, + { &mouse_msinport_device }, #if 0 - { &mouse_genibus_device }, + { &mouse_genibus_device }, #endif - { &mouse_mssystems_device }, - { &mouse_msserial_device }, - { &mouse_ltserial_device }, - { &mouse_ps2_device }, - { &mouse_wacom_device }, - { NULL } + { &mouse_mssystems_device }, + { &mouse_msserial_device }, + { &mouse_ltserial_device }, + { &mouse_ps2_device }, + { &mouse_wacom_device }, + { &mouse_wacom_artpad_device }, + { NULL } // clang-format on }; @@ -97,6 +103,8 @@ static int mouse_nbut; static int (*mouse_dev_poll)(int x, int y, int z, int b, void *priv); static void (*mouse_poll_ex)(void) = NULL; +static double sample_rate = 200.0; + #ifdef ENABLE_MOUSE_LOG int mouse_do_log = ENABLE_MOUSE_LOG; @@ -140,6 +148,29 @@ mouse_close(void) mouse_priv = NULL; mouse_nbut = 0; mouse_dev_poll = NULL; + + timer_stop(&mouse_timer); +} + +static void +mouse_timer_poll(UNUSED(void *priv)) +{ + /* Poll at 255 Hz, maximum supported by PS/2 mic. */ + timer_on_auto(&mouse_timer, 1000000.0 / sample_rate); + +#ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */ + if (gdbstub_step == GDBSTUB_EXEC) +#endif + mouse_process(); +} + +void +mouse_set_sample_rate(double new_rate) +{ + timer_stop(&mouse_timer); + + sample_rate = new_rate; + timer_on_auto(&mouse_timer, 1000000.0 / sample_rate); } void @@ -160,6 +191,12 @@ mouse_reset(void) if (mouse_type == 0) return; + timer_add(&mouse_timer, mouse_timer_poll, NULL, 0); + + /* Poll at 100 Hz, the default of a PS/2 mouse. */ + sample_rate = 100.0; + timer_on_auto(&mouse_timer, 1000000.0 / sample_rate); + mouse_curr = mouse_devices[mouse_type].device; if (mouse_curr != NULL) @@ -230,18 +267,18 @@ mouse_get_from_internal_name(char *s) while (mouse_devices[c].device != NULL) { if (!strcmp((char *) mouse_devices[c].device->internal_name, s)) - return (c); + return c; c++; } - return (0); + return 0; } int mouse_has_config(int mouse) { if (mouse_devices[mouse].device == NULL) - return (0); + return 0; return (mouse_devices[mouse].device->config ? 1 : 0); } @@ -255,7 +292,7 @@ mouse_get_device(int mouse) int mouse_get_buttons(void) { - return (mouse_nbut); + return mouse_nbut; } /* Return number of MOUSE types we know about. */ diff --git a/src/device/mouse_bus.c b/src/device/mouse_bus.c index 3e9cd28e2..0537c0cb4 100644 --- a/src/device/mouse_bus.c +++ b/src/device/mouse_bus.c @@ -80,6 +80,7 @@ #include <86box/timer.h> #include <86box/device.h> #include <86box/mouse.h> +#include <86box/plat_unused.h> #include <86box/random.h> #define IRQ_MASK ((1 << 5) >> dev->irq) @@ -132,16 +133,26 @@ static const uint8_t periods[4] = { 30, 50, 100, 200 }; /* Our mouse device. */ typedef struct mouse { - uint8_t current_b, control_val, - config_val, sig_val, - command_val, pad; + uint8_t current_b; + uint8_t control_val; + uint8_t config_val; + uint8_t sig_val; + uint8_t command_val; + uint8_t pad; - int8_t current_x, current_y; + int8_t current_x; + int8_t current_y; - int base, irq, bn, flags, - mouse_delayed_dx, mouse_delayed_dy, - mouse_buttons, mouse_buttons_last, - toggle_counter, timer_enabled; + int base; + int irq; + int bn; + int flags; + int mouse_delayed_dx; + int mouse_delayed_dy; + int mouse_buttons; + int mouse_buttons_last; + int toggle_counter; + int timer_enabled; double period; pc_timer_t timer; /* mouse event timer */ @@ -215,6 +226,8 @@ lt_read(uint16_t port, void *priv) return (dev->control_val | 0x0F) & ~IRQ_MASK; else return 0xff; + + default: break; } @@ -249,6 +262,7 @@ ms_read(uint16_t port, void *priv) case INP_CTRL_COMMAND: value = dev->control_val; break; + default: bm_log("ERROR: Reading data port in unsupported mode 0x%02x\n", dev->control_val); } @@ -263,6 +277,9 @@ ms_read(uint16_t port, void *priv) case INP_PORT_CONFIG: bm_log("ERROR: Unsupported read from port 0x%04x\n", port); break; + + default: + break; } bm_log("DEBUG: read from address 0x%04x, value = 0x%02x\n", port, value); @@ -355,6 +372,9 @@ lt_write(uint16_t port, uint8_t val, void *priv) dev->control_val &= ~bit; /* Reset */ } break; + + default: + break; } } @@ -380,6 +400,7 @@ ms_write(uint16_t port, uint8_t val, void *priv) case INP_CTRL_READ_Y: dev->command_val = val & 0x07; break; + default: bm_log("ERROR: Unsupported command written to port 0x%04x (value = 0x%02x)\n", port, val); } @@ -429,6 +450,7 @@ ms_write(uint16_t port, uint8_t val, void *priv) dev->control_val &= INP_PERIOD_MASK; dev->control_val |= (val & ~INP_PERIOD_MASK); return; + default: bm_log("ERROR: Unsupported period written to port 0x%04x (value = 0x%02x)\n", port, val); } @@ -436,6 +458,7 @@ ms_write(uint16_t port, uint8_t val, void *priv) dev->control_val = val; break; + default: bm_log("ERROR: Unsupported write to port 0x%04x (value = 0x%02x)\n", port, val); } @@ -444,22 +467,25 @@ ms_write(uint16_t port, uint8_t val, void *priv) case INP_PORT_CONFIG: bm_log("ERROR: Unsupported write to port 0x%04x (value = 0x%02x)\n", port, val); break; + + default: + break; } } /* The emulator calls us with an update on the host mouse device. */ static int -bm_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) +bm_poll(int x, int y, UNUSED(int z), int b, UNUSED(double abs_x), UNUSED(double abs_y), void *priv) { mouse_t *dev = (mouse_t *) priv; int xor ; if (!(dev->flags & FLAG_ENABLED)) - return (1); /* Mouse is disabled, do nothing. */ + return 1; /* Mouse is disabled, do nothing. */ if (!x && !y && !((b ^ dev->mouse_buttons_last) & 0x07)) { dev->mouse_buttons_last = b; - return (1); /* State has not changed, do nothing. */ + return 1; /* State has not changed, do nothing. */ } /* Converts button states from MRL to LMR. */ @@ -512,7 +538,7 @@ bm_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) bm_log("DEBUG: Data Interrupt Fired...\n"); } } - return (0); + return 0; } /* The timer calls us on every tick if the mouse is in timer mode @@ -520,7 +546,8 @@ bm_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) static void bm_update_data(mouse_t *dev) { - int delta_x, delta_y; + int delta_x; + int delta_y; int xor ; /* If the counters are not frozen, update them. */ diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index 7a0cbd6e6..2d150b5ed 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -23,6 +23,7 @@ #include <86box/device.h> #include <86box/keyboard.h> #include <86box/mouse.h> +#include <86box/plat_unused.h> enum { MODE_STREAM, @@ -30,28 +31,15 @@ enum { MODE_ECHO }; -typedef struct { - const char *name; /* name of this device */ - int8_t type; /* type of this device */ +#define FLAG_EXPLORER 0x200 /* Has 5 buttons */ +#define FLAG_5BTN 0x100 /* using Intellimouse Optical mode */ +#define FLAG_INTELLI 0x80 /* device is IntelliMouse */ +#define FLAG_INTMODE 0x40 /* using Intellimouse mode */ +#define FLAG_SCALED 0x20 /* enable delta scaling */ +#define FLAG_ENABLED 0x10 /* dev is enabled for use */ +#define FLAG_CTRLDAT 0x08 /* ctrl or data mode */ - int mode; - - uint16_t flags; - uint8_t resolution; - uint8_t sample_rate; - - uint8_t command; - - int x, y, z, b; - - uint8_t last_data[6]; -} mouse_t; -#define FLAG_5BTN 0x100 /* using Intellimouse Optical mode */ -#define FLAG_INTELLI 0x80 /* device is IntelliMouse */ -#define FLAG_INTMODE 0x40 /* using Intellimouse mode */ -#define FLAG_SCALED 0x20 /* enable delta scaling */ -#define FLAG_ENABLED 0x10 /* dev is enabled for use */ -#define FLAG_CTRLDAT 0x08 /* ctrl or data mode */ +#define FIFO_SIZE 16 int mouse_scan = 0; @@ -76,24 +64,33 @@ mouse_ps2_log(const char *fmt, ...) void mouse_clear_data(void *priv) { - mouse_t *dev = (mouse_t *) priv; + atkbc_dev_t *dev = (atkbc_dev_t *) priv; dev->flags &= ~FLAG_CTRLDAT; } static void -ps2_report_coordinates(mouse_t *dev) +ps2_report_coordinates(atkbc_dev_t *dev, int main) { uint8_t buff[3] = { 0x08, 0x00, 0x00 }; + int temp_z; - if (dev->x > 255) - dev->x = 255; - if (dev->x < -256) + if (dev->x > 255) { + dev->x = 255; + buff[0] |= 0x40; + } + if (dev->x < -256) { dev->x = -256; - if (dev->y > 255) + buff[0] |= 0x40; + } + if (dev->y > 255) { dev->y = 255; - if (dev->y < -256) + buff[0] |= 0x80; + } + if (dev->y < -256) { dev->y = -256; + buff[0] |= 0x80; + } if (dev->z < -8) dev->z = -8; if (dev->z > 7) @@ -103,195 +100,241 @@ ps2_report_coordinates(mouse_t *dev) buff[0] |= 0x10; if (dev->y < 0) buff[0] |= 0x20; - if (mouse_buttons & 0x01) - buff[0] |= 0x01; - if (mouse_buttons & 0x02) - buff[0] |= 0x02; - if (dev->flags & FLAG_INTELLI) { - if (mouse_buttons & 0x04) - buff[0] |= 0x04; - } + buff[0] |= (dev->b & ((dev->flags & FLAG_INTELLI) ? 0x07 : 0x03)); buff[1] = (dev->x & 0xff); buff[2] = (dev->y & 0xff); - keyboard_at_adddata_mouse(buff[0]); - keyboard_at_adddata_mouse(buff[1]); - keyboard_at_adddata_mouse(buff[2]); + kbc_at_dev_queue_add(dev, buff[0], main); + kbc_at_dev_queue_add(dev, buff[1], main); + kbc_at_dev_queue_add(dev, buff[2], main); if (dev->flags & FLAG_INTMODE) { - int temp_z = dev->z; - if ((dev->flags & FLAG_5BTN)) { - temp_z &= 0xF; + temp_z = dev->z & 0x0f; + if (dev->flags & FLAG_5BTN) { if (mouse_buttons & 8) temp_z |= 0x10; if (mouse_buttons & 16) temp_z |= 0x20; + } else { + /* The wheel coordinate is sign-extended. */ + if (temp_z & 0x08) + temp_z |= 0xf0; } - keyboard_at_adddata_mouse(temp_z); + kbc_at_dev_queue_add(dev, temp_z, main); } dev->x = dev->y = dev->z = 0; } static void -ps2_write(uint8_t val, void *priv) +ps2_set_defaults(atkbc_dev_t *dev) { - mouse_t *dev = (mouse_t *) priv; + dev->mode = MODE_STREAM; + dev->rate = 100; + mouse_set_sample_rate(100.0); + dev->resolution = 2; + dev->flags &= 0x88; + mouse_scan = 0; +} + +static void +ps2_bat(void *priv) +{ + atkbc_dev_t *dev = (atkbc_dev_t *) priv; + + ps2_set_defaults(dev); + + kbc_at_dev_queue_add(dev, 0xaa, 0); + kbc_at_dev_queue_add(dev, 0x00, 0); +} + +static void +ps2_write(void *priv) +{ + atkbc_dev_t *dev = (atkbc_dev_t *) priv; uint8_t temp; + uint8_t val; + static uint8_t last_data[6] = { 0x00 }; + + if (dev->port == NULL) + return; + + val = dev->port->dat; + + dev->state = DEV_STATE_MAIN_OUT; if (dev->flags & FLAG_CTRLDAT) { dev->flags &= ~FLAG_CTRLDAT; if (val == 0xff) - goto mouse_reset; - - switch (dev->command) { + kbc_at_dev_reset(dev, 1); + else switch (dev->command) { case 0xe8: /* set mouse resolution */ dev->resolution = val; - keyboard_at_adddata_mouse(0xfa); + kbc_at_dev_queue_add(dev, 0xfa, 0); + mouse_ps2_log("%s: Set mouse resolution [%02X]\n", dev->name, val); break; case 0xf3: /* set sample rate */ - dev->sample_rate = val; - keyboard_at_adddata_mouse(0xfa); /* Command response */ + dev->rate = val; + mouse_set_sample_rate((double) val); + kbc_at_dev_queue_add(dev, 0xfa, 0); /* Command response */ + mouse_ps2_log("%s: Set sample rate [%02X]\n", dev->name, val); break; default: - keyboard_at_adddata_mouse(0xfc); + kbc_at_dev_queue_add(dev, 0xfc, 0); } } else { dev->command = val; switch (dev->command) { case 0xe6: /* set scaling to 1:1 */ + mouse_ps2_log("%s: Set scaling to 1:1\n", dev->name); dev->flags &= ~FLAG_SCALED; - keyboard_at_adddata_mouse(0xfa); + kbc_at_dev_queue_add(dev, 0xfa, 0); break; case 0xe7: /* set scaling to 2:1 */ + mouse_ps2_log("%s: Set scaling to 2:1\n", dev->name); dev->flags |= FLAG_SCALED; - keyboard_at_adddata_mouse(0xfa); + kbc_at_dev_queue_add(dev, 0xfa, 0); break; case 0xe8: /* set mouse resolution */ + mouse_ps2_log("%s: Set mouse resolution\n", dev->name); dev->flags |= FLAG_CTRLDAT; - keyboard_at_adddata_mouse(0xfa); + kbc_at_dev_queue_add(dev, 0xfa, 0); + dev->state = DEV_STATE_MAIN_WANT_IN; break; case 0xe9: /* status request */ - keyboard_at_adddata_mouse(0xfa); - temp = (dev->flags & 0x30); + mouse_ps2_log("%s: Status request\n", dev->name); + kbc_at_dev_queue_add(dev, 0xfa, 0); + temp = (dev->flags & 0x20); + if (mouse_scan) + temp |= FLAG_ENABLED; if (mouse_buttons & 1) temp |= 4; if (mouse_buttons & 2) temp |= 1; if ((mouse_buttons & 4) && (dev->flags & FLAG_INTELLI)) temp |= 2; - keyboard_at_adddata_mouse(temp); - keyboard_at_adddata_mouse(dev->resolution); - keyboard_at_adddata_mouse(dev->sample_rate); + kbc_at_dev_queue_add(dev, temp, 0); + kbc_at_dev_queue_add(dev, dev->resolution, 0); + kbc_at_dev_queue_add(dev, dev->rate, 0); break; case 0xea: /* set stream */ + mouse_ps2_log("%s: Set stream\n", dev->name); dev->flags &= ~FLAG_CTRLDAT; + dev->mode = MODE_STREAM; mouse_scan = 1; - keyboard_at_adddata_mouse(0xfa); /* ACK for command byte */ + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK for command byte */ break; case 0xeb: /* Get mouse data */ - keyboard_at_adddata_mouse(0xfa); + mouse_ps2_log("%s: Get mouse data\n", dev->name); + kbc_at_dev_queue_add(dev, 0xfa, 0); - ps2_report_coordinates(dev); + ps2_report_coordinates(dev, 0); + break; + + case 0xf0: /* set remote */ + mouse_ps2_log("%s: Set remote\n", dev->name); + dev->flags &= ~FLAG_CTRLDAT; + dev->mode = MODE_REMOTE; + mouse_scan = 1; + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK for command byte */ break; case 0xf2: /* read ID */ - keyboard_at_adddata_mouse(0xfa); + mouse_ps2_log("%s: Read ID\n", dev->name); + kbc_at_dev_queue_add(dev, 0xfa, 0); if (dev->flags & FLAG_INTMODE) - keyboard_at_adddata_mouse((dev->flags & FLAG_5BTN) ? 0x04 : 0x03); + kbc_at_dev_queue_add(dev, (dev->flags & FLAG_5BTN) ? 0x04 : 0x03, 0); else - keyboard_at_adddata_mouse(0x00); + kbc_at_dev_queue_add(dev, 0x00, 0); break; - case 0xf3: /* set command mode */ + case 0xf3: /* set sample rate */ + mouse_ps2_log("%s: Set sample rate\n", dev->name); dev->flags |= FLAG_CTRLDAT; - keyboard_at_adddata_mouse(0xfa); /* ACK for command byte */ + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK for command byte */ + dev->state = DEV_STATE_MAIN_WANT_IN; break; case 0xf4: /* enable */ - dev->flags |= FLAG_ENABLED; + mouse_ps2_log("%s: Enable\n", dev->name); mouse_scan = 1; - keyboard_at_adddata_mouse(0xfa); + kbc_at_dev_queue_add(dev, 0xfa, 0); break; case 0xf5: /* disable */ - dev->flags &= ~FLAG_ENABLED; + mouse_ps2_log("%s: Disable\n", dev->name); mouse_scan = 0; - keyboard_at_adddata_mouse(0xfa); + kbc_at_dev_queue_add(dev, 0xfa, 0); break; case 0xf6: /* set defaults */ + mouse_ps2_log("%s: Set defaults\n", dev->name); + ps2_set_defaults(dev); + kbc_at_dev_queue_add(dev, 0xfa, 0); + break; + case 0xff: /* reset */ -mouse_reset: - dev->mode = MODE_STREAM; - dev->flags &= 0x88; - mouse_scan = 1; - keyboard_at_mouse_reset(); - keyboard_at_adddata_mouse(0xfa); - if (dev->command == 0xff) { - keyboard_at_adddata_mouse(0xaa); - keyboard_at_adddata_mouse(0x00); - } + mouse_ps2_log("%s: Reset\n", dev->name); + kbc_at_dev_reset(dev, 1); break; default: - keyboard_at_adddata_mouse(0xfe); + kbc_at_dev_queue_add(dev, 0xfe, 0); } } if (dev->flags & FLAG_INTELLI) { for (temp = 0; temp < 5; temp++) - dev->last_data[temp] = dev->last_data[temp + 1]; + last_data[temp] = last_data[temp + 1]; - dev->last_data[5] = val; + last_data[5] = val; - if (dev->last_data[0] == 0xf3 && dev->last_data[1] == 0xc8 - && dev->last_data[2] == 0xf3 && dev->last_data[3] == 0xc8 - && dev->last_data[4] == 0xf3 && dev->last_data[5] == 0x50 - && mouse_get_buttons() == 5) { - dev->flags |= FLAG_INTMODE | FLAG_5BTN; - } else if (dev->last_data[0] == 0xf3 && dev->last_data[1] == 0xc8 - && dev->last_data[2] == 0xf3 && dev->last_data[3] == 0x64 - && dev->last_data[4] == 0xf3 && dev->last_data[5] == 0x50) { + if ((last_data[0] == 0xf3) && (last_data[1] == 0xc8) && + (last_data[2] == 0xf3) && (last_data[3] == 0x64) && + (last_data[4] == 0xf3) && (last_data[5] == 0x50)) dev->flags |= FLAG_INTMODE; - } + + if ((dev->flags & FLAG_EXPLORER) && (dev->flags & FLAG_INTMODE) && + (last_data[0] == 0xf3) && (last_data[1] == 0xc8) && + (last_data[2] == 0xf3) && (last_data[3] == 0xc8) && + (last_data[4] == 0xf3) && (last_data[5] == 0x50)) + dev->flags |= FLAG_5BTN; } } static int -ps2_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) +ps2_poll(int x, int y, int z, int b, UNUSED(double abs_x), UNUSED(double abs_y), void *priv) { - mouse_t *dev = (mouse_t *) priv; + atkbc_dev_t *dev = (atkbc_dev_t *) priv; + int packet_size = (dev->flags & FLAG_INTMODE) ? 4 : 3; - if (!x && !y && !z && (b == dev->b)) - return (0xff); + if (!mouse_scan || (!x && !y && !z && (b == dev->b))) + return 0xff; -#if 0 - if (!(dev->flags & FLAG_ENABLED)) - return(0xff); -#endif - - if (!mouse_scan) - return (0xff); - - dev->x += x; - dev->y -= y; - dev->z -= z; - if ((dev->mode == MODE_STREAM) && (dev->flags & FLAG_ENABLED) && (keyboard_at_mouse_pos() < 13)) { + if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) { + dev->x = x; + dev->y = -y; + dev->z = -z; + dev->b = b; + } else { + dev->x += x; + dev->y -= y; + dev->z -= z; dev->b = b; - - ps2_report_coordinates(dev); } - return (0); + if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) + ps2_report_coordinates(dev, 1); + + return 0; } /* @@ -302,11 +345,9 @@ ps2_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) void * mouse_ps2_init(const device_t *info) { - mouse_t *dev; + atkbc_dev_t *dev = kbc_at_dev_init(DEV_AUX); int i; - dev = (mouse_t *) malloc(sizeof(mouse_t)); - memset(dev, 0x00, sizeof(mouse_t)); dev->name = info->name; dev->type = info->local; @@ -314,29 +355,35 @@ mouse_ps2_init(const device_t *info) i = device_get_config_int("buttons"); if (i > 2) dev->flags |= FLAG_INTELLI; + if (i > 4) + dev->flags |= FLAG_EXPLORER; - if (i == 4) + if (i >= 4) i = 3; - /* Hook into the general AT Keyboard driver. */ - keyboard_at_set_mouse(ps2_write, dev); - mouse_ps2_log("%s: buttons=%d\n", dev->name, i); /* Tell them how many buttons we have. */ mouse_set_buttons(i); + dev->process_cmd = ps2_write; + dev->execute_bat = ps2_bat; + + dev->scan = &mouse_scan; + + dev->fifo_mask = FIFO_SIZE - 1; + + if (dev->port != NULL) + kbc_at_dev_reset(dev, 0); + /* Return our private data to the I/O layer. */ - return (dev); + return dev; } static void ps2_close(void *priv) { - mouse_t *dev = (mouse_t *) priv; - - /* Unhook from the general AT Keyboard driver. */ - keyboard_at_set_mouse(NULL, NULL); + atkbc_dev_t *dev = (atkbc_dev_t *) priv; free(dev); } diff --git a/src/device/mouse_serial.c b/src/device/mouse_serial.c index f7956a9bd..c74e5216b 100644 --- a/src/device/mouse_serial.c +++ b/src/device/mouse_serial.c @@ -26,6 +26,8 @@ #include <86box/timer.h> #include <86box/serial.h> #include <86box/mouse.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #define SERMOUSE_PORT 0 /* attach to Serial0 */ @@ -37,7 +39,9 @@ enum { PHASE_DIAGNOSTIC, PHASE_FORMAT_AND_REVISION, PHASE_COPYRIGHT_STRING, - PHASE_BUTTONS + PHASE_BUTTONS, + PHASE_ACK, + PHASE_BAUD_RATE }; enum { @@ -45,26 +49,40 @@ enum { REPORT_PHASE_TRANSMIT }; -typedef struct { - const char *name; /* name of this device */ - int8_t type, /* type of this device */ - port; - uint8_t flags, but, /* device flags */ - want_data, - status, format, - prompt, on_change, - id_len, id[255], - data_len, data[5]; - int abs_x, abs_y, - rel_x, rel_y, - rel_z, - oldb, lastb; +typedef struct mouse_t { + const char *name; /* name of this device */ + int8_t type; /* type of this device */ + int8_t port; + uint8_t flags; /* device flags */ + uint8_t but; + uint8_t want_data; + uint8_t status; + uint8_t format; + uint8_t prompt; + uint8_t on_change; + uint8_t id_len; + uint8_t id[255]; + uint8_t data_len; + uint8_t data[5]; + int abs_x; + int abs_y; + int rel_x; + int rel_y; + int rel_z; + int oldb; + int lastb; - int command_pos, command_phase, - report_pos, report_phase, - command_enabled, report_enabled; - double transmit_period, report_period; - pc_timer_t command_timer, report_timer; + int command_pos; + int command_phase; + int report_pos; + int report_phase; + int command_enabled; + int report_enabled; + double transmit_period; + double report_period; + double auto_period; + pc_timer_t command_timer; + pc_timer_t report_timer; serial_t *serial; } mouse_t; @@ -135,8 +153,8 @@ sermouse_transmit_period(mouse_t *dev, int bps, int rps) case 5: /* MM Series format: 8 data, odd parity, 1 stop, 1 start */ word_len = 11; break; - default: case 7: /* Microsoft-compatible format: 7 data, no parity, 1 stop, 1 start */ + default: word_len = 9; break; } @@ -155,7 +173,7 @@ sermouse_transmit_period(mouse_t *dev, int bps, int rps) /* Callback from serial driver: RTS was toggled. */ static void -sermouse_callback(struct serial_s *serial, void *priv) +sermouse_callback(UNUSED(struct serial_s *serial), void *priv) { mouse_t *dev = (mouse_t *) priv; @@ -191,9 +209,9 @@ sermouse_data_msystems(mouse_t *dev, int x, int y, int b) static uint8_t sermouse_data_3bp(mouse_t *dev, int x, int y, int b) { - dev->data[0] |= (b & 0x01) ? 0x00 : 0x04; /* left button */ - dev->data[0] |= (b & 0x04) ? 0x00 : 0x02; /* middle button */ - dev->data[0] |= (b & 0x02) ? 0x00 : 0x01; /* right button */ + dev->data[0] |= (b & 0x01) ? 0x04 : 0x00; /* left button */ + dev->data[0] |= (b & 0x04) ? 0x02 : 0x00; /* middle button */ + dev->data[0] |= (b & 0x02) ? 0x01 : 0x00; /* right button */ dev->data[1] = x; dev->data[2] = -y; @@ -211,13 +229,14 @@ sermouse_data_mmseries(mouse_t *dev, int x, int y, int b) dev->data[0] = 0x80; if (x >= 0) dev->data[0] |= 0x10; + /* It appears we have inverted Y polarity. */ if (y < 0) dev->data[0] |= 0x08; dev->data[0] |= (b & 0x01) ? 0x04 : 0x00; /* left button */ dev->data[0] |= (b & 0x04) ? 0x02 : 0x00; /* middle button */ dev->data[0] |= (b & 0x02) ? 0x01 : 0x00; /* right button */ - dev->data[1] = abs(x); - dev->data[2] = abs(y); + dev->data[1] = abs(x) & 0x7f; + dev->data[2] = abs(y) & 0x7f; return 3; } @@ -281,7 +300,7 @@ static uint8_t sermouse_data_hex(mouse_t *dev, int x, int y, int b) { char ret[6] = { 0, 0, 0, 0, 0, 0 }; - uint8_t i, but = 0x00; + uint8_t but = 0x00; but |= (b & 0x01) ? 0x04 : 0x00; /* left button */ but |= (b & 0x04) ? 0x02 : 0x00; /* middle button */ @@ -289,7 +308,7 @@ sermouse_data_hex(mouse_t *dev, int x, int y, int b) sprintf(ret, "%02X%02X%01X", (int8_t) y, (int8_t) x, but & 0x0f); - for (i = 0; i < 5; i++) + for (uint8_t i = 0; i < 5; i++) dev->data[i] = ret[4 - i]; return 5; @@ -328,6 +347,9 @@ sermouse_report(int x, int y, int z, int b, mouse_t *dev) case 7: len = sermouse_data_ms(dev, x, y, z, b); break; + + default: + break; } dev->data_len = len; @@ -368,7 +390,8 @@ sermouse_last_button_status(mouse_t *dev) static void sermouse_update_delta(mouse_t *dev, int *local, int *global) { - int min, max; + int min; + int max; if (dev->format == 3) { min = -2048; @@ -394,7 +417,9 @@ static uint8_t sermouse_update_data(mouse_t *dev) { uint8_t ret = 0; - int delta_x, delta_y, delta_z; + int delta_x; + int delta_y; + int delta_z; /* Update the deltas and the delays. */ sermouse_update_delta(dev, &delta_x, &dev->rel_x); @@ -481,6 +506,17 @@ sermouse_command_timer(void *priv) sermouse_report_timer((void *) dev); } break; + case PHASE_ACK: + serial_write_fifo(dev->serial, 0x06); +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case PHASE_BAUD_RATE: + sermouse_command_phase_idle(dev); + sermouse_timer_on(dev, dev->report_period, 1); + dev->report_phase = REPORT_PHASE_PREPARE; + sermouse_report_timer((void *) dev); + break; case PHASE_DATA: serial_write_fifo(dev->serial, dev->data[dev->command_pos]); sermouse_command_pos_check(dev, dev->data_len); @@ -511,13 +547,13 @@ sermouse_command_timer(void *priv) } static int -sermouse_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) +sermouse_poll(int x, int y, int z, int b, UNUSED(double abs_x), UNUSED(double abs_y), void *priv) { mouse_t *dev = (mouse_t *) priv; if (!x && !y && !z && (b == dev->oldb)) { dev->oldb = b; - return (1); + return 1; } dev->oldb = b; @@ -556,7 +592,7 @@ sermouse_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv dev->rel_y += y; dev->rel_z += z; - return (0); + return 0; } static void @@ -588,7 +624,16 @@ ltsermouse_set_report_period(mouse_t *dev, int rps) } static void -ltsermouse_write(struct serial_s *serial, void *priv, uint8_t data) +ltsermouse_switch_baud_rate(mouse_t *dev, int phase) +{ + dev->command_pos = 0; + dev->command_phase = phase; + timer_stop(&dev->command_timer); + sermouse_timer_on(dev, 10000.0, 0); +} + +static void +ltsermouse_write(UNUSED(struct serial_s *serial), void *priv, uint8_t data) { mouse_t *dev = (mouse_t *) priv; @@ -603,7 +648,9 @@ ltsermouse_write(struct serial_s *serial, void *priv, uint8_t data) switch (data) { default: mouse_serial_log("Serial mouse: Invalid period %02X, using 1200 bps\n", data); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x6E: dev->transmit_period = sermouse_transmit_period(dev, 1200, -1); break; @@ -617,11 +664,20 @@ ltsermouse_write(struct serial_s *serial, void *priv, uint8_t data) dev->transmit_period = sermouse_transmit_period(dev, 9600, -1); break; } + ltsermouse_switch_baud_rate(dev, PHASE_BAUD_RATE); + break; + default: break; } else switch (data) { + case 0x20: + sermouse_timer_on(dev, 0.0, 1); + dev->transmit_period = dev->auto_period; + ltsermouse_switch_baud_rate(dev, PHASE_ACK); + break; case 0x2A: + sermouse_timer_on(dev, 0.0, 1); dev->want_data = data; dev->data_len = 1; break; @@ -696,9 +752,20 @@ ltsermouse_write(struct serial_s *serial, void *priv, uint8_t data) case 0x6B: ltsermouse_command_phase(dev, PHASE_BUTTONS); break; + + default: + break; } } +static void +ltsermouse_transmit_period(UNUSED(serial_t *serial), void *priv, double transmit_period) +{ + mouse_t *dev = (mouse_t *) priv; + + dev->auto_period = transmit_period; +} + static void sermouse_speed_changed(void *priv) { @@ -756,8 +823,8 @@ sermouse_init(const device_t *info) dev->id_len = 1; dev->id[0] = 'M'; switch (dev->but) { - case 2: default: + case 2: dev->type = info->local ? MOUSE_TYPE_LOGITECH : MOUSE_TYPE_MICROSOFT; break; case 3: @@ -775,6 +842,7 @@ sermouse_init(const device_t *info) } dev->transmit_period = sermouse_transmit_period(dev, 1200, -1); + dev->auto_period = dev->transmit_period; /* Default: Continuous reporting = no delay between reports. */ dev->report_phase = REPORT_PHASE_PREPARE; @@ -787,7 +855,7 @@ sermouse_init(const device_t *info) /* Attach a serial port to the mouse. */ if (info->local) - dev->serial = serial_attach(dev->port, sermouse_callback, ltsermouse_write, dev); + dev->serial = serial_attach_ex(dev->port, sermouse_callback, ltsermouse_write, ltsermouse_transmit_period, NULL, dev); else dev->serial = serial_attach(dev->port, sermouse_callback, NULL, dev); @@ -805,7 +873,7 @@ sermouse_init(const device_t *info) mouse_set_buttons((dev->flags & FLAG_3BTN) ? 3 : 2); /* Return our private data to the I/O layer. */ - return (dev); + return dev; } static const device_config_t mssermouse_config[] = { diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index f6f39fa95..32856634e 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -9,6 +9,7 @@ #include <86box/mouse.h> #include <86box/serial.h> #include <86box/plat.h> +#include <86box/fifo8.h> #define FLAG_3BTN 0x20 /* enable 3-button mode */ @@ -19,48 +20,152 @@ enum wacom_modes { WACOM_MODE_SWITCH = 3, }; +enum wacom_handshake_modes { + WACOM_HANDSHAKE_NONE = 0, + WACOM_HANDSHAKE_CTS = 1, + WACOM_HANDSHAKE_DTS = 2, + WACOM_HANDSHAKE_BOTH = 3, +}; + +enum wacom_cmd_set { + WACOM_CMDSET_BITPAD = 0, + WACOM_CMDSET_MM1201 = 1, + WACOM_CMDSET_IIS = 2, + WACOM_CMDSET_IV = 3 +}; + +enum wacom_tablet_type { + WACOM_TYPE_IISONLY = 0, + WACOM_TYPE_IV, +}; + enum { REPORT_PHASE_PREPARE, REPORT_PHASE_TRANSMIT }; -typedef struct { - const char *name; /* name of this device */ - int8_t type, /* type of this device */ - port; - uint8_t flags, but, /* device flags */ - status, format, - data_len, data[64], - data_rec[0x200]; - int abs_x, abs_y, - rel_x, rel_y, - oldb, b; +typedef struct wacom_tablet_id { + char id[64]; + int type; +} wacom_tablet_id; - int data_pos, data_rec_pos, mode, transmission_ongoing, transmission_format, interval; - int increment, suppressed_increment; +static const wacom_tablet_id sd510_id = { + .id = "~#SD51C V3.2.1.01\r", + .type = WACOM_TYPE_IISONLY +}; + +static const wacom_tablet_id artpad_id = { + .id = "~#KT-0405-R00 V1.1-0\r", + .type = WACOM_TYPE_IV +}; + +static const uint32_t wacom_resolution_values[4] = { + 500, + 508, + 1000, + 1270 +}; + +typedef struct mouse_wacom_t { + const char *name; /* name of this device */ + int8_t type; /* type of this device */ + int8_t port; + uint8_t flags; /* device flags */ + uint8_t but; + uint8_t status; + uint8_t bits; + uint8_t data_rec[0x200]; + int abs_x; + int abs_y; + int rel_x; + int rel_y; + int oldb; + int b; + + Fifo8 data; + + int data_rec_pos; + int mode; + int interval; + int increment; + int suppressed_increment; int transmission_stopped; int reset; - int transmit_id, transmit_id_pending; + int transmit_id; + int transmit_id_pending; int pressure_mode; - int suppressed, measurement, always_report; - int remote_req, remote_mode; + int suppressed; + int measurement; + int remote_req; + + uint32_t x_res; + uint32_t y_res; + const wacom_tablet_id *tablet_type; - int last_abs_x, last_abs_y; /* Suppressed/Increment Mode. */ - uint32_t settings; /* Settings DWORD */ + int last_abs_x; /* Suppressed/Increment Mode. */ + int last_abs_y; /* Suppressed/Increment Mode. */ + union { + uint32_t settings; /* Settings DWORD */ + /* We don't target any architectures except x86/x64/ARM32/ARM64. + (The ABIs for those are explicit in little-endian bit ordering) */ + struct settings_bits { + uint8_t remote_mode : 1; + uint8_t bitpad_two_cursor_data : 1; + uint8_t mm961_orientation : 1; + uint8_t mm_command_set : 1; + uint8_t tilt : 1; + uint8_t multi_device : 1; + uint8_t reading_height : 1; + uint8_t pressure_sensitivity : 1; + + uint8_t pnp : 1; /* Unused. */ + uint8_t dummy : 1; + uint8_t terminator : 2; + uint8_t out_of_range_data : 1; + uint8_t origin_location : 1; + uint8_t resolution : 2; + + uint8_t transfer_rate : 2; + uint8_t coord_sys : 1; + uint8_t output_format : 1; + uint8_t transfer_mode : 2; + uint8_t handshake : 2; + + uint8_t stop_bits_conf : 1; + uint8_t data_bits_conf : 1; + uint8_t parity : 2; + uint8_t baud_rate : 2; + uint8_t cmd_set : 2; + } settings_bits; + }; double transmit_period; - double old_tsc, reset_tsc; + double old_tsc; + double reset_tsc; pc_timer_t report_timer; serial_t *serial; } mouse_wacom_t; +/* TODO: What is this needed for? */ +#if 0 +static unsigned int +reverse(register unsigned int x) +{ + x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); + x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); + x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); + x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); + return ((x >> 16) | (x << 16)); +} +#endif + static double wacom_transmit_period(mouse_wacom_t *dev, int bps, int rps) { double dbps = (double) bps; double temp = 0.0; - int word_len = 10; + int word_len = dev->bits; if (rps == -1) temp = (double) word_len; @@ -74,39 +179,118 @@ wacom_transmit_period(mouse_wacom_t *dev, int bps, int rps) return temp; } +static void +wacom_process_settings_dword(mouse_wacom_t *wacom, uint32_t dword) +{ + wacom->settings = dword; + + wacom->mode = wacom->settings_bits.transfer_mode; + + wacom->bits = 1 + 7 + wacom->settings_bits.data_bits_conf; + wacom->bits += 1 + wacom->settings_bits.stop_bits_conf; + if (wacom->settings_bits.parity == 2 && !(wacom->bits % 2)) { + wacom->bits++; + } else if (wacom->settings_bits.parity == 3 && (wacom->bits % 2)) { + wacom->bits++; + } + + switch(wacom->settings_bits.baud_rate) { + case 0: + wacom->transmit_period = wacom_transmit_period(wacom, 2400, -1); + break; + + case 1: + wacom->transmit_period = wacom_transmit_period(wacom, 4800, -1); + break; + + case 2: + wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); + break; + + case 3: + wacom->transmit_period = wacom_transmit_period(wacom, 19200, -1); + break; + + default: + break; + } + + mouse_mode = !wacom->settings_bits.coord_sys; + wacom->x_res = wacom->y_res = wacom_resolution_values[wacom->settings_bits.resolution]; +} + static void wacom_reset(mouse_wacom_t *wacom) { - wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); - wacom->mode = WACOM_MODE_POINT; - wacom->data_pos = 0; - wacom->transmission_ongoing = 0; - wacom->mode = 0; - wacom->transmission_stopped = 0; - wacom->interval = 0; - wacom->transmit_id = 0; - wacom->format = 0; /* ASCII */ - wacom->measurement = 1; + wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); + wacom->mode = WACOM_MODE_POINT; + wacom->transmission_stopped = 0; + wacom->interval = 0; + wacom->transmit_id = 0; + wacom->settings_bits.output_format = 1; /* ASCII */ + wacom->settings_bits.cmd_set = 1; + wacom->measurement = 1; wacom->increment = wacom->suppressed_increment = 0; wacom->reset_tsc = tsc; - wacom->remote_mode = wacom->remote_req = 0; - wacom->always_report = 0; + wacom->settings_bits.remote_mode = wacom->remote_req = 0; + wacom->settings_bits.out_of_range_data = 0; mouse_mode = 1; + wacom_process_settings_dword(wacom, 0xA21BC800); +} + +static void +wacom_reset_artpad(mouse_wacom_t *wacom) +{ + wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); + wacom->mode = WACOM_MODE_SUPPRESSED; + wacom->transmission_stopped = 0; + wacom->interval = 0; + wacom->transmit_id = 0; + wacom->settings_bits.output_format = 0; /* Binary */ + wacom->measurement = 1; + wacom->increment = 0; + wacom->suppressed_increment = 1; + wacom->reset_tsc = tsc; + wacom->settings_bits.remote_mode = 0; + wacom->remote_req = 0; + wacom->settings_bits.out_of_range_data = 0; + + wacom_process_settings_dword(wacom, 0xE203C000); + mouse_mode = 1; } static void -wacom_callback(struct serial_s *serial, void *priv) +wacom_callback(UNUSED(struct serial_s *serial), void *priv) { mouse_wacom_t *wacom = (mouse_wacom_t *) priv; - wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); + switch(wacom->settings_bits.baud_rate) { + case 0: + wacom->transmit_period = wacom_transmit_period(wacom, 2400, -1); + break; + + case 1: + wacom->transmit_period = wacom_transmit_period(wacom, 4800, -1); + break; + + case 2: + wacom->transmit_period = wacom_transmit_period(wacom, 9600, -1); + break; + + case 3: + wacom->transmit_period = wacom_transmit_period(wacom, 19200, -1); + break; + + default: + break; + } timer_stop(&wacom->report_timer); timer_on_auto(&wacom->report_timer, wacom->transmit_period); } static void -wacom_write(struct serial_s *serial, void *priv, uint8_t data) +wacom_write(UNUSED(struct serial_s *serial), void *priv, uint8_t data) { mouse_wacom_t *wacom = (mouse_wacom_t *) priv; static int special_command = 0; @@ -119,10 +303,19 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) switch (data) { case '#': { - if (!wacom->transmission_ongoing) - wacom->transmit_id++; + wacom->transmit_id = 1; break; } + case 'C': + case '*': + case 'R': + { + wacom->data_rec[wacom->data_rec_pos++] = '~'; + wacom->data_rec[wacom->data_rec_pos++] = data; + break; + } + default: + break; } special_command = 0; return; @@ -130,7 +323,15 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) if (data == '@') { wacom->remote_req = 1; - wacom->remote_mode = 1; + wacom->settings_bits.remote_mode = 1; + return; + } + if (data == '#' && wacom->tablet_type->type == WACOM_TYPE_IV) { + wacom_reset_artpad(wacom); + return; + } + if (data == '$') { + wacom_reset(wacom); return; } if (data == 0x13) { @@ -139,7 +340,7 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) } if (data == 0x11) { wacom->transmission_stopped = 0; - wacom->remote_mode = wacom->remote_req = 0; + wacom->settings_bits.remote_mode = wacom->remote_req = 0; return; } wacom->data_rec[wacom->data_rec_pos++] = data; @@ -151,63 +352,103 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) pclog("Wacom: written %s", wacom->data_rec); else pclog("Wacom: written %s\n", wacom->data_rec); - if (!memcmp(wacom->data_rec, "AS", 2)) { - wacom->format = (wacom->data_rec[2] == '1'); - wacom->transmission_ongoing = 0; + if (!memcmp(wacom->data_rec, "AS", 2) && wacom->settings_bits.cmd_set == WACOM_CMDSET_IIS) { + wacom->settings_bits.output_format = !(wacom->data_rec[2] == '1'); } else if (!memcmp(wacom->data_rec, "SR", 2)) { wacom->mode = WACOM_MODE_STREAM; - wacom->suppressed_increment = 0; } else if (!memcmp(wacom->data_rec, "IN", 2)) { sscanf((const char *) wacom->data_rec, "IN%d", &wacom->increment); - } else if (!memcmp(wacom->data_rec, "RE", 2) || wacom->data_rec[0] == '$' || wacom->data_rec[0] == '#') { - wacom_reset(wacom); + } else if (!memcmp(wacom->data_rec, "RE", 2)) { + if (wacom->tablet_type->type == WACOM_TYPE_IV) wacom_reset_artpad(wacom); + else wacom_reset(wacom); } else if (!memcmp(wacom->data_rec, "IT", 2)) { sscanf((const char *) wacom->data_rec, "IT%d", &wacom->interval); - } else if (!memcmp(wacom->data_rec, "DE", 2)) { + } else if (!memcmp(wacom->data_rec, "DE", 2) && wacom->settings_bits.cmd_set == WACOM_CMDSET_IIS) { sscanf((const char *) wacom->data_rec, "DE%d", &mouse_mode); mouse_mode = !mouse_mode; plat_mouse_capture(0); } else if (!memcmp(wacom->data_rec, "SU", 2)) { sscanf((const char *) wacom->data_rec, "SU%d", &wacom->suppressed_increment); - } else if (!memcmp(wacom->data_rec, "PH", 2)) { + wacom->settings_bits.transfer_mode = wacom->mode = WACOM_MODE_SUPPRESSED; + } else if (!memcmp(wacom->data_rec, "PH", 2) && wacom->settings_bits.cmd_set == WACOM_CMDSET_IIS) { sscanf((const char *) wacom->data_rec, "PH%d", &wacom->pressure_mode); } else if (!memcmp(wacom->data_rec, "IC", 2)) { sscanf((const char *) wacom->data_rec, "IC%d", &wacom->measurement); + } else if (!memcmp(wacom->data_rec, "SW", 2)) { + wacom->mode = WACOM_MODE_SWITCH; } else if (!memcmp(wacom->data_rec, "AL", 2)) { - sscanf((const char *) wacom->data_rec, "AL%d", &wacom->always_report); + uint8_t out_of_range_data = wacom->settings_bits.out_of_range_data; + wacom->settings_bits.out_of_range_data = !!out_of_range_data; } else if (!memcmp(wacom->data_rec, "RQ", 2)) { - sscanf((const char *) wacom->data_rec, "RQ%d", &wacom->remote_mode); - if (wacom->remote_mode) + int remote_mode = 0; + sscanf((const char *) wacom->data_rec, "RQ%d", &remote_mode); + wacom->settings_bits.remote_mode = !!remote_mode; + if (wacom->settings_bits.remote_mode) wacom->remote_req = 1; } else if (!memcmp(wacom->data_rec, "SP", 2)) { wacom->transmission_stopped = 1; } else if (!memcmp(wacom->data_rec, "ST", 2)) { wacom->transmission_stopped = 0; - wacom->remote_mode = wacom->remote_req = 0; + wacom->settings_bits.remote_mode = wacom->remote_req = 0; + } else if (!memcmp(wacom->data_rec, "NR", 2)) { + sscanf((const char *) wacom->data_rec, "NR%d", &wacom->x_res); + wacom->y_res = wacom->x_res; + } else if (wacom->tablet_type->type == WACOM_TYPE_IV && wacom->data_rec[0] == '~') { + if (!memcmp(wacom->data_rec, "~*", 2)) { + uint32_t settings_dword = wacom->settings; + if (strstr((const char *) wacom->data_rec, ",")) { + uint32_t x_res = wacom->x_res; + uint32_t y_res = wacom->y_res; + uint32_t increment = wacom->increment; + uint32_t interval = wacom->interval; + + sscanf((const char *) wacom->data_rec, "~*%08X,%d,%d,%d,%d", &settings_dword, &increment, &interval, &x_res, &y_res); + + wacom->interval = interval; + wacom->increment = increment; + wacom->x_res = x_res; + wacom->y_res = y_res; + } else { + sscanf((const char *) wacom->data_rec, "~*%X", &settings_dword); + } + wacom_process_settings_dword(wacom, settings_dword); + } else if (!memcmp(wacom->data_rec, "~C", 2)) { + fifo8_push_all(&wacom->data, (const uint8_t *) "~C5039,3779\r", sizeof("~C5039,3779\r") - 1); + } else if (!memcmp(wacom->data_rec, "~R", 2)) { + uint8_t data[256] = { 0 }; + snprintf((char *)data, sizeof(data), (const char *) "~*%08X,%d,%d,%d,%d\r", wacom->settings, wacom->increment, wacom->interval, wacom->x_res, wacom->y_res); + fifo8_push_all(&wacom->data, data, strlen((const char *) data)); + } } } } static int -wacom_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) +wacom_poll(int x, int y, UNUSED(int z), int b, double abs_x, double abs_y, void *priv) { mouse_wacom_t *wacom = (mouse_wacom_t *) priv; - wacom->abs_x = abs_x * (wacom->measurement ? 4566. : 5800.); - wacom->abs_y = abs_y * (wacom->measurement ? 2972. : 3774.); - if (wacom->abs_x > (wacom->measurement ? 4566 : 5800)) - wacom->abs_x = (wacom->measurement ? 4566 : 5800); - if (wacom->abs_y > (wacom->measurement ? 2972 : 3774)) - wacom->abs_x = (wacom->measurement ? 2972 : 3774); - if (wacom->abs_x < 0) - wacom->abs_x = 0; - if (wacom->abs_y < 0) - wacom->abs_y = 0; - wacom->rel_x = x; - wacom->rel_y = y; + + if (wacom->settings_bits.cmd_set == WACOM_CMDSET_IV) { + wacom->abs_x = abs_x * 5039. * (wacom->x_res / 1000.); + wacom->abs_y = abs_y * 3779. * (wacom->y_res / 1000.); + } else { + wacom->abs_x = abs_x * (wacom->measurement ? 4566. : 5800.); + wacom->abs_y = abs_y * (wacom->measurement ? 2972. : 3774.); + if (wacom->abs_x > (wacom->measurement ? 4566 : 5800)) + wacom->abs_x = (wacom->measurement ? 4566 : 5800); + if (wacom->abs_y > (wacom->measurement ? 2972 : 3774)) + wacom->abs_x = (wacom->measurement ? 2972 : 3774); + if (wacom->abs_x < 0) + wacom->abs_x = 0; + if (wacom->abs_y < 0) + wacom->abs_y = 0; + wacom->rel_x = x; + wacom->rel_y = y; + } if (wacom->b != b) wacom->oldb = wacom->b; wacom->b = b; - return (0); + return 0; } static int @@ -239,54 +480,72 @@ wacom_get_switch(int b) static void wacom_transmit_prepare(mouse_wacom_t *wacom, int x, int y) { - wacom->transmission_ongoing = 1; - wacom->data_pos = 0; - memset(wacom->data, 0, sizeof(wacom->data)); if (wacom->transmit_id) { - wacom->transmission_format = 0; - snprintf((char *) wacom->data, sizeof(wacom->data), "~#SD51C V3.2.1.01\r"); + uint8_t data[128] = { 0 }; + snprintf((char *) data, sizeof(data), "%s", wacom->tablet_type->id); + fifo8_push_all(&wacom->data, data, strlen((char *)data)); + wacom->transmit_id = 0; return; } - wacom->transmission_format = wacom->format; wacom->last_abs_x = wacom->abs_x; wacom->last_abs_y = wacom->abs_y; wacom->remote_req = 0; wacom->oldb = wacom->b; - if (wacom->format == 1) { - wacom->data[0] = 0xC0; - wacom->data[6] = wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t) 31 : (uint8_t) -31) : wacom_get_switch(wacom->b); + if (wacom->settings_bits.output_format == 0) { + uint8_t data[7]; + data[0] = 0xC0; + if (wacom->settings_bits.cmd_set == WACOM_CMDSET_IV) { + if (tablet_tool_type == 0) + data[6] = ((wacom->b & 0x1) ? (uint8_t) 31 : (uint8_t) -1); + else + data[6] = ((wacom->b & 0x1) ? (uint8_t) 63 : (uint8_t) -63); + } + else + data[6] = (wacom->pressure_mode || wacom->settings_bits.cmd_set == WACOM_CMDSET_IV) ? ((wacom->b & 0x1) ? (uint8_t) 31 : (uint8_t) -31) : wacom_get_switch(wacom->b); - wacom->data[5] = (y & 0x7F); - wacom->data[4] = ((y & 0x3F80) >> 7) & 0x7F; - wacom->data[3] = (((y & 0xC000) >> 14) & 3); + data[5] = (y & 0x7F); + data[4] = ((y & 0x3F80) >> 7) & 0x7F; + data[3] = (((y & 0xC000) >> 14) & 3); - wacom->data[2] = (x & 0x7F); - wacom->data[1] = ((x & 0x3F80) >> 7) & 0x7F; - wacom->data[0] |= (((x & 0xC000) >> 14) & 3); + data[2] = (x & 0x7F); + data[1] = ((x & 0x3F80) >> 7) & 0x7F; + data[0] |= (((x & 0xC000) >> 14) & 3); - if (mouse_mode == 0) { - wacom->data[0] |= (!!(x < 0)) << 2; - wacom->data[3] |= (!!(y < 0)) << 2; + if (mouse_mode == 0 && wacom->settings_bits.cmd_set == WACOM_CMDSET_IIS) { + data[0] |= (!!(x < 0)) << 2; + data[3] |= (!!(y < 0)) << 2; } - if (wacom->pressure_mode) { - wacom->data[0] |= 0x10; - wacom->data[6] &= 0x7F; + if (wacom->settings_bits.cmd_set == WACOM_CMDSET_IV) { + data[6] &= 0x7F; + data[3] &= 0x3; + if (wacom_get_switch(wacom->b) != 0x21) { + data[3] |= (wacom_get_switch(wacom->b) & 0xF) << 3; + data[0] |= 0x8; + } + } + + if (wacom->pressure_mode && wacom->settings_bits.cmd_set == WACOM_CMDSET_IIS) { + data[0] |= 0x10; + data[6] &= 0x7F; } if (tablet_tool_type == 1) { - wacom->data[0] |= 0x20; + data[0] |= 0x20; } if (!mouse_tablet_in_proximity) { - wacom->data[0] &= ~0x40; + data[0] &= ~0x40; } + fifo8_push_all(&wacom->data, data, 7); } else { - wacom->data[0] = 0; - snprintf((char *) wacom->data, sizeof(wacom->data), "*,%05d,%05d,%d\r\n", + uint8_t data[128]; + data[0] = 0; + snprintf((char *) data, sizeof(data), "*,%05d,%05d,%d\r\n", wacom->abs_x, wacom->abs_y, wacom->pressure_mode ? ((wacom->b & 0x1) ? (uint8_t) -31 : (uint8_t) 15) : ((wacom->b & 0x1) ? 21 : 00)); + fifo8_push_all(&wacom->data, data, strlen((char *)data)); } } @@ -306,17 +565,17 @@ wacom_report_timer(void *priv) timer_on_auto(&wacom->report_timer, wacom->transmit_period); if ((((double) (tsc - wacom->reset_tsc)) / cpuclock * 1000.0) <= 10) return; - if (wacom->transmit_id && !wacom->transmission_ongoing) + if (wacom->transmit_id) goto transmit_prepare; - if (wacom->transmission_ongoing) + if (fifo8_num_used(&wacom->data)) goto transmit; - else if (wacom->remote_mode && !wacom->remote_req) + else if (wacom->settings_bits.remote_mode && !wacom->remote_req) return; else { - if (wacom->remote_mode && wacom->remote_req) { + if (wacom->settings_bits.remote_mode && wacom->remote_req) { goto transmit_prepare; } - if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->always_report)) + if (wacom->transmission_stopped || (!mouse_tablet_in_proximity && !wacom->settings_bits.out_of_range_data)) return; if (milisecond_diff >= (wacom->interval * 5)) { @@ -325,12 +584,14 @@ wacom_report_timer(void *priv) return; switch (wacom->mode) { - case WACOM_MODE_STREAM: default: + case WACOM_MODE_STREAM: break; case WACOM_MODE_POINT: { + if (wacom->suppressed_increment) + break; if (!(wacom_switch_off_to_on(wacom->b, wacom->oldb))) return; break; @@ -345,6 +606,9 @@ wacom_report_timer(void *priv) } } + if (increment && !mouse_tablet_in_proximity) + return; + if (increment && !(x_diff > increment || y_diff > increment)) { if (wacom->suppressed_increment && (wacom->b == wacom->oldb)) return; @@ -358,12 +622,8 @@ transmit_prepare: wacom_transmit_prepare(wacom, x, y); transmit: - serial_write_fifo(wacom->serial, wacom->data[wacom->data_pos++]); - if ((wacom->transmission_format == 0 && wacom->data[wacom->data_pos] == 0) - || (wacom->transmission_format == 1 && wacom->data_pos == 7)) { - wacom->transmission_ongoing = 0; - wacom->transmit_id = 0; - wacom->data_pos = 0; + serial_write_fifo(wacom->serial, fifo8_pop(&wacom->data)); + if (fifo8_num_used(&wacom->data) == 0) { wacom->old_tsc = tsc; } return; @@ -377,6 +637,13 @@ wacom_init(const device_t *info) dev = (mouse_wacom_t *) calloc(1, sizeof(mouse_wacom_t)); dev->name = info->name; dev->but = 3; + dev->bits = 10; + if (info->local == 0) { + dev->tablet_type = &sd510_id; + } else + dev->tablet_type = (wacom_tablet_id*)info->local; + + fifo8_create(&dev->data, 512); dev->port = device_get_config_int("port"); @@ -384,7 +651,11 @@ wacom_init(const device_t *info) timer_add(&dev->report_timer, wacom_report_timer, dev, 0); mouse_set_buttons(dev->but); - wacom_reset(dev); + if (dev->tablet_type->type == WACOM_TYPE_IV) { + wacom_reset_artpad(dev); + wacom_process_settings_dword(dev, 0xE2018000); + } + else wacom_reset(dev); return dev; } @@ -402,6 +673,8 @@ wacom_close(void *priv) { mouse_wacom_t *dev = (mouse_wacom_t *) priv; + fifo8_destroy(&dev->data); + /* Detach serial port from the mouse. */ if (dev && dev->serial && dev->serial->sd) memset(dev->serial->sd, 0, sizeof(serial_device_t)); @@ -435,7 +708,21 @@ const device_t mouse_wacom_device = { .name = "Wacom SD-510C", .internal_name = "wacom_serial", .flags = DEVICE_COM, - .local = MOUSE_TYPE_WACOM, + .local = 0, + .init = wacom_init, + .close = wacom_close, + .reset = NULL, + { .poll = wacom_poll }, + .speed_changed = wacom_speed_changed, + .force_redraw = NULL, + .config = wacom_config +}; + +const device_t mouse_wacom_artpad_device = { + .name = "Wacom ArtPad", + .internal_name = "wacom_serial_artpad", + .flags = DEVICE_COM, + .local = (uintptr_t)&artpad_id, .init = wacom_init, .close = wacom_close, .reset = NULL, diff --git a/src/device/pci_bridge.c b/src/device/pci_bridge.c index c5ad77a4f..eb0c734aa 100644 --- a/src/device/pci_bridge.c +++ b/src/device/pci_bridge.c @@ -47,10 +47,10 @@ #define AGP_BRIDGE_VIA(x) (((x) >> 16) == 0x1106) #define AGP_BRIDGE(x) ((x) >= AGP_BRIDGE_ALI_M5243) -typedef struct -{ +typedef struct pci_bridge_t { uint32_t local; - uint8_t type, ctl; + uint8_t type; + uint8_t ctl; uint8_t regs[256]; uint8_t bus_index; @@ -352,6 +352,9 @@ pci_bridge_write(int func, int addr, uint8_t val, void *priv) return; } break; + + default: + break; } dev->regs[addr] = val; @@ -360,8 +363,8 @@ pci_bridge_write(int func, int addr, uint8_t val, void *priv) static uint8_t pci_bridge_read(int func, int addr, void *priv) { - pci_bridge_t *dev = (pci_bridge_t *) priv; - uint8_t ret; + const pci_bridge_t *dev = (pci_bridge_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; @@ -434,6 +437,9 @@ pci_bridge_reset(void *priv) dev->regs[0x06] = 0x20; dev->regs[0x07] = 0x02; break; + + default: + break; } /* class */ @@ -473,7 +479,10 @@ pci_bridge_reset(void *priv) static void * pci_bridge_init(const device_t *info) { - uint8_t interrupts[4], interrupt_count, interrupt_mask, slot_count, i; + uint8_t interrupts[4]; + uint8_t interrupt_count; + uint8_t interrupt_mask; + uint8_t slot_count; pci_bridge_t *dev = (pci_bridge_t *) malloc(sizeof(pci_bridge_t)); memset(dev, 0, sizeof(pci_bridge_t)); @@ -489,7 +498,7 @@ pci_bridge_init(const device_t *info) interrupt_count = sizeof(interrupts); interrupt_mask = interrupt_count - 1; if (dev->slot < 32) { - for (i = 0; i < interrupt_count; i++) + for (uint8_t i = 0; i < interrupt_count; i++) interrupts[i] = pci_get_int(dev->slot, PCI_INTA + i); } pci_bridge_log("PCI Bridge %d: upstream bus %02X slot %02X interrupts %02X %02X %02X %02X\n", dev->bus_index, (dev->slot >> 5) & 0xff, dev->slot & 31, interrupts[0], interrupts[1], interrupts[2], interrupts[3]); @@ -499,7 +508,7 @@ pci_bridge_init(const device_t *info) else slot_count = 1; /* AGP bridges always have 1 slot */ - for (i = 0; i < slot_count; i++) { + for (uint8_t i = 0; i < slot_count; i++) { /* Interrupts for bridge slots are assigned in round-robin: ABCD, BCDA, CDAB and so on. */ pci_bridge_log("PCI Bridge %d: downstream slot %02X interrupts %02X %02X %02X %02X\n", dev->bus_index, i, interrupts[i & interrupt_mask], interrupts[(i + 1) & interrupt_mask], interrupts[(i + 2) & interrupt_mask], interrupts[(i + 3) & interrupt_mask]); pci_register_bus_slot(dev->bus_index, i, AGP_BRIDGE(dev->local) ? PCI_CARD_AGP : PCI_CARD_NORMAL, diff --git a/src/device/phoenix_486_jumper.c b/src/device/phoenix_486_jumper.c index d5e833404..dbdfbe946 100644 --- a/src/device/phoenix_486_jumper.c +++ b/src/device/phoenix_486_jumper.c @@ -1,148 +1,150 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Implementation of the Phoenix 486 Jumper Readout - * - * - * - * Authors: Tiseno100 - * - * Copyright 2020 Tiseno100 - */ - -#include -#include -#include -#include -#include -#include -#define HAVE_STDARG_H -#include <86box/86box.h> -#include "cpu.h" -#include <86box/timer.h> -#include <86box/io.h> -#include <86box/device.h> -#include <86box/chipset.h> - -/* - Bit 7 = Super I/O chip: 1 = enabled, 0 = disabled; - Bit 6 = Graphics card: 1 = standalone, 0 = on-board; - Bit 5 = ???? (if 1, siren and hangs); - Bit 4 = ????; - Bit 3 = ????; - Bit 2 = ????; - Bit 1 = ????; - Bit 0 = ????. -*/ - -typedef struct -{ - uint8_t type, jumper; -} phoenix_486_jumper_t; - -#ifdef ENABLE_PHOENIX_486_JUMPER_LOG -int phoenix_486_jumper_do_log = ENABLE_PHOENIX_486_JUMPER_LOG; - -static void -phoenix_486_jumper_log(const char *fmt, ...) -{ - va_list ap; - - if (phoenix_486_jumper_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define phoenix_486_jumper_log(fmt, ...) -#endif - -static void -phoenix_486_jumper_write(uint16_t addr, uint8_t val, void *priv) -{ - phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; - phoenix_486_jumper_log("Phoenix 486 Jumper: Write %02x\n", val); - if (dev->type == 1) - dev->jumper = val & 0xbf; - else - dev->jumper = val; -} - -static uint8_t -phoenix_486_jumper_read(uint16_t addr, void *priv) -{ - phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; - phoenix_486_jumper_log("Phoenix 486 Jumper: Read %02x\n", dev->jumper); - return dev->jumper; -} - -static void -phoenix_486_jumper_reset(void *priv) -{ - phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; - - if (dev->type == 1) - dev->jumper = 0x00; - else { - dev->jumper = 0x9f; - if (gfxcard[0] != 0x01) - dev->jumper |= 0x40; - } -} - -static void -phoenix_486_jumper_close(void *priv) -{ - phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; - - free(dev); -} - -static void * -phoenix_486_jumper_init(const device_t *info) -{ - phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) malloc(sizeof(phoenix_486_jumper_t)); - memset(dev, 0, sizeof(phoenix_486_jumper_t)); - - dev->type = info->local; - - phoenix_486_jumper_reset(dev); - - io_sethandler(0x0078, 0x0001, phoenix_486_jumper_read, NULL, NULL, phoenix_486_jumper_write, NULL, NULL, dev); - - return dev; -} - -const device_t phoenix_486_jumper_device = { - .name = "Phoenix 486 Jumper Readout", - .internal_name = "phoenix_486_jumper", - .flags = 0, - .local = 0, - .init = phoenix_486_jumper_init, - .close = phoenix_486_jumper_close, - .reset = phoenix_486_jumper_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t phoenix_486_jumper_pci_device = { - .name = "Phoenix 486 Jumper Readout (PCI machines)", - .internal_name = "phoenix_486_jumper_pci", - .flags = 0, - .local = 1, - .init = phoenix_486_jumper_init, - .close = phoenix_486_jumper_close, - .reset = phoenix_486_jumper_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Implementation of the Phoenix 486 Jumper Readout + * + * + * + * Authors: Tiseno100 + * + * Copyright 2020 Tiseno100 + */ + +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/chipset.h> +#include <86box/plat_unused.h> + +/* + Bit 7 = Super I/O chip: 1 = enabled, 0 = disabled; + Bit 6 = Graphics card: 1 = standalone, 0 = on-board; + Bit 5 = ???? (if 1, siren and hangs); + Bit 4 = ????; + Bit 3 = ????; + Bit 2 = ????; + Bit 1 = ????; + Bit 0 = ????. +*/ + +typedef struct phoenix_486_jumper_t { + uint8_t type; + uint8_t jumper; +} phoenix_486_jumper_t; + +#ifdef ENABLE_PHOENIX_486_JUMPER_LOG +int phoenix_486_jumper_do_log = ENABLE_PHOENIX_486_JUMPER_LOG; + +static void +phoenix_486_jumper_log(const char *fmt, ...) +{ + va_list ap; + + if (phoenix_486_jumper_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define phoenix_486_jumper_log(fmt, ...) +#endif + +static void +phoenix_486_jumper_write(UNUSED(uint16_t addr), uint8_t val, void *priv) +{ + phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; + phoenix_486_jumper_log("Phoenix 486 Jumper: Write %02x\n", val); + if (dev->type == 1) + dev->jumper = val & 0xbf; + else + dev->jumper = val; +} + +static uint8_t +phoenix_486_jumper_read(UNUSED(uint16_t addr), void *priv) +{ + const phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; + + phoenix_486_jumper_log("Phoenix 486 Jumper: Read %02x\n", dev->jumper); + return dev->jumper; +} + +static void +phoenix_486_jumper_reset(void *priv) +{ + phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; + + if (dev->type == 1) + dev->jumper = 0x00; + else { + dev->jumper = 0x9f; + if (gfxcard[0] != 0x01) + dev->jumper |= 0x40; + } +} + +static void +phoenix_486_jumper_close(void *priv) +{ + phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; + + free(dev); +} + +static void * +phoenix_486_jumper_init(const device_t *info) +{ + phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) malloc(sizeof(phoenix_486_jumper_t)); + memset(dev, 0, sizeof(phoenix_486_jumper_t)); + + dev->type = info->local; + + phoenix_486_jumper_reset(dev); + + io_sethandler(0x0078, 0x0001, phoenix_486_jumper_read, NULL, NULL, phoenix_486_jumper_write, NULL, NULL, dev); + + return dev; +} + +const device_t phoenix_486_jumper_device = { + .name = "Phoenix 486 Jumper Readout", + .internal_name = "phoenix_486_jumper", + .flags = 0, + .local = 0, + .init = phoenix_486_jumper_init, + .close = phoenix_486_jumper_close, + .reset = phoenix_486_jumper_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t phoenix_486_jumper_pci_device = { + .name = "Phoenix 486 Jumper Readout (PCI machines)", + .internal_name = "phoenix_486_jumper_pci", + .flags = 0, + .local = 1, + .init = phoenix_486_jumper_init, + .close = phoenix_486_jumper_close, + .reset = phoenix_486_jumper_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/device/postcard.c b/src/device/postcard.c index f91736b1a..f5e85dafb 100644 --- a/src/device/postcard.c +++ b/src/device/postcard.c @@ -31,7 +31,8 @@ static uint16_t postcard_port; static uint8_t postcard_written; -static uint8_t postcard_code, postcard_prev_code; +static uint8_t postcard_code; +static uint8_t postcard_prev_code; #define UISTR_LEN 13 static char postcard_str[UISTR_LEN]; /* UI output string */ @@ -85,7 +86,7 @@ postcard_reset(void) } static void -postcard_write(uint16_t port, uint8_t val, void *priv) +postcard_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) { if (postcard_written && (val == postcard_code)) return; @@ -99,7 +100,7 @@ postcard_write(uint16_t port, uint8_t val, void *priv) } static void * -postcard_init(const device_t *info) +postcard_init(UNUSED(const device_t *info)) { postcard_reset(); diff --git a/src/device/serial.c b/src/device/serial.c index c0f5bdb7d..a36e4f99f 100644 --- a/src/device/serial.c +++ b/src/device/serial.c @@ -154,7 +154,9 @@ serial_receive_timer(void *priv) { serial_t *dev = (serial_t *) priv; - // serial_log("serial_receive_timer()\n"); +#if 0 + serial_log("serial_receive_timer()\n"); +#endif timer_on_auto(&dev->receive_timer, /* dev->bits * */ dev->transmit_period); @@ -174,7 +176,9 @@ serial_receive_timer(void *priv) } else { /* We can input data into the FIFO. */ dev->rcvr_fifo[dev->rcvr_fifo_end] = (uint8_t) (dev->out_new & 0xff); - // dev->rcvr_fifo_end = (dev->rcvr_fifo_end + 1) & 0x0f; +#if 0 + dev->rcvr_fifo_end = (dev->rcvr_fifo_end + 1) & 0x0f; +#endif /* Do not wrap around, makes sure it still triggers the interrupt at 16 bytes. */ dev->rcvr_fifo_end++; @@ -266,13 +270,11 @@ serial_transmit(serial_t *dev, uint8_t val) static void serial_move_to_txsr(serial_t *dev) { - int i = 0; - if (dev->fifo_enabled) { dev->txsr = dev->xmit_fifo[0]; if (dev->xmit_fifo_pos > 0) { /* Move the entire fifo forward by one byte. */ - for (i = 1; i < 16; i++) + for (uint8_t i = 1; i < 16; i++) dev->xmit_fifo[i - 1] = dev->xmit_fifo[i]; /* Decrease FIFO position. */ dev->xmit_fifo_pos--; @@ -476,7 +478,8 @@ void serial_write(uint16_t addr, uint8_t val, void *p) { serial_t *dev = (serial_t *) p; - uint8_t new_msr, old; + uint8_t new_msr; + uint8_t old; // serial_log("UART: Write %02X to port %02X\n", val, addr); serial_log("UART: [%04X:%08X] Write %02X to port %02X\n", CS, cpu_state.pc, val, addr); @@ -558,6 +561,8 @@ serial_write(uint16_t addr, uint8_t val, void *p) case 3: dev->rcvr_fifo_len = 14; break; + default: + break; } dev->out_new = 0xffff; serial_log("FIFO now %sabled, receive FIFO length = %i\n", dev->fifo_enabled ? "en" : "dis", dev->rcvr_fifo_len); @@ -625,8 +630,10 @@ serial_write(uint16_t addr, uint8_t val, void *p) serial_update_ints(dev); break; case 6: - // dev->msr = (val & 0xf0) | (dev->msr & 0x0f); - // dev->msr = val; +#if 0 + dev->msr = (val & 0xf0) | (dev->msr & 0x0f); + dev->msr = val; +#endif /* The actual condition bits of the MSR are read-only, but the delta bits are undocumentedly writable, and the PCjr BIOS uses them to raise MSR interrupts. */ dev->msr = (dev->msr & 0xf0) | (val & 0x0f); @@ -638,6 +645,8 @@ serial_write(uint16_t addr, uint8_t val, void *p) if (dev->type >= SERIAL_16450) dev->scratch = val; break; + default: + break; } } @@ -737,6 +746,8 @@ serial_read(uint16_t addr, void *p) case 7: ret = dev->scratch; break; + default: + break; } // serial_log("UART: Read %02X from port %02X\n", ret, addr); @@ -915,7 +926,7 @@ serial_set_next_inst(int ni) void serial_standalone_init(void) { - for (; next_inst < SERIAL_MAX;) + while (next_inst < SERIAL_MAX) device_add_inst(&ns8250_device, next_inst + 1); }; diff --git a/src/device/serial_passthrough.c b/src/device/serial_passthrough.c index 672bc98c3..b703cd67c 100644 --- a/src/device/serial_passthrough.c +++ b/src/device/serial_passthrough.c @@ -29,6 +29,7 @@ #include <86box/serial.h> #include <86box/serial_passthrough.h> #include <86box/plat_serial_passthrough.h> +#include <86box/plat_unused.h> #define ENABLE_SERIAL_PASSTHROUGH_LOG 1 #ifdef ENABLE_SERIAL_PASSTHROUGH_LOG @@ -52,9 +53,7 @@ serial_passthrough_log(const char *fmt, ...) void serial_passthrough_init(void) { - int c; - - for (c = 0; c < SERIAL_MAX; c++) { + for (uint8_t c = 0; c < SERIAL_MAX; c++) { if (serial_passthrough_enabled[c]) { /* Instance n for COM n */ device_add_inst(&serial_passthrough_device, c + 1); @@ -63,7 +62,7 @@ serial_passthrough_init(void) } static void -serial_passthrough_write(serial_t *s, void *priv, uint8_t val) +serial_passthrough_write(UNUSED(serial_t *s), void *priv, uint8_t val) { plat_serpt_write(priv, val); } @@ -88,44 +87,58 @@ host_to_serial_cb(void *priv) } } if (plat_serpt_read(dev, &byte)) { - // printf("got byte %02X\n", byte); +#if 0 + printf("got byte %02X\n", byte); +#endif serial_write_fifo(dev->serial, byte); - // serial_set_dsr(dev->serial, 1); +#if 0 + serial_set_dsr(dev->serial, 1); +#endif } no_write_to_machine: - // serial_device_timeout(dev->serial); +#if 0 + serial_device_timeout(dev->serial); +#endif timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / dev->baudrate) * (double) dev->bits); } static void -serial_passthrough_rcr_cb(struct serial_s *serial, void *priv) +serial_passthrough_rcr_cb(UNUSED(struct serial_s *serial), void *priv) { serial_passthrough_t *dev = (serial_passthrough_t *) priv; timer_stop(&dev->host_to_serial_timer); /* FIXME: do something to dev->baudrate */ timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / dev->baudrate) * (double) dev->bits); - // serial_clear_fifo(dev->serial); +#if 0 + serial_clear_fifo(dev->serial); +#endif } static void serial_passthrough_speed_changed(void *priv) { serial_passthrough_t *dev = (serial_passthrough_t *) priv; + if (!dev) + return; timer_stop(&dev->host_to_serial_timer); /* FIXME: do something to dev->baudrate */ timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / dev->baudrate) * (double) dev->bits); - // serial_clear_fifo(dev->serial); +#if 0 + serial_clear_fifo(dev->serial); +#endif } static void serial_passthrough_dev_close(void *priv) { serial_passthrough_t *dev = (serial_passthrough_t *) priv; + if (!dev) + return; /* Detach passthrough device from COM port */ - if (dev && dev->serial && dev->serial->sd) + if (dev->serial && dev->serial->sd) memset(dev->serial->sd, 0, sizeof(serial_device_t)); plat_serpt_close(dev); @@ -133,28 +146,28 @@ serial_passthrough_dev_close(void *priv) } void -serial_passthrough_transmit_period(serial_t *serial, void *p, double transmit_period) +serial_passthrough_transmit_period(UNUSED(serial_t *serial), void *priv, double transmit_period) { - serial_passthrough_t *dev = (serial_passthrough_t *) p; + serial_passthrough_t *dev = (serial_passthrough_t *) priv; if (dev->mode != SERPT_MODE_HOSTSER) return; - dev->baudrate = 1000000.0 / (transmit_period); + dev->baudrate = 1000000.0 / transmit_period; - serial_passthrough_speed_changed(p); + serial_passthrough_speed_changed(priv); plat_serpt_set_params(dev); } void -serial_passthrough_lcr_callback(serial_t *serial, void *p, uint8_t lcr) +serial_passthrough_lcr_callback(serial_t *serial, void *priv, uint8_t lcr) { - serial_passthrough_t *dev = (serial_passthrough_t *) p; + serial_passthrough_t *dev = (serial_passthrough_t *) priv; if (dev->mode != SERPT_MODE_HOSTSER) return; dev->bits = serial->bits; dev->data_bits = ((lcr & 0x03) + 5); - serial_passthrough_speed_changed(p); + serial_passthrough_speed_changed(priv); plat_serpt_set_params(dev); } @@ -175,6 +188,10 @@ serial_passthrough_dev_init(const device_t *info) /* Attach passthrough device to a COM port */ dev->serial = serial_attach_ex(dev->port, serial_passthrough_rcr_cb, serial_passthrough_write, serial_passthrough_transmit_period, serial_passthrough_lcr_callback, dev); + if (!dev->serial) { + free(dev); + return NULL; + } strncpy(dev->host_serial_path, device_get_config_string("host_serial_path"), 1023); #ifdef _WIN32 @@ -352,12 +369,12 @@ static const device_config_t serial_passthrough_config[] = { // clang-format on const device_t serial_passthrough_device = { - .name = "Serial Passthrough Device", - .flags = 0, - .local = 0, - .init = serial_passthrough_dev_init, - .close = serial_passthrough_dev_close, - .reset = NULL, + .name = "Serial Passthrough Device", + .flags = 0, + .local = 0, + .init = serial_passthrough_dev_init, + .close = serial_passthrough_dev_close, + .reset = NULL, { .poll = NULL }, .speed_changed = serial_passthrough_speed_changed, .force_redraw = NULL, diff --git a/src/device/smbus_ali7101.c b/src/device/smbus_ali7101.c index 2777740dd..855f0c270 100644 --- a/src/device/smbus_ali7101.c +++ b/src/device/smbus_ali7101.c @@ -28,6 +28,7 @@ #include <86box/timer.h> #include <86box/i2c.h> #include <86box/smbus.h> +#include <86box/plat_fallthrough.h> #ifdef ENABLE_SMBUS_ALI7101_LOG int smbus_ali7101_do_log = ENABLE_SMBUS_ALI7101_LOG; @@ -79,6 +80,9 @@ smbus_ali7101_read(uint16_t addr, void *priv) case 0x07: ret = dev->cmd; break; + + default: + break; } smbus_ali7101_log("SMBus ALI7101: read(%02X) = %02x\n", addr, ret); @@ -90,7 +94,10 @@ static void smbus_ali7101_write(uint16_t addr, uint8_t val, void *priv) { smbus_ali7101_t *dev = (smbus_ali7101_t *) priv; - uint8_t smbus_addr, cmd, read, prev_stat; + uint8_t smbus_addr; + uint8_t cmd; + uint8_t read; + uint8_t prev_stat; uint16_t timer_bytes = 0; smbus_ali7101_log("SMBus ALI7101: write(%02X, %02X)\n", addr, val); @@ -187,7 +194,9 @@ smbus_ali7101_write(uint16_t addr, uint8_t val, void *priv) case 0x4: /* block R/W */ timer_bytes++; /* count the SMBus length byte now */ - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: /* unknown */ dev->next_stat = 0x20; /* raise DEV_ERR */ @@ -220,6 +229,9 @@ smbus_ali7101_write(uint16_t addr, uint8_t val, void *priv) case 0x07: dev->cmd = val; break; + + default: + break; } if (dev->next_stat != 0x04) { /* schedule dispatch of any pending status register update */ diff --git a/src/device/smbus_piix4.c b/src/device/smbus_piix4.c index 07a03454f..bad49b957 100644 --- a/src/device/smbus_piix4.c +++ b/src/device/smbus_piix4.c @@ -27,6 +27,7 @@ #include <86box/timer.h> #include <86box/i2c.h> #include <86box/smbus.h> +#include <86box/plat_fallthrough.h> #ifdef ENABLE_SMBUS_PIIX4_LOG int smbus_piix4_do_log = ENABLE_SMBUS_PIIX4_LOG; @@ -83,6 +84,9 @@ smbus_piix4_read(uint16_t addr, void *priv) if (dev->index >= SMBUS_PIIX4_BLOCK_DATA_SIZE) dev->index = 0; break; + + default: + break; } smbus_piix4_log("SMBus PIIX4: read(%02X) = %02x\n", addr, ret); @@ -94,8 +98,13 @@ static void smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) { smbus_piix4_t *dev = (smbus_piix4_t *) priv; - uint8_t smbus_addr, cmd, read, block_len, prev_stat; - uint16_t timer_bytes = 0, i = 0; + uint8_t smbus_addr; + uint8_t cmd; + uint8_t read; + uint8_t block_len; + uint8_t prev_stat; + uint16_t timer_bytes = 0; + uint16_t i = 0; smbus_piix4_log("SMBus PIIX4: write(%02X, %02X)\n", addr, val); @@ -187,7 +196,9 @@ smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) timer_bytes++; } - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xc: /* I2C process call */ if (!read) { /* word write (only when writing) */ @@ -206,7 +217,9 @@ smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) case 0x5: /* block R/W */ timer_bytes++; /* count the SMBus length byte now */ - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xd: /* I2C block R/W */ i2c_write(i2c_smbus, smbus_addr, dev->cmd); @@ -239,7 +252,9 @@ smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) i2c_write(i2c_smbus, smbus_addr, dev->cmd); timer_bytes++; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xe: /* I2C with 7-bit address */ if (!read) { /* word write (only when writing) */ @@ -304,6 +319,9 @@ unknown_protocol: if (dev->index >= SMBUS_PIIX4_BLOCK_DATA_SIZE) dev->index = 0; break; + + default: + break; } if (dev->next_stat) { /* schedule dispatch of any pending status register update */ diff --git a/src/discord.c b/src/discord.c index fcc8d18c1..18faee696 100644 --- a/src/discord.c +++ b/src/discord.c @@ -135,7 +135,7 @@ int discord_load(void) { if (discord_handle != NULL) - return (1); + return 1; // Try to load the DLL discord_handle = dynld_module(PATH_DISCORD_DLL, discord_imports); @@ -144,11 +144,11 @@ discord_load(void) discord_log("discord: couldn't load " PATH_DISCORD_DLL "\n"); discord_close(); - return (0); + return 0; } discord_loaded = 1; - return (1); + return 1; } void diff --git a/src/disk/hdc.c b/src/disk/hdc.c index bae818b9a..f1ef1ecf6 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -174,12 +174,12 @@ hdc_has_config(int hdc) const device_t *dev = hdc_get_device(hdc); if (dev == NULL) - return (0); + return 0; if (!device_has_config(dev)) - return (0); + return 0; - return (1); + return 1; } int diff --git a/src/disk/hdc_esdi_at.c b/src/disk/hdc_esdi_at.c index 66c7a0231..258ea9d0f 100644 --- a/src/disk/hdc_esdi_at.c +++ b/src/disk/hdc_esdi_at.c @@ -70,7 +70,7 @@ #define CMD_SET_PARAMETERS 0x91 #define CMD_READ_PARAMETERS 0xec -typedef struct { +typedef struct drive_t { int cfg_spt; int cfg_hpc; int current_cylinder; @@ -81,10 +81,14 @@ typedef struct { int hdd_num; } drive_t; -typedef struct { +typedef struct esdi_t { uint8_t status; uint8_t error; - int secount, sector, cylinder, head, cylprecomp; + int secount; + int sector; + int cylinder; + int head; + int cylprecomp; uint8_t command; uint8_t fdisk; int pos; @@ -132,13 +136,13 @@ irq_raise(esdi_t *esdi) } static __inline void -irq_lower(esdi_t *esdi) +irq_lower(UNUSED(esdi_t *esdi)) { picintc(1 << 14); } static __inline void -irq_update(esdi_t *esdi) +irq_update(UNUSED(esdi_t *esdi)) { if (esdi->irqstat && !((pic2.irr | pic2.isr) & 0x40) && !(esdi->fdisk & 2)) picint(1 << 14); @@ -159,7 +163,7 @@ esdi_set_callback(esdi_t *esdi, double callback) } double -esdi_get_xfer_time(esdi_t *esdi, int size) +esdi_get_xfer_time(UNUSED(esdi_t *esdi), int size) { /* 390.625 us per sector at 10 Mbit/s = 1280 kB/s. */ return (3125.0 / 8.0) * (double) size; @@ -169,19 +173,22 @@ esdi_get_xfer_time(esdi_t *esdi, int size) static int get_sector(esdi_t *esdi, off64_t *addr) { - drive_t *drive = &esdi->drives[esdi->drive_sel]; - int heads = drive->cfg_hpc; - int sectors = drive->cfg_spt; - int c, h, s, sector; + const drive_t *drive = &esdi->drives[esdi->drive_sel]; + int heads = drive->cfg_hpc; + int sectors = drive->cfg_spt; + int c; + int h; + int s; + int sector; if (esdi->head > heads) { esdi_at_log("esdi_get_sector: past end of configured heads\n"); - return (1); + return 1; } if (esdi->sector >= sectors + 1) { esdi_at_log("esdi_get_sector: past end of configured sectors\n"); - return (1); + return 1; } sector = esdi->sector ? esdi->sector : 1; @@ -203,7 +210,7 @@ get_sector(esdi_t *esdi, off64_t *addr) *addr = ((((off64_t) c * drive->real_hpc) + h) * drive->real_spt) + s; } - return (0); + return 0; } /* Move to the next sector using CHS addressing. */ @@ -253,7 +260,8 @@ static void esdi_write(uint16_t port, uint8_t val, void *priv) { esdi_t *esdi = (esdi_t *) priv; - double seek_time, xfer_time; + double seek_time; + double xfer_time; off64_t addr; esdi_at_log("WD1007 write(%04x, %02x)\n", port, val); @@ -330,7 +338,9 @@ esdi_write(uint16_t port, uint8_t val, void *priv) esdi->command &= ~0x03; if (val & 0x02) fatal("Read with ECC\n"); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xa0: esdi->status = STAT_BUSY; @@ -389,7 +399,9 @@ esdi_write(uint16_t port, uint8_t val, void *priv) default: esdi_at_log("WD1007: bad command %02X\n", val); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xe8: /*???*/ esdi->status = STAT_BUSY; esdi_set_callback(esdi, 200 * HDC_TIME); @@ -413,6 +425,9 @@ esdi_write(uint16_t port, uint8_t val, void *priv) esdi->fdisk = val; irq_update(esdi); break; + + default: + break; } } @@ -452,7 +467,7 @@ esdi_readw(uint16_t port, void *priv) } } - return (temp); + return temp; } static uint8_t @@ -494,11 +509,14 @@ esdi_read(uint16_t port, void *priv) irq_lower(esdi); temp = esdi->status; break; + + default: + break; } esdi_at_log("WD1007 read(%04x) = %02x\n", port, temp); - return (temp); + return temp; } static void @@ -787,7 +805,7 @@ esdi_callback(void *priv) } static void -loadhd(esdi_t *esdi, int hdd_num, int d, const char *fn) +loadhd(esdi_t *esdi, int hdd_num, int d, UNUSED(const char *fn)) { drive_t *drive = &esdi->drives[hdd_num]; @@ -807,9 +825,9 @@ loadhd(esdi_t *esdi, int hdd_num, int d, const char *fn) } static void -esdi_rom_write(uint32_t addr, uint8_t val, void *p) +esdi_rom_write(uint32_t addr, uint8_t val, void *priv) { - rom_t *rom = (rom_t *) p; + rom_t *rom = (rom_t *) priv; addr &= rom->mask; @@ -818,15 +836,15 @@ esdi_rom_write(uint32_t addr, uint8_t val, void *p) } static void * -wd1007vse1_init(const device_t *info) +wd1007vse1_init(UNUSED(const device_t *info)) { - int c, d; + int c; esdi_t *esdi = malloc(sizeof(esdi_t)); memset(esdi, 0x00, sizeof(esdi_t)); c = 0; - for (d = 0; d < HDD_NUM; d++) { + for (uint8_t d = 0; d < HDD_NUM; d++) { if ((hdd[d].bus == HDD_BUS_ESDI) && (hdd[d].esdi_channel < ESDI_NUM)) { loadhd(esdi, hdd[d].esdi_channel, d, hdd[d].fn); @@ -858,17 +876,16 @@ wd1007vse1_init(const device_t *info) ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); - return (esdi); + return esdi; } static void wd1007vse1_close(void *priv) { - esdi_t *esdi = (esdi_t *) priv; - drive_t *drive; - int d; + esdi_t *esdi = (esdi_t *) priv; + const drive_t *drive; - for (d = 0; d < 2; d++) { + for (uint8_t d = 0; d < 2; d++) { drive = &esdi->drives[d]; hdd_image_close(drive->hdd_num); diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index f9af1e864..02f054ca2 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -62,6 +62,7 @@ */ #include +#include #include #include #include @@ -81,6 +82,7 @@ #include <86box/ui.h> #include <86box/hdc.h> #include <86box/hdd.h> +#include <86box/plat_unused.h> /* These are hardwired. */ #define ESDI_IOADDR_PRI 0x3510 @@ -94,7 +96,8 @@ #define CMD_ADAPTER 0 typedef struct esdi_drive_t { - int spt, hpc; + int spt; + int hpc; int tracks; int sectors; int present; @@ -116,8 +119,8 @@ typedef struct esdi_t { uint16_t cmd_data[4]; int cmd_dev; - int status_pos, - status_len; + int status_pos; + int status_len; uint16_t status_data[256]; @@ -137,7 +140,7 @@ typedef struct esdi_t { uint32_t rba; - struct { + struct cmds { int req_in_progress; } cmds[3]; @@ -220,7 +223,7 @@ set_irq(esdi_t *dev) } static __inline void -clear_irq(esdi_t *dev) +clear_irq(UNUSED(esdi_t *dev)) { picintc(1 << 14); } @@ -240,7 +243,7 @@ esdi_mca_set_callback(esdi_t *dev, double callback) } static double -esdi_mca_get_xfer_time(esdi_t *esdi, int size) +esdi_mca_get_xfer_time(UNUSED(esdi_t *esdi), int size) { /* 390.625 us per sector at 10 Mbit/s = 1280 kB/s. */ return (3125.0 / 8.0) * (double) size; @@ -349,10 +352,10 @@ complete_command_status(esdi_t *dev) static void esdi_callback(void *priv) { - esdi_t *dev = (esdi_t *) priv; - drive_t *drive; - int val; - double cmd_time = 0.0; + esdi_t *dev = (esdi_t *) priv; + const drive_t *drive; + int val; + double cmd_time = 0.0; esdi_mca_set_callback(dev, 0); @@ -439,6 +442,9 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); break; + + default: + break; } break; @@ -512,6 +518,9 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); break; + + default: + break; } break; @@ -545,6 +554,9 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); break; + + default: + break; } break; @@ -576,6 +588,9 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); break; + + default: + break; } break; @@ -694,7 +709,6 @@ esdi_callback(void *priv) } dev->data[dev->data_pos++] = val & 0xffff; - ; } memcpy(dev->sector_buffer[dev->sector_pos++], dev->data, 512); @@ -713,6 +727,9 @@ esdi_callback(void *priv) set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); break; + + default: + break; } break; @@ -770,6 +787,9 @@ esdi_callback(void *priv) set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); break; + + default: + break; } break; @@ -838,6 +858,9 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); break; + + default: + break; } break; @@ -867,7 +890,7 @@ esdi_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static void @@ -986,7 +1009,7 @@ esdi_readw(uint16_t port, void *priv) switch (port & 7) { case 0: /*Status Interface Register*/ if (dev->status_pos >= dev->status_len) - return (0); + return 0; ret = dev->status_data[dev->status_pos++]; if (dev->status_pos >= dev->status_len) { dev->status &= ~STATUS_STATUS_OUT_FULL; @@ -998,7 +1021,7 @@ esdi_readw(uint16_t port, void *priv) fatal("esdi_readw port=%04x\n", port); } - return (ret); + return ret; } static void @@ -1036,7 +1059,7 @@ esdi_writew(uint16_t port, uint16_t val, void *priv) static uint8_t esdi_mca_read(int port, void *priv) { - esdi_t *dev = (esdi_t *) priv; + const esdi_t *dev = (esdi_t *) priv; esdi_mca_log("ESDI: mcard(%04x)\n", port); @@ -1084,6 +1107,9 @@ esdi_mca_write(int port, uint8_t val, void *priv) case 0x10: dev->dma = 4; break; + + default: + break; } if (dev->pos_regs[2] & 1) { @@ -1106,17 +1132,18 @@ esdi_mca_write(int port, uint8_t val, void *priv) static uint8_t esdi_mca_feedb(void *priv) { - esdi_t *dev = (esdi_t *) priv; + const esdi_t *dev = (esdi_t *) priv; return (dev->pos_regs[2] & 1); } static void * -esdi_init(const device_t *info) +esdi_init(UNUSED(const device_t *info)) { drive_t *drive; esdi_t *dev; - int c, i; + uint8_t c; + uint8_t i; dev = malloc(sizeof(esdi_t)); if (dev == NULL) @@ -1177,19 +1204,18 @@ esdi_init(const device_t *info) /* Set the reply timer. */ timer_add(&dev->timer, esdi_callback, dev, 0); - return (dev); + return dev; } static void esdi_close(void *priv) { - esdi_t *dev = (esdi_t *) priv; - drive_t *drive; - int d; + esdi_t *dev = (esdi_t *) priv; + const drive_t *drive; dev->drives[0].present = dev->drives[1].present = 0; - for (d = 0; d < 2; d++) { + for (uint8_t d = 0; d < 2; d++) { drive = &dev->drives[d]; hdd_image_close(drive->hdd_num); diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index d4b44a13e..ace646328 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -18,6 +18,7 @@ * Copyright 2016-2020 Miran Grca. */ #include +#include #include #include #include @@ -109,16 +110,20 @@ #define IDE_TIME 10.0 -typedef struct { - int bit32, cur_dev, - irq, inited, - diag, force_ata3; - uint16_t base_main, side_main; +typedef struct ide_board_t { + int bit32; + int cur_dev; + int irq; + int inited; + int diag; + int force_ata3; + uint16_t base_main; + uint16_t side_main; pc_timer_t timer; ide_t *ide[2]; } ide_board_t; -typedef struct { +typedef struct ide_bm_t { int (*dma)(int channel, uint8_t *data, int transfer_length, int out, void *priv); void (*set_irq)(int channel, void *priv); void *priv; @@ -175,7 +180,8 @@ static uint8_t ide_qua_pnp_rom[] = { }; ide_t *ide_drives[IDE_NUM]; -int ide_ter_enabled = 0, ide_qua_enabled = 0; +int ide_ter_enabled = 0; +int ide_qua_enabled = 0; static void ide_atapi_callback(ide_t *ide); static void ide_callback(void *priv); @@ -238,6 +244,9 @@ ide_get_xfer_time(ide_t *ide, int size) case 0x10: period = (50.0 / 3.0); break; + + default: + break; } break; case 0x100: /* Single Word DMA */ @@ -251,6 +260,9 @@ ide_get_xfer_time(ide_t *ide, int size) case 0x04: period = (25.0 / 3.0); break; + + default: + break; } break; case 0x200: /* Multiword DMA */ @@ -264,6 +276,9 @@ ide_get_xfer_time(ide_t *ide, int size) case 0x04: period = (50.0 / 3.0); break; + + default: + break; } break; case 0x300: /* Ultra DMA */ @@ -286,8 +301,14 @@ ide_get_xfer_time(ide_t *ide, int size) case 0x20: period = 100.0; break; + + default: + break; } break; + + default: + break; } period = (1.0 / period); /* get us for 1 byte */ @@ -388,9 +409,9 @@ ide_irq_update(ide_t *ide) void ide_padstr(char *str, const char *src, int len) { - int i, v; + int v; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { if (*src != '\0') v = *src++; else @@ -411,9 +432,7 @@ ide_padstr(char *str, const char *src, int len) void ide_padstr8(uint8_t *buf, int buf_size, const char *src) { - int i; - - for (i = 0; i < buf_size; i++) { + for (int i = 0; i < buf_size; i++) { if (*src != '\0') buf[i] = *src++; else @@ -487,7 +506,9 @@ ide_hd_identify(ide_t *ide) { char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; - uint32_t d_hpc, d_spt, d_tracks; + uint32_t d_hpc; + uint32_t d_spt; + uint32_t d_tracks; uint64_t full_size = (((uint64_t) hdd[ide->hdd_num].tracks) * hdd[ide->hdd_num].hpc * hdd[ide->hdd_num].spt); device_identify[6] = (ide->hdd_num / 10) + 0x30; @@ -576,8 +597,13 @@ ide_hd_identify(ide_t *ide) static void ide_identify(ide_t *ide) { - int d, i, max_pio, max_sdma, max_mdma, max_udma; - ide_t *ide_other = ide_drives[ide->channel ^ 1]; + int d; + int i; + int max_pio; + int max_sdma; + int max_mdma; + int max_udma; + const ide_t *ide_other = ide_drives[ide->channel ^ 1]; ide_log("IDE IDENTIFY or IDENTIFY PACKET DEVICE on board %i (channel %i)\n", ide->board, ide->channel); @@ -673,7 +699,8 @@ ide_identify(ide_t *ide) static off64_t ide_get_sector(ide_t *ide) { - uint32_t heads, sectors; + uint32_t heads; + uint32_t sectors; if (ide->lba) return (off64_t) ide->lba_addr; @@ -709,7 +736,7 @@ ide_next_sector(ide_t *ide) } static void -loadhd(ide_t *ide, int d, const char *fn) +loadhd(ide_t *ide, int d, UNUSED(const char *fn)) { if (!hdd_image_load(d)) { ide->type = IDE_NONE; @@ -738,7 +765,9 @@ ide_set_signature(ide_t *ide) ide->cylinder = ide->sc->request_length; } else { ide->secount = 1; - // ide->cylinder = ((ide->type == IDE_HDD) ? 0 : 0xFFFF); +#if 0 + ide->cylinder = ((ide->type == IDE_HDD) ? 0 : 0xFFFF); +#endif ide->cylinder = ((ide->type == IDE_HDD) ? 0 : 0x7F7F); if (ide->type == IDE_HDD) ide->drive = 0; @@ -748,8 +777,11 @@ ide_set_signature(ide_t *ide) static int ide_set_features(ide_t *ide) { - uint8_t features, features_data; - int mode, submode, max; + uint8_t features; + uint8_t features_data; + int mode; + int submode; + int max; features = ide->cylprecomp; features_data = ide->secount; @@ -835,11 +867,12 @@ ide_set_features(ide_t *ide) void ide_set_sector(ide_t *ide, int64_t sector_num) { - unsigned int cyl, r; + unsigned int cyl; + unsigned int r; if (ide->lba) { ide->head = (sector_num >> 24); ide->cylinder = (sector_num >> 8); - ide->sector = (sector_num); + ide->sector = sector_num; } else { cyl = sector_num / (hdd[ide->hdd_num].hpc * hdd[ide->hdd_num].spt); r = sector_num % (hdd[ide->hdd_num].hpc * hdd[ide->hdd_num].spt); @@ -941,7 +974,8 @@ ide_atapi_command_bus(ide_t *ide) static void ide_atapi_callback(ide_t *ide) { - int out, ret = 0; + int out; + int ret = 0; switch (ide->sc->packet_status) { case PHASE_IDLE: @@ -1080,8 +1114,8 @@ ide_atapi_packet_read(ide_t *ide, int length) { scsi_common_t *dev = ide->sc; - uint16_t *bufferw; - uint32_t *bufferl; + const uint16_t *bufferw; + const uint32_t *bufferl; uint32_t temp = 0; @@ -1277,7 +1311,7 @@ ide_writew(uint16_t addr, uint16_t val, void *priv) static void ide_writel(uint16_t addr, uint32_t val, void *priv) { - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -1321,11 +1355,12 @@ dev_reset(ide_t *ide) } void -ide_write_devctl(uint16_t addr, uint8_t val, void *priv) +ide_write_devctl(UNUSED(uint16_t addr), uint8_t val, void *priv) { ide_board_t *dev = (ide_board_t *) priv; - ide_t *ide, *ide_other; + ide_t *ide; + ide_t *ide_other; int ch; uint8_t old; @@ -1427,7 +1462,8 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) { ide_board_t *dev = (ide_board_t *) priv; - ide_t *ide, *ide_other; + ide_t *ide; + ide_t *ide_other; int ch; ch = dev->cur_dev; @@ -1454,9 +1490,15 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) } ide->cylprecomp = val; +/* The ATA-3 specification says this register is the parameter for the + command and is unclear as to whether or not it's written to both + devices at once. Writing it to both devices at once breaks CD boot + on the AMI Apollo. */ +#ifdef WRITE_PARAM_TO_BOTH_DEVICES if (ide_other->type == IDE_ATAPI) ide_other->sc->features = val; ide_other->cylprecomp = val; +#endif return; case 0x2: /* Sector count */ @@ -1613,7 +1655,9 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) disabled, the Read Multiple operation is rejected with an Aborted Com- mand error. */ ide->blockcount = 0; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case WIN_READ: case WIN_READ_NORETRY: @@ -1662,7 +1706,9 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) /* Turn on the activity indicator *here* so that it gets turned on less times. */ ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case WIN_WRITE: case WIN_WRITE_NORETRY: @@ -1801,6 +1847,9 @@ ide_bad_command: return; } return; + + default: + break; } } @@ -1822,9 +1871,9 @@ ide_read_data(ide_t *ide, int length) } } - uint8_t *idebufferb = (uint8_t *) ide->buffer; - uint16_t *idebufferw = ide->buffer; - uint32_t *idebufferl = (uint32_t *) ide->buffer; + const uint8_t *idebufferb = (uint8_t *) ide->buffer; + const uint16_t *idebufferw = ide->buffer; + const uint32_t *idebufferl = (uint32_t *) ide->buffer; if (ide->command == WIN_PACKETCMD) { ide->pos = 0; @@ -1904,9 +1953,10 @@ ide_status(ide_t *ide, ide_t *ide_other, int ch) uint8_t ide_readb(uint16_t addr, void *priv) { - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; - int ch, absent = 0; + int ch; + int absent = 0; ide_t *ide; ch = dev->cur_dev; @@ -2019,6 +2069,9 @@ ide_readb(uint16_t addr, void *priv) ide_irq_lower(ide); temp = ide_status(ide, ide_drives[ch ^ 1], ch); break; + + default: + break; } ide_log("ide_readb(%04X, %08X) = %02X\n", addr, priv, temp); @@ -2026,11 +2079,11 @@ ide_readb(uint16_t addr, void *priv) } uint8_t -ide_read_alt_status(uint16_t addr, void *priv) +ide_read_alt_status(UNUSED(uint16_t addr), void *priv) { uint8_t temp = 0xff; - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -2051,7 +2104,7 @@ ide_readw(uint16_t addr, void *priv) { uint16_t temp = 0xffff; - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -2081,7 +2134,7 @@ ide_readl(uint16_t addr, void *priv) uint16_t temp2; uint32_t temp = 0xffffffff; - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -2163,7 +2216,8 @@ atapi_error_no_ready(ide_t *ide) static void ide_callback(void *priv) { - int snum, ret = 0; + int snum; + int ret = 0; ide_t *ide = (ide_t *) priv; @@ -2547,6 +2601,9 @@ ide_callback(void *priv) case 0xFF: goto abort_cmd; + + default: + break; } abort_cmd: @@ -2573,9 +2630,11 @@ id_not_found: uint8_t ide_read_ali_75(void) { - ide_t *ide0, *ide1; - int ch0, ch1; - uint8_t ret = 0x00; + const ide_t *ide0; + const ide_t *ide1; + int ch0; + int ch1; + uint8_t ret = 0x00; ch0 = ide_boards[0]->cur_dev; ch1 = ide_boards[1]->cur_dev; @@ -2597,9 +2656,11 @@ ide_read_ali_75(void) uint8_t ide_read_ali_76(void) { - ide_t *ide0, *ide1; - int ch0, ch1; - uint8_t ret = 0x00; + const ide_t *ide0; + const ide_t *ide1; + int ch0; + int ch1; + uint8_t ret = 0x00; ch0 = ide_boards[0]->cur_dev; ch1 = ide_boards[1]->cur_dev; @@ -2736,7 +2797,7 @@ static void ide_board_close(int board) { ide_t *dev; - int c, d; + int c; ide_log("ide_board_close(%i)\n", board); @@ -2750,7 +2811,7 @@ ide_board_close(int board) ide_clear_bus_master(board); /* Close hard disk image files (if previously open) */ - for (d = 0; d < 2; d++) { + for (uint8_t d = 0; d < 2; d++) { c = (board << 1) + d; ide_boards[board]->ide[d] = NULL; @@ -2790,9 +2851,13 @@ static void ide_board_setup(int board) { ide_t *dev; - int c, d; - int ch, is_ide, valid_ch; - int min_ch, max_ch; + int c; + int d; + int ch; + int is_ide; + int valid_ch; + int min_ch; + int max_ch; min_ch = (board << 1); max_ch = min_ch + 1; @@ -2926,7 +2991,7 @@ ide_ter_init(const device_t *info) /* Close a standalone IDE unit. */ static void -ide_ter_close(void *priv) +ide_ter_close(UNUSED(void *priv)) { ide_board_close(2); } @@ -2957,7 +3022,7 @@ ide_qua_init(const device_t *info) /* Close a standalone IDE unit. */ static void -ide_qua_close(void *priv) +ide_qua_close(UNUSED(void *priv)) { ide_board_close(3); } @@ -3006,9 +3071,12 @@ ide_init(const device_t *info) if (info->local & 1) ide_board_init(1, 15, 0x170, 0x376, info->local); break; + + default: + break; } - return (ide_drives); + return ide_drives; } static void @@ -3040,7 +3108,8 @@ ide_drive_reset(int d) static void ide_board_reset(int board) { - int d, min, max; + int min; + int max; ide_log("Resetting IDE board %i...\n", board); @@ -3049,13 +3118,13 @@ ide_board_reset(int board) min = (board << 1); max = min + 2; - for (d = min; d < max; d++) + for (int d = min; d < max; d++) ide_drive_reset(d); } /* Reset a standalone IDE unit. */ static void -ide_reset(void *p) +ide_reset(UNUSED(void *priv)) { ide_log("Resetting IDE...\n"); @@ -3068,7 +3137,7 @@ ide_reset(void *p) /* Close a standalone IDE unit. */ static void -ide_close(void *priv) +ide_close(UNUSED(void *priv)) { ide_log("Closing IDE...\n"); diff --git a/src/disk/hdc_ide_cmd640.c b/src/disk/hdc_ide_cmd640.c index 1dd92e79e..6cb54aea5 100644 --- a/src/disk/hdc_ide_cmd640.c +++ b/src/disk/hdc_ide_cmd640.c @@ -37,14 +37,17 @@ #include <86box/zip.h> #include <86box/mo.h> -typedef struct -{ - uint8_t vlb_idx, id, - in_cfg, single_channel, - pci, regs[256]; +typedef struct cmd640_t { + uint8_t vlb_idx; + uint8_t id; + uint8_t in_cfg; + uint8_t channels; + uint8_t pci, regs[256]; uint32_t local; - int slot, irq_mode[2], - irq_pin, irq_line; + int slot; + int irq_mode[2]; + int irq_pin; + int irq_line; } cmd640_t; static int next_id = 0; @@ -86,6 +89,10 @@ cmd640_set_irq(int channel, void *priv) } channel &= 0x01; + + if (!(dev->channels & (1 << channel))) + return; + if (irq) { if (dev->irq_mode[channel] == 1) pci_set_irq(dev->slot, dev->irq_pin); @@ -102,42 +109,44 @@ cmd640_set_irq(int channel, void *priv) static void cmd640_ide_handlers(cmd640_t *dev) { - uint16_t main, side; + uint16_t main; + uint16_t side; - ide_pri_disable(); + if (dev->channels & 0x01) { + ide_pri_disable(); - if ((dev->regs[0x09] & 0x01) && (dev->regs[0x50] & 0x40)) { - main = (dev->regs[0x11] << 8) | (dev->regs[0x10] & 0xf8); - side = ((dev->regs[0x15] << 8) | (dev->regs[0x14] & 0xfc)) + 2; - } else { - main = 0x1f0; - side = 0x3f6; + if ((dev->regs[0x09] & 0x01) && (dev->regs[0x50] & 0x40)) { + main = (dev->regs[0x11] << 8) | (dev->regs[0x10] & 0xf8); + side = ((dev->regs[0x15] << 8) | (dev->regs[0x14] & 0xfc)) + 2; + } else { + main = 0x1f0; + side = 0x3f6; + } + + ide_set_base(0, main); + ide_set_side(0, side); + + if (dev->regs[0x04] & 0x01) + ide_pri_enable(); } - ide_set_base(0, main); - ide_set_side(0, side); + if (dev->channels & 0x02) { + ide_sec_disable(); - if (dev->regs[0x04] & 0x01) - ide_pri_enable(); + if ((dev->regs[0x09] & 0x04) && (dev->regs[0x50] & 0x40)) { + main = (dev->regs[0x19] << 8) | (dev->regs[0x18] & 0xf8); + side = ((dev->regs[0x1d] << 8) | (dev->regs[0x1c] & 0xfc)) + 2; + } else { + main = 0x170; + side = 0x376; + } - if (dev->single_channel) - return; + ide_set_base(1, main); + ide_set_side(1, side); - ide_sec_disable(); - - if ((dev->regs[0x09] & 0x04) && (dev->regs[0x50] & 0x40)) { - main = (dev->regs[0x19] << 8) | (dev->regs[0x18] & 0xf8); - side = ((dev->regs[0x1d] << 8) | (dev->regs[0x1c] & 0xfc)) + 2; - } else { - main = 0x170; - side = 0x376; + if ((dev->regs[0x04] & 0x01) && (dev->regs[0x51] & 0x08)) + ide_sec_enable(); } - - ide_set_base(1, main); - ide_set_side(1, side); - - if ((dev->regs[0x04] & 0x01) && (dev->regs[0x51] & 0x08)) - ide_sec_enable(); } static void @@ -165,6 +174,9 @@ cmd640_common_write(int addr, uint8_t val, cmd640_t *dev) case 0x5b: /* Undocumented register that Linux attempts to use! */ dev->regs[addr] = val; break; + + default: + break; } } @@ -187,6 +199,9 @@ cmd640_vlb_write(uint16_t addr, uint8_t val, void *priv) if (dev->regs[0x50] & 0x80) dev->in_cfg = 0; break; + + default: + break; } } @@ -226,6 +241,9 @@ cmd640_vlb_read(uint16_t addr, void *priv) if (dev->regs[0x50] & 0x80) dev->in_cfg = 0; break; + + default: + break; } return ret; @@ -355,22 +373,49 @@ cmd640_reset(void *priv) { cmd640_t *dev = (cmd640_t *) priv; int i = 0; + int min_channel; + int max_channel; + + switch (dev->channels) { + default: + case 0x00: + min_channel = max_channel = 0; + break; + case 0x01: + min_channel = 0; + max_channel = 1; + break; + case 0x02: + min_channel = 2; + max_channel = 3; + break; + case 0x03: + min_channel = 0; + max_channel = 3; + break; + } for (i = 0; i < CDROM_NUM; i++) { - if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && (cdrom[i].ide_channel < 4) && cdrom[i].priv) + if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && (cdrom[i].ide_channel >= min_channel) && + (cdrom[i].ide_channel <= max_channel) && cdrom[i].priv) scsi_cdrom_reset((scsi_common_t *) cdrom[i].priv); } for (i = 0; i < ZIP_NUM; i++) { - if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel < 4) && zip_drives[i].priv) + if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel >= min_channel) && + (zip_drives[i].ide_channel <= max_channel) && zip_drives[i].priv) zip_reset((scsi_common_t *) zip_drives[i].priv); } for (i = 0; i < MO_NUM; i++) { - if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel < 4) && mo_drives[i].priv) + if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel >= min_channel) && + (mo_drives[i].ide_channel <= max_channel) && mo_drives[i].priv) mo_reset((scsi_common_t *) mo_drives[i].priv); } - cmd640_set_irq(0x00, priv); - cmd640_set_irq(0x01, priv); + if (dev->channels & 0x01) + cmd640_set_irq(0x00, priv); + + if (dev->channels & 0x02) + cmd640_set_irq(0x01, priv); memset(dev->regs, 0x00, sizeof(dev->regs)); @@ -416,6 +461,8 @@ cmd640_reset(void *priv) dev->irq_pin = PCI_INTA; dev->irq_line = 14; } else { + dev->regs[0x04] = 0x01; /* To make sure the two channels get enabled. */ + if ((dev->local & 0xffff) == 0x0078) dev->regs[0x50] |= 0x20; /* 0 = 178h, 17Ch; 1 = 078h, 07Ch */ @@ -448,20 +495,30 @@ cmd640_init(const device_t *info) dev->pci = !!(info->flags & DEVICE_PCI); dev->local = info->local; + dev->channels = ((info->local & 0x60000) >> 17) & 0x03; + if (info->flags & DEVICE_PCI) { device_add(&ide_pci_2ch_device); dev->slot = pci_add_card(PCI_ADD_IDE, cmd640_pci_read, cmd640_pci_write, dev); - ide_set_bus_master(0, NULL, cmd640_set_irq, dev); - ide_set_bus_master(1, NULL, cmd640_set_irq, dev); + if (dev->channels & 0x01) + ide_set_bus_master(0, NULL, cmd640_set_irq, dev); + + if (dev->channels & 0x02) + ide_set_bus_master(1, NULL, cmd640_set_irq, dev); /* The CMD PCI-0640B IDE controller has no DMA capability, so set our devices IDE devices to force ATA-3 (no DMA). */ - ide_board_set_force_ata3(0, 1); - ide_board_set_force_ata3(1, 1); + if (dev->channels & 0x01) + ide_board_set_force_ata3(0, 1); - // ide_pri_disable(); + if (dev->channels & 0x02) + ide_board_set_force_ata3(1, 1); + +#if 0 + ide_pri_disable(); +#endif } else if (info->flags & DEVICE_VLB) { device_add(&ide_vlb_2ch_device); @@ -471,8 +528,6 @@ cmd640_init(const device_t *info) dev); } - dev->single_channel = !!(info->local & 0x20000); - next_id++; cmd640_reset(dev); @@ -484,7 +539,7 @@ const device_t ide_cmd640_vlb_device = { .name = "CMD PCI-0640B VLB", .internal_name = "ide_cmd640_vlb", .flags = DEVICE_VLB, - .local = 0x0078, + .local = 0x60078, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -498,7 +553,63 @@ const device_t ide_cmd640_vlb_178_device = { .name = "CMD PCI-0640B VLB (Port 178h)", .internal_name = "ide_cmd640_vlb_178", .flags = DEVICE_VLB, - .local = 0x0178, + .local = 0x60178, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_pri_device = { + .name = "CMD PCI-0640B VLB", + .internal_name = "ide_cmd640_vlb", + .flags = DEVICE_VLB, + .local = 0x20078, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_pri_178_device = { + .name = "CMD PCI-0640B VLB (Port 178h)", + .internal_name = "ide_cmd640_vlb_178", + .flags = DEVICE_VLB, + .local = 0x20178, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_sec_device = { + .name = "CMD PCI-0640B VLB", + .internal_name = "ide_cmd640_vlb", + .flags = DEVICE_VLB, + .local = 0x40078, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_sec_178_device = { + .name = "CMD PCI-0640B VLB (Port 178h)", + .internal_name = "ide_cmd640_vlb_178", + .flags = DEVICE_VLB, + .local = 0x40178, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -512,7 +623,7 @@ const device_t ide_cmd640_pci_device = { .name = "CMD PCI-0640B PCI", .internal_name = "ide_cmd640_pci", .flags = DEVICE_PCI, - .local = 0x0a, + .local = 0x6000a, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -526,7 +637,7 @@ const device_t ide_cmd640_pci_legacy_only_device = { .name = "CMD PCI-0640B PCI (Legacy Mode Only)", .internal_name = "ide_cmd640_pci_legacy_only", .flags = DEVICE_PCI, - .local = 0x00, + .local = 0x60000, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -549,3 +660,17 @@ const device_t ide_cmd640_pci_single_channel_device = { .force_redraw = NULL, .config = NULL }; + +const device_t ide_cmd640_pci_single_channel_sec_device = { + .name = "CMD PCI-0640B PCI", + .internal_name = "ide_cmd640_pci_single_channel_sec", + .flags = DEVICE_PCI, + .local = 0x4000a, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/disk/hdc_ide_cmd646.c b/src/disk/hdc_ide_cmd646.c index df992b41b..1f727bf6b 100644 --- a/src/disk/hdc_ide_cmd646.c +++ b/src/disk/hdc_ide_cmd646.c @@ -37,13 +37,15 @@ #include <86box/zip.h> #include <86box/mo.h> -typedef struct -{ - uint8_t vlb_idx, single_channel, - in_cfg, regs[256]; - uint32_t local; - int slot, irq_mode[2], - irq_pin; +typedef struct cmd646_t { + uint8_t vlb_idx; + uint8_t single_channel; + uint8_t in_cfg; + uint8_t regs[256]; + uint32_t local; + int slot; + int irq_mode[2]; + int irq_pin; sff8038i_t *bm[2]; } cmd646_t; @@ -88,7 +90,7 @@ cmd646_set_irq(int channel, void *priv) static int cmd646_bus_master_dma(int channel, uint8_t *data, int transfer_length, int out, void *priv) { - cmd646_t *dev = (cmd646_t *) priv; + const cmd646_t *dev = (cmd646_t *) priv; return sff_bus_master_dma(channel, data, transfer_length, out, dev->bm[channel & 0x01]); } @@ -96,7 +98,8 @@ cmd646_bus_master_dma(int channel, uint8_t *data, int transfer_length, int out, static void cmd646_ide_handlers(cmd646_t *dev) { - uint16_t main, side; + uint16_t main; + uint16_t side; int irq_mode[2] = { 0, 0 }; ide_pri_disable(); @@ -261,6 +264,9 @@ cmd646_pci_write(int func, int addr, uint8_t val, void *priv) case 0x78 ... 0x7f: sff_bus_master_write(addr & 0x0f, val, dev->bm[1]); break; + + default: + break; } } diff --git a/src/disk/hdc_ide_opti611.c b/src/disk/hdc_ide_opti611.c index 06eecb68f..480331201 100644 --- a/src/disk/hdc_ide_opti611.c +++ b/src/disk/hdc_ide_opti611.c @@ -28,12 +28,14 @@ #include <86box/mem.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> +#include <86box/plat_unused.h> -typedef struct -{ - uint8_t tries, - in_cfg, cfg_locked, - regs[19]; +typedef struct opti611_t { + uint8_t is_sec; + uint8_t tries; + uint8_t in_cfg; + uint8_t cfg_locked; + uint8_t regs[19]; } opti611_t; static void opti611_ide_handler(opti611_t *dev); @@ -68,6 +70,9 @@ opti611_cfg_write(uint16_t addr, uint8_t val, void *priv) case 0x0006: dev->regs[0x06] = val; break; + + default: + break; } } @@ -88,8 +93,8 @@ opti611_cfg_writel(uint16_t addr, uint32_t val, void *priv) static uint8_t opti611_cfg_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - opti611_t *dev = (opti611_t *) priv; + uint8_t ret = 0xff; + const opti611_t *dev = (opti611_t *) priv; addr &= 0x0007; @@ -109,6 +114,9 @@ opti611_cfg_read(uint16_t addr, void *priv) case 0x0006: ret = dev->regs[addr]; break; + + default: + break; } return ret; @@ -153,7 +161,7 @@ opti611_ide_write(uint16_t addr, uint8_t val, void *priv) } static void -opti611_ide_writew(uint16_t addr, uint16_t val, void *priv) +opti611_ide_writew(uint16_t addr, UNUSED(uint16_t val), void *priv) { opti611_t *dev = (opti611_t *) priv; @@ -169,7 +177,7 @@ opti611_ide_writew(uint16_t addr, uint16_t val, void *priv) } static void -opti611_ide_writel(uint16_t addr, uint32_t val, void *priv) +opti611_ide_writel(uint16_t addr, UNUSED(uint32_t val), void *priv) { opti611_t *dev = (opti611_t *) priv; @@ -247,28 +255,54 @@ opti611_ide_readl(uint16_t addr, void *priv) static void opti611_ide_handler(opti611_t *dev) { - ide_pri_disable(); - io_removehandler(0x01f0, 0x0007, - opti611_ide_read, opti611_ide_readw, opti611_ide_readl, - opti611_ide_write, opti611_ide_writew, opti611_ide_writel, - dev); - io_removehandler(0x01f0, 0x0007, - opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, - opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, - dev); + if (dev->is_sec) { + ide_sec_disable(); + io_removehandler(0x0170, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + io_removehandler(0x0170, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); - if (dev->in_cfg && !dev->cfg_locked) { - io_sethandler(0x01f0, 0x0007, - opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, - opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, - dev); + if (dev->in_cfg && !dev->cfg_locked) { + io_sethandler(0x0170, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + } else { + if (dev->regs[0x03] & 0x01) + ide_sec_enable(); + io_sethandler(0x0170, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + } } else { - if (dev->regs[0x03] & 0x01) - ide_pri_enable(); - io_sethandler(0x01f0, 0x0007, - opti611_ide_read, opti611_ide_readw, opti611_ide_readl, - opti611_ide_write, opti611_ide_writew, opti611_ide_writel, - dev); + ide_pri_disable(); + io_removehandler(0x01f0, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + io_removehandler(0x01f0, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + + if (dev->in_cfg && !dev->cfg_locked) { + io_sethandler(0x01f0, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + } else { + if (dev->regs[0x03] & 0x01) + ide_pri_enable(); + io_sethandler(0x01f0, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + } } } @@ -281,11 +315,13 @@ opti611_close(void *priv) } static void * -opti611_init(const device_t *info) +opti611_init(UNUSED(const device_t *info)) { opti611_t *dev = (opti611_t *) malloc(sizeof(opti611_t)); memset(dev, 0, sizeof(opti611_t)); + dev->is_sec = info->local; + dev->regs[0x12] = 0x80; dev->regs[0x03] = 0x01; dev->regs[0x05] = 0x20; @@ -310,3 +346,17 @@ const device_t ide_opti611_vlb_device = { .force_redraw = NULL, .config = NULL }; + +const device_t ide_opti611_vlb_sec_device = { + .name = "OPTi 82C611/82C611A VLB (Secondary)", + .internal_name = "ide_opti611_vlb", + .flags = DEVICE_VLB, + .local = 1, + .init = opti611_init, + .close = opti611_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/disk/hdc_ide_sff8038i.c b/src/disk/hdc_ide_sff8038i.c index b5c75a756..5e8e4e987 100644 --- a/src/disk/hdc_ide_sff8038i.c +++ b/src/disk/hdc_ide_sff8038i.c @@ -42,6 +42,7 @@ #include <86box/hdc_ide_sff8038i.h> #include <86box/zip.h> #include <86box/mo.h> +#include <86box/plat_unused.h> static int next_id = 0; @@ -160,6 +161,9 @@ sff_bus_master_write(uint16_t port, uint8_t val, void *priv) dev->ptr = (dev->ptr & 0x00fffffc) | (val << 24); dev->ptr %= (mem_size * 1024); break; + + default: + break; } } @@ -185,6 +189,9 @@ sff_bus_master_writew(uint16_t port, uint16_t val, void *priv) dev->ptr = (dev->ptr & 0x0000fffc) | (val << 16); dev->ptr %= (mem_size * 1024); break; + + default: + break; } } @@ -206,13 +213,16 @@ sff_bus_master_writel(uint16_t port, uint32_t val, void *priv) dev->ptr %= (mem_size * 1024); dev->ptr0 = val & 0xff; break; + + default: + break; } } uint8_t sff_bus_master_read(uint16_t port, void *priv) { - sff8038i_t *dev = (sff8038i_t *) priv; + const sff8038i_t *dev = (sff8038i_t *) priv; uint8_t ret = 0xff; @@ -238,6 +248,9 @@ sff_bus_master_read(uint16_t port, void *priv) case 7: ret = dev->ptr >> 24; break; + + default: + break; } sff_log("SFF-8038i Bus master BYTE read : %04X %02X\n", port, ret); @@ -248,7 +261,7 @@ sff_bus_master_read(uint16_t port, void *priv) static uint16_t sff_bus_master_readw(uint16_t port, void *priv) { - sff8038i_t *dev = (sff8038i_t *) priv; + const sff8038i_t *dev = (sff8038i_t *) priv; uint16_t ret = 0xffff; @@ -264,6 +277,9 @@ sff_bus_master_readw(uint16_t port, void *priv) case 6: ret = dev->ptr >> 16; break; + + default: + break; } sff_log("SFF-8038i Bus master WORD read : %04X %04X\n", port, ret); @@ -274,7 +290,7 @@ sff_bus_master_readw(uint16_t port, void *priv) static uint32_t sff_bus_master_readl(uint16_t port, void *priv) { - sff8038i_t *dev = (sff8038i_t *) priv; + const sff8038i_t *dev = (sff8038i_t *) priv; uint32_t ret = 0xffffffff; @@ -287,6 +303,9 @@ sff_bus_master_readl(uint16_t port, void *priv) case 4: ret = dev->ptr0 | (dev->ptr & 0xffffff00); break; + + default: + break; } sff_log("sff Bus master DWORD read : %04X %08X\n", port, ret); @@ -295,14 +314,15 @@ sff_bus_master_readl(uint16_t port, void *priv) } int -sff_bus_master_dma(int channel, uint8_t *data, int transfer_length, int out, void *priv) +sff_bus_master_dma(UNUSED(int channel), uint8_t *data, int transfer_length, int out, void *priv) { sff8038i_t *dev = (sff8038i_t *) priv; #ifdef ENABLE_SFF_LOG char *sop; #endif - int force_end = 0, buffer_pos = 0; + int force_end = 0; + int buffer_pos = 0; #ifdef ENABLE_SFF_LOG sop = out ? "Read" : "Writ"; @@ -378,8 +398,8 @@ sff_bus_master_set_irq(int channel, void *priv) channel &= 0x01; switch (dev->irq_mode[channel]) { - case 0: default: + case 0: /* Legacy IRQ mode. */ if (irq) picint(1 << (14 + channel)); @@ -442,29 +462,27 @@ sff_bus_master_reset(sff8038i_t *dev, uint16_t old_base) } static void -sff_reset(void *p) +sff_reset(void *priv) { - int i = 0; - #ifdef ENABLE_SFF_LOG sff_log("SFF8038i: Reset\n"); #endif - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && (cdrom[i].ide_channel < 4) && cdrom[i].priv) scsi_cdrom_reset((scsi_common_t *) cdrom[i].priv); } - for (i = 0; i < ZIP_NUM; i++) { + for (uint8_t i = 0; i < ZIP_NUM; i++) { if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel < 4) && zip_drives[i].priv) zip_reset((scsi_common_t *) zip_drives[i].priv); } - for (i = 0; i < MO_NUM; i++) { + for (uint8_t i = 0; i < MO_NUM; i++) { if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel < 4) && mo_drives[i].priv) mo_reset((scsi_common_t *) mo_drives[i].priv); } - sff_bus_master_set_irq(0x00, p); - sff_bus_master_set_irq(0x01, p); + sff_bus_master_set_irq(0x00, priv); + sff_bus_master_set_irq(0x01, priv); } void @@ -480,7 +498,7 @@ sff_set_irq_line(sff8038i_t *dev, int irq_line) } void -sff_set_irq_level(sff8038i_t *dev, int channel, int irq_level) +sff_set_irq_level(sff8038i_t *dev, int channel, UNUSED(int irq_level)) { dev->irq_level[channel] = 0; } @@ -491,8 +509,8 @@ sff_set_irq_mode(sff8038i_t *dev, int channel, int irq_mode) dev->irq_mode[channel] = irq_mode; switch (dev->irq_mode[channel]) { - case 0: default: + case 0: /* Legacy IRQ mode. */ sff_log("[%08X] Setting channel %i to legacy IRQ %i\n", dev, channel, 14 + channel); break; @@ -523,9 +541,9 @@ sff_set_irq_pin(sff8038i_t *dev, int irq_pin) } static void -sff_close(void *p) +sff_close(void *priv) { - sff8038i_t *dev = (sff8038i_t *) p; + sff8038i_t *dev = (sff8038i_t *) priv; free(dev); @@ -534,9 +552,8 @@ sff_close(void *p) next_id = 0; } -static void - * - sff_init(const device_t *info) +static void * +sff_init(UNUSED(const device_t *info)) { sff8038i_t *dev = (sff8038i_t *) malloc(sizeof(sff8038i_t)); memset(dev, 0, sizeof(sff8038i_t)); diff --git a/src/disk/hdc_st506_at.c b/src/disk/hdc_st506_at.c index 2eee8d294..41499591d 100644 --- a/src/disk/hdc_st506_at.c +++ b/src/disk/hdc_st506_at.c @@ -74,36 +74,36 @@ #define CMD_DIAGNOSE 0x90 #define CMD_SET_PARAMETERS 0x91 -typedef struct { - int8_t present, /* drive is present */ - hdd_num, /* drive number in system */ - steprate, /* current servo step rate */ - spt, /* physical #sectors per track */ - hpc, /* physical #heads per cylinder */ - pad; - int16_t tracks; /* physical #tracks per cylinder */ +typedef struct drive_t { + int8_t present; /* drive is present */ + int8_t hdd_num; /* drive number in system */ + int8_t steprate; /* current servo step rate */ + int8_t spt; /* physical #sectors per track */ + int8_t hpc; /* physical #heads per cylinder */ + int8_t pad; + int16_t tracks; /* physical #tracks per cylinder */ - int8_t cfg_spt, /* configured #sectors per track */ - cfg_hpc; /* configured #heads per track */ + int8_t cfg_spt; /* configured #sectors per track */ + int8_t cfg_hpc; /* configured #heads per track */ - int16_t curcyl; /* current track number */ + int16_t curcyl; /* current track number */ } drive_t; -typedef struct { - uint8_t precomp, /* 1: precomp/error register */ - error, - secount, /* 2: sector count register */ - sector, /* 3: sector number */ - head, /* 6: head number + drive select */ - command, /* 7: command/status */ - status, - fdisk; /* 8: control register */ +typedef struct mfm_t { + uint8_t precomp; /* 1: precomp/error register */ + uint8_t error; + uint8_t secount; /* 2: sector count register */ + uint8_t sector; /* 3: sector number */ + uint8_t head; /* 6: head number + drive select */ + uint8_t command; /* 7: command/status */ + uint8_t status; + uint8_t fdisk; /* 8: control register */ uint16_t cylinder; /* 4/5: cylinder LOW and HIGH */ - int8_t reset, /* controller in reset */ - irqstat, /* current IRQ status */ - drvsel, /* current selected drive */ - pad; + int8_t reset; /* controller in reset */ + int8_t irqstat; /* current IRQ status */ + int8_t drvsel; /* current selected drive */ + int8_t pad; int pos; /* offset within data buffer */ pc_timer_t callback_timer; /* callback delay timer */ @@ -144,7 +144,7 @@ irq_raise(mfm_t *mfm) } static inline void -irq_lower(mfm_t *mfm) +irq_lower(UNUSED(mfm_t *mfm)) { picintc(1 << 14); } @@ -171,41 +171,41 @@ irq_update(mfm_t *mfm) static int get_sector(mfm_t *mfm, off64_t *addr) { - drive_t *drive = &mfm->drives[mfm->drvsel]; + const drive_t *drive = &mfm->drives[mfm->drvsel]; /* FIXME: See if this is even needed - if the code is present, IBM AT diagnostics v2.07 will error with: ERROR 152 - SYSTEM BOARD. */ if (drive->curcyl != mfm->cylinder) { st506_at_log("WD1003(%d) sector: wrong cylinder\n"); - return (1); + return 1; } if (mfm->head > drive->cfg_hpc) { st506_at_log("WD1003(%d) get_sector: past end of configured heads\n", mfm->drvsel); - return (1); + return 1; } if (mfm->sector >= drive->cfg_spt + 1) { st506_at_log("WD1003(%d) get_sector: past end of configured sectors\n", mfm->drvsel); - return (1); + return 1; } /* We should check this in the SET_DRIVE_PARAMETERS command! --FvK */ if (mfm->head > drive->hpc) { st506_at_log("WD1003(%d) get_sector: past end of heads\n", mfm->drvsel); - return (1); + return 1; } if (mfm->sector >= drive->spt + 1) { st506_at_log("WD1003(%d) get_sector: past end of sectors\n", mfm->drvsel); - return (1); + return 1; } *addr = ((((off64_t) mfm->cylinder * drive->cfg_hpc) + mfm->head) * drive->cfg_spt) + (mfm->sector - 1); - return (0); + return 0; } /* Move to the next sector using CHS addressing. */ @@ -435,6 +435,9 @@ mfm_write(uint16_t port, uint8_t val, void *priv) mfm->fdisk = val; irq_update(mfm); break; + + default: + break; } } @@ -468,7 +471,7 @@ mfm_readw(uint16_t port, void *priv) } } - return (ret); + return ret; } static uint8_t @@ -517,7 +520,7 @@ mfm_read(uint16_t port, void *priv) st506_at_log("WD1003 read(%04x) = %02x\n", port, ret); - return (ret); + return ret; } static void @@ -668,7 +671,7 @@ do_callback(void *priv) } static void -loadhd(mfm_t *mfm, int c, int d, const char *fn) +loadhd(mfm_t *mfm, int c, int d, UNUSED(const char *fn)) { drive_t *drive = &mfm->drives[c]; @@ -686,17 +689,17 @@ loadhd(mfm_t *mfm, int c, int d, const char *fn) } static void * -mfm_init(const device_t *info) +mfm_init(UNUSED(const device_t *info)) { mfm_t *mfm; - int c, d; + int c; st506_at_log("WD1003: ISA MFM/RLL Fixed Disk Adapter initializing ...\n"); mfm = malloc(sizeof(mfm_t)); memset(mfm, 0x00, sizeof(mfm_t)); c = 0; - for (d = 0; d < HDD_NUM; d++) { + for (uint8_t d = 0; d < HDD_NUM; d++) { if ((hdd[d].bus == HDD_BUS_MFM) && (hdd[d].mfm_channel < MFM_NUM)) { loadhd(mfm, hdd[d].mfm_channel, d, hdd[d].fn); @@ -722,17 +725,16 @@ mfm_init(const device_t *info) ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); - return (mfm); + return mfm; } static void mfm_close(void *priv) { mfm_t *mfm = (mfm_t *) priv; - int d; - for (d = 0; d < 2; d++) { - drive_t *drive = &mfm->drives[d]; + for (uint8_t d = 0; d < 2; d++) { + const drive_t *drive = &mfm->drives[d]; hdd_image_close(drive->hdd_num); } diff --git a/src/disk/hdc_st506_xt.c b/src/disk/hdc_st506_xt.c index e42516c3f..766d70145 100644 --- a/src/disk/hdc_st506_xt.c +++ b/src/disk/hdc_st506_xt.c @@ -229,7 +229,7 @@ enum { STATE_DONE }; -typedef struct { +typedef struct drive_t { int8_t present; uint8_t hdd_num; @@ -238,30 +238,33 @@ typedef struct { uint16_t cylinder; /* current cylinder */ - uint8_t spt, /* physical parameters */ - hpc; + uint8_t spt; /* physical parameters */ + uint8_t hpc; uint16_t tracks; - uint8_t cfg_spt, /* configured parameters */ - cfg_hpc; + uint8_t cfg_spt; /* configured parameters */ + uint8_t cfg_hpc; uint16_t cfg_cyl; } drive_t; -typedef struct { +typedef struct hdc_t { uint8_t type; /* controller type */ uint8_t spt; /* sectors-per-track for controller */ uint16_t base; /* controller configuration */ - int8_t irq, - dma; + int8_t irq; + int8_t dma; uint8_t switches; uint8_t misc; - uint8_t nr_err, err_bv, cur_sec, pad; - uint32_t bios_addr, - bios_size, - bios_ram; - rom_t bios_rom; + uint8_t nr_err; + uint8_t err_bv; + uint8_t cur_sec; + uint8_t pad; + uint32_t bios_addr; + uint32_t bios_size; + uint32_t bios_ram; + rom_t bios_rom; int state; /* operational data */ uint8_t irq_dma; @@ -272,14 +275,14 @@ typedef struct { uint8_t command[6]; /* current command request */ int drive_sel; - int sector, - head, - cylinder, - count; + int sector; + int head; + int cylinder; + int count; uint8_t compl ; /* current request completion code */ - int buff_pos, /* pointers to the RAM buffer */ - buff_cnt; + int buff_pos; /* pointers to the RAM buffer */ + int buff_cnt; drive_t drives[MFM_NUM]; /* the attached drives */ uint8_t scratch[64]; /* ST-11 scratchpad RAM */ @@ -287,7 +290,7 @@ typedef struct { } hdc_t; /* Supported drives table for the Xebec controller. */ -typedef struct { +typedef struct hd_type_t { uint16_t tracks; uint8_t hpc; uint8_t spt; @@ -369,7 +372,7 @@ get_sector(hdc_t *dev, drive_t *drive, off64_t *addr) if (!drive->present) { /* No need to log this. */ dev->error = dev->nr_err; - return (0); + return 0; } #if 0 @@ -387,19 +390,19 @@ get_sector(hdc_t *dev, drive_t *drive, off64_t *addr) st506_xt_log("ST506: get_sector: past end of configured heads\n"); #endif dev->error = ERR_ILLEGAL_ADDR; - return (0); + return 0; } if (dev->sector >= drive->cfg_spt) { #ifdef ENABLE_ST506_XT_LOG st506_xt_log("ST506: get_sector: past end of configured sectors\n"); #endif dev->error = ERR_ILLEGAL_ADDR; - return (0); + return 0; } *addr = ((((off64_t) dev->cylinder * drive->cfg_hpc) + dev->head) * drive->cfg_spt) + dev->sector; - return (1); + return 1; } static void @@ -446,12 +449,12 @@ get_chs(hdc_t *dev, drive_t *drive) * result in an ERR_ILLEGAL_ADDR. --FvK */ drive->cylinder = drive->cfg_cyl - 1; - return (0); + return 0; } drive->cylinder = dev->cylinder; - return (1); + return 1; } static void @@ -505,6 +508,9 @@ st506_callback(void *priv) case STATE_DONE: st506_complete(dev); break; + + default: + break; } break; @@ -531,6 +537,9 @@ st506_callback(void *priv) case STATE_SENT_DATA: st506_complete(dev); break; + + default: + break; } break; @@ -567,6 +576,9 @@ st506_callback(void *priv) ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); st506_complete(dev); break; + + default: + break; } break; @@ -599,6 +611,9 @@ st506_callback(void *priv) timer_advance_u64(&dev->timer, ST506_TIME); break; + + default: + break; } break; @@ -608,6 +623,10 @@ st506_callback(void *priv) st506_complete(dev); break; } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case CMD_FORMAT_TRACK: case CMD_FORMAT_BAD_TRACK: switch (dev->state) { @@ -642,6 +661,9 @@ st506_callback(void *priv) ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); st506_complete(dev); break; + + default: + break; } break; @@ -734,6 +756,9 @@ st506_callback(void *priv) } dev->state = STATE_SEND_DATA; break; + + default: + break; } break; @@ -829,6 +854,9 @@ st506_callback(void *priv) } dev->state = STATE_RECEIVE_DATA; break; + + default: + break; } break; @@ -884,6 +912,9 @@ st506_callback(void *priv) } st506_complete(dev); break; + + default: + break; } break; @@ -903,6 +934,9 @@ st506_callback(void *priv) case STATE_SENT_DATA: st506_complete(dev); break; + + default: + break; } break; @@ -943,6 +977,9 @@ st506_callback(void *priv) case STATE_SENT_DATA: st506_complete(dev); break; + + default: + break; } break; @@ -984,6 +1021,9 @@ st506_callback(void *priv) case STATE_RECEIVED_DATA: st506_complete(dev); break; + + default: + break; } break; @@ -1005,6 +1045,9 @@ st506_callback(void *priv) case STATE_SENT_DATA: st506_complete(dev); break; + + default: + break; } else { st506_error(dev, ERR_BAD_COMMAND); @@ -1117,6 +1160,9 @@ st506_callback(void *priv) case STATE_SENT_DATA: st506_complete(dev); break; + + default: + break; } break; @@ -1136,6 +1182,9 @@ st506_callback(void *priv) /* FIXME: ignore the results. */ st506_complete(dev); break; + + default: + break; } break; @@ -1158,6 +1207,9 @@ st506_callback(void *priv) case STATE_SENT_DATA: st506_complete(dev); break; + + default: + break; } break; @@ -1202,6 +1254,9 @@ st506_read(uint16_t port, void *priv) timer_set_delay_u64(&dev->timer, ST506_TIME); } break; + + default: + break; } break; @@ -1214,10 +1269,13 @@ st506_read(uint16_t port, void *priv) case 2: /* read option jumpers */ ret = dev->switches; break; + + default: + break; } st506_xt_log("ST506: read(%04x) = %02x\n", port, ret); - return (ret); + return ret; } /* Write to one of the registers. */ @@ -1254,6 +1312,9 @@ st506_write(uint16_t port, uint8_t val, void *priv) timer_set_delay_u64(&dev->timer, ST506_TIME); } break; + + default: + break; } break; @@ -1279,6 +1340,9 @@ st506_write(uint16_t port, uint8_t val, void *priv) picintc(1 << dev->irq); } break; + + default: + break; } } @@ -1287,7 +1351,8 @@ static void mem_write(uint32_t addr, uint8_t val, void *priv) { hdc_t *dev = (hdc_t *) priv; - uint32_t ptr, mask = 0; + uint32_t ptr; + uint32_t mask = 0; /* Ignore accesses to anything below the configured address, needed because of the emulator's 4k mapping granularity. */ @@ -1316,9 +1381,10 @@ mem_write(uint32_t addr, uint8_t val, void *priv) static uint8_t mem_read(uint32_t addr, void *priv) { - hdc_t *dev = (hdc_t *) priv; - uint32_t ptr, mask = 0; - uint8_t ret = 0xff; + const hdc_t *dev = (hdc_t *) priv; + uint32_t ptr; + uint32_t mask = 0; + uint8_t ret = 0xff; /* Ignore accesses to anything below the configured address, needed because of the emulator's 4k mapping granularity. */ @@ -1360,9 +1426,10 @@ mem_read(uint32_t addr, void *priv) case ST506_XT_TYPE_ST11R: /* ST-11R */ mask = 0x1fff; /* ST-11 decodes RAM on each 8K block */ break; - - /* default: - break; */ +#if 0 + default: + break; +#endif } addr = addr & dev->bios_rom.mask; @@ -1373,7 +1440,7 @@ mem_read(uint32_t addr, void *priv) else ret = dev->bios_rom.rom[addr]; - return (ret); + return ret; } /* @@ -1427,7 +1494,7 @@ loadrom(hdc_t *dev, const char *fn) } static void -loadhd(hdc_t *dev, int c, int d, const char *fn) +loadhd(hdc_t *dev, int c, int d, UNUSED(const char *fn)) { drive_t *drive = &dev->drives[c]; @@ -1466,13 +1533,12 @@ loadhd(hdc_t *dev, int c, int d, const char *fn) static void set_switches(hdc_t *dev, hd_type_t *hdt, int num) { - drive_t *drive; - int c, d; - int e; + const drive_t *drive; + int e; dev->switches = 0x00; - for (d = 0; d < MFM_NUM; d++) { + for (uint8_t d = 0; d < MFM_NUM; d++) { drive = &dev->drives[d]; if (!drive->present) { @@ -1481,7 +1547,7 @@ set_switches(hdc_t *dev, hd_type_t *hdt, int num) continue; } - for (c = 0; c < num; c++) { + for (int c = 0; c < num; c++) { /* Does the Xebec also support more than 4 types? */ if ((drive->spt == hdt[c].spt) && (drive->hpc == hdt[c].hpc) && (drive->tracks == hdt[c].tracks)) { /* Olivetti M24/M240: Move the upper 2 bites up by 2 bits, as the @@ -1511,7 +1577,8 @@ st506_init(const device_t *info) { char *fn = NULL; hdc_t *dev; - int i, c; + int i; + int c; dev = (hdc_t *) malloc(sizeof(hdc_t)); memset(dev, 0x00, sizeof(hdc_t)); @@ -1541,7 +1608,9 @@ st506_init(const device_t *info) case ST506_XT_TYPE_ST11R: /* Seagate ST-11R (RLL) */ dev->spt = RLL_SECTORS; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case ST506_XT_TYPE_ST11M: /* Seagate ST-11M (MFM) */ dev->nr_err = ERR_NOT_AVAILABLE; @@ -1555,6 +1624,9 @@ st506_init(const device_t *info) case 19: /* v2.0 */ fn = ST11_BIOS_FILE_NEW; break; + + default: + break; } dev->base = device_get_config_hex16("base"); dev->irq = device_get_config_int("irq"); @@ -1659,6 +1731,9 @@ st506_init(const device_t *info) dev->base = 0x01f0; dev->switches = 0x0c; break; + + default: + break; } /* Load the ROM BIOS. */ @@ -1703,17 +1778,16 @@ st506_init(const device_t *info) dev->drives[c].cfg_spt = dev->drives[c].spt; } - return (dev); + return dev; } static void st506_close(void *priv) { - hdc_t *dev = (hdc_t *) priv; - drive_t *drive; - int d; + hdc_t *dev = (hdc_t *) priv; + const drive_t *drive; - for (d = 0; d < MFM_NUM; d++) { + for (uint8_t d = 0; d < MFM_NUM; d++) { drive = &dev->drives[d]; hdd_image_close(drive->hdd_num); diff --git a/src/disk/hdc_xta.c b/src/disk/hdc_xta.c index 0ac095929..b27648eca 100644 --- a/src/disk/hdc_xta.c +++ b/src/disk/hdc_xta.c @@ -182,15 +182,15 @@ enum { /* The device control block (6 bytes) */ #pragma pack(push, 1) -typedef struct { +typedef struct dcb_t { uint8_t cmd; /* [7:5] class, [4:0] opcode */ - uint8_t head : 5, /* [4:0] head number */ - drvsel : 1, /* [5] drive select */ - mbz : 2; /* [7:6] 00 */ + uint8_t head : 5; /* [4:0] head number */ + uint8_t drvsel : 1; /* [5] drive select */ + uint8_t mbz : 2; /* [7:6] 00 */ - uint8_t sector : 6, /* [5:0] sector number 0-63 */ - cyl_high : 2; /* [7:6] cylinder [9:8] bits */ + uint8_t sector : 6; /* [5:0] sector number 0-63 */ + uint8_t cyl_high : 2; /* [7:6] cylinder [9:8] bits */ uint8_t cyl_low; /* [7:0] cylinder [7:0] bits */ @@ -202,7 +202,7 @@ typedef struct { /* The (configured) Drive Parameters. */ #pragma pack(push, 1) -typedef struct { +typedef struct dprm_t { uint8_t cyl_high; /* (MSB) number of cylinders */ uint8_t cyl_low; /* (LSB) number of cylinders */ uint8_t heads; /* number of heads per cylinder */ @@ -215,24 +215,24 @@ typedef struct { #pragma pack(pop) /* Define an attached drive. */ -typedef struct { - int8_t id, /* drive ID on bus */ - present, /* drive is present */ - hdd_num, /* index to global disk table */ - type; /* drive type ID */ +typedef struct drive_t { + int8_t id; /* drive ID on bus */ + int8_t present; /* drive is present */ + int8_t hdd_num; /* index to global disk table */ + int8_t type; /* drive type ID */ uint16_t cur_cyl; /* last known position of heads */ - uint8_t spt, /* active drive parameters */ - hpc; + uint8_t spt; /* active drive parameters */ + uint8_t hpc; uint16_t tracks; - uint8_t cfg_spt, /* configured drive parameters */ - cfg_hpc; + uint8_t cfg_spt; /* configured drive parameters */ + uint8_t cfg_hpc; uint16_t cfg_tracks; } drive_t; -typedef struct { +typedef struct hdc_t { const char *name; /* controller name */ uint16_t base; /* controller base I/O address */ @@ -252,17 +252,17 @@ typedef struct { pc_timer_t timer; /* Data transfer. */ - int16_t buf_idx, /* buffer index and pointer */ - buf_len; + int16_t buf_idx; /* buffer index and pointer */ + int16_t buf_len; uint8_t *buf_ptr; /* Current operation parameters. */ - dcb_t dcb; /* device control block */ - uint16_t track; /* requested track# */ - uint8_t head, /* requested head# */ - sector, /* requested sector# */ - comp; /* operation completion byte */ - int count; /* requested sector count */ + dcb_t dcb; /* device control block */ + uint16_t track; /* requested track# */ + uint8_t head; /* requested head# */ + uint8_t sector; /* requested sector# */ + uint8_t comp; /* operation completion byte */ + int count; /* requested sector count */ drive_t drives[XTA_NUM]; /* the attached drive(s) */ @@ -308,25 +308,25 @@ get_sector(hdc_t *dev, drive_t *drive, off64_t *addr) xta_log("%s: get_sector: wrong cylinder %d/%d\n", dev->name, drive->cur_cyl, dev->track); dev->sense = ERR_ILLADDR; - return (1); + return 1; } if (dev->head >= drive->hpc) { xta_log("%s: get_sector: past end of heads\n", dev->name); dev->sense = ERR_ILLADDR; - return (1); + return 1; } if (dev->sector >= drive->spt) { xta_log("%s: get_sector: past end of sectors\n", dev->name); dev->sense = ERR_ILLADDR; - return (1); + return 1; } /* Calculate logical address (block number) of desired sector. */ *addr = ((((off64_t) dev->track * drive->hpc) + dev->head) * drive->spt) + dev->sector; - return (0); + return 0; } static void @@ -375,10 +375,11 @@ do_seek(hdc_t *dev, drive_t *drive, int cyl) static void do_format(hdc_t *dev, drive_t *drive, dcb_t *dcb) { - int start_cyl, end_cyl; - int start_hd, end_hd; + int start_cyl; + int end_cyl; + int start_hd; + int end_hd; off64_t addr; - int h, s; /* Get the parameters from the DCB. */ if (dcb->cmd == CMD_FORMAT_DRIVE) { @@ -413,8 +414,8 @@ do_fmt: * data to fill the sectors with, so we will use * that at least. */ - for (h = start_hd; h < end_hd; h++) { - for (s = 0; s < drive->spt; s++) { + for (int h = start_hd; h < end_hd; h++) { + for (uint8_t s = 0; s < drive->spt; s++) { /* Set the sector we need to write. */ dev->head = h; dev->sector = s; @@ -435,6 +436,9 @@ do_fmt: /* This saves us a LOT of code. */ goto do_fmt; + + default: + break; } /* De-activate the status icon. */ @@ -496,12 +500,18 @@ hdc_callback(void *priv) case STATE_SDONE: set_intr(dev); + break; + + default: + break; } break; case CMD_READ_VERIFY: no_data = 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case CMD_READ_SECTORS: if (!drive->present) { @@ -526,7 +536,9 @@ hdc_callback(void *priv) dev->buf_len = 512; dev->state = STATE_SEND; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_SEND: /* Activate the status icon. */ @@ -605,6 +617,9 @@ do_send: /* This saves us a LOT of code. */ dev->state = STATE_SEND; goto do_send; + + default: + break; } break; @@ -631,7 +646,9 @@ do_send: dev->buf_len = 512; dev->state = STATE_RECV; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_RECV: /* Activate the status icon. */ @@ -709,6 +726,9 @@ do_recv: /* This saves us a LOT of code. */ dev->state = STATE_RECV; goto do_recv; + + default: + break; } break; @@ -757,6 +777,9 @@ do_recv: dev->status &= ~STAT_REQ; set_intr(dev); break; + + default: + break; } break; @@ -801,6 +824,9 @@ do_recv: dev->data, dev->buf_len); set_intr(dev); break; + + default: + break; } break; @@ -814,6 +840,9 @@ do_recv: case STATE_RDONE: set_intr(dev); break; + + default: + break; } break; @@ -833,6 +862,9 @@ do_recv: case STATE_RDONE: set_intr(dev); break; + + default: + break; } break; @@ -846,6 +878,9 @@ do_recv: case STATE_RDONE: set_intr(dev); break; + + default: + break; } break; @@ -899,9 +934,12 @@ hdc_read(uint16_t port, void *priv) case 2: /* "read option jumpers" */ ret = 0xff; /* all switches off */ break; + + default: + break; } - return (ret); + return ret; } /* Write to one of the controller registers. */ @@ -957,9 +995,14 @@ hdc_write(uint16_t port, uint8_t val, void *priv) break; case 3: /* DMA/IRQ intr register */ - // xta_log("%s: WriteMASK(%02X)\n", dev->name, val); +#if 0 + xta_log("%s: WriteMASK(%02X)\n", dev->name, val); +#endif dev->intr = val; break; + + default: + break; } } @@ -970,7 +1013,7 @@ xta_init(const device_t *info) char *bios_rev = NULL; char *fn = NULL; hdc_t *dev; - int c, i; + int c; int max = XTA_NUM; /* Allocate and initialize device block. */ @@ -997,17 +1040,21 @@ xta_init(const device_t *info) dev->irq = 5; dev->dma = 3; break; + + default: + break; } xta_log("%s: initializing (I/O=%04X, IRQ=%d, DMA=%d", dev->name, dev->base, dev->irq, dev->dma); if (dev->rom_addr != 0x000000) xta_log(", BIOS=%06X", dev->rom_addr); + xta_log(")\n"); /* Load any disks for this device class. */ c = 0; - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if ((hdd[i].bus == HDD_BUS_XTA) && (hdd[i].xta_channel < max)) { drive = &dev->drives[hdd[i].xta_channel]; @@ -1051,22 +1098,21 @@ xta_init(const device_t *info) /* Create a timer for command delays. */ timer_add(&dev->timer, hdc_callback, dev, 0); - return (dev); + return dev; } static void xta_close(void *priv) { - hdc_t *dev = (hdc_t *) priv; - drive_t *drive; - int d; + hdc_t *dev = (hdc_t *) priv; + const drive_t *drive; /* Remove the I/O handler. */ io_removehandler(dev->base, 4, hdc_read, NULL, NULL, hdc_write, NULL, NULL, dev); /* Close all disks and their images. */ - for (d = 0; d < XTA_NUM; d++) { + for (uint8_t d = 0; d < XTA_NUM; d++) { drive = &dev->drives[d]; hdd_image_close(drive->hdd_num); diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index 72ad580ae..91bf5a2e3 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -43,6 +43,7 @@ #include <86box/device.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> +#include <86box/plat_unused.h> #define ROM_PATH_XT "roms/hdd/xtide/ide_xt.bin" #define ROM_PATH_XTP "roms/hdd/xtide/ide_xtp.bin" @@ -51,7 +52,7 @@ #define ROM_PATH_PS2AT "roms/hdd/xtide/ide_at_1_1_5.bin" #define ROM_PATH_AT_386 "roms/hdd/xtide/ide_386.bin" -typedef struct { +typedef struct xtide_t { void *ide_board; uint8_t data_high; rom_t bios_rom; @@ -84,6 +85,9 @@ xtide_write(uint16_t port, uint8_t val, void *priv) case 0xe: ide_write_devctl(0x0, val, xtide->ide_board); return; + + default: + break; } } @@ -145,7 +149,7 @@ xtide_init(const device_t *info) xtide_read, NULL, NULL, xtide_write, NULL, NULL, xtide); - return (xtide); + return xtide; } static int @@ -177,7 +181,7 @@ xtide_at_init(const device_t *info) device_add(&ide_isa_2ch_device); - return (xtide); + return xtide; } static int @@ -193,7 +197,7 @@ xtide_at_386_available(void) } static void * -xtide_acculogic_init(const device_t *info) +xtide_acculogic_init(UNUSED(const device_t *info)) { xtide_t *xtide = malloc(sizeof(xtide_t)); @@ -208,7 +212,7 @@ xtide_acculogic_init(const device_t *info) xtide_read, NULL, NULL, xtide_write, NULL, NULL, xtide); - return (xtide); + return xtide; } static int @@ -228,7 +232,7 @@ xtide_close(void *priv) } static void * -xtide_at_ps2_init(const device_t *info) +xtide_at_ps2_init(UNUSED(const device_t *info)) { xtide_t *xtide = malloc(sizeof(xtide_t)); @@ -239,7 +243,7 @@ xtide_at_ps2_init(const device_t *info) device_add(&ide_isa_2ch_device); - return (xtide); + return xtide; } static int diff --git a/src/disk/hdd.c b/src/disk/hdd.c index 61a355b44..685eec9d0 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -41,23 +41,23 @@ hdd_init(void) /* Clear all global data. */ memset(hdd, 0x00, sizeof(hdd)); - return (0); + return 0; } int hdd_string_to_bus(char *str, int cdrom) { if (!strcmp(str, "none")) - return (HDD_BUS_DISABLED); + return HDD_BUS_DISABLED; if (!strcmp(str, "mfm") || !strcmp(str, "rll")) { if (cdrom) { no_cdrom: ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2131, (wchar_t *) IDS_4099); - return (0); + return 0; } - return (HDD_BUS_MFM); + return HDD_BUS_MFM; } /* FIXME: delete 'rll' in a year or so.. --FvK */ @@ -65,50 +65,50 @@ no_cdrom: if (cdrom) goto no_cdrom; - return (HDD_BUS_ESDI); + return HDD_BUS_ESDI; } if (!strcmp(str, "ide_pio_only")) - return (HDD_BUS_IDE); + return HDD_BUS_IDE; if (!strcmp(str, "ide")) - return (HDD_BUS_IDE); + return HDD_BUS_IDE; if (!strcmp(str, "atapi_pio_only")) - return (HDD_BUS_ATAPI); + return HDD_BUS_ATAPI; if (!strcmp(str, "atapi")) - return (HDD_BUS_ATAPI); + return HDD_BUS_ATAPI; if (!strcmp(str, "eide")) - return (HDD_BUS_IDE); + return HDD_BUS_IDE; if (!strcmp(str, "xta")) - return (HDD_BUS_XTA); + return HDD_BUS_XTA; if (!strcmp(str, "atide")) - return (HDD_BUS_IDE); + return HDD_BUS_IDE; if (!strcmp(str, "ide_pio_and_dma")) - return (HDD_BUS_IDE); + return HDD_BUS_IDE; if (!strcmp(str, "atapi_pio_and_dma")) - return (HDD_BUS_ATAPI); + return HDD_BUS_ATAPI; if (!strcmp(str, "scsi")) - return (HDD_BUS_SCSI); + return HDD_BUS_SCSI; - return (0); + return 0; } char * -hdd_bus_to_string(int bus, int cdrom) +hdd_bus_to_string(int bus, UNUSED(int cdrom)) { char *s = "none"; switch (bus) { - case HDD_BUS_DISABLED: default: + case HDD_BUS_DISABLED: break; case HDD_BUS_MFM: @@ -136,22 +136,22 @@ hdd_bus_to_string(int bus, int cdrom) break; } - return (s); + return s; } int hdd_is_valid(int c) { if (hdd[c].bus == HDD_BUS_DISABLED) - return (0); + return 0; if (strlen(hdd[c].fn) == 0) - return (0); + return 0; if ((hdd[c].tracks == 0) || (hdd[c].hpc == 0) || (hdd[c].spt == 0)) - return (0); + return 0; - return (1); + return 1; } double @@ -160,8 +160,12 @@ hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_ if (!hdd->speed_preset) return HDD_OVERHEAD_TIME; - hdd_zone_t *zone = NULL; - for (int i = 0; i < hdd->num_zones; i++) { + const hdd_zone_t *zone = NULL; + if (hdd->num_zones <= 0) { + fatal("hdd_seek_get_time(): hdd->num_zones < 0)\n"); + return 0.0; + } + for (uint32_t i = 0; i < hdd->num_zones; i++) { zone = &hdd->zones[i]; if (zone->end_sector >= dst_addr) break; @@ -204,8 +208,9 @@ static void hdd_readahead_update(hard_disk_t *hdd) { uint64_t elapsed_cycles; - double elapsed_us, seek_time; - uint32_t max_read_ahead, i; + double elapsed_us; + double seek_time; + uint32_t max_read_ahead; uint32_t space_needed; hdd_cache_t *cache = &hdd->cache; @@ -219,7 +224,7 @@ hdd_readahead_update(hard_disk_t *hdd) seek_time = 0.0; - for (i = 0; i < max_read_ahead; i++) { + for (uint32_t i = 0; i < max_read_ahead; i++) { seek_time += hdd_seek_get_time(hdd, segment->ra_addr, HDD_OP_READ, 1, elapsed_us - seek_time); if (seek_time > elapsed_us) break; @@ -252,7 +257,8 @@ static void hdd_writecache_update(hard_disk_t *hdd) { uint64_t elapsed_cycles; - double elapsed_us, seek_time; + double elapsed_us; + double seek_time; if (hdd->cache.write_pending) { elapsed_cycles = tsc - hdd->cache.write_start_time; @@ -383,13 +389,12 @@ static void hdd_cache_init(hard_disk_t *hdd) { hdd_cache_t *cache = &hdd->cache; - uint32_t i; cache->ra_segment = 0; cache->ra_ongoing = 0; cache->ra_start_time = 0; - for (i = 0; i < cache->num_segments; i++) { + for (uint32_t i = 0; i < cache->num_segments; i++) { cache->segments[i].valid = 0; cache->segments[i].lru = 0; cache->segments[i].id = i; @@ -401,12 +406,13 @@ hdd_cache_init(hard_disk_t *hdd) static void hdd_zones_init(hard_disk_t *hdd) { - uint32_t lba = 0, track = 0; - uint32_t i, tracks; + uint32_t lba = 0; + uint32_t track = 0; + uint32_t tracks; double revolution_usec = 60.0 / (double) hdd->rpm * 1000000.0; hdd_zone_t *zone; - for (i = 0; i < hdd->num_zones; i++) { + for (uint32_t i = 0; i < hdd->num_zones; i++) { zone = &hdd->zones[i]; zone->start_sector = lba; zone->start_track = track; @@ -467,15 +473,20 @@ void hdd_preset_apply(int hdd_id) { hard_disk_t *hd = &hdd[hdd_id]; - double revolution_usec, zone_percent; - uint32_t disk_sectors, sectors_per_surface, cylinders, cylinders_per_zone; - uint32_t total_sectors = 0, i; - uint32_t spt, zone_sectors; + double revolution_usec; + double zone_percent; + uint32_t disk_sectors; + uint32_t sectors_per_surface; + uint32_t cylinders; + uint32_t cylinders_per_zone; + uint32_t total_sectors = 0; + uint32_t spt; + uint32_t zone_sectors; if (hd->speed_preset >= hdd_preset_get_num()) hd->speed_preset = 0; - hdd_preset_t *preset = &hdd_speed_presets[hd->speed_preset]; + const hdd_preset_t *preset = &hdd_speed_presets[hd->speed_preset]; hd->cache.num_segments = preset->rcache_num_seg; hd->cache.segment_size = preset->rcache_seg_size; @@ -503,7 +514,7 @@ hdd_preset_apply(int hdd_id) hd->phy_cyl = cylinders; cylinders_per_zone = cylinders / preset->zones; - for (i = 0; i < preset->zones; i++) { + for (uint32_t i = 0; i < preset->zones; i++) { zone_percent = i * 100 / (double) preset->zones; if (i < preset->zones - 1) { diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index ba7cf18ba..a9b013205 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -18,6 +18,7 @@ */ #define _GNU_SOURCE #include +#include #include #include #include @@ -32,19 +33,19 @@ #include <86box/random.h> #include <86box/hdd.h> #include "minivhd/minivhd.h" -#include "minivhd/minivhd_internal.h" +#include "minivhd/internal.h" #define HDD_IMAGE_RAW 0 #define HDD_IMAGE_HDI 1 #define HDD_IMAGE_HDX 2 #define HDD_IMAGE_VHD 3 -typedef struct -{ +typedef struct hdd_image_t { FILE *file; /* Used for HDD_IMAGE_RAW, HDD_IMAGE_HDI, and HDD_IMAGE_HDX. */ MVHDMeta *vhd; /* Used for HDD_IMAGE_VHD. */ uint32_t base; - uint32_t pos, last_sector; + uint32_t pos; + uint32_t last_sector; uint8_t type; /* HDD_IMAGE_RAW, HDD_IMAGE_HDI, HDD_IMAGE_HDX, or HDD_IMAGE_VHD */ uint8_t loaded; } hdd_image_t; @@ -106,7 +107,7 @@ image_is_hdx(const char *s, int check_signature) if (fread(&signature, 1, 8, f) != 8) fatal("image_is_hdx(): Error reading signature\n"); fclose(f); - if (signature == 0xD778A82044445459ll) + if (signature == 0xD778A82044445459LL) return 1; else return 0; @@ -142,7 +143,11 @@ hdd_image_calc_chs(uint32_t *c, uint32_t *h, uint32_t *s, uint32_t size) /* Calculate the geometry from size (in MB), using the algorithm provided in "Virtual Hard Disk Image Format Specification, Appendix: CHS Calculation" */ uint64_t ts = ((uint64_t) size) << 11LL; - uint32_t spt, heads, cyl, cth; + uint32_t spt; + uint32_t heads; + uint32_t cyl; + uint32_t cth; + if (ts > 65535 * 16 * 255) ts = 65535 * 16 * 255; @@ -179,7 +184,7 @@ prepare_new_hard_disk(uint8_t id, uint64_t full_size) uint64_t target_size = (full_size + hdd_images[id].base) - ftello64(hdd_images[id].file); uint32_t size; - uint32_t t, i; + uint32_t t; t = (uint32_t) (target_size >> 20); /* Amount of 1 MB blocks. */ size = (uint32_t) (target_size & 0xfffff); /* 1 MB mask. */ @@ -194,7 +199,7 @@ prepare_new_hard_disk(uint8_t id, uint64_t full_size) /* First, write all the 1 MB blocks. */ if (t > 0) { - for (i = 0; i < t; i++) { + for (uint32_t i = 0; i < t; i++) { fseek(hdd_images[id].file, 0, SEEK_END); fwrite(empty_sector_1mb, 1, 1048576, hdd_images[id].file); pclog("#"); @@ -223,9 +228,7 @@ prepare_new_hard_disk(uint8_t id, uint64_t full_size) void hdd_image_init(void) { - int i; - - for (i = 0; i < HDD_NUM; i++) + for (uint8_t i = 0; i < HDD_NUM; i++) memset(&hdd_images[i], 0, sizeof(hdd_image_t)); } @@ -234,10 +237,12 @@ hdd_image_load(int id) { uint32_t sector_size = 512; uint32_t zero = 0; - uint64_t signature = 0xD778A82044445459ll; + uint64_t signature = 0xD778A82044445459LL; uint64_t full_size = 0; - uint64_t spt = 0, hpc = 0, tracks = 0; - int c, ret; + uint64_t spt = 0; + uint64_t hpc = 0; + uint64_t tracks = 0; + int ret; uint64_t s = 0; char *fn = hdd[id].fn; int is_hdx[2] = { 0, 0 }; @@ -305,7 +310,7 @@ hdd_image_load(int id) fwrite(&(hdd[id].spt), 1, 4, hdd_images[id].file); fwrite(&(hdd[id].hpc), 1, 4, hdd_images[id].file); fwrite(&(hdd[id].tracks), 1, 4, hdd_images[id].file); - for (c = 0; c < 0x3f8; c++) + for (uint16_t c = 0; c < 0x3f8; c++) fwrite(&zero, 1, 4, hdd_images[id].file); hdd_images[id].type = HDD_IMAGE_HDI; } else if (is_hdx[0]) { @@ -329,11 +334,35 @@ hdd_image_load(int id) full_size = ((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks) << 9LL; hdd_images[id].last_sector = (full_size >> 9LL) - 1; - hdd_images[id].vhd = mvhd_create_fixed(fn, geometry, &vhd_error, NULL); - if (hdd_images[id].vhd == NULL) - fatal("hdd_image_load(): VHD: Could not create VHD : %s\n", mvhd_strerr(vhd_error)); + if (hdd[id].vhd_blocksize || hdd[id].vhd_parent[0]) { + MVHDCreationOptions options; +retry_vhd: + options.block_size_in_sectors = hdd[id].vhd_blocksize; + options.path = fn; + options.size_in_bytes = 0; + options.geometry = geometry; + if (hdd[id].vhd_parent[0]) { + options.type = MVHD_TYPE_DIFF; + options.parent_path = hdd[id].vhd_parent; + } else { + options.type = MVHD_TYPE_DYNAMIC; + options.parent_path = NULL; + } + hdd_images[id].vhd = mvhd_create_ex(options, &vhd_error); + } else { + hdd_images[id].vhd = mvhd_create_fixed(fn, geometry, &vhd_error, NULL); + } + if (hdd_images[id].vhd == NULL) { + /* Don't lock out if the parent of a differential VHD doesn't exist. */ + if (hdd[id].vhd_parent[0]) { + hdd[id].vhd_parent[0] = '\0'; + goto retry_vhd; + } + fatal("hdd_image_load(): VHD: Could not create VHD : %s\n", mvhd_strerr(vhd_error)); + } hdd_images[id].type = HDD_IMAGE_VHD; + return 1; } else { hdd_images[id].type = HDD_IMAGE_RAW; @@ -421,12 +450,15 @@ hdd_image_load(int id) else fatal("hdd_image_load(): VHD: Error opening VHD file '%s': %s\n", fn, mvhd_strerr(vhd_error)); } else if (vhd_error == MVHD_ERR_TIMESTAMP) { - fatal("hdd_image_load(): VHD: Parent/child timestamp mismatch for VHD file '%s'\n", fn); + pclog("hdd_image_load(): VHD: Parent/child timestamp mismatch for VHD file '%s'\n", fn); } - hdd[id].tracks = hdd_images[id].vhd->footer.geom.cyl; - hdd[id].hpc = hdd_images[id].vhd->footer.geom.heads; - hdd[id].spt = hdd_images[id].vhd->footer.geom.spt; + hdd[id].tracks = hdd_images[id].vhd->footer.geom.cyl; + hdd[id].hpc = hdd_images[id].vhd->footer.geom.heads; + hdd[id].spt = hdd_images[id].vhd->footer.geom.spt; + hdd[id].vhd_blocksize = (hdd_images[id].vhd->footer.disk_type == MVHD_TYPE_FIXED) ? 0 : (hdd_images[id].vhd->sparse.block_sz / MVHD_SECTOR_SIZE); + if (hdd_images[id].vhd->parent && hdd_images[id].vhd->parent->filename[0]) + strncpy(hdd[id].vhd_parent, hdd_images[id].vhd->parent->filename, sizeof(hdd[id].vhd_parent) - 1); full_size = ((uint64_t) hdd[id].spt) * ((uint64_t) hdd[id].hpc) * ((uint64_t) hdd[id].tracks) << 9LL; hdd_images[id].type = HDD_IMAGE_VHD; /* If we're here, this means there is a valid VHD footer in the @@ -559,8 +591,6 @@ hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count) int non_transferred_sectors = mvhd_format_sectors(hdd_images[id].vhd, sector, count); hdd_images[id].pos = sector + count - non_transferred_sectors - 1; } else { - uint32_t i = 0; - memset(empty_sector, 0, 512); if (fseeko64(hdd_images[id].file, ((uint64_t) (sector) << 9LL) + hdd_images[id].base, SEEK_SET) == -1) { @@ -568,7 +598,7 @@ hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count) return; } - for (i = 0; i < count; i++) { + for (uint32_t i = 0; i < count; i++) { if (feof(hdd_images[id].file)) break; @@ -607,7 +637,7 @@ hdd_image_get_type(uint8_t id) } void -hdd_image_unload(uint8_t id, int fn_preserve) +hdd_image_unload(uint8_t id, UNUSED(int fn_preserve)) { if (strlen(hdd[id].fn) == 0) return; @@ -625,9 +655,6 @@ hdd_image_unload(uint8_t id, int fn_preserve) hdd_images[id].last_sector = -1; - memset(hdd[id].prev_fn, 0, sizeof(hdd[id].prev_fn)); - if (fn_preserve) - strcpy(hdd[id].prev_fn, hdd[id].fn); memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); } diff --git a/src/disk/minivhd/CMakeLists.txt b/src/disk/minivhd/CMakeLists.txt index ec6caff81..324acf81b 100644 --- a/src/disk/minivhd/CMakeLists.txt +++ b/src/disk/minivhd/CMakeLists.txt @@ -13,6 +13,5 @@ # Copyright 2020,2021 David Hrdlička. # -add_library(minivhd STATIC cwalk.c libxml2_encoding.c minivhd_convert.c - minivhd_create.c minivhd_io.c minivhd_manage.c minivhd_struct_rw.c - minivhd_util.c) +add_library(minivhd STATIC cwalk.c xml2_encoding.c convert.c + create.c minivhd_io.c manage.c struct_rw.c minivhd_util.c) diff --git a/src/disk/minivhd/CREDITS.md b/src/disk/minivhd/CREDITS.md index c494d4e43..266e9f0e4 100644 --- a/src/disk/minivhd/CREDITS.md +++ b/src/disk/minivhd/CREDITS.md @@ -1,7 +1,7 @@ # Credits -MiniVHD Copyright (c) 2019 Sherman Perry +MiniVHD Copyright 2019-2021 Sherman Perry. -MiniVHD was made possible with the help of the following projects +MiniVHD was made possible with the help of the following projects: ### libxml2 **Project Home:** http://www.xmlsoft.org/ @@ -10,3 +10,8 @@ MiniVHD was made possible with the help of the following projects ### cwalk **Project Home:** https://likle.github.io/cwalk/ **Licence:** MIT (https://github.com/likle/cwalk/blob/master/LICENSE.md) + +### VARCem +The MiniVHD was rewritten into a standalone library (both shared as well +as static) by Fred N. van Kempen for use with the VARCem PC Systems +emulator - see https://www.varcem.com/ for more info. diff --git a/src/disk/minivhd/LICENSE b/src/disk/minivhd/LICENSE index af7299185..2997be44a 100644 --- a/src/disk/minivhd/LICENSE +++ b/src/disk/minivhd/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/src/disk/minivhd/minivhd_convert.c b/src/disk/minivhd/convert.c similarity index 57% rename from src/disk/minivhd/minivhd_convert.c rename to src/disk/minivhd/convert.c index 3ae1d084f..1b7d10c87 100644 --- a/src/disk/minivhd/minivhd_convert.c +++ b/src/disk/minivhd/convert.c @@ -1,28 +1,66 @@ +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Version: @(#)convert.c 1.0.2 2021/04/16 + * + * Authors: Sherman Perry, + * Fred N. van Kempen, + * + * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ #ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 +# define _FILE_OFFSET_BITS 64 #endif #include #include #include #include #include -#include "minivhd_create.h" -#include "minivhd_internal.h" -#include "minivhd_util.h" +#include #include "minivhd.h" +#include "internal.h" -static FILE* mvhd_open_existing_raw_img(const char* utf8_raw_path, MVHDGeom* geom, int* err); -static FILE* mvhd_open_existing_raw_img(const char* utf8_raw_path, MVHDGeom* geom, int* err) { +static FILE* +open_existing_raw_img(const char* utf8_raw_path, MVHDGeom* geom, int* err) +{ + if (geom == NULL) { + *err = MVHD_ERR_INVALID_GEOM; + return NULL; + } + FILE *raw_img = mvhd_fopen(utf8_raw_path, "rb", err); if (raw_img == NULL) { *err = MVHD_ERR_FILE; return NULL; } - if (geom == NULL) { - *err = MVHD_ERR_INVALID_GEOM; - return NULL; - } + mvhd_fseeko64(raw_img, 0, SEEK_END); uint64_t size_bytes = (uint64_t)mvhd_ftello64(raw_img); MVHDGeom new_geom = mvhd_calculate_geometry(size_bytes); @@ -34,37 +72,52 @@ static FILE* mvhd_open_existing_raw_img(const char* utf8_raw_path, MVHDGeom* geo geom->heads = new_geom.heads; geom->spt = new_geom.spt; mvhd_fseeko64(raw_img, 0, SEEK_SET); + return raw_img; } -MVHDMeta* mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, int* err) { + +MVHDAPI MVHDMeta* +mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, int* err) +{ MVHDGeom geom; - FILE *raw_img = mvhd_open_existing_raw_img(utf8_raw_path, &geom, err); + + FILE *raw_img = open_existing_raw_img(utf8_raw_path, &geom, err); if (raw_img == NULL) { return NULL; } + uint64_t size_in_bytes = mvhd_calc_size_bytes(&geom); MVHDMeta *vhdm = mvhd_create_fixed_raw(utf8_vhd_path, raw_img, size_in_bytes, &geom, err, NULL); if (vhdm == NULL) { return NULL; } + return vhdm; } -MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8_vhd_path, int* err) { + + +MVHDAPI MVHDMeta* +mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8_vhd_path, int* err) +{ MVHDGeom geom; MVHDMeta *vhdm = NULL; - FILE *raw_img = mvhd_open_existing_raw_img(utf8_raw_path, &geom, err); + + FILE *raw_img = open_existing_raw_img(utf8_raw_path, &geom, err); if (raw_img == NULL) { return NULL; } + vhdm = mvhd_create_sparse(utf8_vhd_path, geom, err); if (vhdm == NULL) { goto end; } + uint8_t buff[4096] = {0}; // 8 sectors uint8_t empty_buff[4096] = {0}; int total_sectors = mvhd_calc_size_sectors(&geom); int copy_sect = 0; + for (int i = 0; i < total_sectors; i += 8) { copy_sect = 8; if ((i + 8) >= total_sectors) { @@ -72,6 +125,7 @@ MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8 memset(buff, 0, sizeof buff); } (void) !fread(buff, MVHD_SECTOR_SIZE, copy_sect, raw_img); + /* Only write data if there's data to write, to take advantage of the sparse VHD format */ if (memcmp(buff, empty_buff, sizeof buff) != 0) { mvhd_write_sectors(vhdm, i, copy_sect, buff); @@ -79,18 +133,25 @@ MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8 } end: fclose(raw_img); + return vhdm; } -FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, int *err) { + + +MVHDAPI FILE* +mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, int *err) +{ FILE *raw_img = mvhd_fopen(utf8_raw_path, "wb", err); if (raw_img == NULL) { return NULL; } + MVHDMeta *vhdm = mvhd_open(utf8_vhd_path, true, err); if (vhdm == NULL) { fclose(raw_img); return NULL; } + uint8_t buff[4096] = {0}; // 8 sectors int total_sectors = mvhd_calc_size_sectors((MVHDGeom*)&vhdm->footer.geom); int copy_sect = 0; @@ -104,5 +165,6 @@ FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, } mvhd_close(vhdm); mvhd_fseeko64(raw_img, 0, SEEK_SET); + return raw_img; } diff --git a/src/disk/minivhd/minivhd_create.c b/src/disk/minivhd/create.c similarity index 71% rename from src/disk/minivhd/minivhd_create.c rename to src/disk/minivhd/create.c index b56437c28..ebfbb69a2 100644 --- a/src/disk/minivhd/minivhd_create.c +++ b/src/disk/minivhd/create.c @@ -1,30 +1,60 @@ +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Version: @(#)create.c 1.0.3 2021/04/16 + * + * Authors: Sherman Perry, + * Fred N. van Kempen, + * + * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ #ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 +# define _FILE_OFFSET_BITS 64 #endif #include +#include #include #include #include #include -#include "cwalk.h" -#include "libxml2_encoding.h" -#include "minivhd_internal.h" -#include "minivhd_util.h" -#include "minivhd_struct_rw.h" -#include "minivhd_io.h" -#include "minivhd_create.h" +#include #include "minivhd.h" +#include "internal.h" +#include "cwalk.h" +#include "xml2_encoding.h" + + +static const char MVHD_CONECTIX_COOKIE[] = "conectix"; +static const char MVHD_CREATOR[] = "mVHD"; +static const char MVHD_CREATOR_HOST_OS[] = "Wi2k"; +static const char MVHD_CXSPARSE_COOKIE[] = "cxsparse"; -static void mvhd_gen_footer(MVHDFooter* footer, uint64_t size_in_bytes, MVHDGeom* geom, MVHDType type, uint64_t sparse_header_off); -static void mvhd_gen_sparse_header(MVHDSparseHeader* header, uint32_t num_blks, uint64_t bat_offset, uint32_t block_size_in_sectors); -static int mvhd_gen_par_loc(MVHDSparseHeader* header, - const char* child_path, - const char* par_path, - uint64_t start_offset, - mvhd_utf16* w2ku_path_buff, - mvhd_utf16* w2ru_path_buff, - MVHDError* err); -static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, uint64_t size_in_bytes, MVHDGeom* geom, uint32_t block_size_in_sectors, int* err); /** * \brief Populate a VHD footer @@ -35,24 +65,29 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, * \param [in] type of HVD that is being created * \param [in] sparse_header_off, an absolute file offset to the sparse header. Not used for fixed VHD images */ -static void mvhd_gen_footer(MVHDFooter* footer, uint64_t size_in_bytes, MVHDGeom* geom, MVHDType type, uint64_t sparse_header_off) { - memcpy(footer->cookie, "conectix", sizeof footer->cookie); +static void +gen_footer(MVHDFooter* footer, uint64_t size_in_bytes, MVHDGeom* geom, MVHDType type, uint64_t sparse_header_off) +{ + memcpy(footer->cookie, MVHD_CONECTIX_COOKIE, sizeof footer->cookie); footer->features = 0x00000002; footer->fi_fmt_vers = 0x00010000; footer->data_offset = (type == MVHD_TYPE_DIFF || type == MVHD_TYPE_DYNAMIC) ? sparse_header_off : 0xffffffffffffffff; footer->timestamp = vhd_calc_timestamp(); - memcpy(footer->cr_app, "mvhd", sizeof footer->cr_app); + memcpy(footer->cr_app, MVHD_CREATOR, sizeof footer->cr_app); footer->cr_vers = 0x000e0000; - memcpy(footer->cr_host_os, "Wi2k", sizeof footer->cr_host_os); + memcpy(footer->cr_host_os, MVHD_CREATOR_HOST_OS, sizeof footer->cr_host_os); footer->orig_sz = footer->curr_sz = size_in_bytes; footer->geom.cyl = geom->cyl; footer->geom.heads = geom->heads; footer->geom.spt = geom->spt; footer->disk_type = type; + mvhd_generate_uuid(footer->uuid); + footer->checksum = mvhd_gen_footer_checksum(footer); } + /** * \brief Populate a VHD sparse header * @@ -61,8 +96,10 @@ static void mvhd_gen_footer(MVHDFooter* footer, uint64_t size_in_bytes, MVHDGeom * \param [in] bat_offset is the absolute file offset for start of the Block Allocation Table * \param [in] block_size_in_sectors is the block size in sectors. */ -static void mvhd_gen_sparse_header(MVHDSparseHeader* header, uint32_t num_blks, uint64_t bat_offset, uint32_t block_size_in_sectors) { - memcpy(header->cookie, "cxsparse", sizeof header->cookie); +static void +gen_sparse_header(MVHDSparseHeader* header, uint32_t num_blks, uint64_t bat_offset, uint32_t block_size_in_sectors) +{ + memcpy(header->cookie, MVHD_CXSPARSE_COOKIE, sizeof header->cookie); header->data_offset = 0xffffffffffffffff; header->bat_offset = bat_offset; header->head_vers = 0x00010000; @@ -71,6 +108,7 @@ static void mvhd_gen_sparse_header(MVHDSparseHeader* header, uint32_t num_blks, header->checksum = mvhd_gen_sparse_checksum(header); } + /** * \brief Generate parent locators for differencing VHD images * @@ -85,13 +123,12 @@ static void mvhd_gen_sparse_header(MVHDSparseHeader* header, uint32_t num_blks, * \retval 0 if success * \retval < 0 if an error occurrs. Check value of *err for actual error */ -static int mvhd_gen_par_loc(MVHDSparseHeader* header, - const char* child_path, - const char* par_path, - uint64_t start_offset, - mvhd_utf16* w2ku_path_buff, - mvhd_utf16* w2ru_path_buff, - MVHDError* err) { +static int +gen_par_loc(MVHDSparseHeader* header, const char* child_path, + const char* par_path, uint64_t start_offset, + mvhd_utf16* w2ku_path_buff, mvhd_utf16* w2ru_path_buff, + MVHDError* err) +{ /* Get our paths to store in the differencing VHD. We want both the absolute path to the parent, as well as the relative path from the child VHD */ int rv = 0; @@ -100,6 +137,7 @@ static int mvhd_gen_par_loc(MVHDSparseHeader* header, char rel_path[MVHD_MAX_PATH_BYTES] = {0}; char child_dir[MVHD_MAX_PATH_BYTES] = {0}; size_t child_dir_len; + if (strlen(child_path) < sizeof child_dir) { strcpy(child_dir, child_path); } else { @@ -107,6 +145,7 @@ static int mvhd_gen_par_loc(MVHDSparseHeader* header, rv = -1; goto end; } + cwk_path_get_basename(par_path, (const char**)&par_filename, &par_fn_len); cwk_path_get_dirname(child_dir, &child_dir_len); child_dir[child_dir_len] = '\0'; @@ -116,6 +155,7 @@ static int mvhd_gen_par_loc(MVHDSparseHeader* header, rv = -1; goto end; } + /* We have our paths, now store the parent filename directly in the sparse header. */ int outlen = sizeof header->par_utf16_name; int utf_ret; @@ -144,6 +184,7 @@ static int mvhd_gen_par_loc(MVHDSparseHeader* header, goto end; } int w2ru_len = utf_ret; + /** * Finally populate the parent locaters in the sparse header. * This is the information needed to find the paths saved elsewhere @@ -169,11 +210,16 @@ end: return rv; } -MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_progress_callback progress_callback) { + +MVHDAPI MVHDMeta* +mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_progress_callback progress_callback) +{ uint64_t size_in_bytes = mvhd_calc_size_bytes(&geom); + return mvhd_create_fixed_raw(path, NULL, size_in_bytes, &geom, err, progress_callback); } + /** * \brief internal function that implements public mvhd_create_fixed() functionality * @@ -182,27 +228,35 @@ MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_prog * * \param [in] raw_image file handle to a raw disk image to populate VHD */ -MVHDMeta* mvhd_create_fixed_raw(const char* path, FILE* raw_img, uint64_t size_in_bytes, MVHDGeom* geom, int* err, mvhd_progress_callback progress_callback) { +MVHDMeta* +mvhd_create_fixed_raw(const char* path, FILE* raw_img, uint64_t size_in_bytes, MVHDGeom* geom, int* err, mvhd_progress_callback progress_callback) +{ uint8_t img_data[MVHD_SECTOR_SIZE] = {0}; uint8_t footer_buff[MVHD_FOOTER_SIZE] = {0}; + + if (geom == NULL || (geom->cyl == 0 || geom->heads == 0 || geom->spt == 0)) { + *err = MVHD_ERR_INVALID_GEOM; + return NULL; + } + MVHDMeta* vhdm = calloc(1, sizeof *vhdm); if (vhdm == NULL) { *err = MVHD_ERR_MEM; goto end; } - if (geom == NULL || (geom->cyl == 0 || geom->heads == 0 || geom->spt == 0)) { - *err = MVHD_ERR_INVALID_GEOM; - goto cleanup_vhdm; - } + FILE* f = mvhd_fopen(path, "wb+", err); if (f == NULL) { goto cleanup_vhdm; } mvhd_fseeko64(f, 0, SEEK_SET); + uint32_t size_sectors = (uint32_t)(size_in_bytes / MVHD_SECTOR_SIZE); uint32_t s; + if (progress_callback) progress_callback(0, size_sectors); + if (raw_img != NULL) { mvhd_fseeko64(raw_img, 0, SEEK_END); uint64_t raw_size = (uint64_t)mvhd_ftello64(raw_img); @@ -211,7 +265,7 @@ MVHDMeta* mvhd_create_fixed_raw(const char* path, FILE* raw_img, uint64_t size_i *err = MVHD_ERR_CONV_SIZE; goto cleanup_vhdm; } - mvhd_gen_footer(&vhdm->footer, raw_size, geom, MVHD_TYPE_FIXED, 0); + gen_footer(&vhdm->footer, raw_size, geom, MVHD_TYPE_FIXED, 0); mvhd_fseeko64(raw_img, 0, SEEK_SET); for (s = 0; s < size_sectors; s++) { (void) !fread(img_data, sizeof img_data, 1, raw_img); @@ -220,7 +274,7 @@ MVHDMeta* mvhd_create_fixed_raw(const char* path, FILE* raw_img, uint64_t size_i progress_callback(s + 1, size_sectors); } } else { - mvhd_gen_footer(&vhdm->footer, size_in_bytes, geom, MVHD_TYPE_FIXED, 0); + gen_footer(&vhdm->footer, size_in_bytes, geom, MVHD_TYPE_FIXED, 0); for (s = 0; s < size_sectors; s++) { fwrite(img_data, sizeof img_data, 1, f); if (progress_callback) @@ -238,10 +292,12 @@ MVHDMeta* mvhd_create_fixed_raw(const char* path, FILE* raw_img, uint64_t size_i cleanup_vhdm: free(vhdm); vhdm = NULL; + end: return vhdm; } + /** * \brief Create sparse or differencing VHD image. * @@ -254,7 +310,9 @@ end: * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, uint64_t size_in_bytes, MVHDGeom* geom, uint32_t block_size_in_sectors, int* err) { +static MVHDMeta* +create_sparse_diff(const char* path, const char* par_path, uint64_t size_in_bytes, MVHDGeom* geom, uint32_t block_size_in_sectors, int* err) +{ uint8_t footer_buff[MVHD_FOOTER_SIZE] = {0}; uint8_t sparse_buff[MVHD_SPARSE_SIZE] = {0}; uint8_t bat_sect[MVHD_SECTOR_SIZE]; @@ -265,6 +323,7 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, mvhd_utf16* w2ku_path_buff = NULL; mvhd_utf16* w2ru_path_buff = NULL; uint32_t par_mod_timestamp = 0; + if (par_path != NULL) { par_mod_timestamp = mvhd_file_mod_timestamp(par_path, err); if (*err != 0) { @@ -275,6 +334,7 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, goto end; } } + vhdm = calloc(1, sizeof *vhdm); if (vhdm == NULL) { *err = MVHD_ERR_MEM; @@ -297,15 +357,18 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, goto cleanup_vhdm; } mvhd_fseeko64(f, 0, SEEK_SET); + /* Note, the sparse header follows the footer copy at the beginning of the file */ if (par_path == NULL) { - mvhd_gen_footer(&vhdm->footer, size_in_bytes, geom, MVHD_TYPE_DYNAMIC, MVHD_FOOTER_SIZE); + gen_footer(&vhdm->footer, size_in_bytes, geom, MVHD_TYPE_DYNAMIC, MVHD_FOOTER_SIZE); } else { - mvhd_gen_footer(&vhdm->footer, size_in_bytes, geom, MVHD_TYPE_DIFF, MVHD_FOOTER_SIZE); + gen_footer(&vhdm->footer, size_in_bytes, geom, MVHD_TYPE_DIFF, MVHD_FOOTER_SIZE); } mvhd_footer_to_buffer(&vhdm->footer, footer_buff); + /* As mentioned, start with a copy of the footer */ fwrite(footer_buff, sizeof footer_buff, 1, f); + /** * Calculate the number of (2MB or 512KB) data blocks required to store the entire * contents of the disk image, followed by the number of sectors the @@ -347,43 +410,51 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, } memcpy(vhdm->sparse.par_uuid, par_vhdm->footer.uuid, sizeof vhdm->sparse.par_uuid); par_loc_offset = bat_offset + ((uint64_t)num_bat_sect * MVHD_SECTOR_SIZE) + (5 * MVHD_SECTOR_SIZE); - if (mvhd_gen_par_loc(&vhdm->sparse, path, par_path, par_loc_offset, w2ku_path_buff, w2ru_path_buff, (MVHDError*)err) < 0) { + if (gen_par_loc(&vhdm->sparse, path, par_path, par_loc_offset, w2ku_path_buff, w2ru_path_buff, (MVHDError*)err) < 0) { goto cleanup_vhdm; } vhdm->sparse.par_timestamp = par_mod_timestamp; } - mvhd_gen_sparse_header(&vhdm->sparse, num_blks, bat_offset, block_size_in_sectors); + gen_sparse_header(&vhdm->sparse, num_blks, bat_offset, block_size_in_sectors); mvhd_header_to_buffer(&vhdm->sparse, sparse_buff); fwrite(sparse_buff, sizeof sparse_buff, 1, f); + /* The BAT sectors need to be filled with 0xffffffff */ - for (uint32_t i = 0; i < num_bat_sect; i++) { + for (uint32_t k = 0; k < num_bat_sect; k++) { fwrite(bat_sect, sizeof bat_sect, 1, f); } mvhd_write_empty_sectors(f, 5); + /** * If creating a differencing VHD, the paths to the parent image need to be written * tp the file. Both absolute and relative paths are written * */ if (par_vhdm != NULL) { uint64_t curr_pos = (uint64_t)mvhd_ftello64(f); + /* Double check my sums... */ assert(curr_pos == par_loc_offset); + /* Fill the space required for location data with zero */ uint8_t empty_sect[MVHD_SECTOR_SIZE] = {0}; + for (int i = 0; i < 2; i++) { for (uint32_t j = 0; j < (vhdm->sparse.par_loc_entry[i].plat_data_space / MVHD_SECTOR_SIZE); j++) { fwrite(empty_sect, sizeof empty_sect, 1, f); } } + /* Now write the location entries */ mvhd_fseeko64(f, vhdm->sparse.par_loc_entry[0].plat_data_offset, SEEK_SET); fwrite(w2ku_path_buff, vhdm->sparse.par_loc_entry[0].plat_data_len, 1, f); mvhd_fseeko64(f, vhdm->sparse.par_loc_entry[1].plat_data_offset, SEEK_SET); fwrite(w2ru_path_buff, vhdm->sparse.par_loc_entry[1].plat_data_len, 1, f); + /* and reset the file position to continue */ mvhd_fseeko64(f, vhdm->sparse.par_loc_entry[1].plat_data_offset + vhdm->sparse.par_loc_entry[1].plat_data_space, SEEK_SET); mvhd_write_empty_sectors(f, 5); } + /* And finish with the footer */ fwrite(footer_buff, sizeof footer_buff, 1, f); fclose(f); @@ -395,91 +466,112 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, cleanup_vhdm: free(vhdm); vhdm = NULL; + cleanup_par_vhdm: if (par_vhdm != NULL) { mvhd_close(par_vhdm); } + end: free(w2ku_path_buff); free(w2ru_path_buff); + return vhdm; } -MVHDMeta* mvhd_create_sparse(const char* path, MVHDGeom geom, int* err) { + +MVHDAPI MVHDMeta* +mvhd_create_sparse(const char* path, MVHDGeom geom, int* err) +{ uint64_t size_in_bytes = mvhd_calc_size_bytes(&geom); - return mvhd_create_sparse_diff(path, NULL, size_in_bytes, &geom, MVHD_BLOCK_LARGE, err); + + return create_sparse_diff(path, NULL, size_in_bytes, &geom, MVHD_BLOCK_LARGE, err); } -MVHDMeta* mvhd_create_diff(const char* path, const char* par_path, int* err) { - return mvhd_create_sparse_diff(path, par_path, 0, NULL, MVHD_BLOCK_LARGE, err); + +MVHDAPI MVHDMeta* +mvhd_create_diff(const char* path, const char* par_path, int* err) +{ + return create_sparse_diff(path, par_path, 0, NULL, MVHD_BLOCK_LARGE, err); } -MVHDMeta* mvhd_create_ex(MVHDCreationOptions options, int* err) { + +MVHDAPI MVHDMeta* +mvhd_create_ex(MVHDCreationOptions options, int* err) +{ uint32_t geom_sector_size; - switch (options.type) - { - case MVHD_TYPE_FIXED: - case MVHD_TYPE_DYNAMIC: - geom_sector_size = mvhd_calc_size_sectors(&(options.geometry)); - if ((options.size_in_bytes > 0 && (options.size_in_bytes % MVHD_SECTOR_SIZE) > 0) - || (options.size_in_bytes > MVHD_MAX_SIZE_IN_BYTES) - || (options.size_in_bytes == 0 && geom_sector_size == 0)) - { - *err = MVHD_ERR_INVALID_SIZE; - return NULL; - } - if (options.size_in_bytes > 0 && ((uint64_t)geom_sector_size * MVHD_SECTOR_SIZE) > options.size_in_bytes) - { - *err = MVHD_ERR_INVALID_GEOM; - return NULL; - } + switch (options.type) { + case MVHD_TYPE_FIXED: + case MVHD_TYPE_DYNAMIC: + geom_sector_size = mvhd_calc_size_sectors(&(options.geometry)); + if ((options.size_in_bytes > 0 && (options.size_in_bytes % MVHD_SECTOR_SIZE) > 0) + || (options.size_in_bytes > MVHD_MAX_SIZE_IN_BYTES) + || (options.size_in_bytes == 0 && geom_sector_size == 0)) { + *err = MVHD_ERR_INVALID_SIZE; + return NULL; + } - if (options.size_in_bytes == 0) - options.size_in_bytes = (uint64_t)geom_sector_size * MVHD_SECTOR_SIZE; + if (options.size_in_bytes > 0 && ((uint64_t)geom_sector_size * MVHD_SECTOR_SIZE) > options.size_in_bytes) { + *err = MVHD_ERR_INVALID_GEOM; + return NULL; + } - if (geom_sector_size == 0) - options.geometry = mvhd_calculate_geometry(options.size_in_bytes); - break; - case MVHD_TYPE_DIFF: - if (options.parent_path == NULL) - { - *err = MVHD_ERR_FILE; + if (options.size_in_bytes == 0) + options.size_in_bytes = (uint64_t)geom_sector_size * MVHD_SECTOR_SIZE; + + if (geom_sector_size == 0) + options.geometry = mvhd_calculate_geometry(options.size_in_bytes); + break; + + case MVHD_TYPE_DIFF: + if (options.parent_path == NULL) { + *err = MVHD_ERR_FILE; + return NULL; + } + break; + + default: + *err = MVHD_ERR_TYPE; return NULL; - } - break; - default: - *err = MVHD_ERR_TYPE; - return NULL; } - if (options.path == NULL) - { + if (options.path == NULL) { *err = MVHD_ERR_FILE; return NULL; } - if (options.type != MVHD_TYPE_FIXED) - { + if (options.type != MVHD_TYPE_FIXED) { if (options.block_size_in_sectors == MVHD_BLOCK_DEFAULT) options.block_size_in_sectors = MVHD_BLOCK_LARGE; - if (options.block_size_in_sectors != MVHD_BLOCK_LARGE && options.block_size_in_sectors != MVHD_BLOCK_SMALL) - { + if (options.block_size_in_sectors != MVHD_BLOCK_LARGE && options.block_size_in_sectors != MVHD_BLOCK_SMALL) { *err = MVHD_ERR_INVALID_BLOCK_SIZE; return NULL; } } - switch (options.type) - { - case MVHD_TYPE_FIXED: - return mvhd_create_fixed_raw(options.path, NULL, options.size_in_bytes, &(options.geometry), err, options.progress_callback); - case MVHD_TYPE_DYNAMIC: - return mvhd_create_sparse_diff(options.path, NULL, options.size_in_bytes, &(options.geometry), options.block_size_in_sectors, err); - case MVHD_TYPE_DIFF: - return mvhd_create_sparse_diff(options.path, options.parent_path, 0, NULL, options.block_size_in_sectors, err); + switch (options.type) { + case MVHD_TYPE_FIXED: + return mvhd_create_fixed_raw(options.path, NULL, options.size_in_bytes, &(options.geometry), err, options.progress_callback); + + case MVHD_TYPE_DYNAMIC: + return create_sparse_diff(options.path, NULL, options.size_in_bytes, &(options.geometry), options.block_size_in_sectors, err); + + case MVHD_TYPE_DIFF: + return create_sparse_diff(options.path, options.parent_path, 0, NULL, options.block_size_in_sectors, err); } return NULL; /* Make the compiler happy */ } + + +bool +mvhd_is_conectix_str(const void* buffer) +{ + if (strncmp(buffer, MVHD_CONECTIX_COOKIE, strlen(MVHD_CONECTIX_COOKIE)) == 0) { + return true; + } + + return false; +} diff --git a/src/disk/minivhd/cwalk.c b/src/disk/minivhd/cwalk.c index f0c48427c..02964af25 100644 --- a/src/disk/minivhd/cwalk.c +++ b/src/disk/minivhd/cwalk.c @@ -1,12 +1,49 @@ +/* + * libCWALK Path library for C/C++ + * + * Version: @(#)cwalk.c 1.0.2 2021/03/16 + * + * Authors: Sherman Perry, + * Leonard Ikl, + * + * Copyright 2019-2021 Sherman Perry. + * Copyright 2020 Leonard Ikl. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ #ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 +# define _FILE_OFFSET_BITS 64 #endif #include #include +#include #include #include #include #include "cwalk.h" + + /** * We try to default to a different path style depending on the operating * system. So this should detect whether we should use windows or unix paths. diff --git a/src/disk/minivhd/cwalk.h b/src/disk/minivhd/cwalk.h index baa5d432d..380f6fa2c 100644 --- a/src/disk/minivhd/cwalk.h +++ b/src/disk/minivhd/cwalk.h @@ -1,10 +1,40 @@ -#pragma once - +/* + * libCWALK path library for C/C++ + * + * Version: @(#)cwalk.h 1.0.3 2021/03/22 + * + * Authors: Sherman Perry, + * Leonard Ikl, + * + * Copyright 2019-2021 Sherman Perry. + * Copyright 2020 Leonard Ikl. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ #ifndef CWK_LIBRARY_H -#define CWK_LIBRARY_H +# define CWK_LIBRARY_H -#include -#include /** * A segment represents a single component of a path. For instance, on linux a @@ -45,6 +75,11 @@ enum cwk_path_style CWK_STYLE_UNIX }; + +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Generates an absolute path based on a base. * @@ -454,4 +489,9 @@ void cwk_path_set_style(enum cwk_path_style style); */ enum cwk_path_style cwk_path_get_style(void); +#ifdef __cplusplus +} #endif + + +#endif /*CWK_LIBRARY_H*/ diff --git a/src/disk/minivhd/internal.h b/src/disk/minivhd/internal.h new file mode 100644 index 000000000..d3f930110 --- /dev/null +++ b/src/disk/minivhd/internal.h @@ -0,0 +1,429 @@ +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Internal definitions. + * + * Version: @(#)internal.h 1.0.1 2021/03/15 + * + * Author: Sherman Perry, + * + * Copyright 2019-2021 Sherman Perry. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#ifndef MINIVHD_INTERNAL_H +# define MINIVHD_INTERNAL_H + + +#define MVHD_FOOTER_SIZE 512 +#define MVHD_SPARSE_SIZE 1024 + +#define MVHD_SECTOR_SIZE 512 +#define MVHD_BAT_ENT_PER_SECT 128 + +#define MVHD_MAX_SIZE_IN_BYTES 0x1fe00000000 + +#define MVHD_SPARSE_BLK 0xffffffff + +/* For simplicity, we don't handle paths longer than this + * Note, this is the max path in characters, as that is what + * Windows uses + */ +#define MVHD_MAX_PATH_CHARS 260 +#define MVHD_MAX_PATH_BYTES 1040 + +#define MVHD_DIF_LOC_W2RU 0x57327275 +#define MVHD_DIF_LOC_W2KU 0x57326B75 + +#define MVHD_START_TS 946684800 + + +typedef struct MVHDSectorBitmap { + uint8_t* curr_bitmap; + int sector_count; + int curr_block; +} MVHDSectorBitmap; + +typedef struct MVHDFooter { + uint8_t cookie[8]; + uint32_t features; + uint32_t fi_fmt_vers; + uint64_t data_offset; + uint32_t timestamp; + uint8_t cr_app[4]; + uint32_t cr_vers; + uint8_t cr_host_os[4]; + uint64_t orig_sz; + uint64_t curr_sz; + struct { + uint16_t cyl; + uint8_t heads; + uint8_t spt; + } geom; + uint32_t disk_type; + uint32_t checksum; + uint8_t uuid[16]; + uint8_t saved_st; + uint8_t reserved[427]; +} MVHDFooter; + +typedef struct MVHDSparseHeader { + uint8_t cookie[8]; + uint64_t data_offset; + uint64_t bat_offset; + uint32_t head_vers; + uint32_t max_bat_ent; + uint32_t block_sz; + uint32_t checksum; + uint8_t par_uuid[16]; + uint32_t par_timestamp; + uint32_t reserved_1; + uint8_t par_utf16_name[512]; + struct { + uint32_t plat_code; + uint32_t plat_data_space; + uint32_t plat_data_len; + uint32_t reserved; + uint64_t plat_data_offset; + } par_loc_entry[8]; + uint8_t reserved_2[256]; +} MVHDSparseHeader; + +struct MVHDMeta { + FILE* f; + bool readonly; + char filename[MVHD_MAX_PATH_BYTES]; + struct MVHDMeta* parent; + MVHDFooter footer; + MVHDSparseHeader sparse; + uint32_t* block_offset; + int sect_per_block; + MVHDSectorBitmap bitmap; + int (*read_sectors)(struct MVHDMeta*, uint32_t, int, void*); + int (*write_sectors)(struct MVHDMeta*, uint32_t, int, void*); + struct { + uint8_t* zero_data; + int sector_count; + } format_buffer; +}; + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Functions to deal with endian issues + */ +uint16_t mvhd_from_be16(uint16_t val); +uint32_t mvhd_from_be32(uint32_t val); +uint64_t mvhd_from_be64(uint64_t val); +uint16_t mvhd_to_be16(uint16_t val); +uint32_t mvhd_to_be32(uint32_t val); +uint64_t mvhd_to_be64(uint64_t val); + +/** + * \brief Check if provided buffer begins with the string "conectix" + * + * \param [in] buffer The buffer to compare. Must be at least 8 bytes in length + * + * \return true if the buffer begins with "conectix" + * \return false if the buffer does not begin with "conectix" + */ +bool mvhd_is_conectix_str(const void* buffer); + +/** + * \brief Generate a raw 16 byte UUID + * + * \param [out] uuid A 16 byte buffer in which the generated UUID will be stored to + */ +void mvhd_generate_uuid(uint8_t *uuid); + +/** + * \brief Calculate a VHD formatted timestamp from the current time + */ +uint32_t vhd_calc_timestamp(void); + +/** + * \brief Convert an epoch timestamp to a VHD timestamp + * + * \param [in] ts epoch timestamp to convert. + * + * \return The adjusted timestamp, or 0 if the input timestamp is + * earlier that 1 Janurary 2000 + */ +uint32_t mvhd_epoch_to_vhd_ts(time_t ts); + +/** + * \brief Return the created time from a VHD image + * + * \param [in] vhdm Pointer to the MiniVHD metadata structure + * + * \return The created time, as a Unix timestamp + */ +time_t vhd_get_created_time(struct MVHDMeta *vhdm); + +/** + * \brief Cross platform, unicode filepath opening + * + * This function accounts for the fact that fopen() handles file paths differently compared to other + * operating systems. Windows version of fopen() will not handle multi byte encoded text like UTF-8. + * + * Unicode filepath support on Windows requires using the _wfopen() function, which expects UTF-16LE + * encoded path and modestring. + * + * \param [in] path The filepath to open as a UTF-8 string + * \param [in] mode The mode string to use (eg: "rb+"") + * \param [out] err The error value, if an error occurrs + * + * \return a FILE pointer if successful, NULL otherwise. If NULL, check the value of err + */ +FILE* mvhd_fopen(const char* path, const char* mode, int* err); + +void mvhd_set_encoding_err(int encoding_retval, int* err); + +/** + * \brief Generate VHD footer checksum + * + * \param [in] vhdm MiniVHD data structure + */ +uint32_t mvhd_gen_footer_checksum(MVHDFooter* footer); + +/** + * \brief Generate VHD sparse header checksum + * + * \param [in] vhdm MiniVHD data structure + */ +uint32_t mvhd_gen_sparse_checksum(MVHDSparseHeader* header); + +uint32_t mvhd_crc32_for_byte(uint32_t r); + +/** + * \brief Get current position in file stream + * + * This is a portable version of the POSIX ftello64(). * + */ +int64_t mvhd_ftello64(FILE* stream); + +/** + * \brief Reposition the file stream's position + * + * This is a portable version of the POSIX fseeko64(). * + */ +int mvhd_fseeko64(FILE* stream, int64_t offset, int origin); + +/** + * \brief Calculate the CRC32 of a data buffer. + * + * This function can be used for verifying data integrity. + * + * \param [in] data The data buffer + * \param [in] n_bytes The size of the data buffer in bytes + * + * \return The CRC32 of the data buffer + */ +uint32_t mvhd_crc32(const void* data, size_t n_bytes); + +/** + * \brief Calculate the file modification timestamp. + * + * This function is primarily to help protect differencing VHD's + * + * \param [in] path the UTF-8 file path + * \param [out] err The error value, if an error occurrs + * + * \return The file modified timestamp, in VHD compatible timestamp. + * 'err' will be set to non-zero on error + */ +uint32_t mvhd_file_mod_timestamp(const char* path, int *err); + +struct MVHDMeta* mvhd_create_fixed_raw(const char* path, FILE* raw_img, uint64_t size_in_bytes, MVHDGeom* geom, int* err, mvhd_progress_callback progress_callback); + +/** + * \brief Write zero filled sectors to file. + * + * Note, the caller should set the file position before calling this + * function for correct operation. + * + * \param [in] f File to write sectors to + * \param [in] sector_count The number of sectors to write + */ +void mvhd_write_empty_sectors(FILE* f, int sector_count); + +/** + * \brief Read a fixed VHD image + * + * Fixed VHD images are essentially raw image files with a footer tacked on + * the end. They are therefore straightforward to write + * + * \param [in] vhdm MiniVHD data structure + * \param [in] offset Sector offset to read from + * \param [in] num_sectors The desired number of sectors to read + * \param [out] out_buff An output buffer to store read sectors. Must be + * large enough to hold num_sectors worth of sectors. + * + * \retval 0 num_sectors were read from file + * \retval >0 < num_sectors were read from file + */ +int mvhd_fixed_read(struct MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); + +/** + * \brief Read a sparse VHD image + * + * Sparse, or dynamic images are VHD images that grow as data is written to them. + * + * This function implements the logic to read sectors from the file, taking into + * account the fact that blocks may be stored on disk in any order, and that the + * read could cross block boundaries. + * + * \param [in] vhdm MiniVHD data structure + * \param [in] offset Sector offset to read from + * \param [in] num_sectors The desired number of sectors to read + * \param [out] out_buff An output buffer to store read sectors. Must be + * large enough to hold num_sectors worth of sectors. + * + * \retval 0 num_sectors were read from file + * \retval >0 < num_sectors were read from file + */ +int mvhd_sparse_read(struct MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); + +/** + * \brief Read a differencing VHD image + * + * Differencing images are a variant of a sparse image. They contain the grow-on-demand + * properties of sparse images, but also reference a parent image. Data is read from the + * child image only if it is newer than the data stored in the parent image. + * + * This function implements the logic to read sectors from the child, or a parent image. + * Differencing images may have a differencing image as a parent, creating a chain of images. + * There is no theoretical chain length limit, although I do not consider long chains to be + * advisable. Verifying the parent-child relationship is not very robust. + * + * \param [in] vhdm MiniVHD data structure + * \param [in] offset Sector offset to read from + * \param [in] num_sectors The desired number of sectors to read + * \param [out] out_buff An output buffer to store read sectors. Must be + * large enough to hold num_sectors worth of sectors. + * + * \retval 0 num_sectors were read from file + * \retval >0 < num_sectors were read from file + */ +int mvhd_diff_read(struct MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); + +/** + * \brief Write to a fixed VHD image + * + * Fixed VHD images are essentially raw image files with a footer tacked on + * the end. They are therefore straightforward to write + * + * \param [in] vhdm MiniVHD data structure + * \param [in] offset Sector offset to write to + * \param [in] num_sectors The desired number of sectors to write + * \param [in] in_buff A source buffer to write sectors from. Must be + * large enough to hold num_sectors worth of sectors. + * + * \retval 0 num_sectors were written to file + * \retval >0 < num_sectors were written to file + */ +int mvhd_fixed_write(struct MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); + +/** + * \brief Write to a sparse or differencing VHD image + * + * Sparse, or dynamic images are VHD images that grow as data is written to them. + * + * Differencing images are a variant of a sparse image. They contain the grow-on-demand + * properties of sparse images, but also reference a parent image. Data is always written + * to the child image. This makes writing to differencing images essentially identical to + * writing to sparse images, hence they use the same function. + * + * This function implements the logic to write sectors to the file, taking into + * account the fact that blocks may be stored on disk in any order, and that the + * write operation could cross block boundaries. + * + * \param [in] vhdm MiniVHD data structure + * \param [in] offset Sector offset to write to + * \param [in] num_sectors The desired number of sectors to write + * \param [in] in_buff A source buffer to write sectors from. Must be + * large enough to hold num_sectors worth of sectors. + * + * \retval 0 num_sectors were written to file + * \retval >0 < num_sectors were written to file + */ +int mvhd_sparse_diff_write(struct MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); + +/** + * \brief A no-op function to "write" to read-only VHD images + * + * \param [in] vhdm MiniVHD data structure + * \param [in] offset Sector offset to write to + * \param [in] num_sectors The desired number of sectors to write + * \param [in] in_buff A source buffer to write sectors from. Must be + * large enough to hold num_sectors worth of sectors. + * + * \retval 0 num_sectors were written to file + * \retval >0 < num_sectors were written to file + */ +int mvhd_noop_write(struct MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); + +/** + * \brief Save the contents of a VHD footer from a buffer to a struct + * + * \param [out] footer save contents of buffer into footer + * \param [in] buffer VHD footer in raw bytes + */ +void mvhd_buffer_to_footer(MVHDFooter* footer, uint8_t* buffer); + +/** + * \brief Save the contents of a VHD sparse header from a buffer to a struct + * + * \param [out] header save contents of buffer into header + * \param [in] buffer VHD header in raw bytes + */ +void mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer); + +/** + * \brief Save the contents of a VHD footer struct to a buffer + * + * \param [in] footer save contents of struct into buffer + * \param [out] buffer VHD footer in raw bytes + */ +void mvhd_footer_to_buffer(MVHDFooter* footer, uint8_t* buffer); + +/** + * \brief Save the contents of a VHD sparse header struct to a buffer + * + * \param [in] header save contents of struct into buffer + * \param [out] buffer VHD sparse header in raw bytes + */ +void mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer); + +#ifdef __cplusplus +} +#endif + + +#endif /*MINIVHD_INTERNAL_H*/ diff --git a/src/disk/minivhd/libxml2_encoding.h b/src/disk/minivhd/libxml2_encoding.h deleted file mode 100644 index d86770b86..000000000 --- a/src/disk/minivhd/libxml2_encoding.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LIBXML2_ENCODING_H -#define LIBXML2_ENCODING_H - -#include -typedef uint16_t mvhd_utf16; - -void xmlEncodingInit(void); -int UTF16LEToUTF8(unsigned char* out, int *outlen, const unsigned char* inb, int *inlenb); -int UTF8ToUTF16LE(unsigned char* outb, int *outlen, const unsigned char* in, int *inlen); -int UTF16BEToUTF8(unsigned char* out, int *outlen, const unsigned char* inb, int *inlenb); -int UTF8ToUTF16BE(unsigned char* outb, int *outlen, const unsigned char* in, int *inlen); -#endif diff --git a/src/disk/minivhd/minivhd_manage.c b/src/disk/minivhd/manage.c similarity index 71% rename from src/disk/minivhd/minivhd_manage.c rename to src/disk/minivhd/manage.c index ce0f31f60..053acc40c 100644 --- a/src/disk/minivhd/minivhd_manage.c +++ b/src/disk/minivhd/manage.c @@ -1,66 +1,105 @@ -/** - * \file - * \brief VHD management functions (open, close, read write etc) +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * VHD management functions (open, close, read write etc) + * + * Version: @(#)manage.c 1.0.4 2021/04/16 + * + * Authors: Sherman Perry, + * Fred N. van Kempen, + * + * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 +# define _FILE_OFFSET_BITS 64 #endif #include #include #include #include #include -#include "cwalk.h" -#include "libxml2_encoding.h" -#include "minivhd_internal.h" -#include "minivhd_io.h" -#include "minivhd_util.h" -#include "minivhd_struct_rw.h" +#include #include "minivhd.h" +#include "internal.h" +#include "version.h" +#include "cwalk.h" +#include "xml2_encoding.h" + -int mvhd_errno = 0; -static char tmp_open_path[MVHD_MAX_PATH_BYTES] = {0}; struct MVHDPaths { - char dir_path[MVHD_MAX_PATH_BYTES]; - char file_name[MVHD_MAX_PATH_BYTES]; - char w2ku_path[MVHD_MAX_PATH_BYTES]; - char w2ru_path[MVHD_MAX_PATH_BYTES]; - char joined_path[MVHD_MAX_PATH_BYTES]; + char dir_path[MVHD_MAX_PATH_BYTES]; + char file_name[MVHD_MAX_PATH_BYTES]; + char w2ku_path[MVHD_MAX_PATH_BYTES]; + char w2ru_path[MVHD_MAX_PATH_BYTES]; + char joined_path[MVHD_MAX_PATH_BYTES]; uint16_t tmp_src_path[MVHD_MAX_PATH_CHARS]; }; -static void mvhd_read_footer(MVHDMeta* vhdm); -static void mvhd_read_sparse_header(MVHDMeta* vhdm); -static bool mvhd_footer_checksum_valid(MVHDMeta* vhdm); -static bool mvhd_sparse_checksum_valid(MVHDMeta* vhdm); -static int mvhd_read_bat(MVHDMeta *vhdm, MVHDError* err); -static void mvhd_calc_sparse_values(MVHDMeta* vhdm); -static int mvhd_init_sector_bitmap(MVHDMeta* vhdm, MVHDError* err); + +int mvhd_errno = 0; + + +static char tmp_open_path[MVHD_MAX_PATH_BYTES] = {0}; + /** * \brief Populate data stuctures with content from a VHD footer * * \param [in] vhdm MiniVHD data structure */ -static void mvhd_read_footer(MVHDMeta* vhdm) { +static void +read_footer(MVHDMeta* vhdm) +{ uint8_t buffer[MVHD_FOOTER_SIZE]; + mvhd_fseeko64(vhdm->f, -MVHD_FOOTER_SIZE, SEEK_END); (void) !fread(buffer, sizeof buffer, 1, vhdm->f); mvhd_buffer_to_footer(&vhdm->footer, buffer); } + /** * \brief Populate data stuctures with content from a VHD sparse header * * \param [in] vhdm MiniVHD data structure */ -static void mvhd_read_sparse_header(MVHDMeta* vhdm) { +static void +read_sparse_header(MVHDMeta* vhdm) +{ uint8_t buffer[MVHD_SPARSE_SIZE]; + mvhd_fseeko64(vhdm->f, vhdm->footer.data_offset, SEEK_SET); (void) !fread(buffer, sizeof buffer, 1, vhdm->f); mvhd_buffer_to_header(&vhdm->sparse, buffer); } + /** * \brief Validate VHD footer checksum * @@ -68,10 +107,13 @@ static void mvhd_read_sparse_header(MVHDMeta* vhdm) { * * \param [in] vhdm MiniVHD data structure */ -static bool mvhd_footer_checksum_valid(MVHDMeta* vhdm) { +static bool +footer_checksum_valid(MVHDMeta* vhdm) +{ return vhdm->footer.checksum == mvhd_gen_footer_checksum(&vhdm->footer); } + /** * \brief Validate VHD sparse header checksum * @@ -79,10 +121,13 @@ static bool mvhd_footer_checksum_valid(MVHDMeta* vhdm) { * * \param [in] vhdm MiniVHD data structure */ -static bool mvhd_sparse_checksum_valid(MVHDMeta* vhdm) { +static bool +sparse_checksum_valid(MVHDMeta* vhdm) +{ return vhdm->sparse.checksum == mvhd_gen_sparse_checksum(&vhdm->sparse); } + /** * \brief Read BAT into MiniVHD data structure * @@ -96,13 +141,17 @@ static bool mvhd_sparse_checksum_valid(MVHDMeta* vhdm) { * \retval -1 if an error occurrs. Check value of err in this case * \retval 0 if the function call succeeds */ -static int mvhd_read_bat(MVHDMeta *vhdm, MVHDError* err) { +static int +read_bat(MVHDMeta *vhdm, MVHDError* err) +{ vhdm->block_offset = calloc(vhdm->sparse.max_bat_ent, sizeof *vhdm->block_offset); if (vhdm->block_offset == NULL) { *err = MVHD_ERR_MEM; return -1; } + mvhd_fseeko64(vhdm->f, vhdm->sparse.bat_offset, SEEK_SET); + for (uint32_t i = 0; i < vhdm->sparse.max_bat_ent; i++) { (void) !fread(&vhdm->block_offset[i], sizeof *vhdm->block_offset, 1, vhdm->f); vhdm->block_offset[i] = mvhd_from_be32(vhdm->block_offset[i]); @@ -110,20 +159,25 @@ static int mvhd_read_bat(MVHDMeta *vhdm, MVHDError* err) { return 0; } + /** * \brief Perform a one-time calculation of some sparse VHD values * * \param [in] vhdm MiniVHD data structure */ -static void mvhd_calc_sparse_values(MVHDMeta* vhdm) { +static void +calc_sparse_values(MVHDMeta* vhdm) +{ vhdm->sect_per_block = vhdm->sparse.block_sz / MVHD_SECTOR_SIZE; int bm_bytes = vhdm->sect_per_block / 8; vhdm->bitmap.sector_count = bm_bytes / MVHD_SECTOR_SIZE; + if (bm_bytes % MVHD_SECTOR_SIZE > 0) { vhdm->bitmap.sector_count++; } } + /** * \brief Allocate memory for a sector bitmap. * @@ -137,16 +191,21 @@ static void mvhd_calc_sparse_values(MVHDMeta* vhdm) { * \retval -1 if an error occurrs. Check value of err in this case * \retval 0 if the function call succeeds */ -static int mvhd_init_sector_bitmap(MVHDMeta* vhdm, MVHDError* err) { +static int +init_sector_bitmap(MVHDMeta* vhdm, MVHDError* err) +{ vhdm->bitmap.curr_bitmap = calloc(vhdm->bitmap.sector_count, MVHD_SECTOR_SIZE); if (vhdm->bitmap.curr_bitmap == NULL) { *err = MVHD_ERR_MEM; return -1; } + vhdm->bitmap.curr_block = -1; + return 0; } + /** * \brief Check if the path for a given platform code exists * @@ -163,13 +222,19 @@ static int mvhd_init_sector_bitmap(MVHDMeta* vhdm, MVHDError* err) { * \retval true if a file is found * \retval false if a file is not found */ -static bool mvhd_parent_path_exists(struct MVHDPaths* paths, uint32_t plat_code) { - memset(paths->joined_path, 0, sizeof paths->joined_path); +static bool +mvhd_parent_path_exists(struct MVHDPaths* paths, uint32_t plat_code) +{ FILE* f; - int cwk_ret, ferr; - enum cwk_path_style style = cwk_path_guess_style((const char*)paths->dir_path); + int ferr; + size_t cwk_ret; + enum cwk_path_style style; + + memset(paths->joined_path, 0, sizeof paths->joined_path); + style = cwk_path_guess_style((const char*)paths->dir_path); cwk_path_set_style(style); cwk_ret = 1; + if (plat_code == MVHD_DIF_LOC_W2RU && *paths->w2ru_path) { cwk_ret = cwk_path_join((const char*)paths->dir_path, (const char*)paths->w2ru_path, paths->joined_path, sizeof paths->joined_path); } else if (plat_code == MVHD_DIF_LOC_W2KU && *paths->w2ku_path) { @@ -181,6 +246,7 @@ static bool mvhd_parent_path_exists(struct MVHDPaths* paths, uint32_t plat_code) if (cwk_ret > MVHD_MAX_PATH_BYTES) { return false; } + f = mvhd_fopen((const char*)paths->joined_path, "rb", &ferr); if (f != NULL) { /* We found a file at the requested path! */ @@ -188,11 +254,12 @@ static bool mvhd_parent_path_exists(struct MVHDPaths* paths, uint32_t plat_code) tmp_open_path[sizeof tmp_open_path - 1] = '\0'; fclose(f); return true; - } else { - return false; } + + return false; } + /** * \brief attempt to obtain a file path to a file that may be a valid VHD image * @@ -208,27 +275,33 @@ static bool mvhd_parent_path_exists(struct MVHDPaths* paths, uint32_t plat_code) * \return a pointer to the global string `tmp_open_path`, or NULL if a path could * not be found, or some error occurred */ -static char* mvhd_get_diff_parent_path(MVHDMeta* vhdm, int* err) { +static char* +get_diff_parent_path(MVHDMeta* vhdm, int* err) +{ int utf_outlen, utf_inlen, utf_ret; - char* par_fp = NULL; + char *par_fp = NULL; + struct MVHDPaths *paths; + size_t dirlen; + /* We can't resolve relative paths if we don't have an absolute path to work with */ if (!cwk_path_is_absolute((const char*)vhdm->filename)) { *err = MVHD_ERR_PATH_REL; goto end; } - struct MVHDPaths* paths = calloc(1, sizeof *paths); + + paths = calloc(1, sizeof *paths); if (paths == NULL) { *err = MVHD_ERR_MEM; goto end; } - size_t dirlen; cwk_path_get_dirname((const char*)vhdm->filename, &dirlen); if (dirlen >= sizeof paths->dir_path) { *err = MVHD_ERR_PATH_LEN; goto paths_cleanup; } memcpy(paths->dir_path, vhdm->filename, dirlen); + /* Get the filename field from the sparse header. */ utf_outlen = (int)sizeof paths->file_name; utf_inlen = (int)sizeof vhdm->sparse.par_utf16_name; @@ -237,8 +310,10 @@ static char* mvhd_get_diff_parent_path(MVHDMeta* vhdm, int* err) { mvhd_set_encoding_err(utf_ret, err); goto paths_cleanup; } + /* Now read the parent locator entries, both relative and absolute, if they exist */ unsigned char* loc_path; + for (int i = 0; i < 8; i++) { utf_outlen = MVHD_MAX_PATH_BYTES - 1; if (vhdm->sparse.par_loc_entry[i].plat_code == MVHD_DIF_LOC_W2RU) { @@ -248,6 +323,7 @@ static char* mvhd_get_diff_parent_path(MVHDMeta* vhdm, int* err) { } else { continue; } + utf_inlen = vhdm->sparse.par_loc_entry[i].plat_data_len; if (utf_inlen > MVHD_MAX_PATH_BYTES) { *err = MVHD_ERR_PATH_LEN; @@ -255,6 +331,7 @@ static char* mvhd_get_diff_parent_path(MVHDMeta* vhdm, int* err) { } mvhd_fseeko64(vhdm->f, vhdm->sparse.par_loc_entry[i].plat_data_offset, SEEK_SET); (void) !fread(paths->tmp_src_path, sizeof (uint8_t), utf_inlen, vhdm->f); + /* Note, the W2*u parent locators are UTF-16LE, unlike the filename field previously obtained, which is UTF-16BE */ utf_ret = UTF16LEToUTF8(loc_path, &utf_outlen, (const unsigned char*)paths->tmp_src_path, &utf_inlen); @@ -263,22 +340,26 @@ static char* mvhd_get_diff_parent_path(MVHDMeta* vhdm, int* err) { goto paths_cleanup; } } + /* We have paths in UTF-8. We should have enough info to try and find the parent VHD */ /* Does the relative path exist? */ if (mvhd_parent_path_exists(paths, MVHD_DIF_LOC_W2RU)) { par_fp = tmp_open_path; goto paths_cleanup; } + /* What about trying the child directory? */ if (mvhd_parent_path_exists(paths, 0)) { par_fp = tmp_open_path; goto paths_cleanup; } + /* Well, all else fails, try the stored absolute path, if it exists */ if (mvhd_parent_path_exists(paths, MVHD_DIF_LOC_W2KU)) { par_fp = tmp_open_path; goto paths_cleanup; } + /* If we reach this point, we could not find a path with a valid file */ par_fp = NULL; *err = MVHD_ERR_PAR_NOT_FOUND; @@ -286,10 +367,12 @@ static char* mvhd_get_diff_parent_path(MVHDMeta* vhdm, int* err) { paths_cleanup: free(paths); paths = NULL; + end: return par_fp; } + /** * \brief Attach the read/write function pointers to read/write functions * @@ -298,44 +381,90 @@ end: * * \param [in] vhdm MiniVHD data structure */ -static void mvhd_assign_io_funcs(MVHDMeta* vhdm) { +static void +assign_io_funcs(MVHDMeta* vhdm) +{ switch (vhdm->footer.disk_type) { - case MVHD_TYPE_FIXED: - vhdm->read_sectors = mvhd_fixed_read; - vhdm->write_sectors = mvhd_fixed_write; - break; - case MVHD_TYPE_DYNAMIC: - vhdm->read_sectors = mvhd_sparse_read; - vhdm->write_sectors = mvhd_sparse_diff_write; - break; - case MVHD_TYPE_DIFF: - vhdm->read_sectors = mvhd_diff_read; - vhdm->write_sectors = mvhd_sparse_diff_write; - break; + case MVHD_TYPE_FIXED: + vhdm->read_sectors = mvhd_fixed_read; + vhdm->write_sectors = mvhd_fixed_write; + break; + + case MVHD_TYPE_DYNAMIC: + vhdm->read_sectors = mvhd_sparse_read; + vhdm->write_sectors = mvhd_sparse_diff_write; + break; + + case MVHD_TYPE_DIFF: + vhdm->read_sectors = mvhd_diff_read; + vhdm->write_sectors = mvhd_sparse_diff_write; + break; } - if (vhdm->readonly) { + + if (vhdm->readonly) vhdm->write_sectors = mvhd_noop_write; - } } -bool mvhd_file_is_vhd(FILE* f) { - if (f) { - uint8_t con_str[8]; - mvhd_fseeko64(f, -MVHD_FOOTER_SIZE, SEEK_END); - (void) !fread(con_str, sizeof con_str, 1, f); - return mvhd_is_conectix_str(con_str); - } else { - return false; - } + +/** + * \brief Return the library version as a string + */ +MVHDAPI const char * +mvhd_version(void) +{ + return LIB_VERSION_4; } -MVHDGeom mvhd_calculate_geometry(uint64_t size) { + +/** + * \brief Return the library version as a number + */ +MVHDAPI uint32_t +mvhd_version_id(void) +{ + return (LIB_VER_MAJOR << 24) | (LIB_VER_MINOR << 16) | + (LIB_VER_REV << 16) | LIB_VER_PATCH; +} + + +/** + * \brief A simple test to see if a given file is a VHD + * + * \param [in] f file to test + * + * \retval 1 if f is a VHD + * \retval 0 if f is not a VHD + */ +MVHDAPI int +mvhd_file_is_vhd(FILE* f) +{ + uint8_t con_str[8]; + + if (f == NULL) { + return 0; + } + + mvhd_fseeko64(f, -MVHD_FOOTER_SIZE, SEEK_END); + fread(con_str, sizeof con_str, 1, f); + if (mvhd_is_conectix_str(con_str)) { + return 1; + } + + return 0; +} + + +MVHDAPI MVHDGeom +mvhd_calculate_geometry(uint64_t size) +{ MVHDGeom chs; uint32_t ts = (uint32_t)(size / MVHD_SECTOR_SIZE); uint32_t spt, heads, cyl, cth; + if (ts > 65535 * 16 * 255) { ts = 65535 * 16 * 255; } + if (ts >= 65535 * 16 * 63) { spt = 255; heads = 16; @@ -358,77 +487,95 @@ MVHDGeom mvhd_calculate_geometry(uint64_t size) { cth = ts / spt; } } + cyl = cth / heads; chs.heads = heads; chs.spt = spt; chs.cyl = cyl; + return chs; } -MVHDMeta* mvhd_open(const char* path, bool readonly, int* err) { + +MVHDAPI MVHDMeta* +mvhd_open(const char* path, int readonly, int* err) +{ MVHDError open_err; + MVHDMeta *vhdm = calloc(sizeof *vhdm, 1); if (vhdm == NULL) { *err = MVHD_ERR_MEM; goto end; } + if (strlen(path) >= sizeof vhdm->filename) { *err = MVHD_ERR_PATH_LEN; goto cleanup_vhdm; } + //This is safe, as we've just checked for potential overflow above strcpy(vhdm->filename, path); - vhdm->f = readonly ? mvhd_fopen((const char*)vhdm->filename, "rb", err) : mvhd_fopen((const char*)vhdm->filename, "rb+", err); + + if (readonly) { + vhdm->f = mvhd_fopen((const char*)vhdm->filename, "rb", err); + } else { + vhdm->f = mvhd_fopen((const char*)vhdm->filename, "rb+", err); + } if (vhdm->f == NULL) { /* note, mvhd_fopen sets err for us */ goto cleanup_vhdm; } vhdm->readonly = readonly; + if (!mvhd_file_is_vhd(vhdm->f)) { *err = MVHD_ERR_NOT_VHD; goto cleanup_file; } - mvhd_read_footer(vhdm); - if (!mvhd_footer_checksum_valid(vhdm)) { + + read_footer(vhdm); + if (!footer_checksum_valid(vhdm)) { *err = MVHD_ERR_FOOTER_CHECKSUM; goto cleanup_file; } if (vhdm->footer.disk_type == MVHD_TYPE_DIFF || vhdm->footer.disk_type == MVHD_TYPE_DYNAMIC) { - mvhd_read_sparse_header(vhdm); - if (!mvhd_sparse_checksum_valid(vhdm)) { + read_sparse_header(vhdm); + if (!sparse_checksum_valid(vhdm)) { *err = MVHD_ERR_SPARSE_CHECKSUM; goto cleanup_file; } - if (mvhd_read_bat(vhdm, &open_err) == -1) { + if (read_bat(vhdm, &open_err) == -1) { *err = open_err; goto cleanup_file; } - mvhd_calc_sparse_values(vhdm); - if (mvhd_init_sector_bitmap(vhdm, &open_err) == -1) { + calc_sparse_values(vhdm); + if (init_sector_bitmap(vhdm, &open_err) == -1) { *err = open_err; goto cleanup_bat; } - } else if (vhdm->footer.disk_type != MVHD_TYPE_FIXED) { *err = MVHD_ERR_TYPE; goto cleanup_bitmap; } - mvhd_assign_io_funcs(vhdm); + assign_io_funcs(vhdm); + vhdm->format_buffer.zero_data = calloc(64, MVHD_SECTOR_SIZE); if (vhdm->format_buffer.zero_data == NULL) { *err = MVHD_ERR_MEM; goto cleanup_bitmap; } + vhdm->format_buffer.sector_count = 64; if (vhdm->footer.disk_type == MVHD_TYPE_DIFF) { - char* par_path = mvhd_get_diff_parent_path(vhdm, err); + char* par_path = get_diff_parent_path(vhdm, err); if (par_path == NULL) { goto cleanup_format_buff; } + uint32_t par_mod_ts = mvhd_file_mod_timestamp(par_path, err); if (*err != 0) { goto cleanup_format_buff; } + if (vhdm->sparse.par_timestamp != par_mod_ts) { /* The last-modified timestamp is to fragile to make this a fatal error. Instead, we inform the caller of the potential problem. */ @@ -438,57 +585,78 @@ MVHDMeta* mvhd_open(const char* path, bool readonly, int* err) { if (vhdm->parent == NULL) { goto cleanup_format_buff; } + if (memcmp(vhdm->sparse.par_uuid, vhdm->parent->footer.uuid, sizeof vhdm->sparse.par_uuid) != 0) { *err = MVHD_ERR_INVALID_PAR_UUID; goto cleanup_format_buff; } } - /* If we've reached this point, we are good to go, so skip the cleanup steps */ + + /* + * If we've reached this point, we are good to go, + * so skip the cleanup steps. + */ goto end; + cleanup_format_buff: free(vhdm->format_buffer.zero_data); vhdm->format_buffer.zero_data = NULL; + cleanup_bitmap: free(vhdm->bitmap.curr_bitmap); vhdm->bitmap.curr_bitmap = NULL; + cleanup_bat: free(vhdm->block_offset); vhdm->block_offset = NULL; + cleanup_file: fclose(vhdm->f); vhdm->f = NULL; + cleanup_vhdm: free(vhdm); vhdm = NULL; + end: return vhdm; } -void mvhd_close(MVHDMeta* vhdm) { - if (vhdm != NULL) { - if (vhdm->parent != NULL) { - mvhd_close(vhdm->parent); - } - fclose(vhdm->f); - if (vhdm->block_offset != NULL) { - free(vhdm->block_offset); - vhdm->block_offset = NULL; - } - if (vhdm->bitmap.curr_bitmap != NULL) { - free(vhdm->bitmap.curr_bitmap); - vhdm->bitmap.curr_bitmap = NULL; - } - if (vhdm->format_buffer.zero_data != NULL) { - free(vhdm->format_buffer.zero_data); - vhdm->format_buffer.zero_data = NULL; - } - free(vhdm); - vhdm = NULL; + +MVHDAPI void +mvhd_close(MVHDMeta* vhdm) +{ + if (vhdm == NULL) + return; + + if (vhdm->parent != NULL) { + mvhd_close(vhdm->parent); } + + fclose(vhdm->f); + + if (vhdm->block_offset != NULL) { + free(vhdm->block_offset); + vhdm->block_offset = NULL; + } + if (vhdm->bitmap.curr_bitmap != NULL) { + free(vhdm->bitmap.curr_bitmap); + vhdm->bitmap.curr_bitmap = NULL; + } + if (vhdm->format_buffer.zero_data != NULL) { + free(vhdm->format_buffer.zero_data); + vhdm->format_buffer.zero_data = NULL; + } + + free(vhdm); } -int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err) { + +MVHDAPI int +mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err) +{ uint8_t sparse_buff[1024]; + if (vhdm == NULL || err == NULL) { *err = MVHD_ERR_INVALID_PARAMS; return -1; @@ -497,7 +665,7 @@ int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err) { *err = MVHD_ERR_TYPE; return -1; } - char* par_path = mvhd_get_diff_parent_path(vhdm, err); + char* par_path = get_diff_parent_path(vhdm, err); if (par_path == NULL) { return -1; } @@ -505,31 +673,53 @@ int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err) { if (*err != 0) { return -1; } + /* Update the timestamp and sparse header checksum */ vhdm->sparse.par_timestamp = par_mod_ts; vhdm->sparse.checksum = mvhd_gen_sparse_checksum(&vhdm->sparse); + /* Generate and write the updated sparse header */ mvhd_header_to_buffer(&vhdm->sparse, sparse_buff); mvhd_fseeko64(vhdm->f, (int64_t)vhdm->footer.data_offset, SEEK_SET); fwrite(sparse_buff, sizeof sparse_buff, 1, vhdm->f); + return 0; } -int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) { + +MVHDAPI int +mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) +{ return vhdm->read_sectors(vhdm, offset, num_sectors, out_buff); } -int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) { + +MVHDAPI int +mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) +{ return vhdm->write_sectors(vhdm, offset, num_sectors, in_buff); } -int mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors) { + +MVHDAPI int +mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors) +{ int num_full = num_sectors / vhdm->format_buffer.sector_count; int remain = num_sectors % vhdm->format_buffer.sector_count; + for (int i = 0; i < num_full; i++) { vhdm->write_sectors(vhdm, offset, vhdm->format_buffer.sector_count, vhdm->format_buffer.zero_data); offset += vhdm->format_buffer.sector_count; } + vhdm->write_sectors(vhdm, offset, remain, vhdm->format_buffer.zero_data); + return 0; } + + +MVHDAPI MVHDType +mvhd_get_type(MVHDMeta* vhdm) +{ + return vhdm->footer.disk_type; +} diff --git a/src/disk/minivhd/minivhd.h b/src/disk/minivhd/minivhd.h index df3a24bb3..929ea5b27 100644 --- a/src/disk/minivhd/minivhd.h +++ b/src/disk/minivhd/minivhd.h @@ -1,11 +1,49 @@ +/* + * MiniVHD Minimalist VHD implementation in C. + * MiniVHD is a minimalist implementation of read/write/creation + * of VHD files. It is designed to read and write to VHD files + * at a sector level. It does not enable file access, or provide + * mounting options. Those features are left to more advanced + * libraries and/or the operating system. + * + * This file is part of the MiniVHD Project. + * + * Definitions for the MiniVHD library. + * + * Version: @(#)minivhd.h 1.0.3 2021/04/16 + * + * Authors: Sherman Perry, + * Fred N. van Kempen, + * + * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ #ifndef MINIVHD_H -#define MINIVHD_H +# define MINIVHD_H -#include -#include -#include - -extern int mvhd_errno; typedef enum MVHDError { MVHD_ERR_MEM = -128, @@ -46,6 +84,11 @@ typedef struct MVHDGeom { uint8_t spt; } MVHDGeom; + +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*mvhd_progress_callback)(uint32_t current_sector, uint32_t total_sectors); typedef struct MVHDCreationOptions { @@ -60,6 +103,42 @@ typedef struct MVHDCreationOptions { typedef struct MVHDMeta MVHDMeta; + +extern int mvhd_errno; + + +/* Shared-library madness. */ +//#if defined(_WIN32) +//# ifdef STATIC +# define MVHDAPI /*nothing*/ +//# else +//# ifdef BUILDING_LIBRARY +//# define MVHDAPI __declspec(dllexport) +//# else +//# define MVHDAPI __declspec(dllimport) +//# endif +//# endif +//#elif defined(__GNUC__) +//# ifdef BUILDING_LIBRARY +//# define MVHDAPI __attribute__((visibility("default"))) +//# else +//# define MVHDAPI /*nothing*/ +//# endif +//#else +//# define MVHDAPI /*nothing*/ +//#endif + + +/** + * \brief Return the library version as a string + */ +MVHDAPI const char *mvhd_version(void); + +/** + * \brief Return the library version as a number + */ +MVHDAPI uint32_t mvhd_version_id(void); + /** * \brief Output a string from a MiniVHD error number * @@ -67,17 +146,26 @@ typedef struct MVHDMeta MVHDMeta; * * \return Error string */ -const char* mvhd_strerr(MVHDError err); +MVHDAPI const char* mvhd_strerr(MVHDError err); /** * \brief A simple test to see if a given file is a VHD * * \param [in] f file to test * - * \retval true if f is a VHD - * \retval false if f is not a VHD + * \retval 1 if f is a VHD + * \retval 0 if f is not a VHD */ -bool mvhd_file_is_vhd(FILE* f); +MVHDAPI int mvhd_file_is_vhd(FILE* f); + +/** + * \brief Return the file type of the given file + * + * \param [in] vhdm VHD to check. + * + * \retval one of the defined MVHDType values + */ +MVHDAPI MVHDType mvhd_get_type(MVHDMeta* vhdm); /** * \brief Open a VHD image for reading and/or writing @@ -89,7 +177,7 @@ bool mvhd_file_is_vhd(FILE* f); * * \param [in] Absolute path to VHD file. Relative path will cause issues when opening * a differencing VHD file - * \param [in] readonly set this to true to open the VHD in a read only manner + * \param [in] readonly set this to 1 to open the VHD in a read only manner * \param [out] err will be set if the VHD fails to open. Value could be one of * MVHD_ERR_MEM, MVHD_ERR_FILE, MVHD_ERR_NOT_VHD, MVHD_ERR_FOOTER_CHECKSUM, MVHD_ERR_SPARSE_CHECKSUM, * MVHD_ERR_TYPE, MVHD_ERR_TIMESTAMP @@ -98,7 +186,7 @@ bool mvhd_file_is_vhd(FILE* f); * \return MVHDMeta pointer. If NULL, check err. err may also be set to MVHD_ERR_TIMESTAMP if * opening a differencing VHD. */ -MVHDMeta* mvhd_open(const char* path, bool readonly, int* err); +MVHDAPI MVHDMeta* mvhd_open(const char* path, int readonly, int* err); /** * \brief Update the parent modified timestamp in the VHD file @@ -116,7 +204,7 @@ MVHDMeta* mvhd_open(const char* path, bool readonly, int* err); * * \return non-zero on error, 0 on success */ -int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err); +MVHDAPI int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err); /** * \brief Create a fixed VHD image @@ -128,7 +216,7 @@ int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err); * * \retval NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_progress_callback progress_callback); +MVHDAPI MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_progress_callback progress_callback); /** * \brief Create sparse (dynamic) VHD image. @@ -139,7 +227,7 @@ MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_prog * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHDMeta* mvhd_create_sparse(const char* path, MVHDGeom geom, int* err); +MVHDAPI MVHDMeta* mvhd_create_sparse(const char* path, MVHDGeom geom, int* err); /** * \brief Create differencing VHD imagee. @@ -150,7 +238,7 @@ MVHDMeta* mvhd_create_sparse(const char* path, MVHDGeom geom, int* err); * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHDMeta* mvhd_create_diff(const char* path, const char* par_path, int* err); +MVHDAPI MVHDMeta* mvhd_create_diff(const char* path, const char* par_path, int* err); /** * \brief Create a VHD using the provided options @@ -162,14 +250,14 @@ MVHDMeta* mvhd_create_diff(const char* path, const char* par_path, int* err); * * \retval NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHDMeta* mvhd_create_ex(MVHDCreationOptions options, int* err); +MVHDAPI MVHDMeta* mvhd_create_ex(MVHDCreationOptions options, int* err); /** * \brief Safely close a VHD image * * \param [in] vhdm MiniVHD data structure to close */ -void mvhd_close(MVHDMeta* vhdm); +MVHDAPI void mvhd_close(MVHDMeta* vhdm); /** * \brief Calculate hard disk geometry from a provided size @@ -189,7 +277,47 @@ void mvhd_close(MVHDMeta* vhdm); * * \return MVHDGeom the calculated geometry. This can be used in the appropriate create functions. */ -MVHDGeom mvhd_calculate_geometry(uint64_t size); +MVHDAPI MVHDGeom mvhd_calculate_geometry(uint64_t size); + +/** + * \brief Get the CHS geometry from the image + * + * \param [in] vhdm MiniVHD data structure + * + * \return The CHS geometry as stored in the image + */ +MVHDAPI MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm); + +/** + * \brief Get the 'current_size' value from the image + * + * Note that the size returned may not match the size calculated from the + * CHS geometry. It is up to the caller to decide how best to handle this. + * + * \param [in] vhdm MiniVHD data structure + * + * \return The 'current_size' value in bytes, as stored in the image. + * Note, this may not match the CHS geometry. + */ +MVHDAPI uint64_t mvhd_get_current_size(MVHDMeta* vhdm); + +/** + * \brief Calculate CHS geometry size in bytes + * + * \param [in] geom the CHS geometry to calculate + * + * \return the size in bytes + */ +MVHDAPI uint64_t mvhd_calc_size_bytes(MVHDGeom *geom); + +/** + * \brief Calculate CHS geometry size in sectors + * + * \param [in] geom the CHS geometry to calculate + * + * \return the size in sectors + */ +MVHDAPI uint32_t mvhd_calc_size_sectors(MVHDGeom *geom); /** * \brief Convert a raw disk image to a fixed VHD image @@ -200,7 +328,7 @@ MVHDGeom mvhd_calculate_geometry(uint64_t size); * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHDMeta* mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); +MVHDAPI MVHDMeta* mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); /** * \brief Convert a raw disk image to a sparse VHD image @@ -211,7 +339,7 @@ MVHDMeta* mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_ * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); +MVHDAPI MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); /** * \brief Convert a VHD image to a raw disk image @@ -222,7 +350,7 @@ MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8 * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns the raw disk image FILE pointer */ -FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, int *err); +MVHDAPI FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, int *err); /** * \brief Read sectors from VHD file @@ -236,7 +364,7 @@ FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, * * \return the number of sectors that were not read, or zero */ -int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); +MVHDAPI int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); /** * \brief Write sectors to VHD file @@ -250,7 +378,7 @@ int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* ou * * \return the number of sectors that were not written, or zero */ -int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); +MVHDAPI int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); /** * \brief Write zeroed sectors to VHD file @@ -265,5 +393,11 @@ int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* i * * \return the number of sectors that were not written, or zero */ -int mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors); +MVHDAPI int mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors); + +#ifdef __cplusplus +} #endif + + +#endif /*MINIVHD_H*/ diff --git a/src/disk/minivhd/minivhd_create.h b/src/disk/minivhd/minivhd_create.h deleted file mode 100644 index 203834a71..000000000 --- a/src/disk/minivhd/minivhd_create.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef MINIVHD_CREATE_H -#define MINIVHD_CREATE_H -#include -#include "minivhd.h" - -MVHDMeta* mvhd_create_fixed_raw(const char* path, FILE* raw_img, uint64_t size_in_bytes, MVHDGeom* geom, int* err, mvhd_progress_callback progress_callback); - -#endif diff --git a/src/disk/minivhd/minivhd_internal.h b/src/disk/minivhd/minivhd_internal.h deleted file mode 100644 index 54b304830..000000000 --- a/src/disk/minivhd/minivhd_internal.h +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef MINIVHD_INTERNAL_H -#define MINIVHD_INTERNAL_H -#include -#include -#include - -#define MVHD_FOOTER_SIZE 512 -#define MVHD_SPARSE_SIZE 1024 - -#define MVHD_SECTOR_SIZE 512 -#define MVHD_BAT_ENT_PER_SECT 128 - -#define MVHD_MAX_SIZE_IN_BYTES 0x1fe00000000 - -#define MVHD_SPARSE_BLK 0xffffffff -/* For simplicity, we don't handle paths longer than this - * Note, this is the max path in characters, as that is what - * Windows uses - */ -#define MVHD_MAX_PATH_CHARS 260 -#define MVHD_MAX_PATH_BYTES 1040 - -#define MVHD_DIF_LOC_W2RU 0x57327275 -#define MVHD_DIF_LOC_W2KU 0x57326B75 - -typedef struct MVHDSectorBitmap { - uint8_t* curr_bitmap; - int sector_count; - int curr_block; -} MVHDSectorBitmap; - -typedef struct MVHDFooter { - uint8_t cookie[8]; - uint32_t features; - uint32_t fi_fmt_vers; - uint64_t data_offset; - uint32_t timestamp; - uint8_t cr_app[4]; - uint32_t cr_vers; - uint8_t cr_host_os[4]; - uint64_t orig_sz; - uint64_t curr_sz; - struct { - uint16_t cyl; - uint8_t heads; - uint8_t spt; - } geom; - uint32_t disk_type; - uint32_t checksum; - uint8_t uuid[16]; - uint8_t saved_st; - uint8_t reserved[427]; -} MVHDFooter; - -typedef struct MVHDSparseHeader { - uint8_t cookie[8]; - uint64_t data_offset; - uint64_t bat_offset; - uint32_t head_vers; - uint32_t max_bat_ent; - uint32_t block_sz; - uint32_t checksum; - uint8_t par_uuid[16]; - uint32_t par_timestamp; - uint32_t reserved_1; - uint8_t par_utf16_name[512]; - struct { - uint32_t plat_code; - uint32_t plat_data_space; - uint32_t plat_data_len; - uint32_t reserved; - uint64_t plat_data_offset; - } par_loc_entry[8]; - uint8_t reserved_2[256]; -} MVHDSparseHeader; - -typedef struct MVHDMeta MVHDMeta; -struct MVHDMeta { - FILE* f; - bool readonly; - char filename[MVHD_MAX_PATH_BYTES]; - struct MVHDMeta* parent; - MVHDFooter footer; - MVHDSparseHeader sparse; - uint32_t* block_offset; - int sect_per_block; - MVHDSectorBitmap bitmap; - int (*read_sectors)(MVHDMeta*, uint32_t, int, void*); - int (*write_sectors)(MVHDMeta*, uint32_t, int, void*); - struct { - uint8_t* zero_data; - int sector_count; - } format_buffer; -}; - -#endif diff --git a/src/disk/minivhd/minivhd_io.c b/src/disk/minivhd/minivhd_io.c index 63017bbf8..ff86a8337 100644 --- a/src/disk/minivhd/minivhd_io.c +++ b/src/disk/minivhd/minivhd_io.c @@ -1,28 +1,61 @@ -/** - * \file - * \brief Sector reading and writing implementations +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Sector reading and writing implementations. + * + * Version: @(#)io.c 1.0.3 2021/04/16 + * + * Author: Sherman Perry, + * + * Copyright 2019-2021 Sherman Perry. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ - #ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 +# define _FILE_OFFSET_BITS 64 #endif +#include +#include #include +#include #include -#include "minivhd_internal.h" -#include "minivhd_util.h" +#include +#include "minivhd.h" +#include "internal.h" -/* The following bit array macros adapted from - http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html */ -#define VHD_SETBIT(A,k) ( A[(k/8)] |= (0x80 >> (k%8)) ) -#define VHD_CLEARBIT(A,k) ( A[(k/8)] &= ~(0x80 >> (k%8)) ) -#define VHD_TESTBIT(A,k) ( A[(k/8)] & (0x80 >> (k%8)) ) +/* + * The following bit array macros adapted from: + * + * http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html + */ +#define VHD_SETBIT(A,k) ( A[(k>>3)] |= (0x80 >> (k&7)) ) +#define VHD_CLEARBIT(A,k) ( A[(k>>3)] &= ~(0x80 >> (k&7)) ) +#define VHD_TESTBIT(A,k) ( A[(k>>3)] & (0x80 >> (k&7)) ) -static inline void mvhd_check_sectors(uint32_t offset, int num_sectors, uint32_t total_sectors, int* transfer_sect, int* trunc_sect); -static void mvhd_read_sect_bitmap(MVHDMeta* vhdm, int blk); -static void mvhd_write_bat_entry(MVHDMeta* vhdm, int blk); -static void mvhd_create_block(MVHDMeta* vhdm, int blk); -static void mvhd_write_curr_sect_bitmap(MVHDMeta* vhdm); /** * \brief Check that we will not be overflowing buffers @@ -34,22 +67,30 @@ static void mvhd_write_curr_sect_bitmap(MVHDMeta* vhdm); * This may be lower than num_sectors if offset + num_sectors >= total_sectors * \param [out] trunc_sectors The number of sectors truncated if transfer_sectors < num_sectors */ -static inline void mvhd_check_sectors(uint32_t offset, int num_sectors, uint32_t total_sectors, int* transfer_sect, int* trunc_sect) { +static inline void +check_sectors(uint32_t offset, int num_sectors, uint32_t total_sectors, int* transfer_sect, int* trunc_sect) +{ *transfer_sect = num_sectors; *trunc_sect = 0; + if ((total_sectors - offset) < (uint32_t)*transfer_sect) { *transfer_sect = total_sectors - offset; *trunc_sect = num_sectors - *transfer_sect; } } -void mvhd_write_empty_sectors(FILE* f, int sector_count) { + +void +mvhd_write_empty_sectors(FILE* f, int sector_count) +{ uint8_t zero_bytes[MVHD_SECTOR_SIZE] = {0}; + for (int i = 0; i < sector_count; i++) { fwrite(zero_bytes, sizeof zero_bytes, 1, f); } } + /** * \brief Read the sector bitmap for a block. * @@ -59,22 +100,28 @@ void mvhd_write_empty_sectors(FILE* f, int sector_count) { * \param [in] vhdm MiniVHD data structure * \param [in] blk The block for which to read the sector bitmap from */ -static void mvhd_read_sect_bitmap(MVHDMeta* vhdm, int blk) { +static void +read_sect_bitmap(MVHDMeta* vhdm, int blk) +{ if (vhdm->block_offset[blk] != MVHD_SPARSE_BLK) { mvhd_fseeko64(vhdm->f, (uint64_t)vhdm->block_offset[blk] * MVHD_SECTOR_SIZE, SEEK_SET); (void) !fread(vhdm->bitmap.curr_bitmap, vhdm->bitmap.sector_count * MVHD_SECTOR_SIZE, 1, vhdm->f); } else { memset(vhdm->bitmap.curr_bitmap, 0, vhdm->bitmap.sector_count * MVHD_SECTOR_SIZE); } + vhdm->bitmap.curr_block = blk; } + /** * \brief Write the current sector bitmap in memory to file * * \param [in] vhdm MiniVHD data structure */ -static void mvhd_write_curr_sect_bitmap(MVHDMeta* vhdm) { +static void +write_curr_sect_bitmap(MVHDMeta* vhdm) +{ if (vhdm->bitmap.curr_block >= 0) { int64_t abs_offset = (int64_t)vhdm->block_offset[vhdm->bitmap.curr_block] * MVHD_SECTOR_SIZE; mvhd_fseeko64(vhdm->f, abs_offset, SEEK_SET); @@ -82,19 +129,24 @@ static void mvhd_write_curr_sect_bitmap(MVHDMeta* vhdm) { } } + /** * \brief Write block offset from memory into file * * \param [in] vhdm MiniVHD data structure * \param [in] blk The block for which to write the offset for */ -static void mvhd_write_bat_entry(MVHDMeta* vhdm, int blk) { +static void +write_bat_entry(MVHDMeta* vhdm, int blk) +{ uint64_t table_offset = vhdm->sparse.bat_offset + ((uint64_t)blk * sizeof *vhdm->block_offset); uint32_t offset = mvhd_to_be32(vhdm->block_offset[blk]); + mvhd_fseeko64(vhdm->f, table_offset, SEEK_SET); fwrite(&offset, sizeof offset, 1, vhdm->f); } + /** * \brief Create an empty block in a sparse or differencing VHD image * @@ -109,18 +161,23 @@ static void mvhd_write_bat_entry(MVHDMeta* vhdm, int blk) { * \param [in] vhdm MiniVHD data structure * \param [in] blk The block number to create */ -static void mvhd_create_block(MVHDMeta* vhdm, int blk) { +static void +create_block(MVHDMeta* vhdm, int blk) +{ uint8_t footer[MVHD_FOOTER_SIZE]; + /* Seek to where the footer SHOULD be */ mvhd_fseeko64(vhdm->f, -MVHD_FOOTER_SIZE, SEEK_END); (void) !fread(footer, sizeof footer, 1, vhdm->f); mvhd_fseeko64(vhdm->f, -MVHD_FOOTER_SIZE, SEEK_END); + if (!mvhd_is_conectix_str(footer)) { /* Oh dear. We use the header instead, since something has gone wrong at the footer */ mvhd_fseeko64(vhdm->f, 0, SEEK_SET); (void) !fread(footer, sizeof footer, 1, vhdm->f); mvhd_fseeko64(vhdm->f, 0, SEEK_END); } + int64_t abs_offset = mvhd_ftello64(vhdm->f); if (abs_offset % MVHD_SECTOR_SIZE != 0) { /* Yikes! We're supposed to be on a sector boundary. Add some padding */ @@ -131,52 +188,68 @@ static void mvhd_create_block(MVHDMeta* vhdm, int blk) { } abs_offset += padding_amount; } + uint32_t sect_offset = (uint32_t)(abs_offset / MVHD_SECTOR_SIZE); int blk_size_sectors = vhdm->sparse.block_sz / MVHD_SECTOR_SIZE; mvhd_write_empty_sectors(vhdm->f, vhdm->bitmap.sector_count + blk_size_sectors); + /* Add a bit of padding. That's what Windows appears to do, although it's not strictly necessary... */ mvhd_write_empty_sectors(vhdm->f, 5); + /* And we finish with the footer */ fwrite(footer, sizeof footer, 1, vhdm->f); + /* We no longer have a sparse block. Update that BAT! */ vhdm->block_offset[blk] = sect_offset; - mvhd_write_bat_entry(vhdm, blk); + write_bat_entry(vhdm, blk); } -int mvhd_fixed_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) { + +int +mvhd_fixed_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) { int64_t addr; int transfer_sectors, truncated_sectors; uint32_t total_sectors = (uint32_t)(vhdm->footer.curr_sz / MVHD_SECTOR_SIZE); - mvhd_check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + + check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + addr = (int64_t)offset * MVHD_SECTOR_SIZE; mvhd_fseeko64(vhdm->f, addr, SEEK_SET); (void) !fread(out_buff, transfer_sectors*MVHD_SECTOR_SIZE, 1, vhdm->f); + return truncated_sectors; } -int mvhd_sparse_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) { + +int +mvhd_sparse_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) +{ int transfer_sectors, truncated_sectors; uint32_t total_sectors = (uint32_t)(vhdm->footer.curr_sz / MVHD_SECTOR_SIZE); - mvhd_check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + + check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + uint8_t* buff = (uint8_t*)out_buff; int64_t addr; uint32_t s, ls; int blk, prev_blk, sib; ls = offset + transfer_sectors; prev_blk = -1; + for (s = offset; s < ls; s++) { blk = s / vhdm->sect_per_block; sib = s % vhdm->sect_per_block; if (blk != prev_blk) { prev_blk = blk; if (vhdm->bitmap.curr_block != blk) { - mvhd_read_sect_bitmap(vhdm, blk); + read_sect_bitmap(vhdm, blk); mvhd_fseeko64(vhdm->f, (uint64_t)sib * MVHD_SECTOR_SIZE, SEEK_CUR); } else { addr = ((int64_t)vhdm->block_offset[blk] + vhdm->bitmap.sector_count + sib) * MVHD_SECTOR_SIZE; mvhd_fseeko64(vhdm->f, addr, SEEK_SET); } } + if (VHD_TESTBIT(vhdm->bitmap.curr_bitmap, sib)) { (void) !fread(buff, MVHD_SECTOR_SIZE, 1, vhdm->f); } else { @@ -185,29 +258,37 @@ int mvhd_sparse_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out } buff += MVHD_SECTOR_SIZE; } + return truncated_sectors; } -int mvhd_diff_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) { + +int +mvhd_diff_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) +{ int transfer_sectors, truncated_sectors; uint32_t total_sectors = (uint32_t)(vhdm->footer.curr_sz / MVHD_SECTOR_SIZE); - mvhd_check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + + check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + uint8_t* buff = (uint8_t*)out_buff; MVHDMeta* curr_vhdm = vhdm; uint32_t s, ls; int blk, sib; ls = offset + transfer_sectors; + for (s = offset; s < ls; s++) { while (curr_vhdm->footer.disk_type == MVHD_TYPE_DIFF) { blk = s / curr_vhdm->sect_per_block; sib = s % curr_vhdm->sect_per_block; if (curr_vhdm->bitmap.curr_block != blk) { - mvhd_read_sect_bitmap(curr_vhdm, blk); + read_sect_bitmap(curr_vhdm, blk); } if (!VHD_TESTBIT(curr_vhdm->bitmap.curr_bitmap, sib)) { curr_vhdm = curr_vhdm->parent; } else { break; } } + /* We handle actual sector reading using the fixed or sparse functions, as a differencing VHD is also a sparse VHD */ if (curr_vhdm->footer.disk_type == MVHD_TYPE_DIFF || curr_vhdm->footer.disk_type == MVHD_TYPE_DYNAMIC) { @@ -215,49 +296,65 @@ int mvhd_diff_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_b } else { mvhd_fixed_read(curr_vhdm, s, 1, buff); } + curr_vhdm = vhdm; buff += MVHD_SECTOR_SIZE; } + return truncated_sectors; } -int mvhd_fixed_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) { + +int +mvhd_fixed_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) +{ int64_t addr; int transfer_sectors, truncated_sectors; uint32_t total_sectors = (uint32_t)(vhdm->footer.curr_sz / MVHD_SECTOR_SIZE); - mvhd_check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + + check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + addr = (int64_t)offset * MVHD_SECTOR_SIZE; mvhd_fseeko64(vhdm->f, addr, SEEK_SET); fwrite(in_buff, transfer_sectors*MVHD_SECTOR_SIZE, 1, vhdm->f); + return truncated_sectors; } -int mvhd_sparse_diff_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) { + +int +mvhd_sparse_diff_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) +{ int transfer_sectors, truncated_sectors; uint32_t total_sectors = (uint32_t)(vhdm->footer.curr_sz / MVHD_SECTOR_SIZE); - mvhd_check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + + check_sectors(offset, num_sectors, total_sectors, &transfer_sectors, &truncated_sectors); + uint8_t* buff = (uint8_t*)in_buff; int64_t addr; uint32_t s, ls; int blk, prev_blk, sib; ls = offset + transfer_sectors; prev_blk = -1; + for (s = offset; s < ls; s++) { blk = s / vhdm->sect_per_block; sib = s % vhdm->sect_per_block; if (vhdm->bitmap.curr_block != blk && prev_blk >= 0) { /* Write the sector bitmap for the previous block, before we replace it. */ - mvhd_write_curr_sect_bitmap(vhdm); + write_curr_sect_bitmap(vhdm); } + if (vhdm->block_offset[blk] == MVHD_SPARSE_BLK) { /* "read" the sector bitmap first, before creating a new block, as the bitmap will be zero either way */ - mvhd_read_sect_bitmap(vhdm, blk); - mvhd_create_block(vhdm, blk); + read_sect_bitmap(vhdm, blk); + create_block(vhdm, blk); } + if (blk != prev_blk) { if (vhdm->bitmap.curr_block != blk) { - mvhd_read_sect_bitmap(vhdm, blk); + read_sect_bitmap(vhdm, blk); mvhd_fseeko64(vhdm->f, (uint64_t)sib * MVHD_SECTOR_SIZE, SEEK_CUR); } else { addr = ((int64_t)vhdm->block_offset[blk] + vhdm->bitmap.sector_count + sib) * MVHD_SECTOR_SIZE; @@ -265,15 +362,26 @@ int mvhd_sparse_diff_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, voi } prev_blk = blk; } + fwrite(buff, MVHD_SECTOR_SIZE, 1, vhdm->f); VHD_SETBIT(vhdm->bitmap.curr_bitmap, sib); buff += MVHD_SECTOR_SIZE; } + /* And write the sector bitmap for the last block we visited to disk */ - mvhd_write_curr_sect_bitmap(vhdm); + write_curr_sect_bitmap(vhdm); + return truncated_sectors; } -int mvhd_noop_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) { + +int +mvhd_noop_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) +{ + (void)vhdm; + (void)offset; + (void)num_sectors; + (void)in_buff; + return 0; } diff --git a/src/disk/minivhd/minivhd_io.h b/src/disk/minivhd/minivhd_io.h deleted file mode 100644 index 7ffd10f49..000000000 --- a/src/disk/minivhd/minivhd_io.h +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef MINIVHD_IO_H -#define MINIVHD_IO_H -#include "minivhd.h" - -/** - * \brief Write zero filled sectors to file. - * - * Note, the caller should set the file position before calling this - * function for correct operation. - * - * \param [in] f File to write sectors to - * \param [in] sector_count The number of sectors to write - */ -void mvhd_write_empty_sectors(FILE* f, int sector_count); - -/** - * \brief Read a fixed VHD image - * - * Fixed VHD images are essentially raw image files with a footer tacked on - * the end. They are therefore straightforward to write - * - * \param [in] vhdm MiniVHD data structure - * \param [in] offset Sector offset to read from - * \param [in] num_sectors The desired number of sectors to read - * \param [out] out_buff An output buffer to store read sectors. Must be - * large enough to hold num_sectors worth of sectors. - * - * \retval 0 num_sectors were read from file - * \retval >0 < num_sectors were read from file - */ -int mvhd_fixed_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); - -/** - * \brief Read a sparse VHD image - * - * Sparse, or dynamic images are VHD images that grow as data is written to them. - * - * This function implements the logic to read sectors from the file, taking into - * account the fact that blocks may be stored on disk in any order, and that the - * read could cross block boundaries. - * - * \param [in] vhdm MiniVHD data structure - * \param [in] offset Sector offset to read from - * \param [in] num_sectors The desired number of sectors to read - * \param [out] out_buff An output buffer to store read sectors. Must be - * large enough to hold num_sectors worth of sectors. - * - * \retval 0 num_sectors were read from file - * \retval >0 < num_sectors were read from file - */ -int mvhd_sparse_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); - -/** - * \brief Read a differencing VHD image - * - * Differencing images are a variant of a sparse image. They contain the grow-on-demand - * properties of sparse images, but also reference a parent image. Data is read from the - * child image only if it is newer than the data stored in the parent image. - * - * This function implements the logic to read sectors from the child, or a parent image. - * Differencing images may have a differencing image as a parent, creating a chain of images. - * There is no theoretical chain length limit, although I do not consider long chains to be - * advisable. Verifying the parent-child relationship is not very robust. - * - * \param [in] vhdm MiniVHD data structure - * \param [in] offset Sector offset to read from - * \param [in] num_sectors The desired number of sectors to read - * \param [out] out_buff An output buffer to store read sectors. Must be - * large enough to hold num_sectors worth of sectors. - * - * \retval 0 num_sectors were read from file - * \retval >0 < num_sectors were read from file - */ -int mvhd_diff_read(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); - -/** - * \brief Write to a fixed VHD image - * - * Fixed VHD images are essentially raw image files with a footer tacked on - * the end. They are therefore straightforward to write - * - * \param [in] vhdm MiniVHD data structure - * \param [in] offset Sector offset to write to - * \param [in] num_sectors The desired number of sectors to write - * \param [in] in_buff A source buffer to write sectors from. Must be - * large enough to hold num_sectors worth of sectors. - * - * \retval 0 num_sectors were written to file - * \retval >0 < num_sectors were written to file - */ -int mvhd_fixed_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); - -/** - * \brief Write to a sparse or differencing VHD image - * - * Sparse, or dynamic images are VHD images that grow as data is written to them. - * - * Differencing images are a variant of a sparse image. They contain the grow-on-demand - * properties of sparse images, but also reference a parent image. Data is always written - * to the child image. This makes writing to differencing images essentially identical to - * writing to sparse images, hence they use the same function. - * - * This function implements the logic to write sectors to the file, taking into - * account the fact that blocks may be stored on disk in any order, and that the - * write operation could cross block boundaries. - * - * \param [in] vhdm MiniVHD data structure - * \param [in] offset Sector offset to write to - * \param [in] num_sectors The desired number of sectors to write - * \param [in] in_buff A source buffer to write sectors from. Must be - * large enough to hold num_sectors worth of sectors. - * - * \retval 0 num_sectors were written to file - * \retval >0 < num_sectors were written to file - */ -int mvhd_sparse_diff_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); - -/** - * \brief A no-op function to "write" to read-only VHD images - * - * \param [in] vhdm MiniVHD data structure - * \param [in] offset Sector offset to write to - * \param [in] num_sectors The desired number of sectors to write - * \param [in] in_buff A source buffer to write sectors from. Must be - * large enough to hold num_sectors worth of sectors. - * - * \retval 0 num_sectors were written to file - * \retval >0 < num_sectors were written to file - */ -int mvhd_noop_write(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); - -#endif diff --git a/src/disk/minivhd/minivhd_struct_rw.c b/src/disk/minivhd/minivhd_struct_rw.c deleted file mode 100644 index 5285f8a68..000000000 --- a/src/disk/minivhd/minivhd_struct_rw.c +++ /dev/null @@ -1,167 +0,0 @@ -/** - * \file - * \brief Header and footer serialize/deserialize functions - */ -#ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 -#endif -#include -#include -#include -#include -#include -#include "minivhd_util.h" -#include "minivhd_internal.h" - -/* Read data from footer into the struct members, swapping endian where necessary - Note: order matters here! We must read each field in the order the struct is in. - Doing this may be less elegant than performing a memcpy to a packed struct, but - it avoids potential data alignment issues, and the endian swapping allows us to - use the fields directly. */ - -static void mvhd_next_buffer_to_struct(void* struct_memb, size_t memb_size, bool req_endian, uint8_t** buffer); -static void mvhd_next_struct_to_buffer(void* struct_memb, size_t memb_size, bool req_endian, uint8_t** buffer); - -/** - * \brief Get the next field from a buffer and store it in a struct member, converting endian if necessary - * - * \param [out] struct_memb struct member to save the field to - * \param [in] memb_size the size of struct_memb, in bytes - * \param [in] req_endian is the field a value that requires endian conversion (eg: uint16, uint32) - * \param [in] buffer the buffer from which fields are read from. Will be advanced at the end of the function call - */ -static void mvhd_next_buffer_to_struct(void* struct_memb, size_t memb_size, bool req_endian, uint8_t** buffer) { - memcpy(struct_memb, *buffer, memb_size); - if (req_endian) { - switch (memb_size) { - case 2: - *(uint16_t*)(struct_memb) = mvhd_from_be16(*(uint16_t*)(struct_memb)); - break; - case 4: - *(uint32_t*)(struct_memb) = mvhd_from_be32(*(uint32_t*)(struct_memb)); - break; - case 8: - *(uint64_t*)(struct_memb) = mvhd_from_be64(*(uint64_t*)(struct_memb)); - break; - } - } - *buffer += memb_size; -} - -/** - * \brief Save a struct member into a buffer, converting endian if necessary - * - * \param [in] struct_memb struct member read from - * \param [in] memb_size the size of struct_memb, in bytes - * \param [in] req_endian is the field a value that requires endian conversion (eg: uint16, uint32) - * \param [out] buffer the buffer from which struct member is saved to. Will be advanced at the end of the function call - */ -static void mvhd_next_struct_to_buffer(void* struct_memb, size_t memb_size, bool req_endian, uint8_t** buffer) { - uint8_t *buf_ptr = *buffer; - memcpy(buf_ptr, struct_memb, memb_size); - if (req_endian) { - switch (memb_size) { - case 2: - *((uint16_t*)buf_ptr) = mvhd_to_be16(*(uint16_t*)(struct_memb)); - break; - case 4: - *((uint32_t*)buf_ptr) = mvhd_to_be32(*(uint32_t*)(struct_memb)); - break; - case 8: - *((uint64_t*)buf_ptr) = mvhd_to_be64(*(uint64_t*)(struct_memb)); - break; - } - } - buf_ptr += memb_size; - *buffer = buf_ptr; -} - -void mvhd_buffer_to_footer(MVHDFooter* footer, uint8_t* buffer) { - uint8_t* buff_ptr = buffer; - mvhd_next_buffer_to_struct(&footer->cookie, sizeof footer->cookie, false, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->features, sizeof footer->features, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->fi_fmt_vers, sizeof footer->fi_fmt_vers, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->data_offset, sizeof footer->data_offset, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->timestamp, sizeof footer->timestamp, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->cr_app, sizeof footer->cr_app, false, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->cr_vers, sizeof footer->cr_vers, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->cr_host_os, sizeof footer->cr_host_os, false, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->orig_sz, sizeof footer->orig_sz, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->curr_sz, sizeof footer->curr_sz, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->geom.cyl, sizeof footer->geom.cyl, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->geom.heads, sizeof footer->geom.heads, false, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->geom.spt, sizeof footer->geom.spt, false, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->disk_type, sizeof footer->disk_type, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->checksum, sizeof footer->checksum, true, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->uuid, sizeof footer->uuid, false, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->saved_st, sizeof footer->saved_st, false, &buff_ptr); - mvhd_next_buffer_to_struct(&footer->reserved, sizeof footer->reserved, false, &buff_ptr); -} - -void mvhd_footer_to_buffer(MVHDFooter* footer, uint8_t* buffer) { - uint8_t* buff_ptr = buffer; - mvhd_next_struct_to_buffer(&footer->cookie, sizeof footer->cookie, false, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->features, sizeof footer->features, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->fi_fmt_vers, sizeof footer->fi_fmt_vers, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->data_offset, sizeof footer->data_offset, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->timestamp, sizeof footer->timestamp, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->cr_app, sizeof footer->cr_app, false, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->cr_vers, sizeof footer->cr_vers, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->cr_host_os, sizeof footer->cr_host_os, false, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->orig_sz, sizeof footer->orig_sz, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->curr_sz, sizeof footer->curr_sz, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->geom.cyl, sizeof footer->geom.cyl, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->geom.heads, sizeof footer->geom.heads, false, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->geom.spt, sizeof footer->geom.spt, false, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->disk_type, sizeof footer->disk_type, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->checksum, sizeof footer->checksum, true, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->uuid, sizeof footer->uuid, false, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->saved_st, sizeof footer->saved_st, false, &buff_ptr); - mvhd_next_struct_to_buffer(&footer->reserved, sizeof footer->reserved, false, &buff_ptr); -} - -void mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer) { - uint8_t* buff_ptr = buffer; - mvhd_next_buffer_to_struct(&header->cookie, sizeof header->cookie, false, &buff_ptr); - mvhd_next_buffer_to_struct(&header->data_offset, sizeof header->data_offset, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->bat_offset, sizeof header->bat_offset, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->head_vers, sizeof header->head_vers, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->max_bat_ent, sizeof header->max_bat_ent, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->block_sz, sizeof header->block_sz, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->checksum, sizeof header->checksum, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->par_uuid, sizeof header->par_uuid, false, &buff_ptr); - mvhd_next_buffer_to_struct(&header->par_timestamp, sizeof header->par_timestamp, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); - for (int i = 0; i < 8; i++) { - mvhd_next_buffer_to_struct(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->par_loc_entry[i].plat_data_len, sizeof header->par_loc_entry[i].plat_data_len, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->par_loc_entry[i].reserved, sizeof header->par_loc_entry[i].reserved, true, &buff_ptr); - mvhd_next_buffer_to_struct(&header->par_loc_entry[i].plat_data_offset, sizeof header->par_loc_entry[i].plat_data_offset, true, &buff_ptr); - } - mvhd_next_buffer_to_struct(&header->reserved_2, sizeof header->reserved_2, false, &buff_ptr); -} - -void mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer) { - uint8_t* buff_ptr = buffer; - mvhd_next_struct_to_buffer(&header->cookie, sizeof header->cookie, false, &buff_ptr); - mvhd_next_struct_to_buffer(&header->data_offset, sizeof header->data_offset, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->bat_offset, sizeof header->bat_offset, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->head_vers, sizeof header->head_vers, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->max_bat_ent, sizeof header->max_bat_ent, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->block_sz, sizeof header->block_sz, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->checksum, sizeof header->checksum, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->par_uuid, sizeof header->par_uuid, false, &buff_ptr); - mvhd_next_struct_to_buffer(&header->par_timestamp, sizeof header->par_timestamp, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); - for (int i = 0; i < 8; i++) { - mvhd_next_struct_to_buffer(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->par_loc_entry[i].plat_data_len, sizeof header->par_loc_entry[i].plat_data_len, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->par_loc_entry[i].reserved, sizeof header->par_loc_entry[i].reserved, true, &buff_ptr); - mvhd_next_struct_to_buffer(&header->par_loc_entry[i].plat_data_offset, sizeof header->par_loc_entry[i].plat_data_offset, true, &buff_ptr); - } - mvhd_next_struct_to_buffer(&header->reserved_2, sizeof header->reserved_2, false, &buff_ptr); -} diff --git a/src/disk/minivhd/minivhd_struct_rw.h b/src/disk/minivhd/minivhd_struct_rw.h deleted file mode 100644 index 39441fb39..000000000 --- a/src/disk/minivhd/minivhd_struct_rw.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef MINIVHD_STRUCT_RW_H -#define MINIVHD_STRUCT_RW_H - -#include "minivhd_internal.h" - -/** - * \brief Save the contents of a VHD footer from a buffer to a struct - * - * \param [out] footer save contents of buffer into footer - * \param [in] buffer VHD footer in raw bytes - */ -void mvhd_buffer_to_footer(MVHDFooter* footer, uint8_t* buffer); - -/** - * \brief Save the contents of a VHD sparse header from a buffer to a struct - * - * \param [out] header save contents of buffer into header - * \param [in] buffer VHD header in raw bytes - */ -void mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer); - -/** - * \brief Save the contents of a VHD footer struct to a buffer - * - * \param [in] footer save contents of struct into buffer - * \param [out] buffer VHD footer in raw bytes - */ -void mvhd_footer_to_buffer(MVHDFooter* footer, uint8_t* buffer); - -/** - * \brief Save the contents of a VHD sparse header struct to a buffer - * - * \param [in] header save contents of struct into buffer - * \param [out] buffer VHD sparse header in raw bytes - */ -void mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer); - -#endif diff --git a/src/disk/minivhd/minivhd_util.c b/src/disk/minivhd/minivhd_util.c index 5bfc59915..dd3244322 100644 --- a/src/disk/minivhd/minivhd_util.c +++ b/src/disk/minivhd/minivhd_util.c @@ -1,46 +1,90 @@ -/** - * \file - * \brief Utility functions +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Utility functions. + * + * Version: @(#)util.c 1.0.4 2021/04/16 + * + * Author: Sherman Perry, + * + * Copyright 2019-2021 Sherman Perry. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 +# define _FILE_OFFSET_BITS 64 #endif #include #include #include #include +#include #include #include #include #include -#include "libxml2_encoding.h" -#include "minivhd_internal.h" -#include "minivhd_util.h" +#include "minivhd.h" +#include "internal.h" +#include "xml2_encoding.h" -const char MVHD_CONECTIX_COOKIE[] = "conectix"; -const char MVHD_CREATOR[] = "pcem"; -const char MVHD_CREATOR_HOST_OS[] = "Wi2k"; -const char MVHD_CXSPARSE_COOKIE[] = "cxsparse"; -uint16_t mvhd_from_be16(uint16_t val) { +uint16_t +mvhd_from_be16(uint16_t val) +{ uint8_t *tmp = (uint8_t*)&val; uint16_t ret = 0; + ret |= (uint16_t)tmp[0] << 8; ret |= (uint16_t)tmp[1] << 0; + return ret; } -uint32_t mvhd_from_be32(uint32_t val) { + + +uint32_t +mvhd_from_be32(uint32_t val) +{ uint8_t *tmp = (uint8_t*)&val; uint32_t ret = 0; + ret = (uint32_t)tmp[0] << 24; ret |= (uint32_t)tmp[1] << 16; ret |= (uint32_t)tmp[2] << 8; ret |= (uint32_t)tmp[3] << 0; + return ret; } -uint64_t mvhd_from_be64(uint64_t val) { + + +uint64_t +mvhd_from_be64(uint64_t val) +{ uint8_t *tmp = (uint8_t*)&val; uint64_t ret = 0; + ret = (uint64_t)tmp[0] << 56; ret |= (uint64_t)tmp[1] << 48; ret |= (uint64_t)tmp[2] << 40; @@ -49,27 +93,45 @@ uint64_t mvhd_from_be64(uint64_t val) { ret |= (uint64_t)tmp[5] << 16; ret |= (uint64_t)tmp[6] << 8; ret |= (uint64_t)tmp[7] << 0; + return ret; } -uint16_t mvhd_to_be16(uint16_t val) { + + +uint16_t +mvhd_to_be16(uint16_t val) +{ uint16_t ret = 0; uint8_t *tmp = (uint8_t*)&ret; + tmp[0] = (val & 0xff00) >> 8; tmp[1] = (val & 0x00ff) >> 0; + return ret; } -uint32_t mvhd_to_be32(uint32_t val) { + + +uint32_t +mvhd_to_be32(uint32_t val) +{ uint32_t ret = 0; uint8_t *tmp = (uint8_t*)&ret; + tmp[0] = (val & 0xff000000) >> 24; tmp[1] = (val & 0x00ff0000) >> 16; tmp[2] = (val & 0x0000ff00) >> 8; tmp[3] = (val & 0x000000ff) >> 0; + return ret; } -uint64_t mvhd_to_be64(uint64_t val) { + + +uint64_t +mvhd_to_be64(uint64_t val) +{ uint64_t ret = 0; uint8_t *tmp = (uint8_t*)&ret; + tmp[0] = (uint8_t)((val & 0xff00000000000000) >> 56); tmp[1] = (uint8_t)((val & 0x00ff000000000000) >> 48); tmp[2] = (uint8_t)((val & 0x0000ff0000000000) >> 40); @@ -78,21 +140,17 @@ uint64_t mvhd_to_be64(uint64_t val) { tmp[5] = (uint8_t)((val & 0x0000000000ff0000) >> 16); tmp[6] = (uint8_t)((val & 0x000000000000ff00) >> 8); tmp[7] = (uint8_t)((val & 0x00000000000000ff) >> 0); + return ret; } -bool mvhd_is_conectix_str(const void* buffer) { - if (strncmp(buffer, MVHD_CONECTIX_COOKIE, strlen(MVHD_CONECTIX_COOKIE)) == 0) { - return true; - } else { - return false; - } -} -void mvhd_generate_uuid(uint8_t* uuid) +void +mvhd_generate_uuid(uint8_t* uuid) { /* We aren't doing crypto here, so using system time as seed should be good enough */ srand((unsigned int)time(0)); + for (int n = 0; n < 16; n++) { uuid[n] = rand(); } @@ -102,34 +160,50 @@ void mvhd_generate_uuid(uint8_t* uuid) uuid[8] |= 0x80; /* Variant 1 */ } -uint32_t vhd_calc_timestamp(void) -{ - time_t start_time; - time_t curr_time; - double vhd_time; - start_time = MVHD_START_TS; /* 1 Jan 2000 00:00 */ - curr_time = time(NULL); - vhd_time = difftime(curr_time, start_time); - return (uint32_t)vhd_time; -} -uint32_t mvhd_epoch_to_vhd_ts(time_t ts) { - time_t start_time = MVHD_START_TS; - if (ts < start_time) { - return start_time; - } - double vhd_time = difftime(ts, start_time); +uint32_t +vhd_calc_timestamp(void) +{ + time_t start_time; + time_t curr_time; + double vhd_time; + + start_time = MVHD_START_TS; /* 1 Jan 2000 00:00 */ + curr_time = time(NULL); + vhd_time = difftime(curr_time, start_time); + return (uint32_t)vhd_time; } -time_t vhd_get_created_time(MVHDMeta *vhdm) + +uint32_t +mvhd_epoch_to_vhd_ts(time_t ts) { - time_t vhd_time = (time_t)vhdm->footer.timestamp; - time_t vhd_time_unix = MVHD_START_TS + vhd_time; - return vhd_time_unix; + time_t start_time = MVHD_START_TS; + double vhd_time; + + if (ts < start_time) + return (uint32_t)start_time; + + vhd_time = difftime(ts, start_time); + + return (uint32_t)vhd_time; } -FILE* mvhd_fopen(const char* path, const char* mode, int* err) { + +time_t +vhd_get_created_time(MVHDMeta *vhdm) +{ + time_t vhd_time = (time_t)vhdm->footer.timestamp; + time_t vhd_time_unix = MVHD_START_TS + vhd_time; + + return vhd_time_unix; +} + + +FILE* +mvhd_fopen(const char* path, const char* mode, int* err) +{ FILE* f = NULL; #ifdef _WIN32 size_t path_len = strlen(path); @@ -140,6 +214,7 @@ FILE* mvhd_fopen(const char* path, const char* mode, int* err) { int new_mode_len = (sizeof mode_str) - 2; int path_res = UTF8ToUTF16LE((unsigned char*)new_path, &new_path_len, (const unsigned char*)path, (int*)&path_len); int mode_res = UTF8ToUTF16LE((unsigned char*)mode_str, &new_mode_len, (const unsigned char*)mode, (int*)&mode_len); + if (path_res > 0 && mode_res > 0) { f = _wfopen(new_path, mode_str); if (f == NULL) { @@ -160,10 +235,14 @@ FILE* mvhd_fopen(const char* path, const char* mode, int* err) { *err = MVHD_ERR_FILE; } #endif + return f; } -void mvhd_set_encoding_err(int encoding_retval, int* err) { + +void +mvhd_set_encoding_err(int encoding_retval, int* err) +{ if (encoding_retval == -1) { *err = MVHD_ERR_UTF_SIZE; } else if (encoding_retval == -2) { @@ -171,87 +250,162 @@ void mvhd_set_encoding_err(int encoding_retval, int* err) { } } -uint64_t mvhd_calc_size_bytes(MVHDGeom *geom) { + +uint64_t +mvhd_calc_size_bytes(MVHDGeom *geom) +{ uint64_t img_size = (uint64_t)geom->cyl * (uint64_t)geom->heads * (uint64_t)geom->spt * (uint64_t)MVHD_SECTOR_SIZE; + return img_size; } -uint32_t mvhd_calc_size_sectors(MVHDGeom *geom) { + +uint32_t +mvhd_calc_size_sectors(MVHDGeom *geom) +{ uint32_t sector_size = (uint32_t)geom->cyl * (uint32_t)geom->heads * (uint32_t)geom->spt; + return sector_size; } -MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm) { - MVHDGeom geometry = { .cyl = vhdm->footer.geom.cyl, .heads = vhdm->footer.geom.heads, .spt = vhdm->footer.geom.spt }; + +MVHDAPI MVHDGeom +mvhd_get_geometry(MVHDMeta* vhdm) +{ + MVHDGeom geometry = { + .cyl = vhdm->footer.geom.cyl, + .heads = vhdm->footer.geom.heads, + .spt = vhdm->footer.geom.spt + }; + return geometry; } -uint32_t mvhd_gen_footer_checksum(MVHDFooter* footer) { + +MVHDAPI uint64_t +mvhd_get_current_size(MVHDMeta* vhdm) +{ + return vhdm->footer.curr_sz; +} + + +uint32_t +mvhd_gen_footer_checksum(MVHDFooter* footer) +{ uint32_t new_chk = 0; uint32_t orig_chk = footer->checksum; footer->checksum = 0; uint8_t* footer_bytes = (uint8_t*)footer; - for (size_t i = 0; i < sizeof *footer; i++) { + + for (size_t i = 0; i < sizeof *footer; i++) new_chk += footer_bytes[i]; - } footer->checksum = orig_chk; + return ~new_chk; } -uint32_t mvhd_gen_sparse_checksum(MVHDSparseHeader* header) { + +uint32_t +mvhd_gen_sparse_checksum(MVHDSparseHeader* header) +{ uint32_t new_chk = 0; uint32_t orig_chk = header->checksum; header->checksum = 0; uint8_t* sparse_bytes = (uint8_t*)header; + for (size_t i = 0; i < sizeof *header; i++) { new_chk += sparse_bytes[i]; } header->checksum = orig_chk; + return ~new_chk; } -const char* mvhd_strerr(MVHDError err) { + +MVHDAPI const char* +mvhd_strerr(MVHDError err) +{ + const char *s = "unknown error"; + switch (err) { - case MVHD_ERR_MEM: - return "memory allocation error"; - case MVHD_ERR_FILE: - return "file error"; - case MVHD_ERR_NOT_VHD: - return "file is not a VHD image"; - case MVHD_ERR_TYPE: - return "unsupported VHD image type"; - case MVHD_ERR_FOOTER_CHECKSUM: - return "invalid VHD footer checksum"; - case MVHD_ERR_SPARSE_CHECKSUM: - return "invalid VHD sparse header checksum"; - case MVHD_ERR_UTF_TRANSCODING_FAILED: - return "error converting path encoding"; - case MVHD_ERR_UTF_SIZE: - return "buffer size mismatch when converting path encoding"; - case MVHD_ERR_PATH_REL: - return "relative path detected where absolute path expected"; - case MVHD_ERR_PATH_LEN: - return "path length exceeds MVHD_MAX_PATH"; - case MVHD_ERR_PAR_NOT_FOUND: - return "parent VHD image not found"; - case MVHD_ERR_INVALID_PAR_UUID: - return "UUID mismatch between child and parent VHD"; - case MVHD_ERR_INVALID_GEOM: - return "invalid geometry detected"; - case MVHD_ERR_INVALID_SIZE: - return "invalid size"; - case MVHD_ERR_INVALID_BLOCK_SIZE: - return "invalid block size"; - case MVHD_ERR_INVALID_PARAMS: - return "invalid parameters passed to function"; - case MVHD_ERR_CONV_SIZE: - return "error converting image. Size mismatch detechted"; - default: - return "unknown error"; + case MVHD_ERR_MEM: + s = "memory allocation error"; + break; + + case MVHD_ERR_FILE: + s = "file error"; + break; + + case MVHD_ERR_NOT_VHD: + s = "file is not a VHD image"; + break; + + case MVHD_ERR_TYPE: + s = "unsupported VHD image type"; + break; + + case MVHD_ERR_FOOTER_CHECKSUM: + s = "invalid VHD footer checksum"; + break; + + case MVHD_ERR_SPARSE_CHECKSUM: + s = "invalid VHD sparse header checksum"; + break; + + case MVHD_ERR_UTF_TRANSCODING_FAILED: + s = "error converting path encoding"; + break; + + case MVHD_ERR_UTF_SIZE: + s = "buffer size mismatch when converting path encoding"; + break; + + case MVHD_ERR_PATH_REL: + s = "relative path detected where absolute path expected"; + break; + + case MVHD_ERR_PATH_LEN: + s = "path length exceeds MVHD_MAX_PATH"; + break; + + case MVHD_ERR_PAR_NOT_FOUND: + s = "parent VHD image not found"; + break; + + case MVHD_ERR_INVALID_PAR_UUID: + s = "UUID mismatch between child and parent VHD"; + break; + + case MVHD_ERR_INVALID_GEOM: + s = "invalid geometry detected"; + break; + + case MVHD_ERR_INVALID_SIZE: + s = "invalid size"; + break; + + case MVHD_ERR_INVALID_BLOCK_SIZE: + s = "invalid block size"; + break; + + case MVHD_ERR_INVALID_PARAMS: + s = "invalid parameters passed to function"; + break; + + case MVHD_ERR_CONV_SIZE: + s = "error converting image. Size mismatch detected"; + break; + + default: + break; } + + return s; } -int64_t mvhd_ftello64(FILE* stream) + +int64_t +mvhd_ftello64(FILE* stream) { #ifdef _MSC_VER return _ftelli64(stream); @@ -262,7 +416,9 @@ int64_t mvhd_ftello64(FILE* stream) #endif } -int mvhd_fseeko64(FILE* stream, int64_t offset, int origin) + +int +mvhd_fseeko64(FILE* stream, int64_t offset, int origin) { #ifdef _MSC_VER return _fseeki64(stream, offset, origin); @@ -273,17 +429,25 @@ int mvhd_fseeko64(FILE* stream, int64_t offset, int origin) #endif } -uint32_t mvhd_crc32_for_byte(uint32_t r) { + +uint32_t +mvhd_crc32_for_byte(uint32_t r) +{ for (int j = 0; j < 8; ++j) r = (r & 1 ? 0 : (uint32_t)0xEDB88320L) ^ r >> 1; + return r ^ (uint32_t)0xFF000000L; } -uint32_t mvhd_crc32(const void* data, size_t n_bytes) { + +uint32_t +mvhd_crc32(const void* data, size_t n_bytes) +{ static uint32_t table[0x100]; + if (!*table) for (size_t i = 0; i < 0x100; ++i) - table[i] = mvhd_crc32_for_byte(i); + table[i] = mvhd_crc32_for_byte((uint32_t)i); uint32_t crc = 0; for (size_t i = 0; i < n_bytes; ++i) @@ -292,7 +456,10 @@ uint32_t mvhd_crc32(const void* data, size_t n_bytes) { return crc; } -uint32_t mvhd_file_mod_timestamp(const char* path, int *err) { + +uint32_t +mvhd_file_mod_timestamp(const char* path, int *err) +{ *err = 0; #ifdef _WIN32 struct _stat file_stat; @@ -300,6 +467,7 @@ uint32_t mvhd_file_mod_timestamp(const char* path, int *err) { mvhd_utf16 new_path[260] = {0}; int new_path_len = (sizeof new_path) - 2; int path_res = UTF8ToUTF16LE((unsigned char*)new_path, &new_path_len, (const unsigned char*)path, (int*)&path_len); + if (path_res > 0) { int stat_res = _wstat(new_path, &file_stat); if (stat_res != 0) { @@ -319,6 +487,7 @@ uint32_t mvhd_file_mod_timestamp(const char* path, int *err) { #else struct stat file_stat; int stat_res = stat(path, &file_stat); + if (stat_res != 0) { mvhd_errno = errno; *err = MVHD_ERR_FILE; diff --git a/src/disk/minivhd/minivhd_util.h b/src/disk/minivhd/minivhd_util.h deleted file mode 100644 index 227570ce2..000000000 --- a/src/disk/minivhd/minivhd_util.h +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef MINIVHD_UTIL_H -#define MINIVHD_UTIL_H - -#include -#include -#include -#include "minivhd_internal.h" -#include "minivhd.h" -#define MVHD_START_TS 946684800 - -/** - * Functions to deal with endian issues - */ -uint16_t mvhd_from_be16(uint16_t val); -uint32_t mvhd_from_be32(uint32_t val); -uint64_t mvhd_from_be64(uint64_t val); -uint16_t mvhd_to_be16(uint16_t val); -uint32_t mvhd_to_be32(uint32_t val); -uint64_t mvhd_to_be64(uint64_t val); - -/** - * \brief Check if provided buffer begins with the string "conectix" - * - * \param [in] buffer The buffer to compare. Must be at least 8 bytes in length - * - * \return true if the buffer begins with "conectix" - * \return false if the buffer does not begin with "conectix" - */ -bool mvhd_is_conectix_str(const void* buffer); - -/** - * \brief Generate a raw 16 byte UUID - * - * \param [out] uuid A 16 byte buffer in which the generated UUID will be stored to - */ -void mvhd_generate_uuid(uint8_t *uuid); - -/** - * \brief Calculate a VHD formatted timestamp from the current time - */ -uint32_t vhd_calc_timestamp(void); - -/** - * \brief Convert an epoch timestamp to a VHD timestamp - * - * \param [in] ts epoch timestamp to convert. - * - * \return The adjusted timestamp, or 0 if the input timestamp is - * earlier that 1 Janurary 2000 - */ -uint32_t mvhd_epoch_to_vhd_ts(time_t ts); - -/** - * \brief Return the created time from a VHD image - * - * \param [in] vhdm Pointer to the MiniVHD metadata structure - * - * \return The created time, as a Unix timestamp - */ -time_t vhd_get_created_time(MVHDMeta *vhdm); - -/** - * \brief Cross platform, unicode filepath opening - * - * This function accounts for the fact that fopen() handles file paths differently compared to other - * operating systems. Windows version of fopen() will not handle multi byte encoded text like UTF-8. - * - * Unicode filepath support on Windows requires using the _wfopen() function, which expects UTF-16LE - * encoded path and modestring. - * - * \param [in] path The filepath to open as a UTF-8 string - * \param [in] mode The mode string to use (eg: "rb+"") - * \param [out] err The error value, if an error occurrs - * - * \return a FILE pointer if successful, NULL otherwise. If NULL, check the value of err - */ -FILE* mvhd_fopen(const char* path, const char* mode, int* err); - -void mvhd_set_encoding_err(int encoding_retval, int* err); -uint64_t mvhd_calc_size_bytes(MVHDGeom *geom); -uint32_t mvhd_calc_size_sectors(MVHDGeom *geom); -MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm); - -/** - * \brief Generate VHD footer checksum - * - * \param [in] vhdm MiniVHD data structure - */ -uint32_t mvhd_gen_footer_checksum(MVHDFooter* footer); - -/** - * \brief Generate VHD sparse header checksum - * - * \param [in] vhdm MiniVHD data structure - */ -uint32_t mvhd_gen_sparse_checksum(MVHDSparseHeader* header); - -/** - * \brief Get current position in file stream - * - * This is a portable version of the POSIX ftello64(). * - */ -int64_t mvhd_ftello64(FILE* stream); - -/** - * \brief Reposition the file stream's position - * - * This is a portable version of the POSIX fseeko64(). * - */ -int mvhd_fseeko64(FILE* stream, int64_t offset, int origin); - -/** - * \brief Calculate the CRC32 of a data buffer. - * - * This function can be used for verifying data integrity. - * - * \param [in] data The data buffer - * \param [in] n_bytes The size of the data buffer in bytes - * - * \return The CRC32 of the data buffer - */ -uint32_t mvhd_crc32(const void* data, size_t n_bytes); - -/** - * \brief Calculate the file modification timestamp. - * - * This function is primarily to help protect differencing VHD's - * - * \param [in] path the UTF-8 file path - * \param [out] err The error value, if an error occurrs - * - * \return The file modified timestamp, in VHD compatible timestamp. - * 'err' will be set to non-zero on error - */ -uint32_t mvhd_file_mod_timestamp(const char* path, int *err); -#endif diff --git a/src/disk/minivhd/struct_rw.c b/src/disk/minivhd/struct_rw.c new file mode 100644 index 000000000..ceb98253a --- /dev/null +++ b/src/disk/minivhd/struct_rw.c @@ -0,0 +1,232 @@ +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Header and footer serialize/deserialize functions. + * + * Read data from footer into the struct members, swapping + * endian where necessary. + * + * NOTE: Order matters here! + * We must read each field in the order the struct is in. + * Doing this may be less elegant than performing a memcpy + * to a packed struct, but it avoids potential data alignment + * issues, and the endian swapping allows us to use the fields + * directly. + * + * Version: @(#)struct_rw.c 1.0.2 2021/04/16 + * + * Author: Sherman Perry, + * + * Copyright 2019-2021 Sherman Perry. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +#endif +#include +#include +#include +#include +#include +#include +#include "minivhd.h" +#include "internal.h" + + +/** + * \brief Get the next field from a buffer and store it in a struct member, converting endian if necessary + * + * \param [out] struct_memb struct member to save the field to + * \param [in] memb_size the size of struct_memb, in bytes + * \param [in] req_endian is the field a value that requires endian conversion (eg: uint16, uint32) + * \param [in] buffer the buffer from which fields are read from. Will be advanced at the end of the function call + */ +static void +next_buffer_to_struct(void* struct_memb, size_t memb_size, bool req_endian, uint8_t** buffer) +{ + memcpy(struct_memb, *buffer, memb_size); + + if (req_endian) switch (memb_size) { + case 2: + *(uint16_t*)(struct_memb) = mvhd_from_be16(*(uint16_t*)(struct_memb)); + break; + + case 4: + *(uint32_t*)(struct_memb) = mvhd_from_be32(*(uint32_t*)(struct_memb)); + break; + + case 8: + *(uint64_t*)(struct_memb) = mvhd_from_be64(*(uint64_t*)(struct_memb)); + break; + } + + *buffer += memb_size; +} + + +/** + * \brief Save a struct member into a buffer, converting endian if necessary + * + * \param [in] struct_memb struct member read from + * \param [in] memb_size the size of struct_memb, in bytes + * \param [in] req_endian is the field a value that requires endian conversion (eg: uint16, uint32) + * \param [out] buffer the buffer from which struct member is saved to. Will be advanced at the end of the function call + */ +static void +next_struct_to_buffer(void* struct_memb, size_t memb_size, bool req_endian, uint8_t** buffer) +{ + uint8_t *buf_ptr = *buffer; + + memcpy(buf_ptr, struct_memb, memb_size); + + if (req_endian) switch (memb_size) { + case 2: + *((uint16_t*)buf_ptr) = mvhd_to_be16(*(uint16_t*)(struct_memb)); + break; + + case 4: + *((uint32_t*)buf_ptr) = mvhd_to_be32(*(uint32_t*)(struct_memb)); + break; + + case 8: + *((uint64_t*)buf_ptr) = mvhd_to_be64(*(uint64_t*)(struct_memb)); + break; + } + + buf_ptr += memb_size; + *buffer = buf_ptr; +} + + +void +mvhd_buffer_to_footer(MVHDFooter* footer, uint8_t* buffer) +{ + uint8_t* buff_ptr = buffer; + + next_buffer_to_struct(&footer->cookie, sizeof footer->cookie, false, &buff_ptr); + next_buffer_to_struct(&footer->features, sizeof footer->features, true, &buff_ptr); + next_buffer_to_struct(&footer->fi_fmt_vers, sizeof footer->fi_fmt_vers, true, &buff_ptr); + next_buffer_to_struct(&footer->data_offset, sizeof footer->data_offset, true, &buff_ptr); + next_buffer_to_struct(&footer->timestamp, sizeof footer->timestamp, true, &buff_ptr); + next_buffer_to_struct(&footer->cr_app, sizeof footer->cr_app, false, &buff_ptr); + next_buffer_to_struct(&footer->cr_vers, sizeof footer->cr_vers, true, &buff_ptr); + next_buffer_to_struct(&footer->cr_host_os, sizeof footer->cr_host_os, false, &buff_ptr); + next_buffer_to_struct(&footer->orig_sz, sizeof footer->orig_sz, true, &buff_ptr); + next_buffer_to_struct(&footer->curr_sz, sizeof footer->curr_sz, true, &buff_ptr); + next_buffer_to_struct(&footer->geom.cyl, sizeof footer->geom.cyl, true, &buff_ptr); + next_buffer_to_struct(&footer->geom.heads, sizeof footer->geom.heads, false, &buff_ptr); + next_buffer_to_struct(&footer->geom.spt, sizeof footer->geom.spt, false, &buff_ptr); + next_buffer_to_struct(&footer->disk_type, sizeof footer->disk_type, true, &buff_ptr); + next_buffer_to_struct(&footer->checksum, sizeof footer->checksum, true, &buff_ptr); + next_buffer_to_struct(&footer->uuid, sizeof footer->uuid, false, &buff_ptr); + next_buffer_to_struct(&footer->saved_st, sizeof footer->saved_st, false, &buff_ptr); + next_buffer_to_struct(&footer->reserved, sizeof footer->reserved, false, &buff_ptr); +} + + +void +mvhd_footer_to_buffer(MVHDFooter* footer, uint8_t* buffer) +{ + uint8_t* buff_ptr = buffer; + + next_struct_to_buffer(&footer->cookie, sizeof footer->cookie, false, &buff_ptr); + next_struct_to_buffer(&footer->features, sizeof footer->features, true, &buff_ptr); + next_struct_to_buffer(&footer->fi_fmt_vers, sizeof footer->fi_fmt_vers, true, &buff_ptr); + next_struct_to_buffer(&footer->data_offset, sizeof footer->data_offset, true, &buff_ptr); + next_struct_to_buffer(&footer->timestamp, sizeof footer->timestamp, true, &buff_ptr); + next_struct_to_buffer(&footer->cr_app, sizeof footer->cr_app, false, &buff_ptr); + next_struct_to_buffer(&footer->cr_vers, sizeof footer->cr_vers, true, &buff_ptr); + next_struct_to_buffer(&footer->cr_host_os, sizeof footer->cr_host_os, false, &buff_ptr); + next_struct_to_buffer(&footer->orig_sz, sizeof footer->orig_sz, true, &buff_ptr); + next_struct_to_buffer(&footer->curr_sz, sizeof footer->curr_sz, true, &buff_ptr); + next_struct_to_buffer(&footer->geom.cyl, sizeof footer->geom.cyl, true, &buff_ptr); + next_struct_to_buffer(&footer->geom.heads, sizeof footer->geom.heads, false, &buff_ptr); + next_struct_to_buffer(&footer->geom.spt, sizeof footer->geom.spt, false, &buff_ptr); + next_struct_to_buffer(&footer->disk_type, sizeof footer->disk_type, true, &buff_ptr); + next_struct_to_buffer(&footer->checksum, sizeof footer->checksum, true, &buff_ptr); + next_struct_to_buffer(&footer->uuid, sizeof footer->uuid, false, &buff_ptr); + next_struct_to_buffer(&footer->saved_st, sizeof footer->saved_st, false, &buff_ptr); + next_struct_to_buffer(&footer->reserved, sizeof footer->reserved, false, &buff_ptr); +} + + +void +mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer) +{ + uint8_t* buff_ptr = buffer; + + next_buffer_to_struct(&header->cookie, sizeof header->cookie, false, &buff_ptr); + next_buffer_to_struct(&header->data_offset, sizeof header->data_offset, true, &buff_ptr); + next_buffer_to_struct(&header->bat_offset, sizeof header->bat_offset, true, &buff_ptr); + next_buffer_to_struct(&header->head_vers, sizeof header->head_vers, true, &buff_ptr); + next_buffer_to_struct(&header->max_bat_ent, sizeof header->max_bat_ent, true, &buff_ptr); + next_buffer_to_struct(&header->block_sz, sizeof header->block_sz, true, &buff_ptr); + next_buffer_to_struct(&header->checksum, sizeof header->checksum, true, &buff_ptr); + next_buffer_to_struct(&header->par_uuid, sizeof header->par_uuid, false, &buff_ptr); + next_buffer_to_struct(&header->par_timestamp, sizeof header->par_timestamp, true, &buff_ptr); + next_buffer_to_struct(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); + next_buffer_to_struct(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); + + for (int i = 0; i < 8; i++) { + next_buffer_to_struct(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); + next_buffer_to_struct(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); + next_buffer_to_struct(&header->par_loc_entry[i].plat_data_len, sizeof header->par_loc_entry[i].plat_data_len, true, &buff_ptr); + next_buffer_to_struct(&header->par_loc_entry[i].reserved, sizeof header->par_loc_entry[i].reserved, true, &buff_ptr); + next_buffer_to_struct(&header->par_loc_entry[i].plat_data_offset, sizeof header->par_loc_entry[i].plat_data_offset, true, &buff_ptr); + } + + next_buffer_to_struct(&header->reserved_2, sizeof header->reserved_2, false, &buff_ptr); +} + + +void +mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer) +{ + uint8_t* buff_ptr = buffer; + + next_struct_to_buffer(&header->cookie, sizeof header->cookie, false, &buff_ptr); + next_struct_to_buffer(&header->data_offset, sizeof header->data_offset, true, &buff_ptr); + next_struct_to_buffer(&header->bat_offset, sizeof header->bat_offset, true, &buff_ptr); + next_struct_to_buffer(&header->head_vers, sizeof header->head_vers, true, &buff_ptr); + next_struct_to_buffer(&header->max_bat_ent, sizeof header->max_bat_ent, true, &buff_ptr); + next_struct_to_buffer(&header->block_sz, sizeof header->block_sz, true, &buff_ptr); + next_struct_to_buffer(&header->checksum, sizeof header->checksum, true, &buff_ptr); + next_struct_to_buffer(&header->par_uuid, sizeof header->par_uuid, false, &buff_ptr); + next_struct_to_buffer(&header->par_timestamp, sizeof header->par_timestamp, true, &buff_ptr); + next_struct_to_buffer(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); + next_struct_to_buffer(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); + + for (int i = 0; i < 8; i++) { + next_struct_to_buffer(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); + next_struct_to_buffer(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); + next_struct_to_buffer(&header->par_loc_entry[i].plat_data_len, sizeof header->par_loc_entry[i].plat_data_len, true, &buff_ptr); + next_struct_to_buffer(&header->par_loc_entry[i].reserved, sizeof header->par_loc_entry[i].reserved, true, &buff_ptr); + next_struct_to_buffer(&header->par_loc_entry[i].plat_data_offset, sizeof header->par_loc_entry[i].plat_data_offset, true, &buff_ptr); + } + + next_struct_to_buffer(&header->reserved_2, sizeof header->reserved_2, false, &buff_ptr); +} diff --git a/src/disk/minivhd/version.h b/src/disk/minivhd/version.h new file mode 100644 index 000000000..fcedc1be2 --- /dev/null +++ b/src/disk/minivhd/version.h @@ -0,0 +1,68 @@ +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Define library version and build info. + * + * Version: @(#)version.h 1.034 2021/04/16 + * + * Author: Fred N. van Kempen, + * + * Copyright 2021 Fred N. van Kempen. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#ifndef MINIVHD_VERSION_H +# define MINIVHD_VERSION_H + + +/* Library name. */ +#define LIB_NAME "MiniVHD" + +/* Version info. */ +#define LIB_VER_MAJOR 1 +#define LIB_VER_MINOR 0 +#define LIB_VER_REV 3 +#define LIB_VER_PATCH 0 + + +/* Standard C preprocessor macros. */ +#define STR_STRING(x) #x +#define STR(x) STR_STRING(x) +#define STR_RC(a,e) a ## , ## e + + +/* These are used in the application. */ +#define LIB_VER_NUM LIB_VER_MAJOR.LIB_VER_MINOR.LIB_VER_REV +#if defined(LIB_VER_PATCH) && LIB_VER_PATCH > 0 +# define LIB_VER_NUM_4 LIB_VER_MAJOR.LIB_VER_MINOR.LIB_VER_REV.LIB_VER_PATCH +#else +# define LIB_VER_NUM_4 LIB_VER_MAJOR.LIB_VER_MINOR.LIB_VER_REV.0 +#endif +#define LIB_VERSION STR(LIB_VER_NUM) +#define LIB_VERSION_4 STR(LIB_VER_NUM_4) + + +#endif /*MINIVHD_VERSION_H*/ diff --git a/src/disk/minivhd/libxml2_encoding.c b/src/disk/minivhd/xml2_encoding.c similarity index 92% rename from src/disk/minivhd/libxml2_encoding.c rename to src/disk/minivhd/xml2_encoding.c index 48c291f2f..6c39cb7f6 100644 --- a/src/disk/minivhd/libxml2_encoding.c +++ b/src/disk/minivhd/xml2_encoding.c @@ -22,9 +22,19 @@ * Adapted and abridged for MiniVHD by Sherman Perry */ #include +#include +#include +#include +#include +#define BUILDING_LIBRARY +#include "minivhd.h" +#include "internal.h" +#include "xml2_encoding.h" + static int xmlLittleEndian = 1; + /* Note: extracted from original 'void xmlInitCharEncodingHandlers(void)' function */ void xmlEncodingInit(void) { @@ -96,8 +106,8 @@ int UTF16LEToUTF8(unsigned char* out, int *outlen, c += 0x10000; } else { - *outlen = out - outstart; - *inlenb = processed - inb; + *outlen = (int)(out - outstart); + *inlenb = (int)(processed - inb); return(-2); } } @@ -117,8 +127,8 @@ int UTF16LEToUTF8(unsigned char* out, int *outlen, } processed = (const unsigned char*) in; } - *outlen = out - outstart; - *inlenb = processed - inb; + *outlen = (int)(out - outstart); + *inlenb = (int)(processed - inb); return(*outlen); } @@ -163,16 +173,16 @@ int UTF8ToUTF16LE(unsigned char* outb, int *outlen, if (d < 0x80) { c= d; trailing= 0; } else if (d < 0xC0) { /* trailing byte in leading position */ - *outlen = (out - outstart) * 2; - *inlen = processed - instart; + *outlen = (int)((out - outstart) * 2); + *inlen = (int)(processed - instart); return(-2); } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } else if (d < 0xF8) { c= d & 0x07; trailing= 3; } else { /* no chance for this in UTF-16 */ - *outlen = (out - outstart) * 2; - *inlen = processed - instart; + *outlen = (int)((out - outstart) * 2); + *inlen = (int)(processed - instart); return(-2); } @@ -225,8 +235,8 @@ int UTF8ToUTF16LE(unsigned char* outb, int *outlen, break; processed = in; } - *outlen = (out - outstart) * 2; - *inlen = processed - instart; + *outlen = (int)((out - outstart) * 2); + *inlen = (int)(processed - instart); return(*outlen); } @@ -275,8 +285,8 @@ int UTF16BEToUTF8(unsigned char* out, int *outlen, } if ((c & 0xFC00) == 0xD800) { /* surrogates */ if (in >= inend) { /* (in > inend) shouldn't happens */ - *outlen = out - outstart; - *inlenb = processed - inb; + *outlen = (int)(out - outstart); + *inlenb = (int)(processed - inb); return(-2); } if (xmlLittleEndian) { @@ -295,8 +305,8 @@ int UTF16BEToUTF8(unsigned char* out, int *outlen, c += 0x10000; } else { - *outlen = out - outstart; - *inlenb = processed - inb; + *outlen = (int)(out - outstart); + *inlenb = (int)(processed - inb); return(-2); } } @@ -316,8 +326,8 @@ int UTF16BEToUTF8(unsigned char* out, int *outlen, } processed = (const unsigned char*) in; } - *outlen = out - outstart; - *inlenb = processed - inb; + *outlen = (int)(out - outstart); + *inlenb = (int)(processed - inb); return(*outlen); } @@ -362,16 +372,16 @@ int UTF8ToUTF16BE(unsigned char* outb, int *outlen, if (d < 0x80) { c= d; trailing= 0; } else if (d < 0xC0) { /* trailing byte in leading position */ - *outlen = out - outstart; - *inlen = processed - instart; + *outlen = (int)(out - outstart); + *inlen = (int)(processed - instart); return(-2); } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } else if (d < 0xF8) { c= d & 0x07; trailing= 3; } else { /* no chance for this in UTF-16 */ - *outlen = out - outstart; - *inlen = processed - instart; + *outlen = (int)(out - outstart); + *inlen = (int)(processed - instart); return(-2); } @@ -421,8 +431,8 @@ int UTF8ToUTF16BE(unsigned char* outb, int *outlen, break; processed = in; } - *outlen = (out - outstart) * 2; - *inlen = processed - instart; + *outlen = (int)((out - outstart) * 2); + *inlen = (int)(processed - instart); return(*outlen); } diff --git a/src/disk/minivhd/xml2_encoding.h b/src/disk/minivhd/xml2_encoding.h new file mode 100644 index 000000000..68c85390d --- /dev/null +++ b/src/disk/minivhd/xml2_encoding.h @@ -0,0 +1,62 @@ +/* + * MiniVHD Minimalist VHD implementation in C. + * + * This file is part of the MiniVHD Project. + * + * Version: @(#)xml2_encoding.h 1.0.1 2021/03/15 + * + * Author: Sherman Perry, + * + * Copyright 2019-2021 Sherman Perry. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documenta- + * tion files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF O R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#ifndef XML2_ENCODING_H +# define XML2_ENCODING_H + + +typedef uint16_t mvhd_utf16; + + +#ifdef __cplusplus +extern "C" { +#endif + +void xmlEncodingInit(void); + +int UTF16LEToUTF8(uint8_t *out, int *outlen, const uint8_t *inb, + int *inlenb); +int UTF8ToUTF16LE(uint8_t *outb, int *outlen, const uint8_t *in, + int *inlen); +int UTF16BEToUTF8(uint8_t *out, int *outlen, const uint8_t *inb, + int *inlenb); +int UTF8ToUTF16BE(uint8_t *outb, int *outlen, const uint8_t *in, + int *inlen); + +#ifdef __cplusplus +} +#endif + + +#endif /*XML2_ENCODING_H*/ diff --git a/src/disk/mo.c b/src/disk/mo.c index 2180fe544..eef83ec3a 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -118,7 +118,7 @@ const uint8_t mo_command_flags[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static uint64_t mo_mode_sense_page_flags = (GPMODEP_ALL_PAGES); +static uint64_t mo_mode_sense_page_flags = GPMODEP_ALL_PAGES; static const mode_sense_pages_t mo_mode_sense_pages_default = // clang-format off @@ -306,9 +306,7 @@ mo_log(const char *fmt, ...) int find_mo_for_channel(uint8_t channel) { - uint8_t i = 0; - - for (i = 0; i < MO_NUM; i++) { + for (uint8_t i = 0; i < MO_NUM; i++) { if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel == channel)) return i; } @@ -340,8 +338,8 @@ int mo_load(mo_t *dev, char *fn) { int is_mdi; - uint32_t size = 0; - unsigned int i, found = 0; + uint32_t size = 0; + unsigned int found = 0; is_mdi = image_is_mdi(fn); @@ -366,7 +364,7 @@ mo_load(mo_t *dev, char *fn) dev->drv->base = 0x1000; } - for (i = 0; i < KNOWN_MO_TYPES; i++) { + for (uint8_t i = 0; i < KNOWN_MO_TYPES; i++) { if (size == (mo_types[i].sectors * mo_types[i].bytes_per_sector)) { found = 1; dev->drv->medium_size = mo_types[i].sectors; @@ -500,6 +498,9 @@ mo_atapi_phase_to_scsi(mo_t *dev) return 1; case 3: return 7; + + default: + break; } } else { if ((dev->phase & 3) == 3) @@ -571,6 +572,9 @@ mo_mode_sense_read(mo_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) else return mo_mode_sense_pages_default.pages[page][pos]; break; + + default: + break; } return 0; @@ -584,9 +588,6 @@ mo_mode_sense(mo_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block pf = mo_mode_sense_page_flags; - int i = 0; - int j = 0; - uint8_t msplen; page &= 0x3f; @@ -602,14 +603,14 @@ mo_mode_sense(mo_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block buf[pos++] = (dev->drv->sector_size & 0xff); } - for (i = 0; i < 0x40; i++) { + for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { if (pf & (1LL << ((uint64_t) page))) { buf[pos++] = mo_mode_sense_read(dev, page_control, i, 0); msplen = mo_mode_sense_read(dev, page_control, i, 1); buf[pos++] = msplen; mo_log("MO %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); - for (j = 0; j < msplen; j++) + for (uint8_t j = 0; j < msplen; j++) buf[pos++] = mo_mode_sense_read(dev, page_control, i, 2 + j); } } @@ -621,7 +622,8 @@ mo_mode_sense(mo_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block static void mo_update_request_length(mo_t *dev, int len, int block_len) { - int bt, min_len = 0; + int bt; + int min_len = 0; dev->max_transfer_len = dev->request_length; @@ -653,7 +655,9 @@ mo_update_request_length(mo_t *dev, int len, int block_len) break; } } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: dev->packet_len = len; break; @@ -696,7 +700,8 @@ mo_bus_speed(mo_t *dev) static void mo_command_common(mo_t *dev) { - double bytes_per_second, period; + double bytes_per_second; + double period; dev->status = BUSY_STAT; dev->phase = 1; @@ -796,7 +801,7 @@ mo_data_command_finish(mo_t *dev, int len, int block_len, int alloc_len, int dir } static void -mo_sense_clear(mo_t *dev, int command) +mo_sense_clear(mo_t *dev, UNUSED(int command)) { mo_sense_key = mo_asc = mo_ascq = 0; } @@ -941,10 +946,9 @@ mo_invalid_field_pl(mo_t *dev) } static int -mo_blocks(mo_t *dev, int32_t *len, int first_batch, int out) +mo_blocks(mo_t *dev, int32_t *len, UNUSED(int first_batch), int out) { *len = 0; - int i; if (!dev->sector_len) { mo_command_complete(dev); @@ -961,7 +965,7 @@ mo_blocks(mo_t *dev, int32_t *len, int first_batch, int out) *len = dev->requested_blocks * dev->drv->sector_size; - for (i = 0; i < dev->requested_blocks; i++) { + for (int i = 0; i < dev->requested_blocks; i++) { if (fseek(dev->drv->f, dev->drv->base + (dev->sector_pos * dev->drv->sector_size) + (i * dev->drv->sector_size), SEEK_SET) == 1) break; @@ -1183,7 +1187,9 @@ mo_pre_execution_check(mo_t *dev, uint8_t *cdb) static void mo_seek(mo_t *dev, uint32_t pos) { - /* mo_log("MO %i: Seek %08X\n", dev->id, pos); */ +#if 0 + mo_log("MO %i: Seek %08X\n", dev->id, pos); +#endif dev->sector_pos = pos; } @@ -1283,11 +1289,14 @@ static void mo_command(scsi_common_t *sc, uint8_t *cdb) { mo_t *dev = (mo_t *) sc; - int pos = 0, block_desc = 0; + int pos = 0; + int block_desc = 0; int ret; - int32_t len, max_len; + int32_t len; + int32_t max_len; int32_t alloc_length; - int size_idx, idx = 0; + int size_idx; + int idx = 0; unsigned preamble_len; char device_identify[9] = { '8', '6', 'B', '_', 'M', 'O', '0', '0', 0 }; int32_t blen = 0; @@ -1335,7 +1344,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_invalid_field(dev); return; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_SCSI_RESERVE: case GPCMD_SCSI_RELEASE: case GPCMD_TEST_UNIT_READY: @@ -1418,6 +1429,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); break; + + default: + break; } if (!dev->sector_len) { @@ -1511,6 +1525,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } if ((dev->sector_pos >= dev->drv->medium_size) /* || @@ -1636,6 +1653,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) case 3: /* Load the disk (close tray). */ mo_reload(dev->id); break; + + default: + break; } mo_command_complete(dev); @@ -1688,7 +1708,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[1] = 0x80; /*Removable*/ dev->buffer[2] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ dev->buffer[3] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x21; - // dev->buffer[4] = 31; +#if 0 + dev->buffer[4] = 31; +#endif dev->buffer[4] = 0; if (dev->drv->bus_type == MO_BUS_SCSI) { dev->buffer[6] = 1; /* 16-bit transfers supported */ @@ -1741,6 +1763,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_SEEK_10: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; break; + + default: + break; } mo_seek(dev, pos); mo_command_complete(dev); @@ -1769,7 +1794,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_ERASE_10: case GPCMD_ERASE_12: /*Relative address*/ - if ((cdb[1] & 1)) + if (cdb[1] & 1) previous_pos = dev->sector_pos; switch (cdb[0]) { @@ -1779,10 +1804,13 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_ERASE_12: dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); break; + + default: + break; } /*Erase all remaining sectors*/ - if ((cdb[1] & 4)) { + if (cdb[1] & 4) { /* Cannot have a sector number when erase all*/ if (dev->sector_len) { mo_invalid_field(dev); @@ -1801,6 +1829,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_ERASE_12: dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } dev->sector_pos += previous_pos; @@ -1831,7 +1862,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) break; } - /* mo_log("MO %i: Phase: %02X, request length: %i\n", dev->id, dev->phase, dev->request_length); */ +#if 0 + mo_log("MO %i: Phase: %02X, request length: %i\n", dev->id, dev->phase, dev->request_length); +#endif if (mo_atapi_phase_to_scsi(dev) == SCSI_PHASE_STATUS) mo_buf_free(dev); @@ -1852,15 +1885,18 @@ mo_phase_data_out(scsi_common_t *sc) { mo_t *dev = (mo_t *) sc; - uint16_t block_desc_len, pos; + uint16_t block_desc_len; + uint16_t pos; uint16_t param_list_len; uint8_t error = 0; - uint8_t page, page_len; + uint8_t page; + uint8_t page_len; - uint32_t i = 0; - - uint8_t hdr_len, val, old_val, ch; + uint8_t hdr_len; + uint8_t val; + uint8_t old_val; + uint8_t ch; int len = 0; @@ -1918,7 +1954,7 @@ mo_phase_data_out(scsi_common_t *sc) if (!(mo_mode_sense_page_flags & (1LL << ((uint64_t) page)))) error |= 1; else { - for (i = 0; i < page_len; i++) { + for (uint8_t i = 0; i < page_len; i++) { ch = mo_mode_sense_pages_changeable.pages[page][i + 2]; val = dev->buffer[pos + i]; old_val = dev->ms_pages_saved.pages[page][i + 2]; @@ -1950,6 +1986,9 @@ mo_phase_data_out(scsi_common_t *sc) return 0; } break; + + default: + break; } mo_command_stop((scsi_common_t *) dev); @@ -2016,7 +2055,7 @@ mo_do_identify(ide_t *ide, int ide_has_dma) { char model[40]; - mo_t *mo = (mo_t *) ide->sc; + const mo_t *mo = (mo_t *) ide->sc; memset(model, 0, 40); @@ -2104,10 +2143,10 @@ void mo_hard_reset(void) { mo_t *dev; - int c; - uint8_t scsi_id, scsi_bus; + uint8_t scsi_id; + uint8_t scsi_bus; - for (c = 0; c < MO_NUM; c++) { + for (uint8_t c = 0; c < MO_NUM; c++) { if ((mo_drives[c].bus_type == MO_BUS_ATAPI) || (mo_drives[c].bus_type == MO_BUS_SCSI)) { mo_log("MO hard_reset drive=%d\n", c); @@ -2154,10 +2193,10 @@ void mo_close(void) { mo_t *dev; - int c; - uint8_t scsi_id, scsi_bus; + uint8_t scsi_id; + uint8_t scsi_bus; - for (c = 0; c < MO_NUM; c++) { + for (uint8_t c = 0; c < MO_NUM; c++) { if (mo_drives[c].bus_type == MO_BUS_SCSI) { scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; scsi_id = mo_drives[c].scsi_device_id & 0x0f; diff --git a/src/disk/zip.c b/src/disk/zip.c index a0107d1ef..cd7359c05 100644 --- a/src/disk/zip.c +++ b/src/disk/zip.c @@ -460,9 +460,7 @@ zip_log(const char *fmt, ...) int find_zip_for_channel(uint8_t channel) { - uint8_t i = 0; - - for (i = 0; i < ZIP_NUM; i++) { + for (uint8_t i = 0; i < ZIP_NUM; i++) { if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel == channel)) return i; } @@ -645,6 +643,9 @@ zip_atapi_phase_to_scsi(zip_t *dev) return 1; case 3: return 7; + + default: + break; } } else { if ((dev->phase & 3) == 3) @@ -715,13 +716,11 @@ zip_mode_sense_read(zip_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) if (dev->drv->is_250 && (page == 5) && (pos == 9) && (dev->drv->medium_size == ZIP_SECTORS)) return 0x60; return dev->ms_pages_saved.pages[page][pos]; - break; case 1: if (dev->drv->is_250) return zip_250_mode_sense_pages_changeable.pages[page][pos]; else return zip_mode_sense_pages_changeable.pages[page][pos]; - break; case 2: if (dev->drv->is_250) { if ((page == 5) && (pos == 9) && (dev->drv->medium_size == ZIP_SECTORS)) @@ -736,6 +735,8 @@ zip_mode_sense_read(zip_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) else return zip_mode_sense_pages_default.pages[page][pos]; } + + default: break; } @@ -753,9 +754,6 @@ zip_mode_sense(zip_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t blo else pf = zip_mode_sense_page_flags; - int i = 0; - int j = 0; - uint8_t msplen; page &= 0x3f; @@ -771,14 +769,14 @@ zip_mode_sense(zip_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t blo buf[pos++] = 0; } - for (i = 0; i < 0x40; i++) { + for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { if (pf & (1LL << ((uint64_t) page))) { buf[pos++] = zip_mode_sense_read(dev, page_control, i, 0); msplen = zip_mode_sense_read(dev, page_control, i, 1); buf[pos++] = msplen; zip_log("ZIP %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); - for (j = 0; j < msplen; j++) + for (uint8_t j = 0; j < msplen; j++) buf[pos++] = zip_mode_sense_read(dev, page_control, i, 2 + j); } } @@ -790,7 +788,8 @@ zip_mode_sense(zip_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t blo static void zip_update_request_length(zip_t *dev, int len, int block_len) { - int bt, min_len = 0; + int bt; + int min_len = 0; dev->max_transfer_len = dev->request_length; @@ -822,7 +821,10 @@ zip_update_request_length(zip_t *dev, int len, int block_len) break; } } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + default: dev->packet_len = len; break; @@ -865,7 +867,8 @@ zip_bus_speed(zip_t *dev) static void zip_command_common(zip_t *dev) { - double bytes_per_second, period; + double bytes_per_second; + double period; dev->status = BUSY_STAT; dev->phase = 1; @@ -965,7 +968,7 @@ zip_data_command_finish(zip_t *dev, int len, int block_len, int alloc_len, int d } static void -zip_sense_clear(zip_t *dev, int command) +zip_sense_clear(zip_t *dev, UNUSED(int command)) { zip_sense_key = zip_asc = zip_ascq = 0; } @@ -1119,10 +1122,9 @@ zip_data_phase_error(zip_t *dev) } static int -zip_blocks(zip_t *dev, int32_t *len, int first_batch, int out) +zip_blocks(zip_t *dev, int32_t *len, UNUSED(int first_batch), int out) { *len = 0; - int i; if (!dev->sector_len) { zip_command_complete(dev); @@ -1139,7 +1141,7 @@ zip_blocks(zip_t *dev, int32_t *len, int first_batch, int out) *len = dev->requested_blocks << 9; - for (i = 0; i < dev->requested_blocks; i++) { + for (int i = 0; i < dev->requested_blocks; i++) { if (fseek(dev->drv->f, dev->drv->base + (dev->sector_pos << 9) + (i << 9), SEEK_SET) == 1) break; @@ -1255,7 +1257,9 @@ zip_pre_execution_check(zip_t *dev, uint8_t *cdb) static void zip_seek(zip_t *dev, uint32_t pos) { - /* zip_log("ZIP %i: Seek %08X\n", dev->id, pos); */ +#if 0 + zip_log("ZIP %i: Seek %08X\n", dev->id, pos); +#endif dev->sector_pos = pos; } @@ -1355,12 +1359,15 @@ static void zip_command(scsi_common_t *sc, uint8_t *cdb) { zip_t *dev = (zip_t *) sc; - int pos = 0, block_desc = 0; + int pos = 0; + int block_desc = 0; int ret; - int32_t len, max_len; + int32_t len; + int32_t max_len; int32_t alloc_length; uint32_t i = 0; - int size_idx, idx = 0; + int size_idx; + int idx = 0; unsigned preamble_len; int32_t blen = 0; int32_t *BufLen; @@ -1404,7 +1411,9 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_invalid_field(dev); return; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_SCSI_RESERVE: case GPCMD_SCSI_RELEASE: case GPCMD_TEST_UNIT_READY: @@ -1514,6 +1523,9 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } if (!dev->sector_len) { @@ -1564,6 +1576,9 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_command_complete(dev); break; } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_WRITE_6: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: @@ -1598,6 +1613,9 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } if ((dev->sector_pos >= dev->drv->medium_size) /* || @@ -1769,11 +1787,16 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) case 1: /* Start the disc and read the TOC. */ break; case 2: /* Eject the disc if possible. */ - /* zip_eject(dev->id); */ +#if 0 + zip_eject(dev->id); +#endif break; case 3: /* Load the disc (close tray). */ zip_reload(dev->id); break; + + default: + break; } zip_command_complete(dev); @@ -1851,7 +1874,9 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[1] = 0x80; /*Removable*/ dev->buffer[2] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ dev->buffer[3] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x21; - // dev->buffer[4] = 31; +#if 0 + dev->buffer[4] = 31; +#endif dev->buffer[4] = 0; if (dev->drv->bus_type == ZIP_BUS_SCSI) { dev->buffer[6] = 1; /* 16-bit transfers supported */ @@ -1908,6 +1933,9 @@ atapi_out: case GPCMD_SEEK_10: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; break; + + default: + break; } zip_seek(dev, pos); zip_command_complete(dev); @@ -2011,7 +2039,9 @@ atapi_out: break; } - /* zip_log("ZIP %i: Phase: %02X, request length: %i\n", dev->id, dev->phase, dev->request_length); */ +#if 0 + zip_log("ZIP %i: Phase: %02X, request length: %i\n", dev->id, dev->phase, dev->request_length); +#endif if (zip_atapi_phase_to_scsi(dev) == SCSI_PHASE_STATUS) zip_buf_free(dev); @@ -2032,18 +2062,25 @@ zip_phase_data_out(scsi_common_t *sc) { zip_t *dev = (zip_t *) sc; - uint16_t block_desc_len, pos; + uint16_t block_desc_len; + uint16_t pos; uint16_t param_list_len; uint8_t error = 0; - uint8_t page, page_len; + uint8_t page; + uint8_t page_len; uint32_t i = 0; - uint8_t hdr_len, val, old_val, ch; + uint8_t hdr_len; + uint8_t val; + uint8_t old_val; + uint8_t ch; uint32_t last_to_write = 0; - uint32_t c, h, s; + uint32_t c; + uint32_t h; + uint32_t s; int len = 0; @@ -2165,6 +2202,9 @@ zip_phase_data_out(scsi_common_t *sc) return 0; } break; + + default: + break; } zip_command_stop((scsi_common_t *) dev); @@ -2248,7 +2288,7 @@ zip_250_identify(ide_t *ide, int ide_has_dma) static void zip_identify(ide_t *ide, int ide_has_dma) { - zip_t *zip; + const zip_t *zip; zip = (zip_t *) ide->sc; @@ -2325,10 +2365,10 @@ void zip_hard_reset(void) { zip_t *dev; - int c; - uint8_t scsi_id, scsi_bus; + uint8_t scsi_id; + uint8_t scsi_bus; - for (c = 0; c < ZIP_NUM; c++) { + for (uint8_t c = 0; c < ZIP_NUM; c++) { if ((zip_drives[c].bus_type == ZIP_BUS_ATAPI) || (zip_drives[c].bus_type == ZIP_BUS_SCSI)) { zip_log("ZIP hard_reset drive=%d\n", c); @@ -2375,10 +2415,10 @@ void zip_close(void) { zip_t *dev; - int c; - uint8_t scsi_bus, scsi_id; + uint8_t scsi_bus; + uint8_t scsi_id; - for (c = 0; c < ZIP_NUM; c++) { + for (uint8_t c = 0; c < ZIP_NUM; c++) { if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; scsi_id = zip_drives[c].scsi_device_id & 0x0f; diff --git a/src/dma.c b/src/dma.c index ecdc393ff..a8ba1c1a9 100644 --- a/src/dma.c +++ b/src/dma.c @@ -31,6 +31,7 @@ #include <86box/io.h> #include <86box/pic.h> #include <86box/dma.h> +#include <86box/plat_unused.h> dma_t dma[8]; uint8_t dma_e; @@ -50,9 +51,9 @@ static uint16_t dma_sg_base; static uint16_t dma16_buffer[65536]; static uint32_t dma_mask; -static struct { - int xfr_command, - xfr_channel; +static struct dma_ps2_t { + int xfr_command; + int xfr_channel; int byte_ptr; int is_ps2; @@ -117,7 +118,7 @@ dma_sg_next_addr(dma_t *dev) dev->eot = dev->count >> 31; dev->count &= 0xfffe; dev->cb = (uint16_t) dev->count; - dev->cc = (int) dev->count; + dev->cc = dev->count; if (!dev->count) dev->count = 65536; if (ts == 2) @@ -132,15 +133,13 @@ dma_sg_next_addr(dma_t *dev) static void dma_block_transfer(int channel) { - int i, bit16; - - bit16 = (channel >= 4); + int bit16 = (channel >= 4); if (dma_advanced) bit16 = !!(dma_transfer_size(&(dma[channel])) == 2); dma_req_is_soft = 1; - for (i = 0; i <= dma[channel].cb; i++) { + for (uint16_t i = 0; i <= dma[channel].cb; i++) { if ((dma[channel].mode & 0x8c) == 0x84) { if (bit16) dma_channel_write(channel, dma16_buffer[i]); @@ -228,6 +227,9 @@ dma_sg_write(uint16_t port, uint8_t val, void *priv) dev->ptr = (dev->ptr & 0x00fffffc) | (val << 24); dev->ptr %= (mem_size * 1024); break; + + default: + break; } } @@ -258,6 +260,9 @@ dma_sg_writew(uint16_t port, uint16_t val, void *priv) dev->ptr = (dev->ptr & 0x0000fffc) | (val << 16); dev->ptr %= (mem_size * 1024); break; + + default: + break; } } @@ -284,13 +289,16 @@ dma_sg_writel(uint16_t port, uint32_t val, void *priv) dev->ptr %= (mem_size * 1024); dev->ptr0 = val & 0xff; break; + + default: + break; } } static uint8_t dma_sg_read(uint16_t port, void *priv) { - dma_t *dev = (dma_t *) priv; + const dma_t *dev = (dma_t *) priv; uint8_t ret = 0xff; @@ -325,6 +333,9 @@ dma_sg_read(uint16_t port, void *priv) case 0x23: ret = dev->ptr >> 24; break; + + default: + break; } dma_log("DMA S/G BYTE read : %04X %02X\n", port, ret); @@ -335,7 +346,7 @@ dma_sg_read(uint16_t port, void *priv) static uint16_t dma_sg_readw(uint16_t port, void *priv) { - dma_t *dev = (dma_t *) priv; + const dma_t *dev = (dma_t *) priv; uint16_t ret = 0xffff; @@ -356,6 +367,9 @@ dma_sg_readw(uint16_t port, void *priv) case 0x22: ret = dev->ptr >> 16; break; + + default: + break; } dma_log("DMA S/G WORD read : %04X %04X\n", port, ret); @@ -366,7 +380,7 @@ dma_sg_readw(uint16_t port, void *priv) static uint32_t dma_sg_readl(uint16_t port, void *priv) { - dma_t *dev = (dma_t *) priv; + const dma_t *dev = (dma_t *) priv; uint32_t ret = 0xffffffff; @@ -384,6 +398,9 @@ dma_sg_readl(uint16_t port, void *priv) case 0x20: ret = dev->ptr0 | (dev->ptr & 0xffffff00); break; + + default: + break; } dma_log("DMA S/G DWORD read : %04X %08X\n", port, ret); @@ -392,7 +409,7 @@ dma_sg_readl(uint16_t port, void *priv) } static void -dma_ext_mode_write(uint16_t addr, uint8_t val, void *priv) +dma_ext_mode_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { int channel = (val & 0x03); @@ -416,16 +433,18 @@ dma_ext_mode_write(uint16_t addr, uint8_t val, void *priv) case 0x03: dma[channel].transfer_mode = 0x0102; break; + + default: + break; } } static uint8_t -dma_sg_int_status_read(uint16_t addr, void *priv) +dma_sg_int_status_read(UNUSED(uint16_t addr), UNUSED(void *priv)) { - int i; uint8_t ret = 0x00; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { if (i != 4) ret = (!!(dma[i].sg_status & 8)) << i; } @@ -434,7 +453,7 @@ dma_sg_int_status_read(uint16_t addr, void *priv) } static uint8_t -dma_read(uint16_t addr, void *priv) +dma_read(uint16_t addr, UNUSED(void *priv)) { int channel = (addr >> 1) & 3; uint8_t temp; @@ -458,24 +477,27 @@ dma_read(uint16_t addr, void *priv) temp = dma[channel].cc & 0xff; else temp = dma[channel].cc >> 8; - return (temp); + return temp; case 8: /*Status register*/ temp = dma_stat_rq_pc & 0xf; temp <<= 4; temp |= dma_stat & 0xf; dma_stat &= ~0xf; - return (temp); + return temp; case 0xd: /*Temporary register*/ - return (0); + return 0; + + default: + break; } return (dmaregs[0][addr & 0xf]); } static void -dma_write(uint16_t addr, uint8_t val, void *priv) +dma_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { int channel = (addr >> 1) & 3; @@ -563,13 +585,16 @@ dma_write(uint16_t addr, uint8_t val, void *priv) case 0xf: /*Mask write*/ dma_m = (dma_m & 0xf0) | (val & 0xf); return; + + default: + break; } } static uint8_t -dma_ps2_read(uint16_t addr, void *priv) +dma_ps2_read(uint16_t addr, UNUSED(void *priv)) { - dma_t *dma_c = &dma[dma_ps2.xfr_channel]; + const dma_t *dma_c = &dma[dma_ps2.xfr_channel]; uint8_t temp = 0xff; switch (addr) { @@ -590,6 +615,9 @@ dma_ps2_read(uint16_t addr, void *priv) temp = (dma_c->ac >> 16) & 0xff; dma_ps2.byte_ptr = 0; break; + + default: + break; } break; @@ -627,12 +655,15 @@ dma_ps2_read(uint16_t addr, void *priv) fatal("Bad XFR Read command %i channel %i\n", dma_ps2.xfr_command, dma_ps2.xfr_channel); } break; + + default: + break; } - return (temp); + return temp; } static void -dma_ps2_write(uint16_t addr, uint8_t val, void *priv) +dma_ps2_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { dma_t *dma_c = &dma[dma_ps2.xfr_channel]; uint8_t mode; @@ -655,6 +686,9 @@ dma_ps2_write(uint16_t addr, uint8_t val, void *priv) if (!(dma_m & (1 << dma_ps2.xfr_channel))) dma_ps2_run(dma_ps2.xfr_channel); break; + + default: + break; } break; @@ -684,6 +718,9 @@ dma_ps2_write(uint16_t addr, uint8_t val, void *priv) dma_c->ac = (dma_c->ac & 0x00ffff) | (val << 16); dma_ps2.byte_ptr = 0; break; + + default: + break; } dma_c->ab = dma_c->ac; break; @@ -720,11 +757,14 @@ dma_ps2_write(uint16_t addr, uint8_t val, void *priv) fatal("Bad XFR command %i channel %i val %02x\n", dma_ps2.xfr_command, dma_ps2.xfr_channel, val); } break; + + default: + break; } } static uint8_t -dma16_read(uint16_t addr, void *priv) +dma16_read(uint16_t addr, UNUSED(void *priv)) { int channel = ((addr >> 2) & 3) + 4; uint8_t temp; @@ -754,20 +794,23 @@ dma16_read(uint16_t addr, void *priv) temp = dma[channel].cc & 0xff; else temp = dma[channel].cc >> 8; - return (temp); + return temp; case 8: /*Status register*/ temp = (dma_stat_rq_pc & 0xf0); temp |= dma_stat >> 4; dma_stat &= ~0xf0; - return (temp); + return temp; + + default: + break; } return (dmaregs[1][addr & 0xf]); } static void -dma16_write(uint16_t addr, uint8_t val, void *priv) +dma16_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { int channel = ((addr >> 2) & 3) + 4; addr >>= 1; @@ -856,6 +899,9 @@ dma16_write(uint16_t addr, uint8_t val, void *priv) case 0xf: /*Mask write*/ dma_m = (dma_m & 0x0f) | ((val & 0xf) << 4); return; + + default: + break; } } @@ -865,7 +911,7 @@ dma16_write(uint16_t addr, uint8_t val, void *priv) } static void -dma_page_write(uint16_t addr, uint8_t val, void *priv) +dma_page_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { uint8_t convert[8] = CHANNELS; @@ -890,7 +936,7 @@ dma_page_write(uint16_t addr, uint8_t val, void *priv) dma[addr].ab = (dma[addr].ab & 0xff01ffff & dma_mask) | (dma[addr].page << 16); dma[addr].ac = (dma[addr].ac & 0xff01ffff & dma_mask) | (dma[addr].page << 16); } else { - dma[addr].page = (dma_at) ? val : val & 0xf; + dma[addr].page = dma_at ? val : val & 0xf; dma[addr].ab = (dma[addr].ab & 0xff00ffff & dma_mask) | (dma[addr].page << 16); dma[addr].ac = (dma[addr].ac & 0xff00ffff & dma_mask) | (dma[addr].page << 16); } @@ -898,7 +944,7 @@ dma_page_write(uint16_t addr, uint8_t val, void *priv) } static uint8_t -dma_page_read(uint16_t addr, void *priv) +dma_page_read(uint16_t addr, UNUSED(void *priv)) { uint8_t convert[8] = CHANNELS; uint8_t ret = 0xff; @@ -918,7 +964,7 @@ dma_page_read(uint16_t addr, void *priv) } static void -dma_high_page_write(uint16_t addr, uint8_t val, void *priv) +dma_high_page_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { uint8_t convert[8] = CHANNELS; @@ -938,7 +984,7 @@ dma_high_page_write(uint16_t addr, uint8_t val, void *priv) } static uint8_t -dma_high_page_read(uint16_t addr, void *priv) +dma_high_page_read(uint16_t addr, UNUSED(void *priv)) { uint8_t convert[8] = CHANNELS; uint8_t ret = 0xff; @@ -966,11 +1012,9 @@ dma_set_params(uint8_t advanced, uint32_t mask) void dma_set_mask(uint32_t mask) { - int i; - dma_mask = mask; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { dma[i].ab &= mask; dma[i].ac &= mask; } @@ -1021,14 +1065,12 @@ dma_reset(void) void dma_remove_sg(void) { - int i; - io_removehandler(dma_sg_base + 0x0a, 0x01, dma_sg_int_status_read, NULL, NULL, NULL, NULL, NULL, NULL); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { io_removehandler(dma_sg_base + 0x10 + i, 0x01, dma_sg_read, dma_sg_readw, dma_sg_readl, dma_sg_write, dma_sg_writew, dma_sg_writel, @@ -1047,8 +1089,6 @@ dma_remove_sg(void) void dma_set_sg_base(uint8_t sg_base) { - int i; - dma_sg_base = sg_base << 8; io_sethandler(dma_sg_base + 0x0a, 0x01, @@ -1056,7 +1096,7 @@ dma_set_sg_base(uint8_t sg_base) NULL, NULL, NULL, NULL); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { io_sethandler(dma_sg_base + 0x10 + i, 0x01, dma_sg_read, dma_sg_readw, dma_sg_readl, dma_sg_write, dma_sg_writew, dma_sg_writel, @@ -1178,7 +1218,8 @@ dma_sg(uint8_t *data, int transfer_length, int out, void *priv) char *sop; #endif - int force_end = 0, buffer_pos = 0; + int force_end = 0; + int buffer_pos = 0; #ifdef ENABLE_DMA_LOG sop = out ? "Read" : "Writ"; @@ -1237,7 +1278,7 @@ dma_sg(uint8_t *data, int transfer_length, int out, void *priv) uint8_t _dma_read(uint32_t addr, dma_t *dma_c) { - uint8_t temp; + uint8_t temp = 0; if (dma_advanced) { if (dma_c->sg_status & 1) @@ -1247,13 +1288,13 @@ _dma_read(uint32_t addr, dma_t *dma_c) } else temp = mem_readb_phys(addr); - return (temp); + return temp; } static uint16_t _dma_readw(uint32_t addr, dma_t *dma_c) { - uint16_t temp; + uint16_t temp = 0; if (dma_advanced) { if (dma_c->sg_status & 1) @@ -1263,7 +1304,7 @@ _dma_readw(uint32_t addr, dma_t *dma_c) } else temp = _dma_read(addr, dma_c) | (_dma_read(addr + 1, dma_c) << 8); - return (temp); + return temp; } static void @@ -1416,7 +1457,7 @@ dma_channel_read(int channel) return (temp | DMA_OVER); } - return (temp); + return temp; } int @@ -1500,10 +1541,10 @@ dma_channel_write(int channel, uint16_t val) dma_c->sg_status |= 8; } - return (DMA_OVER); + return DMA_OVER; } - return (0); + return 0; } static void @@ -1604,7 +1645,8 @@ dma_mode(int channel) void dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int TransferSize) { - uint32_t i = 0, n, n2; + uint32_t n; + uint32_t n2; uint8_t bytes[4] = { 0, 0, 0, 0 }; n = TotalSize & ~(TransferSize - 1); @@ -1612,7 +1654,7 @@ dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int Tra /* Do the divisible block, if there is one. */ if (n) { - for (i = 0; i < n; i += TransferSize) + for (uint32_t i = 0; i < n; i += TransferSize) mem_read_phys((void *) &(DataRead[i]), PhysAddress + i, TransferSize); } @@ -1626,7 +1668,8 @@ dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int Tra void dma_bm_write(uint32_t PhysAddress, const uint8_t *DataWrite, uint32_t TotalSize, int TransferSize) { - uint32_t i = 0, n, n2; + uint32_t n; + uint32_t n2; uint8_t bytes[4] = { 0, 0, 0, 0 }; n = TotalSize & ~(TransferSize - 1); @@ -1634,7 +1677,7 @@ dma_bm_write(uint32_t PhysAddress, const uint8_t *DataWrite, uint32_t TotalSize, /* Do the divisible block, if there is one. */ if (n) { - for (i = 0; i < n; i += TransferSize) + for (uint32_t i = 0; i < n; i += TransferSize) mem_write_phys((void *) &(DataWrite[i]), PhysAddress + i, TransferSize); } diff --git a/src/fifo8.c b/src/fifo8.c index 5e3008a7d..feef0deb2 100644 --- a/src/fifo8.c +++ b/src/fifo8.c @@ -51,7 +51,8 @@ fifo8_push(Fifo8 *fifo, uint8_t data) void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num) { - uint32_t start, avail; + uint32_t start; + uint32_t avail; assert(fifo->num + num <= fifo->capacity); @@ -83,7 +84,7 @@ fifo8_pop(Fifo8 *fifo) const uint8_t * fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num) { - uint8_t *ret; + const uint8_t *ret; assert(max > 0 && max <= fifo->num); *num = MIN(fifo->capacity - fifo->head, max); diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 0c35cfcb6..37e078b76 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -36,6 +36,8 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/fdc_ext.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> extern uint64_t motoron[FDD_NUM]; @@ -94,7 +96,7 @@ fdc_log(const char *fmt, ...) # define fdc_log(fmt, ...) #endif -/* +#if 0 const device_t fdc_none_device = { .name = "None", .internal_name = "none", @@ -108,7 +110,7 @@ const device_t fdc_none_device = { .force_redraw = NULL, .config = NULL }; -*/ +#endif const device_t fdc_internal_device = { .name = "Internal", @@ -130,7 +132,9 @@ typedef const struct { static fdc_cards_t fdc_cards[] = { // clang-format off -// { &fdc_none_device }, +#if 0 + { &fdc_none_device }, +#endif { &fdc_internal_device }, { &fdc_b215_device }, { &fdc_pii151b_device }, @@ -146,7 +150,7 @@ fdc_card_available(int card) if (fdc_cards[card].device) return (device_available(fdc_cards[card].device)); - return (1); + return 1; } const device_t * @@ -159,7 +163,7 @@ int fdc_card_has_config(int card) { if (!fdc_cards[card].device) - return (0); + return 0; return (device_has_config(fdc_cards[card].device) ? 1 : 0); } @@ -177,11 +181,11 @@ fdc_card_get_from_internal_name(char *s) while (fdc_cards[c].device != NULL) { if (!strcmp((char *) fdc_cards[c].device->internal_name, s)) - return (c); + return c; c++; } - return (0); + return 0; } void @@ -200,9 +204,9 @@ fdc_get_current_drive(void) } void -fdc_ctrl_reset(void *p) +fdc_ctrl_reset(void *priv) { - fdc_t *fdc = (fdc_t *) p; + fdc_t *fdc = (fdc_t *) priv; fdc->stat = 0x80; fdc->pnum = fdc->ptot = 0; @@ -224,8 +228,8 @@ int fdc_get_compare_condition(fdc_t *fdc) { switch (fdc->interrupt) { - case 0x11: default: + case 0x11: return 0; case 0x19: return 1; @@ -514,6 +518,9 @@ fdc_update_rate(fdc_t *fdc, int drive) case 2: fdc->bit_rate = 2000; break; + + default: + break; } break; case 2: /*Double density*/ @@ -522,6 +529,9 @@ fdc_update_rate(fdc_t *fdc, int drive) case 3: /*Extended density*/ fdc->bit_rate = 1000; break; + + default: + break; } fdc->bitcell_period = (1000000 / fdc->bit_rate) * 2; /*Bitcell period in ns*/ @@ -541,8 +551,9 @@ fdc_get_bit_rate(fdc_t *fdc) return 2; case 1000: return 3; + default: - return 2; + break; } return 2; } @@ -563,6 +574,9 @@ fdc_get_densel(fdc_t *fdc, int drive) return 0; case 2: return 1; + + default: + break; } } @@ -572,6 +586,9 @@ fdc_get_densel(fdc_t *fdc, int drive) return 1; case 3: return 0; + + default: + break; } } else { switch (fdc->densel_force) { @@ -579,6 +596,9 @@ fdc_get_densel(fdc_t *fdc, int drive) return 0; case 1: return 1; + + default: + break; } } @@ -589,6 +609,9 @@ fdc_get_densel(fdc_t *fdc, int drive) case 1: case 2: return fdc->densel_polarity ? 0 : 1; + + default: + break; } return 0; @@ -598,7 +621,9 @@ static void fdc_rate(fdc_t *fdc, int drive) { fdc_update_rate(fdc, drive); - // fdc_log("FDD %c: Setting rate: %i, %i, %i (%i, %i)\n", 0x41 + drive, fdc->drvrate[drive], fdc->rate, fdc_get_densel(fdc, drive), fdc->rwc[drive], fdc->densel_force); +#if 0 + fdc_log("FDD %c: Setting rate: %i, %i, %i (%i, %i)\n", 0x41 + drive, fdc->drvrate[drive], fdc->rate, fdc_get_densel(fdc, drive), fdc->rwc[drive], fdc->densel_force); +#endif fdc_log("FDD %c: [%i] Setting rate: %i, %i, %i (%i, %i, %i)\n", 0x41 + drive, fdc->enh_mode, fdc->drvrate[drive], fdc->rate, fdc_get_densel(fdc, drive), fdc->rwc[drive], fdc->densel_force, fdc->densel_polarity); fdd_set_densel(fdc_get_densel(fdc, drive)); fdc_log("FDD %c: [%i] Densel: %i\n", 0x41 + drive, fdc->enh_mode, fdc_get_densel(fdc, drive)); @@ -710,7 +735,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) { fdc_t *fdc = (fdc_t *) priv; - int drive, i, drive_num; + int drive; + int i; + int drive_num; fdc_log("Write FDC %04X %02X\n", addr, val); @@ -890,7 +917,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc_bad_command(fdc); break; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x07: /*Recalibrate*/ fdc->pnum = 0; fdc->ptot = 1; @@ -933,7 +962,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc_bad_command(fdc); break; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x10: /*Get version*/ case 0x14: /*Unlock*/ case 0x94: /*Lock*/ @@ -1055,7 +1086,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) case 0x16: /* Verify */ if (fdc->params[0] & 0x80) fdc->sc = fdc->params[7]; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x06: /* Read data */ case 0x0c: /* Read deleted data */ fdc_io_command_phase1(fdc, 0); @@ -1134,7 +1167,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc->stat = (1 << fdc->drive); if (!(fdc->flags & FDC_FLAG_PCJR)) fdc->stat |= 0x80; - /* fdc->head = (fdc->params[0] & 4) ? 1 : 0; */ +#if 0 + fdc->head = (fdc->params[0] & 4) ? 1 : 0; +#endif fdc->head = 0; /* TODO: See if this is correct. */ fdc->st0 = fdc->params[0] & 0x03; fdc->st0 |= (fdc->params[0] & 4); @@ -1221,6 +1256,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc->perp |= (fdc->params[0] & 0x03); } return; + + default: + break; } } else fdc->stat = 0x90 | (fdc->stat & 0xf); @@ -1233,6 +1271,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) if (fdc->flags & FDC_FLAG_PS1) fdc->noprec = !!(val & 0x04); return; + + default: + break; } } @@ -1291,6 +1332,9 @@ fdc_read(uint16_t addr, void *priv) case 3: ret |= 0x61; break; + + default: + break; } } else { if (is486 || !fdc->enable_3f1) @@ -1630,7 +1674,7 @@ fdc_callback(void *priv) fdc_poll_readwrite_finish(fdc, compare); return; } - if ((fdd_get_head(real_drive(fdc, fdc->drive)) == 0)) { + if (fdd_get_head(real_drive(fdc, fdc->drive)) == 0) { fdc->sector = 1; fdc->head |= 1; fdd_set_head(real_drive(fdc, fdc->drive), 1); @@ -1675,6 +1719,9 @@ fdc_callback(void *priv) fdc->stat = 0x90; } break; + + default: + break; } fdc->inread = 1; return; @@ -1778,6 +1825,9 @@ fdc_callback(void *priv) fdc->paramstogo = 1; fdc->interrupt = 0; return; + + default: + break; } } @@ -1883,7 +1933,7 @@ fdc_is_verify(fdc_t *fdc) int fdc_data(fdc_t *fdc, uint8_t data, int last) { - int i, result = 0; + int result = 0; int n; if (fdc->deleted & 2) { @@ -1945,7 +1995,7 @@ fdc_data(fdc_t *fdc, uint8_t data, int last) if (fdc->fifobufpos > 0) fdc->fifobufpos = 0; - for (i = 0; i <= n; i++) { + for (int i = 0; i <= n; i++) { result = dma_channel_write(fdc->dma_ch, fdc->fifobuf[i]); if (result & DMA_OVER) { @@ -2057,7 +2107,7 @@ fdc_writeprotect(fdc_t *fdc) int fdc_getdata(fdc_t *fdc, int last) { - int i, data = 0; + int data = 0; if ((fdc->flags & FDC_FLAG_PCJR) || !fdc->dma) { if ((fdc->flags & FDC_FLAG_PCJR) || !fdc->fifo || (fdc->tfifo < 1)) { @@ -2085,7 +2135,7 @@ fdc_getdata(fdc_t *fdc, int last) } } else { if (fdc->fifobufpos == 0) { - for (i = 0; i <= fdc->tfifo; i++) { + for (int i = 0; i <= fdc->tfifo; i++) { data = dma_channel_read(fdc->dma_ch); fdc->fifobuf[i] = data; @@ -2111,7 +2161,7 @@ fdc_getdata(fdc_t *fdc, int last) } void -fdc_sectorid(fdc_t *fdc, uint8_t track, uint8_t side, uint8_t sector, uint8_t size, uint8_t crc1, uint8_t crc2) +fdc_sectorid(fdc_t *fdc, uint8_t track, uint8_t side, uint8_t sector, uint8_t size, UNUSED(uint8_t crc1), UNUSED(uint8_t crc2)) { fdc_int(fdc, 1); fdc->stat = 0xD0; @@ -2242,7 +2292,6 @@ fdc_remove(fdc_t *fdc) void fdc_reset(void *priv) { - int i = 0; uint8_t default_rwc; fdc_t *fdc = (fdc_t *) priv; @@ -2313,7 +2362,7 @@ fdc_reset(void *priv) current_drive = 0; - for (i = 0; i < FDD_NUM; i++) + for (uint8_t i = 0; i < FDD_NUM; i++) ui_sb_update_icon(SB_FLOPPY | i, 0); } diff --git a/src/floppy/fdc_magitronic.c b/src/floppy/fdc_magitronic.c index d71721d7b..084ce8c81 100644 --- a/src/floppy/fdc_magitronic.c +++ b/src/floppy/fdc_magitronic.c @@ -29,19 +29,19 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/fdc_ext.h> +#include <86box/plat_unused.h> #define ROM_B215 "roms/floppy/magitronic/Magitronic B215 - BIOS ROM.bin" #define ROM_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff) #define DRIVE_SELECT (int) (real_drive(dev->fdc_controller, i)) -typedef struct -{ +typedef struct b215_t { fdc_t *fdc_controller; rom_t rom; } b215_t; static uint8_t -b215_read(uint16_t addr, void *priv) +b215_read(UNUSED(uint16_t addr), void *priv) { b215_t *dev = (b215_t *) priv; @@ -58,7 +58,7 @@ b215_read(uint16_t addr, void *priv) */ int drive_spec[2]; - for (int i = 0; i <= 1; i++) { + for (uint8_t i = 0; i <= 1; i++) { if (fdd_is_525(DRIVE_SELECT)) { if (!fdd_is_dd(DRIVE_SELECT)) drive_spec[i] = 1; @@ -88,7 +88,7 @@ b215_close(void *priv) } static void * -b215_init(const device_t *info) +b215_init(UNUSED(const device_t *info)) { b215_t *dev = (b215_t *) malloc(sizeof(b215_t)); memset(dev, 0, sizeof(b215_t)); diff --git a/src/floppy/fdc_monster.c b/src/floppy/fdc_monster.c index 00a9d968a..1629ac1c4 100644 --- a/src/floppy/fdc_monster.c +++ b/src/floppy/fdc_monster.c @@ -32,12 +32,12 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/fdc_ext.h> +#include <86box/plat_unused.h> #define BIOS_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff) #define ROM_MONSTER_FDC "roms/floppy/monster-fdc/floppy_bios.bin" -typedef struct -{ +typedef struct monster_fdc_t { rom_t bios_rom; fdc_t *fdc_pri; fdc_t *fdc_sec; @@ -52,7 +52,7 @@ monster_fdc_close(void *priv) } static void * -monster_fdc_init(const device_t *info) +monster_fdc_init(UNUSED(const device_t *info)) { monster_fdc_t *dev; diff --git a/src/floppy/fdc_pii15xb.c b/src/floppy/fdc_pii15xb.c index be471face..5fd38d250 100644 --- a/src/floppy/fdc_pii15xb.c +++ b/src/floppy/fdc_pii15xb.c @@ -80,8 +80,7 @@ MiniMicro 4 also won't work with the XT FDC which the Zilog claims to be. #define ROM_PII_151B "roms/floppy/dtk/pii-151b.rom" #define ROM_PII_158B "roms/floppy/dtk/pii-158b.rom" -typedef struct -{ +typedef struct pii_t { rom_t bios_rom; } pii_t; diff --git a/src/floppy/fdd.c b/src/floppy/fdd.c index ee43256a4..2d6892623 100644 --- a/src/floppy/fdd.c +++ b/src/floppy/fdd.c @@ -64,7 +64,7 @@ #define FLAG_IGNORE_DENSEL 512 #define FLAG_PS2 1024 -typedef struct { +typedef struct fdd_t { int type; int track; int densel; @@ -80,12 +80,14 @@ char *fdd_image_history[FDD_NUM][FLOPPY_IMAGE_HISTORY]; pc_timer_t fdd_poll_time[FDD_NUM]; -static int fdd_notfound = 0, - driveloaders[FDD_NUM]; +static int fdd_notfound = 0; +static int driveloaders[FDD_NUM]; -int writeprot[FDD_NUM], fwriteprot[FDD_NUM], - fdd_changed[FDD_NUM], ui_writeprot[FDD_NUM] = { 0, 0, 0, 0 }, - drive_empty[FDD_NUM] = { 1, 1, 1, 1 }; +int writeprot[FDD_NUM]; +int fwriteprot[FDD_NUM]; +int fdd_changed[FDD_NUM]; +int ui_writeprot[FDD_NUM] = { 0, 0, 0, 0 }; +int drive_empty[FDD_NUM] = { 1, 1, 1, 1 }; DRIVE drives[FDD_NUM]; @@ -296,9 +298,7 @@ fdd_current_track(int drive) void fdd_set_densel(int densel) { - int i = 0; - - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (drive_types[fdd[i].type].flags & FLAG_INVERT_DENSEL) fdd[i].densel = densel ^ 1; else @@ -451,9 +451,10 @@ fdd_get_densel(int drive) void fdd_load(int drive, char *fn) { - int c = 0, size; - char *p; - FILE *f; + int c = 0; + int size; + const char *p; + FILE * f; fdd_log("FDD: loading drive %d with '%s'\n", drive, fn); @@ -547,8 +548,8 @@ fdd_set_motor_enable(int drive, int motor_enable) static void fdd_poll(void *priv) { - int drive; - DRIVE *drv = (DRIVE *) priv; + int drive; + const DRIVE *drv = (DRIVE *) priv; drive = drv->id; @@ -585,6 +586,9 @@ fdd_get_bitcell_period(int rate) case 3: /*Extended density*/ bit_rate = 1000; break; + + default: + break; } return 1000000 / bit_rate * 2; /*Bitcell period in ns*/ @@ -593,9 +597,7 @@ fdd_get_bitcell_period(int rate) void fdd_reset(void) { - int i; - - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { drives[i].id = i; timer_add(&(fdd_poll_time[i]), fdd_poll, &drives[i], 0); } diff --git a/src/floppy/fdd_86f.c b/src/floppy/fdd_86f.c index 0267cfe81..0e8085a71 100644 --- a/src/floppy/fdd_86f.c +++ b/src/floppy/fdd_86f.c @@ -125,32 +125,38 @@ enum { FMT_POSTTRK_GAP4 }; -typedef struct { +typedef struct sliding_buffer_t { uint8_t buffer[10]; uint32_t pos; uint32_t len; } sliding_buffer_t; -typedef struct { +typedef struct find_t { uint32_t bits_obtained; uint16_t bytes_obtained; uint16_t sync_marks; uint32_t sync_pos; } find_t; -typedef struct { +typedef struct split_byte_t { unsigned nibble0 : 4; unsigned nibble1 : 4; } split_byte_t; -typedef union { +typedef union decoded_t { uint8_t byte; split_byte_t nibbles; } decoded_t; -typedef struct { - uint8_t c, h, r, n; - uint8_t flags, pad, pad0, pad1; +typedef struct sector_t { + uint8_t c; + uint8_t h; + uint8_t r; + uint8_t n; + uint8_t flags; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; void *prev; } sector_t; @@ -173,11 +179,18 @@ typedef struct { * If bits 6, 5 are 0, and bit 7 is 1, the extra bitcell count * specifies the entire bitcell count */ -typedef struct { - FILE *f; - uint8_t state, fill, sector_count, format_state, - error_condition, id_found; - uint16_t version, disk_flags, satisfying_bytes, turbo_pos; +typedef struct d86f_t { + FILE *fp; + uint8_t state; + uint8_t fill; + uint8_t sector_count; + uint8_t format_state; + uint8_t error_condition; + uint8_t id_found; + uint16_t version; + uint16_t disk_flags; + uint16_t satisfying_bytes; + uint16_t turbo_pos; uint16_t cur_track; uint16_t track_encoded_data[2][53048]; uint16_t *track_surface_data[2]; @@ -191,9 +204,13 @@ typedef struct { #ifdef D86F_COMPRESS int is_compressed; #endif - int32_t extra_bit_cells[2]; - uint32_t file_size, index_count, track_pos, datac, - id_pos, dma_over; + int32_t extra_bit_cells[2]; + uint32_t file_size; + uint32_t index_count; + uint32_t track_pos; + uint32_t datac; + uint32_t id_pos; + uint32_t dma_over; uint32_t index_hole_pos[2]; uint32_t track_offset[512]; sector_id_t last_sector; @@ -203,7 +220,8 @@ typedef struct { crc_t calc_crc; crc_t track_crc; char original_file_name[2048]; - uint8_t *filebuf, *outbuf; + uint8_t *filebuf; + uint8_t *outbuf; sector_t *last_side_sector[2]; } d86f_t; @@ -231,7 +249,7 @@ static const uint8_t encoded_mfm[64] = { static d86f_t *d86f[FDD_NUM]; static uint16_t CRCTable[256]; static fdc_t *d86f_fdc; -uint64_t poly = 0x42F0E1EBA9EA3693ll; /* ECMA normal */ +uint64_t poly = 0x42F0E1EBA9EA3693LL; /* ECMA normal */ uint16_t d86f_side_flags(int drive); int d86f_is_mfm(int drive); @@ -261,7 +279,8 @@ d86f_log(const char *fmt, ...) static void setup_crc(uint16_t poly) { - int c = 256, bc; + int c = 256; + int bc; uint16_t temp; while (c--) { @@ -283,7 +302,8 @@ void d86f_destroy_linked_lists(int drive, int side) { d86f_t *dev = d86f[drive]; - sector_t *s, *t; + sector_t *s; + sector_t *t; if (dev == NULL) return; @@ -335,7 +355,7 @@ d86f_reverse_bytes(int drive) uint16_t d86f_disk_flags(int drive) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; return dev->disk_flags; } @@ -343,49 +363,49 @@ d86f_disk_flags(int drive) uint32_t d86f_index_hole_pos(int drive, int side) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; return dev->index_hole_pos[side]; } uint32_t -null_index_hole_pos(int drive, int side) +null_index_hole_pos(UNUSED(int drive), UNUSED(int side)) { return 0; } uint16_t -null_disk_flags(int drive) +null_disk_flags(UNUSED(int drive)) { return 0x09; } uint16_t -null_side_flags(int drive) +null_side_flags(UNUSED(int drive)) { return 0x0A; } void -null_writeback(int drive) +null_writeback(UNUSED(int drive)) { return; } void -null_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) +null_set_sector(UNUSED(int drive), UNUSED(int side), UNUSED(uint8_t c), UNUSED(uint8_t h), UNUSED(uint8_t r), UNUSED(uint8_t n)) { return; } void -null_write_data(int drive, int side, uint16_t pos, uint8_t data) +null_write_data(UNUSED(int drive), UNUSED(int side), UNUSED(uint16_t pos), UNUSED(uint8_t data)) { return; } int -null_format_conditions(int drive) +null_format_conditions(UNUSED(int drive)) { return 0; } @@ -393,13 +413,13 @@ null_format_conditions(int drive) int32_t d86f_extra_bit_cells(int drive, int side) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; return dev->extra_bit_cells[side]; } int32_t -null_extra_bit_cells(int drive, int side) +null_extra_bit_cells(UNUSED(int drive), UNUSED(int side)) { return 0; } @@ -413,7 +433,7 @@ common_encoded_data(int drive, int side) } void -common_read_revolution(int drive) +common_read_revolution(UNUSED(int drive)) { return; } @@ -421,8 +441,8 @@ common_read_revolution(int drive) uint16_t d86f_side_flags(int drive) { - d86f_t *dev = d86f[drive]; - int side; + const d86f_t *dev = d86f[drive]; + int side; side = fdd_get_head(drive); @@ -432,7 +452,9 @@ d86f_side_flags(int drive) uint16_t d86f_track_flags(int drive) { - uint16_t dr, rr, tf; + uint16_t dr; + uint16_t rr; + uint16_t tf; tf = d86f_handler[drive].side_flags(drive); rr = tf & 0x67; @@ -468,10 +490,12 @@ uint32_t common_get_raw_size(int drive, int side) { double rate = 0.0; - double rpm, rpm_diff; + double rpm; + double rpm_diff; double size = 100000.0; int mfm; - int rm, ssd; + int rm; + int ssd; uint32_t extra_bc = 0; mfm = d86f_is_mfm(drive); @@ -601,7 +625,8 @@ int d86f_get_array_size(int drive, int side, int words) { int array_size; - int hole, rm; + int hole; + int rm; int ssd; rm = d86f_get_rpm_mode(drive); @@ -612,9 +637,9 @@ d86f_get_array_size(int drive, int side, int words) array_size = 0; else switch (hole) { + default: case 0: case 1: - default: array_size = 12500; switch (rm) { case 1: @@ -692,7 +717,8 @@ d86f_get_array_size(int drive, int side, int words) int d86f_valid_bit_rate(int drive) { - int hole, rate; + int hole; + int rate; rate = fdc_get_bit_rate(d86f_fdc); hole = (d86f_handler[drive].disk_flags(drive) & 6) >> 1; @@ -785,8 +811,9 @@ d86f_is_mfm(int drive) uint32_t d86f_get_data_len(int drive) { - d86f_t *dev = d86f[drive]; - uint32_t i, ret = 128; + const d86f_t *dev = d86f[drive]; + uint32_t i; + uint32_t ret = 128; if (dev->req_sector.id.n) ret = (uint32_t) 128 << dev->req_sector.id.n; @@ -803,7 +830,7 @@ d86f_has_extra_bit_cells(int drive) } uint32_t -d86f_header_size(int drive) +d86f_header_size(UNUSED(int drive)) { return 8; } @@ -875,15 +902,14 @@ d86f_wrong_densel(int drive) is_3mode = 1; switch (d86f_hole(drive)) { - case 0: default: + case 0: if (fdd_is_dd(drive)) return 0; if (fdd_get_densel(drive)) return 1; else return 0; - break; case 1: if (fdd_is_dd(drive)) @@ -896,7 +922,6 @@ d86f_wrong_densel(int drive) else return 1; } - break; case 2: if (fdd_is_dd(drive) || !fdd_is_ed(drive)) @@ -905,7 +930,6 @@ d86f_wrong_densel(int drive) return 0; else return 1; - break; } } @@ -930,7 +954,9 @@ d86f_encode_byte(int drive, int sync, decoded_t b, decoded_t prev_b) uint8_t bits89AB = prev_b.nibbles.nibble0; uint8_t bits7654 = b.nibbles.nibble1; uint8_t bits3210 = b.nibbles.nibble0; - uint16_t encoded_7654, encoded_3210, result; + uint16_t encoded_7654; + uint16_t encoded_3210; + uint16_t result; if (encoding > 1) return 0xffff; @@ -954,6 +980,9 @@ d86f_encode_byte(int drive, int sync, decoded_t b, decoded_t prev_b) case 0xfc: return result | d86f_encode_get_clock(0x01); + + default: + break; } } else { switch (b.byte) { @@ -964,6 +993,9 @@ d86f_encode_byte(int drive, int sync, decoded_t b, decoded_t prev_b) case 0xfc: return result | d86f_encode_get_clock(0xd7); + + default: + break; } } } @@ -1011,6 +1043,9 @@ d86f_get_bitcell_period(int drive) case 5: rate = 2000.0; break; + + default: + break; } if (!mfm) @@ -1165,7 +1200,7 @@ d86f_put_bit(int drive, int side, int bit) } static uint8_t -decodefm(int drive, uint16_t dat) +decodefm(UNUSED(int drive), uint16_t dat) { uint8_t temp = 0; @@ -1208,8 +1243,8 @@ d86f_calccrc(d86f_t *dev, uint8_t byte) int d86f_word_is_aligned(int drive, int side, uint32_t base_pos) { - d86f_t *dev = d86f[drive]; - uint32_t adjusted_track_pos = dev->track_pos; + const d86f_t *dev = d86f[drive]; + uint32_t adjusted_track_pos = dev->track_pos; if (base_pos == 0xFFFFFFFF) return 0; @@ -1246,7 +1281,7 @@ d86f_find_address_mark_fm(int drive, int side, find_t *find, uint16_t req_am, ui return; } - if ((wrong_am) && (dev->last_word[side] == wrong_am)) { + if (wrong_am && (dev->last_word[side] == wrong_am)) { dev->data_find.sync_marks = dev->data_find.bits_obtained = dev->data_find.bytes_obtained = 0; dev->error_condition = 0; dev->state = STATE_IDLE; @@ -1311,7 +1346,7 @@ d86f_find_address_mark_mfm(int drive, int side, find_t *find, uint16_t req_am, u return; } - if ((wrong_am) && (dev->last_word[side] == wrong_am) && (find->sync_marks >= 3)) { + if (wrong_am && (dev->last_word[side] == wrong_am) && (find->sync_marks >= 3)) { dev->data_find.sync_marks = dev->data_find.bits_obtained = dev->data_find.bytes_obtained = 0; dev->error_condition = 0; dev->state = STATE_IDLE; @@ -1469,7 +1504,8 @@ uint8_t d86f_get_data(int drive, int base) { d86f_t *dev = d86f[drive]; - int data, byte_count; + int data; + int byte_count; if (fdd_get_turbo(drive) && (dev->version == 0x0063)) byte_count = dev->turbo_pos; @@ -1512,6 +1548,9 @@ d86f_compare_byte(int drive, uint8_t received_byte, uint8_t disk_byte) if ((received_byte >= disk_byte) || (received_byte == 0xFF)) dev->satisfying_bytes++; break; + + default: + break; } } @@ -1620,7 +1659,7 @@ d86f_write_sector_data(int drive, int side, int mfm, uint16_t am) d86f_handler[drive].write_data(drive, side, dev->data_find.bytes_obtained - 1, dev->current_byte[side]); } else { /* We're in the data field of the sector, use a CRC byte. */ - dev->current_byte[side] = dev->calc_crc.bytes[(dev->data_find.bytes_obtained & 1)]; + dev->current_byte[side] = dev->calc_crc.bytes[dev->data_find.bytes_obtained & 1]; } dev->current_bit[side] = (15 - (dev->data_find.bits_obtained & 15)) >> 1; @@ -1749,8 +1788,13 @@ void d86f_write_direct_common(int drive, int side, uint16_t byte, uint8_t type, uint32_t pos) { d86f_t *dev = d86f[drive]; - uint16_t encoded_byte = 0, mask_data, mask_surface, mask_hole, mask_fuzzy; - decoded_t dbyte, dpbyte; + uint16_t encoded_byte = 0; + uint16_t mask_data; + uint16_t mask_surface; + uint16_t mask_hole; + uint16_t mask_fuzzy; + decoded_t dbyte; + decoded_t dpbyte; if (fdc_get_diswr(d86f_fdc)) return; @@ -1797,7 +1841,7 @@ d86f_write_direct_common(int drive, int side, uint16_t byte, uint8_t type, uint3 void d86f_write_direct(int drive, int side, uint16_t byte, uint8_t type) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; d86f_write_direct_common(drive, side, byte, type, dev->track_pos >> 4); } @@ -1815,7 +1859,7 @@ endian_swap(uint16_t word) } void -d86f_format_finish(int drive, int side, int mfm, uint16_t sc, uint16_t gap_fill, int do_write) +d86f_format_finish(int drive, int side, int mfm, UNUSED(uint16_t sc), uint16_t gap_fill, int do_write) { d86f_t *dev = d86f[drive]; @@ -1836,7 +1880,7 @@ d86f_format_finish(int drive, int side, int mfm, uint16_t sc, uint16_t gap_fill, } void -d86f_format_turbo_finish(int drive, int side, int do_write) +d86f_format_turbo_finish(int drive, UNUSED(int side), int do_write) { d86f_t *dev = d86f[drive]; @@ -1907,7 +1951,9 @@ d86f_format_track(int drive, int side, int do_write) if (dev->datac == 3) fdc_stop_id_request(d86f_fdc); } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case FMT_PRETRK_SYNC: case FMT_SECTOR_DATA_SYNC: @@ -2036,13 +2082,14 @@ d86f_format_track(int drive, int side, int do_write) /* Sector within allotted amount, change state to SECTOR_ID_SYNC. */ dev->format_state = FMT_SECTOR_ID_SYNC; fdc_request_next_sector_id(d86f_fdc); - break; } else { dev->format_state = FMT_POSTTRK_GAP4; dev->sector_count = 0; - break; } break; + + default: + break; } } } @@ -2061,8 +2108,9 @@ d86f_initialize_last_sector_id(int drive, int c, int h, int r, int n) static uint8_t d86f_sector_flags(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { - d86f_t *dev = d86f[drive]; - sector_t *s, *t; + const d86f_t *dev = d86f[drive]; + sector_t *s; + sector_t *t; if (dev->last_side_sector[side]) { s = dev->last_side_sector[side]; @@ -2169,7 +2217,6 @@ d86f_turbo_format(int drive, int side, int nop) int dat; uint16_t sc; uint16_t dtl; - int i; sc = fdc_get_format_sectors(d86f_fdc); dtl = 128 << fdc_get_format_n(d86f_fdc); @@ -2187,7 +2234,7 @@ d86f_turbo_format(int drive, int side, int nop) } } else if (dev->datac == 4) { if (!nop) { - for (i = 0; i < dtl; i++) + for (uint16_t i = 0; i < dtl; i++) d86f_handler[drive].write_data(drive, side, i, dev->fill); } @@ -2212,8 +2259,9 @@ d86f_turbo_format(int drive, int side, int nop) int d86f_sector_is_present(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { - d86f_t *dev = d86f[drive]; - sector_t *s, *t; + const d86f_t *dev = d86f[drive]; + sector_t *s; + sector_t *t; if (dev->last_side_sector[side]) { s = dev->last_side_sector[side]; @@ -2248,7 +2296,9 @@ d86f_turbo_poll(int drive, int side) case STATE_0D_SPIN_TO_INDEX: dev->sector_count = 0; dev->datac = 5; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_02_SPIN_TO_INDEX: dev->state++; @@ -2293,7 +2343,9 @@ d86f_turbo_poll(int drive, int side) dev->last_sector.id.r = dev->req_sector.id.r; dev->last_sector.id.n = dev->req_sector.id.n; d86f_handler[drive].set_sector(drive, side, dev->last_sector.id.c, dev->last_sector.id.h, dev->last_sector.id.r, dev->last_sector.id.n); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_0A_FIND_ID: dev->turbo_pos = 0; @@ -2354,7 +2406,8 @@ void d86f_poll(int drive) { d86f_t *dev = d86f[drive]; - int mfm, side; + int mfm; + int side; side = fdd_get_head(drive); if (!fdd_is_double_sided(drive)) @@ -2550,7 +2603,7 @@ uint16_t d86f_prepare_pretrack(int drive, int side, int iso) { d86f_t *dev = d86f[drive]; - uint16_t i, pos; + uint16_t pos; int mfm; int real_gap0_len; int sync_len; @@ -2575,22 +2628,22 @@ d86f_prepare_pretrack(int drive, int side, int iso) d86f_destroy_linked_lists(drive, side); - for (i = 0; i < raw_size; i++) + for (uint32_t i = 0; i < raw_size; i++) d86f_write_direct_common(drive, side, gap_fill, 0, i); pos = 0; if (!iso) { - for (i = 0; i < real_gap0_len; i++) { + for (int i = 0; i < real_gap0_len; i++) { d86f_write_direct_common(drive, side, gap_fill, 0, pos); pos = (pos + 1) % raw_size; } - for (i = 0; i < sync_len; i++) { + for (int i = 0; i < sync_len; i++) { d86f_write_direct_common(drive, side, 0, 0, pos); pos = (pos + 1) % raw_size; } if (mfm) { - for (i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { d86f_write_direct_common(drive, side, 0x2452, 1, pos); pos = (pos + 1) % raw_size; } @@ -2600,7 +2653,7 @@ d86f_prepare_pretrack(int drive, int side, int iso) pos = (pos + 1) % raw_size; } - for (i = 0; i < real_gap1_len; i++) { + for (int i = 0; i < real_gap1_len; i++) { d86f_write_direct_common(drive, side, gap_fill, 0, pos); pos = (pos + 1) % raw_size; } @@ -2750,21 +2803,28 @@ void d86f_construct_encoded_buffer(int drive, int side) { d86f_t *dev = d86f[drive]; - uint32_t i = 0; /* *_fuzm are fuzzy bit masks, *_holm are hole masks, dst_neim are masks is mask for bits that are neither fuzzy nor holes in both, and src1_d and src2_d are filtered source data. */ - uint16_t src1_fuzm, src2_fuzm, dst_fuzm, src1_holm, src2_holm, dst_holm, dst_neim, src1_d, src2_d; - uint32_t len; - uint16_t *dst = dev->track_encoded_data[side]; - uint16_t *dst_s = dev->track_surface_data[side]; - uint16_t *src1 = dev->thin_track_encoded_data[0][side]; - uint16_t *src1_s = dev->thin_track_surface_data[0][side]; - uint16_t *src2 = dev->thin_track_encoded_data[1][side]; - uint16_t *src2_s = dev->thin_track_surface_data[1][side]; + uint16_t src1_fuzm; + uint16_t src2_fuzm; + uint16_t dst_fuzm; + uint16_t src1_holm; + uint16_t src2_holm; + uint16_t dst_holm; + uint16_t dst_neim; + uint16_t src1_d; + uint16_t src2_d; + uint32_t len; + uint16_t *dst = dev->track_encoded_data[side]; + uint16_t *dst_s = dev->track_surface_data[side]; + const uint16_t *src1 = dev->thin_track_encoded_data[0][side]; + const uint16_t *src1_s = dev->thin_track_surface_data[0][side]; + const uint16_t *src2 = dev->thin_track_encoded_data[1][side]; + const uint16_t *src2_s = dev->thin_track_surface_data[1][side]; len = d86f_get_array_size(drive, side, 1); - for (i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { /* The two bits differ. */ if (d86f_has_surface_desc(drive)) { /* Source image has surface description data, so we have some more handling to do. */ @@ -2798,19 +2858,19 @@ d86f_construct_encoded_buffer(int drive, int side) void d86f_decompose_encoded_buffer(int drive, int side) { - d86f_t *dev = d86f[drive]; - uint32_t i = 0; - uint16_t temp, temp2; - uint32_t len; - uint16_t *dst = dev->track_encoded_data[side]; - uint16_t *src1 = dev->thin_track_encoded_data[0][side]; - uint16_t *src1_s = dev->thin_track_surface_data[0][side]; - uint16_t *src2 = dev->thin_track_encoded_data[1][side]; - uint16_t *src2_s = dev->thin_track_surface_data[1][side]; - dst = d86f_handler[drive].encoded_data(drive, side); - len = d86f_get_array_size(drive, side, 1); + d86f_t *dev = d86f[drive]; + uint16_t temp; + uint16_t temp2; + uint32_t len; + const uint16_t *dst = dev->track_encoded_data[side]; + uint16_t *src1 = dev->thin_track_encoded_data[0][side]; + uint16_t *src1_s = dev->thin_track_surface_data[0][side]; + uint16_t *src2 = dev->thin_track_encoded_data[1][side]; + uint16_t *src2_s = dev->thin_track_surface_data[1][side]; + dst = d86f_handler[drive].encoded_data(drive, side); + len = d86f_get_array_size(drive, side, 1); - for (i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { if (d86f_has_surface_desc(drive)) { /* Source image has surface description data, so we have some more handling to do. We need hole masks for both buffers. Holes have data bit clear and surface bit set. */ @@ -2851,12 +2911,12 @@ d86f_read_track(int drive, int track, int thin_track, int side, uint16_t *da, ui if (dev->track_offset[logical_track]) { if (!thin_track) { - if (fseek(dev->f, dev->track_offset[logical_track], SEEK_SET) == -1) + if (fseek(dev->fp, dev->track_offset[logical_track], SEEK_SET) == -1) fatal("d86f_read_track(): Error seeking to offset dev->track_offset[logical_track]\n"); - if (fread(&(dev->side_flags[side]), 1, 2, dev->f) != 2) + if (fread(&(dev->side_flags[side]), 1, 2, dev->fp) != 2) fatal("d86f_read_track(): Error reading side flags\n"); if (d86f_has_extra_bit_cells(drive)) { - if (fread(&(dev->extra_bit_cells[side]), 1, 4, dev->f) != 4) + if (fread(&(dev->extra_bit_cells[side]), 1, 4, dev->fp) != 4) fatal("d86f_read_track(): Error reading number of extra bit cells\n"); /* If RPM shift is 0% and direction is 1, do not adjust extra bit cells, as that is the whole track length. */ @@ -2868,18 +2928,18 @@ d86f_read_track(int drive, int track, int thin_track, int side, uint16_t *da, ui } } else dev->extra_bit_cells[side] = 0; - (void) !fread(&(dev->index_hole_pos[side]), 4, 1, dev->f); + (void) !fread(&(dev->index_hole_pos[side]), 4, 1, dev->fp); } else - fseek(dev->f, dev->track_offset[logical_track] + d86f_track_header_size(drive), SEEK_SET); + fseek(dev->fp, dev->track_offset[logical_track] + d86f_track_header_size(drive), SEEK_SET); array_size = d86f_get_array_size(drive, side, 0); - (void) !fread(da, 1, array_size, dev->f); + (void) !fread(da, 1, array_size, dev->fp); if (d86f_has_surface_desc(drive)) - (void) !fread(sa, 1, array_size, dev->f); + (void) !fread(sa, 1, array_size, dev->fp); } else { if (!thin_track) { switch ((dev->disk_flags >> 1) & 3) { - case 0: default: + case 0: dev->side_flags[side] = 0x0A; break; @@ -2901,10 +2961,10 @@ void d86f_zero_track(int drive) { d86f_t *dev = d86f[drive]; - int sides, side; + int sides; sides = d86f_get_sides(drive); - for (side = 0; side < sides; side++) { + for (int side = 0; side < sides; side++) { if (d86f_has_surface_desc(drive)) memset(dev->track_surface_data[side], 0, 106096); memset(dev->track_encoded_data[side], 0, 106096); @@ -2916,7 +2976,8 @@ d86f_seek(int drive, int track) { d86f_t *dev = d86f[drive]; int sides; - int side, thin_track; + int side; + int thin_track; sides = d86f_get_sides(drive); /* If the drive has thick tracks, shift the track number by 1. */ @@ -2995,8 +3056,9 @@ void d86f_write_tracks(int drive, FILE **f, uint32_t *track_table) { d86f_t *dev = d86f[drive]; - int sides, fdd_side; - int side, thin_track; + int sides; + int fdd_side; + int side; int logical_track = 0; uint32_t *tbl; tbl = dev->track_offset; @@ -3011,7 +3073,7 @@ d86f_write_tracks(int drive, FILE **f, uint32_t *track_table) if (sides == 2) d86f_decompose_encoded_buffer(drive, 1); - for (thin_track = 0; thin_track < 2; thin_track++) { + for (uint8_t thin_track = 0; thin_track < 2; thin_track++) { for (side = 0; side < sides; side++) { fdd_set_head(drive, side); @@ -3060,7 +3122,8 @@ d86f_writeback(int drive) { d86f_t *dev = d86f[drive]; uint8_t header[32]; - int header_size, size; + int header_size; + int size; #ifdef D86F_COMPRESS uint32_t len; int ret = 0; @@ -3068,22 +3131,22 @@ d86f_writeback(int drive) #endif header_size = d86f_header_size(drive); - if (!dev->f) + if (!dev->fp) return; /* First write the track offsets table. */ - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("86F write_back(): Error seeking to the beginning of the file\n"); - if (fread(header, 1, header_size, dev->f) != header_size) + if (fread(header, 1, header_size, dev->fp) != header_size) fatal("86F write_back(): Error reading header size\n"); - if (fseek(dev->f, 8, SEEK_SET) == -1) + if (fseek(dev->fp, 8, SEEK_SET) == -1) fatal("86F write_back(): Error seeking\n"); size = d86f_get_track_table_size(drive); - if (fwrite(dev->track_offset, 1, size, dev->f) != size) + if (fwrite(dev->track_offset, 1, size, dev->fp) != size) fatal("86F write_back(): Error writing data\n"); - d86f_write_tracks(drive, &dev->f, NULL); + d86f_write_tracks(drive, &dev->fp, NULL); #ifdef D86F_COMPRESS if (dev->is_compressed) { @@ -3095,16 +3158,16 @@ d86f_writeback(int drive) /* Write the header to the original file. */ fwrite(header, 1, header_size, cf); - fseek(dev->f, 0, SEEK_END); - len = ftell(dev->f); + fseek(dev->fp, 0, SEEK_END); + len = ftell(dev->fp); len -= header_size; - fseek(dev->f, header_size, SEEK_SET); + fseek(dev->fp, header_size, SEEK_SET); /* Compress data from the temporary uncompressed file to the original, compressed file. */ dev->filebuf = (uint8_t *) malloc(len); dev->outbuf = (uint8_t *) malloc(len - 1); - fread(dev->filebuf, 1, len, dev->f); + fread(dev->filebuf, 1, len, dev->fp); ret = lzf_compress(dev->filebuf, len, dev->outbuf, len - 1); if (!ret) @@ -3127,7 +3190,7 @@ d86f_stop(int drive) } int -d86f_common_command(int drive, int sector, int track, int side, int rate, int sector_size) +d86f_common_command(int drive, int sector, int track, int side, UNUSED(int rate), int sector_size) { d86f_t *dev = d86f[drive]; @@ -3211,7 +3274,7 @@ d86f_comparesector(int drive, int sector, int track, int side, int rate, int sec } void -d86f_readaddress(int drive, int side, int rate) +d86f_readaddress(int drive, UNUSED(int side), UNUSED(int rate)) { d86f_t *dev = d86f[drive]; @@ -3261,11 +3324,11 @@ d86f_add_track(int drive, int track, int side) } void -d86f_common_format(int drive, int side, int rate, uint8_t fill, int proxy) +d86f_common_format(int drive, int side, UNUSED(int rate), uint8_t fill, int proxy) { d86f_t *dev = d86f[drive]; - uint32_t i = 0; - uint16_t temp, temp2; + uint16_t temp; + uint16_t temp2; uint32_t array_size; if (writeprot[drive]) { @@ -3297,7 +3360,7 @@ d86f_common_format(int drive, int side, int rate, uint8_t fill, int proxy) if (d86f_has_surface_desc(drive)) { /* Preserve the physical holes but get rid of the fuzzy bytes. */ - for (i = 0; i < array_size; i++) { + for (uint32_t i = 0; i < array_size; i++) { temp = dev->track_encoded_data[side][i] ^ 0xffff; temp2 = dev->track_surface_data[side][i]; temp &= temp2; @@ -3364,9 +3427,8 @@ d86f_export(int drive, char *fn) uint32_t tt[512]; d86f_t *dev = d86f[drive]; d86f_t *temp86; - FILE *f; + FILE *fp; int tracks = 86; - int i; int inc = 1; uint32_t magic = 0x46423638; uint16_t version = 0x020C; @@ -3374,42 +3436,42 @@ d86f_export(int drive, char *fn) memset(tt, 0, 512 * sizeof(uint32_t)); - f = plat_fopen(fn, "wb"); - if (!f) + fp = plat_fopen(fn, "wb"); + if (!fp) return 0; /* Allocate a temporary drive for conversion. */ temp86 = (d86f_t *) malloc(sizeof(d86f_t)); memcpy(temp86, dev, sizeof(d86f_t)); - fwrite(&magic, 4, 1, f); - fwrite(&version, 2, 1, f); - fwrite(&disk_flags, 2, 1, f); + fwrite(&magic, 4, 1, fp); + fwrite(&version, 2, 1, fp); + fwrite(&disk_flags, 2, 1, fp); - fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), f); + fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), fp); /* In the case of a thick track drive, always increment track by two, since two tracks are going to get output at once. */ if (!fdd_doublestep_40(drive)) inc = 2; - for (i = 0; i < tracks; i += inc) { + for (int i = 0; i < tracks; i += inc) { if (inc == 2) fdd_do_seek(drive, i >> 1); else fdd_do_seek(drive, i); dev->cur_track = i; - d86f_write_tracks(drive, &f, tt); + d86f_write_tracks(drive, &fp, tt); } - fclose(f); + fclose(fp); - f = plat_fopen(fn, "rb+"); + fp = plat_fopen(fn, "rb+"); - fseek(f, 8, SEEK_SET); - fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), f); + fseek(fp, 8, SEEK_SET); + fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), fp); - fclose(f); + fclose(fp); fdd_do_seek(drive, fdd_current_track(drive)); @@ -3426,7 +3488,6 @@ d86f_load(int drive, char *fn) d86f_t *dev = d86f[drive]; uint32_t magic = 0; uint32_t len = 0; - int i = 0, j = 0; #ifdef D86F_COMPRESS char temp_file_name[2048]; uint16_t temp = 0; @@ -3437,10 +3498,10 @@ d86f_load(int drive, char *fn) writeprot[drive] = 0; - dev->f = plat_fopen(fn, "rb+"); - if (!dev->f) { - dev->f = plat_fopen(fn, "rb"); - if (!dev->f) { + dev->fp = plat_fopen(fn, "rb+"); + if (!dev->fp) { + dev->fp = plat_fopen(fn, "rb"); + if (!dev->fp) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3453,16 +3514,16 @@ d86f_load(int drive, char *fn) } fwriteprot[drive] = writeprot[drive]; - fseek(dev->f, 0, SEEK_END); - len = ftell(dev->f); - fseek(dev->f, 0, SEEK_SET); + fseek(dev->fp, 0, SEEK_END); + len = ftell(dev->fp); + fseek(dev->fp, 0, SEEK_SET); - (void) !fread(&magic, 4, 1, dev->f); + (void) !fread(&magic, 4, 1, dev->fp); if (len < 16) { /* File is WAY too small, abort. */ - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3471,13 +3532,13 @@ d86f_load(int drive, char *fn) if ((magic != 0x46423638) && (magic != 0x66623638)) { /* File is not of the valid format, abort. */ d86f_log("86F: Unrecognized magic bytes: %08X\n", magic); - fclose(dev->f); + fclose(dev->fp); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; } - if (fread(&(dev->version), 1, 2, dev->f) != 2) + if (fread(&(dev->version), 1, 2, dev->fp) != 2) fatal("d86f_load(): Error reading format version\n"); if (dev->version != D86FVER) { @@ -3489,8 +3550,8 @@ d86f_load(int drive, char *fn) } else { d86f_log("86F: Unrecognized file version: %i.%02i\n", dev->version >> 8, dev->version & 0xff); } - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3498,14 +3559,14 @@ d86f_load(int drive, char *fn) d86f_log("86F: Recognized file version: %i.%02i\n", dev->version >> 8, dev->version & 0xff); } - (void) !fread(&(dev->disk_flags), 2, 1, dev->f); + (void) !fread(&(dev->disk_flags), 2, 1, dev->fp); if (d86f_has_surface_desc(drive)) { - for (i = 0; i < 2; i++) + for (uint8_t i = 0; i < 2; i++) dev->track_surface_data[i] = (uint16_t *) malloc(53048 * sizeof(uint16_t)); - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) + for (uint8_t i = 0; i < 2; i++) { + for (uint8_t j = 0; j < 2; j++) dev->thin_track_surface_data[i][j] = (uint16_t *) malloc(53048 * sizeof(uint16_t)); } } @@ -3517,31 +3578,31 @@ d86f_load(int drive, char *fn) if (len < 51052) { #endif /* File too small, abort. */ - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; } #ifdef DO_CRC64 - fseek(dev->f, 8, SEEK_SET); - fread(&read_crc64, 1, 8, dev->f); + fseek(dev->fp, 8, SEEK_SET); + fread(&read_crc64, 1, 8, dev->fp); - fseek(dev->f, 0, SEEK_SET); + fseek(dev->fp, 0, SEEK_SET); crc64 = 0xffffffffffffffff; dev->filebuf = malloc(len); - fread(dev->filebuf, 1, len, dev->f); + fread(dev->filebuf, 1, len, dev->fp); *(uint64_t *) &(dev->filebuf[8]) = 0xffffffffffffffff; crc64 = (uint64_t) crc64speed(0, dev->filebuf, len); free(dev->filebuf); if (crc64 != read_crc64) { d86f_log("86F: CRC64 error\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3553,11 +3614,11 @@ d86f_load(int drive, char *fn) memcpy(temp_file_name, drive ? nvr_path("TEMP$$$1.$$$") : nvr_path("TEMP$$$0.$$$"), 256); memcpy(dev->original_file_name, fn, strlen(fn) + 1); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; - dev->f = plat_fopen(temp_file_name, "wb"); - if (!dev->f) { + dev->fp = plat_fopen(temp_file_name, "wb"); + if (!dev->fp) { d86f_log("86F: Unable to create temporary decompressed file\n"); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); @@ -3566,9 +3627,9 @@ d86f_load(int drive, char *fn) tf = plat_fopen(fn, "rb"); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { fread(&temp, 1, 2, tf); - fwrite(&temp, 1, 2, dev->f); + fwrite(&temp, 1, 2, dev->fp); } dev->filebuf = (uint8_t *) malloc(len); @@ -3576,14 +3637,14 @@ d86f_load(int drive, char *fn) fread(dev->filebuf, 1, len, tf); temp = lzf_decompress(dev->filebuf, len, dev->outbuf, 67108864); if (temp) { - fwrite(dev->outbuf, 1, temp, dev->f); + fwrite(dev->outbuf, 1, temp, dev->fp); } free(dev->outbuf); free(dev->filebuf); fclose(tf); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; if (!temp) { d86f_log("86F: Error decompressing file\n"); @@ -3593,15 +3654,15 @@ d86f_load(int drive, char *fn) return; } - dev->f = plat_fopen(temp_file_name, "rb+"); + dev->fp = plat_fopen(temp_file_name, "rb+"); } #endif if (dev->disk_flags & 0x100) { /* Zoned disk. */ d86f_log("86F: Disk is zoned (Apple or Sony)\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; #ifdef D86F_COMPRESS if (dev->is_compressed) plat_remove(temp_file_name); @@ -3614,8 +3675,8 @@ d86f_load(int drive, char *fn) if (dev->disk_flags & 0x600) { /* Zone type is not 0 but the disk is fixed-RPM. */ d86f_log("86F: Disk is fixed-RPM but zone type is not 0\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; #ifdef D86F_COMPRESS if (dev->is_compressed) plat_remove(temp_file_name); @@ -3631,29 +3692,29 @@ d86f_load(int drive, char *fn) } if (writeprot[drive]) { - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; #ifdef D86F_COMPRESS if (dev->is_compressed) - dev->f = plat_fopen(temp_file_name, "rb"); + dev->fp = plat_fopen(temp_file_name, "rb"); else #endif - dev->f = plat_fopen(fn, "rb"); + dev->fp = plat_fopen(fn, "rb"); } /* OK, set the drive data, other code needs it. */ d86f[drive] = dev; - fseek(dev->f, 8, SEEK_SET); + fseek(dev->fp, 8, SEEK_SET); - (void) !fread(dev->track_offset, 1, d86f_get_track_table_size(drive), dev->f); + (void) !fread(dev->track_offset, 1, d86f_get_track_table_size(drive), dev->fp); if (!(dev->track_offset[0])) { /* File has no track 0 side 0, abort. */ d86f_log("86F: No Track 0 side 0\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); d86f[drive] = NULL; @@ -3663,8 +3724,8 @@ d86f_load(int drive, char *fn) if ((d86f_get_sides(drive) == 2) && !(dev->track_offset[1])) { /* File is 2-sided but has no track 0 side 1, abort. */ d86f_log("86F: No Track 0 side 1\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); d86f[drive] = NULL; @@ -3672,12 +3733,12 @@ d86f_load(int drive, char *fn) } /* Load track 0 flags as default. */ - if (fseek(dev->f, dev->track_offset[0], SEEK_SET) == -1) + if (fseek(dev->fp, dev->track_offset[0], SEEK_SET) == -1) fatal("d86f_load(): Track 0: Error seeking to the beginning of the file\n"); - if (fread(&(dev->side_flags[0]), 1, 2, dev->f) != 2) + if (fread(&(dev->side_flags[0]), 1, 2, dev->fp) != 2) fatal("d86f_load(): Track 0: Error reading side flags\n"); if (dev->disk_flags & 0x80) { - if (fread(&(dev->extra_bit_cells[0]), 1, 4, dev->f) != 4) + if (fread(&(dev->extra_bit_cells[0]), 1, 4, dev->fp) != 4) fatal("d86f_load(): Track 0: Error reading the amount of extra bit cells\n"); if ((dev->disk_flags & 0x1060) != 0x1000) { if (dev->extra_bit_cells[0] < -32768) @@ -3690,12 +3751,12 @@ d86f_load(int drive, char *fn) } if (d86f_get_sides(drive) == 2) { - if (fseek(dev->f, dev->track_offset[1], SEEK_SET) == -1) + if (fseek(dev->fp, dev->track_offset[1], SEEK_SET) == -1) fatal("d86f_load(): Track 1: Error seeking to the beginning of the file\n"); - if (fread(&(dev->side_flags[1]), 1, 2, dev->f) != 2) + if (fread(&(dev->side_flags[1]), 1, 2, dev->fp) != 2) fatal("d86f_load(): Track 1: Error reading side flags\n"); if (dev->disk_flags & 0x80) { - if (fread(&(dev->extra_bit_cells[1]), 1, 4, dev->f) != 4) + if (fread(&(dev->extra_bit_cells[1]), 1, 4, dev->fp) != 4) fatal("d86f_load(): Track 4: Error reading the amount of extra bit cells\n"); if ((dev->disk_flags & 0x1060) != 0x1000) { if (dev->extra_bit_cells[1] < -32768) @@ -3708,8 +3769,8 @@ d86f_load(int drive, char *fn) } } else { switch ((dev->disk_flags >> 1) >> 3) { - case 0: default: + case 0: dev->side_flags[1] = 0x0a; break; @@ -3726,10 +3787,10 @@ d86f_load(int drive, char *fn) dev->extra_bit_cells[1] = 0; } - fseek(dev->f, 0, SEEK_END); - dev->file_size = ftell(dev->f); + fseek(dev->fp, 0, SEEK_END); + dev->file_size = ftell(dev->fp); - fseek(dev->f, 0, SEEK_SET); + fseek(dev->fp, 0, SEEK_SET); d86f_register_86f(drive); @@ -3750,11 +3811,9 @@ d86f_load(int drive, char *fn) void d86f_init(void) { - int i; - setup_crc(0x1021); - for (i = 0; i < FDD_NUM; i++) + for (uint8_t i = 0; i < FDD_NUM; i++) d86f[i] = NULL; } @@ -3767,8 +3826,6 @@ d86f_set_fdc(void *fdc) void d86f_close(int drive) { - int i, j; - char temp_file_name[2048]; d86f_t *dev = d86f[drive]; @@ -3779,15 +3836,15 @@ d86f_close(int drive) memcpy(temp_file_name, drive ? nvr_path("TEMP$$$1.$$$") : nvr_path("TEMP$$$0.$$$"), 26); if (d86f_has_surface_desc(drive)) { - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { if (dev->track_surface_data[i]) { free(dev->track_surface_data[i]); dev->track_surface_data[i] = NULL; } } - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { + for (uint8_t i = 0; i < 2; i++) { + for (uint8_t j = 0; j < 2; j++) { if (dev->thin_track_surface_data[i][j]) { free(dev->thin_track_surface_data[i][j]); dev->thin_track_surface_data[i][j] = NULL; @@ -3796,9 +3853,9 @@ d86f_close(int drive) } } - if (dev->f) { - fclose(dev->f); - dev->f = NULL; + if (dev->fp) { + fclose(dev->fp); + dev->fp = NULL; } #ifdef D86F_COMPRESS if (dev->is_compressed) @@ -3828,23 +3885,21 @@ d86f_setup(int drive) void d86f_destroy(int drive) { - int i, j; - d86f_t *dev = d86f[drive]; if (dev == NULL) return; if (d86f_has_surface_desc(drive)) { - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { if (dev->track_surface_data[i]) { free(dev->track_surface_data[i]); dev->track_surface_data[i] = NULL; } } - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { + for (uint8_t i = 0; i < 2; i++) { + for (uint8_t j = 0; j < 2; j++) { if (dev->thin_track_surface_data[i][j]) { free(dev->thin_track_surface_data[i][j]); dev->thin_track_surface_data[i][j] = NULL; diff --git a/src/floppy/fdd_common.c b/src/floppy/fdd_common.c index 9c1f98c39..d0659d990 100644 --- a/src/floppy/fdd_common.c +++ b/src/floppy/fdd_common.c @@ -359,7 +359,7 @@ fdd_get_gap3_size(int rate, int size, int sector) uint8_t fdd_sector_size_code(int size) { - int ret = 2; + uint8_t ret = 2; switch (size) { case 128: @@ -398,7 +398,7 @@ fdd_sector_size_code(int size) break; } - return (ret); + return ret; } int @@ -410,15 +410,13 @@ fdd_sector_code_size(uint8_t code) int fdd_bps_valid(uint16_t bps) { - int i; - - for (i = 0; i <= 8; i++) { + for (uint8_t i = 0; i <= 8; i++) { if (bps == (128 << i)) { return 1; } } - return (0); + return 0; } int @@ -435,5 +433,5 @@ fdd_interleave(int sector, int skew, int spt) adjusted_r += (adjust + add); } - return (adjusted_r); + return adjusted_r; } diff --git a/src/floppy/fdd_fdi.c b/src/floppy/fdd_fdi.c index 64279c173..f14bf2cd4 100644 --- a/src/floppy/fdd_fdi.c +++ b/src/floppy/fdd_fdi.c @@ -36,8 +36,8 @@ #include <86box/fdc.h> #include -typedef struct { - FILE *f; +typedef struct fdi_t { + FILE *fp; FDI *h; int lasttrack; @@ -104,7 +104,7 @@ disk_flags(int drive) */ temp_disk_flags |= 0x800; - return (temp_disk_flags); + return temp_disk_flags; } static uint16_t @@ -143,43 +143,43 @@ side_flags(int drive) */ temp_side_flags |= 0x08; - return (temp_side_flags); + return temp_side_flags; } static int fdi_density(void) { if (!fdc_is_mfm(fdi_fdc)) - return (0); + return 0; switch (fdc_get_bit_rate(fdi_fdc)) { case 0: - return (2); + return 2; case 1: - return (1); + return 1; case 2: - return (1); + return 1; case 3: case 5: - return (3); + return 3; default: break; } - return (1); + return 1; } static int32_t extra_bit_cells(int drive, int side) { - fdi_t *dev = fdi[drive]; - int density = 0; - int raw_size = 0; - int is_300_rpm = 0; + const fdi_t *dev = fdi[drive]; + int density = 0; + int raw_size = 0; + int is_300_rpm = 0; density = fdi_density(); @@ -207,14 +207,15 @@ extra_bit_cells(int drive, int side) raw_size = is_300_rpm ? 100000 : 83333; } - return ((dev->tracklen[side][density] - raw_size)); + return (dev->tracklen[side][density] - raw_size); } static void read_revolution(int drive) { fdi_t *dev = fdi[drive]; - int c, den, side; + int c; + int den; int track = dev->track; if (track > dev->lasttrack) { @@ -227,7 +228,7 @@ read_revolution(int drive) } for (den = 0; den < 4; den++) { - for (side = 0; side < dev->sides; side++) { + for (int side = 0; side < dev->sides; side++) { c = fdi2raw_loadtrack(dev->h, (uint16_t *) dev->track_data[side][den], (uint16_t *) dev->track_timing[side][den], @@ -248,8 +249,8 @@ read_revolution(int drive) static uint32_t index_hole_pos(int drive, int side) { - fdi_t *dev = fdi[drive]; - int density; + const fdi_t *dev = fdi[drive]; + int density; density = fdi_density(); @@ -259,8 +260,8 @@ index_hole_pos(int drive, int side) static uint32_t get_raw_size(int drive, int side) { - fdi_t *dev = fdi[drive]; - int density; + const fdi_t *dev = fdi[drive]; + int density; density = fdi_density(); @@ -290,7 +291,7 @@ fdi_seek(int drive, int track) d86f_set_cur_track(drive, track); - if (dev->f == NULL) + if (dev->fp == NULL) return; if (track < 0) @@ -326,16 +327,16 @@ fdi_load(int drive, char *fn) d86f_unregister(drive); - dev->f = plat_fopen(fn, "rb"); - if (fread(header, 1, 25, dev->f) != 25) + dev->fp = plat_fopen(fn, "rb"); + if (fread(header, 1, 25, dev->fp) != 25) fatal("fdi_load(): Error reading header\n"); - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("fdi_load(): Error seeking to the beginning of the file\n"); header[25] = 0; if (strcmp(header, "Formatted Disk Image file") != 0) { /* This is a Japanese FDI file. */ fdi_log("fdi_load(): Japanese FDI file detected, redirecting to IMG loader\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); img_load(drive, fn); return; @@ -344,7 +345,7 @@ fdi_load(int drive, char *fn) /* Set up the drive unit. */ fdi[drive] = dev; - dev->h = fdi2raw_header(dev->f); + dev->h = fdi2raw_header(dev->fp); dev->lasttrack = fdi2raw_get_last_track(dev->h); dev->sides = fdi2raw_get_last_head(dev->h) + 1; @@ -385,8 +386,8 @@ fdi_close(int drive) if (dev->h) fdi2raw_header_free(dev->h); - if (dev->f) - fclose(dev->f); + if (dev->fp) + fclose(dev->fp); /* Release the memory. */ free(dev); diff --git a/src/floppy/fdd_imd.c b/src/floppy/fdd_imd.c index 830a96b0e..a5cd8f056 100644 --- a/src/floppy/fdd_imd.c +++ b/src/floppy/fdd_imd.c @@ -31,7 +31,7 @@ #include <86box/fdd_imd.h> #include <86box/fdc.h> -typedef struct { +typedef struct imd_track_t { uint8_t is_present; uint32_t file_offs; uint8_t params[5]; @@ -47,11 +47,12 @@ typedef struct { uint8_t max_sector_size; } imd_track_t; -typedef struct { - FILE *f; +typedef struct imd_t { + FILE *fp; char *buffer; uint32_t start_offs; - int track_count, sides; + int track_count; + int sides; int track; uint16_t disk_flags; int track_width; @@ -129,35 +130,39 @@ get_raw_tsize(int side_flags, int slower_rpm) break; } - return (size); + return size; } static int track_is_xdf(int drive, int side, int track) { - imd_t *dev = imd[drive]; - int i, effective_sectors, xdf_sectors; - int high_sectors, low_sectors; - int max_high_id, expected_high_count, expected_low_count; - uint8_t *r_map; - uint8_t *n_map; + imd_t *dev = imd[drive]; + int effective_sectors; + int xdf_sectors; + int high_sectors; + int low_sectors; + int max_high_id; + int expected_high_count; + int expected_low_count; + const uint8_t *r_map; + const uint8_t *n_map; effective_sectors = xdf_sectors = high_sectors = low_sectors = 0; - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) dev->xdf_ordered_pos[i][side] = 0; if (dev->tracks[track][side].params[2] & 0xC0) - return (0); + return 0; if ((dev->tracks[track][side].params[3] != 16) && (dev->tracks[track][side].params[3] != 19)) - return (0); + return 0; r_map = (uint8_t *) (dev->buffer + dev->tracks[track][side].r_map_offs); if (!track) { if (dev->tracks[track][side].params[4] != 2) - return (0); + return 0; if (!side) { max_high_id = (dev->tracks[track][side].params[3] == 19) ? 0x8B : 0x88; @@ -169,7 +174,7 @@ track_is_xdf(int drive, int side, int track) expected_low_count = 0; } - for (i = 0; i < dev->tracks[track][side].params[3]; i++) { + for (uint8_t i = 0; i < dev->tracks[track][side].params[3]; i++) { if ((r_map[i] >= 0x81) && (r_map[i] <= max_high_id)) { high_sectors++; dev->xdf_ordered_pos[(int) r_map[i]][side] = i; @@ -183,14 +188,14 @@ track_is_xdf(int drive, int side, int track) return ((dev->tracks[track][side].params[3] == 19) ? 2 : 1); } } - return (0); + return 0; } else { if (dev->tracks[track][side].params[4] != 0xFF) - return (0); + return 0; n_map = (uint8_t *) (dev->buffer + dev->tracks[track][side].n_map_offs); - for (i = 0; i < dev->tracks[track][side].params[3]; i++) { + for (uint8_t i = 0; i < dev->tracks[track][side].params[3]; i++) { effective_sectors++; if (!(r_map[i]) && !(n_map[i])) effective_sectors--; @@ -203,31 +208,29 @@ track_is_xdf(int drive, int side, int track) if ((effective_sectors == 3) && (xdf_sectors == 3)) { dev->current_side_flags[side] = 0x28; - return (1); /* 5.25" 2HD XDF */ + return 1; /* 5.25" 2HD XDF */ } if ((effective_sectors == 4) && (xdf_sectors == 4)) { dev->current_side_flags[side] = 0x08; - return (2); /* 3.5" 2HD XDF */ + return 2; /* 3.5" 2HD XDF */ } - return (0); + return 0; } - - return (0); } static int track_is_interleave(int drive, int side, int track) { - imd_t *dev = imd[drive]; - int i, effective_sectors; - char *r_map; - int track_spt; + imd_t *dev = imd[drive]; + int effective_sectors; + const char *r_map; + int track_spt; effective_sectors = 0; - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) dev->interleave_ordered_pos[i][side] = 0; track_spt = dev->tracks[track][side].params[3]; @@ -235,15 +238,15 @@ track_is_interleave(int drive, int side, int track) r_map = dev->buffer + dev->tracks[track][side].r_map_offs; if (dev->tracks[track][side].params[2] & 0xC0) - return (0); + return 0; if (track_spt != 21) - return (0); + return 0; if (dev->tracks[track][side].params[4] != 2) - return (0); + return 0; - for (i = 0; i < track_spt; i++) { + for (int i = 0; i < track_spt; i++) { if ((r_map[i] >= 1) && (r_map[i] <= track_spt)) { effective_sectors++; dev->interleave_ordered_pos[(int) r_map[i]][side] = i; @@ -251,17 +254,17 @@ track_is_interleave(int drive, int side, int track) } if (effective_sectors == track_spt) - return (1); + return 1; - return (0); + return 0; } static void sector_to_buffer(int drive, int track, int side, uint8_t *buffer, int sector, int len) { - imd_t *dev = imd[drive]; - int type = dev->buffer[dev->tracks[track][side].sector_data_offs[sector]]; - uint8_t fill_char; + const imd_t *dev = imd[drive]; + int type = dev->buffer[dev->tracks[track][side].sector_data_offs[sector]]; + uint8_t fill_char; if (type == 0) memset(buffer, 0x00, len); @@ -278,32 +281,35 @@ sector_to_buffer(int drive, int track, int side, uint8_t *buffer, int sector, in static void imd_seek(int drive, int track) { - uint32_t track_buf_pos[2] = { 0, 0 }; - uint8_t id[4] = { 0, 0, 0, 0 }; - uint8_t type; - imd_t *dev = imd[drive]; - int sector, current_pos; - int side, c = 0, h, n; - int ssize = 512; - int track_rate = 0; - int track_gap2 = 22; - int track_gap3 = 12; - int xdf_type = 0; - int interleave_type = 0; - int is_trackx = 0; - int xdf_spt = 0; - int xdf_sector = 0; - int ordered_pos = 0; - int real_sector = 0; - int actual_sector = 0; - char *c_map = NULL; - char *h_map = NULL; - char *r_map; - char *n_map = NULL; - uint8_t *data; - int flags = 0x00; + uint32_t track_buf_pos[2] = { 0, 0 }; + uint8_t id[4] = { 0, 0, 0, 0 }; + uint8_t type; + imd_t *dev = imd[drive]; + int sector; + int current_pos; + int c = 0; + int h; + int n; + int ssize = 512; + int track_rate = 0; + int track_gap2 = 22; + int track_gap3 = 12; + int xdf_type = 0; + int interleave_type = 0; + int is_trackx = 0; + int xdf_spt = 0; + int xdf_sector = 0; + int ordered_pos = 0; + int real_sector = 0; + int actual_sector = 0; + const char *c_map = NULL; + const char *h_map = NULL; + const char *r_map; + const char *n_map = NULL; + uint8_t *data; + int flags = 0x00; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (!dev->track_width && fdd_doublestep_40(drive)) @@ -329,7 +335,7 @@ imd_seek(int drive, int track) if (track > dev->track_count) return; - for (side = 0; side < dev->sides; side++) { + for (int side = 0; side < dev->sides; side++) { if (!dev->tracks[track][side].is_present) continue; @@ -445,7 +451,7 @@ imd_seek(int drive, int track) static uint16_t disk_flags(int drive) { - imd_t *dev = imd[drive]; + const imd_t *dev = imd[drive]; return (dev->disk_flags); } @@ -453,27 +459,32 @@ disk_flags(int drive) static uint16_t side_flags(int drive) { - imd_t *dev = imd[drive]; - int side = 0; - uint16_t sflags = 0; + const imd_t *dev = imd[drive]; + int side = 0; + uint16_t sflags = 0; side = fdd_get_head(drive); sflags = dev->current_side_flags[side]; - return (sflags); + return sflags; } static void set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { - imd_t *dev = imd[drive]; - int track = dev->track; - int i, sc, sh, sn; - char *c_map = NULL, *h_map = NULL, *r_map = NULL, *n_map = NULL; - uint8_t id[4] = { 0, 0, 0, 0 }; - sc = dev->tracks[track][side].params[1]; - sh = dev->tracks[track][side].params[2]; - sn = dev->tracks[track][side].params[4]; + imd_t *dev = imd[drive]; + int track = dev->track; + int sc; + int sh; + int sn; + const char *c_map = NULL; + const char *h_map = NULL; + const char *r_map = NULL; + const char *n_map = NULL; + uint8_t id[4] = { 0, 0, 0, 0 }; + sc = dev->tracks[track][side].params[1]; + sh = dev->tracks[track][side].params[2]; + sn = dev->tracks[track][side].params[4]; if (sh & 0x80) c_map = dev->buffer + dev->tracks[track][side].c_map_offs; @@ -487,7 +498,7 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) if (c != dev->track) return; - for (i = 0; i < dev->tracks[track][side].params[3]; i++) { + for (uint8_t i = 0; i < dev->tracks[track][side].params[3]; i++) { id[0] = (sh & 0x80) ? c_map[i] : sc; id[1] = (sh & 0x40) ? h_map[i] : (sh & 1); id[2] = r_map[i]; @@ -501,39 +512,39 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) static void imd_writeback(int drive) { - imd_t *dev = imd[drive]; - int side; - int track = dev->track; - int i = 0; - char *n_map = 0; - uint8_t h, n, spt; - uint32_t ssize; + imd_t *dev = imd[drive]; + int track = dev->track; + const char *n_map = 0; + uint8_t h; + uint8_t n; + uint8_t spt; + uint32_t ssize; if (writeprot[drive]) return; - for (side = 0; side < dev->sides; side++) { + for (int side = 0; side < dev->sides; side++) { if (dev->tracks[track][side].is_present) { - fseek(dev->f, dev->tracks[track][side].file_offs, SEEK_SET); + fseek(dev->fp, dev->tracks[track][side].file_offs, SEEK_SET); h = dev->tracks[track][side].params[2]; spt = dev->tracks[track][side].params[3]; n = dev->tracks[track][side].params[4]; - fwrite(dev->tracks[track][side].params, 1, 5, dev->f); + fwrite(dev->tracks[track][side].params, 1, 5, dev->fp); if (h & 0x80) - fwrite(dev->buffer + dev->tracks[track][side].c_map_offs, 1, spt, dev->f); + fwrite(dev->buffer + dev->tracks[track][side].c_map_offs, 1, spt, dev->fp); if (h & 0x40) - fwrite(dev->buffer + dev->tracks[track][side].h_map_offs, 1, spt, dev->f); + fwrite(dev->buffer + dev->tracks[track][side].h_map_offs, 1, spt, dev->fp); if (n == 0xFF) { n_map = dev->buffer + dev->tracks[track][side].n_map_offs; - fwrite(n_map, 1, spt, dev->f); + fwrite(n_map, 1, spt, dev->fp); } - for (i = 0; i < spt; i++) { + for (uint8_t i = 0; i < spt; i++) { ssize = (n == 0xFF) ? n_map[i] : n; ssize = 128 << ssize; - fwrite(dev->buffer + dev->tracks[track][side].sector_data_offs[i], 1, ssize, dev->f); + fwrite(dev->buffer + dev->tracks[track][side].sector_data_offs[i], 1, ssize, dev->fp); } } } @@ -542,11 +553,11 @@ imd_writeback(int drive) static uint8_t poll_read_data(int drive, int side, uint16_t pos) { - imd_t *dev = imd[drive]; - int type = dev->current_data[side][0]; + const imd_t *dev = imd[drive]; + int type = dev->current_data[side][0]; if ((type == 0) || (type > 8)) - return (0xf6); /* Should never happen. */ + return 0xf6; /* Should never happen. */ if (type & 1) return (dev->current_data[side][pos + 1]); @@ -557,8 +568,8 @@ poll_read_data(int drive, int side, uint16_t pos) static void poll_write_data(int drive, int side, uint16_t pos, uint8_t data) { - imd_t *dev = imd[drive]; - int type = dev->current_data[side][0]; + const imd_t *dev = imd[drive]; + int type = dev->current_data[side][0]; if (writeprot[drive]) return; @@ -572,15 +583,16 @@ poll_write_data(int drive, int side, uint16_t pos, uint8_t data) static int format_conditions(int drive) { - imd_t *dev = imd[drive]; - int track = dev->track; - int side, temp; + const imd_t *dev = imd[drive]; + int track = dev->track; + int side; + int temp; side = fdd_get_head(drive); temp = (fdc_get_format_sectors(imd_fdc) == dev->tracks[track][side].params[3]); temp = temp && (fdc_get_format_n(imd_fdc) == dev->tracks[track][side].params[4]); - return (temp); + return temp; } void @@ -592,28 +604,28 @@ imd_init(void) void imd_load(int drive, char *fn) { - uint32_t magic = 0; - uint32_t fsize = 0; - char *buffer; - char *buffer2; - imd_t *dev; - int i = 0; - int track_spt = 0; - int sector_size = 0; - int track = 0; - int side = 0; - int extra = 0; - uint32_t last_offset = 0; - uint32_t data_size = 512; - uint32_t mfm = 0; - uint32_t pre_sector = 0; - uint32_t track_total = 0; - uint32_t raw_tsize = 0; - uint32_t minimum_gap3 = 0; - uint32_t minimum_gap4 = 0; - uint8_t converted_rate; - uint8_t type; - int size_diff, gap_sum; + uint32_t magic = 0; + uint32_t fsize = 0; + const char *buffer; + const char *buffer2; + imd_t *dev; + int track_spt = 0; + int sector_size = 0; + int track = 0; + int side = 0; + int extra = 0; + uint32_t last_offset = 0; + uint32_t data_size = 512; + uint32_t mfm = 0; + uint32_t pre_sector = 0; + uint32_t track_total = 0; + uint32_t raw_tsize = 0; + uint32_t minimum_gap3 = 0; + uint32_t minimum_gap4 = 0; + uint8_t converted_rate; + uint8_t type; + int size_diff; + int gap_sum; d86f_unregister(drive); @@ -623,10 +635,10 @@ imd_load(int drive, char *fn) dev = (imd_t *) malloc(sizeof(imd_t)); memset(dev, 0x00, sizeof(imd_t)); - dev->f = plat_fopen(fn, "rb+"); - if (dev->f == NULL) { - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb+"); + if (dev->fp == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -638,40 +650,40 @@ imd_load(int drive, char *fn) writeprot[drive] = 1; fwriteprot[drive] = writeprot[drive]; - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("imd_load(): Error seeking to the beginning of the file\n"); - if (fread(&magic, 1, 4, dev->f) != 4) + if (fread(&magic, 1, 4, dev->fp) != 4) fatal("imd_load(): Error reading the magic number\n"); if (magic != 0x20444D49) { imd_log("IMD: Not a valid ImageDisk image\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } else imd_log("IMD: Valid ImageDisk image\n"); - if (fseek(dev->f, 0, SEEK_END) == -1) + if (fseek(dev->fp, 0, SEEK_END) == -1) fatal("imd_load(): Error seeking to the end of the file\n"); - fsize = ftell(dev->f); + fsize = ftell(dev->fp); if (fsize <= 0) { imd_log("IMD: Too small ImageDisk image\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("imd_load(): Error seeking to the beginning of the file again\n"); dev->buffer = malloc(fsize); - if (fread(dev->buffer, 1, fsize, dev->f) != fsize) + if (fread(dev->buffer, 1, fsize, dev->fp) != fsize) fatal("imd_load(): Error reading data\n"); buffer = dev->buffer; buffer2 = memchr(buffer, 0x1A, fsize); if (buffer2 == NULL) { imd_log("IMD: No ASCII EOF character\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -682,7 +694,7 @@ imd_load(int drive, char *fn) buffer2++; if ((buffer2 - buffer) == fsize) { imd_log("IMD: File ends after ASCII EOF character\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -708,7 +720,7 @@ imd_load(int drive, char *fn) dev->tracks[track][side].side_flags = (buffer2[0] % 3); if (!dev->tracks[track][side].side_flags) - dev->disk_flags |= (0x02); + dev->disk_flags |= 0x02; dev->tracks[track][side].side_flags |= (!(buffer2[0] - dev->tracks[track][side].side_flags) ? 0 : 8); mfm = dev->tracks[track][side].side_flags & 8; track_total = mfm ? 146 : 73; @@ -761,7 +773,7 @@ imd_load(int drive, char *fn) dev->tracks[track][side].data_offs = last_offset; - for (i = 0; i < track_spt; i++) { + for (int i = 0; i < track_spt; i++) { data_size = buffer2[i]; data_size = 128 << data_size; dev->tracks[track][side].sector_data_offs[i] = last_offset; @@ -770,7 +782,7 @@ imd_load(int drive, char *fn) /* Invalid sector data type, possibly a malformed HxC IMG image (it outputs data errored sectors with a variable amount of bytes, against the specification). */ imd_log("IMD: Invalid sector data type %02X\n", dev->buffer[dev->tracks[track][side].sector_data_offs[i]]); - fclose(dev->f); + fclose(dev->fp); free(dev); imd[drive] = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); @@ -793,7 +805,7 @@ imd_load(int drive, char *fn) } else { dev->tracks[track][side].data_offs = last_offset; - for (i = 0; i < track_spt; i++) { + for (int i = 0; i < track_spt; i++) { data_size = sector_size; data_size = 128 << data_size; dev->tracks[track][side].sector_data_offs[i] = last_offset; @@ -802,7 +814,7 @@ imd_load(int drive, char *fn) /* Invalid sector data type, possibly a malformed HxC IMG image (it outputs data errored sectors with a variable amount of bytes, against the specification). */ imd_log("IMD: Invalid sector data type %02X\n", dev->buffer[dev->tracks[track][side].sector_data_offs[i]]); - fclose(dev->f); + fclose(dev->fp); free(dev); imd[drive] = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); @@ -851,7 +863,7 @@ imd_load(int drive, char *fn) if (size_diff < gap_sum) { /* If we can't fit the sectors with a reasonable minimum gap even at 2% slower RPM, abort. */ imd_log("IMD: Unable to fit the %i sectors in a track\n", track_spt); - fclose(dev->f); + fclose(dev->fp); free(dev); imd[drive] = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); @@ -882,7 +894,9 @@ imd_load(int drive, char *fn) if (dev->sides == 2) dev->disk_flags |= 8; - /* imd_log("%i tracks, %i sides\n", dev->track_count, dev->sides); */ +#if 0 + imd_log("%i tracks, %i sides\n", dev->track_count, dev->sides); +#endif /* Attach this format to the D86F engine. */ d86f_handler[drive].disk_flags = disk_flags; @@ -915,10 +929,10 @@ imd_close(int drive) d86f_unregister(drive); - if (dev->f != NULL) { + if (dev->fp != NULL) { free(dev->buffer); - fclose(dev->f); + fclose(dev->fp); } /* Release the memory. */ diff --git a/src/floppy/fdd_img.c b/src/floppy/fdd_img.c index a9fc73a24..404cbf9fa 100644 --- a/src/floppy/fdd_img.c +++ b/src/floppy/fdd_img.c @@ -40,9 +40,9 @@ #include <86box/fdd_img.h> #include <86box/fdc.h> -typedef struct { - FILE *f; - uint8_t track_data[2][50000]; +typedef struct img_t { + FILE *fp; + uint8_t track_data[2][688128]; int sectors, tracks, sides; uint8_t sector_size; int xdf_type; /* 0 = not XDF, 1-5 = one of the five XDF types */ @@ -71,10 +71,10 @@ static fdc_t *img_fdc; static double bit_rate_300; static char *ext; -static uint8_t first_byte, - second_byte, - third_byte, - fourth_byte; +static uint8_t first_byte; +static uint8_t second_byte; +static uint8_t third_byte; +static uint8_t fourth_byte; static uint8_t fdf_suppress_final_byte = 0; /* This is hard-coded to 0 - * if you really need to read * those NT 3.1 Beta floppy @@ -339,43 +339,41 @@ sector_size_code(int sector_size) { switch (sector_size) { case 128: - return (0); + return 0; case 256: - return (1); + return 1; default: case 512: - return (2); + return 2; case 1024: - return (3); + return 3; case 2048: - return (4); + return 4; case 4096: - return (5); + return 5; case 8192: - return (6); + return 6; case 16384: - return (7); + return 7; } } static int bps_is_valid(uint16_t bps) { - int i; - - for (i = 0; i <= 8; i++) { + for (uint8_t i = 0; i <= 8; i++) { if (bps == (128 << i)) - return (1); + return 1; } - return (0); + return 0; } static int @@ -385,13 +383,13 @@ first_byte_is_valid(uint8_t first_byte) case 0x60: case 0xE9: case 0xEB: - return (1); + return 1; default: break; } - return (0); + return 0; } #define xdf_img_sector xdf_img_layout[current_xdft][!is_t0][sector] @@ -410,7 +408,7 @@ interleave(int sector, int skew, int track_spt) if (skewed_i & 1) adjusted_r += (adjust + add); - return (adjusted_r); + return adjusted_r; } static void @@ -418,19 +416,19 @@ write_back(int drive) { img_t *dev = img[drive]; int ssize = 128 << ((int) dev->sector_size); - int side, size; + int size; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (dev->disk_at_once) return; - if (fseek(dev->f, dev->base + (dev->track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) + if (fseek(dev->fp, dev->base + (dev->track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) pclog("IMG write_back(): Error seeking to the beginning of the file\n"); - for (side = 0; side < dev->sides; side++) { + for (int side = 0; side < dev->sides; side++) { size = dev->sectors * ssize; - if (fwrite(dev->track_data[side], 1, size, dev->f) != size) + if (fwrite(dev->track_data[side], 1, size, dev->fp) != size) fatal("IMG write_back(): Error writing data\n"); } } @@ -438,7 +436,7 @@ write_back(int drive) static uint16_t disk_flags(int drive) { - img_t *dev = img[drive]; + const img_t *dev = img[drive]; return (dev->disk_flags); } @@ -446,13 +444,13 @@ disk_flags(int drive) static uint16_t side_flags(int drive) { - img_t *dev = img[drive]; + const img_t *dev = img[drive]; return (dev->track_flags); } static void -set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) +set_sector(int drive, UNUSED(int side), UNUSED(uint8_t c), uint8_t h, uint8_t r, UNUSED(uint8_t n)) { img_t *dev = img[drive]; @@ -461,15 +459,15 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) } static uint8_t -poll_read_data(int drive, int side, uint16_t pos) +poll_read_data(int drive, UNUSED(int side), uint16_t pos) { - img_t *dev = img[drive]; + const img_t *dev = img[drive]; return (dev->track_data[dev->current_sector_pos_side][dev->current_sector_pos + pos]); } static void -poll_write_data(int drive, int side, uint16_t pos, uint8_t data) +poll_write_data(int drive, UNUSED(int side), uint16_t pos, uint8_t data) { img_t *dev = img[drive]; @@ -479,13 +477,13 @@ poll_write_data(int drive, int side, uint16_t pos, uint8_t data) static int format_conditions(int drive) { - img_t *dev = img[drive]; - int temp = (fdc_get_format_sectors(img_fdc) == dev->sectors); + const img_t *dev = img[drive]; + int temp = (fdc_get_format_sectors(img_fdc) == dev->sectors); temp = temp && (fdc_get_format_n(img_fdc) == dev->sector_size); temp = temp && (dev->xdf_type == 0); - return (temp); + return temp; } static void @@ -496,11 +494,20 @@ img_seek(int drive, int track) int current_xdft = dev->xdf_type - 1; int read_bytes = 0; uint8_t id[4] = { 0, 0, 0, 0 }; - int is_t0, sector, current_pos, img_pos, sr, sside, total, array_sector, buf_side, buf_pos; + int is_t0; + int sector; + int current_pos; + int img_pos; + int sr; + int sside; + int total; + int array_sector; + int buf_side; + int buf_pos; int ssize = 128 << ((int) dev->sector_size); uint32_t cur_pos = 0; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (!dev->track_width && fdd_doublestep_40(drive)) @@ -512,7 +519,7 @@ img_seek(int drive, int track) is_t0 = (track == 0) ? 1 : 0; if (!dev->disk_at_once) { - if (fseek(dev->f, dev->base + (track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) + if (fseek(dev->fp, dev->base + (track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) fatal("img_seek(): Error seeking\n"); } @@ -521,7 +528,7 @@ img_seek(int drive, int track) cur_pos = (track * dev->sectors * ssize * dev->sides) + (side * dev->sectors * ssize); memcpy(dev->track_data[side], dev->disk_data + cur_pos, (size_t) dev->sectors * ssize); } else { - read_bytes = fread(dev->track_data[side], 1, (size_t) dev->sectors * ssize, dev->f); + read_bytes = fread(dev->track_data[side], 1, (size_t) dev->sectors * ssize, dev->fp); if (read_bytes < (dev->sectors * ssize)) memset(dev->track_data[side] + read_bytes, 0xf6, (dev->sectors * ssize) - read_bytes); } @@ -647,7 +654,10 @@ img_load(int drive, char *fn) uint8_t bpb_mid; /* Media type ID. */ uint8_t bpb_sectors; uint8_t bpb_sides; - uint8_t cqm, ddi, fdf, fdi; + uint8_t cqm; + uint8_t ddi; + uint8_t fdf; + uint8_t fdi; uint16_t comment_len = 0; int16_t block_len = 0; uint32_t cur_pos = 0; @@ -658,10 +668,9 @@ img_load(int drive, char *fn) uint16_t track_bytes = 0; uint8_t *literal; img_t *dev; - int temp_rate; - int guess = 0; + int temp_rate = 0; + int guess = 0; int size; - int i; ext = path_get_extension(fn); @@ -673,10 +682,10 @@ img_load(int drive, char *fn) dev = (img_t *) malloc(sizeof(img_t)); memset(dev, 0x00, sizeof(img_t)); - dev->f = plat_fopen(fn, "rb+"); - if (dev->f == NULL) { - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb+"); + if (dev->fp == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -701,23 +710,23 @@ img_load(int drive, char *fn) if (!strcasecmp(ext, "FDI")) { /* This is a Japanese FDI image, so let's read the header */ img_log("img_load(): File is a Japanese FDI image...\n"); - fseek(dev->f, 0x10, SEEK_SET); - (void) !fread(&bpb_bps, 1, 2, dev->f); - fseek(dev->f, 0x0C, SEEK_SET); - (void) !fread(&size, 1, 4, dev->f); + fseek(dev->fp, 0x10, SEEK_SET); + (void) !fread(&bpb_bps, 1, 2, dev->fp); + fseek(dev->fp, 0x0C, SEEK_SET); + (void) !fread(&size, 1, 4, dev->fp); bpb_total = size / bpb_bps; - fseek(dev->f, 0x08, SEEK_SET); - (void) !fread(&(dev->base), 1, 4, dev->f); - fseek(dev->f, dev->base + 0x15, SEEK_SET); - bpb_mid = fgetc(dev->f); + fseek(dev->fp, 0x08, SEEK_SET); + (void) !fread(&(dev->base), 1, 4, dev->fp); + fseek(dev->fp, dev->base + 0x15, SEEK_SET); + bpb_mid = fgetc(dev->fp); if (bpb_mid < 0xF0) bpb_mid = 0xF0; - fseek(dev->f, 0x14, SEEK_SET); - bpb_sectors = fgetc(dev->f); - fseek(dev->f, 0x18, SEEK_SET); - bpb_sides = fgetc(dev->f); - fseek(dev->f, dev->base, SEEK_SET); - first_byte = fgetc(dev->f); + fseek(dev->fp, 0x14, SEEK_SET); + bpb_sectors = fgetc(dev->fp); + fseek(dev->fp, 0x18, SEEK_SET); + bpb_sides = fgetc(dev->fp); + fseek(dev->fp, dev->base, SEEK_SET); + first_byte = fgetc(dev->fp); fdi = 1; cqm = 0; @@ -725,53 +734,53 @@ img_load(int drive, char *fn) fdf = 0; } else { /* Read the first four bytes. */ - fseek(dev->f, 0x00, SEEK_SET); - first_byte = fgetc(dev->f); - fseek(dev->f, 0x01, SEEK_SET); - second_byte = fgetc(dev->f); - fseek(dev->f, 0x02, SEEK_SET); - third_byte = fgetc(dev->f); - fseek(dev->f, 0x03, SEEK_SET); - fourth_byte = fgetc(dev->f); + fseek(dev->fp, 0x00, SEEK_SET); + first_byte = fgetc(dev->fp); + fseek(dev->fp, 0x01, SEEK_SET); + second_byte = fgetc(dev->fp); + fseek(dev->fp, 0x02, SEEK_SET); + third_byte = fgetc(dev->fp); + fseek(dev->fp, 0x03, SEEK_SET); + fourth_byte = fgetc(dev->fp); if ((first_byte == 0x1A) && (second_byte == 'F') && (third_byte == 'D') && (fourth_byte == 'F')) { /* This is a FDF image. */ img_log("img_load(): File is a FDF image...\n"); fwriteprot[drive] = writeprot[drive] = 1; - fclose(dev->f); - dev->f = plat_fopen(fn, "rb"); + fclose(dev->fp); + dev->fp = plat_fopen(fn, "rb"); fdf = 1; cqm = 0; dev->disk_at_once = 1; - fseek(dev->f, 0x50, SEEK_SET); - (void) !fread(&dev->tracks, 1, 4, dev->f); + fseek(dev->fp, 0x50, SEEK_SET); + (void) !fread(&dev->tracks, 1, 4, dev->fp); /* Decode the entire file - pass 1, no write to buffer, determine length. */ - fseek(dev->f, 0x80, SEEK_SET); + fseek(dev->fp, 0x80, SEEK_SET); size = 0; track_bytes = 0; bpos = dev->disk_data; - while (!feof(dev->f)) { + while (!feof(dev->fp)) { if (!track_bytes) { /* Skip first 3 bytes - their meaning is unknown to us but could be a checksum. */ - first_byte = fgetc(dev->f); - (void) !fread(&track_bytes, 1, 2, dev->f); + first_byte = fgetc(dev->fp); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("Block header: %02X %04X ", first_byte, track_bytes); /* Read the length of encoded data block. */ - (void) !fread(&track_bytes, 1, 2, dev->f); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("%04X\n", track_bytes); } - if (feof(dev->f)) + if (feof(dev->fp)) break; if (first_byte == 0xFF) break; if (first_byte) { - run = fgetc(dev->f); + run = fgetc(dev->fp); /* I *HAVE* to read something because fseek tries to be smart and never hits EOF, causing an infinite loop. */ track_bytes--; @@ -779,12 +788,12 @@ img_load(int drive, char *fn) if (run & 0x80) { /* Repeat. */ track_bytes--; - rep_byte = fgetc(dev->f); + rep_byte = fgetc(dev->fp); } else { /* Literal. */ track_bytes -= (run & 0x7f); literal = (uint8_t *) malloc(run & 0x7f); - (void) !fread(literal, 1, (run & 0x7f), dev->f); + (void) !fread(literal, 1, (run & 0x7f), dev->fp); free(literal); } size += (run & 0x7f); @@ -794,12 +803,12 @@ img_load(int drive, char *fn) /* Literal block. */ size += (track_bytes - fdf_suppress_final_byte); literal = (uint8_t *) malloc(track_bytes); - (void) !fread(literal, 1, track_bytes, dev->f); + (void) !fread(literal, 1, track_bytes, dev->fp); free(literal); track_bytes = 0; } - if (feof(dev->f)) + if (feof(dev->fp)) break; } @@ -807,28 +816,28 @@ img_load(int drive, char *fn) dev->disk_data = (uint8_t *) malloc(size); /* Decode the entire file - pass 2, write to buffer. */ - fseek(dev->f, 0x80, SEEK_SET); + fseek(dev->fp, 0x80, SEEK_SET); track_bytes = 0; bpos = dev->disk_data; - while (!feof(dev->f)) { + while (!feof(dev->fp)) { if (!track_bytes) { /* Skip first 3 bytes - their meaning is unknown to us but could be a checksum. */ - first_byte = fgetc(dev->f); - (void) !fread(&track_bytes, 1, 2, dev->f); + first_byte = fgetc(dev->fp); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("Block header: %02X %04X ", first_byte, track_bytes); /* Read the length of encoded data block. */ - (void) !fread(&track_bytes, 1, 2, dev->f); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("%04X\n", track_bytes); } - if (feof(dev->f)) + if (feof(dev->fp)) break; if (first_byte == 0xFF) break; if (first_byte) { - run = fgetc(dev->f); + run = fgetc(dev->fp); real_run = (run & 0x7f); /* I *HAVE* to read something because fseek tries to be smart and never hits EOF, causing an infinite loop. */ @@ -839,14 +848,14 @@ img_load(int drive, char *fn) track_bytes--; if (!track_bytes) real_run -= fdf_suppress_final_byte; - rep_byte = fgetc(dev->f); + rep_byte = fgetc(dev->fp); if (real_run) memset(bpos, rep_byte, real_run); } else { /* Literal. */ track_bytes -= real_run; literal = (uint8_t *) malloc(real_run); - (void) !fread(literal, 1, real_run, dev->f); + (void) !fread(literal, 1, real_run, dev->fp); if (!track_bytes) real_run -= fdf_suppress_final_byte; if (run & 0x7f) @@ -857,14 +866,14 @@ img_load(int drive, char *fn) } else { /* Literal block. */ literal = (uint8_t *) malloc(track_bytes); - (void) !fread(literal, 1, track_bytes, dev->f); + (void) !fread(literal, 1, track_bytes, dev->fp); memcpy(bpos, literal, track_bytes - fdf_suppress_final_byte); free(literal); bpos += (track_bytes - fdf_suppress_final_byte); track_bytes = 0; } - if (feof(dev->f)) + if (feof(dev->fp)) break; } @@ -883,48 +892,48 @@ img_load(int drive, char *fn) if (((first_byte == 'C') && (second_byte == 'Q')) || ((first_byte == 'c') && (second_byte == 'q'))) { img_log("img_load(): File is a CopyQM image...\n"); fwriteprot[drive] = writeprot[drive] = 1; - fclose(dev->f); - dev->f = plat_fopen(fn, "rb"); + fclose(dev->fp); + dev->fp = plat_fopen(fn, "rb"); - fseek(dev->f, 0x03, SEEK_SET); - (void) !fread(&bpb_bps, 1, 2, dev->f); + fseek(dev->fp, 0x03, SEEK_SET); + (void) !fread(&bpb_bps, 1, 2, dev->fp); #if 0 - fseek(dev->f, 0x0B, SEEK_SET); - (void) !fread(&bpb_total, 1, 2, dev->f); + fseek(dev->fp, 0x0B, SEEK_SET); + (void) !fread(&bpb_total, 1, 2, dev->fp); #endif - fseek(dev->f, 0x10, SEEK_SET); - bpb_sectors = fgetc(dev->f); - fseek(dev->f, 0x12, SEEK_SET); - bpb_sides = fgetc(dev->f); - fseek(dev->f, 0x5B, SEEK_SET); - dev->tracks = fgetc(dev->f); + fseek(dev->fp, 0x10, SEEK_SET); + bpb_sectors = fgetc(dev->fp); + fseek(dev->fp, 0x12, SEEK_SET); + bpb_sides = fgetc(dev->fp); + fseek(dev->fp, 0x5B, SEEK_SET); + dev->tracks = fgetc(dev->fp); bpb_total = ((uint16_t) bpb_sectors) * ((uint16_t) bpb_sides) * dev->tracks; - fseek(dev->f, 0x74, SEEK_SET); - dev->interleave = fgetc(dev->f); - fseek(dev->f, 0x76, SEEK_SET); - dev->skew = fgetc(dev->f); + fseek(dev->fp, 0x74, SEEK_SET); + dev->interleave = fgetc(dev->fp); + fseek(dev->fp, 0x76, SEEK_SET); + dev->skew = fgetc(dev->fp); dev->disk_data = (uint8_t *) malloc(((uint32_t) bpb_total) * ((uint32_t) bpb_bps)); memset(dev->disk_data, 0xf6, ((uint32_t) bpb_total) * ((uint32_t) bpb_bps)); - fseek(dev->f, 0x6F, SEEK_SET); - (void) !fread(&comment_len, 1, 2, dev->f); + fseek(dev->fp, 0x6F, SEEK_SET); + (void) !fread(&comment_len, 1, 2, dev->fp); - fseek(dev->f, -1, SEEK_END); - size = ftell(dev->f) + 1; + fseek(dev->fp, -1, SEEK_END); + size = ftell(dev->fp) + 1; - fseek(dev->f, 133 + comment_len, SEEK_SET); + fseek(dev->fp, 133 + comment_len, SEEK_SET); cur_pos = 0; - while (!feof(dev->f)) { - (void) !fread(&block_len, 1, 2, dev->f); + while (!feof(dev->fp)) { + (void) !fread(&block_len, 1, 2, dev->fp); - if (!feof(dev->f)) { + if (!feof(dev->fp)) { if (block_len < 0) { - rep_byte = fgetc(dev->f); + rep_byte = fgetc(dev->fp); block_len = -block_len; if ((cur_pos + block_len) > ((uint32_t) bpb_total) * ((uint32_t) bpb_bps)) { block_len = ((uint32_t) bpb_total) * ((uint32_t) bpb_bps) - cur_pos; @@ -937,10 +946,10 @@ img_load(int drive, char *fn) } else if (block_len > 0) { if ((cur_pos + block_len) > ((uint32_t) bpb_total) * ((uint32_t) bpb_bps)) { block_len = ((uint32_t) bpb_total) * ((uint32_t) bpb_bps) - cur_pos; - (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->f); + (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->fp); break; } else { - (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->f); + (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->fp); cur_pos += block_len; } } @@ -960,22 +969,22 @@ img_load(int drive, char *fn) fwriteprot[drive] = writeprot[drive] = 1; } else img_log("img_load(): File is a raw image...\n"); - fseek(dev->f, dev->base + 0x0B, SEEK_SET); - (void) !fread(&bpb_bps, 1, 2, dev->f); - fseek(dev->f, dev->base + 0x13, SEEK_SET); - (void) !fread(&bpb_total, 1, 2, dev->f); - fseek(dev->f, dev->base + 0x15, SEEK_SET); - bpb_mid = fgetc(dev->f); - fseek(dev->f, dev->base + 0x18, SEEK_SET); - bpb_sectors = fgetc(dev->f); - fseek(dev->f, dev->base + 0x1A, SEEK_SET); - bpb_sides = fgetc(dev->f); + fseek(dev->fp, dev->base + 0x0B, SEEK_SET); + (void) !fread(&bpb_bps, 1, 2, dev->fp); + fseek(dev->fp, dev->base + 0x13, SEEK_SET); + (void) !fread(&bpb_total, 1, 2, dev->fp); + fseek(dev->fp, dev->base + 0x15, SEEK_SET); + bpb_mid = fgetc(dev->fp); + fseek(dev->fp, dev->base + 0x18, SEEK_SET); + bpb_sectors = fgetc(dev->fp); + fseek(dev->fp, dev->base + 0x1A, SEEK_SET); + bpb_sides = fgetc(dev->fp); cqm = 0; } - fseek(dev->f, -1, SEEK_END); - size = ftell(dev->f) + 1; + fseek(dev->fp, -1, SEEK_END); + size = ftell(dev->fp) + 1; if (ddi) size -= 0x2400; @@ -1022,9 +1031,6 @@ jump_if_fdf: } else if (size <= (320 * 1024)) { dev->sectors = 8; dev->tracks = 40; - } else if (size <= (320 * 1024)) { - dev->sectors = 8; - dev->tracks = 40; } else if (size <= (360 * 1024)) { /*DD 360K*/ dev->sectors = 9; dev->tracks = 40; @@ -1119,7 +1125,7 @@ jump_if_fdf: dev->tracks = 86; } else { img_log("Image is bigger than can fit on an ED floppy, ejecting...\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -1132,9 +1138,9 @@ jump_if_fdf: /* The BPB readings appear to be valid, so let's set the values. */ if (fdi) { /* The image is a Japanese FDI, therefore we read the number of tracks from the header. */ - if (fseek(dev->f, 0x1C, SEEK_SET) == -1) + if (fseek(dev->fp, 0x1C, SEEK_SET) == -1) fatal("Japanese FDI: Failed when seeking to 0x1C\n"); - (void) !fread(&(dev->tracks), 1, 4, dev->f); + (void) !fread(&(dev->tracks), 1, 4, dev->fp); } else { if (!cqm && !fdf) { /* Number of tracks = number of total sectors divided by sides times sectors per track. */ @@ -1152,7 +1158,7 @@ jump_if_fdf: temp_rate = 0xFF; } - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { if ((dev->sectors <= maximum_sectors[dev->sector_size][i]) || (dev->sectors == xdf_sectors[dev->sector_size][i])) { bit_rate_300 = bit_rates_300[i]; temp_rate = rates[i]; @@ -1176,7 +1182,7 @@ jump_if_fdf: if (temp_rate == 0xFF) { img_log("Image is bigger than can fit on an ED floppy, ejecting...\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -1193,7 +1199,7 @@ jump_if_fdf: } if (!dev->gap3_size) { img_log("ERROR: Floppy image of unknown format was inserted into drive %c:!\n", drive + 0x41); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -1253,9 +1259,9 @@ img_close(int drive) d86f_unregister(drive); - if (dev->f != NULL) { - fclose(dev->f); - dev->f = NULL; + if (dev->fp != NULL) { + fclose(dev->fp); + dev->fp = NULL; } if (dev->disk_data != NULL) diff --git a/src/floppy/fdd_json.c b/src/floppy/fdd_json.c index aba7f1d33..36a041a68 100644 --- a/src/floppy/fdd_json.c +++ b/src/floppy/fdd_json.c @@ -62,26 +62,26 @@ #define NSIDES 2 #define NSECTORS 256 -typedef struct { - uint8_t track, /* ID: track number */ - side, /* side number */ - sector; /* sector number 1.. */ - uint16_t size; /* encoded size of sector */ - uint8_t *data; /* allocated data for it */ +typedef struct sector_t { + uint8_t track; /* ID: track number */ + uint8_t side; /* side number */ + uint8_t sector; /* sector number 1.. */ + uint16_t size; /* encoded size of sector */ + uint8_t *data; /* allocated data for it */ } sector_t; -typedef struct { - FILE *f; +typedef struct json_t { + FILE *fp; /* Geometry. */ - uint8_t tracks, /* number of tracks */ - sides, /* number of sides */ - sectors, /* number of sectors per track */ - spt[NTRACKS][NSIDES]; /* number of sectors per track */ + uint8_t tracks; /* number of tracks */ + uint8_t sides; /* number of sides */ + uint8_t sectors; /* number of sectors per track */ + uint8_t spt[NTRACKS][NSIDES]; /* number of sectors per track */ - uint8_t track, /* current track */ - side, /* current side */ - sector[NSIDES]; /* current sector */ + uint8_t track; /* current track */ + uint8_t side; /* current side */ + uint8_t sector[NSIDES]; /* current sector */ uint8_t dmf; /* disk is DMF format */ uint8_t interleave; @@ -92,8 +92,8 @@ typedef struct { uint8_t gap3_len; int track_width; - uint16_t disk_flags, /* flags for the entire disk */ - track_flags; /* flags for the current track */ + uint16_t disk_flags; /* flags for the entire disk */ + uint16_t track_flags; /* flags for the current track */ uint8_t interleave_ordered[NTRACKS][NSIDES]; @@ -125,10 +125,11 @@ static void handle(json_t *dev, char *name, char *str) { sector_t *sec = NULL; - uint32_t l, pat; + uint32_t l; + uint32_t pat; uint8_t *p; char *sp; - int i, s; + int s; /* Point to the currently selected sector. */ sec = &dev->sects[dev->track][dev->side][dev->dmf - 1]; @@ -163,7 +164,7 @@ handle(json_t *dev, char *name, char *str) sec->data = (uint8_t *) malloc(sec->size); p = sec->data; s = (sec->size / sizeof(uint32_t)); - for (i = 0; i < s; i++) { + for (int i = 0; i < s; i++) { l = pat; *p++ = (l & 0x000000ff); l >>= 8; @@ -207,18 +208,21 @@ unexpect(int c, int state, int level) static int load_image(json_t *dev) { - char buff[4096], name[32]; - int c, i, j, state, level; + char buff[4096]; + char name[32]; + int c; + int state; + int level; char *ptr; - if (dev->f == NULL) { + if (dev->fp == NULL) { json_log("JSON: no file loaded!\n"); - return (0); + return 0; } /* Initialize. */ - for (i = 0; i < NTRACKS; i++) { - for (j = 0; j < NSIDES; j++) + for (uint16_t i = 0; i < NTRACKS; i++) { + for (uint8_t j = 0; j < NSIDES; j++) memset(dev->sects[i][j], 0x00, sizeof(sector_t)); } dev->track = dev->side = dev->dmf = 0; /* "dmf" is "sector#" */ @@ -228,8 +232,8 @@ load_image(json_t *dev) level = state = 0; while (state >= 0) { /* Get a character from the input. */ - c = fgetc(dev->f); - if ((c == EOF) || ferror(dev->f)) { + c = fgetc(dev->fp); + if ((c == EOF) || ferror(dev->fp)) { state = -1; break; } @@ -368,6 +372,9 @@ load_image(json_t *dev) } dev->track++; break; + + default: + break; } } @@ -375,7 +382,7 @@ load_image(json_t *dev) dev->tracks = dev->track; dev->sides = dev->side; - return (1); + return 1; } /* Seek the heads to a track, and prepare to read data from that track. */ @@ -384,11 +391,15 @@ json_seek(int drive, int track) { uint8_t id[4] = { 0, 0, 0, 0 }; json_t *dev = images[drive]; - int side, sector; - int rate, gap2, gap3, pos; - int ssize, rsec, asec; + int rate; + int gap2; + int gap3; + int pos; + int ssize; + int rsec; + int asec; - if (dev->f == NULL) { + if (dev->fp == NULL) { json_log("JSON: seek: no file loaded!\n"); return; } @@ -412,7 +423,7 @@ json_seek(int drive, int track) return; } - for (side = 0; side < dev->sides; side++) { + for (uint8_t side = 0; side < dev->sides; side++) { /* Get transfer rate for this side. */ rate = dev->track_flags & 0x07; if (!rate && (dev->track_flags & 0x20)) @@ -428,7 +439,7 @@ json_seek(int drive, int track) pos = d86f_prepare_pretrack(drive, side, 0); - for (sector = 0; sector < dev->spt[track][side]; sector++) { + for (uint8_t sector = 0; sector < dev->spt[track][side]; sector++) { rsec = dev->sects[track][side][sector].sector; asec = sector; @@ -456,7 +467,7 @@ json_seek(int drive, int track) static uint16_t disk_flags(int drive) { - json_t *dev = images[drive]; + const json_t *dev = images[drive]; return (dev->disk_flags); } @@ -464,7 +475,7 @@ disk_flags(int drive) static uint16_t track_flags(int drive) { - json_t *dev = images[drive]; + const json_t *dev = images[drive]; return (dev->track_flags); } @@ -473,7 +484,6 @@ static void set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { json_t *dev = images[drive]; - int i; dev->sector[side] = 0; @@ -485,7 +495,7 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) dev->side = side; /* Now loop over all sector ID's on this side to find our sector. */ - for (i = 0; i < dev->spt[c][side]; i++) { + for (uint8_t i = 0; i < dev->spt[c][side]; i++) { if ((dev->sects[dev->track][side][i].track == c) && (dev->sects[dev->track][side][i].side == h) && (dev->sects[dev->track][side][i].sector == r) && (dev->sects[dev->track][side][i].size == n)) { dev->sector[side] = i; } @@ -495,8 +505,8 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) static uint8_t poll_read_data(int drive, int side, uint16_t pos) { - json_t *dev = images[drive]; - uint8_t sec = dev->sector[side]; + const json_t *dev = images[drive]; + uint8_t sec = dev->sector[side]; return (dev->sects[dev->track][side][sec].data[pos]); } @@ -510,11 +520,10 @@ json_init(void) void json_load(int drive, char *fn) { - double bit_rate; - int temp_rate; - sector_t *sec; - json_t *dev; - int i; + double bit_rate; + int temp_rate; + const sector_t *sec; + json_t *dev; /* Just in case- remove ourselves from 86F. */ d86f_unregister(drive); @@ -524,8 +533,8 @@ json_load(int drive, char *fn) memset(dev, 0x00, sizeof(json_t)); /* Open the image file. */ - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { free(dev); memset(fn, 0x00, sizeof(char)); return; @@ -540,7 +549,7 @@ json_load(int drive, char *fn) /* Load all sectors from the image file. */ if (!load_image(dev)) { json_log("JSON: failed to initialize\n"); - (void) fclose(dev->f); + (void) fclose(dev->fp); free(dev); images[drive] = NULL; memset(fn, 0x00, sizeof(char)); @@ -571,7 +580,7 @@ json_load(int drive, char *fn) temp_rate = 0xff; sec = &dev->sects[0][0][0]; - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { if (dev->spt[0][0] > fdd_max_sectors[sec->size][i]) continue; @@ -602,8 +611,8 @@ json_load(int drive, char *fn) if (temp_rate == 0xff) { json_log("JSON: invalid image (temp_rate=0xff)\n"); - (void) fclose(dev->f); - dev->f = NULL; + (void) fclose(dev->fp); + dev->fp = NULL; free(dev); images[drive] = NULL; memset(fn, 0x00, sizeof(char)); @@ -624,8 +633,8 @@ json_load(int drive, char *fn) if (!dev->gap3_len) { json_log("JSON: image of unknown format was inserted into drive %c:!\n", 'C' + drive); - (void) fclose(dev->f); - dev->f = NULL; + (void) fclose(dev->fp); + dev->fp = NULL; free(dev); images[drive] = NULL; memset(fn, 0x00, sizeof(char)); @@ -667,7 +676,6 @@ void json_close(int drive) { json_t *dev = images[drive]; - int t, h, s; if (dev == NULL) return; @@ -676,10 +684,10 @@ json_close(int drive) d86f_unregister(drive); /* Release all the sector buffers. */ - for (t = 0; t < 256; t++) { - for (h = 0; h < 2; h++) { + for (uint16_t t = 0; t < 256; t++) { + for (uint8_t h = 0; h < 2; h++) { memset(dev->sects[t][h], 0x00, sizeof(sector_t)); - for (s = 0; s < 256; s++) { + for (uint16_t s = 0; s < 256; s++) { if (dev->sects[t][h][s].data != NULL) free(dev->sects[t][h][s].data); dev->sects[t][h][s].data = NULL; @@ -687,8 +695,8 @@ json_close(int drive) } } - if (dev->f != NULL) - (void) fclose(dev->f); + if (dev->fp != NULL) + (void) fclose(dev->fp); /* Release the memory. */ free(dev); diff --git a/src/floppy/fdd_mfm.c b/src/floppy/fdd_mfm.c index 5196bcbe0..b4c859d5d 100644 --- a/src/floppy/fdd_mfm.c +++ b/src/floppy/fdd_mfm.c @@ -32,7 +32,7 @@ #include <86box/fdc.h> #pragma pack(push, 1) -typedef struct { +typedef struct mfm_header_t { uint8_t hdr_name[7]; uint16_t tracks_no; @@ -45,14 +45,14 @@ typedef struct { uint32_t track_list_offset; } mfm_header_t; -typedef struct { +typedef struct mfm_track_t { uint16_t track_no; uint8_t side_no; uint32_t track_size; uint32_t track_offset; } mfm_track_t; -typedef struct { +typedef struct mfm_adv_track_t { uint16_t track_no; uint8_t side_no; uint16_t rpm; @@ -62,18 +62,21 @@ typedef struct { } mfm_adv_track_t; #pragma pack(pop) -typedef struct { - FILE *f; +typedef struct mfm_t { + FILE *fp; mfm_header_t hdr; mfm_track_t *tracks; mfm_adv_track_t *adv_tracks; - uint16_t disk_flags, pad; + uint16_t disk_flags; + uint16_t pad; uint16_t side_flags[2]; - int br_rounded, rpm_rounded, - total_tracks, cur_track; + int br_rounded; + int rpm_rounded; + int total_tracks; + int cur_track; uint8_t track_data[2][256 * 1024]; } mfm_t; @@ -102,10 +105,10 @@ mfm_log(const char *fmt, ...) static int get_track_index(int drive, int side, int track) { - mfm_t *dev = mfm[drive]; - int i, ret = -1; + const mfm_t *dev = mfm[drive]; + int ret = -1; - for (i = 0; i < dev->total_tracks; i++) { + for (int i = 0; i < dev->total_tracks; i++) { if ((dev->tracks[i].track_no == track) && (dev->tracks[i].side_no == side)) { ret = i; break; @@ -118,10 +121,10 @@ get_track_index(int drive, int side, int track) static int get_adv_track_index(int drive, int side, int track) { - mfm_t *dev = mfm[drive]; - int i, ret = -1; + const mfm_t *dev = mfm[drive]; + int ret = -1; - for (i = 0; i < dev->total_tracks; i++) { + for (int i = 0; i < dev->total_tracks; i++) { if ((dev->adv_tracks[i].track_no == track) && (dev->adv_tracks[i].side_no == side)) { ret = i; break; @@ -134,9 +137,9 @@ get_adv_track_index(int drive, int side, int track) static void get_adv_track_bitrate(int drive, int side, int track, int *br, int *rpm) { - mfm_t *dev = mfm[drive]; - int track_index; - double dbr; + const mfm_t *dev = mfm[drive]; + int track_index; + double dbr; track_index = get_adv_track_index(drive, side, track); @@ -154,7 +157,8 @@ get_adv_track_bitrate(int drive, int side, int track, int *br, int *rpm) static void set_disk_flags(int drive) { - int br = 250, rpm = 300; + int br = 250; + int rpm = 300; mfm_t *dev = mfm[drive]; uint16_t temp_disk_flags = 0x1080; /* We ALWAYS claim to have extra bit cells, even if the actual amount is 0; Bit 12 = 1, bits 6, 5 = 0 - extra bit cells field specifies the entire @@ -169,14 +173,14 @@ set_disk_flags(int drive) } switch (br) { - case 500: - temp_disk_flags |= 2; + default: + case 250: + case 300: + temp_disk_flags |= 0; break; - case 300: - case 250: - default: - temp_disk_flags |= 0; + case 500: + temp_disk_flags |= 2; break; case 1000: @@ -193,7 +197,7 @@ set_disk_flags(int drive) static uint16_t disk_flags(int drive) { - mfm_t *dev = mfm[drive]; + const mfm_t *dev = mfm[drive]; return dev->disk_flags; } @@ -203,7 +207,8 @@ set_side_flags(int drive, int side) { mfm_t *dev = mfm[drive]; uint16_t temp_side_flags = 0; - int br = 250, rpm = 300; + int br = 250; + int rpm = 300; if (dev->hdr.if_type & 0x80) get_adv_track_bitrate(drive, side, dev->cur_track, &br, &rpm); @@ -252,8 +257,8 @@ set_side_flags(int drive, int side) static uint16_t side_flags(int drive) { - mfm_t *dev = mfm[drive]; - int side; + const mfm_t *dev = mfm[drive]; + int side; side = fdd_get_head(drive); @@ -263,9 +268,11 @@ side_flags(int drive) static uint32_t get_raw_size(int drive, int side) { - mfm_t *dev = mfm[drive]; - int track_index, is_300_rpm; - int br = 250, rpm = 300; + const mfm_t *dev = mfm[drive]; + int track_index; + int is_300_rpm; + int br = 250; + int rpm = 300; if (dev->hdr.if_type & 0x80) { track_index = get_adv_track_index(drive, side, dev->cur_track); @@ -281,8 +288,8 @@ get_raw_size(int drive, int side) if (track_index == -1) { mfm_log("MFM: Unable to find track (%i, %i)\n", dev->cur_track, side); switch (br) { - case 250: default: + case 250: return is_300_rpm ? 100000 : 83333; case 300: return is_300_rpm ? 120000 : 100000; @@ -319,8 +326,10 @@ void mfm_read_side(int drive, int side) { mfm_t *dev = mfm[drive]; - int track_index, track_size; - int track_bytes, ret; + int track_index; + int track_size; + int track_bytes; + int ret; if (dev->hdr.if_type & 0x80) track_index = get_adv_track_index(drive, side, dev->cur_track); @@ -336,12 +345,12 @@ mfm_read_side(int drive, int side) memset(dev->track_data[side], 0x00, track_bytes); else { if (dev->hdr.if_type & 0x80) - ret = fseek(dev->f, dev->adv_tracks[track_index].track_offset, SEEK_SET); + ret = fseek(dev->fp, dev->adv_tracks[track_index].track_offset, SEEK_SET); else - ret = fseek(dev->f, dev->tracks[track_index].track_offset, SEEK_SET); + ret = fseek(dev->fp, dev->tracks[track_index].track_offset, SEEK_SET); if (ret == -1) fatal("mfm_read_side(): Error seeking to the beginning of the file\n"); - if (fread(dev->track_data[side], 1, track_bytes, dev->f) != track_bytes) + if (fread(dev->track_data[side], 1, track_bytes, dev->fp) != track_bytes) fatal("mfm_read_side(): Error reading track bytes\n"); } @@ -364,7 +373,7 @@ mfm_seek(int drive, int track) dev->cur_track = track; d86f_set_cur_track(drive, track); - if (dev->f == NULL) + if (dev->fp == NULL) return; if (track < 0) @@ -382,7 +391,7 @@ mfm_load(int drive, char *fn) { mfm_t *dev; double dbr; - int i, size; + int size; writeprot[drive] = fwriteprot[drive] = 1; @@ -390,8 +399,8 @@ mfm_load(int drive, char *fn) dev = (mfm_t *) malloc(sizeof(mfm_t)); memset(dev, 0x00, sizeof(mfm_t)); - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -401,7 +410,7 @@ mfm_load(int drive, char *fn) /* Read the header. */ size = sizeof(mfm_header_t); - if (fread(&dev->hdr, 1, size, dev->f) != size) + if (fread(&dev->hdr, 1, size, dev->fp) != size) fatal("mfm_load(): Error reading header\n"); /* Calculate tracks * sides, allocate the tracks array, and read it. */ @@ -409,12 +418,12 @@ mfm_load(int drive, char *fn) if (dev->hdr.if_type & 0x80) { dev->adv_tracks = (mfm_adv_track_t *) malloc(dev->total_tracks * sizeof(mfm_adv_track_t)); size = dev->total_tracks * sizeof(mfm_adv_track_t); - if (fread(dev->adv_tracks, 1, size, dev->f) != size) + if (fread(dev->adv_tracks, 1, size, dev->fp) != size) fatal("mfm_load(): Error reading advanced tracks\n"); } else { dev->tracks = (mfm_track_t *) malloc(dev->total_tracks * sizeof(mfm_track_t)); size = dev->total_tracks * sizeof(mfm_track_t); - if (fread(dev->tracks, 1, size, dev->f) != size) + if (fread(dev->tracks, 1, size, dev->fp) != size) fatal("mfm_load(): Error reading tracks\n"); } @@ -427,7 +436,7 @@ mfm_load(int drive, char *fn) dev->hdr.tracks_no >>= 1; dev->hdr.sides_no <<= 1; - for (i = 0; i < dev->total_tracks; i++) { + for (int i = 0; i < dev->total_tracks; i++) { if (dev->hdr.if_type & 0x80) { dev->adv_tracks[i].side_no <<= 1; dev->adv_tracks[i].side_no |= (dev->adv_tracks[i].track_no & 1); @@ -495,8 +504,8 @@ mfm_close(int drive) if (dev->adv_tracks) free(dev->adv_tracks); - if (dev->f) - fclose(dev->f); + if (dev->fp) + fclose(dev->fp); /* Release the memory. */ free(dev); diff --git a/src/floppy/fdd_td0.c b/src/floppy/fdd_td0.c index bf2b643ff..46e29343b 100644 --- a/src/floppy/fdd_td0.c +++ b/src/floppy/fdd_td0.c @@ -60,16 +60,19 @@ /* update when cumulative frequency */ /* reaches to this value */ -typedef struct { - uint16_t r, - bufcnt, bufndx, bufpos, /* string buffer */ - /* the following to allow block reads - from input in next_word() */ - ibufcnt, ibufndx; /* input buffer counters */ - uint8_t inbuf[BUFSZ]; /* input buffer */ +typedef struct tdlzhuf_t { + uint16_t r; + uint16_t bufcnt; /* string buffer */ + uint16_t bufndx; /* string buffer */ + uint16_t bufpos; /* string buffer */ + /* the following to allow block reads + from input in next_word() */ + uint16_t ibufcnt; /* input buffer counters */ + uint16_t ibufndx; /* input buffer counters */ + uint8_t inbuf[BUFSZ]; /* input buffer */ } tdlzhuf; -typedef struct { +typedef struct td0dsk_t { FILE *fdd_file; off_t fdd_file_offset; @@ -90,7 +93,7 @@ typedef struct { uint8_t getlen; } td0dsk_t; -typedef struct { +typedef struct td0_sector_t { uint8_t track; uint8_t head; uint8_t sector; @@ -100,8 +103,8 @@ typedef struct { uint8_t *data; } td0_sector_t; -typedef struct { - FILE *f; +typedef struct td0_t { + FILE *fp; int tracks; int track_width; @@ -224,9 +227,9 @@ fdd_image_read(int drive, char *buffer, uint32_t offset, uint32_t len) { td0_t *dev = td0[drive]; - if (fseek(dev->f, offset, SEEK_SET) == -1) + if (fseek(dev->fp, offset, SEEK_SET) == -1) fatal("fdd_image_read(): Error seeking to the beginning of the file\n"); - if (fread(buffer, 1, len, dev->f) != len) + if (fread(buffer, 1, len, dev->fp) != len) fatal("fdd_image_read(): Error reading data\n"); } @@ -237,11 +240,11 @@ dsk_identify(int drive) fdd_image_read(drive, header, 0, 2); if (header[0] == 'T' && header[1] == 'D') - return (1); + return 1; else if (header[0] == 't' && header[1] == 'd') - return (1); + return 1; - return (0); + return 0; } static int @@ -259,7 +262,7 @@ state_data_read(td0dsk_t *state, uint8_t *buf, uint16_t size) fatal("TD0: Error reading data in state_data_read()\n"); state->fdd_file_offset += size; - return (size); + return size; } static int @@ -277,7 +280,7 @@ state_next_word(td0dsk_t *state) state->getlen += 8; } - return (0); + return 0; } /* get one bit */ @@ -293,9 +296,9 @@ state_GetBit(td0dsk_t *state) state->getbuf <<= 1; state->getlen--; if (i < 0) - return (1); + return 1; - return (0); + return 0; } /* get a byte */ @@ -305,7 +308,7 @@ state_GetByte(td0dsk_t *state) uint16_t i; if (state_next_word(state) != 0) - return (-1); + return -1; i = state->getbuf; state->getbuf <<= 8; @@ -319,7 +322,8 @@ state_GetByte(td0dsk_t *state) static void state_StartHuff(td0dsk_t *state) { - int i, j; + int i; + int j; for (i = 0; i < N_CHAR; i++) { state->freq[i] = 1; @@ -343,8 +347,11 @@ state_StartHuff(td0dsk_t *state) static void state_reconst(td0dsk_t *state) { - int16_t i, j, k; - uint16_t f, l; + int16_t i; + int16_t j; + int16_t k; + uint16_t f; + uint16_t l; /* halven cumulative freq for leaf nodes */ j = 0; @@ -360,7 +367,7 @@ state_reconst(td0dsk_t *state) for (i = 0, j = N_CHAR; j < T; i += 2, j++) { k = i + 1; f = state->freq[j] = state->freq[i] + state->freq[k]; - for (k = j - 1; f < state->freq[k]; k--) { }; + for (k = j - 1; f < state->freq[k]; k--) { } k++; l = (j - k) * 2; @@ -385,7 +392,10 @@ state_reconst(td0dsk_t *state) static void state_update(td0dsk_t *state, int c) { - int i, j, k, l; + int i; + int j; + int k; + int l; if (state->freq[R] == MAX_FREQ) state_reconst(state); @@ -398,7 +408,7 @@ state_update(td0dsk_t *state, int c) /* swap nodes to keep the tree freq-ordered */ if (k > state->freq[l = c + 1]) { - while (k > state->freq[++l]) { }; + while (k > state->freq[++l]) { } l--; state->freq[c] = state->freq[l]; state->freq[l] = k; @@ -444,14 +454,16 @@ state_DecodeChar(td0dsk_t *state) state_update(state, c); - return (c); + return c; } static int16_t state_DecodePosition(td0dsk_t *state) { int16_t bit; - uint16_t i, j, c; + uint16_t i; + uint16_t j; + uint16_t c; /* decode upper 6 bits from given table */ if ((bit = state_GetByte(state)) < 0) @@ -476,15 +488,13 @@ state_DecodePosition(td0dsk_t *state) static void state_init_Decode(td0dsk_t *state) { - int i; - state->getbuf = 0; state->getlen = 0; state->tdctl.ibufcnt = state->tdctl.ibufndx = 0; /* input buffer is empty */ state->tdctl.bufcnt = 0; state_StartHuff(state); - for (i = 0; i < N - F; i++) + for (uint16_t i = 0; i < N - F; i++) state->text_buf[i] = ' '; state->tdctl.r = N - F; @@ -494,13 +504,14 @@ state_init_Decode(td0dsk_t *state) static int state_Decode(td0dsk_t *state, uint8_t *buf, int len) { - int16_t c, pos; + int16_t c; + int16_t pos; int count; /* was an unsigned long, seems unnecessary */ for (count = 0; count < len;) { if (state->tdctl.bufcnt == 0) { if ((c = state_DecodeChar(state)) < 0) - return (count); /* fatal error */ + return count; /* fatal error */ if (c < 256) { *(buf++) = c & 0xff; state->text_buf[state->tdctl.r++] = c & 0xff; @@ -508,7 +519,7 @@ state_Decode(td0dsk_t *state, uint8_t *buf, int len) count++; } else { if ((pos = state_DecodePosition(state)) < 0) - return (count); /* fatal error */ + return count; /* fatal error */ state->tdctl.bufpos = (state->tdctl.r - pos - 1) & (N - 1); state->tdctl.bufcnt = c - 255 + THRESHOLD; state->tdctl.bufndx = 0; @@ -530,7 +541,7 @@ state_Decode(td0dsk_t *state, uint8_t *buf, int len) } } - return (count); /* count == len, success */ + return count; /* count == len, success */ } static uint32_t @@ -578,70 +589,77 @@ get_raw_tsize(int side_flags, int slower_rpm) break; } - return (size); + return size; } static int td0_initialize(int drive) { - td0_t *dev = td0[drive]; - uint8_t header[12]; - int fm, head, track; - int track_count = 0; - int head_count = 0; - int track_spt, track_spt_adjusted; - int offset = 0; - int density = 0; - int temp_rate = 0; - uint32_t file_size; - uint16_t len, rep; - td0dsk_t disk_decode; - uint8_t *hs; - uint16_t size; - uint8_t *dbuf = dev->processed_buf; - uint32_t total_size = 0; - uint32_t id_field = 0; - uint32_t pre_sector = 0; - int32_t track_size = 0; - int32_t raw_tsize = 0; - uint32_t minimum_gap3 = 0; - uint32_t minimum_gap4 = 0; - int i, j, k; - int size_diff, gap_sum; + td0_t *dev = td0[drive]; + uint8_t header[12]; + int fm; + int head; + int track; + int track_count = 0; + int head_count = 0; + int track_spt; + int track_spt_adjusted; + int offset = 0; + int density = 0; + int temp_rate = 0; + uint32_t file_size; + uint16_t len; + uint16_t rep; + td0dsk_t disk_decode; + const uint8_t *hs; + uint16_t size; + uint8_t *dbuf = dev->processed_buf; + uint32_t total_size = 0; + uint32_t id_field = 0; + uint32_t pre_sector = 0; + int32_t track_size = 0; + int32_t raw_tsize = 0; + uint32_t minimum_gap3 = 0; + uint32_t minimum_gap4 = 0; + int i; + int j; + int k; + int size_diff; + int gap_sum; - if (dev->f == NULL) { + if (dev->fp == NULL) { td0_log("TD0: Attempted to initialize without loading a file first\n"); - return (0); + return 0; } - fseek(dev->f, 0, SEEK_END); - file_size = ftell(dev->f); + fseek(dev->fp, 0, SEEK_END); + file_size = ftell(dev->fp); if (file_size < 12) { td0_log("TD0: File is too small to even contain the header\n"); - return (0); + return 0; } if (file_size > TD0_MAX_BUFSZ) { td0_log("TD0: File exceeds the maximum size\n"); - return (0); + return 0; } - fseek(dev->f, 0, SEEK_SET); - (void) !fread(header, 1, 12, dev->f); + fseek(dev->fp, 0, SEEK_SET); + (void) !fread(header, 1, 12, dev->fp); head_count = header[9]; if (header[0] == 't') { td0_log("TD0: File is compressed\n"); - disk_decode.fdd_file = dev->f; + disk_decode.fdd_file = dev->fp; state_init_Decode(&disk_decode); disk_decode.fdd_file_offset = 12; state_Decode(&disk_decode, dev->imagebuf, TD0_MAX_BUFSZ); } else { td0_log("TD0: File is uncompressed\n"); - if (fseek(dev->f, 12, SEEK_SET) == -1) + if (fseek(dev->fp, 12, SEEK_SET) == -1) fatal("td0_initialize(): Error seeking to offet 12\n"); - if (fread(dev->imagebuf, 1, file_size - 12, dev->f) != (file_size - 12)) + if (fread(dev->imagebuf, 1, file_size - 12, dev->fp) != (file_size - 12)) fatal("td0_initialize(): Error reading image buffer\n"); } @@ -652,14 +670,14 @@ td0_initialize(int drive) if (track_spt == 255) { /* Empty file? */ td0_log("TD0: File has no tracks\n"); - return (0); + return 0; } density = (header[5] >> 1) & 3; if (density == 3) { td0_log("TD0: Unknown density\n"); - return (0); + return 0; } /* @@ -692,6 +710,9 @@ td0_initialize(int drive) dev->default_track_flags = (density == 1) ? 0x00 : ((density == 2) ? 0x03 : 0x02); dev->max_sector_size = (density == 1) ? 6 : ((density == 2) ? 7 : 5); /* 16384, 8192, or 4096 bytes. */ break; + + default: + break; } dev->disk_flags = header[5] & 0x06; @@ -737,7 +758,7 @@ td0_initialize(int drive) size = 128 << hs[3]; if ((total_size + size) >= TD0_MAX_BUFSZ) { td0_log("TD0: Processed buffer overflow\n"); - return (0); + return 0; } if (hs[4] & 0x30) @@ -747,7 +768,7 @@ td0_initialize(int drive) switch (hs[8]) { default: td0_log("TD0: Image uses an unsupported sector data encoding: %i\n", hs[8]); - return (0); + return 0; case 0: memcpy(dbuf, &dev->imagebuf[offset], size); @@ -862,13 +883,13 @@ td0_initialize(int drive) td0_log("TD0: File loaded: %i tracks, %i sides, disk flags: %02X, side flags: %02X, %02X, GAP3 length: %02X\n", dev->tracks, dev->sides, dev->disk_flags, dev->current_side_flags[0], dev->current_side_flags[1], dev->gap3_len); - return (1); + return 1; } static uint16_t disk_flags(int drive) { - td0_t *dev = td0[drive]; + const td0_t *dev = td0[drive]; return (dev->disk_flags); } @@ -876,26 +897,26 @@ disk_flags(int drive) static uint16_t side_flags(int drive) { - td0_t *dev = td0[drive]; - int side = 0; - uint16_t sflags = 0; + const td0_t *dev = td0[drive]; + int side = 0; + uint16_t sflags = 0; side = fdd_get_head(drive); sflags = dev->current_side_flags[side]; - return (sflags); + return sflags; } static void set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { td0_t *dev = td0[drive]; - int i = 0, cyl = c; + int cyl = c; dev->current_sector_index[side] = 0; if (cyl != dev->track) return; - for (i = 0; i < dev->track_spt[cyl][side]; i++) { + for (uint8_t i = 0; i < dev->track_spt[cyl][side]; i++) { if ((dev->sects[cyl][side][i].track == c) && (dev->sects[cyl][side][i].head == h) && (dev->sects[cyl][side][i].sector == r) && (dev->sects[cyl][side][i].size == n)) { dev->current_sector_index[side] = i; } @@ -905,7 +926,7 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) static uint8_t poll_read_data(int drive, int side, uint16_t pos) { - td0_t *dev = td0[drive]; + const td0_t *dev = td0[drive]; return (dev->sects[dev->track][side][dev->current_sector_index[side]].data[pos]); } @@ -915,9 +936,14 @@ track_is_xdf(int drive, int side, int track) { td0_t *dev = td0[drive]; uint8_t id[4] = { 0, 0, 0, 0 }; - int i, effective_sectors, xdf_sectors; - int high_sectors, low_sectors; - int max_high_id, expected_high_count, expected_low_count; + int i; + int effective_sectors; + int xdf_sectors; + int high_sectors; + int low_sectors; + int max_high_id; + int expected_high_count; + int expected_low_count; effective_sectors = xdf_sectors = high_sectors = low_sectors = 0; @@ -976,23 +1002,24 @@ track_is_xdf(int drive, int side, int track) if ((effective_sectors == 3) && (xdf_sectors == 3)) { dev->current_side_flags[side] = 0x28; - return (1); /* 5.25" 2HD XDF */ + return 1; /* 5.25" 2HD XDF */ } if ((effective_sectors == 4) && (xdf_sectors == 4)) { dev->current_side_flags[side] = 0x08; - return (2); /* 3.5" 2HD XDF */ + return 2; /* 3.5" 2HD XDF */ } } - return (0); + return 0; } static int track_is_interleave(int drive, int side, int track) { td0_t *dev = td0[drive]; - int i, effective_sectors; + int i; + int effective_sectors; int track_spt; effective_sectors = 0; @@ -1003,7 +1030,7 @@ track_is_interleave(int drive, int side, int track) track_spt = dev->track_spt[track][side]; if (track_spt != 21) - return (0); + return 0; for (i = 0; i < track_spt; i++) { if ((dev->sects[track][side][i].track == track) && (dev->sects[track][side][i].head == side) && (dev->sects[track][side][i].sector >= 1) && (dev->sects[track][side][i].sector <= track_spt) && (dev->sects[track][side][i].size == 2)) { @@ -1013,18 +1040,18 @@ track_is_interleave(int drive, int side, int track) } if (effective_sectors == track_spt) - return (1); + return 1; - return (0); + return 0; } static void td0_seek(int drive, int track) { td0_t *dev = td0[drive]; - int side; uint8_t id[4] = { 0, 0, 0, 0 }; - int sector, current_pos; + int sector; + int current_pos; int ssize = 512; int track_rate = 0; int track_gap2 = 22; @@ -1037,9 +1064,10 @@ td0_seek(int drive, int track) int ordered_pos = 0; int real_sector = 0; int actual_sector = 0; - int fm, sector_adjusted; + int fm; + int sector_adjusted; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (!dev->track_width && fdd_doublestep_40(drive)) @@ -1064,7 +1092,7 @@ td0_seek(int drive, int track) return; } - for (side = 0; side < dev->sides; side++) { + for (int side = 0; side < dev->sides; side++) { track_rate = dev->current_side_flags[side] & 7; /* Make sure 300 kbps @ 360 rpm is treated the same as 250 kbps @ 300 rpm. */ if (!track_rate && (dev->current_side_flags[side] & 0x20)) @@ -1157,8 +1185,8 @@ td0_abort(int drive) free(dev->imagebuf); if (dev->processed_buf) free(dev->processed_buf); - if (dev->f) - fclose(dev->f); + if (dev->fp) + fclose(dev->fp); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); td0[drive] = NULL; @@ -1178,8 +1206,8 @@ td0_load(int drive, char *fn) memset(dev, 0x00, sizeof(td0_t)); td0[drive] = dev; - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } @@ -1234,7 +1262,6 @@ void td0_close(int drive) { td0_t *dev = td0[drive]; - int i, j, k; if (dev == NULL) return; @@ -1246,23 +1273,23 @@ td0_close(int drive) if (dev->processed_buf) free(dev->processed_buf); - for (i = 0; i < 256; i++) { - for (j = 0; j < 2; j++) { - for (k = 0; k < 256; k++) + for (uint16_t i = 0; i < 256; i++) { + for (uint8_t j = 0; j < 2; j++) { + for (uint16_t k = 0; k < 256; k++) dev->sects[i][j][k].data = NULL; } } - for (i = 0; i < 256; i++) { + for (uint16_t i = 0; i < 256; i++) { memset(dev->side_flags[i], 0, 4); memset(dev->track_in_file[i], 0, 2); memset(dev->calculated_gap3_lengths[i], 0, 2); - for (j = 0; j < 2; j++) + for (uint8_t j = 0; j < 2; j++) memset(dev->sects[i][j], 0, sizeof(td0_sector_t)); } - if (dev->f != NULL) - fclose(dev->f); + if (dev->fp != NULL) + fclose(dev->fp); /* Release resources. */ free(dev); diff --git a/src/floppy/fdi2raw.c b/src/floppy/fdi2raw.c index 810293264..75c65cf25 100644 --- a/src/floppy/fdi2raw.c +++ b/src/floppy/fdi2raw.c @@ -30,17 +30,15 @@ #include #include -/* IF UAE */ -/*#include "sysconfig.h" -#include "sysdeps.h" -#include "zfile.h"*/ -/* ELSE */ #define xmalloc malloc #define HAVE_STDARG_H #include <86box/86box.h> #include +#include <86box/plat_unused.h> +#ifdef DEBUG #undef DEBUG +#endif #define VERBOSE #undef VERBOSE @@ -69,7 +67,8 @@ datalog(uint8_t *src, int len) { static char buf[1000]; static int offset; - int i = 0, offset2; + int i = 0; + int offset2; offset2 = offset; buf[offset++] = '\''; @@ -99,24 +98,24 @@ static int fdi_allocated; #ifdef DEBUG static void -fdi_free(void *p) +fdi_free(void *priv) { int size; - if (!p) + if (!priv) return; - size = ((int *) p)[-1]; + size = ((int *) priv)[-1]; fdi_allocated -= size; write_log("%d freed (%d)\n", size, fdi_allocated); - free((int *) p - 1); + free((int *) priv - 1); } static void * fdi_malloc(int size) { - void *p = xmalloc(size + sizeof(int)); - ((int *) p)[0] = size; + void *priv = xmalloc(size + sizeof(int)); + ((int *) prv)[0] = size; fdi_allocated += size; write_log("%d allocated (%d)\n", size, fdi_allocated); - return (int *) p + 1; + return (int *) priv + 1; } #else # define fdi_free free @@ -188,7 +187,8 @@ struct node { }; typedef struct node NODE; -static uint8_t temp, temp2; +static uint8_t temp; +static uint8_t temp2; static uint8_t * expand_tree(uint8_t *stream, NODE *node) @@ -280,8 +280,9 @@ sign_extend8(uint32_t v) static void fdi_decode(uint8_t *stream, int size, uint8_t *out) { - int i; - uint8_t sign_extend, sixteen_bit, sub_stream_shift; + uint8_t sign_extend; + uint8_t sixteen_bit; + uint8_t sub_stream_shift; NODE root; NODE *current_node; @@ -310,7 +311,7 @@ fdi_decode(uint8_t *stream, int size, uint8_t *out) /* sub-stream data decode */ temp2 = 0; - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { uint32_t v; uint8_t decode = 1; current_node = &root; @@ -358,7 +359,7 @@ decode_raw_track(FDI *fdi) /* unknown track */ static void -zxx(FDI *fdi) +zxx(UNUSED(FDI *fdi)) { fdi2raw_log("track %d: unknown track type 0x%02.2X\n", fdi->current_track, fdi->track_type); } @@ -371,7 +372,7 @@ static void zyy (FDI *fdi) #endif /* empty track */ static void -track_empty(FDI *fdi) +track_empty(UNUSED(FDI *fdi)) { return; } @@ -462,8 +463,7 @@ bit_dedrop(FDI *fdi) static void byte_add(FDI *fdi, uint8_t v) { - int i; - for (i = 7; i >= 0; i--) + for (int8_t i = 7; i >= 0; i--) bit_add(fdi, v & (1 << i)); } /* add one word */ @@ -477,24 +477,21 @@ word_add(FDI *fdi, uint16_t v) static void byte_mfm_add(FDI *fdi, uint8_t v) { - int i; - for (i = 7; i >= 0; i--) + for (int8_t i = 7; i >= 0; i--) bit_mfm_add(fdi, v & (1 << i)); } /* add multiple bytes and mfm encode them */ static void bytes_mfm_add(FDI *fdi, uint8_t v, int len) { - int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) byte_mfm_add(fdi, v); } /* add one mfm encoded word and re-mfm encode it */ static void word_post_mfm_add(FDI *fdi, uint16_t v) { - int i; - for (i = 14; i >= 0; i -= 2) + for (int8_t i = 14; i >= 0; i -= 2) bit_mfm_add(fdi, v & (1 << i)); } @@ -557,7 +554,8 @@ s09(FDI *fdi) static void s0a(FDI *fdi) { - int i, bits = (fdi->track_src[0] << 8) | fdi->track_src[1]; + int i; + int bits = (fdi->track_src[0] << 8) | fdi->track_src[1]; uint8_t b; fdi->track_src += 2; fdi2raw_log("s0a:bits=%d,data=%s", bits, datalog(fdi->track_src, (bits + 7) / 8)); @@ -578,7 +576,8 @@ s0a(FDI *fdi) static void s0b(FDI *fdi) { - int i, bits = ((fdi->track_src[0] << 8) | fdi->track_src[1]) + 65536; + int i; + int bits = ((fdi->track_src[0] << 8) | fdi->track_src[1]) + 65536; uint8_t b; fdi->track_src += 2; fdi2raw_log("s0b:bits=%d,data=%s", bits, datalog(fdi->track_src, (bits + 7) / 8)); @@ -599,7 +598,8 @@ s0b(FDI *fdi) static void s0c(FDI *fdi) { - int i, bits = (fdi->track_src[0] << 8) | fdi->track_src[1]; + int i; + int bits = (fdi->track_src[0] << 8) | fdi->track_src[1]; uint8_t b; fdi->track_src += 2; bit_drop_next(fdi); @@ -621,7 +621,8 @@ s0c(FDI *fdi) static void s0d(FDI *fdi) { - int i, bits = ((fdi->track_src[0] << 8) | fdi->track_src[1]) + 65536; + int i; + int bits = ((fdi->track_src[0] << 8) | fdi->track_src[1]) + 65536; uint8_t b; fdi->track_src += 2; bit_drop_next(fdi); @@ -645,8 +646,9 @@ s0d(FDI *fdi) /* ***** */ /* just for testing integrity of Amiga sectors */ - -/*static void rotateonebit (uint8_t *start, uint8_t *end, int shift) +#if 0 +static void +rotateonebit (uint8_t *start, uint8_t *end, int shift) { if (shift == 0) return; @@ -655,9 +657,10 @@ s0d(FDI *fdi) start[0] |= start[1] >> (8 - shift); start++; } -}*/ +} -/*static uint16_t getmfmword (uint8_t *mbuf) +static uint16_t +getmfmword (uint8_t *mbuf) { uint32_t v; @@ -668,13 +671,15 @@ s0d(FDI *fdi) v |= mbuf[2]; v >>= check_offset; return (uint16_t)v; -}*/ +} #define MFMMASK 0x55555555 -/*static uint32_t getmfmlong (uint8_t * mbuf) +static uint32_t +getmfmlong (uint8_t * mbuf) { return ((getmfmword (mbuf) << 16) | getmfmword (mbuf + 2)) & MFMMASK; -}*/ +} +#endif #if 0 static int amiga_check_track (FDI *fdi) @@ -854,10 +859,11 @@ static void amiga_data(FDI *fdi, uint8_t *secbuf) { uint16_t mfmbuf[4 + 512]; - uint32_t dodd, deven, dck; - int i; + uint32_t dodd; + uint32_t deven; + uint32_t dck; - for (i = 0; i < 512; i += 4) { + for (uint16_t i = 0; i < 512; i += 4) { deven = ((secbuf[i + 0] << 24) | (secbuf[i + 1] << 16) | (secbuf[i + 2] << 8) | (secbuf[i + 3])); dodd = deven >> 1; @@ -869,7 +875,7 @@ amiga_data(FDI *fdi, uint8_t *secbuf) mfmbuf[(i >> 1) + 256 + 5] = (uint16_t) deven; } dck = 0; - for (i = 4; i < 4 + 512; i += 2) + for (uint32_t i = 4; i < 4 + 512; i += 2) dck ^= (mfmbuf[i] << 16) | mfmbuf[i + 1]; deven = dodd = dck; dodd >>= 1; @@ -880,17 +886,19 @@ amiga_data(FDI *fdi, uint8_t *secbuf) mfmbuf[2] = (uint16_t) (deven >> 16); mfmbuf[3] = (uint16_t) deven; - for (i = 0; i < 4 + 512; i++) + for (uint32_t i = 0; i < 4 + 512; i++) word_post_mfm_add(fdi, mfmbuf[i]); } static void amiga_sector_header(FDI *fdi, uint8_t *header, uint8_t *data, int sector, int untilgap) { - uint8_t headerbuf[4], databuf[16]; - uint32_t deven, dodd, hck; + uint8_t headerbuf[4]; + uint8_t databuf[16]; + uint32_t deven; + uint32_t dodd; + uint32_t hck; uint16_t mfmbuf[24]; - int i; byte_mfm_add(fdi, 0); byte_mfm_add(fdi, 0); @@ -918,7 +926,7 @@ amiga_sector_header(FDI *fdi, uint8_t *header, uint8_t *data, int sector, int un mfmbuf[1] = (uint16_t) dodd; mfmbuf[2] = (uint16_t) (deven >> 16); mfmbuf[3] = (uint16_t) deven; - for (i = 0; i < 16; i += 4) { + for (uint8_t i = 0; i < 16; i += 4) { deven = ((databuf[i] << 24) | (databuf[i + 1] << 16) | (databuf[i + 2] << 8) | (databuf[i + 3])); dodd = deven >> 1; @@ -930,7 +938,7 @@ amiga_sector_header(FDI *fdi, uint8_t *header, uint8_t *data, int sector, int un mfmbuf[(i >> 1) + 8 + 5] = (uint16_t) deven; } hck = 0; - for (i = 0; i < 4 + 16; i += 2) + for (uint32_t i = 0; i < 4 + 16; i += 2) hck ^= (mfmbuf[i] << 16) | mfmbuf[i + 1]; deven = dodd = hck; dodd >>= 1; @@ -941,7 +949,7 @@ amiga_sector_header(FDI *fdi, uint8_t *header, uint8_t *data, int sector, int un mfmbuf[22] = (uint16_t) (deven >> 16); mfmbuf[23] = (uint16_t) deven; - for (i = 0; i < 4 + 16 + 4; i++) + for (uint32_t i = 0; i < 4 + 16 + 4; i++) word_post_mfm_add(fdi, mfmbuf[i]); } @@ -1025,11 +1033,10 @@ static uint16_t ibm_crc(uint8_t byte, int reset) { static uint16_t crc; - int i; if (reset) crc = 0xcdb4; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { if (crc & 0x8000) { crc <<= 1; if (!(byte & 0x80)) @@ -1047,7 +1054,6 @@ ibm_crc(uint8_t byte, int reset) static void ibm_data(FDI *fdi, uint8_t *data, uint8_t *crc, int len) { - int i; uint8_t crcbuf[2]; uint16_t crcv = 0; @@ -1056,7 +1062,7 @@ ibm_data(FDI *fdi, uint8_t *data, uint8_t *crc, int len) word_add(fdi, 0x4489); byte_mfm_add(fdi, 0xfb); ibm_crc(0xfb, 1); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { byte_mfm_add(fdi, data[i]); crcv = ibm_crc(data[i], 0); } @@ -1075,7 +1081,6 @@ ibm_sector_header(FDI *fdi, uint8_t *data, uint8_t *crc, int secnum, int pre) uint8_t secbuf[5]; uint8_t crcbuf[2]; uint16_t crcv; - int i; if (pre) bytes_mfm_add(fdi, 0, 12); @@ -1103,7 +1108,7 @@ ibm_sector_header(FDI *fdi, uint8_t *data, uint8_t *crc, int secnum, int pre) crcbuf[1] = (uint8_t) crcv; } /* data */ - for (i = 0; i < 5; i++) + for (uint8_t i = 0; i < 5; i++) byte_mfm_add(fdi, secbuf[i]); /* crc */ byte_mfm_add(fdi, crcbuf[0]); @@ -1235,7 +1240,7 @@ s1d(FDI *fdi) /* end marker */ static void -sff(FDI *fdi) +sff(UNUSED(FDI *fdi)) { } @@ -1263,11 +1268,9 @@ static decode_described_track_func decode_sectors_described_track[] = { static void track_amiga(struct fdi *fdi, int first_sector, int max_sector) { - int i; - bit_add(fdi, 0); bit_drop_next(fdi); - for (i = 0; i < max_sector; i++) { + for (int i = 0; i < max_sector; i++) { amiga_sector_header(fdi, 0, 0, first_sector, max_sector - i); amiga_data(fdi, fdi->track_src + first_sector * 512); first_sector++; @@ -1279,7 +1282,7 @@ track_amiga(struct fdi *fdi, int first_sector, int max_sector) static void track_atari_st(struct fdi *fdi, int max_sector) { - int i, gap3 = 0; + int gap3 = 0; uint8_t *p = fdi->track_src; switch (max_sector) { @@ -1289,9 +1292,12 @@ track_atari_st(struct fdi *fdi, int max_sector) case 10: gap3 = 24; break; + + default: + break; } s15(fdi); - for (i = 0; i < max_sector; i++) { + for (int i = 0; i < max_sector; i++) { byte_mfm_add(fdi, 0x4e); byte_mfm_add(fdi, 0x4e); ibm_sector_header(fdi, 0, 0, fdi->current_track, 1); @@ -1304,7 +1310,7 @@ track_atari_st(struct fdi *fdi, int max_sector) static void track_pc(struct fdi *fdi, int max_sector) { - int i, gap3; + int gap3; uint8_t *p = fdi->track_src; switch (max_sector) { @@ -1319,7 +1325,7 @@ track_pc(struct fdi *fdi, int max_sector) break; } s11(fdi); - for (i = 0; i < max_sector; i++) { + for (int i = 0; i < max_sector; i++) { byte_mfm_add(fdi, 0x4e); byte_mfm_add(fdi, 0x4e); ibm_sector_header(fdi, 0, 0, fdi->current_track, 1); @@ -1402,9 +1408,15 @@ static decode_normal_track_func decode_normal_track[] = { static void fix_mfm_sync(FDI *fdi) { - int i, pos, off1, off2, off3, mask1, mask2, mask3; + int pos; + int off1; + int off2; + int off3; + int mask1; + int mask2; + int mask3; - for (i = 0; i < fdi->mfmsync_offset; i++) { + for (int i = 0; i < fdi->mfmsync_offset; i++) { pos = fdi->mfmsync_buffer[i]; off1 = (pos - 1) >> 3; off2 = (pos + 1) >> 3; @@ -1464,7 +1476,7 @@ fdi_decompress(int pulses, uint8_t *sizep, uint8_t *src, int *dofree) uint32_t *dst2; int len = size & 0x3fffff; uint8_t *dst; - int mode = size >> 22, i; + int mode = size >> 22; *dofree = 0; if (mode == 0 && pulses * 2 > len) @@ -1472,7 +1484,7 @@ fdi_decompress(int pulses, uint8_t *sizep, uint8_t *src, int *dofree) if (mode == 0) { dst2 = (uint32_t *) src; dst = src; - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { *dst2++ = get_u32(src); src += 4; } @@ -1487,7 +1499,7 @@ fdi_decompress(int pulses, uint8_t *sizep, uint8_t *src, int *dofree) } static void -dumpstream(int track, uint8_t *stream, int len) +dumpstream(UNUSED(int track), UNUSED(uint8_t *stream), UNUSED(int len)) { #if 0 char name[100]; @@ -1526,9 +1538,7 @@ static int totaldiv; static void init_array(uint32_t standard_MFM_2_bit_cell_size, int nb_of_bits) { - int i; - - for (i = 0; i < FDI_MAX_ARRAY; i++) { + for (uint8_t i = 0; i < FDI_MAX_ARRAY; i++) { psarray[i].size = standard_MFM_2_bit_cell_size; /* That is (total track length / 50000) for Amiga double density */ total += psarray[i].size; psarray[i].number_of_bits = nb_of_bits; @@ -1672,11 +1682,18 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ uint32_t adjusted_pulse; uint32_t standard_MFM_2_bit_cell_size = totalavg / 50000; uint32_t standard_MFM_8_bit_cell_size = totalavg / 12500; - int real_size, i, j, nexti, eodat, outstep, randval; + int real_size; + int i; + int j; + int nexti; + int eodat; + int outstep; + int randval; int indexoffset = *indexoffsetp; uint8_t *d = fdi->track_dst_buffer; uint16_t *pt = fdi->track_dst_buffer_timing; - uint32_t ref_pulse, pulse; + uint32_t ref_pulse; + uint32_t pulse; int32_t jitter; /* detects a long-enough stable pulse coming just after another stable pulse */ @@ -1702,7 +1719,9 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ /* calculates the current average bitrate from previous decoded data */ uint32_t avg_size = (uint32_t) ((total << (2 + mfm)) / totaldiv); /* this is the new average size for one MFM bit */ - /* uint32_t avg_size = (uint32_t)((((float)total)*((float)(mfm+1))*4.0) / ((float)totaldiv)); */ +#if 0 + uint32_t avg_size = (uint32_t)((((float)total)*((float)(mfm+1))*4.0) / ((float)totaldiv)); +#endif /* you can try tighter ranges than 25%, or wider ranges. I would probably go for tighter... */ if ((avg_size < (standard_MFM_8_bit_cell_size - (pulse_limitval * standard_MFM_8_bit_cell_size / 100))) || (avg_size > (standard_MFM_8_bit_cell_size + (pulse_limitval * standard_MFM_8_bit_cell_size / 100)))) { avg_size = standard_MFM_8_bit_cell_size; @@ -1714,7 +1733,9 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ /* gets the next long-enough pulse (this may require more than one pulse) */ pulse = 0; while (pulse < ((avg_size / 4) - (avg_size / 16))) { - uint32_t avg_pulse, min_pulse, max_pulse; + uint32_t avg_pulse; + uint32_t min_pulse; + uint32_t max_pulse; i++; if (i >= pulses) i = 0; @@ -1742,7 +1763,7 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ randval = rand(); if (randval < (RAND_MAX / 2)) { if (randval > (RAND_MAX / 4)) { - if (randval <= (((3LL * (uint64_t) RAND_MAX) / 8))) + if (randval <= ((3LL * (uint64_t) RAND_MAX) / 8)) randval = (2 * randval) - (RAND_MAX / 4); else randval = (4 * randval) - RAND_MAX; @@ -1751,7 +1772,7 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ } else { randval -= RAND_MAX / 2; if (randval > (RAND_MAX / 4)) { - if (randval <= (((3LL * (uint64_t) RAND_MAX) / 8))) + if (randval <= ((3LL * (uint64_t) RAND_MAX) / 8)) randval = (2 * randval) - (RAND_MAX / 4); else randval = (4 * randval) - RAND_MAX; @@ -1777,7 +1798,7 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ randval = rand(); if (randval < (RAND_MAX / 2)) { if (randval > (RAND_MAX / 4)) { - if (randval <= (((3LL * (uint64_t) RAND_MAX) / 8))) + if (randval <= ((3LL * (uint64_t) RAND_MAX) / 8)) randval = (2 * randval) - (RAND_MAX / 4); else randval = (4 * randval) - RAND_MAX; @@ -1786,7 +1807,7 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ } else { randval -= RAND_MAX / 2; if (randval > (RAND_MAX / 4)) { - if (randval <= (((3LL * (uint64_t) RAND_MAX) / 8))) + if (randval <= ((3LL * (uint64_t) RAND_MAX) / 8)) randval = (2 * randval) - (RAND_MAX / 4); else randval = (4 * randval) - RAND_MAX; @@ -1899,14 +1920,14 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ static void fdi2_celltiming(FDI *fdi, uint32_t totalavg, int bitoffset, uint16_t *out) { - uint16_t *pt2, *pt; - double avg_bit_len; - int i; + const uint16_t *pt2; + uint16_t *pt; + double avg_bit_len; avg_bit_len = (double) totalavg / (double) bitoffset; pt2 = fdi->track_dst_buffer_timing; pt = out; - for (i = 0; i < bitoffset / 8; i++) { + for (int i = 0; i < bitoffset / 8; i++) { double v = (pt2[0] + pt2[1] + pt2[2] + pt2[3] + pt2[4] + pt2[5] + pt2[6] + pt2[7]) / 8.0; v = 1000.0 * v / avg_bit_len; *pt++ = (uint16_t) v; @@ -1919,14 +1940,27 @@ fdi2_celltiming(FDI *fdi, uint32_t totalavg, int bitoffset, uint16_t *out) static int decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) { - uint8_t *p1; - uint32_t *p2; - uint32_t *avgp, *minp = 0, *maxp = 0; - uint8_t *idxp = 0; - uint32_t maxidx, totalavg, weakbits; - int i, j, len, pulses, indexoffset; - int avg_free, min_free = 0, max_free = 0, idx_free; - int idx_off1 = 0, idx_off2 = 0, idx_off3 = 0; + uint8_t *p1; + const uint32_t *p2; + uint32_t *avgp; + uint32_t *minp = 0; + uint32_t *maxp = 0; + uint8_t *idxp = 0; + uint32_t maxidx; + uint32_t totalavg; + uint32_t weakbits; + int j; + int k; + int len; + int pulses; + int indexoffset; + int avg_free; + int min_free = 0; + int max_free = 0; + int idx_free; + int idx_off1 = 0; + int idx_off2 = 0; + int idx_off3 = 0; p1 = fdi->track_src; pulses = get_u32(p1); @@ -1945,7 +1979,7 @@ decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) maxp = (uint32_t *) fdi_decompress(pulses, p1 + 6, p1 + len, &max_free); len += get_u24(p1 + 6) & 0x3fffff; /* Computes the real min and max values */ - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { maxp[i] = avgp[i] + minp[i] - maxp[i]; minp[i] = avgp[i] - minp[i]; } @@ -1971,7 +2005,7 @@ decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) } else { idxp = fdi_malloc(pulses * 2); idx_free = 1; - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { idxp[i * 2 + 0] = 2; idxp[i * 2 + 1] = 0; } @@ -1982,43 +2016,43 @@ decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) maxidx = 0; indexoffset = 0; p1 = idxp; - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { if ((uint32_t) p1[idx_off1] + (uint32_t) p1[idx_off2] > maxidx) maxidx = p1[idx_off1] + p1[idx_off2]; p1 += idx_off3; } p1 = idxp; - for (i = 0; (i < pulses) && (p1[idx_off2] != 0); i++) /* falling edge, replace with idx_off1 for rising edge */ + for (k = 0; (k < pulses) && (p1[idx_off2] != 0); k++) /* falling edge, replace with idx_off1 for rising edge */ p1 += idx_off3; - if (i < pulses) { - j = i; + if (k < pulses) { + j = k; do { - i++; + k++; p1 += idx_off3; - if (i >= pulses) { - i = 0; + if (k >= pulses) { + k = 0; p1 = idxp; } - } while ((i != j) && (p1[idx_off2] == 0)); /* falling edge, replace with idx_off1 for rising edge */ - if (i != j) /* index pulse detected */ + } while ((k != j) && (p1[idx_off2] == 0)); /* falling edge, replace with idx_off1 for rising edge */ + if (k != j) /* index pulse detected */ { - while ((i != j) && (p1[idx_off1] > p1[idx_off2])) { /* falling edge, replace with "<" for rising edge */ - i++; + while ((k != j) && (p1[idx_off1] > p1[idx_off2])) { /* falling edge, replace with "<" for rising edge */ + k++; p1 += idx_off3; - if (i >= pulses) { - i = 0; + if (k >= pulses) { + k = 0; p1 = idxp; } } - if (i != j) - indexoffset = i; /* index position detected */ + if (k != j) + indexoffset = k; /* index position detected */ } } p1 = idxp; p2 = avgp; totalavg = 0; weakbits = 0; - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { uint32_t sum = p1[idx_off1] + p1[idx_off2]; if (sum >= maxidx) { totalavg += *p2; @@ -2030,8 +2064,10 @@ decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) idxp[i] = sum; } len = totalavg / 100000; - /* fdi2raw_log("totalavg=%u index=%d (%d) maxidx=%d weakbits=%d len=%d\n", - totalavg, indexoffset, maxidx, weakbits, len); */ +#if 0 + fdi2raw_log("totalavg=%u index=%d (%d) maxidx=%d weakbits=%d len=%d\n", + totalavg, indexoffset, maxidx, weakbits, len); +#endif cache->avgp = avgp; cache->idxp = idxp; cache->minp = minp; @@ -2056,13 +2092,11 @@ static int bit_rate_table[16] = { 125, 150, 250, 300, 500, 1000 }; void fdi2raw_header_free(FDI *fdi) { - int i; - fdi_free(fdi->mfmsync_buffer); fdi_free(fdi->track_src_buffer); fdi_free(fdi->track_dst_buffer); fdi_free(fdi->track_dst_buffer_timing); - for (i = 0; i < MAX_TRACKS; i++) { + for (uint8_t i = 0; i < MAX_TRACKS; i++) { struct fdi_cache *c = &fdi->cache[i]; if (c->idx_free) fdi_free(c->idxp); @@ -2130,8 +2164,11 @@ fdi2raw_get_tpi(FDI *fdi) FDI * fdi2raw_header(FILE *f) { - long i, offset, oldseek; - uint8_t type, size; + long i; + long offset; + long oldseek; + uint8_t type; + uint8_t size; FDI *fdi; fdi2raw_log("ALLOC: memory allocated %d\n", fdi_allocated); @@ -2204,22 +2241,25 @@ static int fdi2raw_loadrevolution_2(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int track, int *tracklength, int *indexoffsetp, int *multirev, int mfm) { struct fdi_cache *cache = &fdi->cache[track]; - int len, i, idx; + int len; + int idx; memset(fdi->track_dst_buffer, 0, MAX_DST_BUFFER); idx = cache->indexoffset; fdi2_decode(fdi, cache->totalavg, cache->avgp, cache->minp, cache->maxp, cache->idxp, cache->maxidx, &idx, cache->pulses, mfm); - /* fdi2raw_log("track %d: nbits=%d avg len=%.2f weakbits=%d idx=%d\n", - track, bitoffset, (double)cache->totalavg / bitoffset, cache->weakbits, cache->indexoffset); */ +#if 0 + fdi2raw_log("track %d: nbits=%d avg len=%.2f weakbits=%d idx=%d\n", + track, bitoffset, (double)cache->totalavg / bitoffset, cache->weakbits, cache->indexoffset); +#endif len = fdi->out; if (cache->weakbits >= 10 && multirev) *multirev = 1; *tracklength = len; - for (i = 0; i < (len + 15) / (2 * 8); i++) { - uint8_t *data = fdi->track_dst_buffer + i * 2; + for (int i = 0; i < (len + 15) / (2 * 8); i++) { + const uint8_t *data = fdi->track_dst_buffer + i * 2; *mfmbuf++ = 256 * *data + *(data + 1); } fdi2_celltiming(fdi, cache->totalavg, len, tracktiming); @@ -2238,8 +2278,8 @@ fdi2raw_loadrevolution(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int tr int fdi2raw_loadtrack(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int track, int *tracklength, int *indexoffsetp, int *multirev, int mfm) { - uint8_t *p; - int outlen, i; + const uint8_t *p; + int outlen; struct fdi_cache *cache = &fdi->cache[track]; track ^= fdi->reversed_side; @@ -2270,8 +2310,10 @@ fdi2raw_loadtrack(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int track, else fdi->bit_rate = 250; - /* fdi2raw_log("track %d: srclen: %d track_type: %02.2X, bitrate: %d\n", - fdi->current_track, fdi->track_src_len, fdi->track_type, fdi->bit_rate); */ +#if 0 + fdi2raw_log("track %d: srclen: %d track_type: %02.2X, bitrate: %d\n", + fdi->current_track, fdi->track_src_len, fdi->track_type, fdi->bit_rate); +#endif if ((fdi->track_type & 0xc0) == 0x80) { @@ -2285,7 +2327,7 @@ fdi2raw_loadtrack(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int track, outlen = handle_sectors_described_track(fdi); - } else if ((fdi->track_type & 0xf0)) { + } else if (fdi->track_type & 0xf0) { zxx(fdi); outlen = -1; @@ -2309,9 +2351,9 @@ fdi2raw_loadtrack(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int track, if (cache->lowlevel) return fdi2raw_loadrevolution_2(fdi, mfmbuf, tracktiming, track, tracklength, indexoffsetp, multirev, mfm); *tracklength = fdi->out; - for (i = 0; i < ((*tracklength) + 15) / (2 * 8); i++) { - uint8_t *data = fdi->track_dst_buffer + i * 2; - *mfmbuf++ = 256 * *data + *(data + 1); + for (int i = 0; i < ((*tracklength) + 15) / (2 * 8); i++) { + const uint8_t *data = fdi->track_dst_buffer + i * 2; + *mfmbuf++ = 256 * *data + *(data + 1); } } return outlen; diff --git a/src/game/gameport.c b/src/game/gameport.c index f3557d158..413a1ff5a 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -35,8 +35,9 @@ #include <86box/joystick_standard.h> #include <86box/joystick_sw_pad.h> #include <86box/joystick_tm_fcs.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct g_axis_t { pc_timer_t timer; int axis_nr; struct _joystick_instance_ *joystick; @@ -115,9 +116,10 @@ static uint8_t gameport_pnp_rom[] = { }; static const isapnp_device_config_t gameport_pnp_defaults[] = { {.activate = 1, - .io = { - { .base = 0x200 }, - }} + .io = { + { .base = 0x200 }, + } + } }; const device_t *standalone_gameport_type; @@ -214,7 +216,7 @@ gameport_time(joystick_instance_t *joystick, int nr, int axis) } static void -gameport_write(uint16_t addr, uint8_t val, void *priv) +gameport_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), void *priv) { gameport_t *dev = (gameport_t *) priv; joystick_instance_t *joystick = dev->joystick; @@ -238,7 +240,7 @@ gameport_write(uint16_t addr, uint8_t val, void *priv) } static uint8_t -gameport_read(uint16_t addr, void *priv) +gameport_read(UNUSED(uint16_t addr), void *priv) { gameport_t *dev = (gameport_t *) priv; joystick_instance_t *joystick = dev->joystick; @@ -285,7 +287,8 @@ gameport_update_joystick_type(void) void gameport_remap(void *priv, uint16_t address) { - gameport_t *dev = (gameport_t *) priv, *other_dev; + gameport_t *dev = (gameport_t *) priv; + gameport_t *other_dev; if (dev->addr) { /* Remove this port from the active ports list. */ @@ -399,7 +402,7 @@ gameport_init(const device_t *info) } static void * -tmacm_init(const device_t *info) +tmacm_init(UNUSED(const device_t *info)) { uint16_t port = 0x0000; gameport_t *dev = NULL; @@ -427,16 +430,16 @@ tmacm_init(const device_t *info) port = device_get_config_hex16("port2_addr"); switch (port) { - case 0x201: + case 0x209: dev = gameport_add(&gameport_209_device); break; - case 0x203: + case 0x20b: dev = gameport_add(&gameport_20b_device); break; - case 0x205: + case 0x20d: dev = gameport_add(&gameport_20d_device); break; - case 0x207: + case 0x20f: dev = gameport_add(&gameport_20f_device); break; default: diff --git a/src/game/joystick_ch_flightstick_pro.c b/src/game/joystick_ch_flightstick_pro.c index f5785d6f4..49ce824bc 100644 --- a/src/game/joystick_ch_flightstick_pro.c +++ b/src/game/joystick_ch_flightstick_pro.c @@ -44,6 +44,7 @@ #include <86box/timer.h> #include <86box/gameport.h> #include <86box/joystick_standard.h> +#include <86box/plat_unused.h> static void * ch_flightstick_pro_init(void) @@ -52,12 +53,13 @@ ch_flightstick_pro_init(void) } static void -ch_flightstick_pro_close(void *p) +ch_flightstick_pro_close(UNUSED(void *priv)) { + // } static uint8_t -ch_flightstick_pro_read(void *p) +ch_flightstick_pro_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; @@ -86,12 +88,13 @@ ch_flightstick_pro_read(void *p) } static void -ch_flightstick_pro_write(void *p) +ch_flightstick_pro_write(UNUSED(void *priv)) { + // } static int -ch_flightstick_pro_read_axis(void *p, int axis) +ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -111,8 +114,9 @@ ch_flightstick_pro_read_axis(void *p, int axis) } static void -ch_flightstick_pro_a0_over(void *p) +ch_flightstick_pro_a0_over(UNUSED(void *priv)) { + // } const joystick_if_t joystick_ch_flightstick_pro = { diff --git a/src/game/joystick_standard.c b/src/game/joystick_standard.c index 55a28acee..b9c449f99 100644 --- a/src/game/joystick_standard.c +++ b/src/game/joystick_standard.c @@ -44,6 +44,7 @@ #include <86box/timer.h> #include <86box/gameport.h> #include <86box/joystick_standard.h> +#include <86box/plat_unused.h> static void * joystick_standard_init(void) @@ -52,12 +53,13 @@ joystick_standard_init(void) } static void -joystick_standard_close(void *p) +joystick_standard_close(UNUSED(void *priv)) { + // } static uint8_t -joystick_standard_read(void *p) +joystick_standard_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; @@ -78,7 +80,7 @@ joystick_standard_read(void *p) } static uint8_t -joystick_standard_read_4button(void *p) +joystick_standard_read_4button(UNUSED(void *priv)) { uint8_t ret = 0xf0; @@ -97,12 +99,13 @@ joystick_standard_read_4button(void *p) } static void -joystick_standard_write(void *p) +joystick_standard_write(UNUSED(void *priv)) { + // } static int -joystick_standard_read_axis(void *p, int axis) +joystick_standard_read_axis(UNUSED(void *priv), int axis) { switch (axis) { case 0: @@ -127,7 +130,7 @@ joystick_standard_read_axis(void *p, int axis) } static int -joystick_standard_read_axis_4button(void *p, int axis) +joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -147,7 +150,7 @@ joystick_standard_read_axis_4button(void *p, int axis) } static int -joystick_standard_read_axis_3axis(void *p, int axis) +joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -167,7 +170,7 @@ joystick_standard_read_axis_3axis(void *p, int axis) } static int -joystick_standard_read_axis_4axis(void *p, int axis) +joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -187,7 +190,7 @@ joystick_standard_read_axis_4axis(void *p, int axis) } static int -joystick_standard_read_axis_6button(void *p, int axis) +joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -206,7 +209,7 @@ joystick_standard_read_axis_6button(void *p, int axis) } } static int -joystick_standard_read_axis_8button(void *p, int axis) +joystick_standard_read_axis_8button(UNUSED(void *priv), int axis) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -234,8 +237,9 @@ joystick_standard_read_axis_8button(void *p, int axis) } static void -joystick_standard_a0_over(void *p) +joystick_standard_a0_over(UNUSED(void *priv)) { + // } const joystick_if_t joystick_2axis_2button = { diff --git a/src/game/joystick_sw_pad.c b/src/game/joystick_sw_pad.c index 26e26474b..5c91ee1e9 100644 --- a/src/game/joystick_sw_pad.c +++ b/src/game/joystick_sw_pad.c @@ -65,9 +65,9 @@ #include <86box/timer.h> #include <86box/gameport.h> #include <86box/joystick_sw_pad.h> +#include <86box/plat_unused.h> -typedef struct -{ +typedef struct sw_data { pc_timer_t poll_timer; int poll_left; int poll_clock; @@ -79,9 +79,9 @@ typedef struct } sw_data; static void -sw_timer_over(void *p) +sw_timer_over(void *priv) { - sw_data *sw = (sw_data *) p; + sw_data *sw = (sw_data *) priv; sw->poll_clock = !sw->poll_clock; @@ -99,9 +99,9 @@ sw_timer_over(void *p) } static void -sw_trigger_timer_over(void *p) +sw_trigger_timer_over(void *priv) { - sw_data *sw = (sw_data *) p; + sw_data *sw = (sw_data *) priv; timer_disable(&sw->trigger_timer); } @@ -132,17 +132,17 @@ sw_init(void) } static void -sw_close(void *p) +sw_close(void *priv) { - sw_data *sw = (sw_data *) p; + sw_data *sw = (sw_data *) priv; free(sw); } static uint8_t -sw_read(void *p) +sw_read(void *priv) { - sw_data *sw = (sw_data *) p; + sw_data *sw = (sw_data *) priv; uint8_t temp = 0; if (!JOYSTICK_PRESENT(0)) @@ -166,9 +166,9 @@ sw_read(void *p) } static void -sw_write(void *p) +sw_write(void *priv) { - sw_data *sw = (sw_data *) p; + sw_data *sw = (sw_data *) priv; int64_t time_since_last = timer_get_remaining_us(&sw->trigger_timer); if (!JOYSTICK_PRESENT(0)) @@ -183,10 +183,8 @@ sw_write(void *p) if (time_since_last > 9900 && time_since_last < 9940) { sw->poll_mode = 0; sw->poll_left = 49; - sw->poll_data = 0x2400ull | (0x1830ull << 15) | (0x19b0ull << 30); + sw->poll_data = 0x2400ULL | (0x1830ULL << 15) | (0x19b0ULL << 30); } else { - int c; - sw->poll_mode = sw->data_mode; sw->data_mode = !sw->data_mode; @@ -198,9 +196,8 @@ sw_write(void *p) sw->poll_data = 1; } - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { uint16_t data = 0x3fff; - int b; if (!JOYSTICK_PRESENT(c)) break; @@ -214,7 +211,7 @@ sw_write(void *p) if (joystick_state[c].axis[0] < -16383) data &= ~8; - for (b = 0; b < 10; b++) { + for (uint8_t b = 0; b < 10; b++) { if (joystick_state[c].button[b]) data &= ~(1 << (b + 4)); } @@ -237,7 +234,7 @@ sw_write(void *p) } static int -sw_read_axis(void *p, int axis) +sw_read_axis(UNUSED(void *priv), UNUSED(int axis)) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -246,9 +243,9 @@ sw_read_axis(void *p, int axis) } static void -sw_a0_over(void *p) +sw_a0_over(void *priv) { - sw_data *sw = (sw_data *) p; + sw_data *sw = (sw_data *) priv; timer_set_delay_u64(&sw->trigger_timer, TIMER_USEC * 10000); } diff --git a/src/game/joystick_tm_fcs.c b/src/game/joystick_tm_fcs.c index 7bcb15742..d54d0e37d 100644 --- a/src/game/joystick_tm_fcs.c +++ b/src/game/joystick_tm_fcs.c @@ -44,6 +44,7 @@ #include <86box/timer.h> #include <86box/gameport.h> #include <86box/joystick_standard.h> +#include <86box/plat_unused.h> static void * tm_fcs_init(void) @@ -52,12 +53,13 @@ tm_fcs_init(void) } static void -tm_fcs_close(void *p) +tm_fcs_close(UNUSED(void *priv)) { + // } static uint8_t -tm_fcs_read(void *p) +tm_fcs_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; @@ -76,12 +78,13 @@ tm_fcs_read(void *p) } static void -tm_fcs_write(void *p) +tm_fcs_write(UNUSED(void *priv)) { + // } static int -tm_fcs_read_axis(void *p, int axis) +tm_fcs_read_axis(UNUSED(void *priv), int axis) { if (!JOYSTICK_PRESENT(0)) return AXIS_NOT_PRESENT; @@ -111,8 +114,9 @@ tm_fcs_read_axis(void *p, int axis) } static void -tm_fcs_a0_over(void *p) +tm_fcs_a0_over(UNUSED(void *priv)) { + // } const joystick_if_t joystick_tm_fcs = { diff --git a/src/gdbstub.c b/src/gdbstub.c index 92aa93cf1..4fafb545e 100644 --- a/src/gdbstub.c +++ b/src/gdbstub.c @@ -120,13 +120,20 @@ typedef struct _gdbstub_client_ { int socket; struct sockaddr_in addr; - char packet[16384], response[16384]; - int has_packet : 1, first_packet_received : 1, ida_mode : 1, waiting_stop : 1, - packet_pos, response_pos; + char packet[16384], response[16384]; + uint8_t has_packet : 1; + uint8_t first_packet_received : 1; + uint8_t ida_mode : 1; + uint8_t waiting_stop : 1; + int packet_pos; + int response_pos; - event_t *processed_event, *response_event; + event_t *processed_event; + event_t *response_event; - uint16_t last_io_base, last_io_len, last_io_value; + uint16_t last_io_base; + uint16_t last_io_len; + uint16_t last_io_value; struct _gdbstub_client_ *next; } gdbstub_client_t; @@ -322,18 +329,25 @@ static char target_xml[] = /* QEMU gdb-xml/i386-32bit.xml with modificati #ifdef _WIN32 static WSADATA wsa; #endif -static int gdbstub_socket = -1, stop_reason_len = 0, in_gdbstub = 0; +static int gdbstub_socket = -1; +static int stop_reason_len = 0; +static int in_gdbstub = 0; static uint32_t watch_addr; static char stop_reason[2048]; -static gdbstub_client_t *first_client = NULL, *last_client = NULL; +static gdbstub_client_t *first_client = NULL; +static gdbstub_client_t *last_client = NULL; static mutex_t *client_list_mutex; static void (*cpu_exec_shadow)(int cycs); -static gdbstub_breakpoint_t *first_swbreak = NULL, *first_hwbreak = NULL, - *first_rwatch = NULL, *first_wwatch = NULL, *first_awatch = NULL; +static gdbstub_breakpoint_t *first_swbreak = NULL; +static gdbstub_breakpoint_t *first_hwbreak = NULL; +static gdbstub_breakpoint_t *first_rwatch = NULL; +static gdbstub_breakpoint_t *first_wwatch = NULL; +static gdbstub_breakpoint_t *first_awatch = NULL; -int gdbstub_step = 0, gdbstub_next_asap = 0; +int gdbstub_step = 0; +int gdbstub_next_asap = 0; uint64_t gdbstub_watch_pages[(((uint32_t) -1) >> (MEM_GRANULARITY_BITS + 6)) + 1]; static void @@ -455,6 +469,9 @@ gdbstub_num_decode(char *p, int *dest, int mode) else return 0; break; + + default: + break; } p++; } @@ -470,7 +487,8 @@ gdbstub_num_decode(char *p, int *dest, int mode) static int gdbstub_client_read_word(gdbstub_client_t *client, int *dest) { - char *p = &client->packet[client->packet_pos], *q = p; + const char *p = &client->packet[client->packet_pos]; + const char *q = p; while (((*p >= '0') && (*p <= '9')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= 'a') && (*p <= 'f'))) *dest = ((*dest) << 4) | gdbstub_hex_decode(*p++); return p - q; @@ -599,7 +617,8 @@ static void gdbstub_client_respond(gdbstub_client_t *client) { /* Calculate checksum. */ - int checksum = 0, i; + int checksum = 0; + int i; for (i = 0; i < client->response_pos; i++) checksum += client->response[i]; @@ -716,12 +735,17 @@ gdbstub_client_read_reg(int index, uint8_t *buf) static void gdbstub_client_packet(gdbstub_client_t *client) { - gdbstub_breakpoint_t *breakpoint, *prev_breakpoint = NULL, **first_breakpoint = NULL; + gdbstub_breakpoint_t *breakpoint; + gdbstub_breakpoint_t *prev_breakpoint = NULL; + gdbstub_breakpoint_t **first_breakpoint = NULL; #ifdef GDBSTUB_CHECK_CHECKSUM /* msys2 gdb 11.1 transmits qSupported and H with invalid checksum... */ uint8_t rcv_checksum = 0, checksum = 0; #endif - int i, j = 0, k = 0, l; + int i; + int j = 0; + int k = 0; + int l; uint8_t buf[10] = { 0 }; char *p; @@ -1411,14 +1435,14 @@ gdbstub_cpu_exec(int cycs) /* Add register dump. */ uint8_t buf[10] = { 0 }; - int i, j, k; - for (i = 0; i < GDB_REG_MAX; i++) { + int j; + for (int i = 0; i < GDB_REG_MAX; i++) { if (i >= 0x10) stop_reason[stop_reason_len++] = gdbstub_hex_encode(i >> 4); stop_reason[stop_reason_len++] = gdbstub_hex_encode(i & 0x0f); stop_reason[stop_reason_len++] = ':'; j = gdbstub_client_read_reg(i, buf); - for (k = 0; k < j; k++) { + for (int k = 0; k < j; k++) { stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] >> 4); stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] & 0x0f); } @@ -1478,7 +1502,6 @@ gdbstub_client_thread(void *priv) gdbstub_client_t *client = (gdbstub_client_t *) priv; uint8_t buf[256]; ssize_t bytes_read; - int i; gdbstub_log("GDB Stub: New connection from %s:%d\n", inet_ntoa(client->addr.sin_addr), client->addr.sin_port); @@ -1487,7 +1510,7 @@ gdbstub_client_thread(void *priv) /* Read data from client. */ while ((bytes_read = recv(client->socket, (char *) buf, sizeof(buf), 0)) > 0) { - for (i = 0; i < bytes_read; i++) { + for (ssize_t i = 0; i < bytes_read; i++) { switch (buf[i]) { case '$': /* packet start */ /* Wait for any existing packets to be processed. */ @@ -1717,7 +1740,8 @@ gdbstub_mem_access(uint32_t *addrs, int access) if (in_gdbstub) return; - int width = access & (GDBSTUB_MEM_WRITE - 1), i; + int width = access & (GDBSTUB_MEM_WRITE - 1); + int i; /* Go through the lists of watchpoints for this type of access. */ gdbstub_breakpoint_t *watchpoint = (access & GDBSTUB_MEM_WRITE) ? first_wwatch : first_rwatch; diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index b88fa24ef..2f16c92d7 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -55,6 +55,14 @@ #define BCD16(x) ((((x) / 1000) << 12) | (((x) / 100) << 8) | BCD8(x)) #define BCD32(x) ((((x) / 10000000) << 28) | (((x) / 1000000) << 24) | (((x) / 100000) << 20) | (((x) / 10000) << 16) | BCD16(x)) +#if defined(__GNUC__) || defined(__clang__) +# define UNLIKELY(x) __builtin_expect((x), 0) +# define LIKELY(x) __builtin_expect((x), 1) +#else +# define UNLIKELY(x) (x) +# define LIKELY(x) (x) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -89,51 +97,54 @@ extern uint64_t instru_run_ms; #define window_y monitor_settings[0].mon_window_y #define window_w monitor_settings[0].mon_window_w #define window_h monitor_settings[0].mon_window_h -extern int window_remember, - vid_resize, /* (C) allow resizing */ - invert_display, /* (C) invert the display */ - suppress_overscan; /* (C) suppress overscans */ +extern int window_remember; +extern int vid_resize; /* (C) allow resizing */ +extern int invert_display; /* (C) invert the display */ +extern int suppress_overscan; /* (C) suppress overscans */ extern uint32_t lang_id; /* (C) language code identifier */ extern char icon_set[256]; /* (C) iconset identifier */ extern int scale; /* (C) screen scale factor */ extern int dpi_scale; /* (C) DPI scaling of the emulated screen */ extern int vid_api; /* (C) video renderer */ -extern int vid_cga_contrast, /* (C) video */ - video_fullscreen, /* (C) video */ - video_fullscreen_first, /* (C) video */ - video_fullscreen_scale, /* (C) video */ - enable_overscan, /* (C) video */ - force_43, /* (C) video */ - video_filter_method, /* (C) video */ - video_vsync, /* (C) video */ - video_framerate, /* (C) video */ - gfxcard[2]; /* (C) graphics/video card */ +extern int vid_cga_contrast; /* (C) video */ +extern int video_fullscreen; /* (C) video */ +extern int video_fullscreen_first; /* (C) video */ +extern int video_fullscreen_scale; /* (C) video */ +extern int enable_overscan; /* (C) video */ +extern int force_43; /* (C) video */ +extern int video_filter_method; /* (C) video */ +extern int video_vsync; /* (C) video */ +extern int video_framerate; /* (C) video */ +extern int gfxcard[2]; /* (C) graphics/video card */ extern char video_shader[512]; /* (C) video */ -extern int bugger_enabled, /* (C) enable ISAbugger */ - postcard_enabled, /* (C) enable POST card */ - isamem_type[], /* (C) enable ISA mem cards */ - isartc_type; /* (C) enable ISA RTC card */ -extern int sound_is_float, /* (C) sound uses FP values */ - voodoo_enabled, /* (C) video option */ - ibm8514_enabled, /* (C) video option */ - xga_enabled; /* (C) video option */ +extern int bugger_enabled; /* (C) enable ISAbugger */ +extern int postcard_enabled; /* (C) enable POST card */ +extern int isamem_type[]; /* (C) enable ISA mem cards */ +extern int isartc_type; /* (C) enable ISA RTC card */ +extern int sound_is_float; /* (C) sound uses FP values */ +extern int voodoo_enabled; /* (C) video option */ +extern int ibm8514_enabled; /* (C) video option */ +extern int xga_enabled; /* (C) video option */ extern uint32_t mem_size; /* (C) memory size (Installed on system board) */ extern uint32_t isa_mem_size; /* (C) memory size (ISA Memory Cards) */ -extern int cpu, /* (C) cpu type */ - cpu_use_dynarec, /* (C) cpu uses/needs Dyna */ - fpu_type; /* (C) fpu type */ +extern int cpu; /* (C) cpu type */ +extern int cpu_use_dynarec; /* (C) cpu uses/needs Dyna */ +extern int fpu_type; /* (C) fpu type */ +extern int fpu_softfloat; /* (C) fpu uses softfloat */ extern int time_sync; /* (C) enable time sync */ extern int hdd_format_type; /* (C) hard disk file format */ -extern int confirm_reset, /* (C) enable reset confirmation */ - confirm_exit, /* (C) enable exit confirmation */ - confirm_save; /* (C) enable save confirmation */ +extern int confirm_reset; /* (C) enable reset confirmation */ +extern int confirm_exit; /* (C) enable exit confirmation */ +extern int confirm_save; /* (C) enable save confirmation */ extern int enable_discord; /* (C) enable Discord integration */ extern int is_pentium; /* TODO: Move back to cpu/cpu.h when it's figured out, how to remove that hack from the ET4000/W32p. */ -extern int fixed_size_x, fixed_size_y; +extern int fixed_size_x; +extern int fixed_size_y; extern double mouse_sensitivity; /* (C) Mouse sensitivity scale */ -extern double mouse_x_error, mouse_y_error; /* Mouse error accumulators */ +extern double mouse_x_error; /* Mouse error accumulator - Y */ +extern double mouse_y_error; /* Mouse error accumulator - Y */ extern int pit_mode; /* (C) force setting PIT mode */ extern int fm_driver; /* (C) select FM sound driver */ @@ -152,8 +163,8 @@ extern void pclog_ex(const char *fmt, va_list); extern void fatal_ex(const char *fmt, va_list); #endif extern void pclog_toggle_suppr(void); -extern void pclog(const char *fmt, ...); -extern void fatal(const char *fmt, ...); +extern void pclog(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +extern void fatal(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); extern void set_screen_size(int x, int y); extern void set_screen_size_monitor(int x, int y, int monitor_index); extern void reset_screen_size(void); @@ -182,12 +193,13 @@ extern uint16_t get_last_addr(void); /* This is for external subtraction of cycles; should be in cpu.c but I put it here to avoid - having to include cpu.c everywhere. */ + having to include cpu.h everywhere. */ extern void sub_cycles(int c); extern void resub_cycles(int old_cycles); extern double isa_timing; -extern int io_delay, framecountx; +extern int io_delay; +extern int framecountx; extern volatile int cpu_thread_run; diff --git a/src/include/86box/acpi.h b/src/include/86box/acpi.h index 18f40d874..11be67278 100644 --- a/src/include/86box/acpi.h +++ b/src/include/86box/acpi.h @@ -59,46 +59,79 @@ extern "C" { #define VEN_VIA 0x01106 #define VEN_VIA_596B 0x11106 -typedef struct -{ - uint8_t acpitst, auxen, auxsts, plvl2, plvl3, - smicmd, gpio_dir, - gpio_val, muxcntrl, ali_soft_smi, - timer32, smireg, - gpireg[3], gporeg[4], - extiotrapsts, extiotrapen; - uint16_t pmsts, pmen, - pmcntrl, gpsts, gpsts1, - gpen, gpen1, gpscien, - gpcntrl, gplvl, gpmux, - gpsel, gpsmien, pscntrl, - gpscists; - int smi_lock, smi_active; - uint32_t pcntrl, p2cntrl, glbsts, - devsts, glben, - glbctl, devctl, - padsts, paden, - gptren, gptimer, - gpo_val, gpi_val, - extsmi_val, pad0; +typedef struct acpi_regs_t { + uint8_t acpitst; + uint8_t auxen; + uint8_t auxsts; + uint8_t plvl2; + uint8_t plvl3; + uint8_t smicmd; + uint8_t gpio_dir; + uint8_t gpio_val; + uint8_t muxcntrl; + uint8_t ali_soft_smi; + uint8_t timer32; + uint8_t smireg; + uint8_t gpireg[3]; + uint8_t gporeg[4]; + uint8_t extiotrapsts; + uint8_t extiotrapen; + uint16_t pmsts; + uint16_t pmen; + uint16_t pmcntrl; + uint16_t gpsts; + uint16_t gpsts1; + uint16_t gpen; + uint16_t gpen1; + uint16_t gpscien; + uint16_t gpcntrl; + uint16_t gplvl; + uint16_t gpmux; + uint16_t gpsel; + uint16_t gpsmien; + uint16_t pscntrl; + uint16_t gpscists; + int smi_lock; + int smi_active; + uint32_t pcntrl; + uint32_t p2cntrl; + uint32_t glbsts; + uint32_t devsts; + uint32_t glben; + uint32_t glbctl; + uint32_t devctl; + uint32_t padsts; + uint32_t paden; + uint32_t gptren; + uint32_t gptimer; + uint32_t gpo_val; + uint32_t gpi_val; + uint32_t extsmi_val; + uint32_t pad0; } acpi_regs_t; -typedef struct -{ +typedef struct acpi_t { acpi_regs_t regs; - uint8_t gpireg2_default, pad[3], - gporeg_default[4], - suspend_types[8]; - uint16_t io_base, aux_io_base; - int vendor, - slot, irq_mode, - irq_pin, irq_line, - mirq_is_level; - pc_timer_t timer, resume_timer, pwrbtn_timer; - nvr_t *nvr; - apm_t *apm; - void *i2c, - (*trap_update)(void *priv), *trap_priv; + uint8_t gpireg2_default; + uint8_t pad[3]; + uint8_t gporeg_default[4]; + uint8_t suspend_types[8]; + uint16_t io_base; + uint16_t aux_io_base; + int vendor; + int slot; + int irq_mode; + int irq_pin; + int irq_line; + int mirq_is_level; + pc_timer_t timer; + pc_timer_t resume_timer; + pc_timer_t pwrbtn_timer; + nvr_t *nvr; + apm_t *apm; + void *i2c; + void (*trap_update)(void *priv); + void *trap_priv; } acpi_t; /* Global variables. */ diff --git a/src/include/86box/agpgart.h b/src/include/86box/agpgart.h index d73e95e86..fc2976c88 100644 --- a/src/include/86box/agpgart.h +++ b/src/include/86box/agpgart.h @@ -20,7 +20,10 @@ typedef struct agpgart_s { int aperture_enable; - uint32_t aperture_base, aperture_size, aperture_mask, gart_base; + uint32_t aperture_base; + uint32_t aperture_size; + uint32_t aperture_mask; + uint32_t gart_base; mem_mapping_t aperture_mapping; } agpgart_t; diff --git a/src/include/86box/apm.h b/src/include/86box/apm.h index 854969f3d..2d5f0f117 100644 --- a/src/include/86box/apm.h +++ b/src/include/86box/apm.h @@ -21,10 +21,10 @@ extern "C" { #endif -typedef struct -{ - uint8_t cmd, - stat, do_smi; +typedef struct apm_t { + uint8_t cmd; + uint8_t stat; + uint8_t do_smi; } apm_t; /* Global variables. */ diff --git a/src/include/86box/cassette.h b/src/include/86box/cassette.h index 6e6eb646f..3706ca632 100644 --- a/src/include/86box/cassette.h +++ b/src/include/86box/cassette.h @@ -24,7 +24,7 @@ #include -typedef struct { +typedef struct pc_cassette_t { char save; char pcm; @@ -157,9 +157,11 @@ extern pc_cassette_t *cassette; extern char cassette_fname[512]; extern char cassette_mode[512]; -extern unsigned long cassette_pos, cassette_srate; +extern unsigned long cassette_pos; +extern unsigned long cassette_srate; extern int cassette_enable; -extern int cassette_append, cassette_pcm; +extern int cassette_append; +extern int cassette_pcm; extern int cassette_ui_writeprot; extern const device_t cassette_device; diff --git a/src/include/86box/cdrom.h b/src/include/86box/cdrom.h index d2f032280..69b4e90f3 100644 --- a/src/include/86box/cdrom.h +++ b/src/include/86box/cdrom.h @@ -55,9 +55,9 @@ extern "C" { enum { CDROM_BUS_DISABLED = 0, CDROM_BUS_ATAPI = 5, - CDROM_BUS_SCSI, - CDROM_BUS_MITSUMI, - CDROM_BUS_USB + CDROM_BUS_SCSI = 6, + CDROM_BUS_MITSUMI = 7, + CDROM_BUS_USB = 8 }; #define KNOWN_CDROM_DRIVE_TYPES 35 @@ -65,71 +65,77 @@ enum { #define BUS_TYPE_IDE 1 #define BUS_TYPE_SCSI 2 -static const struct -{ - const char vendor[9]; - const char model[17]; - const char revision[5]; +static const struct { + const char vendor[9]; + const char model[17]; + const char revision[5]; const char *name; const char *internal_name; - const int bus_type; -} cdrom_drive_types[] = -{ - { "86BOX", "CD-ROM", "1.00", "(ATAPI/SCSI) 86BOX CD-ROM 1.00", "86BOX_CD-ROM_1.00", BUS_TYPE_ALL}, /*1*/ - { "AZT", "CDA46802I", "1.15", "(ATAPI) AZT CDA46802I 1.15", "AZT_CDA46802I_1.15", BUS_TYPE_IDE}, /*2*/ - { "BTC", "CD-ROM BCD36XH", "U1.0", "(ATAPI) BTC CD-ROM BCD36XH U1.0", "BTC_CD-ROM_BCD36XH_U1.0", BUS_TYPE_IDE}, /*3*/ - { "GOLDSTAR", "CRD-8160B", "3.14", "(ATAPI) GOLDSTAR CRD-8160B 3.14", "GOLDSTAR_CRD-8160B_3.14", BUS_TYPE_IDE}, /*4*/ - { "HITACHI", "CDR-8130", "0020", "(ATAPI) HITACHI CDR-8130 0020", "HITACHI_CDR-8130_0020", BUS_TYPE_IDE}, /*5*/ - { "KENWOOD", "CD-ROM UCR-421", "208E", "(ATAPI) KENWOOD CD-ROM UCR-421 208E", "KENWOOD_CD-ROM_UCR-421_208E", BUS_TYPE_IDE}, /*6*/ - { "MATSHITA", "CD-ROM CR-587", "7S13", "(ATAPI) MATSHITA CD-ROM CR-587 7S13", "MATSHITA_CD-ROM_CR-587_7S13", BUS_TYPE_IDE}, /*7*/ - { "MATSHITA", "CD-ROM CR-588", "LS15", "(ATAPI) MATSHITA CD-ROM CR-588 LS15", "MATSHITA_CD-ROM_CR-588_LS15", BUS_TYPE_IDE}, /*8*/ - { "MATSHITA", "CR-571", "1.0e", "(ATAPI) MATSHITA CR-571 1.0e", "MATSHITA_CR-571_1.0e", BUS_TYPE_IDE}, /*9*/ - { "MATSHITA", "CR-572", "1.0j", "(ATAPI) MATSHITA CR-572 1.0j", "MATSHITA_CR-572_1.0j", BUS_TYPE_IDE}, /*10*/ - { "MITSUMI", "CRMC-FX4820T", "D02A", "(ATAPI) MITSUMI CRMC-FX4820T D02A", "MITSUMI_CRMC-FX4820T_D02A", BUS_TYPE_IDE}, /*11*/ - { "NEC", "CD-ROM DRIVE:260", "1.00", "(ATAPI) NEC CD-ROM DRIVE:260 1.00", "NEC_CD-ROM_DRIVE260_1.00", BUS_TYPE_IDE}, /*12*/ - { "NEC", "CD-ROM DRIVE:260", "1.01", "(ATAPI) NEC CD-ROM DRIVE:260 1.01", "NEC_CD-ROM_DRIVE260_1.01", BUS_TYPE_IDE}, /*13*/ - { "NEC", "CD-ROM DRIVE:273", "4.20", "(ATAPI) NEC CD-ROM DRIVE:273 4.20", "NEC_CD-ROM_DRIVE273_4.20", BUS_TYPE_IDE}, /*14*/ - { "NEC", "CD-ROM DRIVE:280", "1.05", "(ATAPI) NEC CD-ROM DRIVE:280 1.05", "NEC_CD-ROM_DRIVE280_1.05", BUS_TYPE_IDE}, /*15*/ - { "NEC", "CD-ROM DRIVE:280", "3.08", "(ATAPI) NEC CD-ROM DRIVE:280 3.08", "NEC_CD-ROM_DRIVE280_3.08", BUS_TYPE_IDE}, /*16*/ - { "PHILIPS", "CD-ROM PCA403CD", "U31P", "(ATAPI) PHILIPS CD-ROM PCA403CD U31P", "PHILIPS_CD-ROM_PCA403CD_U31P", BUS_TYPE_IDE}, /*17*/ - { "SONY", "CD-ROM CDU76", "1.0i", "(ATAPI) SONY CD-ROM CDU76 1.0i", "SONY_CD-ROM_CDU76_1.0i", BUS_TYPE_IDE}, /*18*/ - { "SONY", "CD-ROM CDU311", "3.0h", "(ATAPI) SONY CD-ROM CDU311 3.0h", "SONY_CD-ROM_CDU311_3.0h", BUS_TYPE_IDE}, /*19*/ - { "TOSHIBA", "CD-ROM XM-5302TA", "0305", "(ATAPI) TOSHIBA CD-ROM XM-5302TA 0305", "TOSHIBA_CD-ROM_XM-5302TA_0305", BUS_TYPE_IDE}, /*20*/ - { "TOSHIBA", "CD-ROM XM-5702B", "TA70", "(ATAPI) TOSHIBA CD-ROM XM-5702B TA70", "TOSHIBA_CD-ROM_XM-5702B_TA70", BUS_TYPE_IDE}, /*21*/ - { "CHINON", "CD-ROM CDS-431", "H42 ", "(SCSI) CHINON CD-ROM CDS-431 H42", "CHINON_CD-ROM_CDS-431_H42", BUS_TYPE_SCSI}, /*22*/ - { "DEC", "RRD45 (C) DEC", "0436", "(SCSI) DEC RRD45 0436", "DEC_RRD45_0436", BUS_TYPE_SCSI}, /*23*/ - { "MATSHITA", "CD-ROM CR-501", "1.0b", "(SCSI) MATSHITA CD-ROM CR-501 1.0b", "MATSHITA_CD-ROM_CR-501_1.0b", BUS_TYPE_SCSI}, /*24*/ - { "NEC", "CD-ROM DRIVE:74", "1.00", "(SCSI) NEC CD-ROM DRIVE:74 1.00", "NEC_CD-ROM_DRIVE74_1.00", BUS_TYPE_SCSI}, /*25*/ - { "NEC", "CD-ROM DRIVE:464", "1.05", "(SCSI) NEC CD-ROM DRIVE:464 1.05", "NEC_CD-ROM_DRIVE464_1.05", BUS_TYPE_SCSI}, /*26*/ - { "SONY", "CD-ROM CDU-541", "1.0i", "(SCSI) SONY CD-ROM CDU-541 1.0i", "SONY_CD-ROM_CDU-541_1.0i", BUS_TYPE_SCSI}, /*27*/ - { "SONY", "CD-ROM CDU-76S", "1.00", "(SCSI) SONY CD-ROM CDU-76S 1.00", "SONY_CD-ROM_CDU-76S_1.00", BUS_TYPE_SCSI}, /*28*/ - { "PHILIPS", "CDD2600", "1.07", "(SCSI) PHILIPS CDD2600 1.07", "PHILIPS_CDD2600_1.07", BUS_TYPE_SCSI}, /*29*/ - { "PIONEER", "CD-ROM DRM-604X", "2403", "(SCSI) PIONEER CD-ROM DRM-604X 2403", "PIONEER_CD-ROM_DRM-604X_2403", BUS_TYPE_SCSI}, /*30*/ - { "PLEXTOR", "CD-ROM PX-32TS", "1.03", "(SCSI) PLEXTOR CD-ROM PX-32TS 1.03", "PLEXTOR_CD-ROM_PX-32TS_1.03", BUS_TYPE_SCSI}, /*31*/ - { "TEAC", "CD-R55S", "1.0R", "(SCSI) TEAC CD-R55S 1.0R", "TEAC_CD-R55S_1.0R", BUS_TYPE_SCSI}, /*32*/ - { "TOSHIBA", "CD-ROM DRIVE:XM", "3433", "(SCSI) TOSHIBA CD-ROM DRIVE:XM 3433", "TOSHIBA_CD-ROM_DRIVEXM_3433", BUS_TYPE_SCSI}, /*33*/ - { "TOSHIBA", "CD-ROM XM-3301TA", "0272", "(SCSI) TOSHIBA CD-ROM XM-3301TA 0272", "TOSHIBA_CD-ROM_XM-3301TA_0272", BUS_TYPE_SCSI}, /*34*/ - { "TOSHIBA", "CD-ROM XM-5701TA", "3136", "(SCSI) TOSHIBA CD-ROM XM-5701TA 3136", "TOSHIBA_CD-ROM_XM-5701TA_3136", BUS_TYPE_SCSI}, /*35*/ - { "", "", "", "", "", -1}, + const int bus_type; +} cdrom_drive_types[] = { + { "86BOX", "CD-ROM", "1.00", "(ATAPI/SCSI) 86BOX CD-ROM 1.00", "86BOX_CD-ROM_1.00", BUS_TYPE_ALL }, /*1*/ + { "AZT", "CDA46802I", "1.15", "(ATAPI) AZT CDA46802I 1.15", "AZT_CDA46802I_1.15", BUS_TYPE_IDE }, /*2*/ + { "BTC", "CD-ROM BCD36XH", "U1.0", "(ATAPI) BTC CD-ROM BCD36XH U1.0", "BTC_CD-ROM_BCD36XH_U1.0", BUS_TYPE_IDE }, /*3*/ + { "GOLDSTAR", "CRD-8160B", "3.14", "(ATAPI) GOLDSTAR CRD-8160B 3.14", "GOLDSTAR_CRD-8160B_3.14", BUS_TYPE_IDE }, /*4*/ + { "HITACHI", "CDR-8130", "0020", "(ATAPI) HITACHI CDR-8130 0020", "HITACHI_CDR-8130_0020", BUS_TYPE_IDE }, /*5*/ + { "KENWOOD", "CD-ROM UCR-421", "208E", "(ATAPI) KENWOOD CD-ROM UCR-421 208E", "KENWOOD_CD-ROM_UCR-421_208E", BUS_TYPE_IDE }, /*6*/ + { "MATSHITA", "CD-ROM CR-587", "7S13", "(ATAPI) MATSHITA CD-ROM CR-587 7S13", "MATSHITA_CD-ROM_CR-587_7S13", BUS_TYPE_IDE }, /*7*/ + { "MATSHITA", "CD-ROM CR-588", "LS15", "(ATAPI) MATSHITA CD-ROM CR-588 LS15", "MATSHITA_CD-ROM_CR-588_LS15", BUS_TYPE_IDE }, /*8*/ + { "MATSHITA", "CR-571", "1.0e", "(ATAPI) MATSHITA CR-571 1.0e", "MATSHITA_CR-571_1.0e", BUS_TYPE_IDE }, /*9*/ + { "MATSHITA", "CR-572", "1.0j", "(ATAPI) MATSHITA CR-572 1.0j", "MATSHITA_CR-572_1.0j", BUS_TYPE_IDE }, /*10*/ + { "MITSUMI", "CRMC-FX4820T", "D02A", "(ATAPI) MITSUMI CRMC-FX4820T D02A", "MITSUMI_CRMC-FX4820T_D02A", BUS_TYPE_IDE }, /*11*/ + { "NEC", "CD-ROM DRIVE:260", "1.00", "(ATAPI) NEC CD-ROM DRIVE:260 1.00", "NEC_CD-ROM_DRIVE260_1.00", BUS_TYPE_IDE }, /*12*/ + { "NEC", "CD-ROM DRIVE:260", "1.01", "(ATAPI) NEC CD-ROM DRIVE:260 1.01", "NEC_CD-ROM_DRIVE260_1.01", BUS_TYPE_IDE }, /*13*/ + { "NEC", "CD-ROM DRIVE:273", "4.20", "(ATAPI) NEC CD-ROM DRIVE:273 4.20", "NEC_CD-ROM_DRIVE273_4.20", BUS_TYPE_IDE }, /*14*/ + { "NEC", "CD-ROM DRIVE:280", "1.05", "(ATAPI) NEC CD-ROM DRIVE:280 1.05", "NEC_CD-ROM_DRIVE280_1.05", BUS_TYPE_IDE }, /*15*/ + { "NEC", "CD-ROM DRIVE:280", "3.08", "(ATAPI) NEC CD-ROM DRIVE:280 3.08", "NEC_CD-ROM_DRIVE280_3.08", BUS_TYPE_IDE }, /*16*/ + { "PHILIPS", "CD-ROM PCA403CD", "U31P", "(ATAPI) PHILIPS CD-ROM PCA403CD U31P", "PHILIPS_CD-ROM_PCA403CD_U31P", BUS_TYPE_IDE }, /*17*/ + { "SONY", "CD-ROM CDU76", "1.0i", "(ATAPI) SONY CD-ROM CDU76 1.0i", "SONY_CD-ROM_CDU76_1.0i", BUS_TYPE_IDE }, /*18*/ + { "SONY", "CD-ROM CDU311", "3.0h", "(ATAPI) SONY CD-ROM CDU311 3.0h", "SONY_CD-ROM_CDU311_3.0h", BUS_TYPE_IDE }, /*19*/ + { "TOSHIBA", "CD-ROM XM-5302TA", "0305", "(ATAPI) TOSHIBA CD-ROM XM-5302TA 0305", "TOSHIBA_CD-ROM_XM-5302TA_0305", BUS_TYPE_IDE }, /*20*/ + { "TOSHIBA", "CD-ROM XM-5702B", "TA70", "(ATAPI) TOSHIBA CD-ROM XM-5702B TA70", "TOSHIBA_CD-ROM_XM-5702B_TA70", BUS_TYPE_IDE }, /*21*/ + { "CHINON", "CD-ROM CDS-431", "H42 ", "(SCSI) CHINON CD-ROM CDS-431 H42", "CHINON_CD-ROM_CDS-431_H42", BUS_TYPE_SCSI }, /*22*/ + { "DEC", "RRD45 (C) DEC", "0436", "(SCSI) DEC RRD45 0436", "DEC_RRD45_0436", BUS_TYPE_SCSI }, /*23*/ + { "MATSHITA", "CD-ROM CR-501", "1.0b", "(SCSI) MATSHITA CD-ROM CR-501 1.0b", "MATSHITA_CD-ROM_CR-501_1.0b", BUS_TYPE_SCSI }, /*24*/ + { "NEC", "CD-ROM DRIVE:74", "1.00", "(SCSI) NEC CD-ROM DRIVE:74 1.00", "NEC_CD-ROM_DRIVE74_1.00", BUS_TYPE_SCSI }, /*25*/ + { "NEC", "CD-ROM DRIVE:464", "1.05", "(SCSI) NEC CD-ROM DRIVE:464 1.05", "NEC_CD-ROM_DRIVE464_1.05", BUS_TYPE_SCSI }, /*26*/ + { "SONY", "CD-ROM CDU-541", "1.0i", "(SCSI) SONY CD-ROM CDU-541 1.0i", "SONY_CD-ROM_CDU-541_1.0i", BUS_TYPE_SCSI }, /*27*/ + { "SONY", "CD-ROM CDU-76S", "1.00", "(SCSI) SONY CD-ROM CDU-76S 1.00", "SONY_CD-ROM_CDU-76S_1.00", BUS_TYPE_SCSI }, /*28*/ + { "PHILIPS", "CDD2600", "1.07", "(SCSI) PHILIPS CDD2600 1.07", "PHILIPS_CDD2600_1.07", BUS_TYPE_SCSI }, /*29*/ + { "PIONEER", "CD-ROM DRM-604X", "2403", "(SCSI) PIONEER CD-ROM DRM-604X 2403", "PIONEER_CD-ROM_DRM-604X_2403", BUS_TYPE_SCSI }, /*30*/ + { "PLEXTOR", "CD-ROM PX-32TS", "1.03", "(SCSI) PLEXTOR CD-ROM PX-32TS 1.03", "PLEXTOR_CD-ROM_PX-32TS_1.03", BUS_TYPE_SCSI }, /*31*/ + { "TEAC", "CD-R55S", "1.0R", "(SCSI) TEAC CD-R55S 1.0R", "TEAC_CD-R55S_1.0R", BUS_TYPE_SCSI }, /*32*/ + { "TOSHIBA", "CD-ROM DRIVE:XM", "3433", "(SCSI) TOSHIBA CD-ROM DRIVE:XM 3433", "TOSHIBA_CD-ROM_DRIVEXM_3433", BUS_TYPE_SCSI }, /*33*/ + { "TOSHIBA", "CD-ROM XM-3301TA", "0272", "(SCSI) TOSHIBA CD-ROM XM-3301TA 0272", "TOSHIBA_CD-ROM_XM-3301TA_0272", BUS_TYPE_SCSI }, /*34*/ + { "TOSHIBA", "CD-ROM XM-5701TA", "3136", "(SCSI) TOSHIBA CD-ROM XM-5701TA 3136", "TOSHIBA_CD-ROM_XM-5701TA_3136", BUS_TYPE_SCSI }, /*35*/ + { "", "", "", "", "", -1 }, }; /* To shut up the GCC compilers. */ struct cdrom; -typedef struct { - uint8_t attr, track, - index, - abs_m, abs_s, abs_f, - rel_m, rel_s, rel_f; +typedef struct subchannel_t { + uint8_t attr; + uint8_t track; + uint8_t index; + uint8_t abs_m; + uint8_t abs_s; + uint8_t abs_f; + uint8_t rel_m; + uint8_t rel_s; + uint8_t rel_f; } subchannel_t; -typedef struct { +typedef struct track_info_t { int number; - uint8_t attr, m, s, f; + uint8_t attr; + uint8_t m; + uint8_t s; + uint8_t f; } track_info_t; /* Define the various CD-ROM drive operations (ops). */ -typedef struct { +typedef struct cdrom_ops_t { void (*get_tracks)(struct cdrom *dev, int *first, int *last); void (*get_track_info)(struct cdrom *dev, uint32_t track, int end, track_info_t *ti); void (*get_subchannel)(struct cdrom *dev, uint32_t lba, subchannel_t *subc); @@ -144,32 +150,40 @@ typedef struct cdrom { uint8_t id; union { - uint8_t res, res0, /* Reserved for other ID's. */ - res1, - ide_channel, scsi_device_id; + uint8_t res; + uint8_t res0; /* Reserved for other ID's. */ + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - uint8_t bus_type, /* 0 = ATAPI, 1 = SCSI */ - bus_mode, /* Bit 0 = PIO suported; - Bit 1 = DMA supportd. */ - cd_status, /* Struct variable reserved for - media status. */ - speed, cur_speed; + uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ + uint8_t bus_mode; /* Bit 0 = PIO suported; + Bit 1 = DMA supportd. */ + uint8_t cd_status; /* Struct variable reserved for + media status. */ + uint8_t speed; + uint8_t cur_speed; int is_dir; void *priv; - char image_path[1024], - prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; char *image_history[CD_IMAGE_HISTORY]; - uint32_t sound_on, cdrom_capacity, - early, seek_pos, - seek_diff, cd_end, type; + uint32_t sound_on; + uint32_t cdrom_capacity; + uint32_t seek_pos; + uint32_t seek_diff; + uint32_t cd_end; + uint32_t type; - int host_drive, prev_host_drive, - cd_buflen, audio_op; + int host_drive; + int prev_host_drive; + int cd_buflen; + int audio_op; const cdrom_ops_t *ops; diff --git a/src/include/86box/cdrom_image_backend.h b/src/include/86box/cdrom_image_backend.h index 511ca68eb..67129dc7c 100644 --- a/src/include/86box/cdrom_image_backend.h +++ b/src/include/86box/cdrom_image_backend.h @@ -56,10 +56,17 @@ typedef struct { } track_file_t; typedef struct { - int number, track_number, attr, sector_size, - mode2, form, pre, pad; - uint64_t start, length, - skip; + int number; + int track_number; + int attr; + int sector_size; + int mode2; + int form; + int pre; + int pad; + uint64_t start; + uint64_t length; + uint64_t skip; track_file_t *file; } track_t; diff --git a/src/include/86box/config.h b/src/include/86box/config.h index 9738b049b..72b0a709f 100644 --- a/src/include/86box/config.h +++ b/src/include/86box/config.h @@ -27,110 +27,110 @@ extern "C" { #endif #if 0 -typedef struct { - uint8_t id, - uint8_t bus_type, /* Bus type: IDE, SCSI, etc. */ - bus, : 4, /* ID of the bus (for example, for IDE, - 0 = primary, 1 = secondary, etc. */ - bus_id, : 4, /* ID of the device on the bus */ - uint8_t type, /* Type flags, interpretation depends - on the device */ - uint8_t is_image; /* This is only used for CD-ROM: - 0 = Image; - 1 = Host drive */ +typedef struct storage_cfg_t { + uint8_t id; + uint8_t bus_type; /* Bus type: IDE, SCSI, etc. */ + uint8_t bus, : 4; /* ID of the bus (for example, for IDE, + 0 = primary, 1 = secondary, etc. */ + uint8_t bus_id, : 4; /* ID of the device on the bus */ + uint8_t type; /* Type flags, interpretation depends + on the device */ + uint8_t is_image; /* This is only used for CD-ROM: + 0 = Image; + 1 = Host drive */ - wchar_t path[1024]; /* Name of current image file or - host drive */ + wchar_t path[1024]; /* Name of current image file or + host drive */ - uint32_t spt, /* Physical geometry parameters */ - hpc, - tracks; + uint32_t spt; /* Physical geometry parameters */ + uint32_t hpc; + uint32_t tracks; } storage_cfg_t; -typedef struct { +typedef struct config_t { /* General configuration */ - int vid_resize, /* Window is resizable or not */ - vid_renderer, /* Renderer */ - vid_fullscreen_scale, /* Full screen scale type */ - vid_fullscreen_start, /* Start emulator in full screen */ - vid_force_43, /* Force 4:3 display ratio in windowed mode */ - vid_scale, /* Windowed mode scale */ - vid_overscan, /* EGA/(S)VGA overscan enabled */ - vid_cga_contrast, /* CGA alternate contrast enabled */ - vid_grayscale, /* Video is grayscale */ - vid_grayscale_type, /* Video grayscale type */ - vid_invert_display, /* Invert display */ - rctrl_is_lalt, /* Right CTRL is left ALT */ - update_icons, /* Update status bar icons */ - window_remember, /* Remember window position and size */ - window_w, /* Window coordinates */ - window_h, - window_x, - window_y, - sound_gain; /* Sound gain */ + int vid_resize; /* Window is resizable or not */ + int vid_renderer; /* Renderer */ + int vid_fullscreen_scale; /* Full screen scale type */ + int vid_fullscreen_start; /* Start emulator in full screen */ + int vid_force_43; /* Force 4:3 display ratio in windowed mode */ + int vid_scale; /* Windowed mode scale */ + int vid_overscan; /* EGA/(S)VGA overscan enabled */ + int vid_cga_contrast; /* CGA alternate contrast enabled */ + int vid_grayscale; /* Video is grayscale */ + int vid_grayscale_type; /* Video grayscale type */ + int vid_invert_display; /* Invert display */ + int rctrl_is_lalt; /* Right CTRL is left ALT */ + int update_icons; /* Update status bar icons */ + int window_remember; /* Remember window position and size */ + int window_w; /* Window coordinates */ + int window_h; + int window_x; + int window_y; + int sound_gain; /* Sound gain */ # ifdef USE_LANGUAGE - uint16_t language_id; /* Language ID (0x0409 = English (US)) */ + uint16_t language_id; /* Language ID (0x0409 = English (US)) */ # endif /* Machine cateogory */ - int machine, /* Machine */ - cpu, /* CPU */ + int machine; /* Machine */ + int cpu; /* CPU */ # ifdef USE_DYNAREC - cpu_use_dynarec, /* CPU recompiler enabled */ + int cpu_use_dynarec; /* CPU recompiler enabled */ # endif - wait_states, /* CPU wait states */ - enable_external_fpu, /* FPU enabled */ - time_sync; /* Time sync enabled */ - uint32_t mem_size; /* Memory size */ + int wait_states; /* CPU wait states */ + int enable_external_fpu; /* FPU enabled */ + int time_sync; /* Time sync enabled */ + uint32_t mem_size; /* Memory size */ /* Video category */ - int video_card, /* Video card */ - voodoo_enabled; /* Voodoo enabled */ + int video_card; /* Video card */ + int voodoo_enabled; /* Voodoo enabled */ /* Input devices category */ - int mouse_type, /* Mouse type */ - joystick_type; /* Joystick type */ + int mouse_type; /* Mouse type */ + int joystick_type; /* Joystick type */ /* Sound category */ - int sound_card, /* Sound card */ - midi_device, /* Midi device */ - mpu_401, /* Standalone MPU-401 enabled */ - ssi_2001_enabled, /* SSI-2001 enabled */ - game_blaster_enabled, /* Game blaster enabled */ - gus_enabled, /* Gravis Ultrasound enabled */ - opl_type, /* OPL emulation type */ - sound_is_float; /* Sound is 32-bit float or 16-bit integer */ + int sound_card; /* Sound card */ + int midi_device; /* Midi device */ + int mpu_401; /* Standalone MPU-401 enabled */ + int ssi_2001_enabled; /* SSI-2001 enabled */ + int game_blaster_enabled; /* Game blaster enabled */ + int gus_enabled; /* Gravis Ultrasound enabled */ + int opl_type; /* OPL emulation type */ + int sound_is_float; /* Sound is 32-bit float or 16-bit integer */ /* Network category */ - int network_type, /* Network type (SLiRP or PCap) */ - network_card; /* Network card */ - char network_host[520]; /* PCap device */ + int network_type; /* Network type (SLiRP or PCap) */ + int network_card; /* Network card */ + char network_host[520]; /* PCap device */ /* Ports category */ char parallel_devices[PARALLEL_MAX][32]; /* LPT device names */ # ifdef USE_SERIAL_DEVICES - char serial_devices[SERIAL_MAX][32]; /* Serial device names */ + char serial_devices[SERIAL_MAX][32]; /* Serial device names */ # endif /* Other peripherals category */ - int fdc_type, /* Floppy disk controller type */ - hdc, /* Hard disk controller */ - scsi_card, /* SCSI controller */ - ide_ter_enabled, /* Tertiary IDE controller enabled */ - ide_qua_enabled, /* Quaternary IDE controller enabled */ - bugger_enabled, /* ISA bugger device enabled */ - isa_rtc_type, /* ISA RTC card */ - isa_mem_type[ISAMEM_MAX]; /* ISA memory boards */ + int fdc_type; /* Floppy disk controller type */ + int hdc; /* Hard disk controller */ + int scsi_card; /* SCSI controller */ + int ide_ter_enabled; /* Tertiary IDE controller enabled */ + int ide_qua_enabled; /* Quaternary IDE controller enabled */ + int bugger_enabled; /* ISA bugger device enabled */ + int isa_rtc_type; /* ISA RTC card */ + int isa_mem_type[ISAMEM_MAX]; /* ISA memory boards */ /* Hard disks category */ - storage_cfg_t hdd[HDD_NUM]; /* Hard disk drives */ + storage_cfg_t hdd[HDD_NUM]; /* Hard disk drives */ /* Floppy drives category */ - storage_cfg_t fdd[FDD_NUM]; /* Floppy drives */ + storage_cfg_t fdd[FDD_NUM]; /* Floppy drives */ /* Other removable devices category */ - storage_cfg_t cdrom[CDROM_NUM], /* CD-ROM drives */ - storage_cfg_t rdisk[ZIP_NUM]; /* Removable disk drives */ + storage_cfg_t cdrom[CDROM_NUM]; /* CD-ROM drives */ + storage_cfg_t rdisk[ZIP_NUM]; /* Removable disk drives */ } config_t; #endif diff --git a/src/include/86box/ddma.h b/src/include/86box/ddma.h index ccc423d27..01c2e980d 100644 --- a/src/include/86box/ddma.h +++ b/src/include/86box/ddma.h @@ -21,14 +21,13 @@ extern "C" { #endif -typedef struct -{ +typedef struct ddma_channel_t { uint16_t io_base; - int channel, enable; + int channel; + int enable; } ddma_channel_t; -typedef struct -{ +typedef struct ddma_t { ddma_channel_t channels[8]; } ddma_t; diff --git a/src/include/86box/device.h b/src/include/86box/device.h index f85be460d..74dd5ee3d 100644 --- a/src/include/86box/device.h +++ b/src/include/86box/device.h @@ -57,21 +57,24 @@ #define CONFIG_SERPORT 12 enum { - DEVICE_PCJR = 2, /* requires an IBM PCjr */ - DEVICE_AT = 4, /* requires an AT-compatible system */ - DEVICE_PS2 = 8, /* requires a PS/1 or PS/2 system */ - DEVICE_ISA = 0x10, /* requires the ISA bus */ - DEVICE_CBUS = 0x20, /* requires the C-BUS bus */ - DEVICE_MCA = 0x40, /* requires the MCA bus */ - DEVICE_EISA = 0x80, /* requires the EISA bus */ - DEVICE_VLB = 0x100, /* requires the PCI bus */ - DEVICE_PCI = 0x200, /* requires the VLB bus */ - DEVICE_AGP = 0x400, /* requires the AGP bus */ - DEVICE_AC97 = 0x800, /* requires the AC'97 bus */ - DEVICE_COM = 0x1000, /* requires a serial port */ - DEVICE_LPT = 0x2000, /* requires a parallel port */ + DEVICE_PCJR = 2, /* requires an IBM PCjr */ + DEVICE_AT = 4, /* requires an AT-compatible system */ + DEVICE_PS2 = 8, /* requires a PS/1 or PS/2 system */ + DEVICE_ISA = 0x10, /* requires the ISA bus */ + DEVICE_CBUS = 0x20, /* requires the C-BUS bus */ + DEVICE_MCA = 0x40, /* requires the MCA bus */ + DEVICE_EISA = 0x80, /* requires the EISA bus */ + DEVICE_VLB = 0x100, /* requires the PCI bus */ + DEVICE_PCI = 0x200, /* requires the VLB bus */ + DEVICE_AGP = 0x400, /* requires the AGP bus */ + DEVICE_AC97 = 0x800, /* requires the AC'97 bus */ + DEVICE_COM = 0x1000, /* requires a serial port */ + DEVICE_LPT = 0x2000, /* requires a parallel port */ + DEVICE_KBC = 0x4000, /* is a keyboard controller */ - DEVICE_EXTPARAMS = 0x40000000 /* accepts extended parameters */ + DEVICE_EXTPARAMS = 0x40000000, /* accepts extended parameters */ + + DEVICE_ALL = 0xffffffff /* match all devices */ }; #define BIOS_NORMAL 0 @@ -83,28 +86,30 @@ enum { #define BIOS_INTERLEAVED_INVERT 8 #define BIOS_HIGH_BIT_INVERT 16 -typedef struct { +typedef struct device_config_selection_t { const char *description; int value; } device_config_selection_t; -typedef struct { +typedef struct device_config_bios_t { const char *name; const char *internal_name; int bios_type; int files_no; - uint32_t local, size; - void *dev1, *dev2; + uint32_t local; + uint32_t size; + void *dev1; + void *dev2; const char *files[9]; } device_config_bios_t; -typedef struct { +typedef struct device_config_spinner_t { int16_t min; int16_t max; int16_t step; } device_config_spinner_t; -typedef struct { +typedef struct device_config_t { const char *name; const char *description; int type; @@ -139,7 +144,7 @@ typedef struct _device_ { const device_config_t *config; } device_t; -typedef struct { +typedef struct device_context_t { const device_t *dev; char name[2048]; int instance; @@ -171,8 +176,7 @@ extern void *device_cadd_inst_parameters(const device_t *d, const device_t *cd, extern void device_cadd_inst_ex(const device_t *d, const device_t *cd, void *priv, int inst); extern void device_cadd_inst_ex_parameters(const device_t *d, const device_t *cd, void *priv, int inst, void *params); extern void device_close_all(void); -extern void device_reset_all(void); -extern void device_reset_all_pci(void); +extern void device_reset_all(uint32_t match_flags); extern void *device_get_priv(const device_t *d); extern int device_available(const device_t *d); extern int device_poll(const device_t *d, int x, int y, int z, int b); diff --git a/src/include/86box/disksizes.h b/src/include/86box/disksizes.h index e47b82943..b5cd1bc30 100644 --- a/src/include/86box/disksizes.h +++ b/src/include/86box/disksizes.h @@ -22,7 +22,7 @@ extern "C" { #endif -typedef struct { +typedef struct disk_size_t { int hole; int sides; int data_rate; @@ -40,10 +40,12 @@ typedef struct { static const disk_size_t disk_sizes[14] = { // clang-format off -// { 1, 1, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 250k 8" */ -// { 1, 2, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 500k 8" */ -// { 1, 1, 2, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 616k 8" */ -// { 1, 2, 0, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 1232k 8" */ +#if 0 + { 1, 1, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 250k 8" */ + { 1, 2, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 500k 8" */ + { 1, 1, 2, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 616k 8" */ + { 1, 2, 0, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 1232k 8" */ +#endif { 0, 1, 2, 1, 0, 40, 8, 2, 0xfe, 2, 2, 1, 64 }, /* 160k */ { 0, 1, 2, 1, 0, 40, 9, 2, 0xfc, 2, 2, 1, 64 }, /* 180k */ { 0, 2, 2, 1, 0, 40, 8, 2, 0xff, 2, 2, 1, 112 }, /* 320k */ @@ -58,8 +60,10 @@ static const disk_size_t disk_sizes[14] = { { 2, 2, 3, 1, 0, 80, 36, 2, 0xf0, 2, 2, 9, 240 }, /* 2.88M */ { 0, 64, 0, 0, 0, 96, 32, 2, 0, 0, 0, 0, 0 }, /* ZIP 100 */ { 0, 64, 0, 0, 0, 239, 32, 2, 0, 0, 0, 0, 0 }, /* ZIP 250 */ -// { 0, 8, 0, 0, 0, 963, 32, 2, 0, 0, 0, 0, 0 }, /* LS-120 */ -// { 0, 32, 0, 0, 0, 262, 56, 2, 0, 0, 0, 0, 0 } /* LS-240 */ +#if 0 + { 0, 8, 0, 0, 0, 963, 32, 2, 0, 0, 0, 0, 0 }, /* LS-120 */ + { 0, 32, 0, 0, 0, 262, 56, 2, 0, 0, 0, 0, 0 } /* LS-240 */ +#endif // clang-format on }; diff --git a/src/include/86box/dma.h b/src/include/86box/dma.h index 904d0b13b..7ead53ba0 100644 --- a/src/include/86box/dma.h +++ b/src/include/86box/dma.h @@ -43,22 +43,37 @@ #define DMA_OVER 0x10000 #define DMA_VERIFY 0x20000 -typedef struct { - uint8_t m, mode, page, stat, - stat_rq, command, - ps2_mode, arb_level, - sg_command, sg_status, - ptr0, enabled, - ext_mode, page_l, - page_h, pad; - uint16_t cb, io_addr, - base, transfer_mode; - uint32_t ptr, ptr_cur, - addr, - ab, ac; - int cc, wp, - size, count, - eot; +typedef struct dma_t { + uint8_t m; + uint8_t mode; + uint8_t page; + uint8_t stat; + uint8_t stat_rq; + uint8_t command; + uint8_t ps2_mode; + uint8_t arb_level; + uint8_t sg_command; + uint8_t sg_status; + uint8_t ptr0; + uint8_t enabled; + uint8_t ext_mode; + uint8_t page_l; + uint8_t page_h; + uint8_t pad; + uint16_t cb; + uint16_t io_addr; + uint16_t base; + uint16_t transfer_mode; + uint32_t ptr; + uint32_t ptr_cur; + uint32_t addr; + uint32_t ab; + uint32_t ac; + int cc; + int wp; + int size; + int count; + int eot; } dma_t; extern dma_t dma[8]; diff --git a/src/include/86box/fdc.h b/src/include/86box/fdc.h index 09678b2e5..9441bdfc4 100644 --- a/src/include/86box/fdc.h +++ b/src/include/86box/fdc.h @@ -56,42 +56,79 @@ extern int fdc_type; #define FDC_FLAG_TER 0x2000 /* Is Tertiary */ #define FDC_FLAG_QUA 0x3000 /* Is Quaternary */ -typedef struct { - uint8_t dor, stat, command, processed_cmd, dat, st0, swap, dtl; - uint8_t swwp, disable_write, st5, st6, error; - uint8_t params[8], res[11]; +typedef struct fdc_t { + uint8_t dor; + uint8_t stat; + uint8_t command; + uint8_t processed_cmd; + uint8_t dat; + uint8_t st0; + uint8_t swap; + uint8_t dtl; + uint8_t swwp; + uint8_t disable_write; + uint8_t st5; + uint8_t st6; + uint8_t error; + uint8_t params[8]; + uint8_t res[11]; uint8_t specify[2]; - uint8_t config, pretrk; + uint8_t config; + uint8_t pretrk; uint8_t fifobuf[16]; uint16_t base_address; - int head, sector, drive, lastdrive; - int pcn[4], eot[4]; - int rw_track, pos; - int pnum, ptot; - int rate, reset_stat; - int lock, perp; - int format_state, format_n; - int step, seek_dir; - int tc, noprec; + int head; + int sector; + int drive; + int lastdrive; + int pcn[4]; + int eot[4]; + int rw_track; + int pos; + int pnum; + int ptot; + int rate; + int reset_stat; + int lock; + int perp; + int format_state; + int format_n; + int step; + int seek_dir; + int tc; + int noprec; - int data_ready, inread; - int bitcell_period, enh_mode; - int rwc[4], drvrate[4]; - int boot_drive, dma; - int densel_polarity, densel_force; - int fifo, tfifo; - int fifobufpos, drv2en; + int data_ready; + int inread; + int bitcell_period; + int enh_mode; + int rwc[4]; + int drvrate[4]; + int boot_drive; + int dma; + int densel_polarity; + int densel_force; + int fifo; + int tfifo; + int fifobufpos; + int drv2en; int gap; - int enable_3f1, format_sectors; - int max_track, mfm; - int deleted, wrong_am; - int sc, satisfying_sectors; - int fintr, rw_drive; + int enable_3f1; + int format_sectors; + int max_track; + int mfm; + int deleted; + int wrong_am; + int sc; + int satisfying_sectors; + int fintr; + int rw_drive; - int flags, interrupt; + int flags; + int interrupt; int irq; /* Should be 6 by default. */ int dma_ch; /* Should be 2 by default. */ @@ -99,11 +136,13 @@ typedef struct { int bit_rate; /* Should be 250 at start. */ int paramstogo; - sector_id_t read_track_sector, format_sector_id; + sector_id_t read_track_sector; + sector_id_t format_sector_id; uint64_t watchdog_count; - pc_timer_t timer, watchdog_timer; + pc_timer_t timer; + pc_timer_t watchdog_timer; } fdc_t; extern void fdc_remove(fdc_t *fdc); diff --git a/src/include/86box/fdd.h b/src/include/86box/fdd.h index 19a2141d3..e21cbb73e 100644 --- a/src/include/86box/fdd.h +++ b/src/include/86box/fdd.h @@ -65,7 +65,7 @@ extern int fdd_get_from_internal_name(char *s); extern int fdd_current_track(int drive); -typedef struct { +typedef struct DRIVE { int id; void (*seek)(int drive, int track); @@ -120,7 +120,8 @@ extern int disable_write; extern int defaultwriteprot; -extern int writeprot[FDD_NUM], fwriteprot[FDD_NUM]; +extern int writeprot[FDD_NUM]; +extern int fwriteprot[FDD_NUM]; extern int fdd_changed[FDD_NUM]; extern int drive_empty[FDD_NUM]; diff --git a/src/include/86box/fifo8.h b/src/include/86box/fifo8.h index 811f0522f..9f88ec408 100644 --- a/src/include/86box/fifo8.h +++ b/src/include/86box/fifo8.h @@ -1,7 +1,7 @@ #ifndef EMU_FIFO8_H #define EMU_FIFO8_H -typedef struct { +typedef struct Fifo8 { /* All fields are private */ uint8_t *data; uint32_t capacity; diff --git a/src/include/86box/gameport.h b/src/include/86box/gameport.h index 905130da0..3b779e4e3 100644 --- a/src/include/86box/gameport.h +++ b/src/include/86box/gameport.h @@ -34,7 +34,7 @@ #define GAMEPORT_SIO 0x1000000 -typedef struct { +typedef struct plat_joystick_t { char name[260]; int a[8]; @@ -57,8 +57,7 @@ typedef struct { int id; } pov[4]; - struct - { + struct { char name[260]; int id; } slider[2]; @@ -69,7 +68,7 @@ typedef struct { int nr_sliders; } plat_joystick_t; -typedef struct { +typedef struct joystick_t { int axis[8]; int button[32]; int pov[4]; @@ -80,20 +79,20 @@ typedef struct { int pov_mapping[4][2]; } joystick_t; -typedef struct { +typedef struct joystick_if_t { const char *name; const char *internal_name; - void *(*init)(void); - void (*close)(void *p); + void *(*init)(void); + void (*close)(void *p); uint8_t (*read)(void *p); - void (*write)(void *p); - int (*read_axis)(void *p, int axis); - void (*a0_over)(void *p); + void (*write)(void *p); + int (*read_axis)(void *p, int axis); + void (*a0_over)(void *p); - int axis_count, - button_count, - pov_count; + int axis_count; + int button_count; + int pov_count; int max_joysticks; const char *axis_names[8]; const char *button_names[32]; diff --git a/src/include/86box/gdbstub.h b/src/include/86box/gdbstub.h index 8ac83f625..5d55615b3 100644 --- a/src/include/86box/gdbstub.h +++ b/src/include/86box/gdbstub.h @@ -24,14 +24,14 @@ #define GDBSTUB_MEM_AWATCH 32 enum { - GDBSTUB_EXEC = 0, - GDBSTUB_SSTEP, - GDBSTUB_BREAK, - GDBSTUB_BREAK_SW, - GDBSTUB_BREAK_HW, - GDBSTUB_BREAK_RWATCH, - GDBSTUB_BREAK_WWATCH, - GDBSTUB_BREAK_AWATCH + GDBSTUB_EXEC = 0, + GDBSTUB_SSTEP = 1, + GDBSTUB_BREAK = 2, + GDBSTUB_BREAK_SW = 3, + GDBSTUB_BREAK_HW = 4, + GDBSTUB_BREAK_RWATCH = 5, + GDBSTUB_BREAK_WWATCH = 6, + GDBSTUB_BREAK_AWATCH = 7 }; #ifdef USE_GDBSTUB diff --git a/src/include/86box/hdc.h b/src/include/86box/hdc.h index 4320d86e2..64fd88659 100644 --- a/src/include/86box/hdc.h +++ b/src/include/86box/hdc.h @@ -60,16 +60,22 @@ extern const device_t ide_vlb_2ch_device; /* vlb_ide_2ch */ extern const device_t ide_pci_device; /* pci_ide */ extern const device_t ide_pci_2ch_device; /* pci_ide_2ch */ -extern const device_t ide_cmd640_vlb_device; /* CMD PCI-640B VLB */ -extern const device_t ide_cmd640_vlb_178_device; /* CMD PCI-640B VLB (Port 178h) */ -extern const device_t ide_cmd640_pci_device; /* CMD PCI-640B PCI */ -extern const device_t ide_cmd640_pci_legacy_only_device; /* CMD PCI-640B PCI (Legacy Mode Only) */ -extern const device_t ide_cmd640_pci_single_channel_device; /* CMD PCI-640B PCI (Only primary channel) */ -extern const device_t ide_cmd646_device; /* CMD PCI-646 */ -extern const device_t ide_cmd646_legacy_only_device; /* CMD PCI-646 (Legacy Mode Only) */ -extern const device_t ide_cmd646_single_channel_device; /* CMD PCI-646 (Only primary channel) */ +extern const device_t ide_cmd640_vlb_device; /* CMD PCI-640B VLB */ +extern const device_t ide_cmd640_vlb_178_device; /* CMD PCI-640B VLB (Port 178h) */ +extern const device_t ide_cmd640_vlb_pri_device; /* CMD PCI-640B VLB (Only primary channel) */ +extern const device_t ide_cmd640_vlb_pri_178_device; /* CMD PCI-640B VLB (Only primary channel) (Port 178h) */ +extern const device_t ide_cmd640_vlb_sec_device; /* CMD PCI-640B VLB (Only secondary channel) */ +extern const device_t ide_cmd640_vlb_sec_178_device; /* CMD PCI-640B VLB (Only secondary channel) (Port 178h) */ +extern const device_t ide_cmd640_pci_device; /* CMD PCI-640B PCI */ +extern const device_t ide_cmd640_pci_legacy_only_device; /* CMD PCI-640B PCI (Legacy Mode Only) */ +extern const device_t ide_cmd640_pci_single_channel_device; /* CMD PCI-640B PCI (Only primary channel) */ +extern const device_t ide_cmd640_pci_single_channel_sec_device; /* CMD PCI-640B PCI (Only secondary channel) */ +extern const device_t ide_cmd646_device; /* CMD PCI-646 */ +extern const device_t ide_cmd646_legacy_only_device; /* CMD PCI-646 (Legacy Mode Only) */ +extern const device_t ide_cmd646_single_channel_device; /* CMD PCI-646 (Only primary channel) */ -extern const device_t ide_opti611_vlb_device; /* OPTi 82c611/611A VLB */ +extern const device_t ide_opti611_vlb_device; /* OPTi 82c611/611A VLB */ +extern const device_t ide_opti611_vlb_sec_device; /* OPTi 82c611/611A VLB (Secondary channel) */ extern const device_t ide_ter_device; extern const device_t ide_ter_pnp_device; diff --git a/src/include/86box/hdc_ide.h b/src/include/86box/hdc_ide.h index e7bd8d7cf..8a4c66da3 100644 --- a/src/include/86box/hdc_ide.h +++ b/src/include/86box/hdc_ide.h @@ -43,23 +43,37 @@ enum { #ifdef SCSI_DEVICE_H typedef struct ide_s { - uint8_t selected, - atastat, error, - command, fdisk; - int type, board, - irqstat, service, - blocksize, blockcount, - hdd_num, channel, - pos, sector_pos, - lba, - reset, mdma_mode, - do_initial_read; - uint32_t secount, sector, - cylinder, head, - drive, cylprecomp, - cfg_spt, cfg_hpc, - lba_addr, tracks, - spt, hpc; + uint8_t selected; + uint8_t atastat; + uint8_t error; + uint8_t command; + uint8_t fdisk; + int type; + int board; + int irqstat; + int service; + int blocksize; + int blockcount; + int hdd_num; + int channel; + int pos; + int sector_pos; + int lba; + int reset; + int mdma_mode; + int do_initial_read; + uint32_t secount; + uint32_t sector; + uint32_t cylinder; + uint32_t head; + uint32_t drive; + uint32_t cylprecomp; + uint32_t cfg_spt; + uint32_t cfg_hpc; + uint32_t lba_addr; + uint32_t tracks; + uint32_t spt; + uint32_t hpc; uint16_t *buffer; uint8_t *sector_buffer; @@ -96,10 +110,10 @@ extern ide_t *ide_drives[IDE_NUM]; This will eventually be hookable. */ enum { - TYPE_PIO = 0, - TYPE_SDMA, - TYPE_MDMA, - TYPE_UDMA + TYPE_PIO = 0, + TYPE_SDMA = 1, + TYPE_MDMA = 2, + TYPE_UDMA = 3 }; /* Return: @@ -108,12 +122,13 @@ enum { This will eventually be hookable. */ enum { - TIMINGS_DMA = 0, - TIMINGS_PIO, - TIMINGS_PIO_FC + TIMINGS_DMA = 0, + TIMINGS_PIO = 1, + TIMINGS_PIO_FC = 2 }; -extern int ide_ter_enabled, ide_qua_enabled; +extern int ide_ter_enabled; +extern int ide_qua_enabled; #ifdef SCSI_DEVICE_H extern ide_t *ide_get_drive(int ch); diff --git a/src/include/86box/hdc_ide_sff8038i.h b/src/include/86box/hdc_ide_sff8038i.h index b411ecf5d..490a13a42 100644 --- a/src/include/86box/hdc_ide_sff8038i.h +++ b/src/include/86box/hdc_ide_sff8038i.h @@ -20,19 +20,27 @@ #ifndef EMU_HDC_IDE_SFF8038I_H #define EMU_HDC_IDE_SFF8038I_H -typedef struct -{ - uint8_t command, status, - ptr0, enabled, - dma_mode, pad, - pad0, pad1; - uint16_t base, pad2; - uint32_t ptr, ptr_cur, - addr; - int count, eot, - slot, - irq_mode[2], irq_level[2], - irq_pin, irq_line; +typedef struct sff8038i_t { + uint8_t command; + uint8_t status; + uint8_t ptr0; + uint8_t enabled; + uint8_t dma_mode; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; + uint16_t base; + uint16_t pad2; + uint32_t ptr; + uint32_t ptr_cur; + uint32_t addr; + int count; + int eot; + int slot; + int irq_mode[2]; + int irq_level[2]; + int irq_pin; + int irq_line; } sff8038i_t; extern const device_t sff8038i_device; diff --git a/src/include/86box/hdd.h b/src/include/86box/hdd.h index 58fff9ffd..9874fb4aa 100644 --- a/src/include/86box/hdd.h +++ b/src/include/86box/hdd.h @@ -34,60 +34,60 @@ Bit 5 = Removable (0 = no, 1 yes). */ enum { - BUS_DISABLED = 0x00, + BUS_DISABLED = 0x00, - BUS_MFM = 0x01, /* These four are for hard disk only. */ - BUS_XIDE = 0x02, - BUS_XTA = 0x03, - BUS_ESDI = 0x04, + BUS_MFM = 0x01, /* These four are for hard disk only. */ + BUS_XIDE = 0x02, + BUS_XTA = 0x03, + BUS_ESDI = 0x04, - BUS_PANASONIC = 0x21, / These four are for CD-ROM only. */ - BUS_PHILIPS = 0x22, - BUS_SONY = 0x23, - BUS_MITSUMI = 0x24, + BUS_PANASONIC = 0x21, / These four are for CD-ROM only. */ + BUS_PHILIPS = 0x22, + BUS_SONY = 0x23, + BUS_MITSUMI = 0x24, - BUS_IDE_PIO_ONLY = 0x05, - BUS_IDE_PIO_AND_DMA = 0x15, - BUS_IDE_R_PIO_ONLY = 0x25, - BUS_IDE_R_PIO_AND_DMA = 0x35, + BUS_IDE_PIO_ONLY = 0x05, + BUS_IDE_PIO_AND_DMA = 0x15, + BUS_IDE_R_PIO_ONLY = 0x25, + BUS_IDE_R_PIO_AND_DMA = 0x35, - BUS_ATAPI_PIO_ONLY = 0x06, - BUS_ATAPI_PIO_AND_DMA = 0x16, - BUS_ATAPI_R_PIO_ONLY = 0x26, - BUS_ATAPI_R_PIO_AND_DMA = 0x36, + BUS_ATAPI_PIO_ONLY = 0x06, + BUS_ATAPI_PIO_AND_DMA = 0x16, + BUS_ATAPI_R_PIO_ONLY = 0x26, + BUS_ATAPI_R_PIO_AND_DMA = 0x36, - BUS_SASI = 0x07, - BUS_SASI_R = 0x27, + BUS_SASI = 0x07, + BUS_SASI_R = 0x27, - BUS_SCSI = 0x08, - BUS_SCSI_R = 0x28, + BUS_SCSI = 0x08, + BUS_SCSI_R = 0x28, - BUS_USB = 0x09, - BUS_USB_R = 0x29 + BUS_USB = 0x09, + BUS_USB_R = 0x29 }; #else enum { HDD_BUS_DISABLED = 0, - HDD_BUS_MFM, - HDD_BUS_XTA, - HDD_BUS_ESDI, - HDD_BUS_IDE, - HDD_BUS_ATAPI, - HDD_BUS_SCSI, - HDD_BUS_USB + HDD_BUS_MFM = 1, + HDD_BUS_XTA = 2, + HDD_BUS_ESDI = 3, + HDD_BUS_IDE = 4, + HDD_BUS_ATAPI = 5, + HDD_BUS_SCSI = 6, + HDD_BUS_USB = 7 }; #endif enum { - HDD_OP_SEEK = 0, - HDD_OP_READ, - HDD_OP_WRITE + HDD_OP_SEEK = 0, + HDD_OP_READ = 2, + HDD_OP_WRITE = 3 }; #define HDD_MAX_ZONES 16 #define HDD_MAX_CACHE_SEG 16 -typedef struct { +typedef struct hdd_preset_t { const char *name; const char *internal_name; uint32_t zones; @@ -101,7 +101,7 @@ typedef struct { double track_seek_ms; } hdd_preset_t; -typedef struct { +typedef struct hdd_cache_seg_t { uint32_t id; uint32_t lba_addr; uint32_t ra_addr; @@ -110,7 +110,7 @@ typedef struct { uint8_t valid; } hdd_cache_seg_t; -typedef struct { +typedef struct hdd_cache_t { // Read cache hdd_cache_seg_t segments[HDD_MAX_CACHE_SEG]; uint32_t num_segments; @@ -126,7 +126,7 @@ typedef struct { uint64_t write_start_time; } hdd_cache_t; -typedef struct { +typedef struct hdd_zone_t { uint32_t cylinders; uint32_t sectors_per_track; double sector_time_usec; @@ -136,7 +136,7 @@ typedef struct { } hdd_zone_t; /* Define the virtual Hard Disk. */ -typedef struct { +typedef struct hard_disk_t { uint8_t id; union { uint8_t channel; /* Needed for Settings to reduce the number of if's */ @@ -147,21 +147,23 @@ typedef struct { uint8_t ide_channel; uint8_t scsi_id; }; - uint8_t bus, - res; /* Reserved for bus mode */ + uint8_t bus; + uint8_t res; /* Reserved for bus mode */ uint8_t wp; /* Disk has been mounted READ-ONLY */ - uint8_t pad, pad0; + uint8_t pad; + uint8_t pad0; void *priv; - char fn[1024], /* Name of current image file */ - prev_fn[1024]; /* Name of previous image file */ + char fn[1024]; /* Name of current image file */ + char vhd_parent[1041]; /* Differential VHD parent file */ - uint32_t res0, pad1, - base, - spt, - hpc, /* Physical geometry parameters */ - tracks; + uint32_t res0; + uint32_t pad1; + uint32_t base; + uint32_t spt; + uint32_t hpc; /* Physical geometry parameters */ + uint32_t tracks; hdd_zone_t zones[HDD_MAX_ZONES]; uint32_t num_zones; @@ -176,6 +178,7 @@ typedef struct { uint32_t cur_addr; uint32_t speed_preset; + uint32_t vhd_blocksize; double avg_rotation_lat_usec; double full_stroke_usec; diff --git a/src/include/86box/hwm.h b/src/include/86box/hwm.h index e0410b3a0..b1b1d8c25 100644 --- a/src/include/86box/hwm.h +++ b/src/include/86box/hwm.h @@ -20,20 +20,21 @@ #define RESISTOR_DIVIDER(v, r1, r2) (((v) * (r2)) / ((r1) + (r2))) -typedef struct { +typedef struct hwm_values_t { uint16_t fans[4]; uint8_t temperatures[4]; uint16_t voltages[13]; } hwm_values_t; -typedef struct { +typedef struct lm75_t { uint32_t local; hwm_values_t *values; void *as99127f; uint8_t regs[8]; uint8_t addr_register; - uint8_t i2c_addr : 7, i2c_state : 2; + uint8_t i2c_addr : 7; + uint8_t i2c_state : 2; uint8_t i2c_enabled : 1; } lm75_t; diff --git a/src/include/86box/i8080.h b/src/include/86box/i8080.h index a3f3fba64..b5ba3c7a4 100644 --- a/src/include/86box/i8080.h +++ b/src/include/86box/i8080.h @@ -21,31 +21,38 @@ typedef struct i8080 { union { uint16_t af; /* Intended in case we also go for μPD9002 emulation, which also has a Z80 emulation mode. */ struct { - uint8_t a, flags; + uint8_t a; + uint8_t flags; }; }; union { uint16_t bc; struct { - uint8_t b, c; + uint8_t b; + uint8_t c; }; }; union { uint16_t de; struct { - uint8_t d, e; + uint8_t d; + uint8_t e; }; }; union { uint16_t hl; struct { - uint8_t h, l; + uint8_t h; + uint8_t l; }; }; - uint16_t pc, sp; - uint16_t oldpc, ei; - uint32_t pmembase, dmembase; /* Base from where i8080 starts. */ - uint8_t emulated; /* 0 = not emulated, use separate registers, 1 = emulated, use x86 registers. */ + uint16_t pc; + uint16_t sp; + uint16_t oldpc; + uint16_t ei; + uint32_t pmembase; + uint32_t dmembase; /* Base from where i8080 starts. */ + uint8_t emulated; /* 0 = not emulated, use separate registers, 1 = emulated, use x86 registers. */ uint16_t *cpu_flags; void (*writemembyte)(uint32_t, uint8_t); uint8_t (*readmembyte)(uint32_t); diff --git a/src/include/86box/ini.h b/src/include/86box/ini.h index 5eca9ab8c..866787352 100644 --- a/src/include/86box/ini.h +++ b/src/include/86box/ini.h @@ -30,26 +30,26 @@ typedef void *ini_t; typedef void *ini_section_t; extern ini_t ini_new(void); -extern ini_t ini_read(char *fn); -extern void ini_write(ini_t ini, char *fn); +extern ini_t ini_read(const char *fn); +extern void ini_write(ini_t ini, const char *fn); extern void ini_dump(ini_t ini); extern void ini_close(ini_t ini); -extern void ini_section_delete_var(ini_section_t section, char *name); -extern int ini_section_get_int(ini_section_t section, char *name, int def); -extern double ini_section_get_double(ini_section_t section, char *name, double def); -extern int ini_section_get_hex16(ini_section_t section, char *name, int def); -extern int ini_section_get_hex20(ini_section_t section, char *name, int def); -extern int ini_section_get_mac(ini_section_t section, char *name, int def); -extern char *ini_section_get_string(ini_section_t section, char *name, char *def); -extern wchar_t *ini_section_get_wstring(ini_section_t section, char *name, wchar_t *def); -extern void ini_section_set_int(ini_section_t section, char *name, int val); -extern void ini_section_set_double(ini_section_t section, char *name, double val); -extern void ini_section_set_hex16(ini_section_t section, char *name, int val); -extern void ini_section_set_hex20(ini_section_t section, char *name, int val); -extern void ini_section_set_mac(ini_section_t section, char *name, int val); +extern void ini_section_delete_var(ini_section_t section, const char *name); +extern int ini_section_get_int(ini_section_t section, const char *name, int def); +extern double ini_section_get_double(ini_section_t section, const char *name, double def); +extern int ini_section_get_hex16(ini_section_t section, const char *name, int def); +extern int ini_section_get_hex20(ini_section_t section, const char *name, int def); +extern int ini_section_get_mac(ini_section_t section, const char *name, int def); +extern char *ini_section_get_string(ini_section_t section, const char *name, char *def); +extern wchar_t *ini_section_get_wstring(ini_section_t section, const char *name, wchar_t *def); +extern void ini_section_set_int(ini_section_t section, const char *name, int val); +extern void ini_section_set_double(ini_section_t section, const char *name, double val); +extern void ini_section_set_hex16(ini_section_t section, const char *name, int val); +extern void ini_section_set_hex20(ini_section_t section, const char *name, int val); +extern void ini_section_set_mac(ini_section_t section, const char *name, int val); extern void ini_section_set_string(ini_section_t section, const char *name, const char *val); -extern void ini_section_set_wstring(ini_section_t section, char *name, wchar_t *val); +extern void ini_section_set_wstring(ini_section_t section, const char *name, wchar_t *val); #define ini_delete_var(ini, head, name) ini_section_delete_var(ini_find_section(ini, head), name) @@ -69,13 +69,13 @@ extern void ini_section_set_wstring(ini_section_t section, char *name, wchar #define ini_set_string(ini, head, name, val) ini_section_set_string(ini_find_or_create_section(ini, head), name, val) #define ini_set_wstring(ini, head, name, val) ini_section_set_wstring(ini_find_or_create_section(ini, head), name, val) -extern ini_section_t ini_find_section(ini_t ini, char *name); -extern ini_section_t ini_find_or_create_section(ini_t ini, char *name); -extern void ini_rename_section(ini_section_t section, char *name); +extern ini_section_t ini_find_section(ini_t ini, const char *name); +extern ini_section_t ini_find_or_create_section(ini_t ini, const char *name); +extern void ini_rename_section(ini_section_t section, const char *name); extern void ini_delete_section_if_empty(ini_t ini, ini_section_t section); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/src/include/86box/isapnp.h b/src/include/86box/isapnp.h index 9fff876dc..71c1bb29a 100644 --- a/src/include/86box/isapnp.h +++ b/src/include/86box/isapnp.h @@ -25,27 +25,31 @@ #define ISAPNP_DMA_DISABLED 4 enum { - ISAPNP_CARD_DISABLE = 0, - ISAPNP_CARD_ENABLE = 1, - ISAPNP_CARD_FORCE_CONFIG, /* cheat code for UMC UM8669F */ - ISAPNP_CARD_NO_KEY /* cheat code for Crystal CS423x */ + ISAPNP_CARD_DISABLE = 0, + ISAPNP_CARD_ENABLE = 1, + ISAPNP_CARD_FORCE_CONFIG = 2, /* cheat code for UMC UM8669F */ + ISAPNP_CARD_NO_KEY = 3 /* cheat code for Crystal CS423x */ }; -typedef struct { +typedef struct isapnp_device_config_t { uint8_t activate; - struct { - uint32_t base : 24, size : 24; + struct pnp_mem_t { + uint32_t base : 24; + uint32_t size : 24; } mem[4]; - struct { - uint32_t base, size; + struct pnp_mem32_t { + uint32_t base; + uint32_t size; } mem32[4]; - struct { + struct pnp_io_t { uint16_t base; } io[8]; - struct { - uint8_t irq : 4, level : 1, type : 1; + struct pnp_irq_t { + uint8_t irq : 4; + uint8_t level : 1; + uint8_t type : 1; } irq[2]; - struct { + struct pnp_dma_t { uint8_t dma : 3; } dma[2]; } isapnp_device_config_t; diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index b89c4504d..b84733d9c 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -22,7 +22,73 @@ #ifndef EMU_KEYBOARD_H #define EMU_KEYBOARD_H -typedef struct { +enum { + DEV_KBD = 0, + DEV_AUX = 1 +}; + +enum { + DEV_STATE_MAIN_1 = 0, + DEV_STATE_MAIN_OUT = 1, + DEV_STATE_MAIN_2 = 2, + DEV_STATE_MAIN_CMD = 3, + DEV_STATE_MAIN_WANT_IN = 4, + DEV_STATE_MAIN_IN = 5, + DEV_STATE_EXECUTE_BAT = 6, + DEV_STATE_MAIN_WANT_EXECUTE_BAT = 7 +}; + +/* Used by the AT / PS/2 keyboard controller, common device, keyboard, and mouse. */ +typedef struct kbc_at_port_t { + uint8_t wantcmd; + uint8_t dat; + + int16_t out_new; + + void *priv; + + void (*poll)(void *priv); +} kbc_at_port_t; + +/* Used by the AT / PS/2 common device, keyboard, and mouse. */ +typedef struct atkbc_dev_t { + const char *name; /* name of this device */ + + uint8_t type; + uint8_t command; + uint8_t last_scan_code; + uint8_t state; + uint8_t resolution; + uint8_t rate; + uint8_t cmd_queue_start; + uint8_t cmd_queue_end; + uint8_t queue_start; + uint8_t queue_end; + + uint16_t flags; + + /* Internal FIFO, not present on real devices, needed for commands that + output multiple bytes. */ + uint8_t cmd_queue[16]; + + uint8_t queue[64]; + + int fifo_mask; + int mode; + int x; + int y; + int z; + int b; + + int *scan; + + void (*process_cmd)(void *priv); + void (*execute_bat)(void *priv); + + kbc_at_port_t *port; +} atkbc_dev_t; + +typedef struct scancode { const uint8_t mk[4]; const uint8_t brk[4]; } scancode; @@ -138,9 +204,14 @@ extern const scancode scancode_xt[512]; extern uint8_t keyboard_set3_flags[512]; extern uint8_t keyboard_set3_all_repeat; extern uint8_t keyboard_set3_all_break; -extern int mouse_queue_start, mouse_queue_end; +extern int mouse_queue_start; +extern int mouse_queue_end; +extern int mouse_cmd_queue_start; +extern int mouse_cmd_queue_end; extern int mouse_scan; +extern kbc_at_port_t *kbc_at_ports[2]; + #ifdef EMU_DEVICE_H extern const device_t keyboard_pc_device; extern const device_t keyboard_pc82_device; @@ -157,18 +228,21 @@ extern const device_t keyboard_xt_olivetti_device; extern const device_t keyboard_xt_zenith_device; extern const device_t keyboard_xtclone_device; extern const device_t keyboard_at_device; +extern const device_t keyboard_at_siemens_device; extern const device_t keyboard_at_ami_device; -extern const device_t keyboard_at_samsung_device; +extern const device_t keyboard_at_tg_ami_device; extern const device_t keyboard_at_toshiba_device; extern const device_t keyboard_at_olivetti_device; extern const device_t keyboard_at_ncr_device; +extern const device_t keyboard_at_compaq_device; extern const device_t keyboard_ps2_device; extern const device_t keyboard_ps2_ps1_device; extern const device_t keyboard_ps2_ps1_pci_device; extern const device_t keyboard_ps2_xi8088_device; extern const device_t keyboard_ps2_ami_device; +extern const device_t keyboard_ps2_tg_ami_device; +extern const device_t keyboard_ps2_tg_ami_green_device; extern const device_t keyboard_ps2_olivetti_device; -extern const device_t keyboard_ps2_mca_device; extern const device_t keyboard_ps2_mca_2_device; extern const device_t keyboard_ps2_quadtel_device; extern const device_t keyboard_ps2_pci_device; @@ -176,6 +250,9 @@ extern const device_t keyboard_ps2_ami_pci_device; extern const device_t keyboard_ps2_intel_ami_pci_device; extern const device_t keyboard_ps2_acer_pci_device; extern const device_t keyboard_ps2_ali_pci_device; +extern const device_t keyboard_ps2_tg_ami_pci_device; + +extern const device_t keyboard_at_generic_device; #endif /*EMU_DEVICE_H*/ extern void keyboard_init(void); @@ -190,22 +267,17 @@ extern uint8_t keyboard_get_shift(void); extern void keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl); extern void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl); extern int keyboard_recv(uint16_t key); +extern int keyboard_isfsenter(void); +extern int keyboard_isfsenter_up(void); extern int keyboard_isfsexit(void); +extern int keyboard_isfsexit_up(void); extern int keyboard_ismsexit(void); extern void keyboard_set_is_amstrad(int ams); -extern void keyboard_at_adddata_mouse(uint8_t val); -extern void keyboard_at_adddata_mouse_direct(uint8_t val); -extern void keyboard_at_adddata_mouse_cmd(uint8_t val); -extern void keyboard_at_mouse_reset(void); -extern uint8_t keyboard_at_mouse_pos(void); -extern int keyboard_at_fixed_channel(void); -extern void keyboard_at_set_mouse(void (*mouse_write)(uint8_t val, void *), void *); -extern void keyboard_at_set_a20_key(int state); -extern void keyboard_at_set_mode(int ps2); -extern uint8_t keyboard_at_get_mouse_scan(void); -extern void keyboard_at_set_mouse_scan(uint8_t val); -extern void keyboard_at_reset(void); +extern uint8_t kbc_at_dev_queue_pos(atkbc_dev_t *dev, uint8_t main); +extern void kbc_at_dev_queue_add(atkbc_dev_t *dev, uint8_t val, uint8_t main); +extern void kbc_at_dev_reset(atkbc_dev_t *dev, int do_fa); +extern atkbc_dev_t *kbc_at_dev_init(uint8_t inst); #ifdef __cplusplus } diff --git a/src/include/86box/language.h b/src/include/86box/language.h index e3ffd1db9..af459c0ff 100644 --- a/src/include/86box/language.h +++ b/src/include/86box/language.h @@ -52,7 +52,6 @@ #define IDS_2077 2077 // "Click to capture mouse" #define IDS_2078 2078 // "Press F12-F8 to release mouse" #define IDS_2079 2079 // "Press F12-F8 or middle button.." -#define IDS_2080 2080 // "Unable to initialize Flui.." #define IDS_2081 2081 // "Bus" #define IDS_BUS IDS_2081 // "Bus" #define IDS_2082 2082 // "File" @@ -69,7 +68,7 @@ #define IDS_2089 2089 // "KB" #define IDS_KB IDS_2089 // "KB" -#define IDS_2090 2090 // "Could not initialize the video..." +#define IDS_2090 2090 // "Could not initialize the video..." #define IDS_2091 2091 // "Default" #define IDS_DEFAULT IDS_2091 // "Default" @@ -81,78 +80,75 @@ #define IDS_TYPE IDS_2093 // "Type" /* TODO */ -#define IDS_2094 2094 // "PCap failed to set up.." -#define IDS_2095 2095 // "No PCap devices found" -#define IDS_2096 2096 // "Invalid PCap device" -#define IDS_2097 2097 // "Standard 2-button joystick(s)" -#define IDS_2098 2098 // "Standard 4-button joystick" -#define IDS_2099 2099 // "Standard 6-button joystick" -#define IDS_2100 2100 // "Standard 8-button joystick" -#define IDS_2101 2101 // "CH Flightstick Pro" -#define IDS_2102 2102 // "Microsoft SideWinder Pad" -#define IDS_2103 2103 // "Thrustmaster Flight Cont.." -#define IDS_2104 2104 // "None" -#define IDS_2105 2105 // "Unable to load keyboard..." -#define IDS_2106 2106 // "Unable to register raw input." -#define IDS_2107 2107 // "%u" -#define IDS_2108 2108 // "%u MB (CHS: %i, %i, %i)" -#define IDS_2109 2109 // "Floppy %i (%s): %ls" -#define IDS_2110 2110 // "All floppy images (*.0??;*.." -#define IDS_2111 2111 // "Unable to initialize Free.." -#define IDS_2112 2112 // "Unable to initialize SDL..." -#define IDS_2113 2113 // "Are you sure you want to..." -#define IDS_2114 2114 // "Are you sure you want to..." -#define IDS_2115 2115 // "Unable to initialize Ghostscript..." -#define IDS_2116 2116 // "MO %i (%03i): %ls" -#define IDS_2117 2117 // "MO images (*.IM?)\0*.IM..." -#define IDS_2118 2118 // "Welcome to 86Box!" -#define IDS_2119 2119 // "Internal controller" -#define IDS_2120 2120 // "Exit" -#define IDS_2121 2121 // "No ROMs found" -#define IDS_2122 2122 // "Do you want to save the settings?" -#define IDS_2123 2123 // "This will hard reset the emulated..." -#define IDS_2124 2124 // "Save" -#define IDS_2125 2125 // "About 86Box" -#define IDS_2126 2126 // "86Box v" EMU_VERSION -#define IDS_2127 2127 // "An emulator of old computers..." -#define IDS_2128 2128 // "OK" -#define IDS_2129 2129 // "Hardware not available" -#define IDS_2130 2130 // "Make sure " LIB_NAME_PCAP "..." -#define IDS_2131 2131 // "Invalid configuration" -#define IDS_2132 2132 // LIB_NAME_FREETYPE " is required..." -#define IDS_2133 2133 // LIB_NAME_GS " is required for... -#define IDS_2134 2134 // LIB_NAME_FLUIDSYNTH " is required..." -#define IDS_2135 2135 // "Entering fullscreen mode" -#define IDS_2136 2136 // "Don't show this message again" -#define IDS_2137 2137 // "Don't exit" -#define IDS_2138 2138 // "Reset" -#define IDS_2139 2139 // "Don't reset" -#define IDS_2140 2140 // "MO images (*.IM?)\0*.IM?..." -#define IDS_2141 2141 // "CD-ROM images (*.ISO;*.CU.." -#define IDS_2142 2142 // "%hs Device Configuration" -#define IDS_2143 2143 // "Monitor in sleep mode" -#define IDS_2144 2144 // "OpenGL Shaders (*.GLSL)..." -#define IDS_2145 2145 // "OpenGL options" -#define IDS_2146 2146 // "You are loading an unsupported..." -#define IDS_2147 2147 // "CPU type filtering based on..." -#define IDS_2148 2148 // "Continue" -#define IDS_2149 2149 // "Cassette: %s" -#define IDS_2150 2150 // "Cassette images (*.PCM;*.RAW;*..." -#define IDS_2151 2151 // "Cartridge %i: %ls" -#define IDS_2152 2152 // "Cartridge images (*.JRC)\0*.JRC\0..." -#define IDS_2153 2153 // "Error initializing renderer" -#define IDS_2154 2154 // "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -#define IDS_2155 2155 // "Resume execution" -#define IDS_2156 2156 // "Pause execution" -#define IDS_2157 2157 // "Press Ctrl+Alt+Del" -#define IDS_2158 2158 // "Press Ctrl+Alt+Esc" -#define IDS_2159 2159 // "Hard reset" -#define IDS_2160 2160 // "ACPI shutdown" -#define IDS_2161 2161 // "Settings" -#define IDS_2162 2162 // "Early drive" -#define IDS_2163 2163 // "no dynarec" -#define IDS_2164 2164 // "old dynarec" -#define IDS_2165 2165 // "new dynarec" +#define IDS_2094 2094 // "PCap failed to set up.." +#define IDS_2095 2095 // "No PCap devices found" +#define IDS_2096 2096 // "Invalid PCap device" +#define IDS_2097 2097 // "Standard 2-button joystick(s)" +#define IDS_2098 2098 // "Standard 4-button joystick" +#define IDS_2099 2099 // "Standard 6-button joystick" +#define IDS_2100 2100 // "Standard 8-button joystick" +#define IDS_2101 2101 // "CH Flightstick Pro" +#define IDS_2102 2102 // "Microsoft SideWinder Pad" +#define IDS_2103 2103 // "Thrustmaster Flight Cont.." +#define IDS_2104 2104 // "None" +#define IDS_2105 2105 // "Unable to load keyboard..." +#define IDS_2106 2106 // "Unable to register raw input." +#define IDS_2107 2107 // "%u" +#define IDS_2108 2108 // "%u MB (CHS: %i, %i, %i)" +#define IDS_2109 2109 // "Floppy %i (%s): %ls" +#define IDS_2110 2110 // "All floppy images (*.0??;*.." +#define IDS_2112 2112 // "Unable to initialize SDL..." +#define IDS_2113 2113 // "Are you sure you want to..." +#define IDS_2114 2114 // "Are you sure you want to..." +#define IDS_2115 2115 // "Unable to initialize Ghostscript..." +#define IDS_2116 2116 // "MO %i (%03i): %ls" +#define IDS_2117 2117 // "MO images (*.IM?)\0*.IM..." +#define IDS_2118 2118 // "Welcome to 86Box!" +#define IDS_2119 2119 // "Internal controller" +#define IDS_2120 2120 // "Exit" +#define IDS_2121 2121 // "No ROMs found" +#define IDS_2122 2122 // "Do you want to save the settings?" +#define IDS_2123 2123 // "This will hard reset the emulated..." +#define IDS_2124 2124 // "Save" +#define IDS_2125 2125 // "About 86Box" +#define IDS_2126 2126 // "86Box v" EMU_VERSION +#define IDS_2127 2127 // "An emulator of old computers..." +#define IDS_2128 2128 // "OK" +#define IDS_2129 2129 // "Hardware not available" +#define IDS_2130 2130 // "Make sure " LIB_NAME_PCAP "..." +#define IDS_2131 2131 // "Invalid configuration" +#define IDS_2133 2133 // LIB_NAME_GS " is required for... +#define IDS_2135 2135 // "Entering fullscreen mode" +#define IDS_2136 2136 // "Don't show this message again" +#define IDS_2137 2137 // "Don't exit" +#define IDS_2138 2138 // "Reset" +#define IDS_2139 2139 // "Don't reset" +#define IDS_2140 2140 // "MO images (*.IM?)\0*.IM?..." +#define IDS_2141 2141 // "CD-ROM images (*.ISO;*.CU.." +#define IDS_2142 2142 // "%hs Device Configuration" +#define IDS_2143 2143 // "Monitor in sleep mode" +#define IDS_2144 2144 // "OpenGL Shaders (*.GLSL)..." +#define IDS_2145 2145 // "OpenGL options" +#define IDS_2146 2146 // "You are loading an unsupported..." +#define IDS_2147 2147 // "CPU type filtering based on..." +#define IDS_2148 2148 // "Continue" +#define IDS_2149 2149 // "Cassette: %s" +#define IDS_2150 2150 // "Cassette images (*.PCM;*.RAW;*..." +#define IDS_2151 2151 // "Cartridge %i: %ls" +#define IDS_2152 2152 // "Cartridge images (*.JRC)\0*.JRC\0..." +#define IDS_2153 2153 // "Error initializing renderer" +#define IDS_2154 2154 // "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." +#define IDS_2155 2155 // "Resume execution" +#define IDS_2156 2156 // "Pause execution" +#define IDS_2157 2157 // "Press Ctrl+Alt+Del" +#define IDS_2158 2158 // "Press Ctrl+Alt+Esc" +#define IDS_2159 2159 // "Hard reset" +#define IDS_2160 2160 // "ACPI shutdown" +#define IDS_2161 2161 // "Settings" +#define IDS_2162 2162 // "Early drive" +#define IDS_2163 2163 // "no dynarec" +#define IDS_2164 2164 // "old dynarec" +#define IDS_2165 2165 // "new dynarec" #ifdef USE_DYNAREC # ifdef USE_NEW_DYNAREC # define IDS_DYNAREC IDS_2165 @@ -162,116 +158,118 @@ #else # define IDS_DYNAREC IDS_2163 #endif -#define IDS_2166 2166 // "Video card #2 ""%hs"" is not..." +#define IDS_2166 2166 // "Video card #2 ""%hs"" is not..." +#define IDS_2167 2167 // "Network driver initialization failed" +#define IDS_2168 2168 // "The network configuration will be switched to the null driver" -#define IDS_4096 4096 // "Hard disk (%s)" -#define IDS_4097 4097 // "%01i:%01i" -#define IDS_4098 4098 // "%i" -#define IDS_4099 4099 // "MFM/RLL or ESDI CD-ROM driv.." -#define IDS_4100 4100 // "Custom..." -#define IDS_4101 4101 // "Custom (large)..." -#define IDS_4102 4102 // "Add New Hard Disk" -#define IDS_4103 4103 // "Add Existing Hard Disk" -#define IDS_4104 4104 // "HDI disk images cannot be..." -#define IDS_4105 4105 // "Disk images cannot be larger..." -#define IDS_4106 4106 // "Hard disk images (*.HDI;*.HD.." -#define IDS_4107 4107 // "Unable to open the file for read" -#define IDS_4108 4108 // "Unable to open the file for write" -#define IDS_4109 4109 // "HDI or HDX image with a sect.." -#define IDS_4110 4110 // "USB is not yet supported" -#define IDS_4111 4111 // "Disk image file already exists" -#define IDS_4112 4112 // "Please specify a valid file name." -#define IDS_4113 4113 // "Remember to partition and fo.." -#define IDS_4114 4114 // "Make sure the file exists and..." -#define IDS_4115 4115 // "Make sure the file is being..." -#define IDS_4116 4116 // "Disk image too large" -#define IDS_4117 4117 // "Remember to partition and format..." -#define IDS_4118 4118 // "The selected file will be..." -#define IDS_4119 4119 // "Unsupported disk image" -#define IDS_4120 4120 // "Overwrite" -#define IDS_4121 4121 // "Don't overwrite" -#define IDS_4122 4122 // "Raw image (.img)" -#define IDS_4123 4123 // "HDI image (.hdi)" -#define IDS_4124 4124 // "HDX image (.hdx)" -#define IDS_4125 4125 // "Fixed-size VHD (.vhd)" -#define IDS_4126 4126 // "Dynamic-size VHD (.vhd)" -#define IDS_4127 4127 // "Differencing VHD (.vhd)" -#define IDS_4128 4128 // "Large blocks (2 MB)" -#define IDS_4129 4129 // "Small blocks (512 KB)" -#define IDS_4130 4130 // "VHD files (*.VHD)\0*.VHD\0All..." -#define IDS_4131 4131 // "Select the parent VHD" -#define IDS_4132 4132 // "This could mean that the parent..." -#define IDS_4133 4133 // "Parent and child disk timestamps..." -#define IDS_4134 4134 // "Could not fix VHD timestamp." -#define IDS_4135 4135 // "%01i:%02i" +#define IDS_4096 4096 // "Hard disk (%s)" +#define IDS_4097 4097 // "%01i:%01i" +#define IDS_4098 4098 // "%i" +#define IDS_4099 4099 // "MFM/RLL or ESDI CD-ROM driv.." +#define IDS_4100 4100 // "Custom..." +#define IDS_4101 4101 // "Custom (large)..." +#define IDS_4102 4102 // "Add New Hard Disk" +#define IDS_4103 4103 // "Add Existing Hard Disk" +#define IDS_4104 4104 // "HDI disk images cannot be..." +#define IDS_4105 4105 // "Disk images cannot be larger..." +#define IDS_4106 4106 // "Hard disk images (*.HDI;*.HD.." +#define IDS_4107 4107 // "Unable to open the file for read" +#define IDS_4108 4108 // "Unable to open the file for write" +#define IDS_4109 4109 // "HDI or HDX image with a sect.." +#define IDS_4110 4110 // "USB is not yet supported" +#define IDS_4111 4111 // "Disk image file already exists" +#define IDS_4112 4112 // "Please specify a valid file name." +#define IDS_4113 4113 // "Remember to partition and fo.." +#define IDS_4114 4114 // "Make sure the file exists and..." +#define IDS_4115 4115 // "Make sure the file is being..." +#define IDS_4116 4116 // "Disk image too large" +#define IDS_4117 4117 // "Remember to partition and format..." +#define IDS_4118 4118 // "The selected file will be..." +#define IDS_4119 4119 // "Unsupported disk image" +#define IDS_4120 4120 // "Overwrite" +#define IDS_4121 4121 // "Don't overwrite" +#define IDS_4122 4122 // "Raw image (.img)" +#define IDS_4123 4123 // "HDI image (.hdi)" +#define IDS_4124 4124 // "HDX image (.hdx)" +#define IDS_4125 4125 // "Fixed-size VHD (.vhd)" +#define IDS_4126 4126 // "Dynamic-size VHD (.vhd)" +#define IDS_4127 4127 // "Differencing VHD (.vhd)" +#define IDS_4128 4128 // "Large blocks (2 MB)" +#define IDS_4129 4129 // "Small blocks (512 KB)" +#define IDS_4130 4130 // "VHD files (*.VHD)\0*.VHD\0All..." +#define IDS_4131 4131 // "Select the parent VHD" +#define IDS_4132 4132 // "This could mean that the parent..." +#define IDS_4133 4133 // "Parent and child disk timestamps..." +#define IDS_4134 4134 // "Could not fix VHD timestamp." +#define IDS_4135 4135 // "%01i:%02i" -#define IDS_4352 4352 // "MFM/RLL" -#define IDS_4353 4353 // "XT IDE" -#define IDS_4354 4354 // "ESDI" -#define IDS_4355 4355 // "IDE" -#define IDS_4356 4356 // "ATAPI" -#define IDS_4357 4357 // "SCSI" +#define IDS_4352 4352 // "MFM/RLL" +#define IDS_4353 4353 // "XT IDE" +#define IDS_4354 4354 // "ESDI" +#define IDS_4355 4355 // "IDE" +#define IDS_4356 4356 // "ATAPI" +#define IDS_4357 4357 // "SCSI" -#define IDS_4608 4608 // "MFM/RLL (%01i:%01i)" -#define IDS_4609 4609 // "XT IDE (%01i:%01i)" -#define IDS_4610 4610 // "ESDI (%01i:%01i)" -#define IDS_4611 4611 // "IDE (%01i:%01i)" -#define IDS_4612 4612 // "ATAPI (%01i:%01i)" -#define IDS_4613 4613 // "SCSI (%02i:%02i)" +#define IDS_4608 4608 // "MFM/RLL (%01i:%01i)" +#define IDS_4609 4609 // "XT IDE (%01i:%01i)" +#define IDS_4610 4610 // "ESDI (%01i:%01i)" +#define IDS_4611 4611 // "IDE (%01i:%01i)" +#define IDS_4612 4612 // "ATAPI (%01i:%01i)" +#define IDS_4613 4613 // "SCSI (%02i:%02i)" -#define IDS_5120 5120 // "CD-ROM %i (%s): %s" +#define IDS_5120 5120 // "CD-ROM %i (%s): %s" -#define IDS_5376 5376 // "Disabled" -#define IDS_5377 5377 // -#define IDS_5378 5378 // -#define IDS_5379 5379 // -#define IDS_5380 5380 // -#define IDS_5381 5381 // "ATAPI" -#define IDS_5382 5382 // "SCSI" +#define IDS_5376 5376 // "Disabled" +#define IDS_5377 5377 // +#define IDS_5378 5378 // +#define IDS_5379 5379 // +#define IDS_5380 5380 // +#define IDS_5381 5381 // "ATAPI" +#define IDS_5382 5382 // "SCSI" -#define IDS_5632 5632 // "Disabled" -#define IDS_5633 5633 // -#define IDS_5634 5634 // -#define IDS_5635 5635 // -#define IDS_5636 5636 // -#define IDS_5637 5637 // "ATAPI (%01i:%01i)" -#define IDS_5638 5638 // "SCSI (%02i:%02i)" +#define IDS_5632 5632 // "Disabled" +#define IDS_5633 5633 // +#define IDS_5634 5634 // +#define IDS_5635 5635 // +#define IDS_5636 5636 // +#define IDS_5637 5637 // "ATAPI (%01i:%01i)" +#define IDS_5638 5638 // "SCSI (%02i:%02i)" -#define IDS_5888 5888 // "160 kB" -#define IDS_5889 5889 // "180 kB" -#define IDS_5890 5890 // "320 kB" -#define IDS_5891 5891 // "360 kB" -#define IDS_5892 5892 // "640 kB" -#define IDS_5893 5893 // "720 kB" -#define IDS_5894 5894 // "1.2 MB" -#define IDS_5895 5895 // "1.25 MB" -#define IDS_5896 5896 // "1.44 MB" -#define IDS_5897 5897 // "DMF (cluster 1024)" -#define IDS_5898 5898 // "DMF (cluster 2048)" -#define IDS_5899 5899 // "2.88 MB" -#define IDS_5900 5900 // "ZIP 100" -#define IDS_5901 5901 // "ZIP 250" -#define IDS_5902 5902 // "3.5\" 128 MB (ISO 10090)" -#define IDS_5903 5903 // "3.5\" 230 MB (ISO 13963)" -#define IDS_5904 5904 // "3.5\" 540 MB (ISO 15498)" -#define IDS_5905 5905 // "3.5\" 640 MB (ISO 15498)" -#define IDS_5906 5906 // "3.5\" 1.3 GB (GigaMO)" -#define IDS_5907 5907 // "3.5\" 2.3 GB (GigaMO 2)" -#define IDS_5908 5908 // "5.25\" 600 MB" -#define IDS_5909 5909 // "5.25\" 650 MB" -#define IDS_5910 5910 // "5.25\" 1 GB" -#define IDS_5911 5911 // "5.25\" 1.3 GB" +#define IDS_5888 5888 // "160 kB" +#define IDS_5889 5889 // "180 kB" +#define IDS_5890 5890 // "320 kB" +#define IDS_5891 5891 // "360 kB" +#define IDS_5892 5892 // "640 kB" +#define IDS_5893 5893 // "720 kB" +#define IDS_5894 5894 // "1.2 MB" +#define IDS_5895 5895 // "1.25 MB" +#define IDS_5896 5896 // "1.44 MB" +#define IDS_5897 5897 // "DMF (cluster 1024)" +#define IDS_5898 5898 // "DMF (cluster 2048)" +#define IDS_5899 5899 // "2.88 MB" +#define IDS_5900 5900 // "ZIP 100" +#define IDS_5901 5901 // "ZIP 250" +#define IDS_5902 5902 // "3.5\" 128 MB (ISO 10090)" +#define IDS_5903 5903 // "3.5\" 230 MB (ISO 13963)" +#define IDS_5904 5904 // "3.5\" 540 MB (ISO 15498)" +#define IDS_5905 5905 // "3.5\" 640 MB (ISO 15498)" +#define IDS_5906 5906 // "3.5\" 1.3 GB (GigaMO)" +#define IDS_5907 5907 // "3.5\" 2.3 GB (GigaMO 2)" +#define IDS_5908 5908 // "5.25\" 600 MB" +#define IDS_5909 5909 // "5.25\" 650 MB" +#define IDS_5910 5910 // "5.25\" 1 GB" +#define IDS_5911 5911 // "5.25\" 1.3 GB" -#define IDS_6144 6144 // "Perfect RPM" -#define IDS_6145 6145 // "1%% below perfect RPM" -#define IDS_6146 6146 // "1.5%% below perfect RPM" -#define IDS_6147 6147 // "2%% below perfect RPM" +#define IDS_6144 6144 // "Perfect RPM" +#define IDS_6145 6145 // "1%% below perfect RPM" +#define IDS_6146 6146 // "1.5%% below perfect RPM" +#define IDS_6147 6147 // "2%% below perfect RPM" -#define IDS_7168 7168 // "(System Default)" +#define IDS_7168 7168 // "(System Default)" #define IDS_LANG_ENUS IDS_7168 -#define STR_NUM_2048 118 +#define STR_NUM_2048 121 // UNUSED: #define STR_NUM_3072 11 #define STR_NUM_4096 40 #define STR_NUM_4352 6 diff --git a/src/include/86box/lpt.h b/src/include/86box/lpt.h index cb8fc7cc6..4c1c793ae 100644 --- a/src/include/86box/lpt.h +++ b/src/include/86box/lpt.h @@ -10,15 +10,14 @@ #define LPT_MDA_IRQ 7 #define LPT4_ADDR 0x0268 #define LPT4_IRQ 5 -/* +#if 0 #define LPT5_ADDR 0x027c #define LPT5_IRQ 7 #define LPT6_ADDR 0x026c #define LPT6_IRQ 5 -*/ +#endif -typedef struct -{ +typedef struct lpt_device_t { const char *name; const char *internal_name; @@ -53,7 +52,7 @@ extern void lpt1_remove_ams(void); #define lpt4_irq(a) lpt_port_irq(3, a) #define lpt4_remove() lpt_port_remove(3) -/* +#if 0 #define lpt5_init(a) lpt_port_init(4, a) #define lpt5_irq(a) lpt_port_irq(4, a) #define lpt5_remove() lpt_port_remove(4) @@ -61,16 +60,20 @@ extern void lpt1_remove_ams(void); #define lpt6_init(a) lpt_port_init(5, a) #define lpt6_irq(a) lpt_port_irq(5, a) #define lpt6_remove() lpt_port_remove(5) -*/ +#endif void lpt_devices_init(void); void lpt_devices_close(void); typedef struct { - uint8_t enabled, irq, - dat, ctrl; - uint16_t addr, pad0; - int device, enable_irq; + uint8_t enabled; + uint8_t irq; + uint8_t dat; + uint8_t ctrl; + uint16_t addr; + uint16_t pad0; + int device; + int enable_irq; lpt_device_t *dt; void *priv; } lpt_port_t; diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 4d1effe9a..7e17c270f 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -26,18 +26,22 @@ #define MACHINE_BUS_NONE 0x00000000 /* sys has no bus */ /* Feature flags for BUS'es. */ #define MACHINE_BUS_ISA 0x00000001 /* sys has ISA bus */ -#define MACHINE_BUS_CARTRIDGE 0x00000002 /* sys has two cartridge bays */ -#define MACHINE_BUS_ISA16 0x00000004 /* sys has ISA16 bus - PC/AT architecture */ -#define MACHINE_BUS_CBUS 0x00000008 /* sys has C-BUS bus */ -#define MACHINE_BUS_PS2 0x00000010 /* system has PS/2 keyboard and mouse ports */ -#define MACHINE_BUS_EISA 0x00000020 /* sys has EISA bus */ -#define MACHINE_BUS_VLB 0x00000040 /* sys has VL bus */ -#define MACHINE_BUS_MCA 0x00000080 /* sys has MCA bus */ -#define MACHINE_BUS_PCI 0x00000100 /* sys has PCI bus */ -#define MACHINE_BUS_PCMCIA 0x00000200 /* sys has PCMCIA bus */ -#define MACHINE_BUS_AGP 0x00000400 /* sys has AGP bus */ -#define MACHINE_BUS_AC97 0x00000800 /* sys has AC97 bus (ACR/AMR/CNR slot) */ +#define MACHINE_BUS_CASSETTE 0x00000002 /* sys has cassette port */ +#define MACHINE_BUS_CARTRIDGE 0x00000004 /* sys has two cartridge bays */ +#define MACHINE_BUS_ISA16 0x00000008 /* sys has ISA16 bus - PC/AT architecture */ +#define MACHINE_BUS_CBUS 0x00000010 /* sys has C-BUS bus */ +#define MACHINE_BUS_PS2_LATCH 0x00000020 /* system has PS/2 keyboard controller IRQ latch */ +#define MACHINE_BUS_PS2_PORTS 0x00000040 /* system has PS/2 keyboard and mouse ports */ +#define MACHINE_BUS_PS2 (MACHINE_BUS_PS2_LATCH | MACHINE_BUS_PS2_PORTS) +#define MACHINE_BUS_EISA 0x00000080 /* sys has EISA bus */ +#define MACHINE_BUS_VLB 0x00000100 /* sys has VL bus */ +#define MACHINE_BUS_MCA 0x00000200 /* sys has MCA bus */ +#define MACHINE_BUS_PCI 0x00000400 /* sys has PCI bus */ +#define MACHINE_BUS_PCMCIA 0x00000800 /* sys has PCMCIA bus */ +#define MACHINE_BUS_AGP 0x00001000 /* sys has AGP bus */ +#define MACHINE_BUS_AC97 0x00002000 /* sys has AC97 bus (ACR/AMR/CNR slot) */ /* Aliases. */ +#define MACHINE_CASSETTE (MACHINE_BUS_CASSETTE) /* sys has cassette port */ #define MACHINE_CARTRIDGE (MACHINE_BUS_CARTRIDGE) /* sys has two cartridge bays */ /* Combined flags. */ #define MACHINE_PC (MACHINE_BUS_ISA) /* sys is PC/XT-compatible (ISA) */ @@ -57,16 +61,17 @@ #define MACHINE_AGP (MACHINE_BUS_AGP | MACHINE_PCI) /* sys is AT-compatible with AGP */ #define MACHINE_AGP98 (MACHINE_BUS_AGP | MACHINE_PCI98) /* sys is NEC PC-98x1 series with AGP (did that even exist?) */ -#define MACHINE_PCJR (MACHINE_PC | MACHINE_CARTRIDGE) /* sys is PCjr */ -#define MACHINE_PS2 (MACHINE_AT | MACHINE_BUS_PS2) /* sys is PS/2 */ -#define MACHINE_PS2_MCA (MACHINE_MCA | MACHINE_BUS_PS2) /* sys is MCA PS/2 */ -#define MACHINE_PS2_VLB (MACHINE_VLB | MACHINE_BUS_PS2) /* sys is VLB PS/2 */ -#define MACHINE_PS2_PCI (MACHINE_PCI | MACHINE_BUS_PS2) /* sys is PCI PS/2 */ -#define MACHINE_PS2_PCIV (MACHINE_PCIV | MACHINE_BUS_PS2) /* sys is VLB/PCI PS/2 */ -#define MACHINE_PS2_AGP (MACHINE_AGP | MACHINE_BUS_PS2) /* sys is AGP PS/2 */ -#define MACHINE_PS2_A97 (MACHINE_PS2_AGP | MACHINE_BUS_AC97) /* sys is AGP/AC97 PS/2 */ -#define MACHINE_PS2_NOISA (MACHINE_PS2_AGP & ~MACHINE_AT) /* sys is AGP PS/2 without ISA */ -#define MACHINE_PS2_NOI97 (MACHINE_PS2_A97 & ~MACHINE_AT) /* sys is AGP/AC97 PS/2 without ISA */ +#define MACHINE_PC5150 (MACHINE_PC | MACHINE_CASSETTE) /* sys is IBM PC 5150 */ +#define MACHINE_PCJR (MACHINE_PC | MACHINE_CASSETTE | MACHINE_CARTRIDGE) /* sys is PCjr */ +#define MACHINE_PS2 (MACHINE_AT | MACHINE_BUS_PS2) /* sys is PS/2 */ +#define MACHINE_PS2_MCA (MACHINE_MCA | MACHINE_BUS_PS2) /* sys is MCA PS/2 */ +#define MACHINE_PS2_VLB (MACHINE_VLB | MACHINE_BUS_PS2) /* sys is VLB PS/2 */ +#define MACHINE_PS2_PCI (MACHINE_PCI | MACHINE_BUS_PS2) /* sys is PCI PS/2 */ +#define MACHINE_PS2_PCIV (MACHINE_PCIV | MACHINE_BUS_PS2) /* sys is VLB/PCI PS/2 */ +#define MACHINE_PS2_AGP (MACHINE_AGP | MACHINE_BUS_PS2) /* sys is AGP PS/2 */ +#define MACHINE_PS2_A97 (MACHINE_PS2_AGP | MACHINE_BUS_AC97) /* sys is AGP/AC97 PS/2 */ +#define MACHINE_PS2_NOISA (MACHINE_PS2_AGP & ~MACHINE_AT) /* sys is AGP PS/2 without ISA */ +#define MACHINE_PS2_NOI97 (MACHINE_PS2_A97 & ~MACHINE_AT) /* sys is AGP/AC97 PS/2 without ISA */ /* Feature flags for miscellaneous internal devices. */ #define MACHINE_FLAGS_NONE 0x00000000 /* sys has no int devices */ #define MACHINE_VIDEO 0x00000001 /* sys has int video */ @@ -95,19 +100,20 @@ #define MACHINE_AV (MACHINE_VIDEO | MACHINE_SOUND) /* sys has video and sound */ #define MACHINE_AG (MACHINE_SOUND | MACHINE_GAMEPORT) /* sys has sound and game port */ /* Feature flags for internal storage controllers. */ -#define MACHINE_HDC 0x03FE0000 /* sys has int HDC */ -#define MACHINE_MFM 0x00020000 /* sys has int MFM/RLL */ -#define MACHINE_XTA 0x00040000 /* sys has int XTA */ -#define MACHINE_ESDI 0x00080000 /* sys has int ESDI */ -#define MACHINE_IDE_PRI 0x00100000 /* sys has int pri IDE/ATAPI */ -#define MACHINE_IDE_SEC 0x00200000 /* sys has int sec IDE/ATAPI */ -#define MACHINE_IDE_TER 0x00400000 /* sys has int ter IDE/ATAPI */ -#define MACHINE_IDE_QUA 0x00800000 /* sys has int qua IDE/ATAPI */ -#define MACHINE_SCSI_PRI 0x01000000 /* sys has int pri SCSI */ -#define MACHINE_SCSI_SEC 0x02000000 /* sys has int sec SCSI */ -#define MACHINE_USB_PRI 0x04000000 /* sys has int pri USB */ -#define MACHINE_USB_SEC 0x08000000 /* sys has int sec USB */ -#define MACHINE_COREBOOT 0x10000000 /* sys has coreboot BIOS */ +#define MACHINE_HDC 0x03FE0000 /* sys has int HDC */ +#define MACHINE_MFM 0x00020000 /* sys has int MFM/RLL */ +#define MACHINE_XTA 0x00040000 /* sys has int XTA */ +#define MACHINE_ESDI 0x00080000 /* sys has int ESDI */ +#define MACHINE_IDE_PRI 0x00100000 /* sys has int pri IDE/ATAPI */ +#define MACHINE_IDE_SEC 0x00200000 /* sys has int sec IDE/ATAPI */ +#define MACHINE_IDE_TER 0x00400000 /* sys has int ter IDE/ATAPI */ +#define MACHINE_IDE_QUA 0x00800000 /* sys has int qua IDE/ATAPI */ +#define MACHINE_SCSI_PRI 0x01000000 /* sys has int pri SCSI */ +#define MACHINE_SCSI_SEC 0x02000000 /* sys has int sec SCSI */ +#define MACHINE_USB_PRI 0x04000000 /* sys has int pri USB */ +#define MACHINE_USB_SEC 0x08000000 /* sys has int sec USB */ +#define MACHINE_COREBOOT 0x10000000 /* sys has coreboot BIOS */ +#define MACHINE_SOFTFLOAT_ONLY 0x20000000 /* sys requires softfloat FPU */ /* Combined flags. */ #define MACHINE_IDE (MACHINE_IDE_PRI) /* sys has int single IDE/ATAPI - mark as pri IDE/ATAPI */ #define MACHINE_IDE_DUAL (MACHINE_IDE_PRI | MACHINE_IDE_SEC) /* sys has int dual IDE/ATAPI - mark as both pri and sec IDE/ATAPI */ @@ -143,31 +149,31 @@ #endif enum { - MACHINE_TYPE_NONE = 0, - MACHINE_TYPE_8088, - MACHINE_TYPE_8086, - MACHINE_TYPE_286, - MACHINE_TYPE_386SX, - MACHINE_TYPE_486SLC, - MACHINE_TYPE_386DX, - MACHINE_TYPE_386DX_486, - MACHINE_TYPE_486, - MACHINE_TYPE_486_S2, - MACHINE_TYPE_486_S3, - MACHINE_TYPE_486_MISC, - MACHINE_TYPE_SOCKET4, - MACHINE_TYPE_SOCKET5, - MACHINE_TYPE_SOCKET7_3V, - MACHINE_TYPE_SOCKET7, - MACHINE_TYPE_SOCKETS7, - MACHINE_TYPE_SOCKET8, - MACHINE_TYPE_SLOT1, - MACHINE_TYPE_SLOT1_2, - MACHINE_TYPE_SLOT1_370, - MACHINE_TYPE_SLOT2, - MACHINE_TYPE_SOCKET370, - MACHINE_TYPE_MISC, - MACHINE_TYPE_MAX + MACHINE_TYPE_NONE = 0, + MACHINE_TYPE_8088 = 1, + MACHINE_TYPE_8086 = 2, + MACHINE_TYPE_286 = 3, + MACHINE_TYPE_386SX = 4, + MACHINE_TYPE_486SLC = 5, + MACHINE_TYPE_386DX = 6, + MACHINE_TYPE_386DX_486 = 7, + MACHINE_TYPE_486 = 8, + MACHINE_TYPE_486_S2 = 9, + MACHINE_TYPE_486_S3 = 10, + MACHINE_TYPE_486_MISC = 11, + MACHINE_TYPE_SOCKET4 = 12, + MACHINE_TYPE_SOCKET5 = 13, + MACHINE_TYPE_SOCKET7_3V = 14, + MACHINE_TYPE_SOCKET7 = 15, + MACHINE_TYPE_SOCKETS7 = 16, + MACHINE_TYPE_SOCKET8 = 17, + MACHINE_TYPE_SLOT1 = 18, + MACHINE_TYPE_SLOT1_2 = 19, + MACHINE_TYPE_SLOT1_370 = 20, + MACHINE_TYPE_SLOT2 = 21, + MACHINE_TYPE_SOCKET370 = 22, + MACHINE_TYPE_MISC = 23, + MACHINE_TYPE_MAX = 24 }; enum { @@ -281,7 +287,10 @@ typedef struct _machine_ { uint32_t type; uintptr_t chipset; int (*init)(const struct _machine_ *); - uintptr_t pad, pad0, pad1, pad2; + uintptr_t pad; + uintptr_t pad0; + uintptr_t pad1; + uintptr_t pad2; const machine_cpu_t cpu; uintptr_t bus_flags; uintptr_t flags; @@ -317,8 +326,8 @@ typedef struct _machine_ { } machine_t; /* Global variables. */ -extern const machine_filter_t machine_types[], - machine_chipsets[]; +extern const machine_filter_t machine_types[]; +extern const machine_filter_t machine_chipsets[]; extern const machine_t machines[]; extern int bios_only; extern int machine; @@ -535,9 +544,8 @@ extern int machine_at_cmdpc_init(const machine_t *); extern int machine_at_portableii_init(const machine_t *); extern int machine_at_portableiii_init(const machine_t *); extern int machine_at_portableiii386_init(const machine_t *); -#if defined(DEV_BRANCH) && defined(USE_DESKPRO386) extern int machine_at_deskpro386_init(const machine_t *); -#endif +extern int machine_at_deskpro386_01_1988_init(const machine_t *); /* m_at_socket4.c */ extern void machine_at_premiere_common_init(const machine_t *, int); @@ -770,6 +778,7 @@ extern int machine_ps2_model_65sx_init(const machine_t *); extern int machine_ps2_model_70_type3_init(const machine_t *); extern int machine_ps2_model_80_init(const machine_t *); extern int machine_ps2_model_80_axx_init(const machine_t *); +extern int machine_ps2_model_70_type4_init(const machine_t *); /* m_tandy.c */ extern int tandy1k_eeprom_read(void); diff --git a/src/include/86box/machine_status.h b/src/include/86box/machine_status.h index 6948dc556..e7c57881b 100644 --- a/src/include/86box/machine_status.h +++ b/src/include/86box/machine_status.h @@ -1,20 +1,20 @@ #ifndef EMU_MACHINE_STATUS_H #define EMU_MACHINE_STATUS_H -typedef struct { +typedef struct dev_status_empty_active_t { atomic_bool_t empty; atomic_bool_t active; } dev_status_empty_active_t; -typedef struct { +typedef struct dev_status_active_t { atomic_bool_t active; } dev_status_active_t; -typedef struct { +typedef struct dev_status_empty_t { atomic_bool_t empty; } dev_status_empty_t; -typedef struct { +typedef struct machine_status_t { dev_status_empty_active_t fdd[FDD_NUM]; dev_status_empty_active_t cdrom[CDROM_NUM]; dev_status_empty_active_t zip[ZIP_NUM]; diff --git a/src/include/86box/mem.h b/src/include/86box/mem.h index f109776a6..30e9359bf 100644 --- a/src/include/86box/mem.h +++ b/src/include/86box/mem.h @@ -157,23 +157,22 @@ mem_set_access((smm ? ACCESS_CPU_SMM : ACCESS_CPU), 1, base, size, is_smram) #define mem_set_access_smram_bus(smm, base, size, is_smram) \ mem_set_access((smm ? ACCESS_BUS_SMM : ACCESS_BUS), 1, base, size, is_smram) -#define flushmmucache_cr3 \ - flushmmucache_nopc -typedef struct { - uint16_t x : 5, - w : 5, - r : 5, - pad : 1; +typedef struct state_t { + uint16_t x : 5; + uint16_t w : 5; + uint16_t r : 5; + uint16_t pad : 1; } state_t; -typedef union { +typedef union mem_state_t { uint16_t vals[4]; state_t states[4]; } mem_state_t; typedef struct _mem_mapping_ { - struct _mem_mapping_ *prev, *next; + struct _mem_mapping_ *prev; + struct _mem_mapping_ *next; int enable; @@ -195,7 +194,7 @@ typedef struct _mem_mapping_ { /* There is never a needed to pass a pointer to the mapping itself, it is much preferable to prepare a structure with the requires data (usually, the base address and mask) instead. */ - void *p; /* backpointer to device */ + void *priv; /* backpointer to device */ } mem_mapping_t; #ifdef USE_NEW_DYNAREC @@ -208,9 +207,9 @@ extern uint64_t *byte_code_present_mask; # define EVICT_NOT_IN_LIST ((uint32_t) -1) typedef struct page_t { - void (*write_b)(uint32_t addr, uint8_t val, struct page_t *p); - void (*write_w)(uint32_t addr, uint16_t val, struct page_t *p); - void (*write_l)(uint32_t addr, uint32_t val, struct page_t *p); + void (*write_b)(uint32_t addr, uint8_t val, struct page_t *page); + void (*write_w)(uint32_t addr, uint16_t val, struct page_t *page); + void (*write_l)(uint32_t addr, uint32_t val, struct page_t *page); uint8_t *mem; @@ -219,45 +218,50 @@ typedef struct page_t { /*Head of codeblock tree associated with this page*/ uint16_t head; - uint64_t code_present_mask, dirty_mask; + uint64_t code_present_mask; + uint64_t dirty_mask; - uint32_t evict_prev, evict_next; + uint32_t evict_prev; + uint32_t evict_next; uint64_t *byte_dirty_mask; uint64_t *byte_code_present_mask; } page_t; extern uint32_t purgable_page_list_head; -static inline int -page_in_evict_list(page_t *p) +__attribute__((always_inline)) static inline int +page_in_evict_list(page_t *page) { - return (p->evict_prev != EVICT_NOT_IN_LIST); + return (page->evict_prev != EVICT_NOT_IN_LIST); } -void page_remove_from_evict_list(page_t *p); -void page_add_to_evict_list(page_t *p); +void page_remove_from_evict_list(page_t *page); +void page_add_to_evict_list(page_t *page); #else typedef struct _page_ { - void (*write_b)(uint32_t addr, uint8_t val, struct _page_ *p); - void (*write_w)(uint32_t addr, uint16_t val, struct _page_ *p); - void (*write_l)(uint32_t addr, uint32_t val, struct _page_ *p); + void (*write_b)(uint32_t addr, uint8_t val, struct _page_ *page); + void (*write_w)(uint32_t addr, uint16_t val, struct _page_ *page); + void (*write_l)(uint32_t addr, uint32_t val, struct _page_ *page); uint8_t *mem; - uint64_t code_present_mask[4], - dirty_mask[4]; + uint64_t code_present_mask[4]; + uint64_t dirty_mask[4]; - struct codeblock_t *block[4], *block_2[4]; + struct codeblock_t *block[4]; + struct codeblock_t *block_2[4]; /*Head of codeblock tree associated with this page*/ struct codeblock_t *head; } page_t; #endif -extern uint8_t *ram, *ram2; +extern uint8_t *ram; +extern uint8_t *ram2; extern uint32_t rammask; extern uint8_t *rom; -extern uint32_t biosmask, biosaddr; +extern uint32_t biosmask; +extern uint32_t biosaddr; extern int readlookup[256]; extern uintptr_t *readlookup2; @@ -270,27 +274,28 @@ extern int writelnext; extern uint32_t ram_mapped_addr[64]; extern uint8_t page_ff[4096]; -extern mem_mapping_t ram_low_mapping, +extern mem_mapping_t ram_low_mapping; #if 1 - ram_mid_mapping, +extern mem_mapping_t ram_mid_mapping; #endif - ram_remapped_mapping, - ram_high_mapping, - ram_2gb_mapping, - bios_mapping, - bios_high_mapping; +extern mem_mapping_t ram_remapped_mapping; +extern mem_mapping_t ram_high_mapping; +extern mem_mapping_t ram_2gb_mapping; +extern mem_mapping_t bios_mapping; +extern mem_mapping_t bios_high_mapping; extern uint32_t mem_logical_addr; -extern page_t *pages, - **page_lookup; +extern page_t *pages; +extern page_t **page_lookup; -extern uint32_t get_phys_virt, get_phys_phys; +extern uint32_t get_phys_virt; +extern uint32_t get_phys_phys; -extern int shadowbios, - shadowbios_write; -extern int readlnum, - writelnum; +extern int shadowbios; +extern int shadowbios_write; +extern int readlnum; +extern int writelnum; extern int memspeed[11]; @@ -299,9 +304,9 @@ extern uint8_t high_page; /* if a high (> 4 gb) page was detected */ extern uint32_t pages_sz; /* #pages in table */ -extern int mem_a20_state, - mem_a20_alt, - mem_a20_key; +extern int mem_a20_state; +extern int mem_a20_alt; +extern int mem_a20_key; extern uint8_t read_mem_b(uint32_t addr); extern uint16_t read_mem_w(uint32_t addr); @@ -335,37 +340,37 @@ extern void addwritelookup(uint32_t virt, uint32_t phys); extern void mem_mapping_set(mem_mapping_t *, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t flags, - void *p); + void *priv); extern void mem_mapping_add(mem_mapping_t *, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t flags, - void *p); + void *priv); extern void mem_mapping_set_handler(mem_mapping_t *, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p)); + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv)); -extern void mem_mapping_set_p(mem_mapping_t *, void *p); +extern void mem_mapping_set_p(mem_mapping_t *, void *priv); extern void mem_mapping_set_addr(mem_mapping_t *, uint32_t base, uint32_t size); @@ -406,16 +411,15 @@ extern uint64_t mmutranslate_noabrt(uint32_t addr, int rw); extern void mem_invalidate_range(uint32_t start_addr, uint32_t end_addr); -extern void mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *p); -extern void mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *p); -extern void mem_write_raml_page(uint32_t addr, uint32_t val, page_t *p); +extern void mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *page); +extern void mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *page); +extern void mem_write_raml_page(uint32_t addr, uint32_t val, page_t *page); extern void mem_flush_write_page(uint32_t addr, uint32_t virt); extern void mem_reset_page_blocks(void); extern void flushmmucache(void); extern void flushmmucache_nopc(void); -extern void mmu_invalidate(uint32_t addr); extern void mem_a20_init(void); extern void mem_a20_recalc(void); diff --git a/src/include/86box/midi.h b/src/include/86box/midi.h index 9f3a81581..bbd53b512 100644 --- a/src/include/86box/midi.h +++ b/src/include/86box/midi.h @@ -40,23 +40,33 @@ typedef struct midi_in_handler_t { int cnt; uint32_t len; - void (*msg)(void *p, uint8_t *msg, uint32_t len); - int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort); - struct midi_in_handler_t *p; - struct midi_in_handler_t *prev, *next; + void (*msg)(void *priv, uint8_t *msg, uint32_t len); + int (*sysex)(void *priv, uint8_t *buffer, uint32_t len, int abort); + struct midi_in_handler_t *priv; + struct midi_in_handler_t *prev; + struct midi_in_handler_t *next; } midi_in_handler_t; typedef struct midi_t { - uint8_t midi_rt_buf[8], midi_cmd_buf[8], - midi_status, midi_sysex_data[SYSEX_SIZE]; - int midi_cmd_pos, midi_cmd_len, midi_cmd_r, - midi_realtime, thruchan, midi_clockout; - unsigned int midi_sysex_start, midi_sysex_delay, - midi_pos; - midi_device_t *m_out_device, *m_in_device; + uint8_t midi_rt_buf[8]; + uint8_t midi_cmd_buf[8]; + uint8_t midi_status; + uint8_t midi_sysex_data[SYSEX_SIZE]; + int midi_cmd_pos; + int midi_cmd_len; + int midi_cmd_r; + int midi_realtime; + int thruchan; + int midi_clockout; + unsigned int midi_sysex_start; + unsigned int midi_sysex_delay; + unsigned int midi_pos; + midi_device_t *m_out_device; + midi_device_t *m_in_device; } midi_t; -extern midi_t *midi_out, *midi_in; +extern midi_t *midi_out; +extern midi_t *midi_in; extern void midi_out_init(midi_device_t *device); extern void midi_in_init(midi_device_t *device, midi_t **mididev); @@ -68,7 +78,7 @@ extern void midi_raw_out_byte(uint8_t val); extern void midi_clear_buffer(void); extern void midi_poll(void); -extern void midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort), void *p); +extern void midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort), void *priv); extern void midi_in_handlers_clear(void); extern void midi_in_msg(uint8_t *msg, uint32_t len); extern void midi_in_sysex(uint8_t *buffer, uint32_t len); diff --git a/src/include/86box/mo.h b/src/include/86box/mo.h index 19c999ee3..a11c4d636 100644 --- a/src/include/86box/mo.h +++ b/src/include/86box/mo.h @@ -27,7 +27,7 @@ #define MO_TIME 10.0 -typedef struct { +typedef struct mo_type_t { uint32_t sectors; uint16_t bytes_per_sector; } mo_type_t; @@ -48,8 +48,7 @@ static const mo_type_t mo_types[KNOWN_MO_TYPES] = { { 637041, 1024}, }; -typedef struct -{ +typedef struct mo_drive_type_t { const char vendor[9]; const char model[16]; const char revision[5]; @@ -85,62 +84,77 @@ static const mo_drive_type_t mo_drive_types[KNOWN_MO_DRIVE_TYPES] = { enum { MO_BUS_DISABLED = 0, MO_BUS_ATAPI = 5, - MO_BUS_SCSI, - MO_BUS_USB + MO_BUS_SCSI = 6, + MO_BUS_USB = 7 }; -typedef struct { +typedef struct mo_drive_t { uint8_t id; union { - uint8_t res, res0, /* Reserved for other ID's. */ - res1, - ide_channel, scsi_device_id; + uint8_t res; + uint8_t res0; /* Reserved for other ID's. */ + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - uint8_t bus_type, /* 0 = ATAPI, 1 = SCSI */ - bus_mode, /* Bit 0 = PIO suported; - Bit 1 = DMA supportd. */ - read_only, /* Struct variable reserved for - media status. */ - pad, pad0; + uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ + uint8_t bus_mode; /* Bit 0 = PIO suported; + Bit 1 = DMA supportd. */ + uint8_t read_only; /* Struct variable reserved for + media status. */ + uint8_t pad; + uint8_t pad0; FILE *f; void *priv; - char image_path[1024], - prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; - uint32_t type, medium_size, - base; + uint32_t type; + uint32_t medium_size; + uint32_t base; uint16_t sector_size; } mo_drive_t; -typedef struct { +typedef struct mo_t { mode_sense_pages_t ms_pages_saved; mo_drive_t *drv; - uint8_t *buffer, - atapi_cdb[16], - current_cdb[16], - sense[256]; + uint8_t *buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint8_t status, phase, - error, id, - features, cur_lun, - pad0, pad1; + uint8_t status; + uint8_t phase; + uint8_t error; + uint8_t id; + uint8_t features; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - uint16_t request_length, max_transfer_len; + uint16_t request_length; + uint16_t max_transfer_len; - int requested_blocks, packet_status, - total_length, do_page_save, - unit_attention, request_pos, - old_len, pad3; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int pad3; - uint32_t sector_pos, sector_len, - packet_len, pos; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t pos; double callback; } mo_t; diff --git a/src/include/86box/mouse.h b/src/include/86box/mouse.h index e6ad93e80..839c0f11a 100644 --- a/src/include/86box/mouse.h +++ b/src/include/86box/mouse.h @@ -35,6 +35,7 @@ #define MOUSE_TYPE_LT3BUTTON 10 /* Logitech 3-button Serial Mouse */ #define MOUSE_TYPE_PS2 11 /* PS/2 series Bus Mouse */ #define MOUSE_TYPE_WACOM 12 /* WACOM tablet */ +#define MOUSE_TYPE_WACOMARTP 13 /* WACOM tablet (ArtPad) */ #define MOUSE_TYPE_ONBOARD 0x80 /* Mouse is an on-board version of one of the above. */ @@ -42,13 +43,16 @@ extern "C" { #endif -extern int mouse_type; -extern int mouse_x, mouse_y, mouse_z; -extern int mouse_mode; /* 1 = Absolute, 0 = Relative */ -extern int mouse_tablet_in_proximity; -extern double mouse_x_abs, mouse_y_abs; -extern int mouse_buttons; -extern int tablet_tool_type; +extern int mouse_type; +extern int mouse_x; +extern int mouse_y; +extern int mouse_z; +extern int mouse_mode; /* 1 = Absolute, 0 = Relative */ +extern int mouse_tablet_in_proximity; +extern double mouse_x_abs; +extern double mouse_y_abs; +extern int mouse_buttons; +extern int tablet_tool_type; #ifdef EMU_DEVICE_H extern const device_t *mouse_get_device(int mouse); @@ -65,6 +69,7 @@ extern const device_t mouse_msserial_device; extern const device_t mouse_ltserial_device; extern const device_t mouse_ps2_device; extern const device_t mouse_wacom_device; +extern const device_t mouse_wacom_artpad_device; #endif extern void mouse_init(void); @@ -78,6 +83,8 @@ extern void mouse_poll(void); extern void mouse_bus_set_irq(void *priv, int irq); +extern void mouse_set_sample_rate(double new_rate); + extern char *mouse_get_name(int mouse); extern char *mouse_get_internal_name(int mouse); extern int mouse_get_from_internal_name(char *s); diff --git a/src/include/86box/net_dp8390.h b/src/include/86box/net_dp8390.h index 4a172d4fe..e9e1e6c71 100644 --- a/src/include/86box/net_dp8390.h +++ b/src/include/86box/net_dp8390.h @@ -36,7 +36,7 @@ #define DP8390_FLAG_CHECK_CR 0x02 #define DP8390_FLAG_CLEAR_IRQ 0x04 -typedef struct { +typedef struct dp8390_t { /* Page 0 */ /* Command Register - 00h read/write */ @@ -178,7 +178,10 @@ typedef struct { 0xFF. */ id1; /* 0x70 for the RTL8019AS, 0x43 for the RTL8029AS, otherwise 0xFF. */ - int mem_size, mem_start, mem_end; + uint32_t mem_size; + uint32_t mem_start; + uint32_t mem_end; + uint32_t mem_wrap; int tx_timer_index; int tx_timer_active; diff --git a/src/include/86box/net_event.h b/src/include/86box/net_event.h index 61eaad166..48580a359 100644 --- a/src/include/86box/net_event.h +++ b/src/include/86box/net_event.h @@ -1,7 +1,7 @@ #ifndef EMU_NET_EVENT_H #define EMU_NET_EVENT_H -typedef struct { +typedef struct net_evt_t { #ifdef _WIN32 HANDLE handle; #else diff --git a/src/include/86box/net_wd8003.h b/src/include/86box/net_wd8003.h index a0ea13287..726510cdb 100644 --- a/src/include/86box/net_wd8003.h +++ b/src/include/86box/net_wd8003.h @@ -45,13 +45,13 @@ #define NET_WD8003_H enum { - WD_NONE = 0, - WD8003E, /* WD8003E : 8-bit ISA, no interface chip */ - WD8003EB, /* WD8003EB : 8-bit ISA, 5x3 interface chip */ - WD8013EBT, /* WD8013EBT : 16-bit ISA, no interface chip */ - WD8003ETA, /* WD8003ET/A: 16-bit MCA, no interface chip */ - WD8003EA, /* WD8003E/A : 16-bit MCA, 5x3 interface chip */ - WD8013EPA + WD_NONE = 0, + WD8003E = 1, /* WD8003E : 8-bit ISA, no interface chip */ + WD8003EB = 2, /* WD8003EB : 8-bit ISA, 5x3 interface chip */ + WD8013EBT = 3, /* WD8013EBT : 16-bit ISA, no interface chip */ + WD8003ETA = 4, /* WD8003ET/A: 16-bit MCA, no interface chip */ + WD8003EA = 5, /* WD8003E/A : 16-bit MCA, 5x3 interface chip */ + WD8013EPA = 6 }; extern const device_t wd8003e_device; diff --git a/src/include/86box/network.h b/src/include/86box/network.h index 0a396968f..d7958ee9a 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -48,20 +48,25 @@ #include /* Network provider types. */ -#define NET_TYPE_NONE 0 /* networking disabled */ +#define NET_TYPE_NONE 0 /* use the null network driver */ #define NET_TYPE_SLIRP 1 /* use the SLiRP port forwarder */ #define NET_TYPE_PCAP 2 /* use the (Win)Pcap API */ +#define NET_TYPE_VDE 3 /* use the VDE plug API */ #define NET_MAX_FRAME 1518 /* Queue size must be a power of 2 */ #define NET_QUEUE_LEN 16 #define NET_QUEUE_LEN_MASK (NET_QUEUE_LEN - 1) +#define NET_QUEUE_COUNT 3 #define NET_CARD_MAX 4 #define NET_HOST_INTF_MAX 64 #define NET_PERIOD_10M 0.8 #define NET_PERIOD_100M 0.08 +/* Error buffers for network driver init */ +#define NET_DRV_ERRBUF_SIZE 384 + enum { NET_LINK_DOWN = (1 << 1), NET_LINK_TEMP_DOWN = (1 << 2), @@ -75,20 +80,20 @@ enum { /* Supported network cards. */ enum { - NONE = 0, - NE1000, - NE2000, - RTL8019AS, - RTL8029AS + NONE = 0, + NE1000 = 1, + NE2000 = 2, + RTL8019AS = 3, + RTL8029AS = 4 }; enum { - NET_QUEUE_RX, - NET_QUEUE_TX_VM, - NET_QUEUE_TX_HOST + NET_QUEUE_RX = 0, + NET_QUEUE_TX_VM = 1, + NET_QUEUE_TX_HOST = 2 }; -typedef struct { +typedef struct netcard_conf_t { uint16_t device_num; int net_type; char host_dev_name[128]; @@ -106,7 +111,7 @@ typedef struct netpkt { int len; } netpkt_t; -typedef struct { +typedef struct netqueue_t { netpkt_t packets[NET_QUEUE_LEN]; int head; int tail; @@ -116,13 +121,15 @@ typedef struct _netcard_t netcard_t; typedef struct netdrv_t { void (*notify_in)(void *priv); - void *(*init)(const netcard_t *card, const uint8_t *mac_addr, void *priv); + void *(*init)(const netcard_t *card, const uint8_t *mac_addr, void *priv, char *netdrv_errbuf); void (*close)(void *priv); void *priv; } netdrv_t; extern const netdrv_t net_pcap_drv; extern const netdrv_t net_slirp_drv; +extern const netdrv_t net_vde_drv; +extern const netdrv_t net_null_drv; struct _netcard_t { const device_t *device; @@ -130,7 +137,7 @@ struct _netcard_t { struct netdrv_t host_drv; NETRXCB rx; NETSETLINKSTATE set_link_state; - netqueue_t queues[3]; + netqueue_t queues[NET_QUEUE_COUNT]; netpkt_t queued_pkt; mutex_t *tx_mutex; mutex_t *rx_mutex; @@ -147,14 +154,26 @@ typedef struct { char description[128]; } netdev_t; +typedef struct { + int has_slirp; + int has_pcap; + int has_vde; +} network_devmap_t; + + +#define HAS_NOSLIRP_NET(x) (x.has_pcap || x.has_vde) + #ifdef __cplusplus extern "C" { #endif /* Global variables. */ -extern int nic_do_log; /* config */ -extern int network_ndev; -extern netdev_t network_devs[NET_HOST_INTF_MAX]; +extern int nic_do_log; // config +extern network_devmap_t network_devmap; +extern int network_ndev; // Number of pcap devices +extern network_devmap_t network_devmap; // Bitmap of available network types +extern netdev_t network_devs[NET_HOST_INTF_MAX]; + /* Function prototypes. */ extern void network_init(void); @@ -166,6 +185,8 @@ extern int network_available(void); extern void network_tx(netcard_t *card, uint8_t *, int); extern int net_pcap_prepare(netdev_t *); +extern int net_vde_prepare(void); + extern void network_connect(int id, int connect); extern int network_is_connected(int id); diff --git a/src/include/86box/nvr.h b/src/include/86box/nvr.h index 25f5e90ad..baba6b6c4 100644 --- a/src/include/86box/nvr.h +++ b/src/include/86box/nvr.h @@ -64,7 +64,8 @@ typedef struct _nvr_ { char *fn; /* pathname of image file */ uint16_t size; /* device configuration */ - int8_t irq, is_new; + int8_t irq; + int8_t is_new; uint8_t onesec_cnt; pc_timer_t onesec_time; diff --git a/src/include/86box/pci.h b/src/include/86box/pci.h index c16d5a7e8..df9c4c573 100644 --- a/src/include/86box/pci.h +++ b/src/include/86box/pci.h @@ -56,46 +56,65 @@ #define PCI_ADD_STRICT 0x80 enum { - PCI_CARD_NORTHBRIDGE = 0, - PCI_CARD_AGPBRIDGE, - PCI_CARD_SOUTHBRIDGE, - PCI_CARD_SOUTHBRIDGE_IDE, - PCI_CARD_SOUTHBRIDGE_PMU, - PCI_CARD_SOUTHBRIDGE_USB, - PCI_CARD_AGP = 0x0f, - PCI_CARD_NORMAL = 0x10, - PCI_CARD_VIDEO, - PCI_CARD_SCSI, - PCI_CARD_SOUND, - PCI_CARD_IDE, - PCI_CARD_NETWORK, - PCI_CARD_BRIDGE, + PCI_CARD_NORTHBRIDGE = 0, + PCI_CARD_AGPBRIDGE = 1, + PCI_CARD_SOUTHBRIDGE = 2, + PCI_CARD_SOUTHBRIDGE_IDE = 3, + PCI_CARD_SOUTHBRIDGE_PMU = 4, + PCI_CARD_SOUTHBRIDGE_USB = 5, + PCI_CARD_AGP = 0x0f, + PCI_CARD_NORMAL = 0x10, + PCI_CARD_VIDEO = 0x11, + PCI_CARD_SCSI = 0x12, + PCI_CARD_SOUND = 0x13, + PCI_CARD_IDE = 0x14, + PCI_CARD_NETWORK = 0x15, + PCI_CARD_BRIDGE = 0x16 }; enum { - PCI_ADD_NORTHBRIDGE = 0, - PCI_ADD_AGPBRIDGE, - PCI_ADD_SOUTHBRIDGE, - PCI_ADD_SOUTHBRIDGE_IDE, - PCI_ADD_SOUTHBRIDGE_PMU, - PCI_ADD_SOUTHBRIDGE_USB, - PCI_ADD_AGP = 0x0f, - PCI_ADD_NORMAL = 0x10, - PCI_ADD_VIDEO, - PCI_ADD_SCSI, - PCI_ADD_SOUND, - PCI_ADD_IDE, - PCI_ADD_NETWORK, - PCI_ADD_BRIDGE + PCI_ADD_NORTHBRIDGE = 0, + PCI_ADD_AGPBRIDGE = 1, + PCI_ADD_SOUTHBRIDGE = 2, + PCI_ADD_SOUTHBRIDGE_IDE = 3, + PCI_ADD_SOUTHBRIDGE_PMU = 4, + PCI_ADD_SOUTHBRIDGE_USB = 5, + PCI_ADD_AGP = 0x0f, + PCI_ADD_NORMAL = 0x10, + PCI_ADD_VIDEO = 0x11, + PCI_ADD_SCSI = 0x12, + PCI_ADD_SOUND = 0x13, + PCI_ADD_IDE = 0x14, + PCI_ADD_NETWORK = 0x15, + PCI_ADD_BRIDGE = 0x16 }; typedef union { uint32_t addr; - uint8_t addr_regs[4]; + uint8_t addr_regs[4]; } bar_t; -extern int pci_burst_time, agp_burst_time, - pci_nonburst_time, agp_nonburst_time; + +#define PCI_IO_ON 0x01 +#define PCI_IO_DEV0 0x02 + + +extern int pci_burst_time; +extern int agp_burst_time; +extern int pci_nonburst_time; +extern int agp_nonburst_time; +extern int pci_take_over_io; + +extern uint32_t pci_base; +extern uint32_t pci_size; + + +extern void pci_type2_write(uint16_t port, uint8_t val, void *priv); +extern void pci_type2_writew(uint16_t port, uint16_t val, void *priv); +extern void pci_type2_writel(uint16_t port, uint32_t val, void *priv); +extern uint8_t pci_type2_read(uint16_t port, void *priv); +extern uint16_t pci_type2_readw(uint16_t port, void *priv); +extern uint32_t pci_type2_readl(uint16_t port, void *priv); extern void pci_set_irq_routing(int pci_int, int irq); extern void pci_set_irq_level(int pci_int, int level); diff --git a/src/include/86box/pic.h b/src/include/86box/pic.h index 318ce2fad..dcc6f1358 100644 --- a/src/include/86box/pic.h +++ b/src/include/86box/pic.h @@ -20,16 +20,32 @@ #define EMU_PIC_H typedef struct pic { - uint8_t icw1, icw2, icw3, icw4, - imr, isr, irr, ocw2, - ocw3, int_pending, is_master, elcr, - state, ack_bytes, priority, special_mask_mode, - auto_eoi_rotate, interrupt, lines, data_bus; + uint8_t icw1; + uint8_t icw2; + uint8_t icw3; + uint8_t icw4; + uint8_t imr; + uint8_t isr; + uint8_t irr; + uint8_t ocw2; + uint8_t ocw3; + uint8_t int_pending; + uint8_t is_master; + uint8_t elcr; + uint8_t state; + uint8_t ack_bytes; + uint8_t priority; + uint8_t special_mask_mode; + uint8_t auto_eoi_rotate; + uint8_t interrupt; + uint8_t lines; + uint8_t data_bus; uint32_t at; struct pic *slaves[8]; } pic_t; -extern pic_t pic, pic2; +extern pic_t pic; +extern pic_t pic2; extern void pic_reset_smi_irq_mask(void); extern void pic_set_smi_irq_mask(int irq, int set); @@ -43,8 +59,11 @@ extern void pic_elcr_write(uint16_t port, uint8_t val, void *priv); extern uint8_t pic_elcr_read(uint16_t port, void *priv); extern void pic_set_shadow(int sh); +extern int pic_get_pci_flag(void); extern void pic_set_pci_flag(int pci); extern void pic_set_pci(void); +extern void pic_kbd_latch(int enable); +extern void pic_mouse_latch(int enable); extern void pic_init(void); extern void pic_init_pcjr(void); extern void pic2_init(void); diff --git a/src/include/86box/pit.h b/src/include/86box/pit.h index d50e45967..bb6c26969 100644 --- a/src/include/86box/pit.h +++ b/src/include/86box/pit.h @@ -19,26 +19,38 @@ #ifndef EMU_PIT_H #define EMU_PIT_H -typedef struct { - uint8_t m, ctrl, - read_status, latch, - s1_det, l_det, - bcd, pad; +typedef struct ctr_t { + uint8_t m; + uint8_t ctrl; + uint8_t read_status; + uint8_t latch; + uint8_t s1_det; + uint8_t l_det; + uint8_t bcd; + uint8_t incomplete; uint16_t rl; - int rm, wm, gate, out, - newcount, clock, using_timer, latched, - state, null_count, do_read_status; + int rm; + int wm; + int gate; + int out; + int newcount; + int clock; + int using_timer; + int latched; + int state; + int null_count; + int do_read_status; union { - int count; + int32_t count; struct { - int units : 4; - int tens : 4; - int hundreds : 4; - int thousands : 4; - int myriads : 4; + int32_t units : 4; + int32_t tens : 4; + int32_t hundreds : 4; + int32_t thousands : 4; + int32_t myriads : 4; }; }; @@ -49,7 +61,8 @@ typedef struct { } ctr_t; typedef struct PIT { - int flags, clock; + int flags; + int clock; pc_timer_t callback_timer; ctr_t counters[3]; @@ -58,13 +71,13 @@ typedef struct PIT { } pit_t; enum { - PIT_8253 = 0, - PIT_8254, - PIT_8253_FAST, - PIT_8254_FAST + PIT_8253 = 0, + PIT_8254 = 1, + PIT_8253_FAST = 2, + PIT_8254_FAST = 3 }; -typedef struct { +typedef struct pit_intf_t { uint8_t (*read)(uint16_t addr, void *priv); void (*write)(uint16_t addr, uint8_t val, void *priv); /* Gets a counter's count. */ @@ -84,15 +97,18 @@ typedef struct { extern pit_intf_t pit_devs[2]; extern const pit_intf_t pit_classic_intf; -extern double SYSCLK, PCICLK, AGPCLK; +extern double SYSCLK; +extern double PCICLK; +extern double AGPCLK; -extern uint64_t PITCONST, ISACONST, - CGACONST, - MDACONST, - HERCCONST, - VGACONST1, - VGACONST2, - RTCCONST; +extern uint64_t PITCONST; +extern uint64_t ISACONST; +extern uint64_t CGACONST; +extern uint64_t MDACONST; +extern uint64_t HERCCONST; +extern uint64_t VGACONST1; +extern uint64_t VGACONST2; +extern uint64_t RTCCONST; extern int refresh_at_enable; diff --git a/src/include/86box/pit_fast.h b/src/include/86box/pit_fast.h index 242fb4207..a7caeabe7 100644 --- a/src/include/86box/pit_fast.h +++ b/src/include/86box/pit_fast.h @@ -19,15 +19,24 @@ #ifndef EMU_PIT_FAST_H #define EMU_PIT_FAST_H -typedef struct { - uint8_t m, ctrl, - read_status, latch, bcd; +typedef struct ctrf_t { + uint8_t m; + uint8_t ctrl; + uint8_t read_status; + uint8_t latch; + uint8_t bcd; uint16_t rl; - int rm, wm, gate, out, - newcount, clock, using_timer, latched, - do_read_status; + int rm; + int wm; + int gate; + int out; + int newcount; + int clock; + int using_timer; + int latched; + int do_read_status; int enabled; int disabled; int initial; @@ -36,13 +45,13 @@ typedef struct { int rereadlatch; union { - int count; + int32_t count; struct { - int units : 4; - int tens : 4; - int hundreds : 4; - int thousands : 4; - int myriads : 4; + int32_t units : 4; + int32_t tens : 4; + int32_t hundreds : 4; + int32_t thousands : 4; + int32_t myriads : 4; }; }; @@ -53,7 +62,7 @@ typedef struct { void (*out_func)(int new_out, int old_out); } ctrf_t; -typedef struct { +typedef struct pitf_t { int flags; ctrf_t counters[3]; diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 05b982216..2b0809c2e 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -55,6 +55,10 @@ extern int strnicmp(const char *s1, const char *s2, size_t n); # define off64_t off_t #endif +#if !defined (__APPLE__) && !defined(__clang__) +# define FALLTHROUGH_ANNOTATION +#endif + #ifdef _MSC_VER # define UNUSED(arg) arg #else @@ -81,9 +85,9 @@ extern "C" { #endif /* Global variables residing in the platform module. */ -extern int dopause, /* system is paused */ - mouse_capture; /* mouse is captured in app */ -extern volatile int is_quit; /* system exit requested */ +extern int dopause; /* system is paused */ +extern int mouse_capture; /* mouse is captured in app */ +extern volatile int is_quit; /* system exit requested */ #ifdef MTR_ENABLED extern int tracing_on; @@ -95,7 +99,9 @@ extern char emu_version[200]; /* version ID string */ extern int rctrl_is_lalt; extern int update_icons; -extern int kbd_req_capture, hide_status_bar, hide_tool_bar; +extern int kbd_req_capture; +extern int hide_status_bar; +extern int hide_tool_bar; /* System-related functions. */ extern char *fix_exe_path(char *str); diff --git a/src/include/86box/plat_dir.h b/src/include/86box/plat_dir.h index d55bc5046..485314f46 100644 --- a/src/include/86box/plat_dir.h +++ b/src/include/86box/plat_dir.h @@ -39,7 +39,7 @@ struct dirent { }; # define d_namlen d_reclen -typedef struct { +typedef struct DIR_t { short flags; /* internal flags */ short offset; /* offset of entry into dir */ long handle; /* open handle to Win32 system */ @@ -68,7 +68,7 @@ extern int closedir(DIR *); # define rewinddir(dirp) seekdir(dirp, 0L) #else /* On linux and macOS, use the standard functions and types */ -# include +# include #endif #endif /*PLAT_DIR_H*/ diff --git a/src/include/86box/plat_dynld.h b/src/include/86box/plat_dynld.h index 986e72424..44891d4ac 100644 --- a/src/include/86box/plat_dynld.h +++ b/src/include/86box/plat_dynld.h @@ -18,7 +18,7 @@ #ifndef PLAT_DYNLD_H #define PLAT_DYNLD_H -typedef struct { +typedef struct dllimp_t { const char *name; void *func; } dllimp_t; diff --git a/src/include/86box/plat_fallthrough.h b/src/include/86box/plat_fallthrough.h new file mode 100644 index 000000000..212d662fe --- /dev/null +++ b/src/include/86box/plat_fallthrough.h @@ -0,0 +1,25 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Define the various platform support functions. + * + * + * + * Authors: Jasmine Iwanek, + * + * Copyright 2023 Jasmine Iwanek + */ + +#ifndef EMU_PLAT_FALLTHROUGH_H +#define EMU_PLAT_FALLTHROUGH_H + +#if !defined (__APPLE__) && !defined(__clang__) +# define FALLTHROUGH_ANNOTATION +#endif + +#endif /*EMU_PLAT_FALLTHROUGH_H*/ diff --git a/src/include/86box/plat_unused.h b/src/include/86box/plat_unused.h new file mode 100644 index 000000000..73eaebaae --- /dev/null +++ b/src/include/86box/plat_unused.h @@ -0,0 +1,31 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Define the various platform support functions. + * + * + * + * Authors: Miran Grca, + * Fred N. van Kempen, + * + * Copyright 2016-2019 Miran Grca. + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2021 Laci bá' + */ + +#ifndef EMU_PLAT_UNUSED_H +#define EMU_PLAT_UNUSED_H + +#ifdef _MSC_VER +# define UNUSED(arg) arg +#else +/* A hack (GCC-specific?) to allow us to ignore unused parameters. */ +# define UNUSED(arg) __attribute__((unused)) arg +#endif + +#endif /*EMU_PLAT_UNUSED_H*/ diff --git a/src/include/86box/port_6x.h b/src/include/86box/port_6x.h index 7eb0c9a56..e0c4b0508 100644 --- a/src/include/86box/port_6x.h +++ b/src/include/86box/port_6x.h @@ -20,9 +20,9 @@ #define EMU_PORT_6X_H #ifdef _TIMER_H_ -typedef struct -{ - uint8_t refresh, flags; +typedef struct port_6x_t { + uint8_t refresh; + uint8_t flags; pc_timer_t refresh_timer; } port_6x_t; diff --git a/src/include/86box/port_92.h b/src/include/86box/port_92.h index 319b2b3ac..2dd4319be 100644 --- a/src/include/86box/port_92.h +++ b/src/include/86box/port_92.h @@ -20,9 +20,9 @@ #define EMU_PORT_92_H #ifdef _TIMER_H_ -typedef struct -{ - uint8_t reg, flags; +typedef struct port_92_t { + uint8_t reg; + uint8_t flags; pc_timer_t pulse_timer; diff --git a/src/include/86box/ppi.h b/src/include/86box/ppi.h index 0e12c98f8..d5649bcc8 100644 --- a/src/include/86box/ppi.h +++ b/src/include/86box/ppi.h @@ -3,7 +3,8 @@ typedef struct PPI { int s2; - uint8_t pa, pb; + uint8_t pa; + uint8_t pb; } PPI; extern int ppispeakon; diff --git a/src/include/86box/resource.h b/src/include/86box/resource.h index 397443299..2080c3a3b 100644 --- a/src/include/86box/resource.h +++ b/src/include/86box/resource.h @@ -142,26 +142,27 @@ #define IDT_CD_LUN 1766 /* LUN: */ #define IDT_CD_CHANNEL 1767 /* Channel: */ #define IDT_CD_SPEED 1768 /* Speed: */ +#define IDT_CD_TYPE 1769 /* Type: */ /* DLG_CFG_OTHER_REMOVABLE_DEVICES */ -#define IDT_MO_DRIVES 1769 /* MO drives: */ -#define IDT_MO_BUS 1770 /* Bus: */ -#define IDT_MO_ID 1771 /* ID: */ -#define IDT_MO_CHANNEL 1772 /* Channel */ -#define IDT_MO_TYPE 1773 /* Type: */ +#define IDT_MO_DRIVES 1770 /* MO drives: */ +#define IDT_MO_BUS 1771 /* Bus: */ +#define IDT_MO_ID 1772 /* ID: */ +#define IDT_MO_CHANNEL 1773 /* Channel */ +#define IDT_MO_TYPE 1774 /* Type: */ -#define IDT_ZIP_DRIVES 1774 /* ZIP drives: */ -#define IDT_ZIP_BUS 1775 /* Bus: */ -#define IDT_ZIP_ID 1776 /* ID: */ -#define IDT_ZIP_LUN 1777 /* LUN: */ -#define IDT_ZIP_CHANNEL 1778 /* Channel: */ +#define IDT_ZIP_DRIVES 1775 /* ZIP drives: */ +#define IDT_ZIP_BUS 1776 /* Bus: */ +#define IDT_ZIP_ID 1777 /* ID: */ +#define IDT_ZIP_LUN 1778 /* LUN: */ +#define IDT_ZIP_CHANNEL 1779 /* Channel: */ /* DLG_CFG_PERIPHERALS */ -#define IDT_ISARTC 1779 /* ISA RTC: */ -#define IDT_ISAMEM_1 1780 /* ISAMEM Board #1: */ -#define IDT_ISAMEM_2 1781 /* ISAMEM Board #2: */ -#define IDT_ISAMEM_3 1782 /* ISAMEM Board #3: */ -#define IDT_ISAMEM_4 1783 /* ISAMEM Board #4: */ +#define IDT_ISARTC 1780 /* ISA RTC: */ +#define IDT_ISAMEM_1 1781 /* ISAMEM Board #1: */ +#define IDT_ISAMEM_2 1782 /* ISAMEM Board #2: */ +#define IDT_ISAMEM_3 1783 /* ISAMEM Board #3: */ +#define IDT_ISAMEM_4 1784 /* ISAMEM Board #4: */ /* * To try to keep these organized, we now group the @@ -185,19 +186,20 @@ #ifdef USE_DYNAREC # define IDC_CHECK_DYNAREC 1017 #endif -#define IDC_MEMTEXT 1018 -#define IDC_MEMSPIN 1019 +#define IDC_CHECK_SOFTFLOAT 1018 +#define IDC_MEMTEXT 1019 +#define IDC_MEMSPIN 1020 #define IDC_TEXT_MB IDT_MB -#define IDC_VIDEO 1020 /* video config */ -#define IDC_COMBO_VIDEO 1021 -#define IDC_VIDEO_2 1022 -#define IDC_COMBO_VIDEO_2 1023 -#define IDC_CHECK_VOODOO 1024 -#define IDC_BUTTON_VOODOO 1025 -#define IDC_CHECK_IBM8514 1026 -#define IDC_CHECK_XGA 1027 -#define IDC_BUTTON_XGA 1028 +#define IDC_VIDEO 1021 /* video config */ +#define IDC_COMBO_VIDEO 1022 +#define IDC_VIDEO_2 1023 +#define IDC_COMBO_VIDEO_2 1024 +#define IDC_CHECK_VOODOO 1025 +#define IDC_BUTTON_VOODOO 1026 +#define IDC_CHECK_IBM8514 1027 +#define IDC_CHECK_XGA 1028 +#define IDC_BUTTON_XGA 1029 #define IDC_INPUT 1030 /* input config */ #define IDC_COMBO_MOUSE 1031 @@ -278,7 +280,7 @@ #define IDC_COMBO_HD_BUS 1135 #define IDC_COMBO_HD_CHANNEL 1136 #define IDC_COMBO_HD_ID 1137 -#define IDC_COMBO_HD_LUN 1138 +#define IDC_COMBO_HD_SPEED 1138 #define IDC_COMBO_HD_CHANNEL_IDE 1139 #define IDC_EDIT_HD_FILE_NAME 1140 /* add hard disk dialog */ @@ -301,7 +303,7 @@ #define IDC_COMBO_CD_ID 1157 #define IDC_COMBO_CD_LUN 1158 #define IDC_COMBO_CD_CHANNEL_IDE 1159 -#define IDC_CHECKEARLY 1160 +#define IDC_COMBO_CD_TYPE 1160 #define IDC_LIST_ZIP_DRIVES 1170 /* other removable devices config */ #define IDC_COMBO_ZIP_BUS 1171 diff --git a/src/include/86box/rom.h b/src/include/86box/rom.h index 91f813a95..e4c50ac01 100644 --- a/src/include/86box/rom.h +++ b/src/include/86box/rom.h @@ -32,7 +32,7 @@ #define bios_load_interleavedr(a, b, c, d, e) bios_load(a, b, c, d, e, FLAG_INT | FLAG_REP) #define bios_load_aux_interleaved(a, b, c, d, e) bios_load(a, b, c, d, e, FLAG_INT | FLAG_AUX) -typedef struct { +typedef struct rom_t { uint8_t *rom; int sz; uint32_t mask; @@ -54,7 +54,7 @@ extern uint32_t rom_readl(uint32_t addr, void *p); extern FILE *rom_fopen(const char *fn, char *mode); extern int rom_getfile(char *fn, char *s, int size); -extern int rom_present(char *fn); +extern int rom_present(const char *fn); extern int rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr); diff --git a/src/include/86box/row.h b/src/include/86box/row.h new file mode 100644 index 000000000..9dab7d4c3 --- /dev/null +++ b/src/include/86box/row.h @@ -0,0 +1,46 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Definitions for the SMRAM interface. + * + * + * + * Authors: Miran Grca, + * + * Copyright 2016-2020 Miran Grca. + */ + +#ifndef EMU_ROW_H +# define EMU_ROW_H + +typedef struct _row_ +{ + struct _smram_ *prev; + struct _smram_ *next; + + uint8_t *buf; + + mem_mapping_t mapping; + + uint32_t host_base; + uint32_t host_size; + uint32_t ram_base; + uint32_t ram_size; + uint32_t ram_mask; + uint32_t boundary; +} row_t; + + +extern void row_disable(uint8_t row_id); +extern void row_set_boundary(uint8_t row_id, uint32_t boundary); + + +extern device_t row_device; + + +#endif /*EMU_ROW_H*/ diff --git a/src/include/86box/scsi_cdrom.h b/src/include/86box/scsi_cdrom.h index 6b94c2aa4..64c24c10e 100644 --- a/src/include/86box/scsi_cdrom.h +++ b/src/include/86box/scsi_cdrom.h @@ -22,31 +22,42 @@ #define CDROM_TIME 10.0 #ifdef SCSI_DEVICE_H -typedef struct { +typedef struct scsi_cdrom_t { /* Common block. */ mode_sense_pages_t ms_pages_saved; cdrom_t *drv; - uint8_t *buffer, - atapi_cdb[16], - current_cdb[16], - sense[256]; + uint8_t *buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint8_t status, phase, - error, id, - features, cur_lun, - early, pad1; + uint8_t status; + uint8_t phase; + uint8_t error; + uint8_t id; + uint8_t features; + uint8_t cur_lun; + uint8_t early; + uint8_t pad1; - uint16_t request_length, max_transfer_len; + uint16_t request_length; + uint16_t max_transfer_len; - int requested_blocks, packet_status, - total_length, do_page_save, - unit_attention, request_pos, - old_len, media_status; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int media_status; - uint32_t sector_pos, sector_len, - packet_len, pos; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t pos; double callback; diff --git a/src/include/86box/scsi_device.h b/src/include/86box/scsi_device.h index 61048fb54..7256970cd 100644 --- a/src/include/86box/scsi_device.h +++ b/src/include/86box/scsi_device.h @@ -43,142 +43,142 @@ #define MCR_ERR 0x08 /* Media change request */ /* SCSI commands. */ -#define GPCMD_TEST_UNIT_READY 0x00 -#define GPCMD_REZERO_UNIT 0x01 -#define GPCMD_REQUEST_SENSE 0x03 -#define GPCMD_FORMAT_UNIT 0x04 -#define GPCMD_IOMEGA_SENSE 0x06 -#define GPCMD_READ_6 0x08 -#define GPCMD_WRITE_6 0x0a -#define GPCMD_SEEK_6 0x0b -#define GPCMD_IOMEGA_SET_PROTECTION_MODE 0x0c -#define GPCMD_IOMEGA_EJECT 0x0d /* ATAPI only? */ -#define GPCMD_NO_OPERATION_TOSHIBA 0x0d /* Toshiba Vendor Unique command */ -#define GPCMD_NO_OPERATION_NEC 0x0d /* NEC Vendor Unique command */ -#define GPCMD_INQUIRY 0x12 -#define GPCMD_VERIFY_6 0x13 -#define GPCMD_MODE_SELECT_6 0x15 -#define GPCMD_SCSI_RESERVE 0x16 -#define GPCMD_SCSI_RELEASE 0x17 -#define GPCMD_MODE_SENSE_6 0x1a -#define GPCMD_START_STOP_UNIT 0x1b -#define GPCMD_SEND_DIAGNOSTIC 0x1d -#define GPCMD_PREVENT_REMOVAL 0x1e -#define GPCMD_READ_FORMAT_CAPACITIES 0x23 -#define GPCMD_READ_CDROM_CAPACITY 0x25 -#define GPCMD_UNKNOWN_CHINON 0x26 /*Chinon Vendor Unique command*/ -#define GPCMD_READ_10 0x28 -#define GPCMD_READ_GENERATION 0x29 -#define GPCMD_WRITE_10 0x2a -#define GPCMD_SEEK_10 0x2b -#define GPCMD_ERASE_10 0x2c -#define GPCMD_WRITE_AND_VERIFY_10 0x2e -#define GPCMD_VERIFY_10 0x2f -#define GPCMD_READ_BUFFER 0x3c -#define GPCMD_WRITE_SAME_10 0x41 -#define GPCMD_READ_SUBCHANNEL 0x42 -#define GPCMD_READ_TOC_PMA_ATIP 0x43 -#define GPCMD_READ_HEADER 0x44 -#define GPCMD_PLAY_AUDIO_10 0x45 -#define GPCMD_GET_CONFIGURATION 0x46 -#define GPCMD_PLAY_AUDIO_MSF 0x47 -#define GPCMD_PLAY_AUDIO_TRACK_INDEX 0x48 -#define GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10 0x49 -#define GPCMD_GET_EVENT_STATUS_NOTIFICATION 0x4a -#define GPCMD_PAUSE_RESUME 0x4b -#define GPCMD_STOP_PLAY_SCAN 0x4e -#define GPCMD_READ_DISC_INFORMATION 0x51 -#define GPCMD_READ_TRACK_INFORMATION 0x52 -#define GPCMD_MODE_SELECT_10 0x55 -#define GPCMD_MODE_SENSE_10 0x5a -#define GPCMD_PLAY_AUDIO_12 0xa5 -#define GPCMD_READ_12 0xa8 -#define GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12 0xa9 -#define GPCMD_WRITE_12 0xaa -#define GPCMD_ERASE_12 0xac -#define GPCMD_READ_DVD_STRUCTURE 0xad /* For reading. */ -#define GPCMD_WRITE_AND_VERIFY_12 0xae -#define GPCMD_VERIFY_12 0xaf -#define GPCMD_PLAY_CD_OLD 0xb4 -#define GPCMD_READ_CD_OLD 0xb8 -#define GPCMD_READ_CD_MSF 0xb9 -#define GPCMD_AUDIO_SCAN 0xba -#define GPCMD_SET_SPEED 0xbb -#define GPCMD_PLAY_CD 0xbc -#define GPCMD_MECHANISM_STATUS 0xbd -#define GPCMD_READ_CD 0xbe -#define GPCMD_SEND_DVD_STRUCTURE 0xbf /* This is for writing only, irrelevant to 86Box. */ -#define GPCMD_EJECT_CHINON 0xc0 /* Chinon Vendor Unique command */ -#define GPCMD_AUDIO_TRACK_SEARCH_TOSHIBA 0xc0 /* Toshiba Vendor Unique command */ -#define GPCMD_UNKNOWN_SONY 0xc0 /* Sony Vendor Unique command */ -#define GPCMD_PLAY_AUDIO_TOSHIBA 0xc1 /* Toshiba Vendor Unique command */ -#define GPCMD_READ_TOC_SONY 0xc1 /* Sony Vendor Unique command */ -#define GPCMD_PAUSE_RESUME_ALT 0xc2 -#define GPCMD_READ_SUBCHANNEL_MATSUSHITA 0xc2 /* Matsushita Vendor Unique command */ -#define GPCMD_READ_SUBCHANNEL_SONY 0xc2 /* Sony Vendor Unique command */ -#define GPCMD_STILL_TOSHIBA 0xc2 /* Toshiba Vendor Unique command */ -#define GPCMD_READ_TOC_MATSUSHITA 0xc3 /* Matsushita Vendor Unique command */ -#define GPCMD_READ_HEADER_SONY 0xc3 /* Sony Vendor Unique command */ -#define GPCMD_SET_STOP_TIME_TOSHIBA 0xc3 /* Toshiba Vendor Unique command */ -#define GPCMD_READ_HEADER_MATSUSHITA 0xc4 /* Matsushita Vendor Unique command */ -#define GPCMD_PLAYBACK_STATUS_TOSHIBA 0xc4 /* Sony Vendor Unique command */ -#define GPCMD_CADDY_EJECT_TOSHIBA 0xc4 /* Toshiba Vendor Unique command */ -#define GPCMD_PAUSE_SONY 0xc5 /* Sony Vendor Unique command */ -#define GPCMD_PLAY_AUDIO_MATSUSHITA 0xc5 /* Matsushita Vendor Unique command */ -#define GPCMD_STOP_CHINON 0xc6 /* Chinon Vendor Unique command */ -#define GPCMD_PLAT_TRACK_SONY 0xc6 /* Sony Vendor Unique command */ -#define GPCMD_READ_SUBCODEQ_PLAYING_STATUS_TOSHIBA 0xc6 /* Toshiba Vendor Unique command */ -#define GPCMD_PLAY_AUDIO_MSF_MATSUSHITA 0xc7 /* Matsushita Vendor Unique command*/ -#define GPCMD_PLAY_MSF_SONY 0xc7 /* Sony Vendor Unique command*/ -#define GPCMD_READ_DISC_INFORMATION_TOSHIBA 0xc7 /* Toshiba Vendor Unique command */ -#define GPCMD_PLAY_AUDIO_TRACK_INDEX_MATSUSHITA 0xc8 /* Matsushita Vendor Unique command */ -#define GPCMD_PLAY_AUDIO_SONY 0xc8 /* Sony Vendor Unique command */ +#define GPCMD_TEST_UNIT_READY 0x00 +#define GPCMD_REZERO_UNIT 0x01 +#define GPCMD_REQUEST_SENSE 0x03 +#define GPCMD_FORMAT_UNIT 0x04 +#define GPCMD_IOMEGA_SENSE 0x06 +#define GPCMD_READ_6 0x08 +#define GPCMD_WRITE_6 0x0a +#define GPCMD_SEEK_6 0x0b +#define GPCMD_IOMEGA_SET_PROTECTION_MODE 0x0c +#define GPCMD_IOMEGA_EJECT 0x0d /* ATAPI only? */ +#define GPCMD_NO_OPERATION_TOSHIBA 0x0d /* Toshiba Vendor Unique command */ +#define GPCMD_NO_OPERATION_NEC 0x0d /* NEC Vendor Unique command */ +#define GPCMD_INQUIRY 0x12 +#define GPCMD_VERIFY_6 0x13 +#define GPCMD_MODE_SELECT_6 0x15 +#define GPCMD_SCSI_RESERVE 0x16 +#define GPCMD_SCSI_RELEASE 0x17 +#define GPCMD_MODE_SENSE_6 0x1a +#define GPCMD_START_STOP_UNIT 0x1b +#define GPCMD_SEND_DIAGNOSTIC 0x1d +#define GPCMD_PREVENT_REMOVAL 0x1e +#define GPCMD_READ_FORMAT_CAPACITIES 0x23 +#define GPCMD_READ_CDROM_CAPACITY 0x25 +#define GPCMD_UNKNOWN_CHINON 0x26 /*Chinon Vendor Unique command*/ +#define GPCMD_READ_10 0x28 +#define GPCMD_READ_GENERATION 0x29 +#define GPCMD_WRITE_10 0x2a +#define GPCMD_SEEK_10 0x2b +#define GPCMD_ERASE_10 0x2c +#define GPCMD_WRITE_AND_VERIFY_10 0x2e +#define GPCMD_VERIFY_10 0x2f +#define GPCMD_READ_BUFFER 0x3c +#define GPCMD_WRITE_SAME_10 0x41 +#define GPCMD_READ_SUBCHANNEL 0x42 +#define GPCMD_READ_TOC_PMA_ATIP 0x43 +#define GPCMD_READ_HEADER 0x44 +#define GPCMD_PLAY_AUDIO_10 0x45 +#define GPCMD_GET_CONFIGURATION 0x46 +#define GPCMD_PLAY_AUDIO_MSF 0x47 +#define GPCMD_PLAY_AUDIO_TRACK_INDEX 0x48 +#define GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10 0x49 +#define GPCMD_GET_EVENT_STATUS_NOTIFICATION 0x4a +#define GPCMD_PAUSE_RESUME 0x4b +#define GPCMD_STOP_PLAY_SCAN 0x4e +#define GPCMD_READ_DISC_INFORMATION 0x51 +#define GPCMD_READ_TRACK_INFORMATION 0x52 +#define GPCMD_MODE_SELECT_10 0x55 +#define GPCMD_MODE_SENSE_10 0x5a +#define GPCMD_PLAY_AUDIO_12 0xa5 +#define GPCMD_READ_12 0xa8 +#define GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12 0xa9 +#define GPCMD_WRITE_12 0xaa +#define GPCMD_ERASE_12 0xac +#define GPCMD_READ_DVD_STRUCTURE 0xad /* For reading. */ +#define GPCMD_WRITE_AND_VERIFY_12 0xae +#define GPCMD_VERIFY_12 0xaf +#define GPCMD_PLAY_CD_OLD 0xb4 +#define GPCMD_READ_CD_OLD 0xb8 +#define GPCMD_READ_CD_MSF 0xb9 +#define GPCMD_AUDIO_SCAN 0xba +#define GPCMD_SET_SPEED 0xbb +#define GPCMD_PLAY_CD 0xbc +#define GPCMD_MECHANISM_STATUS 0xbd +#define GPCMD_READ_CD 0xbe +#define GPCMD_SEND_DVD_STRUCTURE 0xbf /* This is for writing only, irrelevant to 86Box. */ +#define GPCMD_EJECT_CHINON 0xc0 /* Chinon Vendor Unique command */ +#define GPCMD_AUDIO_TRACK_SEARCH_TOSHIBA 0xc0 /* Toshiba Vendor Unique command */ +#define GPCMD_UNKNOWN_SONY 0xc0 /* Sony Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_TOSHIBA 0xc1 /* Toshiba Vendor Unique command */ +#define GPCMD_READ_TOC_SONY 0xc1 /* Sony Vendor Unique command */ +#define GPCMD_PAUSE_RESUME_ALT 0xc2 +#define GPCMD_READ_SUBCHANNEL_MATSUSHITA 0xc2 /* Matsushita Vendor Unique command */ +#define GPCMD_READ_SUBCHANNEL_SONY 0xc2 /* Sony Vendor Unique command */ +#define GPCMD_STILL_TOSHIBA 0xc2 /* Toshiba Vendor Unique command */ +#define GPCMD_READ_TOC_MATSUSHITA 0xc3 /* Matsushita Vendor Unique command */ +#define GPCMD_READ_HEADER_SONY 0xc3 /* Sony Vendor Unique command */ +#define GPCMD_SET_STOP_TIME_TOSHIBA 0xc3 /* Toshiba Vendor Unique command */ +#define GPCMD_READ_HEADER_MATSUSHITA 0xc4 /* Matsushita Vendor Unique command */ +#define GPCMD_PLAYBACK_STATUS_TOSHIBA 0xc4 /* Sony Vendor Unique command */ +#define GPCMD_CADDY_EJECT_TOSHIBA 0xc4 /* Toshiba Vendor Unique command */ +#define GPCMD_PAUSE_SONY 0xc5 /* Sony Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_MATSUSHITA 0xc5 /* Matsushita Vendor Unique command */ +#define GPCMD_STOP_CHINON 0xc6 /* Chinon Vendor Unique command */ +#define GPCMD_PLAT_TRACK_SONY 0xc6 /* Sony Vendor Unique command */ +#define GPCMD_READ_SUBCODEQ_PLAYING_STATUS_TOSHIBA 0xc6 /* Toshiba Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_MSF_MATSUSHITA 0xc7 /* Matsushita Vendor Unique command*/ +#define GPCMD_PLAY_MSF_SONY 0xc7 /* Sony Vendor Unique command*/ +#define GPCMD_READ_DISC_INFORMATION_TOSHIBA 0xc7 /* Toshiba Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_TRACK_INDEX_MATSUSHITA 0xc8 /* Matsushita Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_SONY 0xc8 /* Sony Vendor Unique command */ #define GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10_MATSUSHITA 0xc9 /*Matsushita Vendor Unique command */ -#define GPCMD_PLAYBACK_CONTROL_SONY 0xc9 /* Sony Vendor Unique command */ -#define GPCMD_PAUSE_RESUME_MATSUSHITA 0xcb /* Matsushita Vendor Unique command */ -#define GPCMD_SCAN_PIONEER 0xcd /* Should be equivalent to 0xba */ -#define GPCMD_AUDIO_TRACK_SEARCH_NEC 0xd8 /* NEC Vendor Unique command */ -#define GPCMD_PLAY_AUDIO_NEC 0xd9 /* NEC Vendor Unique command */ -#define GPCMD_STILL_NEC 0xda /* NEC Vendor Unique command */ -#define GPCMD_SET_SPEED_ALT 0xda /* Should be equivalent to 0xbb */ -#define GPCMD_SET_STOP_TIME_NEC 0xdb /* NEC Vendor Unique command */ -#define GPCMD_CADDY_EJECT_NEC 0xdc /* NEC Vendor Unique command */ -#define GPCMD_READ_SUBCODEQ_PLAYING_STATUS_NEC 0xdd /* NEC Vendor Unique command */ -#define GPCMD_READ_DISC_INFORMATION_NEC 0xde /* NEC Vendor Unique command */ -#define GPCMD_PLAY_AUDIO_12_MATSUSHITA 0xe5 /* Matsushita Vendor Unique command */ +#define GPCMD_PLAYBACK_CONTROL_SONY 0xc9 /* Sony Vendor Unique command */ +#define GPCMD_PAUSE_RESUME_MATSUSHITA 0xcb /* Matsushita Vendor Unique command */ +#define GPCMD_SCAN_PIONEER 0xcd /* Should be equivalent to 0xba */ +#define GPCMD_AUDIO_TRACK_SEARCH_NEC 0xd8 /* NEC Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_NEC 0xd9 /* NEC Vendor Unique command */ +#define GPCMD_STILL_NEC 0xda /* NEC Vendor Unique command */ +#define GPCMD_SET_SPEED_ALT 0xda /* Should be equivalent to 0xbb */ +#define GPCMD_SET_STOP_TIME_NEC 0xdb /* NEC Vendor Unique command */ +#define GPCMD_CADDY_EJECT_NEC 0xdc /* NEC Vendor Unique command */ +#define GPCMD_READ_SUBCODEQ_PLAYING_STATUS_NEC 0xdd /* NEC Vendor Unique command */ +#define GPCMD_READ_DISC_INFORMATION_NEC 0xde /* NEC Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_12_MATSUSHITA 0xe5 /* Matsushita Vendor Unique command */ #define GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12_MATSUSHITA 0xe9 /* Matsushita Vendor Unique command */ /* Mode page codes for mode sense/set */ -#define GPMODE_R_W_ERROR_PAGE 0x01 -#define GPMODE_DISCONNECT_PAGE 0x02 /* Disconnect/reconnect page */ -#define GPMODE_FORMAT_DEVICE_PAGE 0x03 -#define GPMODE_RIGID_DISK_PAGE 0x04 /* Rigid disk geometry page */ -#define GPMODE_FLEXIBLE_DISK_PAGE 0x05 -#define GPMODE_CACHING_PAGE 0x08 -#define GPMODE_CDROM_PAGE_SONY 0x08 +#define GPMODE_R_W_ERROR_PAGE 0x01 +#define GPMODE_DISCONNECT_PAGE 0x02 /* Disconnect/reconnect page */ +#define GPMODE_FORMAT_DEVICE_PAGE 0x03 +#define GPMODE_RIGID_DISK_PAGE 0x04 /* Rigid disk geometry page */ +#define GPMODE_FLEXIBLE_DISK_PAGE 0x05 +#define GPMODE_CACHING_PAGE 0x08 +#define GPMODE_CDROM_PAGE_SONY 0x08 #define GPMODE_CDROM_AUDIO_PAGE_SONY 0x09 -#define GPMODE_CDROM_PAGE 0x0d -#define GPMODE_CDROM_AUDIO_PAGE 0x0e -#define GPMODE_CAPABILITIES_PAGE 0x2a -#define GPMODE_IOMEGA_PAGE 0x2f -#define GPMODE_UNK_VENDOR_PAGE 0x30 -#define GPMODE_ALL_PAGES 0x3f +#define GPMODE_CDROM_PAGE 0x0d +#define GPMODE_CDROM_AUDIO_PAGE 0x0e +#define GPMODE_CAPABILITIES_PAGE 0x2a +#define GPMODE_IOMEGA_PAGE 0x2f +#define GPMODE_UNK_VENDOR_PAGE 0x30 +#define GPMODE_ALL_PAGES 0x3f /* Mode page codes for presence */ -#define GPMODEP_R_W_ERROR_PAGE 0x0000000000000002LL -#define GPMODEP_DISCONNECT_PAGE 0x0000000000000004LL -#define GPMODEP_FORMAT_DEVICE_PAGE 0x0000000000000008LL -#define GPMODEP_RIGID_DISK_PAGE 0x0000000000000010LL -#define GPMODEP_FLEXIBLE_DISK_PAGE 0x0000000000000020LL -#define GPMODEP_CACHING_PAGE 0x0000000000000100LL -#define GPMODEP_CDROM_PAGE_SONY 0x0000000000000200LL +#define GPMODEP_R_W_ERROR_PAGE 0x0000000000000002LL +#define GPMODEP_DISCONNECT_PAGE 0x0000000000000004LL +#define GPMODEP_FORMAT_DEVICE_PAGE 0x0000000000000008LL +#define GPMODEP_RIGID_DISK_PAGE 0x0000000000000010LL +#define GPMODEP_FLEXIBLE_DISK_PAGE 0x0000000000000020LL +#define GPMODEP_CACHING_PAGE 0x0000000000000100LL +#define GPMODEP_CDROM_PAGE_SONY 0x0000000000000200LL #define GPMODEP_CDROM_AUDIO_PAGE_SONY 0x0000000000000400LL -#define GPMODEP_CDROM_PAGE 0x0000000000002000LL -#define GPMODEP_CDROM_AUDIO_PAGE 0x0000000000004000LL -#define GPMODEP_CAPABILITIES_PAGE 0x0000040000000000LL -#define GPMODEP_IOMEGA_PAGE 0x0000800000000000LL -#define GPMODEP_UNK_VENDOR_PAGE 0x0001000000000000LL -#define GPMODEP_ALL_PAGES 0x8000000000000000LL +#define GPMODEP_CDROM_PAGE 0x0000000000002000LL +#define GPMODEP_CDROM_AUDIO_PAGE 0x0000000000004000LL +#define GPMODEP_CAPABILITIES_PAGE 0x0000040000000000LL +#define GPMODEP_IOMEGA_PAGE 0x0000800000000000LL +#define GPMODEP_UNK_VENDOR_PAGE 0x0001000000000000LL +#define GPMODEP_ALL_PAGES 0x8000000000000000LL /* SCSI Status Codes */ #define SCSI_STATUS_OK 0 @@ -338,7 +338,7 @@ #define MODE_SELECT_PHASE_PAGE_HEADER 3 #define MODE_SELECT_PHASE_PAGE 4 -typedef struct { +typedef struct mode_sense_pages_t { uint8_t pages[0x40][0x40]; } mode_sense_pages_t; @@ -349,34 +349,46 @@ typedef struct scsi_common_s { void *p; - uint8_t *temp_buffer, - atapi_cdb[16], /* This is atapi_cdb in ATAPI-supporting devices, - and pad in SCSI-only devices. */ - current_cdb[16], - sense[256]; + uint8_t *temp_buffer; + uint8_t atapi_cdb[16]; /* This is atapi_cdb in ATAPI-supporting devices, + and pad in SCSI-only devices. */ + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint8_t status, phase, - error, id, - features, cur_lun, - pad0, pad1; + uint8_t status; + uint8_t phase; + uint8_t error; + uint8_t id; + uint8_t features; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - uint16_t request_length, max_transfer_len; + uint16_t request_length; + uint16_t max_transfer_len; - int requested_blocks, packet_status, - total_length, do_page_save, - unit_attention, request_pos, - old_len, media_status; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int media_status; - uint32_t sector_pos, sector_len, - packet_len, pos; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t pos; double callback; } scsi_common_t; -typedef struct { +typedef struct scsi_device_t { int32_t buffer_length; - uint8_t status, phase; + uint8_t status; + uint8_t phase; uint16_t type; scsi_common_t *sc; diff --git a/src/include/86box/scsi_disk.h b/src/include/86box/scsi_disk.h index bff40a396..ebf21c073 100644 --- a/src/include/86box/scsi_disk.h +++ b/src/include/86box/scsi_disk.h @@ -16,31 +16,42 @@ #ifndef SCSI_DISK_H #define SCSI_DISK_H -typedef struct { +typedef struct scsi_disk_t { mode_sense_pages_t ms_pages_saved; hard_disk_t *drv; - uint8_t *temp_buffer, - pad[16], /* This is atapi_cdb in ATAPI-supporting devices, - and pad in SCSI-only devices. */ - current_cdb[16], - sense[256]; + uint8_t *temp_buffer; + uint8_t pad[16]; /* This is atapi_cdb in ATAPI-supporting devices, + and pad in SCSI-only devices. */ + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint8_t status, phase, - error, id, - pad0, cur_lun, - pad1, pad2; + uint8_t status; + uint8_t phase; + uint8_t error; + uint8_t id; + uint8_t pad0; + uint8_t cur_lun; + uint8_t pad1; + uint8_t pad2; - uint16_t request_length, pad4; + uint16_t request_length; + uint16_t pad4; - int requested_blocks, packet_status, - total_length, do_page_save, - unit_attention, pad5, - pad6, pad7; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int pad5; + int pad6; + int pad7; - uint32_t sector_pos, sector_len, - packet_len, pos; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t pos; double callback; } scsi_disk_t; diff --git a/src/include/86box/scsi_x54x.h b/src/include/86box/scsi_x54x.h index a20f1e788..213873c5a 100644 --- a/src/include/86box/scsi_x54x.h +++ b/src/include/86box/scsi_x54x.h @@ -196,51 +196,51 @@ #define MAX_SG_DESCRIPTORS 32 /* Always make the array 32 elements long, if less are used, that's not an issue. */ #pragma pack(push, 1) -typedef struct { +typedef struct addr24_s { uint8_t hi; uint8_t mid; uint8_t lo; -} addr24; +} addr24_t; /* Structure for the INQUIRE_SETUP_INFORMATION reply. */ -typedef struct { - uint8_t uOffset : 4, - uTransferPeriod : 3, - fSynchronous : 1; +typedef struct ReplyInquireSetupInformationSynchronousValue_t { + uint8_t uOffset : 4; + uint8_t uTransferPeriod : 3; + uint8_t fSynchronous : 1; } ReplyInquireSetupInformationSynchronousValue; -typedef struct { - uint8_t fSynchronousInitiationEnabled : 1, - fParityCheckingEnabled : 1, - uReserved1 : 6; +typedef struct ReplyInquireSetupInformation_t { + uint8_t fSynchronousInitiationEnabled : 1; + uint8_t fParityCheckingEnabled : 1; + uint8_t uReserved1 : 6; uint8_t uBusTransferRate; uint8_t uPreemptTimeOnBus; uint8_t uTimeOffBus; uint8_t cMailbox; - addr24 MailboxAddress; + addr24_t MailboxAddress; ReplyInquireSetupInformationSynchronousValue SynchronousValuesId0To7[8]; uint8_t uDisconnectPermittedId0To7; uint8_t VendorSpecificData[28]; } ReplyInquireSetupInformation; -typedef struct { +typedef struct MailboxInit_t { uint8_t Count; - addr24 Address; + addr24_t Address; } MailboxInit_t; -typedef struct { - uint8_t CmdStatus; - addr24 CCBPointer; +typedef struct Mailbox_t { + uint8_t CmdStatus; + addr24_t CCBPointer; } Mailbox_t; -typedef struct { +typedef struct Mailbox32_t { uint32_t CCBPointer; union { - struct { + struct out_t { uint8_t Reserved[3]; uint8_t ActionCode; } out; - struct { + struct in_t { uint8_t HostStatus; uint8_t TargetStatus; uint8_t Reserved; @@ -255,7 +255,7 @@ typedef struct { Bytes 16 and 17 Reserved (must be 0) Bytes 18 through 18+n-1, where n=size of CDB Command Descriptor Block */ -typedef struct { +typedef struct CCB32_t { uint8_t Opcode; uint8_t Reserved1 : 3, ControlByte : 2, @@ -277,24 +277,24 @@ typedef struct { uint32_t SensePointer; } CCB32; -typedef struct { - uint8_t Opcode; - uint8_t Lun : 3, - ControlByte : 2, - Id : 3; - uint8_t CdbLength; - uint8_t RequestSenseLength; - addr24 DataLength; - addr24 DataPointer; - addr24 LinkPointer; - uint8_t LinkId; - uint8_t HostStatus; - uint8_t TargetStatus; - uint8_t Reserved[2]; - uint8_t Cdb[12]; +typedef struct CCB_t { + uint8_t Opcode; + uint8_t Lun : 3; + uint8_t ControlByte : 2; + uint8_t Id : 3; + uint8_t CdbLength; + uint8_t RequestSenseLength; + addr24_t DataLength; + addr24_t DataPointer; + addr24_t LinkPointer; + uint8_t LinkId; + uint8_t HostStatus; + uint8_t TargetStatus; + uint8_t Reserved[2]; + uint8_t Cdb[12]; } CCB; -typedef struct { +typedef struct CCBC_t { uint8_t Opcode; uint8_t Pad1 : 3, ControlByte : 2, @@ -309,7 +309,7 @@ typedef struct { uint8_t Cdb[12]; } CCBC; -typedef union { +typedef union CCBU_t { CCB32 new; CCB old; CCBC common; @@ -320,26 +320,25 @@ typedef struct { uint8_t *RequestSenseBuffer; uint32_t CCBPointer; int Is24bit; - uint8_t TargetID, - LUN, - HostStatus, - TargetStatus, - MailboxCompletionCode; + uint8_t TargetID; + uint8_t LUN; + uint8_t HostStatus; + uint8_t TargetStatus; + uint8_t MailboxCompletionCode; } Req_t; -typedef struct -{ +typedef struct BIOSCMD_t { uint8_t command; uint8_t lun : 3, reserved : 2, id : 3; union { - struct { + struct chs_t { uint16_t cyl; uint8_t head; uint8_t sec; } chs; - struct { + struct lba_t { uint8_t lba0; /* MSB */ uint8_t lba1; uint8_t lba2; @@ -347,17 +346,17 @@ typedef struct } lba; } u; uint8_t secount; - addr24 dma_address; + addr24_t dma_address; } BIOSCMD; -typedef struct { +typedef struct SGE32_t { uint32_t Segment; uint32_t SegmentPointer; } SGE32; -typedef struct { - addr24 Segment; - addr24 SegmentPointer; +typedef struct SGE_t { + addr24_t Segment; + addr24_t SegmentPointer; } SGE; #pragma pack(pop) @@ -368,92 +367,111 @@ typedef struct { #define X54X_MBX_24BIT 16 #define X54X_ISAPNP 32 -typedef struct { +typedef struct x54x_t { /* 32 bytes */ - char vendor[16], /* name of device vendor */ - name[16]; /* name of device */ + char vendor[16]; /* name of device vendor */ + char name[16]; /* name of device */ /* 24 bytes */ - int8_t type, /* type of device */ - IrqEnabled, Irq, - DmaChannel, - HostID; + int8_t type; /* type of device */ + int8_t IrqEnabled; + int8_t Irq; + int8_t DmaChannel; + int8_t HostID; - uint8_t callback_phase : 4, - callback_sub_phase : 4, - scsi_cmd_phase, bus, - sync, - parity, shram_mode, - Geometry, Control, - Command, CmdParam, - BusOnTime, BusOffTime, - ATBusSpeed, setup_info_len, - max_id, pci_slot, - temp_cdb[12]; + uint8_t callback_phase : 4; + uint8_t callback_sub_phase : 4; + uint8_t scsi_cmd_phase; + uint8_t bus; + uint8_t sync; + uint8_t parity; + uint8_t shram_mode; + uint8_t Geometry; + uint8_t Control; + uint8_t Command; + uint8_t CmdParam; + uint8_t BusOnTime; + uint8_t BusOffTime; + uint8_t ATBusSpeed; + uint8_t setup_info_len; + uint8_t max_id; + uint8_t pci_slot; + uint8_t temp_cdb[12]; - volatile uint8_t /* for multi-threading, keep */ - Status, - Interrupt, /* these volatile */ - MailboxIsBIOS, ToRaise, - flags; + /* for multi-threading, keep these volatile */ + volatile uint8_t Status; + volatile uint8_t Interrupt; + volatile uint8_t MailboxIsBIOS; + volatile uint8_t ToRaise; + volatile uint8_t flags; /* 65928 bytes */ - uint8_t pos_regs[8], /* MCA */ - CmdBuf[128], - DataBuf[65536], - shadow_ram[128], - dma_buffer[128], - cmd_33_buf[4096]; + uint8_t pos_regs[8]; /* MCA */ + uint8_t CmdBuf[128]; + uint8_t DataBuf[65536]; + uint8_t shadow_ram[128]; + uint8_t dma_buffer[128]; + uint8_t cmd_33_buf[4096]; /* 16 bytes */ char *fw_rev; /* The 4 bytes of the revision command information + 2 extra bytes for BusLogic */ - uint8_t *rom1, /* main BIOS image */ - *rom2, /* SCSI-Select image */ - *nvr; /* EEPROM buffer */ + uint8_t *rom1; /* main BIOS image */ + uint8_t *rom2; /* SCSI-Select image */ + uint8_t *nvr; /* EEPROM buffer */ /* 6 words = 12 bytes */ - uint16_t DataReply, DataReplyLeft, - rom_ioaddr, /* offset in BIOS of I/O addr */ - rom_shram, /* index to shared RAM */ - rom_shramsz, /* size of shared RAM */ - rom_fwhigh, /* offset in BIOS of ver ID */ - pnp_len, /* length of the PnP ROM */ - pnp_offset, /* offset in the microcode ROM of the PnP ROM */ - cmd_33_len, /* length of the SCSISelect code decompressor program */ - cmd_33_offset; /* offset in the microcode ROM of the SCSISelect code decompressor program */ + uint16_t DataReply; + uint16_t DataReplyLeft; + uint16_t rom_ioaddr; /* offset in BIOS of I/O addr */ + uint16_t rom_shram; /* index to shared RAM */ + uint16_t rom_shramsz; /* size of shared RAM */ + uint16_t rom_fwhigh; /* offset in BIOS of ver ID */ + uint16_t pnp_len; /* length of the PnP ROM */ + uint16_t pnp_offset; /* offset in the microcode ROM of the PnP ROM */ + uint16_t cmd_33_len; /* length of the SCSISelect code decompressor program */ + uint16_t cmd_33_offset; /* offset in the microcode ROM of the SCSISelect code decompressor program */ /* 16 + 20 + 52 = 88 bytes */ - volatile int - MailboxOutInterrupts, - PendingInterrupt, Lock, - target_data_len, pad0; + volatile int MailboxOutInterrupts; + volatile int PendingInterrupt; + volatile int Lock; + volatile int target_data_len; + volatile int pad0; - uint32_t Base, fdc_address, rom_addr, /* address of BIOS ROM */ - CmdParamLeft, Outgoing, - transfer_size; + uint32_t Base; + uint32_t fdc_address; + uint32_t rom_addr; /* address of BIOS ROM */ + uint32_t CmdParamLeft; + uint32_t Outgoing; + uint32_t transfer_size; - volatile uint32_t - MailboxInit, - MailboxCount, - MailboxOutAddr, MailboxOutPosCur, - MailboxInAddr, MailboxInPosCur, - MailboxReq, - BIOSMailboxInit, BIOSMailboxCount, - BIOSMailboxOutAddr, BIOSMailboxOutPosCur, - BIOSMailboxReq, - Residue, card_bus; /* Basically a copy of device flags */ + volatile uint32_t MailboxInit; + volatile uint32_t MailboxCount; + volatile uint32_t MailboxOutAddr; + volatile uint32_t MailboxOutPosCur; + volatile uint32_t MailboxInAddr; + volatile uint32_t MailboxInPosCur; + volatile uint32_t MailboxReq; + volatile uint32_t BIOSMailboxInit; + volatile uint32_t BIOSMailboxCount; + volatile uint32_t BIOSMailboxOutAddr; + volatile uint32_t BIOSMailboxOutPosCur; + volatile uint32_t BIOSMailboxReq; + volatile uint32_t Residue; + volatile uint32_t card_bus; /* Basically a copy of device flags */ /* 8 bytes */ uint64_t temp_period; /* 16 bytes */ - double media_period, ha_bps; /* bytes per second */ + double media_period; + double ha_bps; /* bytes per second */ /* 8 bytes */ - char *bios_path, /* path to BIOS image file */ - *mcode_path, /* path to microcode image file, needed by the AHA-1542CP */ - *nvr_path; /* path to NVR image file */ + char *bios_path; /* path to BIOS image file */ + char *mcode_path; /* path to microcode image file, needed by the AHA-1542CP */ + char *nvr_path; /* path to NVR image file */ /* 56 bytes */ /* Pointer to a structure of vendor-specific data that only the vendor-specific code can understand */ @@ -486,12 +504,13 @@ typedef struct { /* Pointer to a function that resets vendor-specific data */ void (*ven_reset)(void *p); - rom_t bios, /* BIOS memory descriptor */ - uppersck; /* BIOS memory descriptor */ + rom_t bios; /* BIOS memory descriptor */ + rom_t uppersck; /* BIOS memory descriptor */ mem_mapping_t mmio_mapping; - pc_timer_t timer, ResetCB; + pc_timer_t timer; + pc_timer_t ResetCB; Req_t Req; diff --git a/src/include/86box/serial.h b/src/include/86box/serial.h index 8ed3606a7..b27e54c5e 100644 --- a/src/include/86box/serial.h +++ b/src/include/86box/serial.h @@ -48,23 +48,52 @@ struct serial_device_s; struct serial_s; typedef struct serial_s { - uint8_t lsr, thr, mctrl, rcr, - iir, ier, lcr, msr, - dat, int_status, scratch, fcr, - irq, type, inst, transmit_enabled, - fifo_enabled, rcvr_fifo_len, bits, data_bits, - baud_cycles, rcvr_fifo_full, txsr, out, - msr_set, pad, pad0, pad1; + uint8_t lsr; + uint8_t thr; + uint8_t mctrl; + uint8_t rcr; + uint8_t iir; + uint8_t ier; + uint8_t lcr; + uint8_t msr; + uint8_t dat; + uint8_t int_status; + uint8_t scratch; + uint8_t fcr; + uint8_t irq; + uint8_t type; + uint8_t inst; + uint8_t transmit_enabled; + uint8_t fifo_enabled; + uint8_t rcvr_fifo_len; + uint8_t bits; + uint8_t data_bits; + uint8_t baud_cycles; + uint8_t rcvr_fifo_full; + uint8_t txsr; + uint8_t out; + uint8_t msr_set; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; - uint16_t dlab, base_address, out_new, pad2; + uint16_t dlab; + uint16_t base_address; + uint16_t out_new; + uint16_t pad2; - uint8_t rcvr_fifo_pos, xmit_fifo_pos, - rcvr_fifo_end, xmit_fifo_end, - rcvr_fifo[SERIAL_FIFO_SIZE], xmit_fifo[SERIAL_FIFO_SIZE]; + uint8_t rcvr_fifo_pos; + uint8_t xmit_fifo_pos; + uint8_t rcvr_fifo_end; + uint8_t xmit_fifo_end; + uint8_t rcvr_fifo[SERIAL_FIFO_SIZE]; + uint8_t xmit_fifo[SERIAL_FIFO_SIZE]; - pc_timer_t transmit_timer, timeout_timer, - receive_timer; - double clock_src, transmit_period; + pc_timer_t transmit_timer; + pc_timer_t timeout_timer; + pc_timer_t receive_timer; + double clock_src; + double transmit_period; struct serial_device_s *sd; } serial_t; @@ -78,7 +107,7 @@ typedef struct serial_device_s { serial_t *serial; } serial_device_t; -typedef struct { +typedef struct serial_port_s { uint8_t enabled; } serial_port_t; diff --git a/src/include/86box/serial_passthrough.h b/src/include/86box/serial_passthrough.h index 9612b9500..7ca6479d6 100644 --- a/src/include/86box/serial_passthrough.h +++ b/src/include/86box/serial_passthrough.h @@ -43,7 +43,8 @@ typedef struct serial_passthrough_s { pc_timer_t serial_to_host_timer; serial_t *serial; double baudrate; - uint8_t bits, data_bits; + uint8_t bits; + uint8_t data_bits; uint8_t port; uint8_t data; char slave_pt[32]; /* used for pseudo term name of slave side */ diff --git a/src/include/86box/smbus.h b/src/include/86box/smbus.h index 9bb429b43..340d1d00e 100644 --- a/src/include/86box/smbus.h +++ b/src/include/86box/smbus.h @@ -26,27 +26,39 @@ enum { SMBUS_PIIX4 = 0, - SMBUS_VIA + SMBUS_VIA = 1 }; -typedef struct { - uint32_t local; - uint16_t io_base; - int clock; - double bit_period; - uint8_t stat, next_stat, ctl, cmd, addr, - data0, data1, - index, data[SMBUS_PIIX4_BLOCK_DATA_SIZE]; +typedef struct smbus_piix4_t { + uint32_t local; + uint16_t io_base; + int clock; + double bit_period; + uint8_t stat; + uint8_t next_stat; + uint8_t ctl; + uint8_t cmd; + uint8_t addr; + uint8_t data0; + uint8_t data1; + uint8_t index; + uint8_t data[SMBUS_PIIX4_BLOCK_DATA_SIZE]; pc_timer_t response_timer; void *i2c; } smbus_piix4_t; -typedef struct { - uint32_t local; - uint16_t io_base; - uint8_t stat, next_stat, ctl, cmd, addr, - data0, data1, - index, data[SMBUS_ALI7101_BLOCK_DATA_SIZE]; +typedef struct smbus_ali7101_t { + uint32_t local; + uint16_t io_base; + uint8_t stat; + uint8_t next_stat; + uint8_t ctl; + uint8_t cmd; + uint8_t addr; + uint8_t data0; + uint8_t data1; + uint8_t index; + uint8_t data[SMBUS_ALI7101_BLOCK_DATA_SIZE]; pc_timer_t response_timer; void *i2c; } smbus_ali7101_t; diff --git a/src/include/86box/smram.h b/src/include/86box/smram.h index 84d1cbe8d..707c967f5 100644 --- a/src/include/86box/smram.h +++ b/src/include/86box/smram.h @@ -19,13 +19,16 @@ #define EMU_SMRAM_H typedef struct _smram_ { - struct _smram_ *prev, *next; + struct _smram_ *prev; + struct _smram_ *next; mem_mapping_t mapping; - uint32_t host_base, ram_base, - size, - old_host_base, old_size; + uint32_t host_base; + uint32_t ram_base; + uint32_t size; + uint32_t old_host_base; + uint32_t old_size; } smram_t; /* Make a backup copy of host_base and size of all the SMRAM structs, needed so that if diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index 14d31dc40..45a921863 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -17,7 +17,7 @@ #ifndef SOUND_AC97_H #define SOUND_AC97_H -#define AC97_VENDOR_ID(f, s, t, dev) ((((f) &0xff) << 24) | (((s) &0xff) << 16) | (((t) &0xff) << 8) | ((dev) &0xff)) +#define AC97_VENDOR_ID(a, b, c, i) ((((a) &0xff) << 24) | (((b) &0xff) << 16) | (((c) &0xff) << 8) | ((i) &0xff)) /* Misc support bits (misc_flags). Most of these are not part of any registers, but control enabling/disabling of registers and bits. */ @@ -91,27 +91,29 @@ #define AC97_PRK (1 << 13) #define AC97_PRL (1 << 14) -/* New codecs should be added to the end of this enum to avoid breaking configs. */ -enum { - AC97_CODEC_AD1881 = 0, - AC97_CODEC_ALC100, - AC97_CODEC_CS4297, - AC97_CODEC_CS4297A, - AC97_CODEC_WM9701A, - AC97_CODEC_STAC9708, - AC97_CODEC_STAC9721, - AC97_CODEC_AK4540 -}; +/* Codec IDs. */ +#define AC97_CODEC_AD1881 AC97_VENDOR_ID('A', 'D', 'S', 0x40) +#define AC97_CODEC_AK4540 AC97_VENDOR_ID('A', 'D', 'S', 0x40) +#define AC97_CODEC_ALC100 AC97_VENDOR_ID('A', 'L', 'C', 0x20) +#define AC97_CODEC_CS4297 AC97_VENDOR_ID('C', 'R', 'Y', 0x03) +#define AC97_CODEC_CS4297A AC97_VENDOR_ID('C', 'R', 'Y', 0x11) +#define AC97_CODEC_STAC9708 AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x08) +#define AC97_CODEC_STAC9721 AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x09) +#define AC97_CODEC_TR28023 AC97_VENDOR_ID('T', 'R', 'A', 0x03) +#define AC97_CODEC_WM9701A AC97_VENDOR_ID('W', 'M', 'L', 0x00) -typedef struct { - const uint16_t index, value, write_mask; +typedef struct ac97_vendor_reg_t { + uint8_t page; /* for paged registers [60:6F], 0 otherwise */ + uint8_t index; + uint16_t value; + uint16_t write_mask; } ac97_vendor_reg_t; -typedef struct { - uint32_t vendor_id, min_rate, max_rate, misc_flags; - uint16_t reset_flags, extid_flags, - powerdown_mask, regs[64]; - uint8_t codec_id, vendor_reg_page_max; +typedef struct ac97_codec_t { + int model; + uint16_t regs[64]; + uint8_t codec_id; + uint8_t vendor_reg_page_max; const ac97_vendor_reg_t *vendor_regs; uint16_t *vendor_reg_pages; } ac97_codec_t; @@ -121,7 +123,7 @@ extern void ac97_codec_writew(ac97_codec_t *dev, uint8_t reg, uint16_ extern void ac97_codec_reset(void *priv); extern void ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r); extern uint32_t ac97_codec_getrate(void *priv, uint8_t reg); -extern const device_t *ac97_codec_get(int model); +extern const device_t *ac97_codec_get(uint32_t id); extern void ac97_via_set_slot(void *priv, int slot, int irq_pin); extern uint8_t ac97_via_read_status(void *priv, uint8_t modem); @@ -131,9 +133,12 @@ extern void ac97_via_remap_modem_sgd(void *priv, uint16_t new_io_base, uint8_ extern void ac97_via_remap_audio_codec(void *priv, uint16_t new_io_base, uint8_t enable); extern void ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable); -extern ac97_codec_t **ac97_codec, **ac97_modem_codec; -extern int ac97_codec_count, ac97_modem_codec_count, - ac97_codec_id, ac97_modem_codec_id; +extern ac97_codec_t **ac97_codec; +extern ac97_codec_t **ac97_modem_codec; +extern int ac97_codec_count; +extern int ac97_modem_codec_count; +extern int ac97_codec_id; +extern int ac97_modem_codec_id; #ifdef EMU_DEVICE_H extern const device_t ad1881_device; @@ -141,8 +146,10 @@ extern const device_t ak4540_device; extern const device_t alc100_device; extern const device_t cs4297_device; extern const device_t cs4297a_device; +# define ct1297_device tr28023_device extern const device_t stac9708_device; extern const device_t stac9721_device; +extern const device_t tr28023_device; extern const device_t wm9701a_device; extern const device_t ac97_via_device; diff --git a/src/include/86box/snd_ad1848.h b/src/include/86box/snd_ad1848.h index 76fc775db..be7831fb4 100644 --- a/src/include/86box/snd_ad1848.h +++ b/src/include/86box/snd_ad1848.h @@ -24,26 +24,42 @@ enum { AD1848_TYPE_DEFAULT = 0, - AD1848_TYPE_CS4248, - AD1848_TYPE_CS4231, - AD1848_TYPE_CS4235, - AD1848_TYPE_CS4236 + AD1848_TYPE_CS4248 = 1, + AD1848_TYPE_CS4231 = 2, + AD1848_TYPE_CS4235 = 3, + AD1848_TYPE_CS4236 = 4 }; -typedef struct { - uint8_t type, index, xindex, regs[32], xregs[32], status; /* 16 original registers + 16 CS4231A extensions + 32 CS4236 extensions */ +typedef struct ad1848_t { + uint8_t type; + uint8_t index; + uint8_t xindex; + uint8_t regs[32]; + uint8_t xregs[32]; + uint8_t status; /* 16 original registers + 16 CS4231A extensions + 32 CS4236 extensions */ int count; - uint8_t trd, mce, wten : 1; + uint8_t trd; + uint8_t mce; + uint8_t wten : 1; - int16_t out_l, out_r; - double cd_vol_l, cd_vol_r; - int fm_vol_l, fm_vol_r; - uint8_t fmt_mask, wave_vol_mask; + int16_t out_l; + int16_t out_r; + double cd_vol_l; + double cd_vol_r; + int fm_vol_l; + int fm_vol_r; + uint8_t fmt_mask; + uint8_t wave_vol_mask; - uint8_t enable : 1, irq : 4, dma : 3, adpcm_ref; + uint8_t enable : 1; + uint8_t irq : 4; + uint8_t dma : 3; + uint8_t adpcm_ref; int8_t adpcm_step; - int freq, adpcm_data, adpcm_pos; + int freq; + int adpcm_data; + int adpcm_pos; pc_timer_t timer_count; uint64_t timer_latch; diff --git a/src/include/86box/snd_emu8k.h b/src/include/86box/snd_emu8k.h index a163bdeaf..dd01eaac0 100644 --- a/src/include/86box/snd_emu8k.h +++ b/src/include/86box/snd_emu8k.h @@ -85,10 +85,14 @@ typedef struct emu8k_mem_pointers_t { */ typedef struct emu8k_envelope_t { int state; - int32_t delay_samples, hold_samples, attack_samples; - int32_t value_amp_hz, value_db_oct; + int32_t delay_samples; + int32_t hold_samples; + int32_t attack_samples; + int32_t value_amp_hz; + int32_t value_db_oct; int32_t sustain_value_db_oct; - int32_t attack_amount_amp_hz, ramp_amount_db_oct; + int32_t attack_amount_amp_hz; + int32_t ramp_amount_db_oct; } emu8k_envelope_t; typedef struct emu8k_chorus_eng_t { @@ -320,10 +324,14 @@ typedef struct emu8k_voice_t { emu8k_envelope_t vol_envelope; emu8k_envelope_t mod_envelope; - int64_t lfo1_speed, lfo2_speed; - emu8k_mem_internal_t lfo1_count, lfo2_count; - int32_t lfo1_delay_samples, lfo2_delay_samples; - int vol_l, vol_r; + int64_t lfo1_speed; + int64_t lfo2_speed; + emu8k_mem_internal_t lfo1_count; + emu8k_mem_internal_t lfo2_count; + int32_t lfo1_delay_samples; + int32_t lfo2_delay_samples; + int vol_l; + int vol_r; int16_t fixed_modenv_filter_height; int16_t fixed_modenv_pitch_height; @@ -342,28 +350,44 @@ typedef struct emu8k_voice_t { typedef struct emu8k_t { emu8k_voice_t voice[32]; - uint16_t hwcf1, hwcf2, hwcf3; - uint32_t hwcf4, hwcf5, hwcf6, hwcf7; + uint16_t hwcf1; + uint16_t hwcf2; + uint16_t hwcf3; + uint32_t hwcf4; + uint32_t hwcf5; + uint32_t hwcf6; + uint32_t hwcf7; - uint16_t init1[32], init2[32], init3[32], init4[32]; + uint16_t init1[32]; + uint16_t init2[32]; + uint16_t init3[32]; + uint16_t init4[32]; - uint32_t smalr, smarr, smalw, smarw; - uint16_t smld_buffer, smrd_buffer; + uint32_t smalr; + uint32_t smarr; + uint32_t smalw; + uint32_t smarw; + uint16_t smld_buffer; + uint16_t smrd_buffer; uint16_t wc; uint16_t id; /* The empty block is used to act as an unallocated memory returning zero. */ - int16_t *ram, *rom, *empty; + int16_t *ram; + int16_t *rom; + int16_t *empty; /* RAM pointers are a way to avoid checking ram boundaries on read */ int16_t *ram_pointers[0x100]; uint32_t ram_end_addr; - int cur_reg, cur_voice; + int cur_reg; + int cur_voice; - int16_t out_l, out_r; + int16_t out_l; + int16_t out_r; emu8k_chorus_eng_t chorus_engine; int32_t chorus_in_buffer[SOUNDBUFLEN]; diff --git a/src/include/86box/snd_mpu401.h b/src/include/86box/snd_mpu401.h index 4afbc6b53..ed8b89de7 100644 --- a/src/include/86box/snd_mpu401.h +++ b/src/include/86box/snd_mpu401.h @@ -26,7 +26,7 @@ #define MPU401_VERSION 0x15 #define MPU401_REVISION 0x01 -#define MPU401_QUEUE 64 +#define MPU401_QUEUE 1024 #define MPU401_INPUT_QUEUE 1024 #define MPU401_TIMECONSTANT (60000000 / 1000.0f) #define MPU401_RESETBUSY 27.0f @@ -71,80 +71,119 @@ typedef enum RecState { typedef struct mpu_t { uint16_t addr; - int uart_mode, intelligent, - irq, midi_thru, - queue_pos, queue_used; - uint8_t rx_data, is_mca, - status, - queue[MPU401_QUEUE], pos_regs[8]; + int uart_mode; + int intelligent; + int irq; + int midi_thru; + int queue_pos; + int queue_used; + uint8_t rx_data; + uint8_t is_mca; + uint8_t status; + uint8_t queue[MPU401_QUEUE]; + uint8_t pos_regs[8]; MpuMode mode; uint8_t rec_queue[MPU401_INPUT_QUEUE]; - int rec_queue_pos, rec_queue_used; + int rec_queue_pos; + int rec_queue_used; uint32_t ch_toref[16]; struct track { - int counter; - uint8_t value[3], sys_val, - vlength, length; + int counter; + uint8_t value[3]; + uint8_t sys_val; + uint8_t vlength; + uint8_t length; MpuDataType type; } playbuf[8], condbuf; struct { - int conductor, cond_req, - cond_set, block_ack, - playing, reset, - wsd, wsm, wsd_start, - run_irq, irq_pending, - track_req, - send_now, eoi_scheduled, - data_onoff, clock_to_host, - sync_in, sysex_in_finished, - rec_copy; + int conductor; + int cond_req; + int cond_set; + int block_ack; + int playing; + int reset; + int wsd; + int wsm; + int wsd_start; + int run_irq; + int irq_pending; + int track_req; + int send_now; + int eoi_scheduled; + int data_onoff; + int clock_to_host; + int sync_in; + int sysex_in_finished; + int rec_copy; RecState rec; - uint8_t tmask, cmask, - amask, - last_rtcmd; - uint16_t midi_mask, req_mask; - uint32_t command_byte, cmd_pending, - track, old_track; + uint8_t tmask; + uint8_t cmask; + uint8_t amask; + uint8_t last_rtcmd; + uint16_t midi_mask; + uint16_t req_mask; + uint32_t command_byte; + uint32_t cmd_pending; + uint32_t track; + uint32_t old_track; } state; struct { - uint8_t timebase, old_timebase, - tempo, old_tempo, - tempo_rel, old_tempo_rel, - tempo_grad, cth_rate[4], - cth_mode, midimetro, - metromeas; - uint32_t cth_counter, cth_old, - rec_counter; - int32_t measure_counter, meas_old, - freq; - int ticks_in, active; - float freq_mod; + uint8_t timebase; + uint8_t old_timebase; + uint8_t tempo; + uint8_t old_tempo; + uint8_t tempo_rel; + uint8_t old_tempo_rel; + uint8_t tempo_grad; + uint8_t cth_rate[4]; + uint8_t cth_mode; + uint8_t midimetro; + uint8_t metromeas; + uint32_t cth_counter; + uint32_t cth_old; + uint32_t rec_counter; + int32_t measure_counter; + int32_t meas_old; + int32_t freq; + int ticks_in; + int active; + float freq_mod; } clock; struct { - int all_thru, midi_thru, - sysex_thru, commonmsgs_thru, - modemsgs_in, commonmsgs_in, - bender_in, sysex_in, - allnotesoff_out, rt_affection, - rt_out, rt_in, - timing_in_stop, data_in_stop, - rec_measure_end; + int all_thru; + int midi_thru; + int sysex_thru; + int commonmsgs_thru; + int modemsgs_in; + int commonmsgs_in; + int bender_in; + int sysex_in; + int allnotesoff_out; + int rt_affection; + int rt_out; + int rt_in; + int timing_in_stop; + int data_in_stop; + int rec_measure_end; uint8_t prchg_buf[16]; uint16_t prchg_mask; } filter; struct { int on; - uint8_t chan, trmask; + uint8_t chan; + uint8_t trmask; uint32_t key[4]; } chanref[5], inputref[16]; - pc_timer_t mpu401_event_callback, mpu401_eoi_callback, - mpu401_reset_callback; + pc_timer_t mpu401_event_callback; + pc_timer_t mpu401_eoi_callback; + pc_timer_t mpu401_reset_callback; void (*ext_irq_update)(void *priv, int set); int (*ext_irq_pending)(void *priv); void *priv; } mpu_t; -extern int mpu401_standalone_enable, mpu401_already_loaded; +extern int mpu401_standalone_enable; +extern int mpu401_already_loaded; extern const device_t mpu401_device; extern const device_t mpu401_mca_device; diff --git a/src/include/86box/snd_opl.h b/src/include/86box/snd_opl.h index e7978d6f3..b7d1980ea 100644 --- a/src/include/86box/snd_opl.h +++ b/src/include/86box/snd_opl.h @@ -18,20 +18,20 @@ #define SOUND_OPL_H enum fm_type { - FM_YM3812 = 0, - FM_YMF262, - FM_YMF289B, - FM_YMF278B, - FM_MAX + FM_YM3812 = 0, /* OPL2 */ + FM_YMF262 = 1, /* OPL3 */ + FM_YMF289B = 2, /* OPL3-L */ + FM_YMF278B = 3, /* OPL 4 */ + FM_MAX = 4 }; enum fm_driver { FM_DRV_NUKED = 0, - FM_DRV_YMFM, - FM_DRV_MAX + FM_DRV_YMFM = 1, + FM_DRV_MAX = 2 }; -typedef struct { +typedef struct fm_drv_t { uint8_t (*read)(uint16_t port, void *priv); void (*write)(uint16_t port, uint8_t val, void *priv); int32_t *(*update)(void *priv); diff --git a/src/include/86box/snd_sb.h b/src/include/86box/snd_sb.h index 88f2c74f1..4c6b2bba7 100644 --- a/src/include/86box/snd_sb.h +++ b/src/include/86box/snd_sb.h @@ -48,16 +48,16 @@ typedef struct sb_ct1335_mixer_t { /* SB PRO */ typedef struct sb_ct1345_mixer_t { - double master_l, - master_r; - double voice_l, - voice_r; - double fm_l, - fm_r; - double cd_l, - cd_r; - double line_l, - line_r; + double master_l; + double master_r; + double voice_l; + double voice_r; + double fm_l; + double fm_r; + double cd_l; + double cd_r; + double line_l; + double line_r; double mic; /*see sb_ct1745_mixer for values for input selector*/ int32_t input_selector; @@ -76,23 +76,23 @@ typedef struct sb_ct1345_mixer_t { /* SB16 and AWE32 */ typedef struct sb_ct1745_mixer_t { - double master_l, - master_r; - double voice_l, - voice_r; - double fm_l, - fm_r; - double cd_l, - cd_r; - double line_l, - line_r; + double master_l; + double master_r; + double voice_l; + double voice_r; + double fm_l; + double fm_r; + double cd_l; + double cd_r; + double line_l; + double line_r; double mic; double speaker; - int bass_l, - bass_r; - int treble_l, - treble_r; + int bass_l; + int bass_r; + int treble_l; + int treble_r; int output_selector; #define OUTPUT_MIC 1 @@ -125,12 +125,12 @@ typedef struct sb_ct1745_mixer_t { } sb_ct1745_mixer_t; typedef struct sb_t { - uint8_t cms_enabled, - opl_enabled, - mixer_enabled; + uint8_t cms_enabled; + uint8_t opl_enabled; + uint8_t mixer_enabled; cms_t cms; - fm_drv_t opl, - opl2; + fm_drv_t opl; + fm_drv_t opl2; sb_dsp_t dsp; union { sb_ct1335_mixer_t mixer_sb2; @@ -143,8 +143,8 @@ typedef struct sb_t { int pos; - uint8_t pos_regs[8], - pnp_rom[512]; + uint8_t pos_regs[8]; + uint8_t pnp_rom[512]; uint16_t opl_pnp_addr; diff --git a/src/include/86box/snd_sb_dsp.h b/src/include/86box/snd_sb_dsp.h index 1e9a91828..86f1ee529 100644 --- a/src/include/86box/snd_sb_dsp.h +++ b/src/include/86box/snd_sb_dsp.h @@ -15,19 +15,34 @@ typedef struct sb_dsp_t { int sb_subtype; /* which clone */ void *parent; /* "sb_t *" if default subtype, "azt2316a_t *" if aztech. */ - int sb_8_length, sb_8_origlength, sb_8_format, sb_8_autoinit, sb_8_pause, sb_8_enable, sb_8_autolen, sb_8_output; + int sb_8_length; + int sb_8_origlength; + int sb_8_format; + int sb_8_autoinit; + int sb_8_pause; + int sb_8_enable; + int sb_8_autolen; + int sb_8_output; int sb_8_dmanum; - int sb_16_length, sb_16_origlength, sb_16_format, sb_16_autoinit, sb_16_pause, sb_16_enable, sb_16_autolen, sb_16_output; + int sb_16_length; + int sb_16_origlength; + int sb_16_format; + int sb_16_autoinit; + int sb_16_pause; + int sb_16_enable; + int sb_16_autolen; + int sb_16_output; int sb_16_dmanum; int sb_pausetime; - int (*dma_readb)(void *priv), - (*dma_readw)(void *priv), - (*dma_writeb)(void *priv, uint8_t val), - (*dma_writew)(void *priv, uint16_t val); + int (*dma_readb)(void *priv); + int (*dma_readw)(void *priv); + int (*dma_writeb)(void *priv, uint8_t val); + int (*dma_writew)(void *priv, uint16_t val); void *dma_priv; uint8_t sb_read_data[256]; - int sb_read_wp, sb_read_rp; + int sb_read_wp; + int sb_read_rp; int sb_speaker; int muted; @@ -41,8 +56,8 @@ typedef struct sb_dsp_t { int midi_in_timestamp; int sb_irqnum; - void (*irq_update)(void *priv, int set), - *irq_priv; + void (*irq_update)(void *priv, int set); + void *irq_priv; uint8_t sbe2; int sbe2count; @@ -53,23 +68,30 @@ typedef struct sb_dsp_t { int16_t sbdat; int sbdat2; - int16_t sbdatl, sbdatr; + int16_t sbdatl; + int16_t sbdatr; uint8_t sbref; int8_t sbstep; int sbdacpos; - int sbleftright, sbleftright_default; + int sbleftright; + int sbleftright_default; int sbreset; uint8_t sbreaddat; uint8_t sb_command; uint8_t sb_test; - int sb_timei, sb_timeo; + int sb_timei; + int sb_timeo; - int sb_irq8, sb_irq16, sb_irq401; - int sb_irqm8, sb_irqm16, sb_irqm401; + int sb_irq8; + int sb_irq16; + int sb_irq401; + int sb_irqm8; + int sb_irqm16; + int sb_irqm401; uint8_t sb_asp_regs[256]; uint8_t sb_asp_mode; @@ -79,11 +101,14 @@ typedef struct sb_dsp_t { uint8_t sb_8051_ram[256]; - int sbenable, sb_enable_i; + int sbenable; + int sb_enable_i; - pc_timer_t output_timer, input_timer; + pc_timer_t output_timer; + pc_timer_t input_timer; - double sblatcho, sblatchi; + double sblatcho; + double sblatchi; uint16_t sb_addr; diff --git a/src/include/86box/snd_sn76489.h b/src/include/86box/snd_sn76489.h index c8a3a567c..6e7399d54 100644 --- a/src/include/86box/snd_sn76489.h +++ b/src/include/86box/snd_sn76489.h @@ -14,8 +14,10 @@ extern int sn76489_mute; typedef struct sn76489_t { int stat[4]; - int latch[4], count[4]; - int freqlo[4], freqhi[4]; + int latch[4]; + int count[4]; + int freqlo[4]; + int freqhi[4]; int vol[4]; uint32_t shift; uint8_t noise; diff --git a/src/include/86box/snd_speaker.h b/src/include/86box/snd_speaker.h index 516d20588..fa1a6fe19 100644 --- a/src/include/86box/snd_speaker.h +++ b/src/include/86box/snd_speaker.h @@ -23,7 +23,8 @@ extern int speaker_mute; extern int speaker_gated; -extern int speaker_enable, was_speaker_enable; +extern int speaker_enable; +extern int was_speaker_enable; extern void speaker_init(void); diff --git a/src/include/86box/snd_ym7128.h b/src/include/86box/snd_ym7128.h index 4d5400f34..a0796b1fa 100644 --- a/src/include/86box/snd_ym7128.h +++ b/src/include/86box/snd_ym7128.h @@ -2,19 +2,26 @@ #define SOUND_YM7128_H typedef struct ym7128_t { - int a0, sci; + int a0; + int sci; uint8_t dat; int reg_sel; uint8_t regs[32]; - int gl[8], gr[8]; - int vm, vc, vl, vr; - int c0, c1; + int gl[8]; + int gr[8]; + int vm; + int vc; + int vl; + int vr; + int c0; + int c1; int t[9]; int16_t filter_dat; - int16_t prev_l, prev_r; + int16_t prev_l; + int16_t prev_r; int16_t delay_buffer[2400]; int delay_pos; diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index dada9e164..4c01f289c 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -24,13 +24,13 @@ extern int sound_gain; -#define FREQ_44100 44100 -#define FREQ_48000 48000 -#define FREQ_49716 49716 -#define FREQ_88200 88200 -#define FREQ_96000 96000 +#define FREQ_44100 44100 +#define FREQ_48000 48000 +#define FREQ_49716 49716 +#define FREQ_88200 88200 +#define FREQ_96000 96000 -#define SOUND_FREQ FREQ_48000 +#define SOUND_FREQ FREQ_48000 #define SOUNDBUFLEN (SOUND_FREQ / 50) #define CD_FREQ FREQ_44100 @@ -42,9 +42,9 @@ enum { }; extern int ppispeakon; -extern int gated, - speakval, - speakon; +extern int gated; +extern int speakval; +extern int speakon; extern int sound_pos_global; extern int sound_card_current[SOUND_CARD_MAX]; @@ -62,7 +62,7 @@ extern const device_t *sound_card_getdevice(int card); #endif extern int sound_card_has_config(int card); extern char *sound_card_get_internal_name(int card); -extern int sound_card_get_from_internal_name(char *s); +extern int sound_card_get_from_internal_name(const char *s); extern void sound_card_init(void); extern void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r); diff --git a/src/include/86box/spd.h b/src/include/86box/spd.h index ae4342675..98eb4e178 100644 --- a/src/include/86box/spd.h +++ b/src/include/86box/spd.h @@ -46,49 +46,92 @@ #define SPD_SDR_ATTR_VCC_LOW_5 0x10 #define SPD_SDR_ATTR_VCC_HI_5 0x20 -typedef struct { - uint8_t bytes_used, spd_size, mem_type, - row_bits, col_bits, banks, - data_width_lsb, data_width_msb, - signal_level, trac, tcac, - config, refresh_rate, - dram_width, ecc_width, - reserved[47], - spd_rev, checksum, - mfg_jedec[8], mfg_loc; +typedef struct spd_edo_t { + uint8_t bytes_used; + uint8_t spd_size; + uint8_t mem_type; + uint8_t row_bits; + uint8_t col_bits; + uint8_t banks; + uint8_t data_width_lsb; + uint8_t data_width_msb; + uint8_t signal_level; + uint8_t trac; + uint8_t tcac; + uint8_t config; + uint8_t refresh_rate; + uint8_t dram_width; + uint8_t ecc_width; + uint8_t reserved[47]; + uint8_t spd_rev; + uint8_t checksum; + uint8_t mfg_jedec[8]; + uint8_t mfg_loc; char part_no[18]; - uint8_t rev_code[2], - mfg_year, mfg_week, serial[4], mfg_specific[27], - vendor_specific[2], - other_data[127], - checksum2; + uint8_t rev_code[2]; + uint8_t mfg_year; + uint8_t mfg_week; + uint8_t serial[4]; + uint8_t mfg_specific[27]; + uint8_t vendor_specific[2]; + uint8_t other_data[127]; + uint8_t checksum2; } spd_edo_t; -typedef struct { - uint8_t bytes_used, spd_size, mem_type, - row_bits, col_bits, rows, - data_width_lsb, data_width_msb, - signal_level, tclk, tac, - config, refresh_rate, - sdram_width, ecc_width, - tccd, burst, banks, cas, cslat, we, - mod_attr, dev_attr, - tclk2, tac2, tclk3, tac3, - trp, trrd, trcd, tras, - bank_density, - ca_setup, ca_hold, data_setup, data_hold, - reserved[26], - spd_rev, checksum, - mfg_jedec[8], mfg_loc; +typedef struct spd_sdram_t { + uint8_t bytes_used; + uint8_t spd_size; + uint8_t mem_type; + uint8_t row_bits; + uint8_t col_bits; + uint8_t rows; + uint8_t data_width_lsb; + uint8_t data_width_msb; + uint8_t signal_level; + uint8_t tclk; + uint8_t tac; + uint8_t config; + uint8_t refresh_rate; + uint8_t sdram_width; + uint8_t ecc_width; + uint8_t tccd; + uint8_t burst; + uint8_t banks; + uint8_t cas; + uint8_t cslat; + uint8_t we; + uint8_t mod_attr; + uint8_t dev_attr; + uint8_t tclk2; + uint8_t tac2; + uint8_t tclk3; + uint8_t tac3; + uint8_t trp; + uint8_t trrd; + uint8_t trcd; + uint8_t tras; + uint8_t bank_density; + uint8_t ca_setup; + uint8_t ca_hold; + uint8_t data_setup; + uint8_t data_hold; + uint8_t reserved[26]; + uint8_t spd_rev, checksum; + uint8_t mfg_jedec[8]; + uint8_t mfg_loc; char part_no[18]; - uint8_t rev_code[2], - mfg_year, mfg_week, serial[4], mfg_specific[27], - freq, features, - other_data[127], - checksum2; + uint8_t rev_code[2]; + uint8_t mfg_year; + uint8_t mfg_week; + uint8_t serial[4]; + uint8_t mfg_specific[27]; + uint8_t freq; + uint8_t features; + uint8_t other_data[127]; + uint8_t checksum2; } spd_sdram_t; -typedef struct { +typedef struct spd_t { uint8_t slot; uint16_t size; uint16_t row1; diff --git a/src/include/86box/timer.h b/src/include/86box/timer.h index c9b89788a..e38ac51a3 100644 --- a/src/include/86box/timer.h +++ b/src/include/86box/timer.h @@ -11,14 +11,14 @@ #define TIMER_ENABLED 1 #pragma pack(push, 1) -typedef struct +typedef struct ts_struct_t { uint32_t frac; uint32_t integer; } ts_struct_t; #pragma pack(pop) -typedef union { +typedef union ts_t { uint64_t ts64; ts_struct_t ts32; } ts_t; @@ -42,14 +42,16 @@ typedef struct pc_timer_t { #else ts_t ts; #endif - int flags, pad; /* The flags are defined above. */ - double period; /* This is used for large period timers to count - the microseconds and split the period. */ + int flags; /* The flags are defined above. */ + int pad; + double period; /* This is used for large period timers to count + the microseconds and split the period. */ - void (*callback)(void *p); - void *p; + void (*callback)(void *priv); + void *priv; - struct pc_timer_t *prev, *next; + struct pc_timer_t *prev; + struct pc_timer_t *next; } pc_timer_t; #ifdef __cplusplus @@ -74,7 +76,7 @@ extern void timer_init(void); /*Add new timer. If start_timer is set, timer will be enabled with a zero timestamp - this is useful for permanently enabled timers*/ -extern void timer_add(pc_timer_t *timer, void (*callback)(void *p), void *p, int start_timer); +extern void timer_add(pc_timer_t *timer, void (*callback)(void *priv), void *priv, int start_timer); /*1us in 32:32 format*/ extern uint64_t TIMER_USEC; @@ -160,16 +162,16 @@ timer_get_remaining_u64(pc_timer_t *timer) /*Set timer callback function*/ static __inline void -timer_set_callback(pc_timer_t *timer, void (*callback)(void *p)) +timer_set_callback(pc_timer_t *timer, void (*callback)(void *priv)) { timer->callback = callback; } /*Set timer private data*/ static __inline void -timer_set_p(pc_timer_t *timer, void *p) +timer_set_p(pc_timer_t *timer, void *priv) { - timer->p = p; + timer->priv = priv; } /* The API for big timer periods starts here. */ @@ -207,7 +209,7 @@ timer_process_inline(void) if (timer->flags & TIMER_SPLIT) timer_advance_ex(timer, 0); /* We're splitting a > 1 s period into multiple <= 1 s periods. */ else if (timer->callback != NULL) /* Make sure it's no NULL, so that we can have a NULL callback when no operation is needed. */ - timer->callback(timer->p); + timer->callback(timer->priv); } timer_target = timer_head->ts.ts32.integer; diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index d0b169b6c..7c2e13ee9 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -22,21 +22,188 @@ extern "C" { #endif -typedef struct +typedef struct usb_t usb_t; +typedef struct usb_device_t usb_device_t; + +enum usb_pid { - uint8_t uhci_io[32], ohci_mmio[4096]; + USB_PID_OUT = 0xE1, + USB_PID_IN = 0x69, + USB_PID_SETUP = 0x2D +}; + +enum usb_errors +{ + USB_ERROR_NO_ERROR = 0, + USB_ERROR_NAK = 1, + USB_ERROR_OVERRUN = 2, + USB_ERROR_UNDERRUN = 3 +}; + +enum usb_bus_types +{ + USB_BUS_OHCI = 0, + USB_BUS_UHCI = 1, + USB_BUS_MAX = 2 +}; + +/* USB device creation parameters struct */ +typedef struct usb_params_t +{ + void (*update_interrupt)(usb_t*, void*); + /* Handle (but do not raise) SMI. Returns 1 if SMI can be raised, 0 otherwise. */ + uint8_t (*smi_handle)(usb_t*, void*); + void* parent_priv; +} usb_params_t; + +typedef union { + uint32_t l; + uint16_t w[2]; + uint8_t b[4]; +} ohci_mmio_t; + +/* USB Host Controller device struct */ +typedef struct usb_t { + uint8_t uhci_io[32]; + ohci_mmio_t ohci_mmio[1024]; uint16_t uhci_io_base; - int uhci_enable, ohci_enable; + int uhci_enable; + int ohci_enable; uint32_t ohci_mem_base; + uint32_t irq_level; mem_mapping_t ohci_mmio_mapping; + pc_timer_t ohci_frame_timer; + pc_timer_t ohci_port_reset_timer[2]; + uint8_t ohci_interrupt_counter : 3; + usb_device_t *ohci_devices[2]; + usb_device_t *uhci_devices[2]; + uint8_t ohci_usb_buf[4096]; + uint8_t ohci_initial_start; + + usb_params_t *usb_params; } usb_t; +#pragma pack(push, 1) + +/* Base USB descriptor struct. */ +typedef struct usb_desc_base_t { + uint8_t bLength; + uint8_t bDescriptorType; +} usb_desc_base_t; + +enum usb_desc_setup_req_types { + USB_SETUP_TYPE_DEVICE = 0x0, + USB_SETUP_TYPE_INTERFACE = 0x1, + USB_SETUP_TYPE_ENDPOING = 0x2, + USB_SETUP_TYPE_OTHER = 0x3, +}; + +#define USB_SETUP_TYPE_MAX 0x1F + +#define USB_SETUP_DEV_TO_HOST 0x80 + +typedef struct usb_desc_setup_t { + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} usb_desc_setup_t; + +typedef struct usb_desc_endpoint_t { + usb_desc_base_t base; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} usb_desc_endpoint_t; + +typedef struct usb_desc_hid_t { + usb_desc_base_t base; + + uint16_t bcdHID; + uint8_t bCountryCode; + uint8_t bNumDescriptors; + uint8_t bDescriptorType; + uint16_t wDescriptorLength; +} usb_desc_hid_t; + +typedef struct usb_desc_interface_t { + usb_desc_base_t base; + + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} usb_desc_interface_t; + +typedef struct usb_desc_string_t { + usb_desc_base_t base; + uint16_t bString[]; +} usb_desc_string_t; + +typedef struct usb_desc_conf_t { + usb_desc_base_t base; + + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; +} usb_desc_conf_t; + +typedef struct usb_desc_device_t { + usb_desc_base_t base; + + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} usb_desc_device_t; + +#pragma pack(pop) + +/* USB endpoint device struct. Incomplete and unused. */ +typedef struct usb_device_t { + usb_desc_device_t device_desc; + struct { + usb_desc_conf_t conf_desc; + usb_desc_base_t* other_descs[16]; + } conf_desc_items; + + /* General-purpose function for I/O. Non-zero value indicates error. */ + uint8_t (*device_process)(void* priv, uint8_t* data, uint32_t *len, uint8_t pid_token, uint8_t endpoint, uint8_t underrun_not_allowed); + /* Device reset. */ + void (*device_reset)(void* priv); + /* Get address. */ + uint8_t (*device_get_address)(void* priv); + + void* priv; +} usb_device_t; + /* Global variables. */ extern const device_t usb_device; +extern usb_t* usb_device_inst; /* Functions. */ extern void uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable); extern void ohci_update_mem_mapping(usb_t *dev, uint8_t base1, uint8_t base2, uint8_t base3, int enable); +/* Attach USB device to a port of a USB bus. Returns the port to which it got attached to. */ +extern uint8_t usb_attach_device(usb_t *dev, usb_device_t* device, uint8_t bus_type); +/* Detach USB device from a port. */ +extern void usb_detach_device(usb_t *dev, uint8_t port, uint8_t bus_type); #ifdef __cplusplus } diff --git a/src/include/86box/vid_8514a.h b/src/include/86box/vid_8514a.h index 6463d0214..b2932c725 100644 --- a/src/include/86box/vid_8514a.h +++ b/src/include/86box/vid_8514a.h @@ -24,26 +24,37 @@ typedef struct ibm8514_t { int force_old_addr; int type; + int local; + int bpp; uint32_t vram_size; uint32_t vram_mask; PALETTE vgapal; - uint8_t dac_mask, dac_status; + uint8_t dac_mask; + uint8_t dac_status; uint32_t *map8; - int dac_addr, dac_pos, dac_r, dac_g; + int dac_addr; + int dac_pos; + int dac_r; + int dac_g; + int internal_pitch; struct { uint16_t subsys_cntl; uint16_t setup_md; - uint8_t advfunc_cntl, ext_advfunc_cntl; - uint16_t cur_y, cur_y_bitres; - uint16_t cur_x, cur_x_bitres; + uint8_t advfunc_cntl; + uint8_t ext_advfunc_cntl; + uint16_t cur_y; + uint16_t cur_y_bitres; + uint16_t cur_x; + uint16_t cur_x_bitres; int16_t desty_axstp; int16_t destx_distp; int16_t err_term; int16_t maj_axis_pcnt; - uint16_t cmd, cmd_back; + uint16_t cmd; + uint16_t cmd_back; uint16_t short_stroke; uint16_t bkgd_color; uint16_t frgd_color; @@ -54,58 +65,120 @@ typedef struct ibm8514_t { uint16_t frgd_mix; uint16_t multifunc_cntl; uint16_t multifunc[16]; - int16_t clip_left, clip_top; + int16_t clip_left; + int16_t clip_top; uint8_t pix_trans[2]; int poly_draw; int ssv_state; - int x1, x2, y1, y2; - int sys_cnt, sys_cnt2; + int x1; + int x2; + int x3; + int y1; + int y2; + int sys_cnt; + int sys_cnt2; int temp_cnt; - int16_t cx, cy, oldcy; - int16_t sx, sy; - int16_t dx, dy; + int16_t cx; + int16_t cy; + int16_t oldcy; + int16_t sx; + int16_t sy; + int16_t dx; + int16_t dy; int16_t err; - uint32_t src, dest; - uint32_t newsrc_blt, newdest_blt; - uint32_t newdest_in, newdest_out; - uint8_t *writemono, *nibbleset; - int x_count, xx_count, y_count; - int input, output; + uint32_t src; + uint32_t dest; + uint32_t newsrc_blt; + uint32_t newdest_blt; + uint32_t newdest_in; + uint32_t newdest_out; + uint8_t *writemono; + uint8_t *nibbleset; + int x_count; + int xx_count; + int y_count; + int input; + int output; - uint16_t cur_x_bit12, cur_y_bit12; + uint16_t cur_x_bit12; + uint16_t cur_y_bit12; int ssv_len; uint8_t ssv_dir; uint8_t ssv_draw; - int odd_in, odd_out; + int odd_in; + int odd_out; uint16_t scratch; - int fill_state, xdir, ydir; + int fill_state; + int xdir; + int ydir; + uint32_t ge_offset; } accel; uint16_t test; + int ibm_mode; - int v_total, dispend, v_syncstart, split, - h_disp, h_disp_old, h_total, h_disp_time, rowoffset, - dispon, hdisp_on, linecountff, - vc, linepos, oddeven, cursoron, blink, scrollcache, - firstline, lastline, firstline_draw, lastline_draw, - displine, fullchange, x_add, y_add; - uint32_t ma, maback; + int v_total; + int dispend; + int v_syncstart; + int split; + int h_disp; + int h_disp_old; + int h_total; + int h_disp_time; + int rowoffset; + int dispon; + int hdisp_on; + int linecountff; + int vc; + int linepos; + int oddeven; + int cursoron; + int blink; + int scrollcache; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int displine; + int fullchange; + uint32_t ma; + uint32_t maback; - uint8_t *vram, *changedvram, linedbl; + uint8_t *vram; + uint8_t *changedvram; + uint8_t linedbl; - uint8_t data_available, data_available2; - uint8_t scanmodulos, rowcount; - int htotal, hdisp, vtadj, vdadj, vsadj, sc, - vtb, vdb, vsb, vsyncstart, vsyncwidth; - int vtotal, vdisp; - int disp_cntl, interlace; - uint8_t subsys_cntl, subsys_stat; + uint8_t data_available; + uint8_t data_available2; + uint8_t scanmodulos; + uint8_t rowcount; + int htotal; + int hdisp; + int vtadj; + int vdadj; + int vsadj; + int sc; + int vtb; + int vdb; + int vsb; + int vsyncstart; + int vsyncwidth; + int vtotal; + int vdisp; + int disp_cntl; + int interlace; + uint8_t subsys_cntl; + uint8_t subsys_stat; - volatile int force_busy, force_busy2; + atomic_int force_busy; + atomic_int force_busy2; int blitter_busy; uint64_t blitter_time; uint64_t status_time; + int pitch; + int ext_pitch; + int ext_crt_pitch; } ibm8514_t; #endif /*VIDEO_8514A_H*/ diff --git a/src/include/86box/vid_ati_eeprom.h b/src/include/86box/vid_ati_eeprom.h index 1fa083eaa..99af36eda 100644 --- a/src/include/86box/vid_ati_eeprom.h +++ b/src/include/86box/vid_ati_eeprom.h @@ -32,8 +32,12 @@ enum { typedef struct ati_eeprom_t { uint16_t data[256]; - int oldclk, oldena; - int opcode, state, count, out; + int oldclk; + int oldena; + int opcode; + int state; + int count; + int out; int wp; uint32_t dat; int type; @@ -43,6 +47,7 @@ typedef struct ati_eeprom_t { } ati_eeprom_t; void ati_eeprom_load(ati_eeprom_t *eeprom, char *fn, int type); +void ati_eeprom_load_mach8(ati_eeprom_t *eeprom, char *fn); void ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat); int ati_eeprom_read(ati_eeprom_t *eeprom); diff --git a/src/include/86box/vid_cga.h b/src/include/86box/vid_cga.h index 39e1c24ef..f49fc73cc 100644 --- a/src/include/86box/vid_cga.h +++ b/src/include/86box/vid_cga.h @@ -28,21 +28,31 @@ typedef struct cga_t { uint8_t cgastat; - uint8_t cgamode, cgacol; + uint8_t cgamode; + uint8_t cgacol; int fontbase; - int linepos, displine; - int sc, vc; + int linepos; + int displine; + int sc; + int vc; int cgadispon; - int con, coff, cursoron, cgablink; - int vsynctime, vadj; - uint16_t ma, maback; + int con; + int coff; + int cursoron; + int cgablink; + int vsynctime; + int vadj; + uint16_t ma; + uint16_t maback; int oddeven; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, lastline; + int firstline; + int lastline; int drawcursor; @@ -59,12 +69,12 @@ typedef struct cga_t { } cga_t; void cga_init(cga_t *cga); -void cga_out(uint16_t addr, uint8_t val, void *p); -uint8_t cga_in(uint16_t addr, void *p); -void cga_write(uint32_t addr, uint8_t val, void *p); -uint8_t cga_read(uint32_t addr, void *p); +void cga_out(uint16_t addr, uint8_t val, void *priv); +uint8_t cga_in(uint16_t addr, void *priv); +void cga_write(uint32_t addr, uint8_t val, void *priv); +uint8_t cga_read(uint32_t addr, void *priv); void cga_recalctimings(cga_t *cga); -void cga_poll(void *p); +void cga_poll(void *priv); #ifdef EMU_DEVICE_H extern const device_config_t cga_config[]; diff --git a/src/include/86box/vid_cga_comp.h b/src/include/86box/vid_cga_comp.h index 3c7916034..291145291 100644 --- a/src/include/86box/vid_cga_comp.h +++ b/src/include/86box/vid_cga_comp.h @@ -21,13 +21,11 @@ #ifndef VIDEO_CGA_COMP_H #define VIDEO_CGA_COMP_H -#define Bit8u uint8_t -#define Bit32u uint32_t -#define Bitu unsigned int -#define bool uint8_t +#define Bitu unsigned int +#define bool uint8_t void update_cga16_color(uint8_t cgamode); void cga_comp_init(int revision); -Bit32u *Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewidth*/, Bit32u *TempLine); +Bit32u *Composite_Process(uint8_t cgamode, uint8_t border, uint32_t blocks /*, bool doublewidth*/, uint32_t *TempLine); #endif /*VIDEO_CGA_COMP_H*/ diff --git a/src/include/86box/vid_ega.h b/src/include/86box/vid_ega.h index 784f0c596..97a08b583 100644 --- a/src/include/86box/vid_ega.h +++ b/src/include/86box/vid_ega.h @@ -27,11 +27,26 @@ typedef struct ega_t { rom_t bios_rom; - uint8_t crtcreg, gdcaddr, attraddr, attrff, - attr_palette_enable, seqaddr, miscout, - writemask, la, lb, lc, ld, - stat, colourcompare, colournocare, scrblank, - plane_mask, pad, pad0, pad1; + uint8_t crtcreg; + uint8_t gdcaddr; + uint8_t attraddr; + uint8_t attrff; + uint8_t attr_palette_enable; + uint8_t seqaddr; + uint8_t miscout; + uint8_t writemask; + uint8_t la; + uint8_t lb; + uint8_t lc; + uint8_t ld; + uint8_t stat; + uint8_t colourcompare; + uint8_t colournocare; + uint8_t scrblank; + uint8_t plane_mask; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; uint8_t crtc[32]; uint8_t gdcreg[16]; uint8_t attrregs[32]; @@ -41,25 +56,72 @@ typedef struct ega_t { uint8_t *vram; - int vidclock, fast, extvram, vres, - readmode, writemode, readplane, vrammask, - chain4, chain2_read, chain2_write, con, - oddeven_page, oddeven_chain, vc, sc, - dispon, hdisp_on, cursoron, blink, fullchange, - linepos, vslines, linecountff, oddeven, - lowres, interlace, linedbl, lindebl, rowcount, - vtotal, dispend, vsyncstart, split, - hdisp, hdisp_old, htotal, hdisp_time, rowoffset, - vblankstart, scrollcache, firstline, lastline, - firstline_draw, lastline_draw, x_add, y_add, - displine, res_x, res_y, bpp, index; + int vidclock; + int fast; + int extvram; + int vres; + int readmode; + int writemode; + int readplane; + int vrammask; + int chain4; + int chain2_read; + int chain2_write; + int con; + int oddeven_page; + int oddeven_chain; + int vc; + int sc; + int dispon; + int hdisp_on; + int cursoron; + int blink; + int fullchange; + int linepos; + int vslines; + int linecountff; + int oddeven; + int lowres; + int interlace; + int linedbl; + int lindebl; + int rowcount; + int vtotal; + int dispend; + int vsyncstart; + int split; + int hdisp; + int hdisp_old; + int htotal; + int hdisp_time; + int rowoffset; + int vblankstart; + int scrollcache; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int x_add; + int y_add; + int displine; + int res_x; + int res_y; + int bpp; + int index; - uint32_t charseta, charsetb, ma_latch, ma, - maback, ca, vram_limit, overscan_color; + uint32_t charseta; + uint32_t charsetb; + uint32_t ma_latch; + uint32_t ma; + uint32_t maback; + uint32_t ca; + uint32_t vram_limit; + uint32_t overscan_color; uint32_t *pallook; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; double clock; @@ -97,22 +159,27 @@ extern void ega_recalctimings(struct ega_t *ega); extern void ega_recalc_remap_func(struct ega_t *ega); #endif -extern void ega_out(uint16_t addr, uint8_t val, void *p); -extern uint8_t ega_in(uint16_t addr, void *p); -extern void ega_poll(void *p); -extern void ega_write(uint32_t addr, uint8_t val, void *p); -extern uint8_t ega_read(uint32_t addr, void *p); +extern void ega_out(uint16_t addr, uint8_t val, void *priv); +extern uint8_t ega_in(uint16_t addr, void *priv); +extern void ega_poll(void *priv); +extern void ega_write(uint32_t addr, uint8_t val, void *priv); +extern uint8_t ega_read(uint32_t addr, void *priv); -extern int firstline_draw, lastline_draw; +extern int firstline_draw; +extern int lastline_draw; extern int displine; extern int sc; -extern uint32_t ma, ca; -extern int con, cursoron, cgablink; +extern uint32_t ma; +extern uint32_t ca; +extern int con; +extern int cursoron; +extern int cgablink; extern int scrollcache; extern uint8_t edatlookup[4][4]; +extern uint8_t egaremap2bpp[256]; #if defined(EMU_MEM_H) && defined(EMU_ROM_H) void ega_render_blank(ega_t *ega); @@ -120,14 +187,8 @@ void ega_render_blank(ega_t *ega); void ega_render_overscan_left(ega_t *ega); void ega_render_overscan_right(ega_t *ega); -void ega_render_text_40(ega_t *ega); -void ega_render_text_80(ega_t *ega); - -void ega_render_2bpp_lowres(ega_t *ega); -void ega_render_2bpp_highres(ega_t *ega); - -void ega_render_4bpp_lowres(ega_t *ega); -void ega_render_4bpp_highres(ega_t *ega); +void ega_render_text(ega_t *ega); +void ega_render_graphics(ega_t *ega); #endif #endif /*VIDEO_EGA_H*/ diff --git a/src/include/86box/vid_ega_render_remap.h b/src/include/86box/vid_ega_render_remap.h index a33b27ed4..b01bb2b0e 100644 --- a/src/include/86box/vid_ega_render_remap.h +++ b/src/include/86box/vid_ega_render_remap.h @@ -20,11 +20,11 @@ break; \ \ case VAR_WORD_MODE_MA13: \ - out_addr = ((in_addr << 1) & 0x1fff8) | ((in_addr >> 13) & 0x4) | (in_addr & ~0x1ffff); \ + out_addr = ((in_addr << 1) & 0x3fff8) | ((in_addr >> 13) & 0x4) | (in_addr & ~0x3ffff); \ break; \ \ case VAR_WORD_MODE_MA15: \ - out_addr = ((in_addr << 1) & 0x1fff8) | ((in_addr >> 15) & 0x4) | (in_addr & ~0x1ffff); \ + out_addr = ((in_addr << 1) & 0x3fff8) | ((in_addr >> 15) & 0x4) | (in_addr & ~0x3ffff); \ break; \ \ case VAR_DWORD_MODE: \ @@ -85,7 +85,7 @@ ega_recalc_remap_func(ega_t *ega) func_nr = VAR_DWORD_MODE; else if (ega->crtc[0x17] & 0x40) func_nr = VAR_BYTE_MODE; - else if (ega->crtc[0x17] & 0x20) + else if ((ega->crtc[0x17] & 0x20) && ega->vram_limit > 64 * 1024) func_nr = VAR_WORD_MODE_MA15; else func_nr = VAR_WORD_MODE_MA13; diff --git a/src/include/86box/vid_hercules.h b/src/include/86box/vid_hercules.h index bbb4239aa..b5ba6af9f 100644 --- a/src/include/86box/vid_hercules.h +++ b/src/include/86box/vid_hercules.h @@ -25,30 +25,32 @@ typedef struct { mem_mapping_t mapping; - uint8_t crtc[32], charbuffer[4096]; + uint8_t crtc[32]; + uint8_t charbuffer[4096]; int crtcreg; - uint8_t ctrl, - ctrl2, - stat; + uint8_t ctrl; + uint8_t ctrl2; + uint8_t stat; - uint64_t dispontime, - dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, - lastline; + int firstline; + int lastline; - int linepos, - displine; - int vc, - sc; - uint16_t ma, - maback; - int con, coff, - cursoron; - int dispon, - blink; + int linepos; + int displine; + int vc; + int sc; + uint16_t ma; + uint16_t maback; + int con; + int coff; + int cursoron; + int dispon; + int blink; int vsynctime; int vadj; diff --git a/src/include/86box/vid_mda.h b/src/include/86box/vid_mda.h index 0f5080865..ea98bef61 100644 --- a/src/include/86box/vid_mda.h +++ b/src/include/86box/vid_mda.h @@ -11,18 +11,27 @@ typedef struct mda_t { uint8_t crtc[32]; int crtcreg; - uint8_t ctrl, stat; + uint8_t ctrl; + uint8_t stat; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, lastline; + int firstline; + int lastline; - int linepos, displine; - int vc, sc; - uint16_t ma, maback; - int con, coff, cursoron; - int dispon, blink; + int linepos; + int displine; + int vc; + int sc; + uint16_t ma; + uint16_t maback; + int con; + int coff; + int cursoron; + int dispon; + int blink; int vsynctime; int vadj; int monitor_index; @@ -43,12 +52,12 @@ typedef struct mda_t { void mda_init(mda_t *mda); void mda_setcol(int chr, int blink, int fg, uint8_t cga_ink); -void mda_out(uint16_t addr, uint8_t val, void *p); -uint8_t mda_in(uint16_t addr, void *p); -void mda_write(uint32_t addr, uint8_t val, void *p); -uint8_t mda_read(uint32_t addr, void *p); +void mda_out(uint16_t addr, uint8_t val, void *priv); +uint8_t mda_in(uint16_t addr, void *priv); +void mda_write(uint32_t addr, uint8_t val, void *priv); +uint8_t mda_read(uint32_t addr, void *priv); void mda_recalctimings(mda_t *mda); -void mda_poll(void *p); +void mda_poll(void *priv); #ifdef EMU_DEVICE_H extern const device_t mda_device; diff --git a/src/include/86box/vid_pgc.h b/src/include/86box/vid_pgc.h index 12450c0d1..a59ca3d8e 100644 --- a/src/include/86box/vid_pgc.h +++ b/src/include/86box/vid_pgc.h @@ -59,10 +59,10 @@ typedef struct pgc { mem_mapping_t mapping; mem_mapping_t cga_mapping; - pgc_cl_t *clist, - *clcur; - const pgc_cmd_t *master, - *commands; + pgc_cl_t *clist; + pgc_cl_t *clcur; + const pgc_cmd_t *master; + const pgc_cmd_t *commands; uint8_t mapram[2048]; /* host <> PGC communication buffer */ uint8_t *cga_vram; @@ -73,10 +73,18 @@ typedef struct pgc { uint32_t userpal[256]; uint32_t maxw, maxh; /* maximum framebuffer size */ uint32_t visw, vish; /* maximum screen size */ - uint32_t screenw, screenh; - int16_t pan_x, pan_y; - uint16_t win_x1, win_x2, win_y1, win_y2; - uint16_t vp_x1, vp_x2, vp_y1, vp_y2; + uint32_t screenw; + uint32_t screenh; + int16_t pan_x; + int16_t pan_y; + uint16_t win_x1; + uint16_t win_x2; + uint16_t win_y1; + uint16_t win_y2; + uint16_t vp_x1; + uint16_t vp_x2; + uint16_t vp_y1; + uint16_t vp_y2; int16_t fill_pattern[16]; int16_t line_pattern; uint8_t draw_mode; @@ -86,7 +94,9 @@ typedef struct pgc { uint8_t tjust_v; /* vert alignment 1=bottom 2=ctr 3=top*/ int32_t tsize; /* horizontal spacing */ - int32_t x, y, z; /* drawing position */ + int32_t x; + int32_t y; + int32_t z; /* drawing position */ thread_t *pgc_thread; event_t *pgc_wake_thread; @@ -98,18 +108,23 @@ typedef struct pgc { int ascii_mode; int result_count; - int fontbase; - int linepos, - displine; + int fontbase; + int linepos; + int displine; int vc; int cgadispon; - int con, coff, cursoron, cgablink; - int vsynctime, vadj; - uint16_t ma, maback; + int con; + int coff; + int cursoron; + int cgablink; + int vsynctime; + int vadj; + uint16_t ma; + uint16_t maback; int oddeven; - uint64_t dispontime, - dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; double native_pixel_clock; @@ -140,10 +155,14 @@ extern void pgc_init(pgc_t *, extern void pgc_sto_raster(pgc_t *, int16_t *x, int16_t *y); extern void pgc_ito_raster(pgc_t *, int32_t *x, int32_t *y); extern void pgc_dto_raster(pgc_t *, double *x, double *y); -// extern int pgc_input_byte(pgc_t *, uint8_t *val); -// extern int pgc_output_byte(pgc_t *, uint8_t val); +#if 0 +extern int pgc_input_byte(pgc_t *, uint8_t *val); +extern int pgc_output_byte(pgc_t *, uint8_t val); +#endif extern int pgc_output_string(pgc_t *, const char *val); -// extern int pgc_error_byte(pgc_t *, uint8_t val); +#if 0 +extern int pgc_error_byte(pgc_t *, uint8_t val); +#endif extern int pgc_error_string(pgc_t *, const char *val); extern int pgc_error(pgc_t *, int err); diff --git a/src/include/86box/vid_svga.h b/src/include/86box/vid_svga.h index 31eabc064..ab8144a77 100644 --- a/src/include/86box/vid_svga.h +++ b/src/include/86box/vid_svga.h @@ -31,15 +31,23 @@ # define FLAG_NOSKEW 16 # define FLAG_ADDR_BY16 32 # define FLAG_RAMDAC_SHIFT 64 -# define FLAG_128K_MASK 128 - +# define FLAG_ATI 128 +# define FLAG_S3_911_16BIT 256 +# define FLAG_512K_MASK 512 struct monitor_t; -typedef struct { - int ena, - x, y, xoff, yoff, cur_xsize, cur_ysize, - v_acc, h_acc; - uint32_t addr, pitch; +typedef struct hwcursor_t { + int ena; + int x; + int y; + int xoff; + int yoff; + int cur_xsize; + int cur_ysize; + int v_acc; + int h_acc; + uint32_t addr; + uint32_t pitch; } hwcursor_t; typedef union { @@ -54,25 +62,78 @@ typedef struct svga_t { xga_t xga; mem_mapping_t mapping; - uint8_t fast, chain4, chain2_write, chain2_read, - ext_overscan, bus_size, - lowres, interlace, linedbl, rowcount, - set_reset_disabled, bpp, ramdac_type, fb_only, - readmode, writemode, readplane, - hwcursor_oddeven, dac_hwcursor_oddeven, overlay_oddeven, - fcr, hblank_overscan; + uint8_t fast; + uint8_t chain4; + uint8_t chain2_write; + uint8_t chain2_read; + uint8_t ext_overscan; + uint8_t bus_size; + uint8_t lowres; + uint8_t interlace; + uint8_t linedbl; + uint8_t rowcount; + uint8_t set_reset_disabled; + uint8_t bpp; + uint8_t ramdac_type; + uint8_t fb_only; + uint8_t readmode; + uint8_t writemode; + uint8_t readplane; + uint8_t hwcursor_oddeven; + uint8_t dac_hwcursor_oddeven; + uint8_t overlay_oddeven; + uint8_t fcr; + uint8_t hblank_overscan; - int dac_addr, dac_pos, dac_r, dac_g, - vtotal, dispend, vsyncstart, split, vblankstart, - hdisp, hdisp_old, htotal, hdisp_time, rowoffset, - dispon, hdisp_on, - vc, sc, linepos, vslines, linecountff, oddeven, - con, cursoron, blink, scrollcache, char_width, - firstline, lastline, firstline_draw, lastline_draw, - displine, fullchange, x_add, y_add, pan, - vram_display_mask, vidclock, dots_per_clock, hblank_ext, - hwcursor_on, dac_hwcursor_on, overlay_on, set_override, - hblankstart, hblankend, hblank_sub, hblank_end_val, hblank_end_len; + int dac_addr; + int dac_pos; + int dac_r; + int dac_g; + int vtotal; + int dispend; + int vsyncstart; + int split; + int vblankstart; + int hdisp; + int hdisp_old; + int htotal; + int hdisp_time; + int rowoffset; + int dispon; + int hdisp_on; + int vc; + int sc; + int linepos; + int vslines; + int linecountff; + int oddeven; + int con; + int cursoron; + int blink; + int scrollcache; + int char_width; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int displine; + int fullchange; + int x_add; + int y_add; + int pan; + int vram_display_mask; + int vidclock; + int dots_per_clock; + int hblank_ext; + int hwcursor_on; + int dac_hwcursor_on; + int overlay_on; + int set_override; + int hblankstart; + int hblankend; + int hblank_sub; + int hblank_end_val; + int hblank_end_len; /*The three variables below allow us to implement memory maps like that seen on a 1MB Trio64 : 0MB-1MB - VRAM @@ -83,35 +144,47 @@ typedef struct svga_t { For the example memory map, decode_mask would be 4MB-1 (4MB address space), vram_max would be 2MB (present video memory only responds to first 2MB), vram_mask would be 1MB-1 (video memory wraps at 1MB) */ - uint32_t decode_mask, vram_max, - vram_mask, - charseta, charsetb, - adv_flags, ma_latch, - ca_adj, ma, maback, - write_bank, read_bank, - extra_banks[2], - banked_mask, - ca, overscan_color, - *map8, pallook[512]; + uint32_t decode_mask; + uint32_t vram_max; + uint32_t vram_mask; + uint32_t charseta; + uint32_t charsetb; + uint32_t adv_flags; + uint32_t ma_latch; + uint32_t ca_adj; + uint32_t ma; + uint32_t maback; + uint32_t write_bank; + uint32_t read_bank; + uint32_t extra_banks[2]; + uint32_t banked_mask; + uint32_t ca; + uint32_t overscan_color; + uint32_t *map8; + uint32_t pallook[512]; PALETTE vgapal; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; latch_t latch; pc_timer_t timer; double clock; - hwcursor_t hwcursor, hwcursor_latch, - dac_hwcursor, dac_hwcursor_latch, - overlay, overlay_latch; + hwcursor_t hwcursor; + hwcursor_t hwcursor_latch; + hwcursor_t dac_hwcursor; + hwcursor_t dac_hwcursor_latch; + hwcursor_t overlay; + hwcursor_t overlay_latch; void (*render)(struct svga_t *svga); void (*recalctimings_ex)(struct svga_t *svga); - void (*video_out)(uint16_t addr, uint8_t val, void *p); - uint8_t (*video_in)(uint16_t addr, void *p); + void (*video_out)(uint16_t addr, uint8_t val, void *priv); + uint8_t (*video_in)(uint16_t addr, void *priv); void (*hwcursor_draw)(struct svga_t *svga, int displine); @@ -122,7 +195,7 @@ typedef struct svga_t { void (*vblank_start)(struct svga_t *svga); void (*ven_write)(struct svga_t *svga, uint8_t val, uint32_t addr); - float (*getclock)(int clock, void *p); + float (*getclock)(int clock, void *priv); /* Called when VC=R18 and friends. If this returns zero then MA resetting is skipped. Matrox Mystique in Power mode reuses this counter for @@ -132,24 +205,39 @@ typedef struct svga_t { /*Called at the start of vertical sync*/ void (*vsync_callback)(struct svga_t *svga); - uint32_t (*translate_address)(uint32_t addr, void *p); + uint32_t (*translate_address)(uint32_t addr, void *priv); /*If set then another device is driving the monitor output and the SVGA card should not attempt to display anything */ int override; - void *p; + void *priv; - uint8_t crtc[256], gdcreg[256], attrregs[32], seqregs[256], - egapal[16], - *vram, *changedvram; + uint8_t crtc[256]; + uint8_t gdcreg[256]; + uint8_t attrregs[32]; + uint8_t seqregs[256]; + uint8_t egapal[16]; + uint8_t *vram; + uint8_t *changedvram; - uint8_t crtcreg, gdcaddr, - attrff, attr_palette_enable, attraddr, seqaddr, - miscout, cgastat, scrblank, - plane_mask, writemask, - colourcompare, colournocare, - dac_mask, dac_status, - dpms, dpms_ui, - ksc5601_sbyte_mask, ksc5601_udc_area_msb[2]; + uint8_t crtcreg; + uint8_t gdcaddr; + uint8_t attrff; + uint8_t attr_palette_enable; + uint8_t attraddr; + uint8_t seqaddr; + uint8_t miscout; + uint8_t cgastat; + uint8_t scrblank; + uint8_t plane_mask; + uint8_t writemask; + uint8_t colourcompare; + uint8_t colournocare; + uint8_t dac_mask; + uint8_t dac_status; + uint8_t dpms; + uint8_t dpms_ui; + uint8_t ksc5601_sbyte_mask; + uint8_t ksc5601_udc_area_msb[2]; int ksc5601_swap_mode; uint16_t ksc5601_english_font_type; @@ -171,53 +259,62 @@ typedef struct svga_t { int remap_required; uint32_t (*remap_func)(struct svga_t *svga, uint32_t in_addr); - void *ramdac, *clock_gen; + void *ramdac; + void *clock_gen; /* Monitor Index */ uint8_t monitor_index; /* Pointer to monitor */ - monitor_t* monitor; + monitor_t *monitor; } svga_t; -extern int vga_on, ibm8514_on; +extern int vga_on; +extern int ibm8514_on; -extern void ibm8514_poll(ibm8514_t *dev, svga_t *svga); -extern void ibm8514_recalctimings(svga_t *svga); +extern void ibm8514_poll(ibm8514_t *dev, svga_t *svga); +extern void ibm8514_recalctimings(svga_t *svga); +extern uint8_t ibm8514_ramdac_in(uint16_t port, void *priv); +extern void ibm8514_ramdac_out(uint16_t port, uint8_t val, void *priv); +extern int ibm8514_cpu_src(svga_t *svga); +extern int ibm8514_cpu_dest(svga_t *svga); +extern void ibm8514_accel_out_pixtrans(svga_t *svga, uint16_t port, uint16_t val, int len); +extern void ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, uint8_t ssv, int len); +extern void ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, int len); extern void xga_poll(xga_t *xga, svga_t *svga); extern void xga_recalctimings(svga_t *svga); -extern int svga_init(const device_t *info, svga_t *svga, void *p, int memsize, +extern int svga_init(const device_t *info, svga_t *svga, void *priv, int memsize, void (*recalctimings_ex)(struct svga_t *svga), - uint8_t (*video_in)(uint16_t addr, void *p), - void (*video_out)(uint16_t addr, uint8_t val, void *p), + uint8_t (*video_in)(uint16_t addr, void *priv), + void (*video_out)(uint16_t addr, uint8_t val, void *priv), void (*hwcursor_draw)(struct svga_t *svga, int displine), void (*overlay_draw)(struct svga_t *svga, int displine)); extern void svga_recalctimings(svga_t *svga); extern void svga_close(svga_t *svga); -uint8_t svga_read(uint32_t addr, void *p); -uint16_t svga_readw(uint32_t addr, void *p); -uint32_t svga_readl(uint32_t addr, void *p); -void svga_write(uint32_t addr, uint8_t val, void *p); -void svga_writew(uint32_t addr, uint16_t val, void *p); -void svga_writel(uint32_t addr, uint32_t val, void *p); -uint8_t svga_read_linear(uint32_t addr, void *p); -uint8_t svga_readb_linear(uint32_t addr, void *p); -uint16_t svga_readw_linear(uint32_t addr, void *p); -uint32_t svga_readl_linear(uint32_t addr, void *p); -void svga_write_linear(uint32_t addr, uint8_t val, void *p); -void svga_writeb_linear(uint32_t addr, uint8_t val, void *p); -void svga_writew_linear(uint32_t addr, uint16_t val, void *p); -void svga_writel_linear(uint32_t addr, uint32_t val, void *p); +uint8_t svga_read(uint32_t addr, void *priv); +uint16_t svga_readw(uint32_t addr, void *priv); +uint32_t svga_readl(uint32_t addr, void *priv); +void svga_write(uint32_t addr, uint8_t val, void *priv); +void svga_writew(uint32_t addr, uint16_t val, void *priv); +void svga_writel(uint32_t addr, uint32_t val, void *priv); +uint8_t svga_read_linear(uint32_t addr, void *priv); +uint8_t svga_readb_linear(uint32_t addr, void *priv); +uint16_t svga_readw_linear(uint32_t addr, void *priv); +uint32_t svga_readl_linear(uint32_t addr, void *priv); +void svga_write_linear(uint32_t addr, uint8_t val, void *priv); +void svga_writeb_linear(uint32_t addr, uint8_t val, void *priv); +void svga_writew_linear(uint32_t addr, uint16_t val, void *priv); +void svga_writel_linear(uint32_t addr, uint32_t val, void *priv); -void svga_add_status_info(char *s, int max_len, void *p); +void svga_add_status_info(char *s, int max_len, void *priv); extern uint8_t svga_rotate[8][256]; -void svga_out(uint16_t addr, uint8_t val, void *p); -uint8_t svga_in(uint16_t addr, void *p); +void svga_out(uint16_t addr, uint8_t val, void *priv); +uint8_t svga_in(uint16_t addr, void *priv); svga_t *svga_get_pri(void); void svga_set_override(svga_t *svga, int val); @@ -237,65 +334,65 @@ enum { /* We need a way to add a device with a pointer to a parent device so it can attach itself to it, and possibly also a second ATi 68860 RAM DAC type that auto-sets SVGA render on RAM DAC render change. */ -extern void ati68860_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t ati68860_ramdac_in(uint16_t addr, void *p, svga_t *svga); -extern void ati68860_set_ramdac_type(void *p, int type); -extern void ati68860_ramdac_set_render(void *p, svga_t *svga); -extern void ati68860_ramdac_set_pallook(void *p, int i, uint32_t col); +extern void ati68860_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t ati68860_ramdac_in(uint16_t addr, void *priv, svga_t *svga); +extern void ati68860_set_ramdac_type(void *priv, int type); +extern void ati68860_ramdac_set_render(void *priv, svga_t *svga); +extern void ati68860_ramdac_set_pallook(void *priv, int i, uint32_t col); extern void ati68860_hwcursor_draw(svga_t *svga, int displine); -extern void att49x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t att49x_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); +extern void att49x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t att49x_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); -extern void att498_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t att498_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); -extern float av9194_getclock(int clock, void *p); +extern void att498_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t att498_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); +extern float av9194_getclock(int clock, void *priv); -extern void bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t *svga); -extern uint8_t bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga); -extern void bt48x_recalctimings(void *p, svga_t *svga); +extern void bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga); +extern uint8_t bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga); +extern void bt48x_recalctimings(void *priv, svga_t *svga); extern void bt48x_hwcursor_draw(svga_t *svga, int displine); -extern void ibm_rgb528_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t ibm_rgb528_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); -extern void ibm_rgb528_recalctimings(void *p, svga_t *svga); +extern void ibm_rgb528_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t ibm_rgb528_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); +extern void ibm_rgb528_recalctimings(void *priv, svga_t *svga); extern void ibm_rgb528_hwcursor_draw(svga_t *svga, int displine); -extern void icd2061_write(void *p, int val); -extern float icd2061_getclock(int clock, void *p); +extern void icd2061_write(void *priv, int val); +extern float icd2061_getclock(int clock, void *priv); /* The code is the same, the #define's are so that the correct name can be used. */ # define ics9161_write icd2061_write # define ics9161_getclock icd2061_getclock -extern float ics2494_getclock(int clock, void *p); +extern float ics2494_getclock(int clock, void *priv); -extern void ics2595_write(void *p, int strobe, int dat); -extern double ics2595_getclock(void *p); -extern void ics2595_setclock(void *p, double clock); +extern void ics2595_write(void *priv, int strobe, int dat); +extern double ics2595_getclock(void *priv); +extern void ics2595_setclock(void *priv, double clock); -extern void sc1148x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t sc1148x_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); +extern void sc1148x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t sc1148x_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); -extern void sc1502x_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t sc1502x_ramdac_in(uint16_t addr, void *p, svga_t *svga); +extern void sc1502x_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t sc1502x_ramdac_in(uint16_t addr, void *priv, svga_t *svga); -extern void sdac_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t sdac_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); -extern float sdac_getclock(int clock, void *p); +extern void sdac_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t sdac_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); +extern float sdac_getclock(int clock, void *priv); -extern void stg_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t stg_ramdac_in(uint16_t addr, void *p, svga_t *svga); -extern float stg_getclock(int clock, void *p); +extern void stg_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t stg_ramdac_in(uint16_t addr, void *priv, svga_t *svga); +extern float stg_getclock(int clock, void *priv); -extern void tkd8001_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t tkd8001_ramdac_in(uint16_t addr, void *p, svga_t *svga); +extern void tkd8001_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t tkd8001_ramdac_in(uint16_t addr, void *priv, svga_t *svga); -extern void tvp3026_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t *svga); -extern uint8_t tvp3026_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga); -extern void tvp3026_recalctimings(void *p, svga_t *svga); +extern void tvp3026_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga); +extern uint8_t tvp3026_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga); +extern void tvp3026_recalctimings(void *priv, svga_t *svga); extern void tvp3026_hwcursor_draw(svga_t *svga, int displine); -extern float tvp3026_getclock(int clock, void *p); +extern float tvp3026_getclock(int clock, void *priv); # ifdef EMU_DEVICE_H extern const device_t ati68860_ramdac_device; diff --git a/src/include/86box/vid_svga_render.h b/src/include/86box/vid_svga_render.h index 13ff527e0..1f587d4f5 100644 --- a/src/include/86box/vid_svga_render.h +++ b/src/include/86box/vid_svga_render.h @@ -20,12 +20,16 @@ #ifndef VIDEO_SVGA_RENDER_H #define VIDEO_SVGA_RENDER_H -extern int firstline_draw, lastline_draw; +extern int firstline_draw; +extern int lastline_draw; extern int displine; extern int sc; -extern uint32_t ma, ca; -extern int con, cursoron, cgablink; +extern uint32_t ma; +extern uint32_t ca; +extern int con; +extern int cursoron; +extern int cgablink; extern int scrollcache; diff --git a/src/include/86box/vid_vga.h b/src/include/86box/vid_vga.h index 08a1a2591..bc552b285 100644 --- a/src/include/86box/vid_vga.h +++ b/src/include/86box/vid_vga.h @@ -30,7 +30,7 @@ typedef struct vga_t { static video_timings_t timing_vga = { VIDEO_ISA, 8, 16, 32, 8, 16, 32 }; -void vga_out(uint16_t addr, uint8_t val, void *p); -uint8_t vga_in(uint16_t addr, void *p); +void vga_out(uint16_t addr, uint8_t val, void *priv); +uint8_t vga_in(uint16_t addr, void *priv); #endif /*VIDEO_VGA_H*/ diff --git a/src/include/86box/vid_voodoo_banshee.h b/src/include/86box/vid_voodoo_banshee.h index 56fd47eeb..89298e94e 100644 --- a/src/include/86box/vid_voodoo_banshee.h +++ b/src/include/86box/vid_voodoo_banshee.h @@ -18,6 +18,6 @@ #ifndef VIDEO_VOODOO_BANSHEE_H #define VIDEO_VOODOO_BANSHEE_H -void banshee_set_overlay_addr(void *p, uint32_t addr); +void banshee_set_overlay_addr(void *priv, uint32_t addr); #endif /*VIDEO_VOODOO_BANSHEE_H*/ diff --git a/src/include/86box/vid_voodoo_codegen_x86-64.h b/src/include/86box/vid_voodoo_codegen_x86-64.h index 4999f38c5..dc0ebce72 100644 --- a/src/include/86box/vid_voodoo_codegen_x86-64.h +++ b/src/include/86box/vid_voodoo_codegen_x86-64.h @@ -38,7 +38,9 @@ typedef struct voodoo_x86_data_t { int is_tiled; } voodoo_x86_data_t; -// static voodoo_x86_data_t voodoo_x86_data[2][BLOCK_NUM]; +#if 0 +static voodoo_x86_data_t voodoo_x86_data[2][BLOCK_NUM]; +#endif static int last_block[4] = { 0, 0 }; static int next_block_to_write[4] = { 0, 0 }; @@ -70,7 +72,8 @@ static __m128i xmm_01_w; // = 0x0001000100010001ull; static __m128i xmm_ff_w; // = 0x00ff00ff00ff00ffull; static __m128i xmm_ff_b; // = 0x00000000ffffffffull; -static __m128i alookup[257], aminuslookup[256]; +static __m128i alookup[257]; +static __m128i aminuslookup[256]; static __m128i minus_254; // = 0xff02ff02ff02ff02ull; static __m128i bilinear_lookup[256 * 2]; static __m128i xmm_00_ff_w[2]; @@ -233,10 +236,12 @@ codegen_texture_fetch(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *pa addlong(1); addbyte(0x28); /*SUB DL, CL*/ addbyte(0xca); - // addbyte(0x8a); /*MOV DL, params->tex_shift[RSI+ECX*4]*/ - // addbyte(0x94); - // addbyte(0x8e); - // addlong(offsetof(voodoo_params_t, tex_shift)); +#if 0 + addbyte(0x8a); /*MOV DL, params->tex_shift[RSI+ECX*4]*/ + addbyte(0x94); + addbyte(0x8e); + addlong(offsetof(voodoo_params_t, tex_shift)); +#endif addbyte(0xd3); /*SHL EBP, CL*/ addbyte(0xe5); addbyte(0x8b); /*MOV EAX, state->tex_s[RDI]*/ @@ -655,24 +660,29 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, int depth_jump_pos = 0; int depth_jump_pos2 = 0; int loop_jump_pos = 0; - // xmm_01_w = (__m128i)0x0001000100010001ull; - // xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; - // xmm_ff_b = (__m128i)0x00000000ffffffffull; +#if 0 + xmm_01_w = (__m128i)0x0001000100010001ull; + xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; + xmm_ff_b = (__m128i)0x00000000ffffffffull; +#endif xmm_01_w = _mm_set_epi32(0, 0, 0x00010001, 0x00010001); xmm_ff_w = _mm_set_epi32(0, 0, 0x00ff00ff, 0x00ff00ff); xmm_ff_b = _mm_set_epi32(0, 0, 0, 0x00ffffff); minus_254 = _mm_set_epi32(0, 0, 0xff02ff02, 0xff02ff02); - // *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; - // block_pos = 0; - // voodoo_get_depth = &code_block[block_pos]; +#if 0 + *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; + block_pos = 0; + voodoo_get_depth = &code_block[block_pos]; +#endif /*W at (%esp+4) Z at (%esp+12) new_depth at (%esp+16)*/ - // if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) - // { - // addbyte(0xC3); /*RET*/ - // return; - // } +#if 0 + if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) { + addbyte(0xC3); /*RET*/ + return; + } +#endif addbyte(0x55); /*PUSH RBP*/ addbyte(0x57); /*PUSH RDI*/ addbyte(0x56); /*PUSH RSI*/ @@ -795,7 +805,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x75); /*JNZ got_depth*/ depth_jump_pos = block_pos; addbyte(0); - // addbyte(4+5+2+3+2+5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#if 0 + addbyte(4+5+2+3+2+5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#endif addbyte(0x8b); /*MOV EDX, w*/ addbyte(0x97); addlong(offsetof(voodoo_state_t, w)); @@ -809,7 +821,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x74); /*JZ got_depth*/ depth_jump_pos2 = block_pos; addbyte(0); - // addbyte(5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#if 0 + addbyte(5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#endif addbyte(0xb9); /*MOV ECX, 19*/ addlong(19); addbyte(0x0f); /*BSR EAX, EDX*/ @@ -2223,10 +2237,12 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(10); addbyte(0x01); /*ADD EAX, EBX*/ addbyte(0xd8); - /* int fog_idx = (w_depth >> 10) & 0x3f; +#if 0 + int fog_idx = (w_depth >> 10) & 0x3f; - fog_a = params->fogTable[fog_idx].fog; - fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10;*/ + fog_a = params->fogTable[fog_idx].fog; + fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10; +#endif break; case FOG_Z: @@ -2238,7 +2254,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(12); addbyte(0x25); /*AND EAX, 0xff*/ addlong(0xff); - // fog_a = (z >> 20) & 0xff; +#if 0 + fog_a = (z >> 20) & 0xff; +#endif break; case FOG_ALPHA: @@ -2260,7 +2278,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(ia >> 12); +#if 0 + fog_a = CLAMP(ia >> 12); +#endif break; case FOG_W: @@ -2281,7 +2301,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(w >> 32); +#if 0 + fog_a = CLAMP(w >> 32); +#endif break; } addbyte(0x01); /*ADD EAX, EAX*/ @@ -3163,12 +3185,11 @@ int voodoo_recomp = 0; static inline void * voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *state, int odd_even) { - int c; int b = last_block[odd_even]; voodoo_x86_data_t *voodoo_x86_data = voodoo->codegen_data; voodoo_x86_data_t *data; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { data = &voodoo_x86_data[odd_even + c * 4]; //&voodoo_x86_data[odd_even][b]; if (state->xdir == data->xdir && params->alphaMode == data->alphaMode && params->fbzMode == data->fbzMode && params->fogMode == data->fogMode && params->fbzColorPath == data->fbzColorPath && (voodoo->trexInit1[0] & (1 << 18)) == data->trexInit1 && params->textureMode[0] == data->textureMode[0] && params->textureMode[1] == data->textureMode[1] && (params->tLOD[0] & LOD_MASK) == data->tLOD[0] && (params->tLOD[1] & LOD_MASK) == data->tLOD[1] && ((params->col_tiled || params->aux_tiled) ? 1 : 0) == data->is_tiled) { @@ -3180,7 +3201,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat } voodoo_recomp++; data = &voodoo_x86_data[odd_even + next_block_to_write[odd_even] * 4]; - // code_block = data->code_block; +#if 0 + code_block = data->code_block; +#endif voodoo_generate(data->code_block, voodoo, params, state, depth_op); @@ -3204,11 +3227,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat void voodoo_codegen_init(voodoo_t *voodoo) { - int c; - voodoo->codegen_data = plat_mmap(sizeof(voodoo_x86_data_t) * BLOCK_NUM * 4, 1); - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { int d[4]; int _ds = c & 0xf; int dt = c >> 4; diff --git a/src/include/86box/vid_voodoo_codegen_x86.h b/src/include/86box/vid_voodoo_codegen_x86.h index c04330190..996bd28f1 100644 --- a/src/include/86box/vid_voodoo_codegen_x86.h +++ b/src/include/86box/vid_voodoo_codegen_x86.h @@ -69,9 +69,10 @@ static __m128i xmm_ff_w; // = 0x00ff00ff00ff00ffull; static __m128i xmm_ff_b; // = 0x00000000ffffffffull; static uint32_t zero = 0; -static double const_1_48 = (double) (1ull << 4); +static double const_1_48 = (double) (1ULL << 4); -static __m128i alookup[257], aminuslookup[256]; +static __m128i alookup[257]; +static __m128i aminuslookup[256]; static __m128i minus_254; // = 0xff02ff02ff02ff02ull; static __m128i bilinear_lookup[256 * 2]; static __m128i xmm_00_ff_w[2]; @@ -638,24 +639,29 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, int depth_jump_pos = 0; int depth_jump_pos2 = 0; int loop_jump_pos = 0; - // xmm_01_w = (__m128i)0x0001000100010001ull; - // xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; - // xmm_ff_b = (__m128i)0x00000000ffffffffull; +#if 0 + xmm_01_w = (__m128i)0x0001000100010001ull; + xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; + xmm_ff_b = (__m128i)0x00000000ffffffffull; +#endif xmm_01_w = _mm_set_epi32(0, 0, 0x00010001, 0x00010001); xmm_ff_w = _mm_set_epi32(0, 0, 0x00ff00ff, 0x00ff00ff); xmm_ff_b = _mm_set_epi32(0, 0, 0, 0x00ffffff); minus_254 = _mm_set_epi32(0, 0, 0xff02ff02, 0xff02ff02); - // *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; - // block_pos = 0; - // voodoo_get_depth = &code_block[block_pos]; +#if 0 + *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; + block_pos = 0; + voodoo_get_depth = &code_block[block_pos]; +#endif /*W at (%esp+4) Z at (%esp+12) new_depth at (%esp+16)*/ - // if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) - // { - // addbyte(0xC3); /*RET*/ - // return; - // } +#if 0 + if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) { + addbyte(0xC3); /*RET*/ + return; + } +#endif addbyte(0x55); /*PUSH EBP*/ addbyte(0x57); /*PUSH EDI*/ addbyte(0x56); /*PUSH ESI*/ @@ -870,16 +876,19 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, fatal("Bad depth_op\n"); } else if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depthop == DEPTHOP_NEVER)) { addbyte(0xC3); /*RET*/ - // addbyte(0x30); /*XOR EAX, EAX*/ - // addbyte(0xc0); +#if 0 + addbyte(0x30); /*XOR EAX, EAX*/ + addbyte(0xc0); +#endif + } +#if 0 + else { + addbyte(0xb0); /*MOV AL, 1*/ + addbyte(1); } - // else - // { - // addbyte(0xb0); /*MOV AL, 1*/ - // addbyte(1); - // } - // voodoo_combine = &code_block[block_pos]; + voodoo_combine = &code_block[block_pos]; +#endif /*XMM0 = colour*/ /*XMM2 = 0 (for unpacking*/ @@ -2075,12 +2084,13 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x05); addlong((uint32_t) &xmm_ff_b); } - // #if 0 - // addbyte(0x66); /*MOVD state->out[EDI], XMM0*/ - // addbyte(0x0f); - // addbyte(0x7e); - // addbyte(0x87); - // addlong(offsetof(voodoo_state_t, out)); +#if 0 + addbyte(0x66); /*MOVD state->out[EDI], XMM0*/ + addbyte(0x0f); + addbyte(0x7e); + addbyte(0x87); + addlong(offsetof(voodoo_state_t, out)); +#endif if (params->fogMode & FOG_ENABLE) { if (params->fogMode & FOG_CONSTANT) { addbyte(0x66); /*MOVD XMM3, params->fogColor[ESI]*/ @@ -2092,11 +2102,18 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); addbyte(0xdc); addbyte(0xc3); - /* src_r += params->fogColor.r; - src_g += params->fogColor.g; - src_b += params->fogColor.b; */ +#if 0 + src_r += params->fogColor.r; + src_g += params->fogColor.g; + src_b += params->fogColor.b; */ +#endif } else { - /*int fog_r, fog_g, fog_b, fog_a; */ +#if 0 + int fog_r; + int fog_g; + int fog_b; + int fog_a; +#endif addbyte(0x66); /*PUNPCKLBW XMM0, XMM2*/ addbyte(0x0f); @@ -2167,10 +2184,12 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x01); /*ADD EAX, EBX*/ addbyte(0xd8); - /* int fog_idx = (w_depth >> 10) & 0x3f; +#if 0 + int fog_idx = (w_depth >> 10) & 0x3f; - fog_a = params->fogTable[fog_idx].fog; - fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10;*/ + fog_a = params->fogTable[fog_idx].fog; + fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10; +#endif break; case FOG_Z: @@ -2182,7 +2201,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(12); addbyte(0x25); /*AND EAX, 0xff*/ addlong(0xff); - // fog_a = (z >> 20) & 0xff; +#if 0 + fog_a = (z >> 20) & 0xff; +#endif break; case FOG_ALPHA: @@ -2204,7 +2225,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(ia >> 12); +#if 0 + fog_a = CLAMP(ia >> 12); +#endif break; case FOG_W: @@ -2225,13 +2248,16 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(w >> 32); +#if 0 + fog_a = CLAMP(w >> 32); +#endif break; } addbyte(0x01); /*ADD EAX, EAX*/ addbyte(0xc0); - // fog_a++; - +#if 0 + fog_a++; +#endif addbyte(0x66); /*PMULLW XMM3, alookup+4[EAX*8]*/ addbyte(0x0f); addbyte(0xd5); @@ -2243,9 +2269,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x71); addbyte(0xe3); addbyte(7); - /* fog_r = (fog_r * fog_a) >> 8; - fog_g = (fog_g * fog_a) >> 8; - fog_b = (fog_b * fog_a) >> 8;*/ +#if 0 + fog_r = (fog_r * fog_a) >> 8; + fog_g = (fog_g * fog_a) >> 8; + fog_b = (fog_b * fog_a) >> 8; +#endif if (params->fogMode & FOG_MULT) { addbyte(0xf3); /*MOV XMM0, XMM3*/ @@ -2257,9 +2285,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); addbyte(0xfd); addbyte(0xc3); - /* src_r += fog_r; - src_g += fog_g; - src_b += fog_b;*/ +#if 0 + src_r += fog_r; + src_g += fog_g; + src_b += fog_b; +#endif } addbyte(0x66); /*PACKUSWB XMM0, XMM0*/ addbyte(0x0f); @@ -2267,9 +2297,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0xc0); } - /* src_r = CLAMP(src_r); - src_g = CLAMP(src_g); - src_b = CLAMP(src_b);*/ +#if 0 + src_r = CLAMP(src_r); + src_g = CLAMP(src_g); + src_b = CLAMP(src_b); +#endif } if ((params->alphaMode & 1) && (alpha_func != AFUNC_NEVER) && (alpha_func != AFUNC_ALWAYS)) { @@ -2695,12 +2727,13 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x67); addbyte(0xc0); } - // #endif - // addbyte(0x8b); /*MOV EDX, x (ESP+12)*/ - // addbyte(0x54); - // addbyte(0x24); - // addbyte(12); +#if 0 + addbyte(0x8b); /*MOV EDX, x (ESP+12)*/ + addbyte(0x54); + addbyte(0x24); + addbyte(12); +#endif addbyte(0x8b); /*MOV EDX, state->x[EDI]*/ addbyte(0x97); @@ -2715,9 +2748,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0xc0); if (params->fbzMode & FBZ_RGB_WMASK) { - // addbyte(0x89); /*MOV state->rgb_out[EDI], EAX*/ - // addbyte(0x87); - // addlong(offsetof(voodoo_state_t, rgb_out)); +#if 0 + addbyte(0x89); /*MOV state->rgb_out[EDI], EAX*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, rgb_out)); +#endif if (dither) { addbyte(0x8b); /*MOV ESI, real_y (ESP+16)*/ @@ -3117,7 +3152,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat } voodoo_recomp++; data = &codegen_data[odd_even + next_block_to_write[odd_even] * 4]; - // code_block = data->code_block; +#if 0 + code_block = data->code_block; +#endif voodoo_generate(data->code_block, voodoo, params, state, depth_op); @@ -3141,11 +3178,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat void voodoo_codegen_init(voodoo_t *voodoo) { - int c; - voodoo->codegen_data = plat_mmap(sizeof(voodoo_x86_data_t) * BLOCK_NUM * 4, 1); - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { int d[4]; int _ds = c & 0xf; int dt = c >> 4; diff --git a/src/include/86box/vid_voodoo_common.h b/src/include/86box/vid_voodoo_common.h index 7744ed08b..92c608789 100644 --- a/src/include/86box/vid_voodoo_common.h +++ b/src/include/86box/vid_voodoo_common.h @@ -53,17 +53,25 @@ typedef union int_float { } int_float; typedef struct rgbvoodoo_t { - uint8_t b, g, r; + uint8_t b; + uint8_t g; + uint8_t r; uint8_t pad; } rgbvoodoo_t; typedef struct rgba8_t { - uint8_t b, g, r, a; + uint8_t b; + uint8_t g; + uint8_t r; + uint8_t a; } rgba8_t; typedef union rgba_u { struct { - uint8_t b, g, r, a; + uint8_t b; + uint8_t g; + uint8_t r; + uint8_t a; } rgba; uint32_t u; } rgba_u; @@ -105,24 +113,53 @@ typedef struct typedef struct voodoo_params_t { int command; - int32_t vertexAx, vertexAy, vertexBx, vertexBy, vertexCx, vertexCy; + int32_t vertexAx; + int32_t vertexAy; + int32_t vertexBx; + int32_t vertexBy; + int32_t vertexCx; + int32_t vertexCy; - uint32_t startR, startG, startB, startZ, startA; + uint32_t startR; + uint32_t startG; + uint32_t startB; + uint32_t startZ; + uint32_t startA; - int32_t dBdX, dGdX, dRdX, dAdX, dZdX; + int32_t dBdX; + int32_t dGdX; + int32_t dRdX; + int32_t dAdX; + int32_t dZdX; - int32_t dBdY, dGdY, dRdY, dAdY, dZdY; + int32_t dBdY; + int32_t dGdY; + int32_t dRdY; + int32_t dAdY; + int32_t dZdY; - int64_t startW, dWdX, dWdY; + int64_t startW; + int64_t dWdX; + int64_t dWdY; struct { - int64_t startS, startT, startW, p1; - int64_t dSdX, dTdX, dWdX, p2; - int64_t dSdY, dTdY, dWdY, p3; + int64_t startS; + int64_t startT; + int64_t startW; + int64_t p1; + int64_t dSdX; + int64_t dTdX; + int64_t dWdX; + int64_t p2; + int64_t dSdY; + int64_t dTdY; + int64_t dWdY; + int64_t p3; } tmu[2]; - uint32_t color0, color1; + uint32_t color0; + uint32_t color1; uint32_t fbzMode; uint32_t fbzColorPath; @@ -131,20 +168,26 @@ typedef struct voodoo_params_t { rgbvoodoo_t fogColor; struct { - uint8_t fog, dfog; + uint8_t fog; + uint8_t dfog; } fogTable[64]; uint32_t alphaMode; uint32_t zaColor; - int chromaKey_r, chromaKey_g, chromaKey_b; + int chromaKey_r; + int chromaKey_g; + int chromaKey_b; uint32_t chromaKey; uint32_t textureMode[2]; uint32_t tLOD[2]; - uint32_t texBaseAddr[2], texBaseAddr1[2], texBaseAddr2[2], texBaseAddr38[2]; + uint32_t texBaseAddr[2]; + uint32_t texBaseAddr1[2]; + uint32_t texBaseAddr2[2]; + uint32_t texBaseAddr38[2]; uint32_t tex_base[2][LOD_MAX + 2]; uint32_t tex_end[2][LOD_MAX + 2]; @@ -155,14 +198,23 @@ typedef struct voodoo_params_t { int tex_shift[2][LOD_MAX + 2]; int tex_lod[2][LOD_MAX + 2]; int tex_entry[2]; - int detail_max[2], detail_bias[2], detail_scale[2]; + int detail_max[2]; + int detail_bias[2]; + int detail_scale[2]; - uint32_t draw_offset, aux_offset; + uint32_t draw_offset; + uint32_t aux_offset; int tformat[2]; - int clipLeft, clipRight, clipLowY, clipHighY; - int clipLeft1, clipRight1, clipLowY1, clipHighY1; + int clipLeft; + int clipRight; + int clipLowY; + int clipHighY; + int clipLeft1; + int clipRight1; + int clipLowY1; + int clipHighY1; int sign; @@ -172,31 +224,46 @@ typedef struct voodoo_params_t { uint32_t stipple; - int col_tiled, aux_tiled; - int row_width, aux_row_width; + int col_tiled; + int aux_tiled; + int row_width; + int aux_row_width; } voodoo_params_t; typedef struct texture_t { uint32_t base; uint32_t tLOD; - atomic_int refcount, refcount_r[4]; + atomic_int refcount; + atomic_int refcount_r[4]; int is16; uint32_t palette_checksum; - uint32_t addr_start[4], addr_end[4]; + uint32_t addr_start[4]; + uint32_t addr_end[4]; uint32_t *data; } texture_t; typedef struct vert_t { - float sVx, sVy; - float sRed, sGreen, sBlue, sAlpha; - float sVz, sWb; - float sW0, sS0, sT0; - float sW1, sS1, sT1; + float sVx; + float sVy; + float sRed; + float sGreen; + float sBlue; + float sAlpha; + float sVz; + float sWb; + float sW0; + float sS0; + float sT0; + float sW1; + float sS1; + float sT1; } vert_t; typedef struct clip_t { - int x_min, x_max; - int y_min, y_max; + int x_min; + int x_max; + int y_min; + int y_max; } clip_t; typedef struct voodoo_t { @@ -205,7 +272,8 @@ typedef struct voodoo_t { int pci_enable; uint8_t dac_data[8]; - int dac_reg, dac_reg_ff; + int dac_reg; + int dac_reg_ff; uint8_t dac_readdata; uint16_t dac_pll_regs[16]; @@ -214,8 +282,14 @@ typedef struct voodoo_t { voodoo_params_t params; - uint32_t fbiInit0, fbiInit1, fbiInit2, fbiInit3, fbiInit4; - uint32_t fbiInit5, fbiInit6, fbiInit7; /*Voodoo 2*/ + uint32_t fbiInit0; + uint32_t fbiInit1; + uint32_t fbiInit2; + uint32_t fbiInit3; + uint32_t fbiInit4; + uint32_t fbiInit5; + uint32_t fbiInit6; + uint32_t fbiInit7; /*Voodoo 2*/ uint32_t initEnable; @@ -223,18 +297,28 @@ typedef struct voodoo_t { uint32_t memBaseAddr; - int_float fvertexAx, fvertexAy, fvertexBx, fvertexBy, fvertexCx, fvertexCy; + int_float fvertexAx; + int_float fvertexAy; + int_float fvertexBx; + int_float fvertexBy; + int_float fvertexCx; + int_float fvertexCy; - uint32_t front_offset, back_offset; + uint32_t front_offset; + uint32_t back_offset; - uint32_t fb_read_offset, fb_write_offset; + uint32_t fb_read_offset; + uint32_t fb_write_offset; - int row_width, aux_row_width; + int row_width; + int aux_row_width; int block_width; - int col_tiled, aux_tiled; + int col_tiled; + int aux_tiled; - uint8_t *fb_mem, *tex_mem[2]; + uint8_t *fb_mem; + uint8_t *tex_mem[2]; uint16_t *tex_mem_w[2]; int rgb_sel; @@ -246,7 +330,8 @@ typedef struct voodoo_t { mutex_t *swap_mutex; int swap_count; - int disp_buffer, draw_buffer; + int disp_buffer; + int draw_buffer; pc_timer_t timer; int line; @@ -254,15 +339,20 @@ typedef struct voodoo_t { uint32_t backPorch; uint32_t videoDimensions; - uint32_t hSync, vSync; + uint32_t hSync; + uint32_t vSync; - int h_total, v_total, v_disp; + int h_total; + int v_total; + int v_disp; int h_disp; int v_retrace; struct { - uint32_t y[4], i[4], q[4]; + uint32_t y[4]; + uint32_t i[4]; + uint32_t q[4]; } nccTable[2][2]; rgba_u palette[2][256]; @@ -284,9 +374,15 @@ typedef struct voodoo_t { int render_threads; int odd_even_mask; - int pixel_count[4], texel_count[4], tri_count, frame_count; - int pixel_count_old[4], texel_count_old[4]; - int wr_count, rd_count, tex_count; + int pixel_count[4]; + int texel_count[4]; + int tri_count; + int frame_count; + int pixel_count_old[4]; + int texel_count_old[4]; + int wr_count; + int rd_count; + int tex_count; int retrace_count; int swap_interval; @@ -306,18 +402,27 @@ typedef struct voodoo_t { int type; fifo_entry_t fifo[FIFO_SIZE]; - atomic_int fifo_read_idx, fifo_write_idx; - atomic_int cmd_read, cmd_written, cmd_written_fifo; + atomic_int fifo_read_idx; + atomic_int fifo_write_idx; + atomic_int cmd_read; + atomic_int cmd_written; + atomic_int cmd_written_fifo; voodoo_params_t params_buffer[PARAM_SIZE]; - atomic_int params_read_idx[4], params_write_idx; + atomic_int params_read_idx[4]; + atomic_int params_write_idx; - uint32_t cmdfifo_base, cmdfifo_end, cmdfifo_size; - int cmdfifo_rp, cmdfifo_ret_addr; + uint32_t cmdfifo_base; + uint32_t cmdfifo_end; + uint32_t cmdfifo_size; + int cmdfifo_rp; + int cmdfifo_ret_addr; int cmdfifo_in_sub; - atomic_int cmdfifo_depth_rd, cmdfifo_depth_wr; + atomic_int cmdfifo_depth_rd; + atomic_int cmdfifo_depth_wr; atomic_int cmdfifo_enabled; - uint32_t cmdfifo_amin, cmdfifo_amax; + uint32_t cmdfifo_amin; + uint32_t cmdfifo_amax; int cmdfifo_holecount; atomic_uint cmd_status; @@ -346,21 +451,37 @@ typedef struct voodoo_t { uint32_t bltSrcBaseAddr; uint32_t bltDstBaseAddr; - int bltSrcXYStride, bltDstXYStride; - uint32_t bltSrcChromaRange, bltDstChromaRange; - int bltSrcChromaMinR, bltSrcChromaMinG, bltSrcChromaMinB; - int bltSrcChromaMaxR, bltSrcChromaMaxG, bltSrcChromaMaxB; - int bltDstChromaMinR, bltDstChromaMinG, bltDstChromaMinB; - int bltDstChromaMaxR, bltDstChromaMaxG, bltDstChromaMaxB; + int bltSrcXYStride; + int bltDstXYStride; + uint32_t bltSrcChromaRange; + uint32_t bltDstChromaRange; + int bltSrcChromaMinR; + int bltSrcChromaMinG; + int bltSrcChromaMinB; + int bltSrcChromaMaxR; + int bltSrcChromaMaxG; + int bltSrcChromaMaxB; + int bltDstChromaMinR; + int bltDstChromaMinG; + int bltDstChromaMinB; + int bltDstChromaMaxR; + int bltDstChromaMaxG; + int bltDstChromaMaxB; - int bltClipRight, bltClipLeft; - int bltClipHighY, bltClipLowY; + int bltClipRight; + int bltClipLeft; + int bltClipHighY; + int bltClipLowY; - int bltSrcX, bltSrcY; - int bltDstX, bltDstY; - int bltSizeX, bltSizeY; + int bltSrcX; + int bltSrcY; + int bltDstX; + int bltDstY; + int bltSizeX; + int bltSizeY; int bltRop[4]; - uint16_t bltColorFg, bltColorBg; + uint16_t bltColorFg; + uint16_t bltColorBg; uint32_t bltCommand; @@ -368,20 +489,28 @@ typedef struct voodoo_t { struct { - int dst_x, dst_y; + int dst_x; + int dst_y; int cur_x; - int size_x, size_y; - int x_dir, y_dir; + int size_x; + int size_y; + int x_dir; + int y_dir; int dst_stride; } blt; struct { - uint32_t bresError0, bresError1; - uint32_t clip0Min, clip0Max; - uint32_t clip1Min, clip1Max; - uint32_t colorBack, colorFore; - uint32_t command, commandExtra; + uint32_t bresError0; + uint32_t bresError1; + uint32_t clip0Min; + uint32_t clip0Max; + uint32_t clip1Min; + uint32_t clip1Max; + uint32_t colorBack; + uint32_t colorFore; + uint32_t command; + uint32_t commandExtra; uint32_t dstBaseAddr; uint32_t dstFormat; uint32_t dstSize; @@ -396,20 +525,31 @@ typedef struct voodoo_t { uint32_t colorPattern[64]; - int bres_error_0, bres_error_1; - uint32_t colorPattern8[64], colorPattern16[64], colorPattern24[64]; - int cur_x, cur_y; + int bres_error_0; + int bres_error_1; + uint32_t colorPattern8[64]; + uint32_t colorPattern16[64]; + uint32_t colorPattern24[64]; + int cur_x; + int cur_y; uint32_t dstBaseAddr_tiled; - uint32_t dstColorkeyMin, dstColorkeyMax; - int dstSizeX, dstSizeY; - int dstX, dstY; + uint32_t dstColorkeyMin; + uint32_t dstColorkeyMax; + int dstSizeX; + int dstSizeY; + int dstX; + int dstY; int dst_stride; - int patoff_x, patoff_y; + int patoff_x; + int patoff_y; uint8_t rops[4]; uint32_t srcBaseAddr_tiled; - uint32_t srcColorkeyMin, srcColorkeyMax; - int srcSizeX, srcSizeY; - int srcX, srcY; + uint32_t srcColorkeyMin; + uint32_t srcColorkeyMax; + int srcSizeX; + int srcSizeY; + int srcX; + int srcY; int src_stride; int old_srcX; @@ -418,39 +558,54 @@ typedef struct voodoo_t { uint32_t old_host_data; /*Polyfill coordinates*/ - int lx[2], rx[2]; - int ly[2], ry[2]; + int lx[2]; + int rx[2]; + int ly[2]; + int ry[2]; /*Polyfill state*/ int error[2]; - int dx[2], dy[2]; + int dx[2]; + int dy[2]; int x_inc[2]; /*y_inc is always 1 for polyfill*/ - int lx_cur, rx_cur; + int lx_cur; + int rx_cur; clip_t clip[2]; uint8_t host_data[16384]; int host_data_count; - int host_data_size_src, host_data_size_dest; - int src_stride_src, src_stride_dest; + int host_data_size_src; + int host_data_size_dest; + int src_stride_src; + int src_stride_dest; int src_bpp; - int line_pix_pos, line_bit_pos; - int line_rep_cnt, line_bit_mask_size; + int line_pix_pos; + int line_bit_pos; + int line_rep_cnt; + int line_bit_mask_size; } banshee_blt; struct { uint32_t vidOverlayStartCoords; uint32_t vidOverlayEndScreenCoords; - uint32_t vidOverlayDudx, vidOverlayDudxOffsetSrcWidth; - uint32_t vidOverlayDvdy, vidOverlayDvdyOffset; - // uint32_t vidDesktopOverlayStride; + uint32_t vidOverlayDudx; + uint32_t vidOverlayDudxOffsetSrcWidth; + uint32_t vidOverlayDvdy; + uint32_t vidOverlayDvdyOffset; +#if 0 + uint32_t vidDesktopOverlayStride; +#endif - int start_x, start_y; - int end_x, end_y; - int size_x, size_y; + int start_x; + int start_y; + int end_x; + int end_y; + int size_x; + int size_y; int overlay_bytes; unsigned int src_y; @@ -462,17 +617,24 @@ typedef struct voodoo_t { uint32_t video_16to32[0x10000]; uint8_t dirty_line[2048]; - int dirty_line_low, dirty_line_high; + int dirty_line_low; + int dirty_line_high; - int fb_write_buffer, fb_draw_buffer; + int fb_write_buffer; + int fb_draw_buffer; int buffer_cutoff; - uint32_t tile_base, tile_stride; - int tile_stride_shift, tile_x, tile_x_real; + uint32_t tile_base; + uint32_t tile_stride; + int tile_stride_shift; + int tile_x; + int tile_x_real; int y_origin_swap; - int read_time, write_time, burst_time; + int read_time; + int write_time; + int burst_time; pc_timer_t wake_timer; @@ -501,9 +663,11 @@ typedef struct voodoo_t { struct voodoo_set_t *set; - uint8_t fifo_thread_run, render_thread_run[4]; + uint8_t fifo_thread_run; + uint8_t render_thread_run[4]; - uint8_t *vram, *changedvram; + uint8_t *vram; + uint8_t *changedvram; void *p; uint8_t monitor_index; @@ -517,7 +681,12 @@ typedef struct voodoo_set_t { int nr_cards; } voodoo_set_t; -extern rgba8_t rgb332[0x100], ai44[0x100], rgb565[0x10000], argb1555[0x10000], argb4444[0x10000], ai88[0x10000]; +extern rgba8_t rgb332[0x100]; +extern rgba8_t ai44[0x100]; +extern rgba8_t rgb565[0x10000]; +extern rgba8_t argb1555[0x10000]; +extern rgba8_t argb4444[0x10000]; +extern rgba8_t ai88[0x10000]; void voodoo_generate_vb_filters(voodoo_t *voodoo, int fcr, int fcg); diff --git a/src/include/86box/vid_xga.h b/src/include/86box/vid_xga.h index 5bc580335..b022aff28 100644 --- a/src/include/86box/vid_xga.h +++ b/src/include/86box/vid_xga.h @@ -20,9 +20,14 @@ #include <86box/rom.h> -typedef struct { +typedef struct xga_hwcursor_t { int ena; - int x, y, xoff, yoff, cur_xsize, cur_ysize; + int x; + int y; + int xoff; + int yoff; + int cur_xsize; + int cur_ysize; uint32_t addr; } xga_hwcursor_t; @@ -31,11 +36,15 @@ typedef struct xga_t { mem_mapping_t linear_mapping; mem_mapping_t video_mapping; rom_t bios_rom; - xga_hwcursor_t hwcursor, hwcursor_latch; + rom_t vga_bios_rom; + xga_hwcursor_t hwcursor; + xga_hwcursor_t hwcursor_latch; PALETTE extpal; - uint8_t test, atest[2], testpixel; - ; + uint8_t test; + uint8_t atest[2]; + uint8_t testpixel; + uint8_t pos_regs[8]; uint8_t disp_addr; uint8_t cfg_reg; @@ -48,31 +57,44 @@ typedef struct xga_t { uint8_t regs_idx; uint8_t hwc_hotspot_x; uint8_t hwc_hotspot_y; - uint8_t disp_cntl_1, disp_cntl_2; - uint8_t clk_sel_1, clk_sel_2; + uint8_t disp_cntl_1; + uint8_t disp_cntl_2; + uint8_t clk_sel_1; + uint8_t clk_sel_2; uint8_t hwc_control; uint8_t bus_arb; - uint8_t select_pos_isa; + uint8_t isa_pos_enable; uint8_t hwcursor_oddeven; uint8_t cfg_reg_instance; uint8_t rowcount; - uint8_t pal_idx, pal_idx_prefetch; + uint8_t pal_idx; + uint8_t pal_idx_prefetch; uint8_t pal_seq; uint8_t pal_mask; - uint8_t pal_r, pal_r_prefetch; - uint8_t pal_g, pal_g_prefetch; - uint8_t pal_b, pal_b_prefetch; + uint8_t pal_r; + uint8_t pal_r_prefetch; + uint8_t pal_g; + uint8_t pal_g_prefetch; + uint8_t pal_b; + uint8_t pal_b_prefetch; uint8_t sprite_data[1024]; uint8_t scrollcache; + uint8_t border_color; uint8_t direct_color; - uint8_t *vram, *changedvram; + uint8_t dma_channel; + uint8_t instance_isa; + uint8_t instance_num; + uint8_t ext_mem_addr; + uint8_t *vram; + uint8_t *changedvram; int16_t hwc_pos_x; int16_t hwc_pos_y; uint16_t pos_idx; uint16_t htotal; - uint16_t sprite_idx, sprite_idx_prefetch; + uint16_t sprite_idx; + uint16_t sprite_idx_prefetch; uint16_t hdisp; uint16_t vtotal; uint16_t vdispend; @@ -80,41 +102,74 @@ typedef struct xga_t { uint16_t vsyncstart; uint16_t linecmp; uint16_t pix_map_width; - uint16_t sprite_pal_addr_idx, old_pal_addr_idx; + uint16_t sprite_pal_addr_idx; + uint16_t old_pal_addr_idx; uint16_t sprite_pal_addr_idx_prefetch; - int v_total, dispend, v_syncstart, split, v_blankstart, - h_disp, h_disp_old, h_total, h_disp_time, rowoffset, - dispon, h_disp_on, vc, sc, linepos, oddeven, firstline, lastline, - firstline_draw, lastline_draw, displine, fullchange, interlace, - char_width, hwcursor_on; - int pal_pos, pal_pos_prefetch; + int v_total; + int dispend; + int v_syncstart; + int split; + int v_blankstart; + int h_disp; + int h_disp_old; + int h_total; + int h_disp_time; + int rowoffset; + int dispon; + int h_disp_on; + int vc; + int sc; + int linepos; + int oddeven; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int displine; + int fullchange; + int interlace; + int char_width; + int hwcursor_on; + int pal_pos; + int pal_pos_prefetch; int on; - int op_mode_reset, linear_endian_reverse; - int sprite_pos, sprite_pos_prefetch, cursor_data_on; - int pal_test, a5_test; - int type, bus; + int op_mode_reset; + int linear_endian_reverse; + int sprite_pos; + int sprite_pos_prefetch; + int cursor_data_on; + int pal_test; + int a5_test; + int type; + int bus; - uint32_t linear_base, linear_size, banked_mask; + uint32_t linear_base; + uint32_t linear_size; + uint32_t banked_mask; uint32_t base_addr_1mb; - uint32_t hwc_color0, hwc_color1; + uint32_t hwc_color0; + uint32_t hwc_color1; uint32_t disp_start_addr; uint32_t ma_latch; uint32_t vram_size; uint32_t vram_mask; uint32_t rom_addr; - uint32_t ma, maback; + uint32_t ma; + uint32_t maback; uint32_t extpallook[256]; - uint32_t read_bank, write_bank; + uint32_t read_bank; + uint32_t write_bank; uint32_t px_map_base; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; - struct - { + struct { uint8_t control; uint8_t px_map_idx; - uint8_t frgd_mix, bkgd_mix; + uint8_t frgd_mix; + uint8_t bkgd_mix; uint8_t cc_cond; uint8_t octant; uint8_t draw_mode; @@ -125,15 +180,19 @@ typedef struct xga_t { uint8_t short_stroke_vector4; int16_t bres_err_term; - int16_t bres_k1, bres_k2; + int16_t bres_k1; + int16_t bres_k2; uint16_t blt_width; uint16_t blt_height; uint16_t mask_map_origin_x_off; uint16_t mask_map_origin_y_off; - uint16_t src_map_x, src_map_y; - uint16_t dst_map_x, dst_map_y; - uint16_t pat_map_x, pat_map_y; + uint16_t src_map_x; + uint16_t src_map_y; + uint16_t dst_map_x; + uint16_t dst_map_y; + uint16_t pat_map_x; + uint16_t pat_map_y; int ssv_state; int pat_src; @@ -141,7 +200,14 @@ typedef struct xga_t { int dst_map; int bkgd_src; int fore_src; - int x, y, sx, sy, dx, dy, px, py; + int x; + int y; + int sx; + int sy; + int dx; + int dy; + int px; + int py; int pattern; int command_len; @@ -149,7 +215,8 @@ typedef struct xga_t { uint32_t color_cmp; uint32_t carry_chain; uint32_t plane_mask; - uint32_t frgd_color, bkgd_color; + uint32_t frgd_color; + uint32_t bkgd_color; uint32_t command; uint32_t dir_cmd; @@ -159,6 +226,6 @@ typedef struct xga_t { uint32_t px_map_base[4]; } accel; - volatile int force_busy; + int big_endian_linear; } xga_t; #endif /*VIDEO_XGA_H*/ diff --git a/src/include/86box/vid_xga_device.h b/src/include/86box/vid_xga_device.h index a92c6d3c6..7aa274d30 100644 --- a/src/include/86box/vid_xga_device.h +++ b/src/include/86box/vid_xga_device.h @@ -17,6 +17,11 @@ #ifndef VIDEO_XGA_DEVICE_H #define VIDEO_XGA_DEVICE_H +extern int xga_has_vga; + +#ifdef EMU_DEVICE_H extern const device_t xga_device; extern const device_t xga_isa_device; +extern const device_t inmos_isa_device; +#endif #endif /*VIDEO_XGA_DEVICE_H*/ diff --git a/src/include/86box/video.h b/src/include/86box/video.h index a49f3bf34..b915fe35d 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -60,50 +60,59 @@ enum { #define VIDEO_FLAG_TYPE_CGA 0 #define VIDEO_FLAG_TYPE_MDA 1 #define VIDEO_FLAG_TYPE_SPECIAL 2 -#define VIDEO_FLAG_TYPE_NONE 3 -#define VIDEO_FLAG_TYPE_MASK 3 +#define VIDEO_FLAG_TYPE_8514 3 +#define VIDEO_FLAG_TYPE_XGA 4 +#define VIDEO_FLAG_TYPE_NONE 5 +#define VIDEO_FLAG_TYPE_MASK 7 -typedef struct { +typedef struct video_timings_t { int type; - int write_b, write_w, write_l; - int read_b, read_w, read_l; + int write_b; + int write_w; + int write_l; + int read_b; + int read_w; + int read_l; } video_timings_t; -typedef struct { - int w, h; +typedef struct bitmap_t { + int w; + int h; uint32_t *dat; uint32_t *line[2112]; } bitmap_t; -typedef struct { - uint8_t r, g, b; +typedef struct rgb_t { + uint8_t r; + uint8_t g; + uint8_t b; } rgb_t; -typedef struct { +typedef struct dbcs_font_t { uint8_t chr[32]; } dbcs_font_t; struct blit_data_struct; typedef struct monitor_t { - char name[512]; - int mon_xsize; - int mon_ysize; - int mon_scrnsz_x; - int mon_scrnsz_y; - int mon_efscrnsz_y; - int mon_unscaled_size_x; - int mon_unscaled_size_y; - int mon_res_x; - int mon_res_y; - int mon_bpp; - bitmap_t *target_buffer; - int mon_video_timing_read_b, - mon_video_timing_read_w, - mon_video_timing_read_l; - int mon_video_timing_write_b, - mon_video_timing_write_w, - mon_video_timing_write_l; + char name[512]; + int mon_xsize; + int mon_ysize; + int mon_scrnsz_x; + int mon_scrnsz_y; + int mon_efscrnsz_y; + int mon_unscaled_size_x; + int mon_unscaled_size_y; + int mon_res_x; + int mon_res_y; + int mon_bpp; + bitmap_t *target_buffer; + int mon_video_timing_read_b; + int mon_video_timing_read_w; + int mon_video_timing_read_l; + int mon_video_timing_write_b; + int mon_video_timing_write_w; + int mon_video_timing_write_l; int mon_overscan_x; int mon_overscan_y; int mon_force_resize; @@ -137,10 +146,14 @@ extern int video_fullscreen_scale_maximized; typedef rgb_t PALETTE[256]; -// extern int changeframecount; +#if 0 +extern int changeframecount; +#endif extern volatile int screenshots; -// extern bitmap_t *buffer32; +#if 0 +extern bitmap_t *buffer32; +#endif #define buffer32 (monitors[monitor_index_global].target_buffer) #define pal_lookup (monitors[monitor_index_global].mon_pal_lookup) #define overscan_x (monitors[monitor_index_global].mon_overscan_x) @@ -163,12 +176,14 @@ extern volatile int screenshots; #define efscrnsz_y (monitors[monitor_index_global].mon_efscrnsz_y) #define unscaled_size_x (monitors[monitor_index_global].mon_unscaled_size_x) #define unscaled_size_y (monitors[monitor_index_global].mon_unscaled_size_y) -extern PALETTE cgapal, - cgapal_mono[6]; -// extern uint32_t pal_lookup[256]; -extern int video_fullscreen, - video_fullscreen_scale, - video_fullscreen_first; +extern PALETTE cgapal; +extern PALETTE cgapal_mono[6]; +#if 0 +extern uint32_t pal_lookup[256]; +#endif +extern int video_fullscreen; +extern int video_fullscreen_scale; +extern int video_fullscreen_first; extern uint8_t fontdat[2048][8]; extern uint8_t fontdatm[2048][16]; extern uint8_t fontdatw[512][32]; @@ -176,23 +191,24 @@ extern uint8_t fontdat8x12[256][16]; extern uint8_t fontdat12x18[256][36]; extern dbcs_font_t *fontdatksc5601; extern dbcs_font_t *fontdatksc5601_user; -extern uint32_t *video_6to8, - *video_8togs, - *video_8to32, - *video_15to32, - *video_16to32; -extern int enable_overscan; -extern int force_43; -extern int vid_resize; -extern int herc_blend; -extern int vid_cga_contrast; -extern int video_grayscale; -extern int video_graytype; +extern uint32_t *video_6to8; +extern uint32_t *video_8togs; +extern uint32_t *video_8to32; +extern uint32_t *video_15to32; +extern uint32_t *video_16to32; +extern int enable_overscan; +extern int force_43; +extern int vid_resize; +extern int herc_blend; +extern int vid_cga_contrast; +extern int video_grayscale; +extern int video_graytype; extern double cpuclock; -extern int emu_fps, - frames; -extern int readflash; +extern int emu_fps; +extern int frames; +extern int readflash; +extern int ibm8514_has_vga; /* Function handler pointers. */ extern void (*video_recalctimings)(void); @@ -219,6 +235,8 @@ extern int video_card_get_flags(int card); extern int video_is_mda(void); extern int video_is_cga(void); extern int video_is_ega_vga(void); +extern int video_is_8514(void); +extern int video_is_xga(void); extern void video_inform_monitor(int type, const video_timings_t *ptr, int monitor_index); extern int video_get_type_monitor(int monitor_index); @@ -277,8 +295,12 @@ extern uint32_t video_color_transform(uint32_t color); /* IBM XGA */ extern void xga_device_add(void); -/* IBM 8514/A and generic clones*/ +/* IBM 8514/A and clones*/ extern void ibm8514_device_add(void); +extern const device_t mach8_isa_device; +extern const device_t mach32_isa_device; +extern const device_t mach32_vlb_device; +extern const device_t mach32_pci_device; /* ATi Mach64 */ extern const device_t mach64gx_isa_device; diff --git a/src/include/86box/win.h b/src/include/86box/win.h index 99620cbeb..35f6688ad 100644 --- a/src/include/86box/win.h +++ b/src/include/86box/win.h @@ -103,17 +103,21 @@ extern "C" { #endif extern HINSTANCE hinstance; -extern HWND hwndMain, - hwndRender, - hwndRender2; -extern HANDLE ghMutex; -extern HICON hIcon[256]; -extern int dpi; -extern RECT oldclip; -extern int sbar_height, tbar_height, user_resize; -extern int acp_utf8; +extern HWND hwndMain; +extern HWND hwndRender; +extern HWND hwndRender2; +extern HANDLE ghMutex; +extern HICON hIcon[256]; +extern int dpi; +extern RECT oldclip; +extern int sbar_height; +extern int tbar_height; +extern int user_resize; +extern int acp_utf8; -// extern int status_is_open; +#if 0 +extern int status_is_open; +#endif extern char openfilestring[512]; extern WCHAR wopenfilestring[512]; diff --git a/src/include/86box/zip.h b/src/include/86box/zip.h index 3981465ce..9ff69d092 100644 --- a/src/include/86box/zip.h +++ b/src/include/86box/zip.h @@ -32,60 +32,75 @@ enum { ZIP_BUS_DISABLED = 0, ZIP_BUS_ATAPI = 5, - ZIP_BUS_SCSI, - ZIP_BUS_USB + ZIP_BUS_SCSI = 6, + ZIP_BUS_USB = 7 }; -typedef struct { +typedef struct zip_drive_t { uint8_t id; union { - uint8_t res, res0, /* Reserved for other ID's. */ - res1, - ide_channel, scsi_device_id; + uint8_t res; + uint8_t res0; /* Reserved for other ID's. */ + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - uint8_t bus_type, /* 0 = ATAPI, 1 = SCSI */ - bus_mode, /* Bit 0 = PIO suported; - Bit 1 = DMA supportd. */ - read_only, /* Struct variable reserved for - media status. */ - pad, pad0; + uint8_t bus_type; /* 0 = ATAPI, 1 = SCSI */ + uint8_t bus_mode; /* Bit 0 = PIO suported; + Bit 1 = DMA supportd. */ + uint8_t read_only; /* Struct variable reserved for + media status. */ + uint8_t pad; + uint8_t pad0; FILE *f; void *priv; - char image_path[1024], - prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; - uint32_t is_250, medium_size, - base; + uint32_t is_250; + uint32_t medium_size; + uint32_t base; } zip_drive_t; -typedef struct { +typedef struct zip_t { mode_sense_pages_t ms_pages_saved; zip_drive_t *drv; - uint8_t *buffer, - atapi_cdb[16], - current_cdb[16], - sense[256]; + uint8_t *buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint8_t status, phase, - error, id, - features, cur_lun, - pad0, pad1; + uint8_t status; + uint8_t phase; + uint8_t error; + uint8_t id; + uint8_t features; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - uint16_t request_length, max_transfer_len; + uint16_t request_length; + uint16_t max_transfer_len; - int requested_blocks, packet_status, - total_length, do_page_save, - unit_attention, request_pos, - old_len, pad3; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int pad3; - uint32_t sector_pos, sector_len, - packet_len, pos; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t pos; double callback; } zip_t; diff --git a/src/include/tinyglib.h b/src/include/tinyglib.h deleted file mode 100644 index 9edd5986a..000000000 --- a/src/include/tinyglib.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Minimal reimplementation of GLib for libslirp. - * - * - * - * Authors: RichardG, - * - * Copyright 2020 RichardG. - */ -#ifndef TINYGLIB_H -#define TINYGLIB_H - -/* Define this to bypass TinyGLib and use full GLib instead. */ -#ifdef TINYGLIB_USE_GLIB -# include -#else - -# include -# include -# include -# include -# define HAVE_STDARG_H -# include <86box/86box.h> - -/* Definitions */ - -# define G_LITTLE_ENDIAN 1234 -# define G_BIG_ENDIAN 4321 -# define G_PDP_ENDIAN 3412 -# ifdef __BYTE_ORDER__ -# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# define G_BYTE_ORDER G_LITTLE_ENDIAN -# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define G_BYTE_ORDER G_BIG_ENDIAN -# elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ -# define G_BYTE_ORDER G_PDP_ENDIAN -# endif -# endif -# ifndef G_BYTE_ORDER -/* Safe to assume LE for MSVC, as Windows is LE on all architectures. */ -# define G_BYTE_ORDER G_LITTLE_ENDIAN -# endif - -# ifdef _WIN32 -# define G_OS_WIN32 1 -# else -# define G_OS_UNIX 1 -# endif - -# define G_SPAWN_SEARCH_PATH 0 - -# if defined(__LP64__) || defined(__LLP64__) || defined(_WIN64) -# define GLIB_SIZEOF_VOID_P 8 -# if defined(__LLP64__) || defined(_WIN64) -# define GLIB_SIZEOF_LONG 4 -# else -# define GLIB_SIZEOF_LONG 8 -# endif -# define GLIB_SIZEOF_SIZE_T 8 -# define GLIB_SIZEOF_SSIZE_T 8 -# else -# define GLIB_SIZEOF_VOID_P 4 -# define GLIB_SIZEOF_LONG 4 -# define GLIB_SIZEOF_SIZE_T 4 -# define GLIB_SIZEOF_SSIZE_T 4 -# endif - -/* Types */ - -/* Windows does not define ssize_t, so we need to define it here. */ -# ifndef _SSIZE_T_DEFINED -# define _SSIZE_T_DEFINED -# undef ssize_t -# ifdef _WIN64 -# define ssize_t int64_t -# else -# define ssize_t int32_t -# endif -# endif - -# define gboolean int -# define gchar char -# define gint int -# define gint16 int16_t -# define gint32 int32_t -# define gint64 int64_t -# define glong long -# define GPid void * -# define gpointer void * -# define gsize size_t -# define GSpawnFlags void * -# define GSpawnChildSetupFunc void * -# define gssize ssize_t -# define GString char -# define GStrv char ** -# define guint unsigned int -# define guint16 uint16_t -# define guint32 uint32_t -# define guint64 uint64_t - -typedef struct _GDebugKey { - char key[32]; - int val; -} GDebugKey; - -typedef struct _GError { - char message[1]; -} GError; - -typedef struct _GRand { - uint8_t dummy; -} GRand; - -/* Functions */ -extern gboolean g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, - gchar **envp, GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, GPid *child_pid, gint stdin_fd, - gint stdout_fd, gint stderr_fd, GError **error); -extern gboolean g_str_has_prefix (const gchar *str, - const gchar *prefix); -extern GString *g_string_new(gchar *base); -extern gchar *g_string_free(GString *string, gboolean free_segment); -extern gchar *g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle); -extern guint g_strv_length(gchar **str_array); - -/* Macros */ -# define tinyglib_pclog(f, s, ...) pclog("TinyGLib " f "(): " s "\n", ##__VA_ARGS__) - -# define GLIB_CHECK_VERSION(a, b, c) 1 -# ifdef __GNUC__ -# define G_GNUC_PRINTF(format_idx, arg_idx) __attribute__((__format__(__printf__, format_idx, arg_idx))) -# else -# define G_GNUC_PRINTF(format_idx, arg_idx) -# endif -# define G_N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0])) -# define G_STATIC_ASSERT(e) /* this should probably do something */ -# define G_UNLIKELY(e) (e) - -# define g_assert(e) \ - do { \ - if (!(e)) \ - fatal("TinyGLib g_assert(" #e ")\n"); \ - } while (0) -# ifdef __GNUC__ -# define g_assert_not_reached __builtin_unreachable -# else -# ifdef _MSC_VER -# define g_assert_not_reached() __assume(0) -# else -# define g_assert_not_reached() -# endif -# endif -# define g_critical(s, ...) fatal("TinyGLib g_critical(): " s "\n", ##__VA_ARGS__) -# ifdef TINYGLIB_DEBUG -# define g_debug(s, ...) tinyglib_pclog("g_debug", s, ##__VA_ARGS__) -# else -# define g_debug(s, ...) -# endif -# define g_error(s, ...) tinyglib_pclog("g_error", s, ##__VA_ARGS__) -# define g_error_free(err) -# define g_malloc0(s) calloc(1, s) -# define g_new(t, n) (t *) malloc(sizeof(t) * n) -# define g_new0(t, n) (t *) calloc(n, sizeof(t)) -# ifdef TINYGLIB_DEBUG -# define g_parse_debug_string(s, k, n) ((!!sizeof(k)) * -1) /* unimplemented; always enables all debug flags */ -# else -# define g_parse_debug_string(s, k, n) (!sizeof(k)) -# endif -# define g_rand_int_range(r, min, max) (rand() % (max + 1 - min) + min) -# define g_rand_new() calloc(1, sizeof(GRand)) -# define g_return_val_if_fail(e, v) \ - if (!(e)) \ - return (v) -# define g_shell_parse_argv(a, b, c, d) !!(sizeof(b)) /* unimplemented */ -# define g_strdup(str) ((str) ? strdup(str) : NULL) -# define g_warn_if_fail(e) \ - do { \ - if (!(e)) \ - pclog("TinyGLib g_warn_if_fail(" #e ")\n"); \ - } while (0) -# define g_warn_if_reached() pclog("TinyGLib g_warn_if_reached()\n") -# define g_warning(s, ...) tinyglib_pclog("g_warning", s, ##__VA_ARGS__) - -/* Remapped functions */ -# define g_free free -# define g_getenv getenv -# define g_malloc malloc -# define g_rand_free free -# define g_realloc realloc -# define g_snprintf snprintf -# define g_strerror strerror -# define g_strfreev free -# define g_string_append_printf sprintf /* unimplemented */ -# define g_vsnprintf vsnprintf - -#endif - -#endif diff --git a/src/ini.c b/src/ini.c index 009d21c0b..29f8e05fb 100644 --- a/src/ini.c +++ b/src/ini.c @@ -42,7 +42,7 @@ typedef struct _list_ { struct _list_ *next; } list_t; -typedef struct { +typedef struct section_t { list_t list; char name[128]; @@ -50,7 +50,7 @@ typedef struct { list_t entry_head; } section_t; -typedef struct { +typedef struct entry_t { list_t list; char name[128]; @@ -101,17 +101,17 @@ ini_log(const char *fmt, ...) #endif static section_t * -find_section(list_t *head, char *name) +find_section(list_t *head, const char *name) { section_t *sec = (section_t *) head->next; - char blank[] = ""; + const char blank[] = ""; if (name == NULL) name = blank; while (sec != NULL) { if (!strncmp(sec->name, name, sizeof(sec->name))) - return (sec); + return sec; sec = (section_t *) sec->list.next; } @@ -120,7 +120,7 @@ find_section(list_t *head, char *name) } ini_section_t -ini_find_section(ini_t ini, char *name) +ini_find_section(ini_t ini, const char *name) { if (ini == NULL) return NULL; @@ -129,7 +129,7 @@ ini_find_section(ini_t ini, char *name) } void -ini_rename_section(ini_section_t section, char *name) +ini_rename_section(ini_section_t section, const char *name) { section_t *sec = (section_t *) section; @@ -149,7 +149,7 @@ find_entry(section_t *section, const char *name) while (ent != NULL) { if (!strncmp(ent->name, name, sizeof(ent->name))) - return (ent); + return ent; ent = (entry_t *) ent->list.next; } @@ -172,7 +172,7 @@ entries_num(section_t *section) ent = (entry_t *) ent->list.next; } - return (i); + return i; } static void @@ -197,7 +197,7 @@ ini_delete_section_if_empty(ini_t ini, ini_section_t section) } static section_t * -create_section(list_t *head, char *name) +create_section(list_t *head, const char *name) { section_t *ns = malloc(sizeof(section_t)); @@ -205,11 +205,11 @@ create_section(list_t *head, char *name) memcpy(ns->name, name, strlen(name) + 1); list_add(&ns->list, head); - return (ns); + return ns; } ini_section_t -ini_find_or_create_section(ini_t ini, char *name) +ini_find_or_create_section(ini_t ini, const char *name) { if (ini == NULL) return NULL; @@ -230,13 +230,14 @@ create_entry(section_t *section, const char *name) memcpy(ne->name, name, strlen(name) + 1); list_add(&ne->list, §ion->entry_head); - return (ne); + return ne; } void ini_close(ini_t ini) { - section_t *sec, *ns; + section_t *sec; + section_t *ns; entry_t *ent; list_t *list = (list_t *) ini; @@ -263,7 +264,7 @@ ini_close(ini_t ini) } static int -ini_detect_bom(char *fn) +ini_detect_bom(const char *fn) { FILE *f; unsigned char bom[4] = { 0, 0, 0, 0 }; @@ -274,7 +275,7 @@ ini_detect_bom(char *fn) f = plat_fopen(fn, "rt, ccs=UTF-8"); #endif if (f == NULL) - return (0); + return 0; (void) !fread(bom, 1, 3, f); if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) { fclose(f); @@ -311,13 +312,17 @@ ini_fgetws(wchar_t *str, int count, FILE *stream) /* Read and parse the configuration file into memory. */ ini_t -ini_read(char *fn) +ini_read(const char *fn) { - char sname[128], ename[128]; + char sname[128]; + char ename[128]; wchar_t buff[1024]; - section_t *sec, *ns; + section_t *sec; + section_t *ns; entry_t *ne; - int c, d, bom; + int c; + int d; + int bom; FILE *f; list_t *head; @@ -438,7 +443,7 @@ ini_read(char *fn) /* Write the in-memory configuration to disk. */ void -ini_write(ini_t ini, char *fn) +ini_write(ini_t ini, const char *fn) { wchar_t wtemp[512]; list_t *list = (list_t *) ini; @@ -521,7 +526,7 @@ ini_dump(ini_t ini) } void -ini_section_delete_var(ini_section_t self, char *name) +ini_section_delete_var(ini_section_t self, const char *name) { section_t *section = (section_t *) self; entry_t *entry; @@ -537,94 +542,96 @@ ini_section_delete_var(ini_section_t self, char *name) } int -ini_section_get_int(ini_section_t self, char *name, int def) +ini_section_get_int(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - int value; + section_t *section = (section_t *) self; + const entry_t *entry; + int value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%i", &value); - return (value); + return value; } double -ini_section_get_double(ini_section_t self, char *name, double def) +ini_section_get_double(ini_section_t self, const char *name, double def) { - section_t *section = (section_t *) self; - entry_t *entry; - double value; + section_t *section = (section_t *) self; + const entry_t *entry; + double value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%lg", &value); - return (value); + return value; } int -ini_section_get_hex16(ini_section_t self, char *name, int def) +ini_section_get_hex16(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - unsigned int value; + section_t *section = (section_t *) self; + const entry_t *entry; + unsigned int value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%04X", &value); - return (value); + return value; } int -ini_section_get_hex20(ini_section_t self, char *name, int def) +ini_section_get_hex20(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - unsigned int value; + section_t *section = (section_t *) self; + const entry_t *entry; + unsigned int value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%05X", &value); - return (value); + return value; } int -ini_section_get_mac(ini_section_t self, char *name, int def) +ini_section_get_mac(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - unsigned int val0 = 0, val1 = 0, val2 = 0; + section_t *section = (section_t *) self; + const entry_t *entry; + unsigned int val0 = 0; + unsigned int val1 = 0; + unsigned int val2 = 0; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); @@ -632,39 +639,39 @@ ini_section_get_mac(ini_section_t self, char *name, int def) } char * -ini_section_get_string(ini_section_t self, char *name, char *def) +ini_section_get_string(ini_section_t self, const char *name, char *def) { section_t *section = (section_t *) self; entry_t *entry; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; return (entry->data); } wchar_t * -ini_section_get_wstring(ini_section_t self, char *name, wchar_t *def) +ini_section_get_wstring(ini_section_t self, const char *name, wchar_t *def) { section_t *section = (section_t *) self; entry_t *entry; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; return (entry->wdata); } void -ini_section_set_int(ini_section_t self, char *name, int val) +ini_section_set_int(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -681,7 +688,7 @@ ini_section_set_int(ini_section_t self, char *name, int val) } void -ini_section_set_double(ini_section_t self, char *name, double val) +ini_section_set_double(ini_section_t self, const char *name, double val) { section_t *section = (section_t *) self; entry_t *ent; @@ -698,7 +705,7 @@ ini_section_set_double(ini_section_t self, char *name, double val) } void -ini_section_set_hex16(ini_section_t self, char *name, int val) +ini_section_set_hex16(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -715,7 +722,7 @@ ini_section_set_hex16(ini_section_t self, char *name, int val) } void -ini_section_set_hex20(ini_section_t self, char *name, int val) +ini_section_set_hex20(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -732,7 +739,7 @@ ini_section_set_hex20(ini_section_t self, char *name, int val) } void -ini_section_set_mac(ini_section_t self, char *name, int val) +ini_section_set_mac(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -774,7 +781,7 @@ ini_section_set_string(ini_section_t self, const char *name, const char *val) } void -ini_section_set_wstring(ini_section_t self, char *name, wchar_t *val) +ini_section_set_wstring(ini_section_t self, const char *name, wchar_t *val) { section_t *section = (section_t *) self; entry_t *ent; diff --git a/src/io.c b/src/io.c index 0cd7cd87b..173e6707b 100644 --- a/src/io.c +++ b/src/io.c @@ -29,6 +29,7 @@ #include <86box/timer.h> #include "cpu.h" #include <86box/m_amstrad.h> +#include <86box/pci.h> #define NPORTS 65536 /* PC/AT supports 64K ports */ @@ -47,14 +48,16 @@ typedef struct _io_ { } io_t; typedef struct { - uint8_t enable; - uint16_t base, size; - void (*func)(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv), - *priv; + uint8_t enable; + uint16_t base; + uint16_t size; + void (*func)(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv); + void *priv; } io_trap_t; int initialized = 0; -io_t *io[NPORTS], *io_last[NPORTS]; +io_t *io[NPORTS]; +io_t *io_last[NPORTS]; #ifdef ENABLE_IO_LOG int io_do_log = ENABLE_IO_LOG; @@ -78,7 +81,8 @@ void io_init(void) { int c; - io_t *p, *q; + io_t *p; + io_t *q; if (!initialized) { for (c = 0; c < NPORTS; c++) @@ -114,10 +118,10 @@ io_sethandler_common(uint16_t base, int size, void (*outl)(uint16_t addr, uint32_t val, void *priv), void *priv, int step) { - int c; - io_t *p, *q = NULL; + io_t *p; + io_t *q = NULL; - for (c = 0; c < size; c += step) { + for (int c = 0; c < size; c += step) { p = io_last[base + c]; q = (io_t *) malloc(sizeof(io_t)); memset(q, 0, sizeof(io_t)); @@ -154,10 +158,10 @@ io_removehandler_common(uint16_t base, int size, void (*outl)(uint16_t addr, uint32_t val, void *priv), void *priv, int step) { - int c; - io_t *p, *q; + io_t *p; + io_t *q; - for (c = 0; c < size; c += step) { + for (int c = 0; c < size; c += step) { p = io[base + c]; if (!p) continue; @@ -279,19 +283,30 @@ uint8_t inb(uint16_t port) { uint8_t ret = 0xff; - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; - p = io[port]; - while (p) { - q = p->next; - if (p->inb) { - ret &= p->inb(port, p->priv); - found |= 1; - qfound++; + if ((pci_take_over_io & PCI_IO_ON) && (port >= pci_base) && (port < (pci_base + pci_size))) { + ret = pci_type2_read(port, NULL); + found = 1; + qfound = 1; + } else if ((pci_take_over_io & PCI_IO_DEV0) && (port >= 0xc000) && (port < 0xc100)) { + ret = pci_type2_read(port, NULL); + found = 1; + qfound = 1; + } else { + p = io[port]; + while (p) { + q = p->next; + if (p->inb) { + ret &= p->inb(port, p->priv); + found |= 1; + qfound++; + } + p = q; } - p = q; } if (amstrad_latch & 0x80000000) { @@ -307,30 +322,43 @@ inb(uint16_t port) cycles -= io_delay; /* TriGem 486-BIOS MHz output. */ - /* if (port == 0x1ed) - ret = 0xfe; */ +#if 0 + if (port == 0x1ed) + ret = 0xfe; +#endif io_log("[%04X:%08X] (%i, %i, %04i) in b(%04X) = %02X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret); - return (ret); + return ret; } void outb(uint16_t port, uint8_t val) { - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; - p = io[port]; - while (p) { - q = p->next; - if (p->outb) { - p->outb(port, val, p->priv); - found |= 1; - qfound++; + if ((pci_take_over_io & PCI_IO_ON) && (port >= pci_base) && (port < (pci_base + pci_size))) { + pci_type2_write(port, val, NULL); + found = 1; + qfound = 1; + } else if ((pci_take_over_io & PCI_IO_DEV0) && (port >= 0xc000) && (port < 0xc100)) { + pci_type2_write(port, val, NULL); + found = 1; + qfound = 1; + } else { + p = io[port]; + while (p) { + q = p->next; + if (p->outb) { + p->outb(port, val, p->priv); + found |= 1; + qfound++; + } + p = q; } - p = q; } if (!found) { @@ -349,39 +377,49 @@ outb(uint16_t port, uint8_t val) uint16_t inw(uint16_t port) { - io_t *p, *q; + io_t *p; + io_t *q; uint16_t ret = 0xffff; int found = 0; int qfound = 0; uint8_t ret8[2]; - int i = 0; - p = io[port]; - while (p) { - q = p->next; - if (p->inw) { - ret &= p->inw(port, p->priv); - found |= 2; - qfound++; - } - p = q; - } - - ret8[0] = ret & 0xff; - ret8[1] = (ret >> 8) & 0xff; - for (i = 0; i < 2; i++) { - p = io[(port + i) & 0xffff]; + if ((pci_take_over_io & PCI_IO_ON) && (port >= pci_base) && (port < (pci_base + pci_size))) { + ret = pci_type2_readw(port, NULL); + found = 2; + qfound = 1; + } else if ((pci_take_over_io & PCI_IO_DEV0) && (port >= 0xc000) && (port < 0xc100)) { + ret = pci_type2_readw(port, NULL); + found = 2; + qfound = 1; + } else { + p = io[port]; while (p) { q = p->next; - if (p->inb && !p->inw) { - ret8[i] &= p->inb(port + i, p->priv); - found |= 1; + if (p->inw) { + ret &= p->inw(port, p->priv); + found |= 2; qfound++; } p = q; } + + ret8[0] = ret & 0xff; + ret8[1] = (ret >> 8) & 0xff; + for (uint8_t i = 0; i < 2; i++) { + p = io[(port + i) & 0xffff]; + while (p) { + q = p->next; + if (p->inb && !p->inw) { + ret8[i] &= p->inb(port + i, p->priv); + found |= 1; + qfound++; + } + p = q; + } + } + ret = (ret8[1] << 8) | ret8[0]; } - ret = (ret8[1] << 8) | ret8[0]; if (amstrad_latch & 0x80000000) { if (port & 0x80) @@ -403,33 +441,43 @@ inw(uint16_t port) void outw(uint16_t port, uint16_t val) { - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; - int i = 0; - p = io[port]; - while (p) { - q = p->next; - if (p->outw) { - p->outw(port, val, p->priv); - found |= 2; - qfound++; - } - p = q; - } - - for (i = 0; i < 2; i++) { - p = io[(port + i) & 0xffff]; + if ((pci_take_over_io & PCI_IO_ON) && (port >= pci_base) && (port < (pci_base + pci_size))) { + pci_type2_writew(port, val, NULL); + found = 2; + qfound = 1; + } else if ((pci_take_over_io & PCI_IO_DEV0) && (port >= 0xc000) && (port < 0xc100)) { + pci_type2_writew(port, val, NULL); + found = 2; + qfound = 1; + } else { + p = io[port]; while (p) { q = p->next; - if (p->outb && !p->outw) { - p->outb(port + i, val >> (i << 3), p->priv); - found |= 1; + if (p->outw) { + p->outw(port, val, p->priv); + found |= 2; qfound++; } p = q; } + + for (uint8_t i = 0; i < 2; i++) { + p = io[(port + i) & 0xffff]; + while (p) { + q = p->next; + if (p->outb && !p->outw) { + p->outb(port + i, val >> (i << 3), p->priv); + found |= 1; + qfound++; + } + p = q; + } + } } if (!found) { @@ -448,67 +496,77 @@ outw(uint16_t port, uint16_t val) uint32_t inl(uint16_t port) { - io_t *p, *q; + io_t *p; + io_t *q; uint32_t ret = 0xffffffff; uint16_t ret16[2]; uint8_t ret8[4]; int found = 0; int qfound = 0; - int i = 0; - p = io[port]; - while (p) { - q = p->next; - if (p->inl) { - ret &= p->inl(port, p->priv); - found |= 4; - qfound++; - } - p = q; - } - - ret16[0] = ret & 0xffff; - ret16[1] = (ret >> 16) & 0xffff; - p = io[port & 0xffff]; - while (p) { - q = p->next; - if (p->inw && !p->inl) { - ret16[0] &= p->inw(port, p->priv); - found |= 2; - qfound++; - } - p = q; - } - - p = io[(port + 2) & 0xffff]; - while (p) { - q = p->next; - if (p->inw && !p->inl) { - ret16[1] &= p->inw(port + 2, p->priv); - found |= 2; - qfound++; - } - p = q; - } - ret = (ret16[1] << 16) | ret16[0]; - - ret8[0] = ret & 0xff; - ret8[1] = (ret >> 8) & 0xff; - ret8[2] = (ret >> 16) & 0xff; - ret8[3] = (ret >> 24) & 0xff; - for (i = 0; i < 4; i++) { - p = io[(port + i) & 0xffff]; + if ((pci_take_over_io & PCI_IO_ON) && (port >= pci_base) && (port < (pci_base + pci_size))) { + ret = pci_type2_readl(port, NULL); + found = 4; + qfound = 1; + } else if ((pci_take_over_io & PCI_IO_DEV0) && (port >= 0xc000) && (port < 0xc100)) { + ret = pci_type2_readl(port, NULL); + found = 4; + qfound = 1; + } else { + p = io[port]; while (p) { q = p->next; - if (p->inb && !p->inw && !p->inl) { - ret8[i] &= p->inb(port + i, p->priv); - found |= 1; + if (p->inl) { + ret &= p->inl(port, p->priv); + found |= 4; qfound++; } p = q; } + + ret16[0] = ret & 0xffff; + ret16[1] = (ret >> 16) & 0xffff; + p = io[port & 0xffff]; + while (p) { + q = p->next; + if (p->inw && !p->inl) { + ret16[0] &= p->inw(port, p->priv); + found |= 2; + qfound++; + } + p = q; + } + + p = io[(port + 2) & 0xffff]; + while (p) { + q = p->next; + if (p->inw && !p->inl) { + ret16[1] &= p->inw(port + 2, p->priv); + found |= 2; + qfound++; + } + p = q; + } + ret = (ret16[1] << 16) | ret16[0]; + + ret8[0] = ret & 0xff; + ret8[1] = (ret >> 8) & 0xff; + ret8[2] = (ret >> 16) & 0xff; + ret8[3] = (ret >> 24) & 0xff; + for (uint8_t i = 0; i < 4; i++) { + p = io[(port + i) & 0xffff]; + while (p) { + q = p->next; + if (p->inb && !p->inw && !p->inl) { + ret8[i] &= p->inb(port + i, p->priv); + found |= 1; + qfound++; + } + p = q; + } + } + ret = (ret8[3] << 24) | (ret8[2] << 16) | (ret8[1] << 8) | ret8[0]; } - ret = (ret8[3] << 24) | (ret8[2] << 16) | (ret8[1] << 8) | ret8[0]; if (amstrad_latch & 0x80000000) { if (port & 0x80) @@ -530,47 +588,58 @@ inl(uint16_t port) void outl(uint16_t port, uint32_t val) { - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; int i = 0; - p = io[port]; - if (p) { - while (p) { - q = p->next; - if (p->outl) { - p->outl(port, val, p->priv); - found |= 4; - qfound++; + if ((pci_take_over_io & PCI_IO_ON) && (port >= pci_base) && (port < (pci_base + pci_size))) { + pci_type2_writel(port, val, NULL); + found = 4; + qfound = 1; + } else if ((pci_take_over_io & PCI_IO_DEV0) && (port >= 0xc000) && (port < 0xc100)) { + pci_type2_writel(port, val, NULL); + found = 4; + qfound = 1; + } else { + p = io[port]; + if (p) { + while (p) { + q = p->next; + if (p->outl) { + p->outl(port, val, p->priv); + found |= 4; + qfound++; + } + p = q; } - p = q; } - } - for (i = 0; i < 4; i += 2) { - p = io[(port + i) & 0xffff]; - while (p) { - q = p->next; - if (p->outw && !p->outl) { - p->outw(port + i, val >> (i << 3), p->priv); - found |= 2; - qfound++; + for (i = 0; i < 4; i += 2) { + p = io[(port + i) & 0xffff]; + while (p) { + q = p->next; + if (p->outw && !p->outl) { + p->outw(port + i, val >> (i << 3), p->priv); + found |= 2; + qfound++; + } + p = q; } - p = q; } - } - for (i = 0; i < 4; i++) { - p = io[(port + i) & 0xffff]; - while (p) { - q = p->next; - if (p->outb && !p->outw && !p->outl) { - p->outb(port + i, val >> (i << 3), p->priv); - found |= 1; - qfound++; + for (i = 0; i < 4; i++) { + p = io[(port + i) & 0xffff]; + while (p) { + q = p->next; + if (p->outb && !p->outw && !p->outl) { + p->outb(port + i, val >> (i << 3), p->priv); + found |= 1; + qfound++; + } + p = q; } - p = q; } } diff --git a/src/ioapic.c b/src/ioapic.c index 7d1a62cca..c3939f249 100644 --- a/src/ioapic.c +++ b/src/ioapic.c @@ -27,8 +27,9 @@ #include <86box/machine.h> #include <86box/mem.h> #include <86box/chipset.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct ioapic_t { uint8_t dummy; } ioapic_t; @@ -51,9 +52,9 @@ ioapic_log(const char *fmt, ...) #endif static void -ioapic_write(uint16_t port, uint8_t val, void *priv) +ioapic_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) { - uint32_t addr, pcmp; + uint32_t pcmp; /* target POST FF, issued by Award before jumping to the bootloader */ if (val != 0xff) @@ -63,7 +64,7 @@ ioapic_write(uint16_t port, uint8_t val, void *priv) /* The _MP_ table must be located in the BIOS area, the EBDA, or the last 1k of conventional memory; at a 16-byte boundary in all cases. Award writes both tables to the BIOS area. */ - for (addr = 0xf0000; addr <= 0xfffff; addr += 16) { + for (uint32_t addr = 0xf0000; addr <= 0xfffff; addr += 16) { /* check signature for the _MP_ table (Floating Point Structure) */ if (mem_readl_phys(addr) != 0x5f504d5f) /* ASCII "_MP_" */ continue; @@ -83,8 +84,9 @@ ioapic_write(uint16_t port, uint8_t val, void *priv) } static void -ioapic_reset(ioapic_t *dev) +ioapic_reset(UNUSED(ioapic_t *dev)) { + // } static void @@ -99,7 +101,7 @@ ioapic_close(void *priv) } static void * -ioapic_init(const device_t *info) +ioapic_init(UNUSED(const device_t *info)) { ioapic_t *dev = (ioapic_t *) malloc(sizeof(ioapic_t)); memset(dev, 0, sizeof(ioapic_t)); diff --git a/src/log.c b/src/log.c index e36ab69f9..b5267d70b 100644 --- a/src/log.c +++ b/src/log.c @@ -35,10 +35,11 @@ #include <86box/log.h> #ifndef RELEASE_BUILD -typedef struct -{ - char buff[1024], *dev_name; - int seen, suppr_seen; +typedef struct log_t { + char buff[1024]; + char *dev_name; + int seen; + int suppr_seen; } log_t; extern FILE *stdlog; /* file to log output to */ @@ -81,7 +82,8 @@ void log_out(void *priv, const char *fmt, va_list ap) { log_t *log = (log_t *) priv; - char temp[1024], fmt2[1024]; + char temp[1024]; + char fmt2[1024]; if (log == NULL) return; @@ -119,7 +121,8 @@ void log_fatal(void *priv, const char *fmt, ...) { log_t *log = (log_t *) priv; - char temp[1024], fmt2[1024]; + char temp[1024]; + char fmt2[1024]; va_list ap; if (log == NULL) diff --git a/src/lpt.c b/src/lpt.c index b20b25641..7eb96a278 100644 --- a/src/lpt.c +++ b/src/lpt.c @@ -80,9 +80,7 @@ lpt_device_get_from_internal_name(char *s) void lpt_devices_init(void) { - int i = 0; - - for (i = 0; i < PARALLEL_MAX; i++) { + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { lpt_ports[i].dt = (lpt_device_t *) lpt_devices[lpt_ports[i].device].device; if (lpt_ports[i].dt && lpt_ports[i].dt->init) @@ -93,10 +91,9 @@ lpt_devices_init(void) void lpt_devices_close(void) { - int i = 0; lpt_port_t *dev; - for (i = 0; i < PARALLEL_MAX; i++) { + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { dev = &lpt_ports[i]; if (lpt_ports[i].dt && lpt_ports[i].dt->close) @@ -127,6 +124,9 @@ lpt_write(uint16_t port, uint8_t val, void *priv) dev->ctrl = val; dev->enable_irq = val & 0x10; break; + + default: + break; } } @@ -157,6 +157,9 @@ lpt_read(uint16_t port, void *priv) else ret = 0xe0 | dev->ctrl | dev->enable_irq; break; + + default: + break; } return ret; @@ -165,7 +168,7 @@ lpt_read(uint16_t port, void *priv) void lpt_irq(void *priv, int raise) { - lpt_port_t *dev = (lpt_port_t *) priv; + const lpt_port_t *dev = (lpt_port_t *) priv; if (dev->enable_irq && (dev->irq != 0xff)) { if (raise) @@ -178,11 +181,10 @@ lpt_irq(void *priv, int raise) void lpt_init(void) { - int i; uint16_t default_ports[PARALLEL_MAX] = { LPT1_ADDR, LPT2_ADDR, LPT_MDA_ADDR, LPT4_ADDR }; uint8_t default_irqs[PARALLEL_MAX] = { LPT1_IRQ, LPT2_IRQ, LPT_MDA_IRQ, LPT4_IRQ }; - for (i = 0; i < PARALLEL_MAX; i++) { + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { lpt_ports[i].addr = 0xffff; lpt_ports[i].irq = 0xff; lpt_ports[i].enable_irq = 0x10; diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index a37427de1..543ebfc11 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -74,6 +74,7 @@ #include <86box/vid_mda.h> #include <86box/machine.h> #include <86box/m_amstrad.h> +#include <86box/plat_unused.h> #define STAT_PARITY 0x80 #define STAT_RTIMEOUT 0x40 @@ -84,60 +85,64 @@ #define STAT_IFULL 0x02 #define STAT_OFULL 0x01 -typedef struct { - rom_t bios_rom; /* 1640 */ - cga_t cga; /* 1640/200 */ - mda_t mda; /* 1512/200/PPC512/640*/ - ega_t ega; /* 1640 */ - uint8_t emulation; /* Which display are we emulating? */ - uint8_t dipswitches; /* DIP switches 1-3 */ - uint8_t crtc_index; /* CRTC index readback - * Bit 7: CGA control port written - * Bit 6: Operation control port written - * Bit 5: CRTC register written - * Bits 0-4: Last CRTC register selected */ - uint8_t operation_ctrl; - uint8_t reg_3df, type; - uint8_t crtc[32]; - int crtcreg; - int cga_enabled; /* 1640 */ - uint8_t cgacol, - cgamode, - stat; - uint8_t plane_write, /* 1512/200 */ - plane_read, /* 1512/200 */ - border, /* 1512/200 */ - invert; /* 512/640 */ - int fontbase; /* 1512/200 */ - int linepos, - displine; - int sc, vc; - int cgadispon; - int con, coff, - cursoron, - cgablink; - int vsynctime; - int fullchange; - int vadj; - uint16_t ma, maback; - int dispon; - int blink; - uint64_t dispontime, /* 1512/1640 */ - dispofftime; /* 1512/1640 */ - pc_timer_t timer; /* 1512/1640 */ - int firstline, - lastline; - uint8_t *vram; - void *ams; +typedef struct amsvid_t { + rom_t bios_rom; /* 1640 */ + cga_t cga; /* 1640/200 */ + mda_t mda; /* 1512/200/PPC512/640*/ + ega_t ega; /* 1640 */ + uint8_t emulation; /* Which display are we emulating? */ + uint8_t dipswitches; /* DIP switches 1-3 */ + uint8_t crtc_index; /* CRTC index readback + * Bit 7: CGA control port written + * Bit 6: Operation control port written + * Bit 5: CRTC register written + * Bits 0-4: Last CRTC register selected */ + uint8_t operation_ctrl; + uint8_t reg_3df; + uint8_t type; + uint8_t crtc[32]; + int crtcreg; + int cga_enabled; /* 1640 */ + uint8_t cgacol; + uint8_t cgamode; + uint8_t stat; + uint8_t plane_write; /* 1512/200 */ + uint8_t plane_read; /* 1512/200 */ + uint8_t border; /* 1512/200 */ + uint8_t invert; /* 512/640 */ + int fontbase; /* 1512/200 */ + int linepos; + int displine; + int sc; + int vc; + int cgadispon; + int con; + int coff; + int cursoron; + int cgablink; + int vsynctime; + int fullchange; + int vadj; + uint16_t ma; + uint16_t maback; + int dispon; + int blink; + uint64_t dispontime; /* 1512/1640 */ + uint64_t dispofftime; /* 1512/1640 */ + pc_timer_t timer; /* 1512/1640 */ + int firstline; + int lastline; + uint8_t *vram; + void *ams; } amsvid_t; -typedef struct { +typedef struct amstrad_t { /* Machine stuff. */ uint8_t dead; - uint8_t stat1, - stat2; - uint8_t type, - language; + uint8_t stat1; + uint8_t stat2; + uint8_t type; + uint8_t language; /* Keyboard stuff. */ int8_t wantirq; @@ -147,8 +152,8 @@ typedef struct { pc_timer_t send_delay_timer; /* Mouse stuff. */ - uint8_t mousex, - mousey; + uint8_t mousex; + uint8_t mousey; int oldb; /* Video stuff. */ @@ -159,8 +164,8 @@ typedef struct { uint32_t amstrad_latch; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; static uint8_t crtc_mask[32] = { 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x7f, 0x7f, 0xf3, 0x1f, 0x7f, 0x1f, 0x3f, 0xff, 0x3f, 0xff, @@ -202,7 +207,9 @@ amstrad_log(const char *fmt, ...) static void recalc_timings_1512(amsvid_t *vid) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; disptime = /*128*/ 114; /*Fixed on PC1512*/ _dispontime = 80; @@ -261,14 +268,17 @@ vid_out_1512(uint16_t addr, uint8_t val, void *priv) case 0x03df: vid->border = val; return; + + default: + return; } } static uint8_t vid_in_1512(uint16_t addr, void *priv) { - amsvid_t *vid = (amsvid_t *) priv; - uint8_t ret = 0xff; + const amsvid_t *vid = (amsvid_t *) priv; + uint8_t ret = 0xff; if ((addr >= 0x3d0) && (addr <= 0x3d7)) addr = (addr & 0xff9) | 0x004; @@ -285,9 +295,12 @@ vid_in_1512(uint16_t addr, void *priv) case 0x03da: ret = vid->stat; break; + + default: + break; } - return (ret); + return ret; } static void @@ -314,7 +327,7 @@ vid_write_1512(uint32_t addr, uint8_t val, void *priv) static uint8_t vid_read_1512(uint32_t addr, void *priv) { - amsvid_t *vid = (amsvid_t *) priv; + const amsvid_t *vid = (amsvid_t *) priv; cycles -= 12; addr &= 0x3fff; @@ -331,9 +344,16 @@ vid_poll_1512(void *priv) amsvid_t *vid = (amsvid_t *) priv; uint16_t ca = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; - uint8_t chr, attr; - uint16_t dat, dat2, dat3, dat4; + int x; + int c; + int xs_temp; + int ys_temp; + uint8_t chr; + uint8_t attr; + uint16_t dat; + uint16_t dat2; + uint16_t dat3; + uint16_t dat4; int cols[4]; int col; int oldsc; @@ -351,25 +371,25 @@ vid_poll_1512(void *priv) vid->lastline = vid->displine; for (c = 0; c < 8; c++) { if ((vid->cgamode & 0x12) == 0x12) { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->border & 15) + 16; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->border & 15) + 16; if (vid->cgamode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; } } else { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->cgacol & 15) + 16; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->cgacol & 15) + 16; if (vid->cgamode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = (vid->cgacol & 15) + 16; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = (vid->cgacol & 15) + 16; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->cgacol & 15) + 16; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->cgacol & 15) + 16; } } } if (vid->cgamode & 1) { for (x = 0; x < 80; x++) { - chr = vid->vram[((vid->ma << 1) & 0x3fff)]; - attr = vid->vram[(((vid->ma << 1) + 1) & 0x3fff)]; + chr = vid->vram[(vid->ma << 1) & 0x3fff]; + attr = vid->vram[((vid->ma << 1) + 1) & 0x3fff]; drawcursor = ((vid->ma == ca) && vid->con && vid->cursoron); if (vid->cgamode & 0x20) { cols[1] = (attr & 15) + 16; @@ -382,19 +402,19 @@ vid_poll_1512(void *priv) } if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } vid->ma++; } } else if (!(vid->cgamode & 2)) { for (x = 0; x < 40; x++) { - chr = vid->vram[((vid->ma << 1) & 0x3fff)]; - attr = vid->vram[(((vid->ma << 1) + 1) & 0x3fff)]; + chr = vid->vram[(vid->ma << 1) & 0x3fff]; + attr = vid->vram[((vid->ma << 1) + 1) & 0x3fff]; drawcursor = ((vid->ma == ca) && vid->con && vid->cursoron); if (vid->cgamode & 0x20) { cols[1] = (attr & 15) + 16; @@ -408,11 +428,11 @@ vid_poll_1512(void *priv) vid->ma++; if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } @@ -436,7 +456,7 @@ vid_poll_1512(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000) + 1]; vid->ma++; for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; dat <<= 2; } } @@ -450,7 +470,7 @@ vid_poll_1512(void *priv) vid->ma++; for (c = 0; c < 16; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = (((dat >> 15) | ((dat2 >> 15) << 1) | ((dat3 >> 15) << 2) | ((dat4 >> 15) << 3)) & (vid->cgacol & 15)) + 16; + buffer32->line[vid->displine << 1][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = (((dat >> 15) | ((dat2 >> 15) << 1) | ((dat3 >> 15) << 2) | ((dat4 >> 15) << 3)) & (vid->cgacol & 15)) + 16; dat <<= 1; dat2 <<= 1; dat3 <<= 1; @@ -771,9 +791,15 @@ vid_out_1640(uint16_t addr, uint8_t val, void *priv) mem_mapping_set_addr(&vid->ega.mapping, 0xb8000, 0x08000); break; + + default: + break; } } return; + + default: + break; } if (vid->cga_enabled) @@ -897,7 +923,8 @@ const device_t vid_1640_device = { extern int nmi_mask; -static uint32_t blue, green; +static uint32_t blue; +static uint32_t green; static uint32_t lcdcols[256][2][2]; @@ -914,6 +941,9 @@ ams_inform(amsvid_t *vid) case PC200_LCDM: video_inform(VIDEO_FLAG_TYPE_MDA, &timing_pc200); break; + + default: + break; } } @@ -980,10 +1010,9 @@ static unsigned char mapping2[256] = { static void set_lcd_cols(uint8_t mode_reg) { - unsigned char *mapping = (mode_reg & 0x80) ? mapping2 : mapping1; - int c; + const unsigned char *mapping = (mode_reg & 0x80) ? mapping2 : mapping1; - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { switch (mapping[c]) { case 0: lcdcols[c][0][0] = lcdcols[c][1][0] = green; @@ -1004,6 +1033,9 @@ set_lcd_cols(uint8_t mode_reg) lcdcols[c][0][0] = lcdcols[c][1][0] = blue; lcdcols[c][0][1] = lcdcols[c][1][1] = blue; break; + + default: + break; } } } @@ -1027,13 +1059,16 @@ vid_in_200(uint16_t addr, void *priv) ret = vid->crtc_index; /* Read NMI reason */ vid->crtc_index &= 0x1f; /* Reset NMI reason */ nmi = 0; /* And reset NMI flag */ - return (ret); + return ret; case 0x03de: return ((vid->operation_ctrl & 0xc7) | vid->dipswitches); /*External CGA*/ case 0x03df: return (vid->reg_3df); + + default: + break; } if (addr >= 0x3D0 && addr <= 0x3DF) @@ -1167,6 +1202,9 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) mem_mapping_enable(&vid->cga.mapping); } return; + + default: + break; } if (addr >= 0x3D0 && addr <= 0x3DF) @@ -1216,7 +1254,6 @@ lcd_draw_char_40(amsvid_t *vid, uint32_t *buffer, uint8_t chr, uint8_t attr, int drawcursor, int blink, int sc, uint8_t control) { - int c; uint8_t bits = fontdat[chr + vid->cga.fontbase][sc]; uint8_t mask = 0x80; @@ -1225,7 +1262,7 @@ lcd_draw_char_40(amsvid_t *vid, uint32_t *buffer, uint8_t chr, if (drawcursor) bits ^= 0xFF; - for (c = 0; c < 8; c++, mask >>= 1) { + for (uint8_t c = 0; c < 8; c++, mask >>= 1) { if (control & 0x20) { buffer[c * 2] = buffer[c * 2 + 1] = lcdcols[attr & 0x7F][blink][(bits & mask) ? 1 : 0]; } else { @@ -1242,7 +1279,8 @@ lcdm_poll(amsvid_t *vid) int drawcursor; int x; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int oldsc; int blink; @@ -1263,7 +1301,7 @@ lcdm_poll(amsvid_t *vid) drawcursor = ((mda->ma == ca) && mda->con && mda->cursoron); blink = ((mda->blink & 16) && (mda->ctrl & 0x20) && (attr & 0x80) && !drawcursor); - lcd_draw_char_80(vid, &((uint32_t *) (buffer32->line[mda->displine]))[x * 8], chr, attr, drawcursor, blink, mda->sc, 0, mda->ctrl); + lcd_draw_char_80(vid, &((buffer32->line[mda->displine]))[x * 8], chr, attr, drawcursor, blink, mda->sc, 0, mda->ctrl); mda->ma++; } } @@ -1351,7 +1389,7 @@ lcdm_poll(amsvid_t *vid) mda->sc &= 31; mda->ma = mda->maback; } - if ((mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1)))) + if (mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1))) mda->con = 1; } } @@ -1361,9 +1399,12 @@ lcdc_poll(amsvid_t *vid) { cga_t *cga = &vid->cga; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t dat; int oldsc; uint16_t ca; @@ -1391,17 +1432,17 @@ lcdc_poll(amsvid_t *vid) attr = cga->charbuffer[(x << 1) + 1]; drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron); blink = ((cga->cgablink & 16) && (cga->cgamode & 0x20) && (attr & 0x80) && !drawcursor); - lcd_draw_char_80(vid, &(buffer32->line[(cga->displine << 1)])[x * 8], chr, attr, drawcursor, blink, cga->sc, cga->cgamode & 0x40, cga->cgamode); + lcd_draw_char_80(vid, &(buffer32->line[cga->displine << 1])[x * 8], chr, attr, drawcursor, blink, cga->sc, cga->cgamode & 0x40, cga->cgamode); lcd_draw_char_80(vid, &(buffer32->line[(cga->displine << 1) + 1])[x * 8], chr, attr, drawcursor, blink, cga->sc, cga->cgamode & 0x40, cga->cgamode); cga->ma++; } } else if (!(cga->cgamode & 2)) { for (x = 0; x < cga->crtc[1]; x++) { - chr = cga->vram[((cga->ma << 1) & 0x3fff)]; - attr = cga->vram[(((cga->ma << 1) + 1) & 0x3fff)]; + chr = cga->vram[(cga->ma << 1) & 0x3fff]; + attr = cga->vram[((cga->ma << 1) + 1) & 0x3fff]; drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron); blink = ((cga->cgablink & 16) && (cga->cgamode & 0x20) && (attr & 0x80) && !drawcursor); - lcd_draw_char_40(vid, &(buffer32->line[(cga->displine << 1)])[x * 16], chr, attr, drawcursor, blink, cga->sc, cga->cgamode); + lcd_draw_char_40(vid, &(buffer32->line[cga->displine << 1])[x * 16], chr, attr, drawcursor, blink, cga->sc, cga->cgamode); lcd_draw_char_40(vid, &(buffer32->line[(cga->displine << 1) + 1])[x * 16], chr, attr, drawcursor, blink, cga->sc, cga->cgamode); cga->ma++; } @@ -1409,8 +1450,8 @@ lcdc_poll(amsvid_t *vid) for (x = 0; x < cga->crtc[1]; x++) { dat = (cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000)] << 8) | cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000) + 1]; cga->ma++; - for (c = 0; c < 16; c++) { - buffer32->line[(cga->displine << 1)][(x << 4) + c] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + c] = (dat & 0x8000) ? blue : green; + for (uint8_t c = 0; c < 16; c++) { + buffer32->line[cga->displine << 1][(x << 4) + c] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + c] = (dat & 0x8000) ? blue : green; dat <<= 1; } } @@ -1546,19 +1587,19 @@ lcdc_poll(amsvid_t *vid) } if (cga->cgadispon) cga->cgastat &= ~1; - if ((cga->sc == (cga->crtc[10] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[10] & 31) >> 1)))) + if (cga->sc == (cga->crtc[10] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[10] & 31) >> 1))) cga->con = 1; if (cga->cgadispon && (cga->cgamode & 1)) { for (x = 0; x < (cga->crtc[1] << 1); x++) - cga->charbuffer[x] = cga->vram[(((cga->ma << 1) + x) & 0x3fff)]; + cga->charbuffer[x] = cga->vram[((cga->ma << 1) + x) & 0x3fff]; } } } static void -vid_poll_200(void *p) +vid_poll_200(void *priv) { - amsvid_t *vid = (amsvid_t *) p; + amsvid_t *vid = (amsvid_t *) priv; switch (vid->emulation) { case PC200_LCDM: @@ -1567,6 +1608,9 @@ vid_poll_200(void *p) case PC200_LCDC: lcdc_poll(vid); return; + + default: + break; } } @@ -1602,6 +1646,9 @@ vid_init_200(amstrad_t *ams) break; /* The other combination is 'IDA disabled' (0x20) - see * m_amstrad.c */ + + default: + break; } else switch (vid->emulation) { @@ -1623,6 +1670,9 @@ vid_init_200(amstrad_t *ams) case PC200_LCDM: vid->dipswitches = 0x10; break; + + default: + break; } cga = &vid->cga; @@ -1957,7 +2007,7 @@ const device_t vid_pc3086_device = { }; static void -ms_write(uint16_t addr, uint8_t val, void *priv) +ms_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { amstrad_t *ams = (amstrad_t *) priv; @@ -1981,11 +2031,11 @@ ms_read(uint16_t addr, void *priv) ams->mousey = 0; } - return (ret); + return ret; } static int -ms_poll(int x, int y, int z, int b, void *priv) +ms_poll(int x, int y, UNUSED(int z), int b, void *priv) { amstrad_t *ams = (amstrad_t *) priv; @@ -2004,7 +2054,7 @@ ms_poll(int x, int y, int z, int b, void *priv) ams->oldb = b; - return (0); + return 0; } static void @@ -2172,7 +2222,7 @@ kbd_read(uint16_t port, void *priv) amstrad_log("AMDkb: bad keyboard read %04X\n", port); } - return (ret); + return ret; } static void @@ -2210,6 +2260,9 @@ ams_write(uint16_t port, uint8_t val, void *priv) case 0xdead: ams->dead = val; break; + + default: + break; } } @@ -2273,6 +2326,9 @@ ams_read(uint16_t port, void *priv) case AMSTRAD_SW10: ret |= 0x20; break; + + default: + break; } break; @@ -2288,9 +2344,12 @@ ams_read(uint16_t port, void *priv) case 0xdead: ret = ams->dead; break; + + default: + break; } - return (ret); + return ret; } static const scancode scancode_pc200[512] = { @@ -2470,6 +2529,9 @@ machine_amstrad_init(const machine_t *model, int type) case AMS_PC3086: ams->fdc = device_add(&fdc_at_actlow_device); break; + + default: + break; } ams->language = 7; @@ -2527,6 +2589,9 @@ machine_amstrad_init(const machine_t *model, int type) device_context_restore(); device_add(¶dise_pvga1a_pc3086_device); break; + + default: + break; } else if ((type == AMS_PC200) || (type == AMS_PPC512)) io_sethandler(0x03de, 1, diff --git a/src/machine/m_at.c b/src/machine/m_at.c index 92f8c0f5f..9fc53ebcd 100644 --- a/src/machine/m_at.c +++ b/src/machine/m_at.c @@ -246,7 +246,14 @@ machine_at_siemens_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_ibm_common_init(model); + machine_at_common_init_ex(model, 1); + + device_add(&keyboard_at_siemens_device); + + mem_remap_top(384); + + if (fdc_type == FDC_INTERNAL) + device_add(&fdc_at_device); return ret; } diff --git a/src/machine/m_at_286_386sx.c b/src/machine/m_at_286_386sx.c index 54e7d6b9e..fb87c9976 100644 --- a/src/machine/m_at_286_386sx.c +++ b/src/machine/m_at_286_386sx.c @@ -807,10 +807,6 @@ machine_at_pc8_init(const machine_t *model) return ret; } -/* - * Current bugs: - * - ctrl-alt-del produces an 8042 error - */ int machine_at_3302_init(const machine_t *model) { @@ -820,8 +816,8 @@ machine_at_3302_init(const machine_t *model) 0x000f0000, 65536, 0); if (ret) { - bios_load_aux_linear("roms/machines/3302/f800-setup_ncr3.5-013190.bin", - 0x000f8000, 32768, 0); + ret &= bios_load_aux_linear("roms/machines/3302/f800-setup_ncr3.5-013190.bin", + 0x000f8000, 32768, 0); } if (bios_only || !ret) diff --git a/src/machine/m_at_386dx_486.c b/src/machine/m_at_386dx_486.c index 0ee7b51a2..3f37c13c4 100644 --- a/src/machine/m_at_386dx_486.c +++ b/src/machine/m_at_386dx_486.c @@ -48,6 +48,7 @@ #include <86box/scsi_ncr53c8xx.h> #include <86box/hwm.h> #include <86box/machine.h> +#include <86box/plat_unused.h> int machine_at_acc386_init(const machine_t *model) @@ -220,7 +221,7 @@ machine_at_spc6000a_init(const machine_t *model) if (fdc_type == FDC_INTERNAL) device_add(&fdc_at_device); - device_add(&keyboard_at_samsung_device); + device_add(&keyboard_at_ami_device); return ret; } @@ -404,7 +405,7 @@ machine_at_acerv10_init(const machine_t *model) machine_at_common_init(model); device_add(&sis_85c461_device); - device_add(&keyboard_ps2_ami_pci_device); + device_add(&keyboard_ps2_acer_pci_device); device_add(&ide_isa_2ch_device); if (fdc_type == FDC_INTERNAL) @@ -812,7 +813,7 @@ machine_at_greenb_init(const machine_t *model) } static void -machine_at_sis_85c496_common_init(const machine_t *model) +machine_at_sis_85c496_common_init(UNUSED(const machine_t *model)) { device_add(&ide_pci_2ch_device); @@ -1281,7 +1282,9 @@ machine_at_abpb4_init(const machine_t *model) device_add(&ali1489_device); device_add(&w83787f_device); device_add(&keyboard_at_device); - // device_add(&intel_flash_bxt_device); +#if 0 + device_add(&intel_flash_bxt_device); +#endif device_add(&sst_flash_29ee010_device); return ret; @@ -1593,10 +1596,8 @@ machine_at_hot433_init(const machine_t *model) device_add(&umc_hb4_device); device_add(&umc_8886af_device); device_add(&um8669f_device); - // device_add(&intel_flash_bxt_device); - device_add(&sst_flash_29ee010_device); - // device_add(&keyboard_at_ami_device); - device_add(&keyboard_ps2_ami_device); + device_add(&winbond_flash_w29c010_device); + device_add(&keyboard_at_ami_device); return ret; } @@ -1657,7 +1658,7 @@ machine_at_actionpc2600_init(const machine_t *model) device_add(&umc_8886af_device); device_add(&um8669f_device); device_add(&intel_flash_bxt_device); - device_add(&keyboard_at_ami_device); + device_add(&keyboard_ps2_tg_ami_device); return ret; } @@ -1782,7 +1783,7 @@ machine_at_tg486gp_init(const machine_t *model) device_add(&ali1435_device); device_add(&sst_flash_29ee010_device); - device_add(&keyboard_ps2_ami_device); + device_add(&keyboard_ps2_tg_ami_device); return ret; } @@ -1797,16 +1798,19 @@ machine_at_tg486g_init(const machine_t *model) if (bios_only || !ret) return ret; - else { - mem_mapping_set_addr(&bios_mapping, 0x0c0000, 0x40000); - mem_mapping_set_exec(&bios_mapping, rom); - } machine_at_common_init(model); device_add(&sis_85c471_device); device_add(&ide_isa_device); device_add(&fdc37c651_ide_device); - device_add(&keyboard_ps2_intel_ami_pci_device); + device_add(&keyboard_ps2_tg_ami_pci_device); + + if (gfxcard[0] != VID_INTERNAL) { + for (uint16_t i = 0; i < 32768; i++) + rom[i] = mem_readb_phys(0x000c0000 + i); + } + mem_mapping_set_addr(&bios_mapping, 0x0c0000, 0x40000); + mem_mapping_set_exec(&bios_mapping, rom); return ret; } diff --git a/src/machine/m_at_commodore.c b/src/machine/m_at_commodore.c index 3587db44a..a0b522371 100644 --- a/src/machine/m_at_commodore.c +++ b/src/machine/m_at_commodore.c @@ -52,11 +52,12 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/machine.h> +#include <86box/plat_unused.h> static serial_t *cmd_uart; static void -cbm_io_write(uint16_t port, uint8_t val, void *p) +cbm_io_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) { lpt1_remove(); lpt2_remove(); @@ -71,6 +72,9 @@ cbm_io_write(uint16_t port, uint8_t val, void *p) case 3: lpt1_init(LPT2_ADDR); break; + + default: + break; } switch (val & 0xc) { @@ -80,6 +84,9 @@ cbm_io_write(uint16_t port, uint8_t val, void *p) case 0x8: serial_setup(cmd_uart, COM1_ADDR, COM1_IRQ); break; + + default: + break; } } diff --git a/src/machine/m_at_compaq.c b/src/machine/m_at_compaq.c index e74261b8a..0731aa810 100644 --- a/src/machine/m_at_compaq.c +++ b/src/machine/m_at_compaq.c @@ -31,6 +31,7 @@ #include <86box/mem.h> #include <86box/rom.h> #include <86box/device.h> +#include <86box/keyboard.h> #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/fdc_ext.h> @@ -40,25 +41,33 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> + + +static video_timings_t timing_compaq_plasma = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; enum { COMPAQ_PORTABLEII = 0, COMPAQ_PORTABLEIII, COMPAQ_PORTABLEIII386, - COMPAQ_DESKPRO386 + COMPAQ_DESKPRO386, + COMPAQ_DESKPRO386_01_1988 }; #define CGA_RGB 0 #define CGA_COMPOSITE 1 -#define COMPOSITE_OLD 0 -#define COMPOSITE_NEW 1 - /*Very rough estimate*/ #define VID_CLOCK (double) (651 * 416 * 60) +static uint8_t cga_crtcmask[32] = { + 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x7f, 0x7f, 0xf3, 0x1f, 0x7f, 0x1f, 0x3f, 0xff, 0x3f, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + /* Mapping of attributes to colours */ -static uint32_t amber, black; +static uint32_t amber; +static uint32_t black; static uint32_t blinkcols[256][2]; static uint32_t normcols[256][2]; @@ -71,6 +80,8 @@ static uint32_t normcols[256][2]; */ static int8_t cpq_st_display_internal = -1; +static uint8_t mdaattr[256][2][2]; + static void compaq_plasma_display_set(uint8_t internal) { @@ -84,21 +95,13 @@ compaq_plasma_display_get(void) } typedef struct compaq_plasma_t { - mem_mapping_t plasma_mapping; cga_t cga; uint8_t port_23c6; uint8_t internal_monitor; - uint8_t attrmap; /* Attribute mapping register */ - int linepos, displine; - uint8_t *vram; - uint64_t dispontime, dispofftime; - int dispon, fullchange; + uint8_t attrmap; } compaq_plasma_t; -static uint8_t cga_crtcmask[32] = { - 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x7f, 0x7f, 0xf3, 0x1f, 0x7f, 0x1f, 0x3f, 0xff, 0x3f, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; +static int compaq_machine_type = 0; /* Compaq Deskpro 386 remaps RAM from 0xA0000-0xFFFFF to 0xFA0000-0xFFFFFF */ static mem_mapping_t ram_mapping; @@ -108,7 +111,9 @@ static void compaq_plasma_recalcattrs(compaq_plasma_t *self); static void compaq_plasma_recalctimings(compaq_plasma_t *self) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; if (!self->internal_monitor && !(self->port_23c6 & 1)) { cga_recalctimings(&self->cga); @@ -118,8 +123,18 @@ compaq_plasma_recalctimings(compaq_plasma_t *self) disptime = 651; _dispontime = 640; _dispofftime = disptime - _dispontime; - self->dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); - self->dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); + self->cga.dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); + self->cga.dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); +} + +static void +compaq_plasma_waitstates(UNUSED(void *priv)) +{ + int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; + int ws; + + ws = ws_array[cycles & 0xf]; + sub_cycles(ws); } static void @@ -127,7 +142,8 @@ compaq_plasma_write(uint32_t addr, uint8_t val, void *priv) { compaq_plasma_t *self = (compaq_plasma_t *) priv; - self->vram[addr & 0x7fff] = val; + self->cga.vram[addr & 0x7fff] = val; + compaq_plasma_waitstates(&self->cga); } static uint8_t @@ -136,204 +152,12 @@ compaq_plasma_read(uint32_t addr, void *priv) compaq_plasma_t *self = (compaq_plasma_t *) priv; uint8_t ret; - ret = (self->vram[addr & 0x7fff]); + compaq_plasma_waitstates(&self->cga); + ret = (self->cga.vram[addr & 0x7fff]); return ret; } -/* Draw a row of text in 80-column mode */ -static void -compaq_plasma_text80(compaq_plasma_t *self) -{ - uint32_t cols[2]; - int x, c; - uint8_t chr, attr; - int drawcursor; - int cursorline; - int blink; - uint16_t addr; - uint8_t sc; - uint16_t ma = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x7fff; - uint16_t ca = (self->cga.crtc[15] | (self->cga.crtc[14] << 8)) & 0x7fff; - - sc = (self->displine) & 15; - addr = ((ma & ~1) + (self->displine >> 4) * 80) * 2; - ma += (self->displine >> 4) * 80; - - if ((self->cga.crtc[10] & 0x60) == 0x20) - cursorline = 0; - else - cursorline = ((self->cga.crtc[10] & 0x0F) * 2 <= sc) && ((self->cga.crtc[11] & 0x0F) * 2 >= sc); - - for (x = 0; x < 80; x++) { - chr = self->vram[(addr + 2 * x) & 0x7FFF]; - attr = self->vram[(addr + 2 * x + 1) & 0x7FFF]; - drawcursor = ((ma == ca) && cursorline && (self->cga.cgamode & 8) && (self->cga.cgablink & 16)); - - blink = ((self->cga.cgablink & 16) && (self->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); - - if (self->cga.cgamode & 0x20) { /* Blink */ - cols[1] = blinkcols[attr][1]; - cols[0] = blinkcols[attr][0]; - if (blink) - cols[1] = cols[0]; - } else { - cols[1] = normcols[attr][1]; - cols[0] = normcols[attr][0]; - } - if (drawcursor) { - for (c = 0; c < 8; c++) - ((uint32_t *) buffer32->line[self->displine])[(x << 3) + c] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); - } else { - for (c = 0; c < 8; c++) - ((uint32_t *) buffer32->line[self->displine])[(x << 3) + c] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0]; - } - ++ma; - } -} - -/* Draw a row of text in 40-column mode */ -static void -compaq_plasma_text40(compaq_plasma_t *self) -{ - uint32_t cols[2]; - int x, c; - uint8_t chr, attr; - int drawcursor; - int cursorline; - int blink; - uint16_t addr; - uint8_t sc; - uint16_t ma = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x7fff; - uint16_t ca = (self->cga.crtc[15] | (self->cga.crtc[14] << 8)) & 0x7fff; - - sc = (self->displine) & 15; - addr = ((ma & ~1) + (self->displine >> 4) * 40) * 2; - ma += (self->displine >> 4) * 40; - - if ((self->cga.crtc[10] & 0x60) == 0x20) - cursorline = 0; - else - cursorline = ((self->cga.crtc[10] & 0x0F) * 2 <= sc) && ((self->cga.crtc[11] & 0x0F) * 2 >= sc); - - for (x = 0; x < 40; x++) { - chr = self->vram[(addr + 2 * x) & 0x7FFF]; - attr = self->vram[(addr + 2 * x + 1) & 0x7FFF]; - drawcursor = ((ma == ca) && cursorline && (self->cga.cgamode & 8) && (self->cga.cgablink & 16)); - - blink = ((self->cga.cgablink & 16) && (self->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); - - if (self->cga.cgamode & 0x20) { /* Blink */ - cols[1] = blinkcols[attr][1]; - cols[0] = blinkcols[attr][0]; - if (blink) - cols[1] = cols[0]; - } else { - cols[1] = normcols[attr][1]; - cols[0] = normcols[attr][0]; - } - if (drawcursor) { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[self->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[self->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); - } - } else { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[self->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[self->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0]; - } - } - ++ma; - } -} - -/* Draw a line in CGA 640x200 or Compaq Plasma 640x400 mode */ -static void -compaq_plasma_cgaline6(compaq_plasma_t *self) -{ - int x, c; - uint8_t dat; - uint32_t ink = 0; - uint16_t addr; - uint32_t fg = (self->cga.cgacol & 0x0F) ? amber : black; - uint32_t bg = black; - - uint16_t ma = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x7fff; - - if ((self->cga.crtc[9] == 3) || (self->port_23c6 & 1)) /* 640*400 */ { - addr = ((self->displine) & 1) * 0x2000 + ((self->displine >> 1) & 1) * 0x4000 + (self->displine >> 2) * 80 + ((ma & ~1) << 1); - } else { - addr = ((self->displine >> 1) & 1) * 0x2000 + (self->displine >> 2) * 80 + ((ma & ~1) << 1); - } - for (x = 0; x < 80; x++) { - dat = self->vram[(addr & 0x7FFF)]; - addr++; - - for (c = 0; c < 8; c++) { - ink = (dat & 0x80) ? fg : bg; - if (!(self->cga.cgamode & 8)) - ink = black; - ((uint32_t *) buffer32->line[self->displine])[x * 8 + c] = ink; - dat <<= 1; - } - } -} - -/* Draw a line in CGA 320x200 mode. Here the CGA colours are converted to - * dither patterns: colour 1 to 25% grey, colour 2 to 50% grey */ -static void -compaq_plasma_cgaline4(compaq_plasma_t *self) -{ - int x, c; - uint8_t dat, pattern; - uint32_t ink0 = 0, ink1 = 0; - uint16_t addr; - - uint16_t ma = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x7fff; - - /* 320*200 */ - addr = ((self->displine >> 1) & 1) * 0x2000 + (self->displine >> 2) * 80 + ((ma & ~1) << 1); - - for (x = 0; x < 80; x++) { - dat = self->vram[(addr & 0x7FFF)]; - addr++; - - for (c = 0; c < 4; c++) { - pattern = (dat & 0xC0) >> 6; - if (!(self->cga.cgamode & 8)) - pattern = 0; - - switch (pattern & 3) { - case 0: - ink0 = ink1 = black; - break; - case 1: - if (self->displine & 1) { - ink0 = black; - ink1 = black; - } else { - ink0 = amber; - ink1 = black; - } - break; - case 2: - if (self->displine & 1) { - ink0 = black; - ink1 = amber; - } else { - ink0 = amber; - ink1 = black; - } - break; - case 3: - ink0 = ink1 = amber; - break; - } - ((uint32_t *) buffer32->line[self->displine])[x * 8 + 2 * c] = ink0; - ((uint32_t *) buffer32->line[self->displine])[x * 8 + 2 * c + 1] = ink1; - dat <<= 2; - } - } -} - static void compaq_plasma_out(uint16_t addr, uint8_t val, void *priv) { @@ -343,7 +167,7 @@ compaq_plasma_out(uint16_t addr, uint8_t val, void *priv) switch (addr) { /* Emulated CRTC, register select */ case 0x3d4: - self->cga.crtcreg = val & 31; + cga_out(addr, val, &self->cga); break; /* Emulated CRTC, value */ @@ -361,33 +185,29 @@ compaq_plasma_out(uint16_t addr, uint8_t val, void *priv) if (old != val) { if (self->cga.crtcreg < 0xe || self->cga.crtcreg > 0x10) { - self->fullchange = changeframecount; + self->cga.fullchange = changeframecount; compaq_plasma_recalctimings(self); } } break; - case 0x3d8: - self->cga.cgamode = val; - break; - case 0x3d9: - self->cga.cgacol = val; + cga_out(addr, val, &self->cga); break; case 0x13c6: - if (val & 8) - compaq_plasma_display_set(1); - else - compaq_plasma_display_set(0); + compaq_plasma_display_set((val & 8) ? 1 : 0); break; case 0x23c6: self->port_23c6 = val; if (val & 8) /* Disable internal CGA */ - mem_mapping_disable(&self->plasma_mapping); + mem_mapping_disable(&self->cga.mapping); else - mem_mapping_enable(&self->plasma_mapping); + mem_mapping_enable(&self->cga.mapping); + break; + + default: break; } } @@ -400,31 +220,41 @@ compaq_plasma_in(uint16_t addr, void *priv) switch (addr) { case 0x3d4: - ret = self->cga.crtcreg; + case 0x3da: + ret = cga_in(addr, &self->cga); break; case 0x3d5: if (self->cga.crtcreg == 0x12) { - ret = self->attrmap & 0x0F; + ret = self->attrmap & 0x0f; if (self->internal_monitor) ret |= 0x30; /* Plasma / CRT */ } else - ret = self->cga.crtc[self->cga.crtcreg]; - break; - - case 0x3da: - ret = self->cga.cgastat; + ret = cga_in(addr, &self->cga); break; case 0x13c6: - if (compaq_plasma_display_get()) - ret = 8; - else - ret = 0; + ret = compaq_plasma_display_get() ? 8 : 0; + ret |= 4; + break; + + case 0x1bc6: + ret = 0; + if (compaq_plasma_display_get()) { + if ((self->cga.cgamode & 0x12) == 0x12) { + if (self->port_23c6 & 8) + ret |= 0x40; + else + ret |= 0x20; + } + } break; case 0x23c6: - ret = self->port_23c6; + ret = 0; + break; + + default: break; } @@ -432,59 +262,250 @@ compaq_plasma_in(uint16_t addr, void *priv) } static void -compaq_plasma_poll(void *p) +compaq_plasma_poll(void *priv) { - compaq_plasma_t *self = (compaq_plasma_t *) p; + compaq_plasma_t *self = (compaq_plasma_t *) priv; + uint8_t chr; + uint8_t attr; + uint8_t sc; + uint16_t ma = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x7fff; + uint16_t ca = (self->cga.crtc[15] | (self->cga.crtc[14] << 8)) & 0x7fff; + uint16_t addr; + int drawcursor; + int cursorline; + int blink = 0; + int underline = 0; + uint32_t ink = 0; + uint32_t fg = (self->cga.cgacol & 0x0f) ? amber : black; + uint32_t bg = black; + uint32_t cols[2]; + uint8_t dat2; + uint8_t pattern; + uint32_t ink0 = 0; + uint32_t ink1 = 0; /* Switch between internal plasma and external CRT display. */ - if (cpq_st_display_internal != -1 && cpq_st_display_internal != self->internal_monitor) { + if ((cpq_st_display_internal != -1) && (cpq_st_display_internal != self->internal_monitor)) { self->internal_monitor = cpq_st_display_internal; compaq_plasma_recalctimings(self); } + /* graphic mode and not mode 40h */ if (!self->internal_monitor && !(self->port_23c6 & 1)) { cga_poll(&self->cga); return; } - if (!self->linepos) { - timer_advance_u64(&self->cga.timer, self->dispofftime); + /* mode 40h or text mode */ + if (!self->cga.linepos) { + timer_advance_u64(&self->cga.timer, self->cga.dispofftime); self->cga.cgastat |= 1; - self->linepos = 1; - if (self->dispon) { - if (self->displine == 0) + self->cga.linepos = 1; + if (self->cga.cgadispon) { + if (self->cga.displine == 0) { video_wait_for_buffer(); + } + if (self->cga.cgamode & 2) { + if (self->cga.cgamode & 0x10) { + /* 640x400 mode */ + if (self->port_23c6 & 1) /* 640*400 */ { + addr = ((self->cga.displine) & 1) * 0x2000 + ((self->cga.displine >> 1) & 1) * 0x4000 + (self->cga.displine >> 2) * 80 + ((ma & ~1) << 1); + } else { + addr = ((self->cga.displine >> 1) & 1) * 0x2000 + (self->cga.displine >> 2) * 80 + ((ma & ~1) << 1); + } + for (uint8_t x = 0; x < 80; x++) { + dat2 = self->cga.vram[addr & 0x7FFF]; + addr++; - /* Graphics */ - if (self->cga.cgamode & 0x02) { - if (self->cga.cgamode & 0x10) - compaq_plasma_cgaline6(self); + for (uint8_t c = 0; c < 8; c++) { + ink = (dat2 & 0x80) ? fg : bg; + if (!(self->cga.cgamode & 8)) + ink = black; + (buffer32->line[self->cga.displine])[x * 8 + c] = ink; + dat2 <<= 1; + } + } + } else { + addr = ((self->cga.displine >> 1) & 1) * 0x2000 + (self->cga.displine >> 2) * 80 + ((ma & ~1) << 1); + for (uint8_t x = 0; x < 80; x++) { + dat2 = self->cga.vram[addr & 0x7fff]; + addr++; + + for (uint8_t c = 0; c < 4; c++) { + pattern = (dat2 & 0xC0) >> 6; + if (!(self->cga.cgamode & 8)) + pattern = 0; + + switch (pattern & 3) { + case 0: + ink0 = ink1 = black; + break; + case 1: + if (self->cga.displine & 1) { + ink0 = black; + ink1 = black; + } else { + ink0 = amber; + ink1 = black; + } + break; + case 2: + if (self->cga.displine & 1) { + ink0 = black; + ink1 = amber; + } else { + ink0 = amber; + ink1 = black; + } + break; + case 3: + ink0 = ink1 = amber; + break; + + default: + break; + } + buffer32->line[self->cga.displine][x * 8 + 2 * c] = ink0; + buffer32->line[self->cga.displine][x * 8 + 2 * c + 1] = ink1; + dat2 <<= 2; + } + } + } + } else if (self->cga.cgamode & 1) { + /* 80-col */ + sc = self->cga.displine & 0x0f; + addr = ((ma & ~1) + (self->cga.displine >> 4) * 80) * 2; + ma += (self->cga.displine >> 4) * 80; + + if ((self->cga.crtc[0x0a] & 0x60) == 0x20) + cursorline = 0; else - compaq_plasma_cgaline4(self); - } else if (self->cga.cgamode & 0x01) /* High-res text */ - compaq_plasma_text80(self); - else - compaq_plasma_text40(self); + cursorline = ((self->cga.crtc[0x0a] & 0x0f) * 2 <= sc) && ((self->cga.crtc[0x0b] & 0x0F) * 2 >= sc); + + /* for each text column */ + for (uint8_t x = 0; x < 80; x++) { + /* video output enabled */ + if (self->cga.cgamode & 8) { + chr = self->cga.vram[(addr + 2 * x) & 0x7fff]; + attr = self->cga.vram[(addr + 2 * x + 1) & 0x7fff]; + } else + chr = attr = 0; + /* check if cursor has to be drawn */ + drawcursor = ((ma == ca) && cursorline && self->cga.cursoron); + underline = ((self->port_23c6 & 0x40) && (attr & 0x1) && !(attr & 0x6)); + if (underline) { + /* set forecolor to white */ + attr |= 7; + } + blink = 0; + /* blink active */ + if (self->cga.cgamode & 0x20) { + cols[1] = blinkcols[attr][1]; + cols[0] = blinkcols[attr][0]; + /* attribute 7 active and not cursor */ + if ((self->cga.cgablink & 8) && (attr & 0x80) && !self->cga.drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + blink = 1; + } + } else { + /* Set intensity bit */ + cols[1] = normcols[attr][1]; + cols[0] = normcols[attr][0]; + blink = (attr & 0x80) * 8 + 7 + 16; + } + /* character underline active and 7th row of pixels in character height being drawn */ + if (underline && (sc == 7)) { + /* for each pixel in character width */ + for (uint8_t c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (uint8_t c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(fontdatm[chr + self->cga.fontbase][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + } else { + for (uint8_t c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(fontdatm[chr + self->cga.fontbase][sc] & (1 << (c ^ 7))) ? 1 : 0]; + } + + ++ma; + } + } else { /* 40-col */ + sc = self->cga.displine & 0x0f; + addr = ((ma & ~1) + (self->cga.displine >> 4) * 40) * 2; + ma += (self->cga.displine >> 4) * 40; + + if ((self->cga.crtc[0x0a] & 0x60) == 0x20) + cursorline = 0; + else + cursorline = ((self->cga.crtc[0x0a] & 0x0f) * 2 <= sc) && ((self->cga.crtc[0x0b] & 0x0F) * 2 >= sc); + + for (uint8_t x = 0; x < 40; x++) { + if (self->cga.cgamode & 8) { + chr = self->cga.vram[(addr + 2 * x) & 0x7fff]; + attr = self->cga.vram[(addr + 2 * x + 1) & 0x7fff]; + } else { + chr = attr = 0; + } + drawcursor = ((ma == ca) && cursorline && self->cga.cursoron); + underline = ((self->port_23c6 & 0x40) && (attr & 0x1) && !(attr & 0x6)); + if (underline) { + /* set forecolor to white */ + attr |= 7; + } + blink = 0; + /* blink active */ + if (self->cga.cgamode & 0x20) { + cols[1] = blinkcols[attr][1]; + cols[0] = blinkcols[attr][0]; + /* attribute 7 active and not cursor */ + if ((self->cga.cgablink & 8) && (attr & 0x80) && !self->cga.drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + blink = 1; + } + } else { + /* Set intensity bit */ + cols[1] = normcols[attr][1]; + cols[0] = normcols[attr][0]; + blink = (attr & 0x80) * 8 + 7 + 16; + } + /* character underline active and 7th row of pixels in character height being drawn */ + if (underline && (sc == 7)) { + /* for each pixel in character width */ + for (uint8_t c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c * 2)] = buffer32->line[self->cga.displine][(x << 4) + (c * 2) + 1] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[self->cga.displine][(x << 4) + c * 2] = buffer32->line[self->cga.displine][(x << 4) + c * 2 + 1] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + } + } else { + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[self->cga.displine][(x << 4) + c * 2] = buffer32->line[self->cga.displine][(x << 4) + c * 2 + 1] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0]; + } + } + ++ma; + } + } } - self->displine++; + self->cga.displine++; /* Hardcode a fixed refresh rate and VSYNC timing */ - if (self->displine == 400) { /* Start of VSYNC */ + if (self->cga.displine == 400) { /* Start of VSYNC */ self->cga.cgastat |= 8; - self->dispon = 0; + self->cga.cgadispon = 0; } - if (self->displine == 416) { /* End of VSYNC */ - self->displine = 0; + if (self->cga.displine == 416) { /* End of VSYNC */ + self->cga.displine = 0; self->cga.cgastat &= ~8; - self->dispon = 1; + self->cga.cgadispon = 1; } } else { - if (self->dispon) + if (self->cga.cgadispon) self->cga.cgastat &= ~1; - timer_advance_u64(&self->cga.timer, self->dispontime); - self->linepos = 0; + timer_advance_u64(&self->cga.timer, self->cga.dispontime); + self->cga.linepos = 0; - if (self->displine == 400) { + if (self->cga.displine == 400) { /* Hardcode 640x400 window size */ if ((640 != xsize) || (400 != ysize) || video_force_resize_get()) { xsize = 640; @@ -510,14 +531,39 @@ compaq_plasma_poll(void *p) video_bpp = 1; else video_bpp = 2; - } else video_bpp = 0; + self->cga.cgablink++; } } } +static void +compaq_plasma_mdaattr_rebuild(void) +{ + for (uint16_t c = 0; c < 256; c++) { + mdaattr[c][0][0] = mdaattr[c][1][0] = mdaattr[c][1][1] = 16; + if (c & 8) + mdaattr[c][0][1] = 15 + 16; + else + mdaattr[c][0][1] = 7 + 16; + } + + mdaattr[0x70][0][1] = 16; + mdaattr[0x70][0][0] = mdaattr[0x70][1][0] = mdaattr[0x70][1][1] = 16 + 15; + mdaattr[0xF0][0][1] = 16; + mdaattr[0xF0][0][0] = mdaattr[0xF0][1][0] = mdaattr[0xF0][1][1] = 16 + 15; + mdaattr[0x78][0][1] = 16 + 7; + mdaattr[0x78][0][0] = mdaattr[0x78][1][0] = mdaattr[0x78][1][1] = 16 + 15; + mdaattr[0xF8][0][1] = 16 + 7; + mdaattr[0xF8][0][0] = mdaattr[0xF8][1][0] = mdaattr[0xF8][1][1] = 16 + 15; + mdaattr[0x00][0][1] = mdaattr[0x00][1][1] = 16; + mdaattr[0x08][0][1] = mdaattr[0x08][1][1] = 16; + mdaattr[0x80][0][1] = mdaattr[0x80][1][1] = 16; + mdaattr[0x88][0][1] = mdaattr[0x88][1][1] = 16; +} + static void compaq_plasma_recalcattrs(compaq_plasma_t *self) { @@ -532,10 +578,10 @@ compaq_plasma_recalcattrs(compaq_plasma_t *self) * are bold */ /* Set up colours */ - amber = makecol(0xff, 0x7D, 0x00); - black = makecol(0x64, 0x19, 0x00); + amber = makecol(0xff, 0x7d, 0x00); + black = makecol(0x64, 0x0c, 0x00); - /* Initialise the attribute mapping. Start by defaulting everything + /* Initialize the attribute mapping. Start by defaulting everything * to black on amber, and with bold set by bit 3 */ for (n = 0; n < 256; n++) { blinkcols[n][0] = normcols[n][0] = amber; @@ -600,94 +646,66 @@ compaq_plasma_recalcattrs(compaq_plasma_t *self) } static void * -compaq_plasma_init(const device_t *info) +compaq_plasma_init(UNUSED(const device_t *info)) { - int display_type; compaq_plasma_t *self = malloc(sizeof(compaq_plasma_t)); memset(self, 0, sizeof(compaq_plasma_t)); - display_type = device_get_config_int("display_type"); - self->cga.composite = (display_type != CGA_RGB); - self->cga.revision = device_get_config_int("composite_type"); + video_inform(VIDEO_FLAG_TYPE_CGA, &timing_compaq_plasma); + loadfont_ex("roms/machines/portableiii/K Combined.bin", 1, 0x4bb2); - self->vram = malloc(0x8000); + self->cga.composite = 0; + self->cga.revision = 0; + + self->cga.vram = malloc(0x8000); self->internal_monitor = 1; cga_comp_init(self->cga.revision); timer_add(&self->cga.timer, compaq_plasma_poll, self, 1); - mem_mapping_add(&self->plasma_mapping, 0xb8000, 0x08000, compaq_plasma_read, NULL, NULL, compaq_plasma_write, NULL, NULL, NULL /*self->cga.vram*/, MEM_MAPPING_EXTERNAL, self); + mem_mapping_add(&self->cga.mapping, 0xb8000, 0x08000, compaq_plasma_read, NULL, NULL, compaq_plasma_write, NULL, NULL, NULL /*self->cga.vram*/, MEM_MAPPING_EXTERNAL, self); io_sethandler(0x03d0, 0x0010, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); io_sethandler(0x13c6, 0x0001, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); + io_sethandler(0x1bc6, 0x0001, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); io_sethandler(0x23c6, 0x0001, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); /* Default attribute mapping is 4 */ self->attrmap = 4; compaq_plasma_recalcattrs(self); - self->cga.cgastat = 0xF4; - self->cga.vram = self->vram; - + self->cga.cgastat = 0xf4; overscan_x = overscan_y = 16; self->cga.rgb_type = device_get_config_int("rgb_type"); cga_palette = (self->cga.rgb_type << 1); cgapal_rebuild(); + compaq_plasma_mdaattr_rebuild(); return self; } static void -compaq_plasma_close(void *p) +compaq_plasma_close(void *priv) { - compaq_plasma_t *self = (compaq_plasma_t *) p; - - free(self->vram); + compaq_plasma_t *self = (compaq_plasma_t *) priv; + free(self->cga.vram); free(self); } static void -compaq_plasma_speed_changed(void *p) +compaq_plasma_speed_changed(void *priv) { - compaq_plasma_t *self = (compaq_plasma_t *) p; + compaq_plasma_t *self = (compaq_plasma_t *) priv; compaq_plasma_recalctimings(self); } const device_config_t compaq_plasma_config[] = { // clang-format off - { - .name = "display_type", - .description = "Display type", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = CGA_RGB, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "RGB", .value = CGA_RGB }, - { .description = "Composite", .value = CGA_COMPOSITE }, - { .description = "" } - } - }, - { - .name = "composite_type", - .description = "Composite type", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = COMPOSITE_OLD, - .file_filter = "", - .spinner = { 0 }, - { - { .description = "Old", .value = COMPOSITE_OLD }, - { .description = "New", .value = COMPOSITE_NEW }, - { .description = "" } - } - }, { .name = "rgb_type", - .description = "RGB type", - .type = CONFIG_SELECTION, + .description = "RGB type", + .type = CONFIG_SELECTION, .default_string = "", .default_int = 0, .file_filter = "", @@ -697,7 +715,6 @@ const device_config_t compaq_plasma_config[] = { { .description = "Green Monochrome", .value = 1 }, { .description = "Amber Monochrome", .value = 2 }, { .description = "Gray Monochrome", .value = 3 }, - { .description = "Color (no brown)", .value = 4 }, { .description = "" } } }, @@ -720,7 +737,7 @@ const device_t compaq_plasma_device = { }; static uint8_t -read_ram(uint32_t addr, void *priv) +read_ram(uint32_t addr, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addreadlookup(mem_logical_addr, addr); @@ -729,7 +746,7 @@ read_ram(uint32_t addr, void *priv) } static uint16_t -read_ramw(uint32_t addr, void *priv) +read_ramw(uint32_t addr, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addreadlookup(mem_logical_addr, addr); @@ -738,7 +755,7 @@ read_ramw(uint32_t addr, void *priv) } static uint32_t -read_raml(uint32_t addr, void *priv) +read_raml(uint32_t addr, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addreadlookup(mem_logical_addr, addr); @@ -747,7 +764,7 @@ read_raml(uint32_t addr, void *priv) } static void -write_ram(uint32_t addr, uint8_t val, void *priv) +write_ram(uint32_t addr, uint8_t val, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addwritelookup(mem_logical_addr, addr); @@ -756,7 +773,7 @@ write_ram(uint32_t addr, uint8_t val, void *priv) } static void -write_ramw(uint32_t addr, uint16_t val, void *priv) +write_ramw(uint32_t addr, uint16_t val, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addwritelookup(mem_logical_addr, addr); @@ -765,7 +782,7 @@ write_ramw(uint32_t addr, uint16_t val, void *priv) } static void -write_raml(uint32_t addr, uint32_t val, void *priv) +write_raml(uint32_t addr, uint32_t val, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addwritelookup(mem_logical_addr, addr); @@ -776,26 +793,36 @@ write_raml(uint32_t addr, uint32_t val, void *priv) static void machine_at_compaq_init(const machine_t *model, int type) { - if (type != COMPAQ_DESKPRO386) + compaq_machine_type = type; + + if ((type != COMPAQ_DESKPRO386) && (type != COMPAQ_DESKPRO386_01_1988)) mem_remap_top(384); if (fdc_type == FDC_INTERNAL) device_add(&fdc_at_device); - mem_mapping_add(&ram_mapping, 0xfa0000, 0x60000, - read_ram, read_ramw, read_raml, - write_ram, write_ramw, write_raml, - 0xa0000 + ram, MEM_MAPPING_INTERNAL, NULL); + if ((type == COMPAQ_DESKPRO386) || (type == COMPAQ_DESKPRO386_01_1988) || (type == COMPAQ_PORTABLEIII386)) + mem_mapping_add(&ram_mapping, 0xfa0000, 0x60000, + read_ram, read_ramw, read_raml, + write_ram, write_ramw, write_raml, + 0xa0000 + ram, MEM_MAPPING_EXTERNAL, NULL); + else + mem_mapping_add(&ram_mapping, 0xfa0000, 0x60000, + read_ram, read_ramw, read_raml, + write_ram, write_ramw, write_raml, + 0xa0000 + ram, MEM_MAPPING_INTERNAL, NULL); video_reset(gfxcard[0]); switch (type) { case COMPAQ_PORTABLEII: + machine_at_init(model); break; case COMPAQ_PORTABLEIII: if (gfxcard[0] == VID_INTERNAL) device_add(&compaq_plasma_device); + machine_at_init(model); break; case COMPAQ_PORTABLEIII386: @@ -803,15 +830,20 @@ machine_at_compaq_init(const machine_t *model, int type) device_add(&ide_isa_device); if (gfxcard[0] == VID_INTERNAL) device_add(&compaq_plasma_device); + machine_at_init(model); break; case COMPAQ_DESKPRO386: + case COMPAQ_DESKPRO386_01_1988: if (hdc_current == 1) device_add(&ide_isa_device); + machine_at_common_init(model); + device_add(&keyboard_at_compaq_device); + break; + + default: break; } - - machine_at_init(model); } int @@ -836,9 +868,9 @@ machine_at_portableiii_init(const machine_t *model) { int ret; - ret = bios_load_interleavedr("roms/machines/portableiii/Compaq Portable III - BIOS - 106779-002 - Even.bin", - "roms/machines/portableiii/Compaq Portable III - BIOS - 106778-002 - Odd.bin", - 0x000f8000, 65536, 0); + ret = bios_load_linearr("roms/machines/portableiii/K Combined.bin", + 0x000f8000, 65536, 0); + if (bios_only || !ret) return ret; @@ -853,9 +885,8 @@ machine_at_portableiii386_init(const machine_t *model) { int ret; - ret = bios_load_interleavedr("roms/machines/portableiii/Compaq Portable III - BIOS - 106779-002 - Even.bin", - "roms/machines/portableiii/Compaq Portable III - BIOS - 106778-002 - Odd.bin", - 0x000f8000, 65536, 0); + ret = bios_load_linearr("roms/machines/portableiii/K Combined.bin", + 0x000f8000, 65536, 0); if (bios_only || !ret) return ret; @@ -865,14 +896,13 @@ machine_at_portableiii386_init(const machine_t *model) return ret; } -#if defined(DEV_BRANCH) && defined(USE_DESKPRO386) int machine_at_deskpro386_init(const machine_t *model) { int ret; ret = bios_load_linearr("roms/machines/deskpro386/1986-09-04-HI.json.bin", - 0x000fc000, 65536, 0); + 0x000f8000, 65536, 0); if (bios_only || !ret) return ret; @@ -881,4 +911,19 @@ machine_at_deskpro386_init(const machine_t *model) return ret; } -#endif + +int +machine_at_deskpro386_01_1988_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linearr("roms/machines/deskpro386/1988-01-28.json.bin", + 0x000f8000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_compaq_init(model, COMPAQ_DESKPRO386_01_1988); + + return ret; +} diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index 3cedb669a..184cfc34d 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -200,8 +200,8 @@ machine_at_p2bls_init(const machine_t *model) pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); pci_register_slot(0x04, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); - pci_register_slot(0x06, PCI_CARD_NORMAL, 4, 1, 2, 3); /* SCSI */ - pci_register_slot(0x07, PCI_CARD_NORMAL, 3, 4, 1, 2); /* LAN */ + pci_register_slot(0x06, PCI_CARD_SCSI, 4, 1, 2, 3); + pci_register_slot(0x07, PCI_CARD_NETWORK, 3, 4, 1, 2); pci_register_slot(0x0B, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 2, 3, 4); pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); @@ -211,7 +211,9 @@ machine_at_p2bls_init(const machine_t *model) device_add(&piix4e_device); device_add(&keyboard_ps2_ami_pci_device); device_add(&w83977ef_device); - // device_add(ics9xxx_get(ICS9150_08)); /* setting proper speeds requires some interaction with the AS97127F ASIC */ +#if 0 + device_add(ics9xxx_get(ICS9150_08)); /* setting proper speeds requires some interaction with the AS97127F ASIC */ +#endif device_add(&sst_flash_39sf020_device); spd_register(SPD_TYPE_SDRAM, 0xF, 256); device_add(&w83781d_device); /* fans: Chassis, CPU, Power; temperatures: MB, unused, CPU */ diff --git a/src/machine/m_at_socket4.c b/src/machine/m_at_socket4.c index ef745d088..b8e080d62 100644 --- a/src/machine/m_at_socket4.c +++ b/src/machine/m_at_socket4.c @@ -81,7 +81,9 @@ machine_at_award_common_init(const machine_t *model) if (fdc_type == FDC_INTERNAL) device_add(&fdc_at_device); - // device_add(&keyboard_ps2_pci_device); +#if 0 + device_add(&keyboard_ps2_pci_device); +#endif device_add(&keyboard_ps2_ami_pci_device); } diff --git a/src/machine/m_at_socket5.c b/src/machine/m_at_socket5.c index 842554713..9a45e71bf 100644 --- a/src/machine/m_at_socket5.c +++ b/src/machine/m_at_socket5.c @@ -237,7 +237,7 @@ machine_at_hawk_init(const machine_t *model) pci_register_slot(0x13, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x12, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - device_add(&keyboard_ps2_ami_pci_device); + device_add(&keyboard_ps2_tg_ami_pci_device); device_add(&i430fx_device); device_add(&piix_device); device_add(&fdc37c665_device); diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index 55a5068d9..852ce0a55 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -61,7 +61,9 @@ machine_at_thor_common_init(const machine_t *model, int mr) if (gfxcard[0] == VID_INTERNAL) device_add(&s3_phoenix_trio64vplus_onboard_pci_device); - // device_add(&keyboard_ps2_ami_pci_device); +#if 0 + device_add(&keyboard_ps2_ami_pci_device); +#endif device_add(&keyboard_ps2_intel_ami_pci_device); device_add(&i430fx_device); device_add(&piix_device); @@ -81,7 +83,7 @@ machine_at_p54tp4xe_common_init(const machine_t *model) pci_register_slot(0x0A, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - device_add(&keyboard_ps2_pci_device); + device_add(&keyboard_ps2_ami_pci_device); device_add(&i430fx_device); device_add(&piix_device); device_add(&fdc37c665_device); diff --git a/src/machine/m_at_t3100e.c b/src/machine/m_at_t3100e.c index 080f22977..a84845982 100644 --- a/src/machine/m_at_t3100e.c +++ b/src/machine/m_at_t3100e.c @@ -166,6 +166,7 @@ #include <86box/fdc_ext.h> #include <86box/machine.h> #include <86box/m_at_t3100e.h> +#include <86box/plat_unused.h> extern uint8_t *ram; /* Physical RAM */ @@ -191,12 +192,12 @@ static unsigned t3100e_ems_page_reg[] = { 0x4208, 0x8208, 0xc208, /* The first four map the first 2Mb */ - /* of RAM into the page frame */ + /* of RAM into the page frame */ 0x218, 0x4218, 0x8218, 0xc218, /* The next four map the next 2Mb */ - /* of RAM */ + /* of RAM */ 0x258, 0x4258, 0x8258, @@ -221,7 +222,7 @@ struct t3100e_ems_regs { /* Bit 0 is 0 for colour, 1 for mono */ } t3100e_ems; -void t3100e_ems_out(uint16_t addr, uint8_t val, void *p); +void t3100e_ems_out(uint16_t addr, uint8_t val, void *priv); #ifdef ENABLE_T3100E_LOG int t3100e_do_log = ENABLE_T3100E_LOG; @@ -331,11 +332,15 @@ port_to_page(uint16_t addr) return 14; case 0xC268: return 15; + + default: + break; } return -1; } -/* Used to dump the memory mapping table, for debugging +/* Used to dump the memory mapping table, for debugging */ +#if 0 void dump_mappings(void) { mem_mapping_t *mm = base_mapping.next; @@ -377,12 +382,12 @@ void dump_mappings(void) mm = mm->next; } -}*/ +} +#endif void t3100e_map_ram(uint8_t val) { - int n; int32_t upper_len; #ifdef ENABLE_T3100E_LOG @@ -433,12 +438,14 @@ t3100e_map_ram(uint8_t val) mem_mapping_disable(&t3100e_ems.upper_mapping); } /* Recalculate EMS mappings */ - for (n = 0; n < 4; n++) { + for (uint8_t n = 0; n < 4; n++) { t3100e_ems_out(t3100e_ems_page_reg[n], t3100e_ems.page[n], &t3100e_ems); } - // dump_mappings(); +#if 0 + dump_mappings(); +#endif } void @@ -471,9 +478,9 @@ t3100e_turbo_set(uint8_t value) } uint8_t -t3100e_sys_in(uint16_t addr, void *p) +t3100e_sys_in(UNUSED(uint16_t addr), void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) p; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; /* The low 4 bits always seem to be 0x0C. The high 4 are a * notification sent by the keyboard controller when it detects @@ -484,9 +491,11 @@ t3100e_sys_in(uint16_t addr, void *p) /* Handle writes to the T3100e system control port at 0x8084 */ void -t3100e_sys_out(uint16_t addr, uint8_t val, void *p) +t3100e_sys_out(UNUSED(uint16_t addr), uint8_t val, UNUSED(void *priv)) { - // struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *)p; +#if 0 + struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; +#endif switch (val & 0xE0) { case 0x00: /* Set serial port IRQs. Not implemented */ @@ -552,6 +561,9 @@ t3100e_config_get(void) value |= 0x10; break; /* Tri-mode */ /* All others will be treated as 1.4M */ + + default: + break; } break; case 4: @@ -575,7 +587,11 @@ t3100e_config_get(void) prt_switch = 0; /* No external drive */ } break; + + default: + break; } /* End switch */ + switch (prt_switch) { case 0: value |= 4; @@ -586,15 +602,18 @@ t3100e_config_get(void) case 2: value |= 6; break; /* External floppy is B: */ + + default: + break; } return value; } /* Read EMS page register */ uint8_t -t3100e_ems_in(uint16_t addr, void *p) +t3100e_ems_in(uint16_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) p; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; int page = port_to_page(addr); if (page >= 0) @@ -607,9 +626,9 @@ t3100e_ems_in(uint16_t addr, void *p) /* Write EMS page register */ void -t3100e_ems_out(uint16_t addr, uint8_t val, void *p) +t3100e_ems_out(uint16_t addr, uint8_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) p; + struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; int pg = port_to_page(addr); if (pg == -1) @@ -638,8 +657,8 @@ t3100e_ems_out(uint16_t addr, uint8_t val, void *p) static uint8_t ems_read_ram(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xFF; @@ -650,22 +669,26 @@ ems_read_ram(uint32_t addr, void *priv) static uint16_t ems_read_ramw(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xFFFF; - // t3100e_log("ems_read_ramw addr=%05x ", addr); +#if 0 + t3100e_log("ems_read_ramw addr=%05x ", addr); +#endif addr = regs->page_exec[pg] + (addr & 0x3FFF); - // t3100e_log("-> %06x val=%04x\n", addr, *(uint16_t *)&ram[addr]); +#if 0 + // t3100e_log("-> %06x val=%04x\n", addr, *(uint16_t *) &ram[addr]); +#endif return *(uint16_t *) &ram[addr]; } static uint32_t ems_read_raml(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xFFFFFFFF; @@ -677,8 +700,8 @@ ems_read_raml(uint32_t addr, void *priv) static void ems_write_ram(uint32_t addr, uint8_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -689,14 +712,18 @@ ems_write_ram(uint32_t addr, uint8_t val, void *priv) static void ems_write_ramw(uint32_t addr, uint16_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; - // t3100e_log("ems_write_ramw addr=%05x ", addr); +#if 0 + t3100e_log("ems_write_ramw addr=%05x ", addr); +#endif addr = regs->page_exec[pg] + (addr & 0x3FFF); - // t3100e_log("-> %06x val=%04x\n", addr, val); +#if 0 + t3100e_log("-> %06x val=%04x\n", addr, val); +#endif *(uint16_t *) &ram[addr] = val; } @@ -704,8 +731,8 @@ ems_write_ramw(uint32_t addr, uint16_t val, void *priv) static void ems_write_raml(uint32_t addr, uint32_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -718,7 +745,7 @@ ems_write_raml(uint32_t addr, uint32_t val, void *priv) static uint8_t upper_read_ram(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; return ram[addr]; @@ -727,7 +754,7 @@ upper_read_ram(uint32_t addr, void *priv) static uint16_t upper_read_ramw(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; return *(uint16_t *) &ram[addr]; @@ -736,7 +763,7 @@ upper_read_ramw(uint32_t addr, void *priv) static uint32_t upper_read_raml(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; return *(uint32_t *) &ram[addr]; @@ -745,7 +772,7 @@ upper_read_raml(uint32_t addr, void *priv) static void upper_write_ram(uint32_t addr, uint8_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; ram[addr] = val; @@ -754,7 +781,7 @@ upper_write_ram(uint32_t addr, uint8_t val, void *priv) static void upper_write_ramw(uint32_t addr, uint16_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; *(uint16_t *) &ram[addr] = val; @@ -763,7 +790,7 @@ upper_write_ramw(uint32_t addr, uint16_t val, void *priv) static void upper_write_raml(uint32_t addr, uint32_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; *(uint32_t *) &ram[addr] = val; diff --git a/src/machine/m_at_t3100e_vid.c b/src/machine/m_at_t3100e_vid.c index 53571c49e..57b0641a6 100644 --- a/src/machine/m_at_t3100e_vid.c +++ b/src/machine/m_at_t3100e_vid.c @@ -66,6 +66,7 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/m_at_t3100e.h> +#include <86box/plat_unused.h> #define T3100E_XSIZE 640 #define T3100E_YSIZE 400 @@ -74,7 +75,8 @@ #define VID_CLOCK (double) (651 * 416 * 60) /* Mapping of attributes to colours */ -static uint32_t amber, black; +static uint32_t amber; +static uint32_t black; static uint8_t boldcols[256]; /* Which attributes use the bold font */ static uint32_t blinkcols[256][2]; static uint32_t normcols[256][2]; @@ -133,14 +135,14 @@ typedef struct t3100e_t { static video_timings_t timing_t3100e = { VIDEO_ISA, 8, 16, 32, 8, 16, 32 }; void t3100e_recalctimings(t3100e_t *t3100e); -void t3100e_write(uint32_t addr, uint8_t val, void *p); -uint8_t t3100e_read(uint32_t addr, void *p); +void t3100e_write(uint32_t addr, uint8_t val, void *priv); +uint8_t t3100e_read(uint32_t addr, void *priv); void t3100e_recalcattrs(t3100e_t *t3100e); void -t3100e_out(uint16_t addr, uint8_t val, void *p) +t3100e_out(uint16_t addr, uint8_t val, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; switch (addr) { /* Emulated CRTC, register select */ case 0x3d0: @@ -167,21 +169,20 @@ t3100e_out(uint16_t addr, uint8_t val, void *p) t3100e_recalctimings(t3100e); return; - /* CGA control register */ - case 0x3D8: - cga_out(addr, val, &t3100e->cga); - return; - /* CGA colour register */ - case 0x3D9: + case 0x3D8: /* CGA control register */ + case 0x3D9: /* CGA colour register */ cga_out(addr, val, &t3100e->cga); return; + + default: + break; } } uint8_t -t3100e_in(uint16_t addr, void *p) +t3100e_in(uint16_t addr, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; uint8_t val; switch (addr) { @@ -195,24 +196,29 @@ t3100e_in(uint16_t addr, void *p) val |= 0x30; /* Plasma / CRT */ return val; } + break; + + default: + break; } return cga_in(addr, &t3100e->cga); } void -t3100e_write(uint32_t addr, uint8_t val, void *p) +t3100e_write(uint32_t addr, uint8_t val, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; t3100e->vram[addr & 0x7fff] = val; cycles -= 4; } uint8_t -t3100e_read(uint32_t addr, void *p) +t3100e_read(uint32_t addr, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + const t3100e_t *t3100e = (t3100e_t *) priv; + cycles -= 4; return t3100e->vram[addr & 0x7fff]; @@ -222,7 +228,8 @@ void t3100e_recalctimings(t3100e_t *t3100e) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; if (!t3100e->internal) { cga_recalctimings(&t3100e->cga); @@ -231,8 +238,8 @@ t3100e_recalctimings(t3100e_t *t3100e) disptime = 651; _dispontime = 640; _dispofftime = disptime - _dispontime; - t3100e->dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); - t3100e->dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); + t3100e->dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); + t3100e->dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); } /* Draw a row of text in 80-column mode */ @@ -240,8 +247,8 @@ void t3100e_text_row80(t3100e_t *t3100e) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -260,7 +267,7 @@ t3100e_text_row80(t3100e_t *t3100e) } else { cursorline = ((t3100e->cga.crtc[10] & 0x0F) * 2 <= sc) && ((t3100e->cga.crtc[11] & 0x0F) * 2 >= sc); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { chr = t3100e->vram[(addr + 2 * x) & 0x7FFF]; attr = t3100e->vram[(addr + 2 * x + 1) & 0x7FFF]; drawcursor = ((ma == ca) && cursorline && (t3100e->cga.cgamode & 8) && (t3100e->cga.cgablink & 16)); @@ -284,12 +291,12 @@ t3100e_text_row80(t3100e_t *t3100e) cols[0] = normcols[attr][0]; } if (drawcursor) { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } } else { - for (c = 0; c < 8; c++) - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) + (buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } ++ma; } @@ -300,8 +307,9 @@ void t3100e_text_row40(t3100e_t *t3100e) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + int c; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -320,7 +328,7 @@ t3100e_text_row40(t3100e_t *t3100e) } else { cursorline = ((t3100e->cga.crtc[10] & 0x0F) * 2 <= sc) && ((t3100e->cga.crtc[11] & 0x0F) * 2 >= sc); } - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { chr = t3100e->vram[(addr + 2 * x) & 0x7FFF]; attr = t3100e->vram[(addr + 2 * x + 1) & 0x7FFF]; drawcursor = ((ma == ca) && cursorline && (t3100e->cga.cgamode & 8) && (t3100e->cga.cgablink & 16)); @@ -345,11 +353,11 @@ t3100e_text_row40(t3100e_t *t3100e) } if (drawcursor) { for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + (buffer32->line[t3100e->displine])[(x << 4) + c * 2] = (buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } } else { for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + (buffer32->line[t3100e->displine])[(x << 4) + c * 2] = (buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } } ++ma; @@ -360,7 +368,6 @@ t3100e_text_row40(t3100e_t *t3100e) void t3100e_cgaline6(t3100e_t *t3100e) { - int x, c; uint8_t dat; uint32_t ink = 0; uint16_t addr; @@ -375,16 +382,16 @@ t3100e_cgaline6(t3100e_t *t3100e) } else { addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t3100e->vram[addr & 0x7FFF]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { ink = (dat & 0x80) ? fg : bg; if (!(t3100e->cga.cgamode & 8)) ink = black; - ((uint32_t *) buffer32->line[t3100e->displine])[x * 8 + c] = ink; - dat = dat << 1; + (buffer32->line[t3100e->displine])[x * 8 + c] = ink; + dat = dat << 1; } } } @@ -394,9 +401,10 @@ t3100e_cgaline6(t3100e_t *t3100e) void t3100e_cgaline4(t3100e_t *t3100e) { - int x, c; - uint8_t dat, pattern; - uint32_t ink0 = 0, ink1 = 0; + uint8_t dat; + uint8_t pattern; + uint32_t ink0 = 0; + uint32_t ink1 = 0; uint16_t addr; uint16_t ma = (t3100e->cga.crtc[13] | (t3100e->cga.crtc[12] << 8)) & 0x7fff; @@ -407,11 +415,11 @@ t3100e_cgaline4(t3100e_t *t3100e) { addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t3100e->vram[addr & 0x7FFF]; addr++; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; if (!(t3100e->cga.cgamode & 8)) pattern = 0; @@ -441,18 +449,21 @@ t3100e_cgaline4(t3100e_t *t3100e) case 3: ink0 = ink1 = amber; break; + + default: + break; } - ((uint32_t *) buffer32->line[t3100e->displine])[x * 8 + 2 * c] = ink0; - ((uint32_t *) buffer32->line[t3100e->displine])[x * 8 + 2 * c + 1] = ink1; - dat = dat << 2; + (buffer32->line[t3100e->displine])[x * 8 + 2 * c] = ink0; + (buffer32->line[t3100e->displine])[x * 8 + 2 * c + 1] = ink1; + dat = dat << 2; } } } void -t3100e_poll(void *p) +t3100e_poll(void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; if (t3100e->video_options != st_video_options) { t3100e->video_options = st_video_options; @@ -642,7 +653,7 @@ t3100e_recalcattrs(t3100e_t *t3100e) } void * -t3100e_init(const device_t *info) +t3100e_init(UNUSED(const device_t *info)) { t3100e_t *t3100e = malloc(sizeof(t3100e_t)); memset(t3100e, 0, sizeof(t3100e_t)); @@ -676,18 +687,18 @@ t3100e_init(const device_t *info) } void -t3100e_close(void *p) +t3100e_close(void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; free(t3100e->vram); free(t3100e); } void -t3100e_speed_changed(void *p) +t3100e_speed_changed(void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; t3100e_recalctimings(t3100e); } diff --git a/src/machine/m_elt.c b/src/machine/m_elt.c index 0370b45a2..573095223 100644 --- a/src/machine/m_elt.c +++ b/src/machine/m_elt.c @@ -50,11 +50,13 @@ #include <86box/rom.h> #include <86box/video.h> #include <86box/vid_cga.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> static void -elt_vid_off_poll(void *p) +elt_vid_off_poll(void *priv) { - cga_t *cga = p; + cga_t *cga = priv; uint8_t hdisp = cga->crtc[1]; /* Don't display anything. @@ -65,9 +67,9 @@ elt_vid_off_poll(void *p) } static void -sysstat_out(uint16_t port, uint8_t val, void *p) +sysstat_out(UNUSED(uint16_t port), uint8_t val, void *priv) { - cga_t *cga = p; + cga_t *cga = priv; switch (val) { case 0: @@ -88,10 +90,10 @@ sysstat_out(uint16_t port, uint8_t val, void *p) } static uint8_t -sysstat_in(uint16_t port, void *p) +sysstat_in(UNUSED(uint16_t port), void *priv) { - cga_t *cga = p; - uint8_t ret = 0x0a; /* No idea what these bits are */ + const cga_t *cga = priv; + uint8_t ret = 0x0a; /* No idea what these bits are */ /* External CRT. We don't emulate the LCD/CRT switching, let's just * frivolously use this bit to indicate we're using the LCD if the @@ -103,9 +105,9 @@ sysstat_in(uint16_t port, void *p) } static void -elt_vid_out(uint16_t addr, uint8_t val, void *p) +elt_vid_out(uint16_t addr, uint8_t val, void *priv) { - cga_t *cga = p; + cga_t *cga = priv; /* The Equity LT chipset's CRTC contains more registers than the * regular CGA. The BIOS writes one of them, register 36 (0x24). @@ -122,30 +124,32 @@ elt_vid_out(uint16_t addr, uint8_t val, void *p) case 0x3d1: if (cga->crtcreg >= 32) return; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + default: cga->crtcreg &= 31; - cga_out(addr, val, p); + cga_out(addr, val, priv); } } static uint8_t -elt_vid_in(uint16_t addr, void *p) +elt_vid_in(uint16_t addr, void *priv) { - cga_t *cga = p; + cga_t *cga = priv; /* Just make sure we don't ever let regular CGA code run with crtcreg * pointing out of crtcregs[] bounds. */ cga->crtcreg &= 31; - return cga_in(addr, p); + return cga_in(addr, priv); } static void load_font_rom(uint32_t font_data) { - int c, d; - for (c = 0; c < 256; c++) - for (d = 0; d < 8; d++) + for (uint16_t c = 0; c < 256; c++) + for (uint8_t d = 0; d < 8; d++) fontdat[c][d] = mem_readb_phys(font_data++); } diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index b1368dd5d..e541cf718 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -104,6 +104,7 @@ #include <86box/hdc.h> #include <86box/video.h> #include <86box/machine.h> +#include <86box/plat_unused.h> #define EUROPC_DEBUG 0 /* current debugging level */ @@ -125,7 +126,7 @@ #define MRTC_CHECK_HI 0x0e /* Checksum, high byte */ #define MRTC_CTRLSTAT 0x0f /* RTC control/status, binary */ -typedef struct { +typedef struct europc_t { uint16_t jim; /* JIM base address */ uint8_t regs[16]; /* JIM internal regs (8) */ @@ -173,7 +174,8 @@ static void europc_rtc_tick(nvr_t *nvr) { uint8_t *regs; - int mon, yr; + int mon; + int yr; /* Only if RTC is running.. */ regs = nvr->regs; @@ -266,14 +268,13 @@ static uint8_t rtc_checksum(uint8_t *ptr) { uint8_t sum; - int i; /* Calculate all bytes with XOR. */ sum = 0x00; - for (i = MRTC_CONF_A; i <= MRTC_CONF_E; i++) + for (uint8_t i = MRTC_CONF_A; i <= MRTC_CONF_E; i++) sum += ptr[i]; - return (sum); + return sum; } /* Reset the machine's NVR to a sane state. */ @@ -372,13 +373,17 @@ jim_set(europc_t *sys, uint8_t reg, uint8_t val) switch (val) { case 0x1f: /* 0001 1111 */ case 0x0b: /* 0000 1011 */ - // europc_jim.mode=AGA_MONO; +#if 0 + europc_jim.mode=AGA_MONO; +#endif europc_log("EuroPC: AGA Monochrome mode!\n"); break; case 0x18: /* 0001 1000 */ case 0x1a: /* 0001 1010 */ - // europc_jim.mode=AGA_COLOR; +#if 0 + europc_jim.mode=AGA_COLOR; +#endif break; case 0x0e: /* 0000 1100 */ @@ -392,7 +397,9 @@ jim_set(europc_t *sys, uint8_t reg, uint8_t val) break; default: - // europc_jim.mode=AGA_OFF; +#if 0 + europc_jim.mode=AGA_OFF; +#endif break; } break; @@ -400,15 +407,21 @@ jim_set(europc_t *sys, uint8_t reg, uint8_t val) case 4: /* CPU Speed control */ switch (val & 0xc0) { case 0x00: /* 4.77 MHz */ - // cpu_set_clockscale(0, 1.0/2); +#if 0 + cpu_set_clockscale(0, 1.0/2); +#endif break; case 0x40: /* 7.16 MHz */ - // cpu_set_clockscale(0, 3.0/4); +#if 0 + cpu_set_clockscale(0, 3.0/4); +#endif break; default: /* 9.54 MHz */ - // cpu_set_clockscale(0, 1);break; +#if 0 + cpu_set_clockscale(0, 1);break; +#endif break; } break; @@ -465,6 +478,9 @@ jim_write(uint16_t addr, uint8_t val, void *priv) sys->nvr_stat = 0; nvr_dosave++; break; + + default: + break; } break; @@ -511,6 +527,9 @@ jim_read(uint16_t addr, void *priv) r = (sys->nvr.regs[sys->nvr_addr] & 0x0f); sys->nvr_stat = 0; break; + + default: + break; } break; @@ -523,12 +542,12 @@ jim_read(uint16_t addr, void *priv) europc_log("EuroPC: jim_rd(%04x): %02x\n", addr, r); #endif - return (r); + return r; } /* Initialize the mainboard 'device' of the machine. */ static void * -europc_boot(const device_t *info) +europc_boot(UNUSED(const device_t *info)) { europc_t *sys = &europc; uint8_t b; @@ -573,6 +592,9 @@ europc_boot(const device_t *info) case 640: b |= 0x00; break; + + default: + break; } sys->nvr.regs[MRTC_CONF_C] = b; @@ -590,6 +612,9 @@ europc_boot(const device_t *info) case 2: /* 8088, 9.56 MHz */ b |= 0x80; break; + + default: + break; } sys->nvr.regs[MRTC_CONF_D] = b; @@ -638,11 +663,11 @@ europc_boot(const device_t *info) if (hdc_current == 1) (void) device_add(&xta_hd20_device); - return (sys); + return sys; } static void -europc_close(void *priv) +europc_close(UNUSED(void *priv)) { nvr_t *nvr = &europc.nvr; diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index d1eafef79..f8c50a931 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -49,6 +49,7 @@ #include <86box/video.h> #include <86box/vid_cga_comp.h> #include <86box/machine.h> +#include <86box/plat_unused.h> #define PCJR_RGB 0 #define PCJR_COMPOSITE 1 @@ -62,7 +63,7 @@ #define STAT_IFULL 0x02 #define STAT_OFULL 0x01 -typedef struct { +typedef struct pcjr_t { /* Video Controller stuff. */ mem_mapping_t mapping; uint8_t crtc[32]; @@ -73,20 +74,28 @@ typedef struct { int memctrl; uint8_t stat; int addr_mode; - uint8_t *vram, - *b8000; - int linepos, displine; - int sc, vc; - int dispon; - int con, coff, cursoron, blink; - int vsynctime; - int fullchange; - int vadj; - uint16_t ma, maback; - uint64_t dispontime, dispofftime; - pc_timer_t timer; - int firstline, lastline; - int composite; + uint8_t *vram; + uint8_t *b8000; + int linepos; + int displine; + int sc; + int vc; + int dispon; + int con; + int coff; + int cursoron; + int blink; + int vsynctime; + int fullchange; + int vadj; + uint16_t ma; + uint16_t maback; + uint64_t dispontime; + uint64_t dispofftime; + pc_timer_t timer; + int firstline; + int lastline; + int composite; /* Keyboard Controller stuff. */ int latched; @@ -107,8 +116,8 @@ static uint8_t crtcmask[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; static void recalc_address(pcjr_t *pcjr) @@ -125,7 +134,9 @@ recalc_address(pcjr_t *pcjr) static void recalc_timings(pcjr_t *pcjr) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; if (pcjr->array[0] & 1) { disptime = pcjr->crtc[0] + 1; @@ -143,9 +154,9 @@ recalc_timings(pcjr_t *pcjr) } static void -vid_out(uint16_t addr, uint8_t val, void *p) +vid_out(uint16_t addr, uint8_t val, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; uint8_t old; switch (addr) { @@ -182,13 +193,16 @@ vid_out(uint16_t addr, uint8_t val, void *p) pcjr->addr_mode = val >> 6; recalc_address(pcjr); break; + + default: + break; } } static uint8_t -vid_in(uint16_t addr, void *p) +vid_in(uint16_t addr, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; uint8_t ret = 0xff; switch (addr) { @@ -205,15 +219,18 @@ vid_in(uint16_t addr, void *p) pcjr->stat ^= 0x10; ret = pcjr->stat; break; + + default: + break; } - return (ret); + return ret; } static void -vid_write(uint32_t addr, uint8_t val, void *p) +vid_write(uint32_t addr, uint8_t val, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; if (pcjr->memctrl == -1) return; @@ -222,25 +239,28 @@ vid_write(uint32_t addr, uint8_t val, void *p) } static uint8_t -vid_read(uint32_t addr, void *p) +vid_read(uint32_t addr, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + const pcjr_t *pcjr = (pcjr_t *) priv; if (pcjr->memctrl == -1) - return (0xff); + return 0xff; return (pcjr->b8000[addr & 0x3fff]); } static void -vid_poll(void *p) +vid_poll(void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; uint16_t ca = (pcjr->crtc[15] | (pcjr->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t dat; int cols[4]; int oldsc; @@ -262,12 +282,12 @@ vid_poll(void *p) } pcjr->lastline = pcjr->displine; cols[0] = (pcjr->array[2] & 0xf) + 16; - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[pcjr->displine])[c] = cols[0]; + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[pcjr->displine])[c] = cols[0]; if (pcjr->array[0] & 1) { - buffer32->line[(pcjr->displine << 1)][c + (pcjr->crtc[1] << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 3) + 8] = cols[0]; + buffer32->line[pcjr->displine << 1][c + (pcjr->crtc[1] << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 3) + 8] = cols[0]; } else { - buffer32->line[(pcjr->displine << 1)][c + (pcjr->crtc[1] << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 4) + 8] = cols[0]; + buffer32->line[pcjr->displine << 1][c + (pcjr->crtc[1] << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 4) + 8] = cols[0]; } } @@ -282,36 +302,39 @@ vid_poll(void *p) case 3: /*High resolution graphics*/ offset = (pcjr->sc & 3) * 0x2000; break; + + default: + break; } switch ((pcjr->array[0] & 0x13) | ((pcjr->array[3] & 0x08) << 5)) { case 0x13: /*320x200x16*/ for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 9] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 10] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 11] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 12] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 13] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 14] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 15] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 8] = buffer32->line[pcjr->displine << 1][(x << 3) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 9] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 10] = buffer32->line[pcjr->displine << 1][(x << 3) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 11] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 12] = buffer32->line[pcjr->displine << 1][(x << 3) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 13] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 14] = buffer32->line[pcjr->displine << 1][(x << 3) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 15] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; } break; case 0x12: /*160x200x16*/ for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 9] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 10] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 11] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 12] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 13] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 14] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 15] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 16] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 17] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 18] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 19] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 16] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 17] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 18] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 19] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 20] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 21] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 22] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 23] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 20] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 21] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 22] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 23] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + 9] = buffer32->line[pcjr->displine << 1][(x << 4) + 10] = buffer32->line[pcjr->displine << 1][(x << 4) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 11] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 12] = buffer32->line[pcjr->displine << 1][(x << 4) + 13] = buffer32->line[pcjr->displine << 1][(x << 4) + 14] = buffer32->line[pcjr->displine << 1][(x << 4) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 15] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 16] = buffer32->line[pcjr->displine << 1][(x << 4) + 17] = buffer32->line[pcjr->displine << 1][(x << 4) + 18] = buffer32->line[pcjr->displine << 1][(x << 4) + 19] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 16] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 17] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 18] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 19] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 20] = buffer32->line[pcjr->displine << 1][(x << 4) + 21] = buffer32->line[pcjr->displine << 1][(x << 4) + 22] = buffer32->line[pcjr->displine << 1][(x << 4) + 23] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 20] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 21] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 22] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 23] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; } break; case 0x03: /*640x200x4*/ for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { chr = (dat >> 7) & 1; chr |= ((dat >> 14) & 2); - buffer32->line[(pcjr->displine << 1)][(x << 3) + 8 + c] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8 + c] = pcjr->array[(chr & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 8 + c] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8 + c] = pcjr->array[(chr & pcjr->array[1]) + 16] + 16; dat <<= 1; } } @@ -331,17 +354,17 @@ vid_poll(void *p) cols[0] = pcjr->array[((attr >> 4) & pcjr->array[1]) + 16] + 16; } if (pcjr->sc & 8) { - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; } } else { - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } if (drawcursor) { - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 3) + c + 8] ^= 15; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] ^= 15; buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] ^= 15; } } @@ -364,17 +387,17 @@ vid_poll(void *p) } pcjr->ma++; if (pcjr->sc & 8) { - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; } } else { - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } if (drawcursor) { - for (c = 0; c < 16; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + c + 8] ^= 15; + for (uint8_t c = 0; c < 16; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + c + 8] ^= 15; buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + c + 8] ^= 15; } } @@ -388,8 +411,8 @@ vid_poll(void *p) for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; dat <<= 2; } } @@ -400,12 +423,15 @@ vid_poll(void *p) for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - for (c = 0; c < 16; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; + for (uint8_t c = 0; c < 16; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; dat <<= 1; } } break; + + default: + break; } } else { if (pcjr->array[3] & 4) { @@ -432,7 +458,7 @@ vid_poll(void *p) else x = (pcjr->crtc[1] << 4) + 16; if (pcjr->composite) { - Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[(pcjr->displine << 1)]); + Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[pcjr->displine << 1]); Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[(pcjr->displine << 1) + 1]); } else { video_process_8(x, pcjr->displine << 1); @@ -544,7 +570,7 @@ vid_poll(void *p) pcjr->sc &= 31; pcjr->ma = pcjr->maback; } - if ((pcjr->sc == (pcjr->crtc[10] & 31) || ((pcjr->crtc[8] & 3) == 3 && pcjr->sc == ((pcjr->crtc[10] & 31) >> 1)))) + if (pcjr->sc == (pcjr->crtc[10] & 31) || ((pcjr->crtc[8] & 3) == 3 && pcjr->sc == ((pcjr->crtc[10] & 31) >> 1))) pcjr->con = 1; } } @@ -585,6 +611,9 @@ kbd_write(uint16_t port, uint8_t val, void *priv) case 0x60: sn76489_mute = 0; break; + + default: + break; } break; @@ -592,6 +621,9 @@ kbd_write(uint16_t port, uint8_t val, void *priv) nmi_mask = val & 0x80; pit_devs[0].set_using_timer(pit_devs[0].data, 1, !(val & 0x20)); break; + + default: + break; } } @@ -631,16 +663,21 @@ kbd_read(uint16_t port, void *priv) pcjr->latched = 0; ret = 0; break; + + default: + break; } - return (ret); + return ret; } static void kbd_poll(void *priv) { pcjr_t *pcjr = (pcjr_t *) priv; - int c, p = 0, key; + int c; + int p = 0; + int key; timer_advance_u64(&pcjr->send_delay_timer, 220 * TIMER_USEC); @@ -757,7 +794,7 @@ const device_t pcjr_device = { }; int -machine_pcjr_init(const machine_t *model) +machine_pcjr_init(UNUSED(const machine_t *model)) { int display_type; pcjr_t *pcjr; diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index d002ba6bd..d2c9f80ba 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -153,6 +153,9 @@ ps1_write(uint16_t port, uint8_t val, void *priv) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps->ps1_102 = val; @@ -174,6 +177,9 @@ ps1_write(uint16_t port, uint8_t val, void *priv) case 0x0190: ps->ps1_190 = val; break; + + default: + break; } } @@ -233,7 +239,7 @@ ps1_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static void diff --git a/src/machine/m_ps1_hdc.c b/src/machine/m_ps1_hdc.c index 4355a0ad6..225ae04a5 100644 --- a/src/machine/m_ps1_hdc.c +++ b/src/machine/m_ps1_hdc.c @@ -161,54 +161,54 @@ enum { * block is transferred. */ #pragma pack(push, 1) -typedef struct { +typedef struct ssb_t { /* Status byte 0. */ - uint8_t track_0 : 1, /* T0 */ - mbz1 : 1, /* 0 */ - mbz2 : 1, /* 0 */ - cylinder_err : 1, /* CE */ - write_fault : 1, /* WF */ - mbz3 : 1, /* 0 */ - seek_end : 1, /* SE */ - not_ready : 1; /* NR */ + uint8_t track_0 : 1; /* T0 */ + uint8_t mbz1 : 1; /* 0 */ + uint8_t mbz2 : 1; /* 0 */ + uint8_t cylinder_err : 1; /* CE */ + uint8_t write_fault : 1; /* WF */ + uint8_t mbz3 : 1; /* 0 */ + uint8_t seek_end : 1; /* SE */ + uint8_t not_ready : 1; /* NR */ /* Status byte 1. */ - uint8_t id_not_found : 1, /* ID */ - mbz4 : 1, /* 0 */ - mbz5 : 1, /* 0 */ - wrong_cyl : 1, /* WC */ - all_bit_set : 1, /* BT */ - mark_not_found : 1, /* AM */ - ecc_crc_err : 1, /* ET */ - ecc_crc_field : 1; /* EF */ + uint8_t id_not_found : 1; /* ID */ + uint8_t mbz4 : 1; /* 0 */ + uint8_t mbz5 : 1; /* 0 */ + uint8_t wrong_cyl : 1; /* WC */ + uint8_t all_bit_set : 1; /* BT */ + uint8_t mark_not_found : 1; /* AM */ + uint8_t ecc_crc_err : 1; /* ET */ + uint8_t ecc_crc_field : 1; /* EF */ /* Status byte 2. */ - uint8_t headsel_state : 4, /* headsel state[4] */ - defective_sector : 1, /* DS */ - retried_ok : 1, /* RG */ - need_reset : 1, /* RR */ + uint8_t headsel_state : 4; /* headsel state[4] */ + uint8_t defective_sector : 1; /* DS */ + uint8_t retried_ok : 1; /* RG */ + uint8_t need_reset : 1; /* RR */ #if 1 - valid : 1; /* 0 (abused as VALID) */ + uint8_t valid : 1; /* 0 (abused as VALID) */ #else - mbz6 : 1; /* 0 */ + uint8_t mbz6 : 1; /* 0 */ #endif /* Most recent ID field seen. */ - uint8_t last_cyl_low; /* Cyl_Low[8] */ - uint8_t last_head : 4, /* HD[4] */ - mbz7 : 1, /* 0 */ - last_cyl_high : 2, /* Cyl_high[2] */ - last_def_sect : 1; /* DS */ - uint8_t last_sect; /* Sect[8] */ + uint8_t last_cyl_low; /* Cyl_Low[8] */ + uint8_t last_head : 4; /* HD[4] */ + uint8_t mbz7 : 1; /* 0 */ + uint8_t last_cyl_high : 2; /* Cyl_high[2] */ + uint8_t last_def_sect : 1; /* DS */ + uint8_t last_sect; /* Sect[8] */ uint8_t sect_size; /* Size[8] = 02 */ /* Current position. */ - uint8_t curr_cyl_high : 2, /* Cyl_High_[2] */ - mbz8 : 1, /* 0 */ - mbz9 : 1, /* 0 */ - curr_head : 4; /* HD_2[4] */ - uint8_t curr_cyl_low; /* Cyl_Low_2[8] */ + uint8_t curr_cyl_high : 2; /* Cyl_High_[2] */ + uint8_t mbz8 : 1; /* 0 */ + uint8_t mbz9 : 1; /* 0 */ + uint8_t curr_head : 4; /* HD_2[4] */ + uint8_t curr_cyl_low; /* Cyl_Low_2[8] */ uint8_t sect_corr; /* sectors corrected */ @@ -290,21 +290,21 @@ typedef struct { * bits 0. */ #pragma pack(push, 1) -typedef struct { - uint8_t cyl_high : 2, /* cylinder [9:8] bits */ - defective_sector : 1, /* DS */ - mbz1 : 1, /* 0 */ - head : 4; /* head number */ +typedef struct fcb_t { + uint8_t cyl_high : 2; /* cylinder [9:8] bits */ + uint8_t defective_sector : 1; /* DS */ + uint8_t mbz1 : 1; /* 0 */ + uint8_t head : 4; /* head number */ - uint8_t cyl_low; /* cylinder [7:0] bits */ + uint8_t cyl_low; /* cylinder [7:0] bits */ - uint8_t sector; /* sector number */ + uint8_t sector; /* sector number */ - uint8_t mbz2 : 1, /* 0 */ - mbo : 1, /* 1 */ - mbz3 : 6; /* 000000 */ + uint8_t mbz2 : 1; /* 0 */ + uint8_t mbo : 1; /* 1 */ + uint8_t mbz3 : 6; /* 000000 */ - uint8_t fill; /* filler byte */ + uint8_t fill; /* filler byte */ } fcb_t; #pragma pack(pop) @@ -316,31 +316,31 @@ typedef struct { * through a DMA or PIO operation. */ #pragma pack(push, 1) -typedef struct { - uint8_t ec_p : 1, /* EC/P (ecc/park) */ - mbz1 : 1, /* 0 */ - auto_seek : 1, /* AS (auto-seek) */ - no_data : 1, /* ND (no data) */ - cmd : 4; /* command code[4] */ +typedef struct ccb_t{ + uint8_t ec_p : 1; /* EC/P (ecc/park) */ + uint8_t mbz1 : 1; /* 0 */ + uint8_t auto_seek : 1; /* AS (auto-seek) */ + uint8_t no_data : 1; /* ND (no data) */ + uint8_t cmd : 4; /* command code[4] */ - uint8_t cyl_high : 2, /* cylinder [9:8] bits */ - mbz2 : 2, /* 00 */ - head : 4; /* head number */ + uint8_t cyl_high : 2; /* cylinder [9:8] bits */ + uint8_t mbz2 : 2; /* 00 */ + uint8_t head : 4; /* head number */ uint8_t cyl_low; /* cylinder [7:0] bits */ uint8_t sector; /* sector number */ - uint8_t mbz3 : 1, /* 0 */ - mbo1 : 1, /* 1 */ - mbz4 : 6; /* 000000 */ + uint8_t mbz3 : 1; /* 0 */ + uint8_t mbo1 : 1; /* 1 */ + uint8_t mbz4 : 6; /* 000000 */ uint8_t count; /* blk count/interleave */ } ccb_t; #pragma pack(pop) /* Define the hard drive geometry table. */ -typedef struct { +typedef struct geom_t { uint16_t cyl; uint8_t hpc; uint8_t spt; @@ -349,54 +349,54 @@ typedef struct { } geom_t; /* Define an attached drive. */ -typedef struct { - int8_t id, /* drive ID on bus */ - present, /* drive is present */ - hdd_num, /* index to global disk table */ - type; /* drive type ID */ +typedef struct drive_t { + int8_t id; /* drive ID on bus */ + int8_t present; /* drive is present */ + int8_t hdd_num; /* index to global disk table */ + int8_t type; /* drive type ID */ uint16_t cur_cyl; /* last known position of heads */ - uint8_t spt, /* active drive parameters */ - hpc; + uint8_t spt; /* active drive parameters */ + uint8_t hpc; uint16_t tracks; - uint8_t cfg_spt, /* configured drive parameters */ - cfg_hpc; + uint8_t cfg_spt; /* configured drive parameters */ + uint8_t cfg_hpc; uint16_t cfg_tracks; } drive_t; -typedef struct { +typedef struct hdc_t { uint16_t base; /* controller base I/O address */ int8_t irq; /* controller IRQ channel */ int8_t dma; /* controller DMA channel */ /* Registers. */ - uint8_t attn, /* ATTENTION register */ - ctrl, /* Control register (ACR) */ - status, /* Status register (ASR) */ - intstat; /* Interrupt Status register (ISR) */ + uint8_t attn; /* ATTENTION register */ + uint8_t ctrl; /* Control register (ACR) */ + uint8_t status; /* Status register (ASR) */ + uint8_t intstat; /* Interrupt Status register (ISR) */ uint8_t *reg_91; /* handle to system board's register 0x91 */ /* Controller state. */ uint64_t callback; pc_timer_t timer; - int8_t state, /* controller state */ - reset; /* reset state counter */ + int8_t state; /* controller state */ + int8_t reset; /* reset state counter */ /* Data transfer. */ - int16_t buf_idx, /* buffer index and pointer */ - buf_len; + int16_t buf_idx; /* buffer index and pointer */ + int16_t buf_len; uint8_t *buf_ptr; /* Current operation parameters. */ - ssb_t ssb; /* sense block */ - ccb_t ccb; /* command control block */ - uint16_t track; /* requested track# */ - uint8_t head, /* requested head# */ - sector; /* requested sector# */ - int count; /* requested sector count */ + ssb_t ssb; /* sense block */ + ccb_t ccb; /* command control block */ + uint16_t track; /* requested track# */ + uint8_t head; /* requested head# */ + uint8_t sector; /* requested sector# */ + int count; /* requested sector count */ drive_t drives[XTA_NUM]; /* the attached drive(s) */ @@ -502,15 +502,14 @@ static int ibm_drive_type(drive_t *drive) { const geom_t *ptr; - int i; - for (i = 0; i < (sizeof(ibm_type_table) / sizeof(geom_t)); i++) { + for (uint16_t i = 0; i < (sizeof(ibm_type_table) / sizeof(geom_t)); i++) { ptr = &ibm_type_table[i]; if ((drive->tracks == ptr->cyl) && (drive->hpc == ptr->hpc) && (drive->spt == ptr->spt)) - return (i); + return i; } - return (HDC_TYPE_USER); + return HDC_TYPE_USER; } static void @@ -534,25 +533,25 @@ get_sector(hdc_t *dev, drive_t *drive, off64_t *addr) ps1_hdc_log("HDC: get_sector: wrong cylinder %d/%d\n", drive->cur_cyl, dev->track); dev->ssb.wrong_cyl = 1; - return (1); + return 1; } if (dev->head >= drive->hpc) { ps1_hdc_log("HDC: get_sector: past end of heads\n"); dev->ssb.cylinder_err = 1; - return (1); + return 1; } if (dev->sector > drive->spt) { ps1_hdc_log("HDC: get_sector: past end of sectors\n"); dev->ssb.mark_not_found = 1; - return (1); + return 1; } /* Calculate logical address (block number) of desired sector. */ *addr = ((((off64_t) dev->track * drive->hpc) + dev->head) * drive->spt) + dev->sector - 1; - return (0); + return 0; } static void @@ -590,21 +589,23 @@ do_seek(hdc_t *dev, drive_t *drive, uint16_t cyl) { if (cyl >= drive->tracks) { dev->ssb.cylinder_err = 1; - return (1); + return 1; } dev->track = cyl; drive->cur_cyl = dev->track; - return (0); + return 0; } /* Format a track or an entire drive. */ static void do_format(hdc_t *dev, drive_t *drive, ccb_t *ccb) { - int start_cyl, end_cyl; - int intr = 0, val; + int start_cyl; + int end_cyl; + int intr = 0; + int val; off64_t addr; #if 0 fcb_t *fcb; @@ -698,8 +699,9 @@ do_fmt: /* Done with this track. */ dev->state = STATE_FDONE; - /*FALLTHROUGH*/ - +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_FDONE: /* One more track done. */ if (++start_cyl == end_cyl) { @@ -713,6 +715,9 @@ do_fmt: /* This saves us a LOT of code. */ dev->state = STATE_FINIT; goto do_fmt; + + default: + break; } /* If we errored out, go back idle. */ @@ -871,6 +876,9 @@ do_send: /* This saves us a LOT of code. */ dev->state = STATE_SEND; goto do_send; + + default: + break; } break; @@ -1013,6 +1021,9 @@ do_recv: /* This saves us a LOT of code. */ dev->state = STATE_RECV; goto do_recv; + + default: + break; } break; @@ -1051,7 +1062,7 @@ do_recv: static void hdc_send_ssb(hdc_t *dev) { - drive_t *drive; + const drive_t *drive; /* We only support one drive, really, but ohwell. */ drive = &dev->drives[0]; @@ -1126,9 +1137,12 @@ hdc_read(uint16_t port, void *priv) ret = dev->intstat; dev->intstat = 0x00; break; + + default: + break; } - return (ret); + return ret; } static void @@ -1232,15 +1246,18 @@ hdc_write(uint16_t port, uint8_t val, void *priv) set_intr(dev, 1); } break; + + default: + break; } } static void * -ps1_hdc_init(const device_t *info) +ps1_hdc_init(UNUSED(const device_t *info)) { drive_t *drive; hdc_t *dev; - int c, i; + int c; /* Allocate and initialize device block. */ dev = malloc(sizeof(hdc_t)); @@ -1256,7 +1273,7 @@ ps1_hdc_init(const device_t *info) /* Load any disks for this device class. */ c = 0; - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if ((hdd[i].bus == HDD_BUS_XTA) && (hdd[i].xta_channel < 1)) { drive = &dev->drives[hdd[i].xta_channel]; @@ -1299,22 +1316,21 @@ ps1_hdc_init(const device_t *info) /* Create a timer for command delays. */ timer_add(&dev->timer, hdc_callback, dev, 0); - return (dev); + return dev; } static void ps1_hdc_close(void *priv) { - hdc_t *dev = (hdc_t *) priv; - drive_t *drive; - int d; + hdc_t *dev = (hdc_t *) priv; + const drive_t *drive; /* Remove the I/O handler. */ io_removehandler(dev->base, 5, hdc_read, NULL, NULL, hdc_write, NULL, NULL, dev); /* Close all disks and their images. */ - for (d = 0; d < XTA_NUM; d++) { + for (uint8_t d = 0; d < XTA_NUM; d++) { drive = &dev->drives[d]; if (drive->present) diff --git a/src/machine/m_ps2_isa.c b/src/machine/m_ps2_isa.c index af4fc5849..fa9c5acc2 100644 --- a/src/machine/m_ps2_isa.c +++ b/src/machine/m_ps2_isa.c @@ -72,6 +72,9 @@ ps2_write(uint16_t port, uint8_t val, void *priv) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2->ps2_102 = val; @@ -93,6 +96,9 @@ ps2_write(uint16_t port, uint8_t val, void *priv) case 0x0190: ps2->ps2_190 = val; break; + + default: + break; } } @@ -131,6 +137,9 @@ ps2_read(uint16_t port, void *priv) case 0x0190: temp = ps2->ps2_190; break; + + default: + break; } return temp; diff --git a/src/machine/m_ps2_mca.c b/src/machine/m_ps2_mca.c index 5057b65ea..b93f332db 100644 --- a/src/machine/m_ps2_mca.c +++ b/src/machine/m_ps2_mca.c @@ -68,15 +68,16 @@ #include <86box/serial.h> #include <86box/video.h> #include <86box/machine.h> +#include <86box/plat_unused.h> -static struct -{ +static struct ps2_t { uint8_t adapter_setup; uint8_t option[4]; uint8_t pos_vga; uint8_t setup; uint8_t sys_ctrl_port_a; - uint8_t subaddr_lo, subaddr_hi; + uint8_t subaddr_lo; + uint8_t subaddr_hi; uint8_t memory_bank[8]; @@ -88,11 +89,12 @@ static struct mem_mapping_t cache_mapping; uint8_t (*planar_read)(uint16_t port); - void (*planar_write)(uint16_t port, uint8_t val); + void (*planar_write)(uint16_t port, uint8_t val); uint8_t mem_regs[3]; - uint32_t split_addr, split_size; + uint32_t split_addr; + uint32_t split_size; uint32_t split_phys; uint8_t mem_pos_regs[8]; @@ -158,7 +160,7 @@ ps2_mca_log(const char *fmt, ...) #endif static uint8_t -ps2_read_cache_ram(uint32_t addr, void *priv) +ps2_read_cache_ram(uint32_t addr, UNUSED(void *priv)) { ps2_mca_log("ps2_read_cache_ram: addr=%08x %i %04x:%04x\n", addr, ps2_cache_valid[addr >> 3], CS, cpu_state.pc); if (!ps2_cache_valid[addr >> 3]) { @@ -170,7 +172,7 @@ ps2_read_cache_ram(uint32_t addr, void *priv) return ps2_cache[addr]; } static uint16_t -ps2_read_cache_ramw(uint32_t addr, void *priv) +ps2_read_cache_ramw(uint32_t addr, UNUSED(void *priv)) { ps2_mca_log("ps2_read_cache_ramw: addr=%08x %i %04x:%04x\n", addr, ps2_cache_valid[addr >> 3], CS, cpu_state.pc); if (!ps2_cache_valid[addr >> 3]) { @@ -182,7 +184,7 @@ ps2_read_cache_ramw(uint32_t addr, void *priv) return *(uint16_t *) &ps2_cache[addr]; } static uint32_t -ps2_read_cache_raml(uint32_t addr, void *priv) +ps2_read_cache_raml(uint32_t addr, UNUSED(void *priv)) { ps2_mca_log("ps2_read_cache_raml: addr=%08x %i %04x:%04x\n", addr, ps2_cache_valid[addr >> 3], CS, cpu_state.pc); if (!ps2_cache_valid[addr >> 3]) { @@ -194,7 +196,7 @@ ps2_read_cache_raml(uint32_t addr, void *priv) return *(uint32_t *) &ps2_cache[addr]; } static void -ps2_write_cache_ram(uint32_t addr, uint8_t val, void *priv) +ps2_write_cache_ram(uint32_t addr, uint8_t val, UNUSED(void *priv)) { ps2_mca_log("ps2_write_cache_ram: addr=%08x val=%02x %04x:%04x %i\n", addr, val, CS, cpu_state.pc); ps2_cache[addr] = val; @@ -268,6 +270,9 @@ model_50_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -292,6 +297,9 @@ model_55sx_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -316,6 +324,9 @@ model_70_type3_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -340,6 +351,9 @@ model_80_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -373,6 +387,9 @@ model_50_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -392,18 +409,23 @@ model_50_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } static void model_55sx_mem_recalc(void) { - int i, j, state; + int state; #ifdef ENABLE_PS2_MCA_LOG int enabled_mem = 0; #endif - int base = 0, remap_size = (ps2.option[3] & 0x10) ? 384 : 256; - int bit_mask = 0x00, max_rows = 4; + int base = 0; + int remap_size = (ps2.option[3] & 0x10) ? 384 : 256; + int bit_mask = 0x00; + int max_rows = 4; int bank_to_rows[16] = { 4, 2, 1, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 2, 1, 0 }; ps2_mca_log("%02X %02X\n", ps2.option[1], ps2.option[3]); @@ -412,13 +434,13 @@ model_55sx_mem_recalc(void) mem_set_mem_state(0x00000000, (mem_size + 384) * 1024, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); mem_set_mem_state(0x000e0000, 0x00020000, MEM_READ_EXTANY | MEM_WRITE_DISABLED); - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { max_rows = bank_to_rows[(ps2.memory_bank[i] >> 4) & 0x0f]; if (max_rows == 0) continue; - for (j = 0; j < max_rows; j++) { + for (int j = 0; j < max_rows; j++) { if (ps2.memory_bank[i] & (1 << j)) { ps2_mca_log("Set memory at %06X-%06X to internal\n", (base * 1024), (base * 1024) + (((base > 0) ? 1024 : 640) * 1024) - 1); mem_set_mem_state(base * 1024, ((base > 0) ? 1024 : 640) * 1024, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); @@ -456,11 +478,12 @@ model_55sx_mem_recalc(void) mem_set_mem_state(0xe0000, 0x20000, state); - /* if (!(ps2.option[3] & 0x08)) - { +#if 0 + if (!(ps2.option[3] & 0x08)) { ps2_mca_log("Memory not yet configured\n"); return; - } */ + } +#endif ps2_mca_log("Enable shadow mapping at %06X-%06X\n", (mem_size * 1024), (mem_size * 1024) + (remap_size * 1024) - 1); @@ -501,6 +524,9 @@ model_55sx_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -527,6 +553,9 @@ model_55sx_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } @@ -558,6 +587,9 @@ model_70_type3_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -579,6 +611,9 @@ model_70_type3_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } @@ -610,6 +645,9 @@ model_80_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -629,17 +667,22 @@ model_80_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } uint8_t -ps2_mca_read(uint16_t port, void *p) +ps2_mca_read(uint16_t port, UNUSED(void *priv)) { uint8_t temp; switch (port) { case 0x91: - // fatal("Read 91 setup=%02x adapter=%02x\n", ps2.setup, ps2.adapter_setup); +#if 0 + fatal("Read 91 setup=%02x adapter=%02x\n", ps2.setup, ps2.adapter_setup); +#endif if (!(ps2.setup & PS2_SETUP_IO)) temp = 0x00; else if (!(ps2.setup & PS2_SETUP_VGA)) @@ -738,7 +781,7 @@ ps2_mca_read(uint16_t port, void *p) } static void -ps2_mca_write(uint16_t port, uint8_t val, void *p) +ps2_mca_write(uint16_t port, uint8_t val, UNUSED(void *priv)) { ps2_mca_log("ps2_write: port=%04x val=%02x %04x:%04x\n", port, val, CS, cpu_state.pc); @@ -761,7 +804,7 @@ ps2_mca_write(uint16_t port, uint8_t val, void *p) case 0x101: if (!(ps2.setup & PS2_SETUP_IO)) ps2.planar_write(port, val); - else if ((ps2.setup & PS2_SETUP_VGA) && (ps2.setup & PS2_SETUP_VGA) && (ps2.adapter_setup & PS2_ADAPTER_SETUP)) + else if ((ps2.setup & PS2_SETUP_VGA) && (ps2.adapter_setup & PS2_ADAPTER_SETUP)) mca_write(port, val); break; case 0x102: @@ -802,6 +845,9 @@ ps2_mca_write(uint16_t port, uint8_t val, void *p) else if (ps2.adapter_setup & PS2_ADAPTER_SETUP) mca_write(port, val); break; + + default: + break; } } @@ -822,13 +868,13 @@ ps2_mca_board_common_init(void) } static uint8_t -ps2_mem_expansion_read(int port, void *p) +ps2_mem_expansion_read(int port, UNUSED(void *priv)) { return ps2.mem_pos_regs[port & 7]; } static void -ps2_mem_expansion_write(int port, uint8_t val, void *p) +ps2_mem_expansion_write(int port, uint8_t val, UNUSED(void *priv)) { if (port < 0x102 || port == 0x104) return; @@ -842,7 +888,7 @@ ps2_mem_expansion_write(int port, uint8_t val, void *p) } static uint8_t -ps2_mem_expansion_feedb(void *p) +ps2_mem_expansion_feedb(UNUSED(void *priv)) { return (ps2.mem_pos_regs[2] & 1); } @@ -850,7 +896,8 @@ ps2_mem_expansion_feedb(void *p) static void ps2_mca_mem_fffc_init(int start_mb) { - uint32_t planar_size, expansion_start; + uint32_t planar_size; + uint32_t expansion_start; planar_size = (start_mb - 1) << 20; expansion_start = start_mb << 20; @@ -885,6 +932,9 @@ ps2_mca_mem_fffc_init(int start_mb) case 8: ps2.mem_pos_regs[4] = 0xaa; /* 10 10 10 10 = 2 2 2 2 */ break; + + default: + break; } mca_add(ps2_mem_expansion_read, ps2_mem_expansion_write, ps2_mem_expansion_feedb, NULL, NULL); @@ -906,7 +956,8 @@ ps2_mca_mem_fffc_init(int start_mb) static void ps2_mca_mem_d071_init(int start_mb) { - uint32_t planar_size, expansion_start; + uint32_t planar_size; + uint32_t expansion_start; planar_size = (start_mb - 1) << 20; expansion_start = start_mb << 20; @@ -984,9 +1035,6 @@ ps2_mca_board_model_55sx_init(int has_sec_nvram, int slots) ps2.memory_bank[1] = 0x61; break; case 6: - ps2.memory_bank[0] = 0x01; - ps2.memory_bank[1] = 0x51; - break; case 7: /*Not supported*/ ps2.memory_bank[0] = 0x01; ps2.memory_bank[1] = 0x51; @@ -995,10 +1043,13 @@ ps2_mca_board_model_55sx_init(int has_sec_nvram, int slots) ps2.memory_bank[0] = 0x01; ps2.memory_bank[1] = 0x01; break; + + default: + break; } mca_init(slots); - device_add(&keyboard_ps2_mca_device); + device_add(&keyboard_ps2_device); if (has_sec_nvram == 1) device_add(&ps2_nvr_55ls_device); @@ -1067,18 +1118,21 @@ mem_encoding_update(void) } static uint8_t -mem_encoding_read(uint16_t addr, void *p) +mem_encoding_read(uint16_t addr, UNUSED(void *priv)) { switch (addr) { case 0xe0: return ps2.mem_regs[0]; case 0xe1: return ps2.mem_regs[1]; + + default: + break; } return 0xff; } static void -mem_encoding_write(uint16_t addr, uint8_t val, void *p) +mem_encoding_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { switch (addr) { case 0xe0: @@ -1087,12 +1141,15 @@ mem_encoding_write(uint16_t addr, uint8_t val, void *p) case 0xe1: ps2.mem_regs[1] = val; break; + + default: + break; } mem_encoding_update(); } static uint8_t -mem_encoding_read_cached(uint16_t addr, void *p) +mem_encoding_read_cached(uint16_t addr, UNUSED(void *priv)) { switch (addr) { case 0xe0: @@ -1101,12 +1158,15 @@ mem_encoding_read_cached(uint16_t addr, void *p) return ps2.mem_regs[1]; case 0xe2: return ps2.mem_regs[2]; + + default: + break; } return 0xff; } static void -mem_encoding_write_cached(uint16_t addr, uint8_t val, void *p) +mem_encoding_write_cached(uint16_t addr, uint8_t val, UNUSED(void *priv)) { uint8_t old; @@ -1141,6 +1201,9 @@ mem_encoding_write_cached(uint16_t addr, uint8_t val, void *p) ram_mid_mapping.flags &= ~MEM_MAPPING_ROM_WS; #endif break; + + default: + break; } ps2_mca_log("mem_encoding_write: addr=%02x val=%02x %04x:%04x %02x %02x\n", addr, val, CS, cpu_state.pc, ps2.mem_regs[1], ps2.mem_regs[2]); mem_encoding_update(); @@ -1162,7 +1225,7 @@ ps2_mca_board_model_70_type34_init(int is_type4, int slots) ps2.split_addr = mem_size * 1024; mca_init(slots); - device_add(&keyboard_ps2_mca_device); + device_add(&keyboard_ps2_device); ps2.planar_read = model_70_type3_read; ps2.planar_write = model_70_type3_write; @@ -1212,7 +1275,7 @@ ps2_mca_board_model_70_type34_init(int is_type4, int slots) mem_mapping_add(&ps2.cache_mapping, 0, - (is_type4) ? (8 * 1024) : (64 * 1024), + is_type4 ? (8 * 1024) : (64 * 1024), ps2_read_cache_ram, ps2_read_cache_ramw, ps2_read_cache_raml, @@ -1249,13 +1312,13 @@ ps2_mca_board_model_70_type34_init(int is_type4, int slots) } static void -ps2_mca_board_model_80_type2_init(int is486) +ps2_mca_board_model_80_type2_init(int is486ps2) { ps2_mca_board_common_init(); ps2.split_addr = mem_size * 1024; mca_init(8); - device_add(&keyboard_ps2_mca_device); + device_add(&keyboard_ps2_device); ps2.planar_read = model_80_read; ps2.planar_write = model_80_write; @@ -1309,7 +1372,7 @@ ps2_mca_board_model_80_type2_init(int is486) NULL); mem_mapping_disable(&ps2.split_mapping); - if ((mem_size > 4096) && !is486) { + if ((mem_size > 4096) && !is486ps2) { /* Only 4 MB supported on planar, create a memory expansion card for the rest */ if (mem_size > 12288) ps2_mca_mem_d071_init(4); @@ -1492,3 +1555,24 @@ machine_ps2_model_80_axx_init(const machine_t *model) return ret; } + +int +machine_ps2_model_70_type4_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/ibmps2_m70_type4/64F3126.BIN", + "roms/machines/ibmps2_m70_type4/64F3125.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_ps2_common_init(model); + + ps2.planar_id = 0xf9ff; + + ps2_mca_board_model_70_type34_init(1, 4); + + return ret; +} diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index 04f5e5381..5784eb4df 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -43,6 +43,7 @@ #include <86box/video.h> #include <86box/vid_cga_comp.h> #include <86box/machine.h> +#include <86box/plat_unused.h> enum { TANDY_RGB = 0, @@ -62,7 +63,7 @@ enum { EEPROM_WRITE }; -typedef struct { +typedef struct t1kvid_t { mem_mapping_t mapping; mem_mapping_t vram_mapping; @@ -72,36 +73,41 @@ typedef struct { int array_index; uint8_t array[256]; int memctrl; - uint8_t mode, col; + uint8_t mode; + uint8_t col; uint8_t stat; - uint8_t *vram, *b8000; + uint8_t *vram; + uint8_t *b8000; uint32_t b8000_mask; uint32_t b8000_limit; uint8_t planar_ctrl; - int linepos, - displine; - int sc, vc; - int dispon; - int con, coff, - cursoron, - blink; + int linepos; + int displine; + int sc; + int vc; + int dispon; + int con; + int coff; + int cursoron; + int blink; int fullchange; int vsynctime; int vadj; - uint16_t ma, maback; + uint16_t ma; + uint16_t maback; - uint64_t dispontime, - dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, - lastline; + int firstline; + int lastline; int composite; } t1kvid_t; -typedef struct { +typedef struct t1keep_t { char *path; int state; @@ -112,7 +118,7 @@ typedef struct { uint16_t store[64]; } t1keep_t; -typedef struct { +typedef struct tandy_t { mem_mapping_t ram_mapping; mem_mapping_t rom_mapping; /* SL2 */ @@ -448,7 +454,9 @@ recalc_timings(tandy_t *dev) { t1kvid_t *vid = dev->vid; - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; if (vid->mode & 1) { disptime = vid->crtc[0] + 1; @@ -571,15 +579,18 @@ vid_out(uint16_t addr, uint8_t val, void *priv) vid->planar_ctrl = val; recalc_mapping(dev); break; + + default: + break; } } static uint8_t vid_in(uint16_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; - uint8_t ret = 0xff; + const tandy_t *dev = (tandy_t *) priv; + const t1kvid_t *vid = dev->vid; + uint8_t ret = 0xff; if ((addr >= 0x3d0) && (addr <= 0x3d7)) addr = (addr & 0xff9) | 0x004; @@ -596,9 +607,12 @@ vid_in(uint16_t addr, void *priv) case 0x03da: ret = vid->stat; break; + + default: + break; } - return (ret); + return ret; } static void @@ -625,11 +639,11 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t vid_read(uint32_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; + const tandy_t *dev = (tandy_t *) priv; + const t1kvid_t *vid = dev->vid; if (vid->memctrl == -1) - return (0xff); + return 0xff; if (dev->is_sl2) { if (vid->array[5] & 1) @@ -637,7 +651,7 @@ vid_read(uint32_t addr, void *priv) if ((addr & 0x7fff) < vid->b8000_limit) return (vid->b8000[addr & 0x7fff]); else - return (0xff); + return 0xff; } else { return (vid->b8000[addr & vid->b8000_mask]); } @@ -650,9 +664,13 @@ vid_poll(void *priv) t1kvid_t *vid = dev->vid; uint16_t ca = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int c; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t dat; int cols[4]; int col; @@ -674,25 +692,25 @@ vid_poll(void *priv) cols[0] = (vid->array[2] & 0xf) + 16; for (c = 0; c < 8; c++) { if (vid->array[3] & 4) { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = cols[0]; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = cols[0]; if (vid->mode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = cols[0]; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = cols[0]; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = cols[0]; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = cols[0]; } } else if ((vid->mode & 0x12) == 0x12) { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = 0; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = 0; if (vid->mode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; } } else { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->col & 15) + 16; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->col & 15) + 16; if (vid->mode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = (vid->col & 15) + 16; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = (vid->col & 15) + 16; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->col & 15) + 16; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->col & 15) + 16; } } } @@ -700,19 +718,19 @@ vid_poll(void *priv) for (x = 0; x < vid->crtc[1] * 2; x++) { dat = (vid->vram[(vid->ma << 1) & 0xffff] << 8) | vid->vram[((vid->ma << 1) + 1) & 0xffff]; vid->ma++; - buffer32->line[(vid->displine << 1)][(x << 2) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 8] = vid->array[((dat >> 12) & 0xf) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 2) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 9] = vid->array[((dat >> 8) & 0xf) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 2) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 10] = vid->array[((dat >> 4) & 0xf) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 2) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 11] = vid->array[(dat & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 8] = vid->array[((dat >> 12) & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 9] = vid->array[((dat >> 8) & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 10] = vid->array[((dat >> 4) & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 11] = vid->array[(dat & 0xf) + 16] + 16; } } else if ((vid->array[3] & 0x10) && (vid->mode & 1)) { /*320x200x16*/ for (x = 0; x < vid->crtc[1]; x++) { dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000) + 1]; vid->ma++; - buffer32->line[(vid->displine << 1)][(x << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8] = buffer32->line[(vid->displine << 1)][(x << 3) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 9] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 3) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 10] = buffer32->line[(vid->displine << 1)][(x << 3) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 11] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 3) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 12] = buffer32->line[(vid->displine << 1)][(x << 3) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 13] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 3) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 14] = buffer32->line[(vid->displine << 1)][(x << 3) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 15] = vid->array[(dat & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8] = buffer32->line[vid->displine << 1][(x << 3) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 9] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 10] = buffer32->line[vid->displine << 1][(x << 3) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 11] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 12] = buffer32->line[vid->displine << 1][(x << 3) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 13] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 14] = buffer32->line[vid->displine << 1][(x << 3) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 15] = vid->array[(dat & vid->array[1]) + 16] + 16; } } else if (vid->array[3] & 0x10) { /*160x200x16*/ for (x = 0; x < vid->crtc[1]; x++) { @@ -722,10 +740,10 @@ vid_poll(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000) + 1]; } vid->ma++; - buffer32->line[(vid->displine << 1)][(x << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 9] = buffer32->line[(vid->displine << 1)][(x << 4) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 10] = buffer32->line[(vid->displine << 1)][(x << 4) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 11] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 4) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 12] = buffer32->line[(vid->displine << 1)][(x << 4) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 13] = buffer32->line[(vid->displine << 1)][(x << 4) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 14] = buffer32->line[(vid->displine << 1)][(x << 4) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 15] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 4) + 16] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 16] = buffer32->line[(vid->displine << 1)][(x << 4) + 17] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 17] = buffer32->line[(vid->displine << 1)][(x << 4) + 18] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 18] = buffer32->line[(vid->displine << 1)][(x << 4) + 19] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 19] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 4) + 20] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 20] = buffer32->line[(vid->displine << 1)][(x << 4) + 21] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 21] = buffer32->line[(vid->displine << 1)][(x << 4) + 22] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 22] = buffer32->line[(vid->displine << 1)][(x << 4) + 23] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 23] = vid->array[(dat & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 8] = buffer32->line[vid->displine << 1][(x << 4) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 9] = buffer32->line[vid->displine << 1][(x << 4) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 10] = buffer32->line[vid->displine << 1][(x << 4) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 11] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 12] = buffer32->line[vid->displine << 1][(x << 4) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 13] = buffer32->line[vid->displine << 1][(x << 4) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 14] = buffer32->line[vid->displine << 1][(x << 4) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 15] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 16] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 16] = buffer32->line[vid->displine << 1][(x << 4) + 17] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 17] = buffer32->line[vid->displine << 1][(x << 4) + 18] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 18] = buffer32->line[vid->displine << 1][(x << 4) + 19] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 19] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 20] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 20] = buffer32->line[vid->displine << 1][(x << 4) + 21] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 21] = buffer32->line[vid->displine << 1][(x << 4) + 22] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 22] = buffer32->line[vid->displine << 1][(x << 4) + 23] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 23] = vid->array[(dat & vid->array[1]) + 16] + 16; } } else if (vid->array[3] & 0x08) { /*640x200x4 - this implementation is a complete guess!*/ for (x = 0; x < vid->crtc[1]; x++) { @@ -734,7 +752,7 @@ vid_poll(void *priv) for (c = 0; c < 8; c++) { chr = (dat >> 6) & 2; chr |= ((dat >> 15) & 1); - buffer32->line[(vid->displine << 1)][(x << 3) + 8 + c] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8 + c] = vid->array[(chr & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 8 + c] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8 + c] = vid->array[(chr & vid->array[1]) + 16] + 16; dat <<= 1; } } @@ -754,20 +772,20 @@ vid_poll(void *priv) } if (vid->sc & 8) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; } } else { for (c = 0; c < 8; c++) { if (vid->sc == 8) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; } else { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] ^= 15; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] ^= 15; buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] ^= 15; } } @@ -790,19 +808,19 @@ vid_poll(void *priv) vid->ma++; if (vid->sc & 8) { for (c = 0; c < 8; c++) - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = cols[0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; } else { for (c = 0; c < 8; c++) { if (vid->sc == 8) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; } else { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } if (drawcursor) { for (c = 0; c < 16; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + c + 8] ^= 15; + buffer32->line[vid->displine << 1][(x << 4) + c + 8] ^= 15; buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] ^= 15; } } @@ -831,7 +849,7 @@ vid_poll(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000) + 1]; vid->ma++; for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; dat <<= 2; } } @@ -842,7 +860,7 @@ vid_poll(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000) + 1]; vid->ma++; for (c = 0; c < 16; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; + buffer32->line[vid->displine << 1][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; dat <<= 1; } } @@ -873,7 +891,7 @@ vid_poll(void *priv) else x = (vid->crtc[1] << 4) + 16; if (!dev->is_sl2 && vid->composite) { - Composite_Process(vid->mode, 0, x >> 2, buffer32->line[(vid->displine << 1)]); + Composite_Process(vid->mode, 0, x >> 2, buffer32->line[vid->displine << 1]); Composite_Process(vid->mode, 0, x >> 2, buffer32->line[(vid->displine << 1) + 1]); } else { video_process_8(x, vid->displine << 1); @@ -961,7 +979,7 @@ vid_poll(void *priv) if (!enable_overscan) xs_temp -= 16; - if (((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) { + if ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get()) { xsize = xs_temp; ysize = ys_temp; set_screen_size(xsize, ysize + (enable_overscan ? 16 : 0)); @@ -1015,7 +1033,7 @@ vid_poll(void *priv) vid->sc &= 31; vid->ma = vid->maback; } - if ((vid->sc == (vid->crtc[10] & 31) || ((vid->crtc[8] & 3) == 3 && vid->sc == ((vid->crtc[10] & 31) >> 1)))) + if (vid->sc == (vid->crtc[10] & 31) || ((vid->crtc[8] & 3) == 3 && vid->sc == ((vid->crtc[10] & 31) >> 1))) vid->con = 1; } } @@ -1133,7 +1151,7 @@ const device_t vid_device_sl = { }; static void -eep_write(uint16_t addr, uint8_t val, void *priv) +eep_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { t1keep_t *eep = (t1keep_t *) priv; @@ -1160,6 +1178,9 @@ eep_write(uint16_t addr, uint8_t val, void *priv) eep->state = EEPROM_GET_OPERATION; eep->count = 0; break; + + default: + break; } break; @@ -1205,6 +1226,9 @@ eep_write(uint16_t addr, uint8_t val, void *priv) eep->store[eep->addr] = eep->data; } break; + + default: + break; } eep->clk = val & 4; @@ -1227,6 +1251,9 @@ eep_init(const device_t *info) case TYPE_TANDY1000SL2: eep->path = "tandy1000sl2.bin"; break; + + default: + break; } f = nvr_fopen(eep->path, "rb"); @@ -1239,7 +1266,7 @@ eep_init(const device_t *info) io_sethandler(0x037c, 1, NULL, NULL, NULL, eep_write, NULL, NULL, eep); - return (eep); + return eep; } static void @@ -1313,14 +1340,18 @@ tandy_write(uint16_t addr, uint8_t val, void *priv) dev->rom_offset = ((val ^ 4) & 7) * 0x10000; mem_mapping_set_exec(&dev->rom_mapping, &dev->rom[dev->rom_offset]); + break; + + default: + break; } } static uint8_t tandy_read(uint16_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - uint8_t ret = 0xff; + const tandy_t *dev = (tandy_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0x00a0: @@ -1334,15 +1365,18 @@ tandy_read(uint16_t addr, void *priv) case 0xffea: ret = (dev->rom_bank ^ 0x10); break; + + default: + break; } - return (ret); + return ret; } static void write_ram(uint32_t addr, uint8_t val, void *priv) { - tandy_t *dev = (tandy_t *) priv; + const tandy_t *dev = (tandy_t *) priv; ram[dev->base + (addr & 0x1ffff)] = val; } @@ -1350,7 +1384,7 @@ write_ram(uint32_t addr, uint8_t val, void *priv) static uint8_t read_ram(uint32_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; + const tandy_t *dev = (tandy_t *) priv; return (ram[dev->base + (addr & 0x1ffff)]); } @@ -1358,8 +1392,8 @@ read_ram(uint32_t addr, void *priv) static uint8_t read_rom(uint32_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - uint32_t addr2 = (addr & 0xffff) + dev->rom_offset; + const tandy_t *dev = (tandy_t *) priv; + uint32_t addr2 = (addr & 0xffff) + dev->rom_offset; return (dev->rom[addr2]); } @@ -1469,6 +1503,9 @@ machine_tandy1k_init(const machine_t *model, int type) device_add(&pssj_device); device_add(&eep_1000sl2_device); break; + + default: + break; } standalone_gameport_type = &gameport_device; @@ -1479,7 +1516,7 @@ machine_tandy1k_init(const machine_t *model, int type) int tandy1k_eeprom_read(void) { - return (eep_data_out); + return eep_data_out; } int diff --git a/src/machine/m_v86p.c b/src/machine/m_v86p.c index af90ab629..54af9b053 100644 --- a/src/machine/m_v86p.c +++ b/src/machine/m_v86p.c @@ -51,7 +51,8 @@ int machine_v86p_init(const machine_t *model) { - int ret, rom = 0; + int ret; + int rom_id = 0; ret = bios_load_interleavedr("roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_122089_Even.rom", "roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_122089_Odd.rom", @@ -59,7 +60,7 @@ machine_v86p_init(const machine_t *model) if (!ret) { /* Try an older version of the BIOS. */ - rom = 1; + rom_id = 1; ret = bios_load_interleavedr("roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_090489_Even.rom", "roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_090489_Odd.rom", 0x000f8000, 65536, 0); @@ -67,7 +68,7 @@ machine_v86p_init(const machine_t *model) if (!ret) { /* Try JVERNET's BIOS. */ - rom = 2; + rom_id = 2; ret = bios_load_linear("roms/machines/v86p/V86P.ROM", 0x000f0000, 65536, 0); } @@ -75,7 +76,7 @@ machine_v86p_init(const machine_t *model) if (bios_only || !ret) return ret; - if (rom == 2) + if (rom_id == 2) loadfont("roms/machines/v86p/V86P.FON", 8); else loadfont("roms/machines/v86p/v86pfont.rom", 8); diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index b8d318438..84eb517c8 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -67,7 +67,8 @@ machine_pc_init(const machine_t *model) int machine_pc82_init(const machine_t *model) { - int ret, ret2; + int ret; + int ret2; ret = bios_load_linear("roms/machines/ibmpc82/pc102782.bin", 0x000fe000, 40960, 0); diff --git a/src/machine/m_xt_laserxt.c b/src/machine/m_xt_laserxt.c index 418835a0b..87c2fe362 100644 --- a/src/machine/m_xt_laserxt.c +++ b/src/machine/m_xt_laserxt.c @@ -19,6 +19,7 @@ #include <86box/fdc_ext.h> #include <86box/gameport.h> #include <86box/keyboard.h> +#include <86box/plat_unused.h> static int laserxt_emspage[4]; static int laserxt_emscontrol[4]; @@ -37,10 +38,10 @@ get_laserxt_ems_addr(uint32_t addr) } static void -laserxt_write(uint16_t port, uint8_t val, void *priv) +laserxt_write(uint16_t port, uint8_t val, UNUSED(void *priv)) { - int i; - uint32_t paddr, vaddr; + uint32_t paddr; + uint32_t vaddr; switch (port) { case 0x0208: case 0x4208: @@ -63,7 +64,7 @@ laserxt_write(uint16_t port, uint8_t val, void *priv) case 0xC209: laserxt_emscontrol[port >> 14] = val; laserxt_ems_baseaddr_index = 0; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { laserxt_ems_baseaddr_index |= (laserxt_emscontrol[i] & 0x80) >> (7 - i); } @@ -73,11 +74,14 @@ laserxt_write(uint16_t port, uint8_t val, void *priv) mem_mapping_set_addr(&laserxt_ems_mapping[3], 0xCC000 + (((laserxt_ems_baseaddr_index + 1) & 0x0C) << 14), 0x4000); flushmmucache(); break; + + default: + break; } } static uint8_t -laserxt_read(uint16_t port, void *priv) +laserxt_read(uint16_t port, UNUSED(void *priv)) { switch (port) { case 0x0208: @@ -90,13 +94,15 @@ laserxt_read(uint16_t port, void *priv) case 0x8209: case 0xC209: return laserxt_emscontrol[port >> 14]; + + default: break; } return 0xff; } static void -mem_write_laserxtems(uint32_t addr, uint8_t val, void *priv) +mem_write_laserxtems(uint32_t addr, uint8_t val, UNUSED(void *priv)) { addr = get_laserxt_ems_addr(addr); if (addr < (mem_size << 10)) @@ -104,7 +110,7 @@ mem_write_laserxtems(uint32_t addr, uint8_t val, void *priv) } static uint8_t -mem_read_laserxtems(uint32_t addr, void *priv) +mem_read_laserxtems(uint32_t addr, UNUSED(void *priv)) { uint8_t val = 0xFF; addr = get_laserxt_ems_addr(addr); @@ -116,8 +122,6 @@ mem_read_laserxtems(uint32_t addr, void *priv) static void laserxt_init(int is_lxt3) { - int i; - if (mem_size > 640) { io_sethandler(0x0208, 0x0002, laserxt_read, NULL, NULL, laserxt_write, NULL, NULL, NULL); io_sethandler(0x4208, 0x0002, laserxt_read, NULL, NULL, laserxt_write, NULL, NULL, NULL); @@ -126,7 +130,7 @@ laserxt_init(int is_lxt3) mem_mapping_set_addr(&ram_low_mapping, 0, !is_lxt3 ? 0x70000 + (((mem_size + 64) & 255) << 10) : 0x30000 + (((mem_size + 320) & 511) << 10)); } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { laserxt_emspage[i] = 0x7F; laserxt_emscontrol[i] = (i == 3) ? 0x00 : 0x80; mem_mapping_add(&laserxt_ems_mapping[i], 0xE0000 + (i << 14), 0x4000, mem_read_laserxtems, NULL, NULL, mem_write_laserxtems, NULL, NULL, ram + 0xA0000 + (i << 14), 0, NULL); diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index e9c24f88f..0a638ce37 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -57,6 +57,7 @@ #include <86box/vid_ogc.h> #include <86box/vid_colorplus.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> #define STAT_PARITY 0x80 #define STAT_RTIMEOUT 0x40 @@ -115,7 +116,7 @@ enum MM58274_ADDR { static struct tm intclk; -typedef struct { +typedef struct m24_kbd_t { /* Keyboard stuff. */ int wantirq; uint8_t command; @@ -123,26 +124,28 @@ typedef struct { uint8_t out; uint8_t output_port; uint8_t id; - int param, - param_total; + int param; + int param_total; uint8_t params[16]; uint8_t scan[7]; /* Mouse stuff. */ int mouse_mode; - int x, y, b; + int x; + int y; + int b; pc_timer_t send_delay_timer; } m24_kbd_t; -typedef struct { +typedef struct m19_vid_t { ogc_t ogc; colorplus_t colorplus; int mode; } m19_vid_t; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; video_timings_t timing_m19_vid = { VIDEO_ISA, 8, 16, 32, 8, 16, 32 }; @@ -346,7 +349,7 @@ mm58274_time_set(uint8_t *regs, struct tm *tm) regs[MM58274_HOUR10] = (tm->tm_hour / 10); } else { regs[MM58274_HOUR1] = ((tm->tm_hour % 12) % 10); - regs[MM58274_HOUR10] = (((tm->tm_hour % 12) / 10)); + regs[MM58274_HOUR10] = ((tm->tm_hour % 12) / 10); if (tm->tm_hour >= 12) regs[MM58274_SETTINGS] |= 0x04; else @@ -419,7 +422,7 @@ mm58274_write(uint16_t addr, uint8_t val, void *priv) val &= 0x0f; /* Update non-read-only changed values if not synchronizing time to host */ - if ((addr != MM58274_TENTHS)) + if (addr != MM58274_TENTHS) if ((nvr->regs[addr] != val) && !(time_sync & TIME_SYNC_ENABLED)) nvr_dosave = 1; @@ -439,7 +442,7 @@ mm58274_write(uint16_t addr, uint8_t val, void *priv) static uint8_t mm58274_read(uint16_t addr, void *priv) { - nvr_t *nvr = (nvr_t *) priv; + const nvr_t *nvr = (nvr_t *) priv; addr &= 0x0f; @@ -635,6 +638,10 @@ m24_kbd_write(uint16_t port, uint8_t val, void *priv) if (val == 0x02) m24_kbd_adddata(0x00); + break; + + default: + break; } } @@ -680,7 +687,7 @@ m24_kbd_read(uint16_t port, void *priv) xt_olivetti_log("\nBad M24 keyboard read %04X\n", port); } - return (ret); + return ret; } static void @@ -725,7 +732,7 @@ m24_kbd_reset(void *priv) } static int -ms_poll(int x, int y, int z, int b, void *priv) +ms_poll(int x, int y, UNUSED(int z), int b, void *priv) { m24_kbd_t *m24_kbd = (m24_kbd_t *) priv; @@ -733,7 +740,7 @@ ms_poll(int x, int y, int z, int b, void *priv) m24_kbd->y += y; if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; if ((b & 1) && !(m24_kbd->b & 1)) m24_kbd_adddata(m24_kbd->scan[0]); @@ -742,7 +749,7 @@ ms_poll(int x, int y, int z, int b, void *priv) m24_kbd->b = (m24_kbd->b & ~1) | (b & 1); if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; if ((b & 2) && !(m24_kbd->b & 2)) m24_kbd_adddata(m24_kbd->scan[2]); @@ -751,7 +758,7 @@ ms_poll(int x, int y, int z, int b, void *priv) m24_kbd->b = (m24_kbd->b & ~2) | (b & 2); if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; if ((b & 4) && !(m24_kbd->b & 4)) m24_kbd_adddata(m24_kbd->scan[1]); @@ -761,10 +768,10 @@ ms_poll(int x, int y, int z, int b, void *priv) if (m24_kbd->mouse_mode) { if (((key_queue_end - key_queue_start) & 0xf) > 12) - return (0xff); + return 0xff; if (!m24_kbd->x && !m24_kbd->y) - return (0xff); + return 0xff; m24_kbd->y = -m24_kbd->y; @@ -790,31 +797,31 @@ ms_poll(int x, int y, int z, int b, void *priv) } else { while (m24_kbd->x < -4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->x += 4; m24_kbd_adddata(m24_kbd->scan[3]); } while (m24_kbd->x > 4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->x -= 4; m24_kbd_adddata(m24_kbd->scan[4]); } while (m24_kbd->y < -4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->y += 4; m24_kbd_adddata(m24_kbd->scan[5]); } while (m24_kbd->y > 4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->y -= 4; m24_kbd_adddata(m24_kbd->scan[6]); } } - return (0); + return 0; } /* Remapping as follows: @@ -1492,12 +1499,16 @@ m19_vid_init(m19_vid_t *vid) { device_context(&m19_vid_device); - /* int display_type; */ +#if 0 + int display_type; +#endif vid->mode = OLIVETTI_OGC_MODE; video_inform(VIDEO_FLAG_TYPE_CGA, &timing_m19_vid); - /* display_type = device_get_config_int("display_type"); */ +#if 0 + display_type = device_get_config_int("display_type"); +#endif /* OGC emulation part begin */ loadfont_ex("roms/machines/m19/BIOS.BIN", 1, 90); @@ -1508,7 +1519,9 @@ m19_vid_init(m19_vid_t *vid) vid->ogc.cga.vram = malloc(0x8000); - /* cga_comp_init(vid->ogc.cga.revision); */ +#if 0 + cga_comp_init(vid->ogc.cga.revision); +#endif vid->ogc.cga.rgb_type = device_get_config_int("rgb_type"); cga_palette = (vid->ogc.cga.rgb_type << 1); @@ -1525,11 +1538,15 @@ m19_vid_init(m19_vid_t *vid) /* Plantronics emulation part begin*/ /* composite is not working yet */ vid->colorplus.cga.composite = 0; //(display_type != CGA_RGB); - /* vid->colorplus.cga.snow_enabled = device_get_config_int("snow_enabled"); */ +#if 0 + vid->colorplus.cga.snow_enabled = device_get_config_int("snow_enabled"); +#endif vid->colorplus.cga.vram = malloc(0x8000); - /* vid->colorplus.cga.cgamode = 0x1; */ +#if 0 + vid->colorplus.cga.cgamode = 0x1; +#endif /* Plantronics emulation part end*/ timer_add(&vid->ogc.cga.timer, ogc_poll, &vid->ogc, 1); @@ -1602,10 +1619,10 @@ const device_t m19_vid_device = { }; static uint8_t -m24_read(uint16_t port, void *priv) +m24_read(uint16_t port, UNUSED(void *priv)) { - uint8_t ret = 0x00; - int i, fdd_count = 0; + uint8_t ret = 0x00; + int fdd_count = 0; switch (port) { case 0x62: @@ -1674,7 +1691,7 @@ m24_read(uint16_t port, void *priv) * on on EGA/VGA (works only for BIOS ROM 1.43) */ case 0x67: - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -1706,16 +1723,19 @@ m24_read(uint16_t port, void *priv) /* 1 = 720 kB (3.5"), 0 = 360 kB (5.25") */ ret |= (fdd_doublestep_40(0) || fdd_doublestep_40(1)) ? 0x1 : 0x0; break; + + default: + break; } - return (ret); + return ret; } static uint8_t -m240_read(uint16_t port, void *priv) +m240_read(uint16_t port, UNUSED(void *priv)) { uint8_t ret = 0x00; - int i, fdd_count = 0; + int fdd_count = 0; switch (port) { case 0x62: @@ -1723,7 +1743,7 @@ m240_read(uint16_t port, void *priv) ret = 0x00; if (ppi.pb & 0x8) { /* Switches 4, 5 - floppy drives (number) */ - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -1761,9 +1781,12 @@ m240_read(uint16_t port, void *priv) ret |= fdd_doublestep_40(1) ? 0x40 : 0x00; ret |= fdd_doublestep_40(0) ? 0x20 : 0x00; break; + + default: + break; } - return (ret); + return ret; } /* @@ -1802,7 +1825,7 @@ machine_xt_m24_init(const machine_t *model) /* Allocate an NVR for this machine. */ nvr = (nvr_t *) malloc(sizeof(nvr_t)); if (nvr == NULL) - return (0); + return 0; memset(nvr, 0x00, sizeof(nvr_t)); mm58174_init(nvr, model->nvrmask + 1); @@ -1876,7 +1899,7 @@ machine_xt_m240_init(const machine_t *model) /* Allocate an NVR for this machine. */ nvr = (nvr_t *) malloc(sizeof(nvr_t)); if (nvr == NULL) - return (0); + return 0; memset(nvr, 0x00, sizeof(nvr_t)); mm58274_init(nvr, model->nvrmask + 1); diff --git a/src/machine/m_xt_philips.c b/src/machine/m_xt_philips.c index bc1b6f792..4caff1431 100644 --- a/src/machine/m_xt_philips.c +++ b/src/machine/m_xt_philips.c @@ -39,9 +39,9 @@ #include <86box/chipset.h> #include <86box/io.h> #include <86box/video.h> +#include <86box/plat_unused.h> -typedef struct -{ +typedef struct philips_t { uint8_t reg; } philips_t; @@ -80,6 +80,9 @@ philips_write(uint16_t port, uint8_t val, void *priv) else cpu_dynamic_switch(0); break; + + default: + break; } philips_log("Philips XT Mainboard: Write %02x at %02x\n", val, port); @@ -100,6 +103,9 @@ philips_read(uint16_t port, void *priv) case 0xc0: ret = dev->reg; break; + + default: + break; } philips_log("Philips XT Mainboard: Read %02x at %02x\n", ret, port); @@ -116,7 +122,7 @@ philips_close(void *priv) } static void * -philips_init(const device_t *info) +philips_init(UNUSED(const device_t *info)) { philips_t *dev = (philips_t *) malloc(sizeof(philips_t)); memset(dev, 0, sizeof(philips_t)); diff --git a/src/machine/m_xt_t1000.c b/src/machine/m_xt_t1000.c index f632003ac..2880f4201 100644 --- a/src/machine/m_xt_t1000.c +++ b/src/machine/m_xt_t1000.c @@ -135,7 +135,7 @@ enum TC8521_ADDR { TC8521_LEAPYEAR = 0x1B }; -typedef struct { +typedef struct t1000_t { /* ROM drive */ uint8_t *romdrive; uint8_t rom_ctl; @@ -237,7 +237,7 @@ tc8521_time_get(uint8_t *regs, struct tm *tm) /* This is called every second through the NVR/RTC hook. */ static void -tc8521_tick(nvr_t *nvr) +tc8521_tick(UNUSED(nvr_t *nvr)) { t1000_log("TC8521: ping\n"); } @@ -288,8 +288,8 @@ tc8521_write(uint16_t addr, uint8_t val, void *priv) static uint8_t tc8521_read(uint16_t addr, void *priv) { - nvr_t *nvr = (nvr_t *) priv; - uint8_t page; + const nvr_t *nvr = (nvr_t *) priv; + uint8_t page; /* Get to the correct register page. */ addr &= 0x0f; @@ -336,12 +336,12 @@ tc8521_init(nvr_t *nvr, int size) /* Given an EMS page ID, return its physical address in RAM. */ static uint32_t -ems_execaddr(t1000_t *sys, int pg, uint16_t val) +ems_execaddr(t1000_t *sys, UNUSED(int pg), uint16_t val) { if (!(val & 0x80)) - return (0); /* Bit 7 reset => not mapped */ + return 0; /* Bit 7 reset => not mapped */ if (!sys->ems_pages) - return (0); /* No EMS available: all used by + return 0; /* No EMS available: all used by * HardRAM or conventional RAM */ val &= 0x7f; @@ -354,13 +354,13 @@ ems_execaddr(t1000_t *sys, int pg, uint16_t val) return ((512 * 1024) + (sys->ems_base * 0x10000) + (0x4000 * val)); } - return (0); + return 0; } static uint8_t ems_in(uint16_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; #if 0 t1000_log("ems_in(%04x)=%02x\n", addr, sys->ems_reg[(addr >> 14) & 3]); @@ -392,8 +392,6 @@ ems_out(uint16_t addr, uint8_t val, void *priv) static void ems_set_hardram(t1000_t *sys, uint8_t val) { - int n; - val &= 0x1f; /* Mask off pageframe address */ if (val && mem_size > 512) sys->ems_base = val; @@ -408,7 +406,7 @@ ems_set_hardram(t1000_t *sys, uint8_t val) sys->ems_pages = 0; /* Recalculate EMS mappings */ - for (n = 0; n < 4; n++) + for (uint8_t n = 0; n < 4; n++) ems_out(n << 14, sys->ems_reg[n], sys); } @@ -469,11 +467,11 @@ addr_to_page(uint32_t addr) static uint8_t ems_read_ram(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; int pg = addr_to_page(addr); if (pg < 0) - return (0xff); + return 0xff; addr = sys->page_exec[pg] + (addr & 0x3fff); return (ram[addr]); @@ -482,11 +480,11 @@ ems_read_ram(uint32_t addr, void *priv) static uint16_t ems_read_ramw(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) - return (0xff); + return 0xff; #if 0 t1000_log("ems_read_ramw addr=%05x ", addr); @@ -503,11 +501,11 @@ ems_read_ramw(uint32_t addr, void *priv) static uint32_t ems_read_raml(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) - return (0xff); + return 0xff; addr = sys->page_exec[pg] + (addr & 0x3fff); return (*(uint32_t *) &ram[addr]); @@ -517,8 +515,8 @@ ems_read_raml(uint32_t addr, void *priv) static void ems_write_ram(uint32_t addr, uint8_t val, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -533,8 +531,8 @@ ems_write_ram(uint32_t addr, uint8_t val, void *priv) static void ems_write_ramw(uint32_t addr, uint16_t val, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -557,8 +555,8 @@ ems_write_ramw(uint32_t addr, uint16_t val, void *priv) static void ems_write_raml(uint32_t addr, uint32_t val, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -573,8 +571,8 @@ ems_write_raml(uint32_t addr, uint32_t val, void *priv) static uint8_t read_ctl(uint16_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; - uint8_t ret = 0xff; + const t1000_t *sys = (t1000_t *) priv; + uint8_t ret = 0xff; switch (addr & 0x0f) { case 1: @@ -597,6 +595,9 @@ read_ctl(uint16_t addr, void *priv) case 0x52: ret = (sys->is_640k ? 0x80 : 0); break; + + default: + break; } break; @@ -604,7 +605,7 @@ read_ctl(uint16_t addr, void *priv) ret = (sys->sys_ctl[addr & 0x0f]); } - return (ret); + return ret; } static void @@ -658,8 +659,14 @@ write_ctl(uint16_t addr, uint8_t val, void *priv) case 0x52: ems_set_640k(sys, val); break; + + default: + break; } break; + + default: + break; } } @@ -691,9 +698,12 @@ t1000_read_nvram(uint16_t addr, void *priv) tmp |= 0x2e; /* Bits 5, 3, 2, 1 always 1 */ tmp |= (sys->nvr_active & 0x40) >> 6; /* Ready state */ break; + + default: + break; } - return (tmp); + return tmp; } static void @@ -735,13 +745,16 @@ t1000_write_nvram(uint16_t addr, uint8_t val, void *priv) if (val == 0x80) sys->nvr_addr = -1; break; + + default: + break; } } static uint8_t read_t1200_nvram(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; return sys->t1200_nvram[addr & 0x7FF]; } @@ -759,15 +772,15 @@ write_t1200_nvram(uint32_t addr, uint8_t value, void *priv) /* Port 0xC8 controls the ROM drive */ static uint8_t -t1000_read_rom_ctl(uint16_t addr, void *priv) +t1000_read_rom_ctl(UNUSED(uint16_t addr), void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; return (sys->rom_ctl); } static void -t1000_write_rom_ctl(uint16_t addr, uint8_t val, void *priv) +t1000_write_rom_ctl(UNUSED(uint16_t addr), uint8_t val, void *priv) { t1000_t *sys = (t1000_t *) priv; @@ -787,10 +800,10 @@ t1000_write_rom_ctl(uint16_t addr, uint8_t val, void *priv) static uint8_t t1000_read_rom(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; if (!sys->romdrive) - return (0xff); + return 0xff; return (sys->romdrive[sys->rom_offset + (addr & 0xffff)]); } @@ -801,7 +814,7 @@ t1000_read_romw(uint32_t addr, void *priv) t1000_t *sys = (t1000_t *) priv; if (!sys->romdrive) - return (0xffff); + return 0xffff; return (*(uint16_t *) (&sys->romdrive[sys->rom_offset + (addr & 0xffff)])); } @@ -812,7 +825,7 @@ t1000_read_roml(uint32_t addr, void *priv) t1000_t *sys = (t1000_t *) priv; if (!sys->romdrive) - return (0xffffffff); + return 0xffffffff; return (*(uint32_t *) (&sys->romdrive[sys->rom_offset + (addr & 0xffff)])); } @@ -821,8 +834,6 @@ int machine_xt_t1000_init(const machine_t *model) { FILE *f; - int pg; - int ret; ret = bios_load_linear("roms/machines/t1000/t1000.rom", @@ -861,7 +872,7 @@ machine_xt_t1000_init(const machine_t *model) mem_mapping_disable(&t1000.rom_mapping); /* Map the EMS page frame */ - for (pg = 0; pg < 4; pg++) { + for (uint8_t pg = 0; pg < 4; pg++) { mem_mapping_add(&t1000.mapping[pg], 0xd0000 + (0x4000 * pg), 16384, ems_read_ram, ems_read_ramw, ems_read_raml, ems_write_ram, ems_write_ramw, ems_write_raml, @@ -906,8 +917,6 @@ machine_xt_t1000_init(const machine_t *model) int machine_xt_t1200_init(const machine_t *model) { - int pg; - int ret; ret = bios_load_linear("roms/machines/t1200/t1200_019e.ic15.bin", @@ -924,7 +933,7 @@ machine_xt_t1200_init(const machine_t *model) loadfont("roms/machines/t1000/t1000font.bin", 2); /* Map the EMS page frame */ - for (pg = 0; pg < 4; pg++) { + for (uint8_t pg = 0; pg < 4; pg++) { mem_mapping_add(&t1000.mapping[pg], 0xd0000 + (0x4000 * pg), 16384, ems_read_ram, ems_read_ramw, ems_read_raml, diff --git a/src/machine/m_xt_t1000_vid.c b/src/machine/m_xt_t1000_vid.c index 48c00d3c3..006698869 100644 --- a/src/machine/m_xt_t1000_vid.c +++ b/src/machine/m_xt_t1000_vid.c @@ -51,12 +51,14 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/m_xt_t1000.h> +#include <86box/plat_unused.h> #define T1000_XSIZE 640 #define T1000_YSIZE 200 /* Mapping of attributes to colours */ -static uint32_t blue, grey; +static uint32_t blue; +static uint32_t grey; static uint8_t boldcols[256]; /* Which attributes use the bold font */ static uint32_t blinkcols[256][2]; static uint32_t normcols[256][2]; @@ -124,14 +126,14 @@ typedef struct t1000_t { } t1000_t; static void t1000_recalctimings(t1000_t *t1000); -static void t1000_write(uint32_t addr, uint8_t val, void *p); -static uint8_t t1000_read(uint32_t addr, void *p); +static void t1000_write(uint32_t addr, uint8_t val, void *priv); +static uint8_t t1000_read(uint32_t addr, void *priv); static void t1000_recalcattrs(t1000_t *t1000); static void -t1000_out(uint16_t addr, uint8_t val, void *p) +t1000_out(uint16_t addr, uint8_t val, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; switch (addr) { /* Emulated CRTC, register select */ case 0x3d0: @@ -158,21 +160,20 @@ t1000_out(uint16_t addr, uint8_t val, void *p) t1000_recalctimings(t1000); return; - /* CGA control register */ - case 0x3D8: - cga_out(addr, val, &t1000->cga); - return; - /* CGA colour register */ - case 0x3D9: + case 0x3D8: /* CGA control register */ + case 0x3D9: /* CGA colour register */ cga_out(addr, val, &t1000->cga); return; + + default: + break; } } static uint8_t -t1000_in(uint16_t addr, void *p) +t1000_in(uint16_t addr, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; uint8_t val; switch (addr) { @@ -186,24 +187,29 @@ t1000_in(uint16_t addr, void *p) val |= 0x20; /* LCD / CRT */ return val; } + break; + + default: + break; } return cga_in(addr, &t1000->cga); } static void -t1000_write(uint32_t addr, uint8_t val, void *p) +t1000_write(uint32_t addr, uint8_t val, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; t1000->vram[addr & 0x3fff] = val; cycles -= 4; } static uint8_t -t1000_read(uint32_t addr, void *p) +t1000_read(uint32_t addr, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + const t1000_t *t1000 = (t1000_t *) priv; + cycles -= 4; return t1000->vram[addr & 0x3fff]; @@ -213,7 +219,8 @@ static void t1000_recalctimings(t1000_t *t1000) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; if (!t1000->internal) { cga_recalctimings(&t1000->cga); @@ -231,8 +238,8 @@ static void t1000_text_row80(t1000_t *t1000) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -251,7 +258,7 @@ t1000_text_row80(t1000_t *t1000) } else { cursorline = ((t1000->cga.crtc[10] & 0x0F) <= sc) && ((t1000->cga.crtc[11] & 0x0F) >= sc); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { chr = t1000->vram[(addr + 2 * x) & 0x3FFF]; attr = t1000->vram[(addr + 2 * x + 1) & 0x3FFF]; drawcursor = ((ma == ca) && cursorline && (t1000->cga.cgamode & 8) && (t1000->cga.cgablink & 16)); @@ -276,12 +283,12 @@ t1000_text_row80(t1000_t *t1000) cols[0] = normcols[attr][0]; } if (drawcursor) { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); } } else { - for (c = 0; c < 8; c++) - ((uint32_t *) buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) + (buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } ++ma; } @@ -292,8 +299,8 @@ static void t1000_text_row40(t1000_t *t1000) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -312,7 +319,7 @@ t1000_text_row40(t1000_t *t1000) } else { cursorline = ((t1000->cga.crtc[10] & 0x0F) <= sc) && ((t1000->cga.crtc[11] & 0x0F) >= sc); } - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { chr = t1000->vram[(addr + 2 * x) & 0x3FFF]; attr = t1000->vram[(addr + 2 * x + 1) & 0x3FFF]; drawcursor = ((ma == ca) && cursorline && (t1000->cga.cgamode & 8) && (t1000->cga.cgablink & 16)); @@ -337,12 +344,12 @@ t1000_text_row40(t1000_t *t1000) cols[0] = normcols[attr][0]; } if (drawcursor) { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t1000->displine])[(x << 4) + c * 2] = (buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); } } else { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t1000->displine])[(x << 4) + c * 2] = (buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } } ++ma; @@ -353,7 +360,6 @@ t1000_text_row40(t1000_t *t1000) static void t1000_cgaline6(t1000_t *t1000) { - int x, c; uint8_t dat; uint32_t ink = 0; uint16_t addr; @@ -364,15 +370,15 @@ t1000_cgaline6(t1000_t *t1000) addr = ((t1000->displine) & 1) * 0x2000 + (t1000->displine >> 1) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t1000->vram[addr & 0x3FFF]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { ink = (dat & 0x80) ? fg : bg; if (!(t1000->cga.cgamode & 8)) ink = grey; - ((uint32_t *) buffer32->line[t1000->displine])[x * 8 + c] = ink; + (buffer32->line[t1000->displine])[x * 8 + c] = ink; dat = dat << 1; } } @@ -383,19 +389,20 @@ t1000_cgaline6(t1000_t *t1000) static void t1000_cgaline4(t1000_t *t1000) { - int x, c; - uint8_t dat, pattern; - uint32_t ink0, ink1; + uint8_t dat; + uint8_t pattern; + uint32_t ink0; + uint32_t ink1; uint16_t addr; uint16_t ma = (t1000->cga.crtc[13] | (t1000->cga.crtc[12] << 8)) & 0x3fff; addr = ((t1000->displine) & 1) * 0x2000 + (t1000->displine >> 1) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t1000->vram[addr & 0x3FFF]; addr++; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; if (!(t1000->cga.cgamode & 8)) pattern = 0; @@ -427,17 +434,17 @@ t1000_cgaline4(t1000_t *t1000) ink0 = ink1 = blue; break; } - ((uint32_t *) buffer32->line[t1000->displine])[x * 8 + 2 * c] = ink0; - ((uint32_t *) buffer32->line[t1000->displine])[x * 8 + 2 * c + 1] = ink1; - dat = dat << 2; + (buffer32->line[t1000->displine])[x * 8 + 2 * c] = ink0; + (buffer32->line[t1000->displine])[x * 8 + 2 * c + 1] = ink1; + dat = dat << 2; } } } static void -t1000_poll(void *p) +t1000_poll(void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; if (t1000->video_options != st_video_options || t1000->enabled != st_enabled) { t1000->video_options = st_video_options; @@ -642,7 +649,7 @@ t1000_recalcattrs(t1000_t *t1000) } static void * -t1000_init(const device_t *info) +t1000_init(UNUSED(const device_t *info)) { t1000_t *t1000 = malloc(sizeof(t1000_t)); memset(t1000, 0, sizeof(t1000_t)); @@ -680,18 +687,18 @@ t1000_init(const device_t *info) } static void -t1000_close(void *p) +t1000_close(void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; free(t1000->vram); free(t1000); } static void -t1000_speed_changed(void *p) +t1000_speed_changed(void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; t1000_recalctimings(t1000); } diff --git a/src/machine/m_xt_xi8088.c b/src/machine/m_xt_xi8088.c index 5bf958d8a..3f07e6a4e 100644 --- a/src/machine/m_xt_xi8088.c +++ b/src/machine/m_xt_xi8088.c @@ -24,6 +24,7 @@ #include <86box/video.h> #include <86box/machine.h> #include "cpu.h" +#include <86box/plat_unused.h> #include <86box/m_xt_xi8088.h> @@ -67,7 +68,7 @@ xi8088_bios_128kb(void) } static void * -xi8088_init(const device_t *info) +xi8088_init(UNUSED(const device_t *info)) { xi8088.turbo = 1; xi8088.turbo_setting = device_get_config_int("turbo_setting"); diff --git a/src/machine/m_xt_zenith.c b/src/machine/m_xt_zenith.c index e5cebe552..628b98e8b 100644 --- a/src/machine/m_xt_zenith.c +++ b/src/machine/m_xt_zenith.c @@ -46,6 +46,7 @@ #include <86box/machine.h> #include <86box/io.h> #include <86box/vid_cga.h> +#include <86box/plat_unused.h> typedef struct { mem_mapping_t scratchpad_mapping; @@ -53,21 +54,21 @@ typedef struct { } zenith_t; static uint8_t -zenith_scratchpad_read(uint32_t addr, void *p) +zenith_scratchpad_read(uint32_t addr, void *priv) { - zenith_t *dev = (zenith_t *) p; + zenith_t *dev = (zenith_t *) priv; return dev->scratchpad_ram[addr & 0x3fff]; } static void -zenith_scratchpad_write(uint32_t addr, uint8_t val, void *p) +zenith_scratchpad_write(uint32_t addr, uint8_t val, void *priv) { - zenith_t *dev = (zenith_t *) p; + zenith_t *dev = (zenith_t *) priv; dev->scratchpad_ram[addr & 0x3fff] = val; } static void * -zenith_scratchpad_init(const device_t *info) +zenith_scratchpad_init(UNUSED(const device_t *info)) { zenith_t *dev; @@ -85,9 +86,9 @@ zenith_scratchpad_init(const device_t *info) } static void -zenith_scratchpad_close(void *p) +zenith_scratchpad_close(void *priv) { - zenith_t *dev = (zenith_t *) p; + zenith_t *dev = (zenith_t *) priv; free(dev->scratchpad_ram); free(dev); diff --git a/src/machine/machine.c b/src/machine/machine.c index 893700c7e..47e98e7b3 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -41,6 +41,8 @@ #include <86box/video.h> #include <86box/machine.h> #include <86box/isamem.h> +#include <86box/pci.h> +#include <86box/plat_unused.h> int bios_only = 0; int machine; @@ -77,8 +79,10 @@ machine_init_ex(int m) gameport_instance_id = 0; /* Set up the architecture flags. */ - // AT = IS_AT(machine); - // PCI = IS_ARCH(machine, MACHINE_BUS_PCI); +#if 0 + AT = IS_AT(machine); + PCI = IS_ARCH(machine, MACHINE_BUS_PCI); +#endif cpu_set(); pc_speed_changed(); @@ -103,6 +107,8 @@ machine_init_ex(int m) /* Reset the fast off stuff. */ cpu_fast_off_reset(); + + pci_take_over_io = 0x00000000; } /* All good, boot the machine! */ @@ -137,15 +143,15 @@ machine_init(void) int machine_available(int m) { - int ret; - device_t *d = (device_t *) machine_get_device(m); + int ret; + const device_t *dev = machine_get_device(m); bios_only = 1; - ret = device_available(d); + ret = device_available(dev); /* Do not check via machine_init_ex() if the device is not NULL and it has a CONFIG_BIOS field. */ - if ((d == NULL) || (ret != -1)) + if ((dev == NULL) || (ret != -1)) ret = machine_init_ex(m); bios_only = 0; @@ -164,7 +170,7 @@ pit_irq0_timer(int new_out, int old_out) } void -machine_common_init(const machine_t *model) +machine_common_init(UNUSED(const machine_t *model)) { /* System devices first. */ pic_init(); diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 9047342e8..fa34bdef8 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -34,6 +34,7 @@ #include <86box/keyboard.h> #include <86box/sound.h> #include <86box/video.h> +#include <86box/plat_unused.h> // Temporarily here till we move everything out into the right files extern const device_t pcjr_device; @@ -222,7 +223,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PC, + .bus_flags = MACHINE_PC5150, .flags = MACHINE_FLAGS_NONE, .ram = { .min = 16, @@ -260,7 +261,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PC, + .bus_flags = MACHINE_PC5150, .flags = MACHINE_FLAGS_NONE, .ram = { .min = 64, @@ -303,7 +304,7 @@ const machine_t machines[] = { .ram = { .min = 128, .max = 640, - .step = 128 + .step = 64 }, .nvrmask = 0, .kbc_device = NULL, /* TODO: No specific kbd_device yet */ @@ -886,6 +887,44 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { + .name = "[8088] Micoms XL-7 Turbo", + .internal_name = "mxl7t", + .type = MACHINE_TYPE_8088, + .chipset = MACHINE_CHIPSET_DISCRETE, + .init = machine_xt_micoms_xl7turbo_init, + .pad = 0, + .pad0 = 0, + .pad1 = MACHINE_AVAILABLE, + .pad2 = 0, + .cpu = { + .package = CPU_PKG_8088, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PC, + .flags = MACHINE_FLAGS_NONE, + .ram = { + .min = 64, + .max = 640, + .step = 64 + }, + .nvrmask = 0, + .kbc_device = &keyboard_xt_device, + .kbc_p1 = 0xff00, + .gpio = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, { .name = "[8088] Multitech PC-500", .internal_name = "pc500", @@ -962,44 +1001,6 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - { - .name = "[8088] Micoms XL-7 Turbo", - .internal_name = "mxl7t", - .type = MACHINE_TYPE_8088, - .chipset = MACHINE_CHIPSET_DISCRETE, - .init = machine_xt_micoms_xl7turbo_init, - .pad = 0, - .pad0 = 0, - .pad1 = MACHINE_AVAILABLE, - .pad2 = 0, - .cpu = { - .package = CPU_PKG_8088, - .block = CPU_BLOCK_NONE, - .min_bus = 0, - .max_bus = 0, - .min_voltage = 0, - .max_voltage = 0, - .min_multi = 0, - .max_multi = 0 - }, - .bus_flags = MACHINE_PC, - .flags = MACHINE_FLAGS_NONE, - .ram = { - .min = 64, - .max = 640, - .step = 64 - }, - .nvrmask = 0, - .kbc_device = &keyboard_xt_device, - .kbc_p1 = 0xff00, - .gpio = 0xffffffff, - .device = NULL, - .fdc_device = NULL, - .sio_device = NULL, - .vid_device = NULL, - .snd_device = NULL, - .net_device = NULL - }, { .name = "[8088] NCR PC4i", .internal_name = "pc4i", @@ -2587,8 +2588,8 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_286, .block = CPU_BLOCK_NONE, - .min_bus = 6000000, - .max_bus = 8000000, + .min_bus = 0, + .max_bus = 0, .min_voltage = 0, .max_voltage = 0, .min_multi = 0, @@ -2904,8 +2905,8 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_286, .block = CPU_BLOCK_NONE, - .min_bus = 6000000, - .max_bus = 8000000, + .min_bus = 0, + .max_bus = 0, .min_voltage = 0, .max_voltage = 0, .min_multi = 0, @@ -2943,8 +2944,8 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_286, .block = CPU_BLOCK_NONE, - .min_bus = 6000000, - .max_bus = 8000000, + .min_bus = 0, + .max_bus = 0, .min_voltage = 0, .max_voltage = 0, .min_multi = 0, @@ -3774,7 +3775,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PS2, + .bus_flags = MACHINE_AT, .flags = MACHINE_IDE, .ram = { .min = 1024, @@ -3813,7 +3814,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PS2, + .bus_flags = MACHINE_AT, .flags = MACHINE_IDE, .ram = { .min = 1024, @@ -3894,7 +3895,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PS2, + .bus_flags = MACHINE_AT, .flags = MACHINE_IDE, .ram = { .min = 1024, @@ -4670,9 +4671,8 @@ const machine_t machines[] = { .net_device = NULL }, /* Uses Compaq KBC firmware. */ -#if defined(DEV_BRANCH) && defined(USE_DESKPRO386) { - .name = "[ISA] Compaq Deskpro 386", + .name = "[ISA] Compaq Deskpro 386 (September 1986)", .internal_name = "deskpro386", .type = MACHINE_TYPE_386DX, .chipset = MACHINE_CHIPSET_DISCRETE, @@ -4692,13 +4692,51 @@ const machine_t machines[] = { .max_multi = 0 }, .bus_flags = MACHINE_AT, - .flags = MACHINE_IDE | MACHINE_APM, + .flags = MACHINE_IDE, .ram = { - .min = 1024, - .max = 14336, - .step = 1024 + .min = 640, + .max = 16384, + .step = 128 }, - .nvrmask = 127, + .nvrmask = 63, + .kbc_device = NULL, + .kbc_p1 = 0, + .gpio = 0, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + { + .name = "[ISA] Compaq Deskpro 386 (January 1988)", + .internal_name = "deskpro386_01_1988", + .type = MACHINE_TYPE_386DX, + .chipset = MACHINE_CHIPSET_DISCRETE, + .init = machine_at_deskpro386_01_1988_init, + .pad = 0, + .pad0 = 0, + .pad1 = MACHINE_AVAILABLE, + .pad2 = 0, + .cpu = { + .package = CPU_PKG_386DX, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_AT, + .flags = MACHINE_IDE, + .ram = { + .min = 640, + .max = 16384, + .step = 128 + }, + .nvrmask = 63, .kbc_device = NULL, .kbc_p1 = 0, .gpio = 0, @@ -4709,7 +4747,6 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, -#endif /* defined(DEV_BRANCH) && defined(USE_DESKPRO386) */ { .name = "[ISA] Compaq Portable III (386)", .internal_name = "portableiii386", @@ -4731,7 +4768,7 @@ const machine_t machines[] = { .max_multi = 0 }, .bus_flags = MACHINE_AT, - .flags = MACHINE_IDE | MACHINE_VIDEO | MACHINE_APM, + .flags = MACHINE_IDE | MACHINE_VIDEO, .ram = { .min = 1024, .max = 14336, @@ -5470,7 +5507,45 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - + /* Has IBM PS/2 Type 1 KBC firmware. */ + { + .name = "[MCA] IBM PS/2 model 70 (type 4)", + .internal_name = "ibmps2_m70_type4", + .type = MACHINE_TYPE_486, + .chipset = MACHINE_CHIPSET_PROPRIETARY, + .init = machine_ps2_model_70_type4_init, + .pad = 0, + .pad0 = 0, + .pad1 = MACHINE_AVAILABLE, + .pad2 = 0, + .cpu = { + .package = CPU_PKG_SOCKET1, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PS2_MCA, + .flags = MACHINE_VIDEO | MACHINE_SOFTFLOAT_ONLY, + .ram = { + .min = 2048, + .max = 65536, + .step = 2048 + }, + .nvrmask = 63, + .kbc_device = NULL, + .kbc_p1 = 0, + .gpio = 0, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* 486 machines - Socket 2 */ /* 486 machines with just the ISA slot */ /* Uses some variant of Phoenix MultiKey/42 as the BIOS sends keyboard controller @@ -6761,7 +6836,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PCI, + .bus_flags = MACHINE_BUS_PS2_LATCH | MACHINE_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 1024, @@ -6839,7 +6914,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PCI, + .bus_flags = MACHINE_BUS_PS2_LATCH | MACHINE_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 1024, @@ -7036,7 +7111,7 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PCI, + .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 1024, @@ -12517,7 +12592,7 @@ const machine_t machines[] = { .min_voltage = 1300, .max_voltage = 3500, .min_multi = 1.5, - .max_multi = 8.0 /* limits assumed */ + .max_multi = 8.0 /* limits assumed */ }, .bus_flags = MACHINE_PS2_AGP, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI, @@ -12879,7 +12954,7 @@ machine_get_p1(void) } void -machine_load_p1(int m) +machine_load_p1(UNUSED(int m)) { machine_p1 = machines[machine].kbc_p1; } @@ -12891,7 +12966,7 @@ machine_get_gpio(void) } void -machine_load_gpio(int m) +machine_load_gpio(UNUSED(int m)) { machine_gpio = machines[machine].gpio; } @@ -13054,11 +13129,11 @@ machine_get_machine_from_internal_name(char *s) while (machines[c].init != NULL) { if (!strcmp(machines[c].internal_name, (const char *) s)) - return (c); + return c; c++; } - return (0); + return 0; } int diff --git a/src/mca.c b/src/mca.c index b48bdd2a7..871060bb4 100644 --- a/src/mca.c +++ b/src/mca.c @@ -17,9 +17,7 @@ static int mca_nr_cards; void mca_init(int nr_cards) { - int c; - - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { mca_card_read[c] = NULL; mca_card_write[c] = NULL; mca_card_reset[c] = NULL; @@ -83,9 +81,7 @@ mca_feedb(void) void mca_reset(void) { - int c; - - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { if (mca_card_reset[c]) mca_card_reset[c](mca_priv[c]); } @@ -94,9 +90,7 @@ mca_reset(void) void mca_add(uint8_t (*read)(int addr, void *priv), void (*write)(int addr, uint8_t val, void *priv), uint8_t (*feedb)(void *priv), void (*reset)(void *priv), void *priv) { - int c; - - for (c = 0; c < mca_nr_cards; c++) { + for (int c = 0; c < mca_nr_cards; c++) { if (!mca_card_read[c] && !mca_card_write[c]) { mca_card_read[c] = read; mca_card_write[c] = write; diff --git a/src/mem/CMakeLists.txt b/src/mem/CMakeLists.txt index 6aad80544..001e7b5bc 100644 --- a/src/mem/CMakeLists.txt +++ b/src/mem/CMakeLists.txt @@ -14,4 +14,4 @@ # add_library(mem OBJECT catalyst_flash.c i2c_eeprom.c intel_flash.c mem.c rom.c - smram.c spd.c sst_flash.c) + row.c smram.c spd.c sst_flash.c) diff --git a/src/mem/catalyst_flash.c b/src/mem/catalyst_flash.c index 5e473f540..7cd40e9d7 100644 --- a/src/mem/catalyst_flash.c +++ b/src/mem/catalyst_flash.c @@ -55,20 +55,23 @@ enum { }; typedef struct flash_t { - uint8_t command, pad, - pad0, pad1, - *array; + uint8_t command; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; + uint8_t *array; - mem_mapping_t mapping, mapping_h[2]; + mem_mapping_t mapping; + mem_mapping_t mapping_h[2]; } flash_t; static char flash_path[1024]; static uint8_t -flash_read(uint32_t addr, void *p) +flash_read(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint8_t ret = 0xff; + const flash_t *dev = (flash_t *) priv; + uint8_t ret = 0xff; addr &= biosmask; @@ -86,16 +89,19 @@ flash_read(uint32_t addr, void *p) else if (addr == 0x00001) ret = 0xB4; /* 28F010 */ break; + + default: + break; } return ret; } static uint16_t -flash_readw(uint32_t addr, void *p) +flash_readw(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint16_t *q; + flash_t *dev = (flash_t *) priv; + const uint16_t *q; addr &= biosmask; @@ -105,10 +111,10 @@ flash_readw(uint32_t addr, void *p) } static uint32_t -flash_readl(uint32_t addr, void *p) +flash_readl(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint32_t *q; + flash_t *dev = (flash_t *) priv; + const uint32_t *q; addr &= biosmask; @@ -118,9 +124,9 @@ flash_readl(uint32_t addr, void *p) } static void -flash_write(uint32_t addr, uint8_t val, void *p) +flash_write(uint32_t addr, uint8_t val, void *priv) { - flash_t *dev = (flash_t *) p; + flash_t *dev = (flash_t *) priv; addr &= biosmask; @@ -141,13 +147,15 @@ flash_write(uint32_t addr, uint8_t val, void *p) } static void -flash_writew(uint32_t addr, uint16_t val, void *p) +flash_writew(UNUSED(uint32_t addr), UNUSED(uint16_t val), UNUSED(void *priv)) { + // } static void -flash_writel(uint32_t addr, uint32_t val, void *p) +flash_writel(UNUSED(uint32_t addr), UNUSED(uint32_t val), UNUSED(void *priv)) { + // } static void @@ -179,9 +187,9 @@ catalyst_flash_reset(void *priv) } static void * -catalyst_flash_init(const device_t *info) +catalyst_flash_init(UNUSED(const device_t *info)) { - FILE *f; + FILE *fp; flash_t *dev; dev = malloc(sizeof(flash_t)); @@ -199,24 +207,24 @@ catalyst_flash_init(const device_t *info) dev->command = CMD_RESET; - f = nvr_fopen(flash_path, "rb"); - if (f) { - (void) !fread(dev->array, 0x20000, 1, f); - fclose(f); + fp = nvr_fopen(flash_path, "rb"); + if (fp) { + (void) !fread(dev->array, 0x20000, 1, fp); + fclose(fp); } return dev; } static void -catalyst_flash_close(void *p) +catalyst_flash_close(void *priv) { - FILE *f; - flash_t *dev = (flash_t *) p; + FILE *fp; + flash_t *dev = (flash_t *) priv; - f = nvr_fopen(flash_path, "wb"); - fwrite(dev->array, 0x20000, 1, f); - fclose(f); + fp = nvr_fopen(flash_path, "wb"); + fwrite(dev->array, 0x20000, 1, fp); + fclose(fp); free(dev->array); dev->array = NULL; diff --git a/src/mem/i2c_eeprom.c b/src/mem/i2c_eeprom.c index 22b7154d6..7d83bbe88 100644 --- a/src/mem/i2c_eeprom.c +++ b/src/mem/i2c_eeprom.c @@ -23,13 +23,18 @@ #include #include <86box/86box.h> #include <86box/i2c.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct i2c_eeprom_t { void *i2c; - uint8_t addr, *data, writable; + uint8_t addr; + uint8_t *data; + uint8_t writable; - uint32_t addr_mask, addr_register; - uint8_t addr_len, addr_pos; + uint32_t addr_mask; + uint32_t addr_register; + uint8_t addr_len; + uint8_t addr_pos; } i2c_eeprom_t; #ifdef ENABLE_I2C_EEPROM_LOG @@ -51,7 +56,7 @@ i2c_eeprom_log(const char *fmt, ...) #endif static uint8_t -i2c_eeprom_start(void *bus, uint8_t addr, uint8_t read, void *priv) +i2c_eeprom_start(UNUSED(void *bus), uint8_t addr, uint8_t read, void *priv) { i2c_eeprom_t *dev = (i2c_eeprom_t *) priv; @@ -66,7 +71,7 @@ i2c_eeprom_start(void *bus, uint8_t addr, uint8_t read, void *priv) } static uint8_t -i2c_eeprom_read(void *bus, uint8_t addr, void *priv) +i2c_eeprom_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { i2c_eeprom_t *dev = (i2c_eeprom_t *) priv; uint8_t ret = dev->data[dev->addr_register]; @@ -79,7 +84,7 @@ i2c_eeprom_read(void *bus, uint8_t addr, void *priv) } static uint8_t -i2c_eeprom_write(void *bus, uint8_t addr, uint8_t data, void *priv) +i2c_eeprom_write(UNUSED(void *bus), uint8_t addr, uint8_t data, void *priv) { i2c_eeprom_t *dev = (i2c_eeprom_t *) priv; @@ -104,7 +109,7 @@ i2c_eeprom_write(void *bus, uint8_t addr, uint8_t data, void *priv) } static void -i2c_eeprom_stop(void *bus, uint8_t addr, void *priv) +i2c_eeprom_stop(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) { i2c_eeprom_t *dev = (i2c_eeprom_t *) priv; @@ -117,7 +122,7 @@ uint8_t log2i(uint32_t i) { uint8_t ret = 0; - while ((i >>= 1)) + while (i >>= 1) ret++; return ret; } diff --git a/src/mem/intel_flash.c b/src/mem/intel_flash.c index f06b2426d..7949f302a 100644 --- a/src/mem/intel_flash.c +++ b/src/mem/intel_flash.c @@ -58,34 +58,39 @@ enum { }; typedef struct flash_t { - uint8_t command, status, - pad, flags, - *array; + uint8_t command; + uint8_t status; + uint8_t pad; + uint8_t flags; + uint8_t *array; - uint16_t flash_id, pad16; + uint16_t flash_id; + uint16_t pad16; - uint32_t program_addr, - block_start[BLOCKS_NUM], block_end[BLOCKS_NUM], - block_len[BLOCKS_NUM]; + uint32_t program_addr; + uint32_t block_start[BLOCKS_NUM]; + uint32_t block_end[BLOCKS_NUM]; + uint32_t block_len[BLOCKS_NUM]; - mem_mapping_t mapping[4], mapping_h[16]; + mem_mapping_t mapping[4]; + mem_mapping_t mapping_h[16]; } flash_t; static char flash_path[1024]; static uint8_t -flash_read(uint32_t addr, void *p) +flash_read(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint8_t ret = 0xff; + const flash_t *dev = (flash_t *) priv; + uint8_t ret = 0xff; if (dev->flags & FLAG_INV_A16) addr ^= 0x10000; addr &= biosmask; switch (dev->command) { - case CMD_READ_ARRAY: default: + case CMD_READ_ARRAY: ret = dev->array[addr]; break; @@ -105,11 +110,11 @@ flash_read(uint32_t addr, void *p) } static uint16_t -flash_readw(uint32_t addr, void *p) +flash_readw(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint16_t *q; - uint16_t ret = 0xffff; + flash_t *dev = (flash_t *) priv; + const uint16_t *q; + uint16_t ret = 0xffff; if (dev->flags & FLAG_INV_A16) addr ^= 0x10000; @@ -123,8 +128,8 @@ flash_readw(uint32_t addr, void *p) if (dev->flags & FLAG_WORD) switch (dev->command) { - case CMD_READ_ARRAY: default: + case CMD_READ_ARRAY: break; case CMD_IID: @@ -143,10 +148,10 @@ flash_readw(uint32_t addr, void *p) } static uint32_t -flash_readl(uint32_t addr, void *p) +flash_readl(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint32_t *q; + flash_t *dev = (flash_t *) priv; + const uint32_t *q; if (dev->flags & FLAG_INV_A16) addr ^= 0x10000; @@ -158,10 +163,9 @@ flash_readl(uint32_t addr, void *p) } static void -flash_write(uint32_t addr, uint8_t val, void *p) +flash_write(uint32_t addr, uint8_t val, void *priv) { - flash_t *dev = (flash_t *) p; - int i; + flash_t *dev = (flash_t *) priv; uint32_t bb_mask = biosmask & 0xffffe000; if (biosmask == 0x7ffff) bb_mask &= 0xffff8000; @@ -175,7 +179,7 @@ flash_write(uint32_t addr, uint8_t val, void *p) switch (dev->command) { case CMD_ERASE_SETUP: if (val == CMD_ERASE_CONFIRM) { - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { if ((i == dev->program_addr) && (addr >= dev->block_start[i]) && (addr <= dev->block_end[i])) memset(&(dev->array[dev->block_start[i]]), 0xff, dev->block_len[i]); } @@ -200,7 +204,7 @@ flash_write(uint32_t addr, uint8_t val, void *p) dev->status = 0; break; case CMD_ERASE_SETUP: - for (i = 0; i < 7; i++) { + for (uint8_t i = 0; i < 7; i++) { if ((addr >= dev->block_start[i]) && (addr <= dev->block_end[i])) dev->program_addr = i; } @@ -209,15 +213,17 @@ flash_write(uint32_t addr, uint8_t val, void *p) case CMD_PROGRAM_SETUP_ALT: dev->program_addr = addr; break; + + default: + break; } } } static void -flash_writew(uint32_t addr, uint16_t val, void *p) +flash_writew(uint32_t addr, uint16_t val, void *priv) { - flash_t *dev = (flash_t *) p; - int i; + flash_t *dev = (flash_t *) priv; uint32_t bb_mask = biosmask & 0xffffe000; if (biosmask == 0x7ffff) bb_mask &= 0xffff8000; @@ -232,7 +238,7 @@ flash_writew(uint32_t addr, uint16_t val, void *p) switch (dev->command) { case CMD_ERASE_SETUP: if (val == CMD_ERASE_CONFIRM) { - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { if ((i == dev->program_addr) && (addr >= dev->block_start[i]) && (addr <= dev->block_end[i])) memset(&(dev->array[dev->block_start[i]]), 0xff, dev->block_len[i]); } @@ -257,7 +263,7 @@ flash_writew(uint32_t addr, uint16_t val, void *p) dev->status = 0; break; case CMD_ERASE_SETUP: - for (i = 0; i < 7; i++) { + for (uint8_t i = 0; i < 7; i++) { if ((addr >= dev->block_start[i]) && (addr <= dev->block_end[i])) dev->program_addr = i; } @@ -266,24 +272,28 @@ flash_writew(uint32_t addr, uint16_t val, void *p) case CMD_PROGRAM_SETUP_ALT: dev->program_addr = addr; break; + + default: + break; } } } static void -flash_writel(uint32_t addr, uint32_t val, void *p) +flash_writel(UNUSED(uint32_t addr), UNUSED(uint32_t val), UNUSED(void *priv)) { #if 0 - flash_writew(addr, val & 0xffff, p); - flash_writew(addr + 2, (val >> 16) & 0xffff, p); + flash_writew(addr, val & 0xffff, priv); + flash_writew(addr + 2, (val >> 16) & 0xffff, priv); #endif } static void intel_flash_add_mappings(flash_t *dev) { - int max = 2, i = 0; - uint32_t base, fbase; + uint8_t max = 2; + uint32_t base; + uint32_t fbase; uint32_t sub = 0x20000; if (biosmask == 0x7ffff) { @@ -294,7 +304,7 @@ intel_flash_add_mappings(flash_t *dev) max = 4; } - for (i = 0; i < max; i++) { + for (uint8_t i = 0; i < max; i++) { if (biosmask == 0x7ffff) base = 0x80000 + (i << 16); else if (biosmask == 0x3ffff) @@ -337,7 +347,7 @@ intel_flash_reset(void *priv) static void * intel_flash_init(const device_t *info) { - FILE *f; + FILE *fp; flash_t *dev; uint8_t type = info->local & 0xff; @@ -502,42 +512,42 @@ intel_flash_init(const device_t *info) dev->command = CMD_READ_ARRAY; dev->status = 0; - f = nvr_fopen(flash_path, "rb"); - if (f) { - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, f); + fp = nvr_fopen(flash_path, "rb"); + if (fp) { + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, fp); if (dev->block_len[BLOCK_MAIN2]) - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, fp); if (dev->block_len[BLOCK_MAIN3]) - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, fp); if (dev->block_len[BLOCK_MAIN4]) - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, fp); - (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, f); - (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, f); - fclose(f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, fp); + (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, fp); + fclose(fp); } return dev; } static void -intel_flash_close(void *p) +intel_flash_close(void *priv) { - FILE *f; - flash_t *dev = (flash_t *) p; + FILE *fp; + flash_t *dev = (flash_t *) priv; - f = nvr_fopen(flash_path, "wb"); - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, f); + fp = nvr_fopen(flash_path, "wb"); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, fp); if (dev->block_len[BLOCK_MAIN2]) - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, f); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, fp); if (dev->block_len[BLOCK_MAIN3]) - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, f); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, fp); if (dev->block_len[BLOCK_MAIN4]) - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, f); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, fp); - fwrite(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, f); - fwrite(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, f); - fclose(f); + fwrite(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, fp); + fwrite(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, fp); + fclose(fp); free(dev->array); dev->array = NULL; diff --git a/src/mem/mem.c b/src/mem/mem.c index 1af83c844..3facfcc31 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -54,28 +54,30 @@ # define BLOCK_INVALID 0 #endif -mem_mapping_t ram_low_mapping, /* 0..640K mapping */ - ram_mid_mapping, /* 640..1024K mapping */ - ram_mid_mapping2, /* 640..1024K mapping, second part, for SiS 471 in relocate mode */ - ram_remapped_mapping, /* 640..1024K mapping */ - ram_remapped_mapping2, /* 640..1024K second mapping, for SiS 471 mode */ - ram_high_mapping, /* 1024K+ mapping */ - ram_2gb_mapping, /* 1024M+ mapping */ - ram_split_mapping, - bios_mapping, - bios_high_mapping; +mem_mapping_t ram_low_mapping; /* 0..640K mapping */ +mem_mapping_t ram_mid_mapping; /* 640..1024K mapping */ +mem_mapping_t ram_mid_mapping2; /* 640..1024K mapping, second part, for SiS 471 in relocate mode */ +mem_mapping_t ram_remapped_mapping; /* 640..1024K mapping */ +mem_mapping_t ram_remapped_mapping2; /* 640..1024K second mapping, for SiS 471 mode */ +mem_mapping_t ram_high_mapping; /* 1024K+ mapping */ +mem_mapping_t ram_2gb_mapping; /* 1024M+ mapping */ +mem_mapping_t ram_split_mapping; +mem_mapping_t bios_mapping; +mem_mapping_t bios_high_mapping; -page_t *pages, /* RAM page table */ - **page_lookup; /* pagetable lookup */ -uint32_t pages_sz; /* #pages in table */ +page_t *pages; /* RAM page table */ +page_t **page_lookup; /* pagetable lookup */ +uint32_t pages_sz; /* #pages in table */ -uint8_t *ram, *ram2; /* the virtual RAM */ +uint8_t *ram; /* the virtual RAM */ +uint8_t *ram2; /* the virtual RAM */ uint8_t page_ff[4096]; uint32_t rammask; uint32_t addr_space_size; uint8_t *rom; /* the virtual ROM */ -uint32_t biosmask, biosaddr; +uint32_t biosmask; +uint32_t biosaddr; uint32_t pccache; uint8_t *pccache2; @@ -91,18 +93,18 @@ uintptr_t *writelookup2; uint32_t mem_logical_addr; -int shadowbios = 0, - shadowbios_write; -int readlnum = 0, - writelnum = 0; +int shadowbios = 0; +int shadowbios_write; +int readlnum = 0; +int writelnum = 0; int cachesize = 256; -uint32_t get_phys_virt, - get_phys_phys; +uint32_t get_phys_virt; +uint32_t get_phys_phys; -int mem_a20_key = 0, - mem_a20_alt = 0, - mem_a20_state = 0; +int mem_a20_key = 0; +int mem_a20_alt = 0; +int mem_a20_state = 0; int mmuflush = 0; int mmu_perm = 4; @@ -121,7 +123,8 @@ uint8_t high_page = 0; /* if a high (> 4 gb) page was detected */ static uint8_t *page_lookupp; /* pagetable mmu_perm lookup */ static uint8_t *readlookupp; static uint8_t *writelookupp; -static mem_mapping_t *base_mapping, *last_mapping; +static mem_mapping_t *base_mapping; +static mem_mapping_t *last_mapping; static mem_mapping_t *read_mapping[MEM_MAPPINGS_NO]; static mem_mapping_t *write_mapping[MEM_MAPPINGS_NO]; static mem_mapping_t *read_mapping_bus[MEM_MAPPINGS_NO]; @@ -129,9 +132,11 @@ static mem_mapping_t *write_mapping_bus[MEM_MAPPINGS_NO]; static uint8_t *_mem_exec[MEM_MAPPINGS_NO]; static uint8_t ff_pccache[4] = { 0xff, 0xff, 0xff, 0xff }; static mem_state_t _mem_state[MEM_MAPPINGS_NO]; -static uint32_t remap_start_addr, remap_start_addr2; +static uint32_t remap_start_addr; +static uint32_t remap_start_addr2; #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) -static size_t ram_size = 0, ram2_size = 0; +static size_t ram_size = 0; +static size_t ram2_size = 0; #else static size_t ram_size = 0; #endif @@ -157,7 +162,7 @@ mem_log(const char *fmt, ...) int mem_addr_is_ram(uint32_t addr) { - mem_mapping_t *mapping = read_mapping[addr >> MEM_GRANULARITY_BITS]; + const mem_mapping_t *mapping = read_mapping[addr >> MEM_GRANULARITY_BITS]; return (mapping == &ram_low_mapping) || (mapping == &ram_high_mapping) || (mapping == &ram_mid_mapping) || (mapping == &ram_mid_mapping2) || (mapping == &ram_remapped_mapping); @@ -166,13 +171,11 @@ mem_addr_is_ram(uint32_t addr) void resetreadlookup(void) { - int c; - /* Initialize the page lookup table. */ memset(page_lookup, 0x00, (1 << 20) * sizeof(page_t *)); /* Initialize the tables for lower (<= 1024K) RAM. */ - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { readlookup[c] = 0xffffffff; writelookup[c] = 0xffffffff; } @@ -193,9 +196,7 @@ resetreadlookup(void) void flushmmucache(void) { - int c; - - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { if (readlookup[c] != (int) 0xffffffff) { readlookup2[readlookup[c]] = LOOKUP_INV; readlookupp[readlookup[c]] = 4; @@ -222,9 +223,7 @@ flushmmucache(void) void flushmmucache_nopc(void) { - int c; - - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { if (readlookup[c] != (int) 0xffffffff) { readlookup2[readlookup[c]] = LOOKUP_INV; readlookupp[readlookup[c]] = 4; @@ -243,13 +242,12 @@ flushmmucache_nopc(void) void mem_flush_write_page(uint32_t addr, uint32_t virt) { - page_t *page_target = &pages[addr >> 12]; - int c; + const page_t *page_target = &pages[addr >> 12]; #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uint32_t a; #endif - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { if (writelookup[c] != (int) 0xffffffff) { #if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) uintptr_t target = (uintptr_t) &ram[(uintptr_t) (addr & ~0xfff) - (virt & ~0xfff)]; @@ -280,7 +278,9 @@ mem_flush_write_page(uint32_t addr, uint32_t virt) static __inline uint64_t mmutranslatereal_normal(uint32_t addr, int rw) { - uint32_t temp, temp2, temp3; + uint32_t temp; + uint32_t temp2; + uint32_t temp3; uint32_t addr2; if (cpu_state.abrt) @@ -345,8 +345,13 @@ mmutranslatereal_normal(uint32_t addr, int rw) static __inline uint64_t mmutranslatereal_pae(uint32_t addr, int rw) { - uint64_t temp, temp2, temp3, temp4; - uint64_t addr2, addr3, addr4; + uint64_t temp; + uint64_t temp2; + uint64_t temp3; + uint64_t temp4; + uint64_t addr2; + uint64_t addr3; + uint64_t addr4; if (cpu_state.abrt) return 0xffffffffffffffffULL; @@ -449,7 +454,9 @@ mmutranslatereal32(uint32_t addr, int rw) static __inline uint64_t mmutranslate_noabrt_normal(uint32_t addr, int rw) { - uint32_t temp, temp2, temp3; + uint32_t temp; + uint32_t temp2; + uint32_t temp3; uint32_t addr2; if (cpu_state.abrt) @@ -481,8 +488,13 @@ mmutranslate_noabrt_normal(uint32_t addr, int rw) static __inline uint64_t mmutranslate_noabrt_pae(uint32_t addr, int rw) { - uint64_t temp, temp2, temp3, temp4; - uint64_t addr2, addr3, addr4; + uint64_t temp; + uint64_t temp2; + uint64_t temp3; + uint64_t temp4; + uint64_t addr2; + uint64_t addr3; + uint64_t addr4; if (cpu_state.abrt) return 0xffffffffffffffffULL; @@ -510,7 +522,7 @@ mmutranslate_noabrt_pae(uint32_t addr, int rw) addr4 = (temp & ~0xfffULL) + ((addr >> 9) & 0xff8); temp = rammap64(addr4) & 0x000000ffffffffffULL; - ; + temp3 = temp & temp4; if (!(temp & 1) || ((CPL == 3) && !(temp3 & 4) && !cpl_override) || (rw && !(temp3 & 2) && ((CPL == 3) || (cr0 & WP_FLAG)))) @@ -532,12 +544,6 @@ mmutranslate_noabrt(uint32_t addr, int rw) return mmutranslate_noabrt_normal(addr, rw); } -void -mmu_invalidate(uint32_t addr) -{ - flushmmucache_cr3(); -} - uint8_t mem_addr_range_match(uint32_t addr, uint32_t start, uint32_t len) { @@ -651,6 +657,9 @@ uint8_t * getpccache(uint32_t a) { uint64_t a64 = (uint64_t) a; +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + uint8_t *p; +#endif uint32_t a2; a2 = a; @@ -671,7 +680,12 @@ getpccache(uint32_t a) cpu_prefetch_cycles = cpu_mem_prefetch_cycles; } +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + p = &_mem_exec[a64 >> MEM_GRANULARITY_BITS][(uintptr_t) (a64 & MEM_GRANULARITY_PAGE) - (uintptr_t) (a2 & ~0xfff)]; + return (uint8_t *) (((uintptr_t) p & 0x00000000ffffffffULL) | ((uintptr_t) &_mem_exec[a64 >> MEM_GRANULARITY_BITS][0] & 0xffffffff00000000ULL)); +#else return &_mem_exec[a64 >> MEM_GRANULARITY_BITS][(uintptr_t) (a64 & MEM_GRANULARITY_PAGE) - (uintptr_t) (a2 & ~0xfff)]; +#endif } mem_log("Bad getpccache %08X%08X\n", (uint32_t) (a64 >> 32), (uint32_t) (a64 & 0xffffffffULL)); @@ -691,7 +705,7 @@ read_mem_b(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_b) - ret = map->read_b(addr, map->p); + ret = map->read_b(addr, map->priv); resub_cycles(old_cycles); @@ -714,9 +728,9 @@ read_mem_w(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_w) - ret = map->read_w(addr, map->p); + ret = map->read_w(addr, map->priv); else if (map && map->read_b) - ret = map->read_b(addr, map->p) | (map->read_b(addr + 1, map->p) << 8); + ret = map->read_b(addr, map->priv) | (map->read_b(addr + 1, map->priv) << 8); } resub_cycles(old_cycles); @@ -735,7 +749,7 @@ write_mem_b(uint32_t addr, uint8_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); resub_cycles(old_cycles); } @@ -756,10 +770,10 @@ write_mem_w(uint32_t addr, uint16_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map) { if (map->write_w) - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); else if (map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); } } } @@ -791,7 +805,7 @@ readmembl(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_b) - return map->read_b(addr, map->p); + return map->read_b(addr, map->priv); return 0xff; } @@ -825,7 +839,7 @@ writemembl(uint32_t addr, uint8_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); } /* Read a byte from memory without MMU translation - result of previous MMU translation passed as value. */ @@ -848,7 +862,7 @@ readmembl_no_mmut(uint32_t addr, uint32_t a64) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_b) - return map->read_b(addr, map->p); + return map->read_b(addr, map->priv); return 0xff; } @@ -878,14 +892,13 @@ writemembl_no_mmut(uint32_t addr, uint32_t a64, uint8_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); } uint16_t readmemwl(uint32_t addr) { mem_mapping_t *map; - int i; uint64_t a; addr64a[0] = addr; @@ -901,7 +914,7 @@ readmemwl(uint32_t addr) cycles -= timing_misaligned; if ((addr & 0xfff) > 0xffe) { if (cr0 >> 31) { - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { a = mmutranslate_read(addr + i); addr64a[i] = (uint32_t) a; @@ -931,10 +944,10 @@ readmemwl(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_w) - return map->read_w(addr, map->p); + return map->read_w(addr, map->priv); if (map && map->read_b) { - return map->read_b(addr, map->p) | ((uint16_t) (map->read_b(addr + 1, map->p)) << 8); + return map->read_b(addr, map->priv) | ((uint16_t) (map->read_b(addr + 1, map->priv)) << 8); } return 0xffff; @@ -944,7 +957,6 @@ void writememwl(uint32_t addr, uint16_t val) { mem_mapping_t *map; - int i; uint64_t a; addr64a[0] = addr; @@ -960,7 +972,7 @@ writememwl(uint32_t addr, uint16_t val) cycles -= timing_misaligned; if ((addr & 0xfff) > 0xffe) { if (cr0 >> 31) { - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { /* Do not translate a page that has a valid lookup, as that is by definition valid and the whole purpose of the lookup is to avoid repeat identical translations. */ if (!page_lookup[(addr + i) >> 12] || !page_lookup[(addr + i) >> 12]->write_b) { @@ -1004,13 +1016,13 @@ writememwl(uint32_t addr, uint16_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_w) { - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); return; } } @@ -1052,10 +1064,10 @@ readmemwl_no_mmut(uint32_t addr, uint32_t *a64) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_w) - return map->read_w(addr, map->p); + return map->read_w(addr, map->priv); if (map && map->read_b) { - return map->read_b(addr, map->p) | ((uint16_t) (map->read_b(addr + 1, map->p)) << 8); + return map->read_b(addr, map->priv) | ((uint16_t) (map->read_b(addr + 1, map->priv)) << 8); } return 0xffff; @@ -1107,13 +1119,13 @@ writememwl_no_mmut(uint32_t addr, uint32_t *a64, uint16_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_w) { - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); return; } } @@ -1181,13 +1193,13 @@ readmemll(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_l) - return map->read_l(addr, map->p); + return map->read_l(addr, map->priv); if (map && map->read_w) - return map->read_w(addr, map->p) | ((uint32_t) (map->read_w(addr + 2, map->p)) << 16); + return map->read_w(addr, map->priv) | ((uint32_t) (map->read_w(addr + 2, map->priv)) << 16); if (map && map->read_b) - return map->read_b(addr, map->p) | ((uint32_t) (map->read_b(addr + 1, map->p)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->p)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->p)) << 24); + return map->read_b(addr, map->priv) | ((uint32_t) (map->read_b(addr + 1, map->priv)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->priv)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->priv)) << 24); return 0xffffffff; } @@ -1268,19 +1280,19 @@ writememll(uint32_t addr, uint32_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_l) { - map->write_l(addr, val, map->p); + map->write_l(addr, val, map->priv); return; } if (map && map->write_w) { - map->write_w(addr, val, map->p); - map->write_w(addr + 2, val >> 16, map->p); + map->write_w(addr, val, map->priv); + map->write_w(addr + 2, val >> 16, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); - map->write_b(addr + 2, val >> 16, map->p); - map->write_b(addr + 3, val >> 24, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); + map->write_b(addr + 2, val >> 16, map->priv); + map->write_b(addr + 3, val >> 24, map->priv); return; } } @@ -1322,13 +1334,13 @@ readmemll_no_mmut(uint32_t addr, uint32_t *a64) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_l) - return map->read_l(addr, map->p); + return map->read_l(addr, map->priv); if (map && map->read_w) - return map->read_w(addr, map->p) | ((uint32_t) (map->read_w(addr + 2, map->p)) << 16); + return map->read_w(addr, map->priv) | ((uint32_t) (map->read_w(addr + 2, map->priv)) << 16); if (map && map->read_b) - return map->read_b(addr, map->p) | ((uint32_t) (map->read_b(addr + 1, map->p)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->p)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->p)) << 24); + return map->read_b(addr, map->priv) | ((uint32_t) (map->read_b(addr + 1, map->priv)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->priv)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->priv)) << 24); return 0xffffffff; } @@ -1379,19 +1391,19 @@ writememll_no_mmut(uint32_t addr, uint32_t *a64, uint32_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_l) { - map->write_l(addr, val, map->p); + map->write_l(addr, val, map->priv); return; } if (map && map->write_w) { - map->write_w(addr, val, map->p); - map->write_w(addr + 2, val >> 16, map->p); + map->write_w(addr, val, map->priv); + map->write_w(addr + 2, val >> 16, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); - map->write_b(addr + 2, val >> 16, map->p); - map->write_b(addr + 3, val >> 24, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); + map->write_b(addr + 2, val >> 16, map->priv); + map->write_b(addr + 3, val >> 24, map->priv); return; } } @@ -1457,7 +1469,7 @@ readmemql(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_l) - return map->read_l(addr, map->p) | ((uint64_t) map->read_l(addr + 4, map->p) << 32); + return map->read_l(addr, map->priv) | ((uint64_t) map->read_l(addr + 4, map->priv) << 32); return readmemll(addr) | ((uint64_t) readmemll(addr + 4) << 32); } @@ -1536,26 +1548,26 @@ writememql(uint32_t addr, uint64_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_l) { - map->write_l(addr, val, map->p); - map->write_l(addr + 4, val >> 32, map->p); + map->write_l(addr, val, map->priv); + map->write_l(addr + 4, val >> 32, map->priv); return; } if (map && map->write_w) { - map->write_w(addr, val, map->p); - map->write_w(addr + 2, val >> 16, map->p); - map->write_w(addr + 4, val >> 32, map->p); - map->write_w(addr + 6, val >> 48, map->p); + map->write_w(addr, val, map->priv); + map->write_w(addr + 2, val >> 16, map->priv); + map->write_w(addr + 4, val >> 32, map->priv); + map->write_w(addr + 6, val >> 48, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); - map->write_b(addr + 2, val >> 16, map->p); - map->write_b(addr + 3, val >> 24, map->p); - map->write_b(addr + 4, val >> 32, map->p); - map->write_b(addr + 5, val >> 40, map->p); - map->write_b(addr + 6, val >> 48, map->p); - map->write_b(addr + 7, val >> 56, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); + map->write_b(addr + 2, val >> 16, map->priv); + map->write_b(addr + 3, val >> 24, map->priv); + map->write_b(addr + 4, val >> 32, map->priv); + map->write_b(addr + 5, val >> 40, map->priv); + map->write_b(addr + 6, val >> 48, map->priv); + map->write_b(addr + 7, val >> 56, map->priv); return; } } @@ -1563,7 +1575,8 @@ writememql(uint32_t addr, uint64_t val) void do_mmutranslate(uint32_t addr, uint32_t *a64, int num, int write) { - int i, cond = 1; + int i; + int cond = 1; uint32_t last_addr = addr + (num - 1); uint64_t a = 0x0000000000000000ULL; @@ -1621,7 +1634,7 @@ mem_readb_phys(uint32_t addr) if (map->exec) ret = map->exec[(addr - map->base) & map->mask]; else if (map->read_b) - ret = map->read_b(addr, map->p); + ret = map->read_b(addr, map->priv); } return ret; @@ -1630,8 +1643,9 @@ mem_readb_phys(uint32_t addr) uint16_t mem_readw_phys(uint32_t addr) { - mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; - uint16_t ret, *p; + mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; + uint16_t ret; + const uint16_t *p; mem_logical_addr = 0xffffffff; @@ -1639,7 +1653,7 @@ mem_readw_phys(uint32_t addr) p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]); ret = *p; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->read_w)) - ret = map->read_w(addr, map->p); + ret = map->read_w(addr, map->priv); else { ret = mem_readb_phys(addr + 1) << 8; ret |= mem_readb_phys(addr); @@ -1651,8 +1665,9 @@ mem_readw_phys(uint32_t addr) uint32_t mem_readl_phys(uint32_t addr) { - mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; - uint32_t ret, *p; + mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; + uint32_t ret; + const uint32_t *p; mem_logical_addr = 0xffffffff; @@ -1660,7 +1675,7 @@ mem_readl_phys(uint32_t addr) p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]); ret = *p; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->read_l)) - ret = map->read_l(addr, map->p); + ret = map->read_l(addr, map->priv); else { ret = mem_readw_phys(addr + 2) << 16; ret |= mem_readw_phys(addr); @@ -1699,7 +1714,7 @@ mem_writeb_phys(uint32_t addr, uint8_t val) if (map->exec) map->exec[(addr - map->base) & map->mask] = val; else if (map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); } } @@ -1715,7 +1730,7 @@ mem_writew_phys(uint32_t addr, uint16_t val) p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]); *p = val; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->write_w)) - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); else { mem_writeb_phys(addr, val & 0xff); mem_writeb_phys(addr + 1, (val >> 8) & 0xff); @@ -1734,7 +1749,7 @@ mem_writel_phys(uint32_t addr, uint32_t val) p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]); *p = val; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->write_l)) - map->write_l(addr, val, map->p); + map->write_l(addr, val, map->priv); else { mem_writew_phys(addr, val & 0xffff); mem_writew_phys(addr + 2, (val >> 16) & 0xffff); @@ -1744,9 +1759,9 @@ mem_writel_phys(uint32_t addr, uint32_t val) void mem_write_phys(void *src, uint32_t addr, int transfer_size) { - uint8_t *pb; - uint16_t *pw; - uint32_t *pl; + const uint8_t *pb; + const uint16_t *pw; + const uint32_t *pl; if (transfer_size == 4) { pl = (uint32_t *) src; @@ -1761,7 +1776,7 @@ mem_write_phys(void *src, uint32_t addr, int transfer_size) } uint8_t -mem_read_ram(uint32_t addr, void *priv) +mem_read_ram(uint32_t addr, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -1775,7 +1790,7 @@ mem_read_ram(uint32_t addr, void *priv) } uint16_t -mem_read_ramw(uint32_t addr, void *priv) +mem_read_ramw(uint32_t addr, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -1789,7 +1804,7 @@ mem_read_ramw(uint32_t addr, void *priv) } uint32_t -mem_read_raml(uint32_t addr, void *priv) +mem_read_raml(uint32_t addr, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -1803,7 +1818,7 @@ mem_read_raml(uint32_t addr, void *priv) } uint8_t -mem_read_ram_2gb(uint32_t addr, void *priv) +mem_read_ram_2gb(uint32_t addr, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -1816,7 +1831,7 @@ mem_read_ram_2gb(uint32_t addr, void *priv) } uint16_t -mem_read_ram_2gbw(uint32_t addr, void *priv) +mem_read_ram_2gbw(uint32_t addr, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -1829,7 +1844,7 @@ mem_read_ram_2gbw(uint32_t addr, void *priv) } uint32_t -mem_read_ram_2gbl(uint32_t addr, void *priv) +mem_read_ram_2gbl(uint32_t addr, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -1843,71 +1858,71 @@ mem_read_ram_2gbl(uint32_t addr, void *priv) #ifdef USE_NEW_DYNAREC static inline int -page_index(page_t *p) +page_index(page_t *page) { - return ((uintptr_t) p - (uintptr_t) pages) / sizeof(page_t); + return ((uintptr_t) page - (uintptr_t) pages) / sizeof(page_t); } void -page_add_to_evict_list(page_t *p) +page_add_to_evict_list(page_t *page) { - pages[purgable_page_list_head].evict_prev = page_index(p); - p->evict_next = purgable_page_list_head; - p->evict_prev = 0; + pages[purgable_page_list_head].evict_prev = page_index(page); + page->evict_next = purgable_page_list_head; + page->evict_prev = 0; purgable_page_list_head = pages[purgable_page_list_head].evict_prev; purgeable_page_count++; } void -page_remove_from_evict_list(page_t *p) +page_remove_from_evict_list(page_t *page) { - if (!page_in_evict_list(p)) + if (!page_in_evict_list(page)) fatal("page_remove_from_evict_list: not in evict list!\n"); - if (p->evict_prev) - pages[p->evict_prev].evict_next = p->evict_next; + if (page->evict_prev) + pages[page->evict_prev].evict_next = page->evict_next; else - purgable_page_list_head = p->evict_next; - if (p->evict_next) - pages[p->evict_next].evict_prev = p->evict_prev; - p->evict_prev = EVICT_NOT_IN_LIST; + purgable_page_list_head = page->evict_next; + if (page->evict_next) + pages[page->evict_next].evict_prev = page->evict_prev; + page->evict_prev = EVICT_NOT_IN_LIST; purgeable_page_count--; } void -mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *p) +mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *page) { - if (p == NULL) + if (page == NULL) return; # ifdef USE_DYNAREC - if ((p->mem == NULL) || (p->mem == page_ff) || (val != p->mem[addr & 0xfff]) || codegen_in_recompile) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != page->mem[addr & 0xfff]) || codegen_in_recompile) { # else - if ((p->mem == NULL) || (p->mem == page_ff) || (val != p->mem[addr & 0xfff])) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != page->mem[addr & 0xfff])) { # endif uint64_t mask = (uint64_t) 1 << ((addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); int byte_offset = (addr >> PAGE_BYTE_MASK_SHIFT) & PAGE_BYTE_MASK_OFFSET_MASK; uint64_t byte_mask = (uint64_t) 1 << (addr & PAGE_BYTE_MASK_MASK); - p->mem[addr & 0xfff] = val; - p->dirty_mask |= mask; - if ((p->code_present_mask & mask) && !page_in_evict_list(p)) - page_add_to_evict_list(p); - p->byte_dirty_mask[byte_offset] |= byte_mask; - if ((p->byte_code_present_mask[byte_offset] & byte_mask) && !page_in_evict_list(p)) - page_add_to_evict_list(p); + page->mem[addr & 0xfff] = val; + page->dirty_mask |= mask; + if ((page->code_present_mask & mask) && !page_in_evict_list(page)) + page_add_to_evict_list(page); + page->byte_dirty_mask[byte_offset] |= byte_mask; + if ((page->byte_code_present_mask[byte_offset] & byte_mask) && !page_in_evict_list(page)) + page_add_to_evict_list(page); } } void -mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *p) +mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *page) { - if (p == NULL) + if (page == NULL) return; # ifdef USE_DYNAREC - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint16_t *) &p->mem[addr & 0xfff]) || codegen_in_recompile) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint16_t *) &page->mem[addr & 0xfff]) || codegen_in_recompile) { # else - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint16_t *) &p->mem[addr & 0xfff])) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint16_t *) &page->mem[addr & 0xfff])) { # endif uint64_t mask = (uint64_t) 1 << ((addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); int byte_offset = (addr >> PAGE_BYTE_MASK_SHIFT) & PAGE_BYTE_MASK_OFFSET_MASK; @@ -1915,34 +1930,34 @@ mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *p) if ((addr & 0xf) == 0xf) mask |= (mask << 1); - *(uint16_t *) &p->mem[addr & 0xfff] = val; - p->dirty_mask |= mask; - if ((p->code_present_mask & mask) && !page_in_evict_list(p)) - page_add_to_evict_list(p); + *(uint16_t *) &page->mem[addr & 0xfff] = val; + page->dirty_mask |= mask; + if ((page->code_present_mask & mask) && !page_in_evict_list(page)) + page_add_to_evict_list(page); if ((addr & PAGE_BYTE_MASK_MASK) == PAGE_BYTE_MASK_MASK) { - p->byte_dirty_mask[byte_offset + 1] |= 1; - if ((p->byte_code_present_mask[byte_offset + 1] & 1) && !page_in_evict_list(p)) - page_add_to_evict_list(p); + page->byte_dirty_mask[byte_offset + 1] |= 1; + if ((page->byte_code_present_mask[byte_offset + 1] & 1) && !page_in_evict_list(page)) + page_add_to_evict_list(page); } else byte_mask |= (byte_mask << 1); - p->byte_dirty_mask[byte_offset] |= byte_mask; + page->byte_dirty_mask[byte_offset] |= byte_mask; - if ((p->byte_code_present_mask[byte_offset] & byte_mask) && !page_in_evict_list(p)) - page_add_to_evict_list(p); + if ((page->byte_code_present_mask[byte_offset] & byte_mask) && !page_in_evict_list(page)) + page_add_to_evict_list(page); } } void -mem_write_raml_page(uint32_t addr, uint32_t val, page_t *p) +mem_write_raml_page(uint32_t addr, uint32_t val, page_t *page) { - if (p == NULL) + if (page == NULL) return; # ifdef USE_DYNAREC - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint32_t *) &p->mem[addr & 0xfff]) || codegen_in_recompile) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint32_t *) &page->mem[addr & 0xfff]) || codegen_in_recompile) { # else - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint32_t *) &p->mem[addr & 0xfff])) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint32_t *) &page->mem[addr & 0xfff])) { # endif uint64_t mask = (uint64_t) 1 << ((addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); int byte_offset = (addr >> PAGE_BYTE_MASK_SHIFT) & PAGE_BYTE_MASK_OFFSET_MASK; @@ -1950,79 +1965,79 @@ mem_write_raml_page(uint32_t addr, uint32_t val, page_t *p) if ((addr & 0xf) >= 0xd) mask |= (mask << 1); - *(uint32_t *) &p->mem[addr & 0xfff] = val; - p->dirty_mask |= mask; - p->byte_dirty_mask[byte_offset] |= byte_mask; - if (!page_in_evict_list(p) && ((p->code_present_mask & mask) || (p->byte_code_present_mask[byte_offset] & byte_mask))) - page_add_to_evict_list(p); + *(uint32_t *) &page->mem[addr & 0xfff] = val; + page->dirty_mask |= mask; + page->byte_dirty_mask[byte_offset] |= byte_mask; + if (!page_in_evict_list(page) && ((page->code_present_mask & mask) || (page->byte_code_present_mask[byte_offset] & byte_mask))) + page_add_to_evict_list(page); if ((addr & PAGE_BYTE_MASK_MASK) > (PAGE_BYTE_MASK_MASK - 3)) { uint32_t byte_mask_2 = 0xf >> (4 - (addr & 3)); - p->byte_dirty_mask[byte_offset + 1] |= byte_mask_2; - if ((p->byte_code_present_mask[byte_offset + 1] & byte_mask_2) && !page_in_evict_list(p)) - page_add_to_evict_list(p); + page->byte_dirty_mask[byte_offset + 1] |= byte_mask_2; + if ((page->byte_code_present_mask[byte_offset + 1] & byte_mask_2) && !page_in_evict_list(page)) + page_add_to_evict_list(page); } } } #else void -mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *p) +mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *page) { - if (p == NULL) + if (page == NULL) return; # ifdef USE_DYNAREC - if ((p->mem == NULL) || (p->mem == page_ff) || (val != p->mem[addr & 0xfff]) || codegen_in_recompile) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != page->mem[addr & 0xfff]) || codegen_in_recompile) { # else - if ((p->mem == NULL) || (p->mem == page_ff) || (val != p->mem[addr & 0xfff])) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != page->mem[addr & 0xfff])) { # endif uint64_t mask = (uint64_t) 1 << ((addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); - p->dirty_mask[(addr >> PAGE_MASK_INDEX_SHIFT) & PAGE_MASK_INDEX_MASK] |= mask; - p->mem[addr & 0xfff] = val; + page->dirty_mask[(addr >> PAGE_MASK_INDEX_SHIFT) & PAGE_MASK_INDEX_MASK] |= mask; + page->mem[addr & 0xfff] = val; } } void -mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *p) +mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *page) { - if (p == NULL) + if (page == NULL) return; # ifdef USE_DYNAREC - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint16_t *) &p->mem[addr & 0xfff]) || codegen_in_recompile) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint16_t *) &page->mem[addr & 0xfff]) || codegen_in_recompile) { # else - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint16_t *) &p->mem[addr & 0xfff])) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint16_t *) &page->mem[addr & 0xfff])) { # endif uint64_t mask = (uint64_t) 1 << ((addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); if ((addr & 0xf) == 0xf) mask |= (mask << 1); - p->dirty_mask[(addr >> PAGE_MASK_INDEX_SHIFT) & PAGE_MASK_INDEX_MASK] |= mask; - *(uint16_t *) &p->mem[addr & 0xfff] = val; + page->dirty_mask[(addr >> PAGE_MASK_INDEX_SHIFT) & PAGE_MASK_INDEX_MASK] |= mask; + *(uint16_t *) &page->mem[addr & 0xfff] = val; } } void -mem_write_raml_page(uint32_t addr, uint32_t val, page_t *p) +mem_write_raml_page(uint32_t addr, uint32_t val, page_t *page) { - if (p == NULL) + if (page == NULL) return; # ifdef USE_DYNAREC - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint32_t *) &p->mem[addr & 0xfff]) || codegen_in_recompile) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint32_t *) &page->mem[addr & 0xfff]) || codegen_in_recompile) { # else - if ((p->mem == NULL) || (p->mem == page_ff) || (val != *(uint32_t *) &p->mem[addr & 0xfff])) { + if ((page->mem == NULL) || (page->mem == page_ff) || (val != *(uint32_t *) &page->mem[addr & 0xfff])) { # endif uint64_t mask = (uint64_t) 1 << ((addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); if ((addr & 0xf) >= 0xd) mask |= (mask << 1); - p->dirty_mask[(addr >> PAGE_MASK_INDEX_SHIFT) & PAGE_MASK_INDEX_MASK] |= mask; - *(uint32_t *) &p->mem[addr & 0xfff] = val; + page->dirty_mask[(addr >> PAGE_MASK_INDEX_SHIFT) & PAGE_MASK_INDEX_MASK] |= mask; + *(uint32_t *) &page->mem[addr & 0xfff] = val; } } #endif void -mem_write_ram(uint32_t addr, uint8_t val, void *priv) +mem_write_ram(uint32_t addr, uint8_t val, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -2036,7 +2051,7 @@ mem_write_ram(uint32_t addr, uint8_t val, void *priv) } void -mem_write_ramw(uint32_t addr, uint16_t val, void *priv) +mem_write_ramw(uint32_t addr, uint16_t val, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -2050,7 +2065,7 @@ mem_write_ramw(uint32_t addr, uint16_t val, void *priv) } void -mem_write_raml(uint32_t addr, uint32_t val, void *priv) +mem_write_raml(uint32_t addr, uint32_t val, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -2064,7 +2079,7 @@ mem_write_raml(uint32_t addr, uint32_t val, void *priv) } static uint8_t -mem_read_remapped(uint32_t addr, void *priv) +mem_read_remapped(uint32_t addr, UNUSED(void *priv)) { addr = 0xA0000 + (addr - remap_start_addr); if (is286) @@ -2073,7 +2088,7 @@ mem_read_remapped(uint32_t addr, void *priv) } static uint16_t -mem_read_remappedw(uint32_t addr, void *priv) +mem_read_remappedw(uint32_t addr, UNUSED(void *priv)) { addr = 0xA0000 + (addr - remap_start_addr); if (is286) @@ -2082,7 +2097,7 @@ mem_read_remappedw(uint32_t addr, void *priv) } static uint32_t -mem_read_remappedl(uint32_t addr, void *priv) +mem_read_remappedl(uint32_t addr, UNUSED(void *priv)) { addr = 0xA0000 + (addr - remap_start_addr); if (is286) @@ -2091,7 +2106,7 @@ mem_read_remappedl(uint32_t addr, void *priv) } static uint8_t -mem_read_remapped2(uint32_t addr, void *priv) +mem_read_remapped2(uint32_t addr, UNUSED(void *priv)) { addr = 0xD0000 + (addr - remap_start_addr2); if (is286) @@ -2100,7 +2115,7 @@ mem_read_remapped2(uint32_t addr, void *priv) } static uint16_t -mem_read_remappedw2(uint32_t addr, void *priv) +mem_read_remappedw2(uint32_t addr, UNUSED(void *priv)) { addr = 0xD0000 + (addr - remap_start_addr2); if (is286) @@ -2109,7 +2124,7 @@ mem_read_remappedw2(uint32_t addr, void *priv) } static uint32_t -mem_read_remappedl2(uint32_t addr, void *priv) +mem_read_remappedl2(uint32_t addr, UNUSED(void *priv)) { addr = 0xD0000 + (addr - remap_start_addr2); if (is286) @@ -2118,7 +2133,7 @@ mem_read_remappedl2(uint32_t addr, void *priv) } static void -mem_write_remapped(uint32_t addr, uint8_t val, void *priv) +mem_write_remapped(uint32_t addr, uint8_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xA0000 + (addr - remap_start_addr); @@ -2130,7 +2145,7 @@ mem_write_remapped(uint32_t addr, uint8_t val, void *priv) } static void -mem_write_remappedw(uint32_t addr, uint16_t val, void *priv) +mem_write_remappedw(uint32_t addr, uint16_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xA0000 + (addr - remap_start_addr); @@ -2142,7 +2157,7 @@ mem_write_remappedw(uint32_t addr, uint16_t val, void *priv) } static void -mem_write_remappedl(uint32_t addr, uint32_t val, void *priv) +mem_write_remappedl(uint32_t addr, uint32_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xA0000 + (addr - remap_start_addr); @@ -2154,7 +2169,7 @@ mem_write_remappedl(uint32_t addr, uint32_t val, void *priv) } static void -mem_write_remapped2(uint32_t addr, uint8_t val, void *priv) +mem_write_remapped2(uint32_t addr, uint8_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xD0000 + (addr - remap_start_addr2); @@ -2166,7 +2181,7 @@ mem_write_remapped2(uint32_t addr, uint8_t val, void *priv) } static void -mem_write_remappedw2(uint32_t addr, uint16_t val, void *priv) +mem_write_remappedw2(uint32_t addr, uint16_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xD0000 + (addr - remap_start_addr2); @@ -2178,7 +2193,7 @@ mem_write_remappedw2(uint32_t addr, uint16_t val, void *priv) } static void -mem_write_remappedl2(uint32_t addr, uint32_t val, void *priv) +mem_write_remappedl2(uint32_t addr, uint32_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xD0000 + (addr - remap_start_addr2); @@ -2193,7 +2208,7 @@ void mem_invalidate_range(uint32_t start_addr, uint32_t end_addr) { #ifdef USE_NEW_DYNAREC - page_t *p; + page_t *page; start_addr &= ~PAGE_MASK_MASK; end_addr = (end_addr + PAGE_MASK_MASK) & ~PAGE_MASK_MASK; @@ -2202,15 +2217,15 @@ mem_invalidate_range(uint32_t start_addr, uint32_t end_addr) if ((start_addr >> 12) >= pages_sz) continue; - p = &pages[start_addr >> 12]; - if (p) { - p->dirty_mask = 0xffffffffffffffffULL; + page = &pages[start_addr >> 12]; + if (page) { + page->dirty_mask = 0xffffffffffffffffULL; - if (p->byte_dirty_mask) - memset(p->byte_dirty_mask, 0xff, 64 * sizeof(uint64_t)); + if ((page->mem != page_ff) && page->byte_dirty_mask) + memset(page->byte_dirty_mask, 0xff, 64 * sizeof(uint64_t)); - if (!page_in_evict_list(p)) - page_add_to_evict_list(p); + if (!page_in_evict_list(page)) + page_add_to_evict_list(page); } } #else @@ -2312,22 +2327,72 @@ mem_mapping_recalc(uint64_t base, uint64_t size) map = map->next; } - flushmmucache_cr3(); + flushmmucache_nopc(); + +#ifdef ENABLE_MEM_LOG + pclog("\nMemory map:\n"); + mem_mapping_t *write = (mem_mapping_t *) -1, *read = (mem_mapping_t *) -1, *write_bus = (mem_mapping_t *) -1, *read_bus = (mem_mapping_t *) -1; + for (c = 0; c < (sizeof(write_mapping) / sizeof(write_mapping[0])); c++) { + if ((write_mapping[c] == write) && (read_mapping[c] == read) && (write_mapping_bus[c] == write_bus) && (read_mapping_bus[c] == read_bus)) + continue; + write = write_mapping[c]; + read = read_mapping[c]; + write_bus = write_mapping_bus[c]; + read_bus = read_mapping_bus[c]; + + pclog("%08X | ", c << MEM_GRANULARITY_BITS); + if (read) { + pclog("R%c%c%c %08X+% 8X", + read->read_b ? 'b' : ' ', read->read_w ? 'w' : ' ', read->read_l ? 'l' : ' ', + read->base, read->size); + } else { + pclog(" "); + } + if (write) { + pclog(" | W%c%c%c %08X+% 8X", + write->write_b ? 'b' : ' ', write->write_w ? 'w' : ' ', write->write_l ? 'l' : ' ', + write->base, write->size); + } else { + pclog(" | "); + } + pclog(" | %c\n", _mem_exec[c] ? 'X' : ' '); + + if ((write != write_bus) || (read != read_bus)) { + pclog(" ^ bus | "); + if (read_bus) { + pclog("R%c%c%c %08X+% 8X", + read_bus->read_b ? 'b' : ' ', read_bus->read_w ? 'w' : ' ', read_bus->read_l ? 'l' : ' ', + read_bus->base, read_bus->size); + } else { + pclog(" "); + } + if (write_bus) { + pclog(" | W%c%c%c %08X+% 8X", + write_bus->write_b ? 'b' : ' ', write_bus->write_w ? 'w' : ' ', write_bus->write_l ? 'l' : ' ', + write_bus->base, write_bus->size); + } else { + pclog(" | "); + } + pclog(" |\n"); + } + } + pclog("\n"); +#endif } void mem_mapping_set(mem_mapping_t *map, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t fl, - void *p) + void *priv) { if (size != 0x00000000) map->enable = 1; @@ -2344,7 +2409,7 @@ mem_mapping_set(mem_mapping_t *map, map->write_l = write_l; map->exec = exec; map->flags = fl; - map->p = p; + map->priv = priv; map->next = NULL; mem_log("mem_mapping_add(): Linked list structure: %08X -> %08X -> %08X\n", map->prev, map, map->next); @@ -2357,15 +2422,15 @@ void mem_mapping_add(mem_mapping_t *map, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t fl, - void *p) + void *priv) { /* Do a sanity check */ if ((base_mapping == NULL) && (last_mapping != NULL)) { @@ -2396,7 +2461,7 @@ mem_mapping_add(mem_mapping_t *map, last_mapping = map; mem_mapping_set(map, base, size, read_b, read_w, read_l, - write_b, write_w, write_l, exec, fl, p); + write_b, write_w, write_l, exec, fl, priv); } void @@ -2407,12 +2472,12 @@ mem_mapping_do_recalc(mem_mapping_t *map) void mem_mapping_set_handler(mem_mapping_t *map, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p)) + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv)) { map->read_b = read_b; map->read_w = read_w; @@ -2456,9 +2521,9 @@ mem_mapping_set_mask(mem_mapping_t *map, uint32_t mask) } void -mem_mapping_set_p(mem_mapping_t *map, void *p) +mem_mapping_set_p(mem_mapping_t *map, void *priv) { - map->p = p; + map->priv = priv; } void @@ -2480,13 +2545,11 @@ mem_mapping_enable(mem_mapping_t *map) void mem_set_access(uint8_t bitmap, int mode, uint32_t base, uint32_t size, uint16_t access) { - uint32_t c; - uint16_t mask, smstate = 0x0000; + uint16_t mask; + uint16_t smstate = 0x0000; const uint16_t smstates[4] = { 0x0000, (MEM_READ_SMRAM | MEM_WRITE_SMRAM), MEM_READ_SMRAM_EX, (MEM_READ_DISABLED_EX | MEM_WRITE_DISABLED_EX) }; - int i; - if (mode) mask = 0x2d6b; else @@ -2508,8 +2571,8 @@ mem_set_access(uint8_t bitmap, int mode, uint32_t base, uint32_t size, uint16_t } else smstate = access & 0x6f7b; - for (c = 0; c < size; c += MEM_GRANULARITY_SIZE) { - for (i = 0; i < 4; i++) { + for (uint32_t c = 0; c < size; c += MEM_GRANULARITY_SIZE) { + for (uint8_t i = 0; i < 4; i++) { if (bitmap & (1 << i)) { _mem_state[(c + base) >> MEM_GRANULARITY_BITS].vals[i] = (_mem_state[(c + base) >> MEM_GRANULARITY_BITS].vals[i] & mask) | smstate; } @@ -2530,11 +2593,14 @@ void mem_a20_init(void) { if (is286) { - rammask = cpu_16bitbus ? 0xefffff : 0xffefffff; + mem_a20_key = mem_a20_alt = mem_a20_state = 0; + rammask = cpu_16bitbus ? 0xffffff : 0xffffffff; if (is6117) rammask |= 0x03000000; flushmmucache(); +#if 0 mem_a20_state = mem_a20_key | mem_a20_alt; +#endif } else { rammask = 0xfffff; flushmmucache(); @@ -2546,7 +2612,8 @@ mem_a20_init(void) void mem_close(void) { - mem_mapping_t *map = base_mapping, *next; + mem_mapping_t *map = base_mapping; + mem_mapping_t *next; while (map != NULL) { next = map->next; @@ -2577,7 +2644,7 @@ mem_init_ram_mapping(mem_mapping_t *mapping, uint32_t base, uint32_t size) void mem_reset(void) { - uint32_t c, m; + size_t m; memset(page_ff, 0xff, sizeof(page_ff)); @@ -2615,7 +2682,7 @@ mem_reset(void) mem_size = 2097152; #endif - m = 1024UL * mem_size; + m = 1024UL * (size_t) mem_size; #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (mem_size > 1048576) { @@ -2692,7 +2759,7 @@ mem_reset(void) memset(byte_code_present_mask, 0, (mem_size * 1024) / 8); #endif - for (c = 0; c < pages_sz; c++) { + for (uint32_t c = 0; c < pages_sz; c++) { if ((c << 12) >= (mem_size << 10)) pages[c].mem = page_ff; else { @@ -2805,11 +2872,13 @@ mem_remap_top(int kb) { uint32_t c; uint32_t start = (mem_size >= 1024) ? mem_size : 1024; - int offset, size = mem_size - 640; + int offset; + int size = mem_size - 640; int set = 1; static int old_kb = 0; int sis_mode = 0; - uint32_t start_addr = 0, addr = 0; + uint32_t start_addr = 0; + uint32_t addr = 0; mem_log("MEM: remapping top %iKB (mem=%i)\n", kb, mem_size); if (mem_size <= 640) @@ -2821,6 +2890,10 @@ mem_remap_top(int kb) sis_mode = 1; } + /* Do not remap if we're have more than (16 MB - RAM) memory. */ + if ((kb != 0) && (mem_size >= (16384 - kb))) + return; + if (kb == 0) { kb = old_kb; set = 0; @@ -2842,7 +2915,7 @@ mem_remap_top(int kb) if (addr >= 0x000c0000) addr += 0x00010000; } - if (start_addr != 0) + if (start_addr == 0) start_addr = addr; pages[c].mem = set ? &ram[addr] : page_ff; pages[c].write_b = set ? mem_write_ramb_page : NULL; @@ -2927,12 +3000,10 @@ mem_remap_top(int kb) void mem_reset_page_blocks(void) { - uint32_t c; - if (pages == NULL) return; - for (c = 0; c < pages_sz; c++) { + for (uint32_t c = 0; c < pages_sz; c++) { pages[c].write_b = mem_write_ramb_page; pages[c].write_w = mem_write_ramw_page; pages[c].write_l = mem_write_raml_page; @@ -2963,12 +3034,12 @@ mem_a20_recalc(void) state = mem_a20_key | mem_a20_alt; if (state && !mem_a20_state) { - rammask = (cpu_16bitbus) ? 0xffffff : 0xffffffff; + rammask = cpu_16bitbus ? 0xffffff : 0xffffffff; if (is6117) rammask |= 0x03000000; flushmmucache(); } else if (!state && mem_a20_state) { - rammask = (cpu_16bitbus) ? 0xefffff : 0xffefffff; + rammask = cpu_16bitbus ? 0xefffff : 0xffefffff; if (is6117) rammask |= 0x03000000; flushmmucache(); diff --git a/src/mem/rom.c b/src/mem/rom.c index 25ca1db71..4a20e8ebc 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -90,12 +90,11 @@ FILE * rom_fopen(const char *fn, char *mode) { char temp[1024]; - rom_path_t *rom_path; FILE *fp = NULL; if (strstr(fn, "roms/") == fn) { /* Relative path */ - for (rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { + for (rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { path_append_filename(temp, rom_path->path, fn + 5); if ((fp = plat_fopen(temp, mode)) != NULL) { @@ -114,11 +113,10 @@ int rom_getfile(char *fn, char *s, int size) { char temp[1024]; - rom_path_t *rom_path; if (strstr(fn, "roms/") == fn) { /* Relative path */ - for (rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { + for (rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { path_append_filename(temp, rom_path->path, fn + 5); if (rom_present(temp)) { @@ -140,23 +138,23 @@ rom_getfile(char *fn, char *s, int size) } int -rom_present(char *fn) +rom_present(const char *fn) { - FILE *f; + FILE *fp; - f = rom_fopen(fn, "rb"); - if (f != NULL) { - (void) fclose(f); - return (1); + fp = rom_fopen(fn, "rb"); + if (fp != NULL) { + (void) fclose(fp); + return 1; } - return (0); + return 0; } uint8_t rom_read(uint32_t addr, void *priv) { - rom_t *rom = (rom_t *) priv; + const rom_t *rom = (rom_t *) priv; #ifdef ROM_TRACE if (rom->mapping.base == ROM_TRACE) @@ -207,12 +205,11 @@ rom_readl(uint32_t addr, void *priv) int rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn, "rb"); - int i; + FILE *fp = rom_fopen(fn, "rb"); - if (f == NULL) { + if (fp == NULL) { rom_log("ROM: image '%s' not found\n", fn); - return (0); + return 0; } /* Make sure we only look at the base-256K offset. */ @@ -222,32 +219,32 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t addr &= 0x03ffff; if (ptr != NULL) { - if (fseek(f, off, SEEK_SET) == -1) + if (fseek(fp, off, SEEK_SET) == -1) fatal("rom_load_linear(): Error seeking to the beginning of the file\n"); - for (i = 0; i < (sz >> 1); i++) { - if (fread(ptr + (addr + (i << 1)), 1, 1, f) != 1) + for (int i = 0; i < (sz >> 1); i++) { + if (fread(ptr + (addr + (i << 1)), 1, 1, fp) != 1) fatal("rom_load_linear(): Error reading even data\n"); } - for (i = 0; i < (sz >> 1); i++) { - if (fread(ptr + (addr + (i << 1) + 1), 1, 1, f) != 1) + for (int i = 0; i < (sz >> 1); i++) { + if (fread(ptr + (addr + (i << 1) + 1), 1, 1, fp) != 1) fatal("rom_load_linear(): Error reading od data\n"); } } - (void) fclose(f); + (void) fclose(fp); - return (1); + return 1; } /* Load a ROM BIOS from its chips, interleaved mode. */ int rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn, "rb"); + FILE *fp = rom_fopen(fn, "rb"); - if (f == NULL) { + if (fp == NULL) { rom_log("ROM: image '%s' not found\n", fn); - return (0); + return 0; } /* Make sure we only look at the base-256K offset. */ @@ -257,26 +254,26 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) addr &= 0x03ffff; if (ptr != NULL) { - if (fseek(f, off, SEEK_SET) == -1) + if (fseek(fp, off, SEEK_SET) == -1) fatal("rom_load_linear(): Error seeking to the beginning of the file\n"); - if (fread(ptr + addr, 1, sz, f) > sz) + if (fread(ptr + addr, 1, sz, fp) > sz) fatal("rom_load_linear(): Error reading data\n"); } - (void) fclose(f); + (void) fclose(fp); - return (1); + return 1; } /* Load a ROM BIOS from its chips, linear mode with high bit flipped. */ int rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn, "rb"); + FILE *fp = rom_fopen(fn, "rb"); - if (f == NULL) { + if (fp == NULL) { rom_log("ROM: image '%s' not found\n", fn); - return (0); + return 0; } /* Make sure we only look at the base-256K offset. */ @@ -286,45 +283,44 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t addr &= 0x03ffff; } - (void) fseek(f, 0, SEEK_END); - if (ftell(f) < sz) { - (void) fclose(f); - return (0); + (void) fseek(fp, 0, SEEK_END); + if (ftell(fp) < sz) { + (void) fclose(fp); + return 0; } if (ptr != NULL) { - if (fseek(f, off, SEEK_SET) == -1) + if (fseek(fp, off, SEEK_SET) == -1) fatal("rom_load_linear_inverted(): Error seeking to the beginning of the file\n"); - if (fread(ptr + addr + 0x10000, 1, sz >> 1, f) > (sz >> 1)) + if (fread(ptr + addr + 0x10000, 1, sz >> 1, fp) > (sz >> 1)) fatal("rom_load_linear_inverted(): Error reading the upper half of the data\n"); - if (fread(ptr + addr, sz >> 1, 1, f) > (sz >> 1)) + if (fread(ptr + addr, sz >> 1, 1, fp) > (sz >> 1)) fatal("rom_load_linear_inverted(): Error reading the lower half of the data\n"); } - (void) fclose(f); + (void) fclose(fp); - return (1); + return 1; } /* Load a ROM BIOS from its chips, interleaved mode. */ int rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *fl = rom_fopen(fnl, "rb"); - FILE *fh = rom_fopen(fnh, "rb"); - int c; + FILE *fpl = rom_fopen(fnl, "rb"); + FILE *fph = rom_fopen(fnh, "rb"); - if (fl == NULL || fh == NULL) { - if (fl == NULL) + if (fpl == NULL || fph == NULL) { + if (fpl == NULL) rom_log("ROM: image '%s' not found\n", fnl); else - (void) fclose(fl); - if (fh == NULL) + (void) fclose(fpl); + if (fph == NULL) rom_log("ROM: image '%s' not found\n", fnh); else - (void) fclose(fh); + (void) fclose(fph); - return (0); + return 0; } /* Make sure we only look at the base-256K offset. */ @@ -335,18 +331,18 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in } if (ptr != NULL) { - (void) fseek(fl, off, SEEK_SET); - (void) fseek(fh, off, SEEK_SET); - for (c = 0; c < sz; c += 2) { - ptr[addr + c] = fgetc(fl) & 0xff; - ptr[addr + c + 1] = fgetc(fh) & 0xff; + (void) fseek(fpl, off, SEEK_SET); + (void) fseek(fph, off, SEEK_SET); + for (int c = 0; c < sz; c += 2) { + ptr[addr + c] = fgetc(fpl) & 0xff; + ptr[addr + c + 1] = fgetc(fph) & 0xff; } } - (void) fclose(fh); - (void) fclose(fl); + (void) fclose(fph); + (void) fclose(fpl); - return (1); + return 1; } static int @@ -387,7 +383,7 @@ rom_reset(uint32_t addr, int sz) } uint8_t -bios_read(uint32_t addr, void *priv) +bios_read(uint32_t addr, UNUSED(void *priv)) { uint8_t ret = 0xff; @@ -400,7 +396,7 @@ bios_read(uint32_t addr, void *priv) } uint16_t -bios_readw(uint32_t addr, void *priv) +bios_readw(uint32_t addr, UNUSED(void *priv)) { uint16_t ret = 0xffff; @@ -413,7 +409,7 @@ bios_readw(uint32_t addr, void *priv) } uint32_t -bios_readl(uint32_t addr, void *priv) +bios_readl(uint32_t addr, UNUSED(void *priv)) { uint32_t ret = 0xffffffff; @@ -428,8 +424,10 @@ bios_readl(uint32_t addr, void *priv) static void bios_add(void) { - int temp_cpu_type, temp_cpu_16bitbus = 1; - int temp_is286 = 0, temp_is6117 = 0; + int temp_cpu_type; + int temp_cpu_16bitbus = 1; + int temp_is286 = 0; + int temp_is6117 = 0; if (/*AT && */ cpu_s) { temp_cpu_type = cpu_s->cpu_type; @@ -443,7 +441,7 @@ bios_add(void) mem_mapping_add(&bios_mapping, 0xe0000, 0x20000, bios_read, bios_readw, bios_readl, NULL, NULL, NULL, - &rom[0x20000], MEM_MAPPING_EXTERNAL | MEM_MAPPING_ROM | MEM_MAPPING_ROMCS, 0); + &rom[biosmask + 1 - 0x20000], MEM_MAPPING_EXTERNAL | MEM_MAPPING_ROM | MEM_MAPPING_ROMCS, 0); mem_set_mem_state_both(0x0e0000, 0x20000, MEM_READ_ROMCS | MEM_WRITE_ROMCS); @@ -482,7 +480,7 @@ bios_load(const char *fn1, const char *fn2, uint32_t addr, int sz, int off, int { uint8_t ret = 0; uint8_t *ptr = NULL; - int i, old_sz = sz; + int old_sz = sz; /* f0000, 65536 = prepare 64k rom starting at f0000, load 64k bios at 0000 @@ -512,7 +510,7 @@ bios_load(const char *fn1, const char *fn2, uint32_t addr, int sz, int off, int if (!bios_only && (flags & FLAG_REP) && (old_sz >= 65536) && (sz < old_sz)) { old_sz /= sz; - for (i = 0; i < (old_sz - 1); i++) { + for (int i = 0; i < (old_sz - 1); i++) { rom_log("Copying ptr[%08X] to ptr[%08X]\n", addr - biosaddr, i * sz); memcpy(&(ptr[i * sz]), &(ptr[addr - biosaddr]), sz); } @@ -525,7 +523,7 @@ bios_load(const char *fn1, const char *fn2, uint32_t addr, int sz, int off, int } int -bios_load_linear_combined(const char *fn1, const char *fn2, int sz, int off) +bios_load_linear_combined(const char *fn1, const char *fn2, int sz, UNUSED(int off)) { uint8_t ret = 0; @@ -591,7 +589,7 @@ rom_init(rom_t *rom, const char *fn, uint32_t addr, int sz, int mask, int off, u NULL, NULL, NULL, rom->rom, flags | MEM_MAPPING_ROM_WS, rom); - return (0); + return 0; } int @@ -620,7 +618,7 @@ rom_init_oddeven(rom_t *rom, const char *fn, uint32_t addr, int sz, int mask, in NULL, NULL, NULL, rom->rom, flags | MEM_MAPPING_ROM_WS, rom); - return (0); + return 0; } int @@ -647,5 +645,5 @@ rom_init_interleaved(rom_t *rom, const char *fnl, const char *fnh, uint32_t addr NULL, NULL, NULL, rom->rom, flags | MEM_MAPPING_ROM_WS, rom); - return (0); + return 0; } diff --git a/src/mem/row.c b/src/mem/row.c new file mode 100644 index 000000000..ccd0325a4 --- /dev/null +++ b/src/mem/row.c @@ -0,0 +1,348 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * DRAM row handling. + * + * Authors: Miran Grca, + * + * Copyright 2016-2020 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include "x86_ops.h" +#include "x86.h" +#include <86box/config.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/mem.h> +#include <86box/spd.h> +#include <86box/row.h> +#include <86box/plat_unused.h> + +/* 0 1 2 3 4 5 6 7 */ +static uint8_t rows_num; +static uint8_t rows_default; +static uint8_t rows_bits; +static uint32_t row_unit; +static uint8_t drb_defaults[16]; +static row_t *rows; + + +static uint8_t +row_read(uint32_t addr, void *priv) +{ + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + + addreadlookup(mem_logical_addr, new_addr); + + return dev->buf[new_addr]; +} + + +static uint16_t +row_readw(uint32_t addr, void *priv) +{ + row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + + addreadlookup(mem_logical_addr, new_addr); + + return *(uint16_t *) &(dev->buf[new_addr]); +} + + +static uint32_t +row_readl(uint32_t addr, void *priv) +{ + row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + + addreadlookup(mem_logical_addr, new_addr); + + return *(uint32_t *) &(dev->buf[new_addr]); +} + + +static void +row_write(uint32_t addr, uint8_t val, void *priv) +{ + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + + addwritelookup(mem_logical_addr, new_addr); + mem_write_ramb_page(new_addr, val, &pages[addr >> 12]); +} + + +static void +row_writew(uint32_t addr, uint16_t val, void *priv) +{ + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + + addwritelookup(mem_logical_addr, new_addr); + mem_write_ramw_page(new_addr, val, &pages[addr >> 12]); +} + + +static void +row_writel(uint32_t addr, uint32_t val, void *priv) +{ + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + + addwritelookup(mem_logical_addr, new_addr); + mem_write_raml_page(new_addr, val, &pages[addr >> 12]); +} + + +void +row_allocate(uint8_t row_id, uint8_t set) +{ + uint32_t offset; + + /* Do nothing if size is either zero or invalid. */ + if ((rows[row_id].host_size == 0x00000000) || (rows[row_id].host_size == 0xffffffff)) + return; + + if (rows[row_id].ram_size == 0x00000000) + return; + + for (uint32_t c = (rows[row_id].host_base >> 12); c < ((rows[row_id].host_base + rows[row_id].host_size) >> 12); c++) { + offset = c - (rows[row_id].host_base >> 12); + + pages[c].mem = set ? (rows[row_id].buf + rows[row_id].ram_base + ((offset << 12) & rows[row_id].ram_mask)) : page_ff; + pages[c].write_b = set ? mem_write_ramb_page : NULL; + pages[c].write_w = set ? mem_write_ramw_page : NULL; + pages[c].write_l = set ? mem_write_raml_page : NULL; +#ifdef USE_NEW_DYNAREC + pages[c].evict_prev = EVICT_NOT_IN_LIST; + pages[c].byte_dirty_mask = &byte_dirty_mask[offset * 64]; + pages[c].byte_code_present_mask = &byte_code_present_mask[offset * 64]; +#endif + } + + if (rows[row_id].host_base >= 0x00100000) { + mem_set_mem_state_both(rows[row_id].host_base, rows[row_id].host_base + rows[row_id].host_size, + set ? (MEM_READ_INTERNAL | MEM_WRITE_INTERNAL) : (MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL)); + } else { + if (0x000a0000 > rows[row_id].host_base) { + mem_set_mem_state_both(rows[row_id].host_base, 0x000a0000 - rows[row_id].host_base, + set ? (MEM_READ_INTERNAL | MEM_WRITE_INTERNAL) : (MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL)); + } + if ((rows[row_id].host_base + rows[row_id].host_size) > 0x00100000) { + mem_set_mem_state_both(0x00100000, (rows[row_id].host_base + rows[row_id].host_size) - 0x00100000, + set ? (MEM_READ_INTERNAL | MEM_WRITE_INTERNAL) : (MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL)); + } + } + + if (set) { + mem_mapping_set_addr(&rows[row_id].mapping, rows[row_id].host_base, rows[row_id].host_size); + mem_mapping_set_exec(&rows[row_id].mapping, rows[row_id].buf + rows[row_id].ram_base); + mem_mapping_set_mask(&rows[row_id].mapping, rows[row_id].ram_mask); + if ((rows[row_id].host_base == rows[row_id].ram_base) && (rows[row_id].host_size == rows[row_id].ram_size)) { +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + mem_mapping_set_handler(&rows[row_id].mapping, mem_read_ram,mem_read_ramw,mem_read_raml, + mem_write_ram,mem_write_ramw,mem_write_raml); +#else + if (rows[row_id].buf == ram2) { + mem_mapping_set_handler(&rows[row_id].mapping, mem_read_ram_2gb,mem_read_ram_2gbw,mem_read_ram_2gbl, + mem_write_ram,mem_write_ramw,mem_write_raml); + } else { + mem_mapping_set_handler(&rows[row_id].mapping, mem_read_ram,mem_read_ramw,mem_read_raml, + mem_write_ram,mem_write_ramw,mem_write_raml); + } +#endif + } else { + mem_mapping_set_handler(&rows[row_id].mapping, row_read, row_readw, row_readl, + row_write, row_writew, row_writel); + } + } else + mem_mapping_disable(&rows[row_id].mapping); +} + + +void +row_disable(uint8_t row_id) +{ + row_allocate(row_id, 0); +} + + +void +row_set_boundary(uint8_t row_id, uint32_t boundary) +{ + if (row_id >= rows_num) + return; + + boundary &= ((1 << rows_bits) - 1); + + rows[row_id].host_size = boundary * row_unit; + if (row_id == 0) + rows[row_id].host_base = 0x00000000; + else { + rows[row_id].host_base = rows[row_id - 1].boundary * row_unit; + if (rows[row_id - 1].boundary > boundary) + rows[row_id].host_size = 0x00000000; + else + rows[row_id].host_size -= rows[row_id].host_base; + } + + rows[row_id].boundary = boundary; + + row_allocate(row_id, 1); +} + + +void +row_reset(UNUSED(void *priv)) +{ + uint32_t boundary; + uint32_t shift; + + for (int8_t i = (rows_num - 1); i >= 0; i--) + row_disable(i); + + for (uint8_t i = 0; i < rows_num; i++) { + shift = (i & 1) << 2; + boundary = ((uint32_t) drb_defaults[i]) + (((((uint32_t) drb_defaults[(i >> 1) + 8]) >> shift) & 0xf) << 8); + row_set_boundary(i, boundary); + } +} + + +void +row_close(UNUSED(void *priv)) +{ + free(rows); + rows = NULL; +} + + +void * +row_init(const device_t *info) +{ + uint32_t cur_drb = 0; + uint32_t cur_drbe = 0; + uint32_t last_drb = 0; + uint32_t last_drbe = 0; + uint8_t phys_drbs[16]; + int i; + int max = info->local & 0xff; + uint32_t shift; + uint32_t drb; + uint32_t boundary; + uint32_t mask; + row_t *new_rows = NULL; + + rows_bits = ((info->local >> 24) & 0xff); + mask = (1 << rows_bits) - 1; + row_unit = ((info->local >> 8) & 0xff); + memset(phys_drbs, 0x00, 16); + spd_write_drbs(phys_drbs, 0x00, max, row_unit); + row_unit <<= 20; + rows_default = (info->local >> 16) & 0xff; + memset(drb_defaults, 0x00, 16); + for (i = 0; i < 8; i++) + drb_defaults[i] = rows_default; + + new_rows = calloc(max + 1, sizeof(row_t)); + rows_num = max + 1; + + rows = new_rows; + + mem_mapping_disable(&ram_low_mapping); + mem_mapping_disable(&ram_mid_mapping); + mem_mapping_disable(&ram_high_mapping); +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) + if (mem_size > 1048576) + mem_mapping_disable(&ram_2gb_mapping); +#endif + + for (uint32_t c = 0; c < pages_sz; c++) { + pages[c].mem = page_ff; + pages[c].write_b = NULL; + pages[c].write_w = NULL; + pages[c].write_l = NULL; +#ifdef USE_NEW_DYNAREC + pages[c].evict_prev = EVICT_NOT_IN_LIST; + pages[c].byte_dirty_mask = &byte_dirty_mask[c * 64]; + pages[c].byte_code_present_mask = &byte_code_present_mask[c * 64]; +#endif + } + + /* Set all memory space above the default allocated area to external. */ + boundary = ((uint32_t) rows_default) * row_unit; + mem_set_mem_state_both(boundary, (mem_size << 10) - boundary, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); + + for (i = 0; i <= max; i++) { + cur_drb = phys_drbs[i]; + cur_drbe = phys_drbs[(i >> 1) + 8]; + + shift = (i & 1) << 2; + drb = (cur_drb & mask) + (((cur_drbe >> shift) & 0x03) << 8); + rows[i].ram_size = drb * row_unit; + + shift = ((i - 1) & 1) << 2; + drb = (last_drb & mask) + (((last_drbe >> shift) & 0x03) << 8); + rows[i].ram_base = drb * row_unit; + rows[i].ram_size -= rows[i].ram_base; + + rows[i].buf = ram; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) + if (rows[i].ram_base >= (1 << 30)) { + rows[i].ram_base -= (1 << 30); + rows[i].buf = ram2; + } +#endif + + rows[i].ram_mask = rows[i].ram_size - 1; + + mem_mapping_add(&rows[i].mapping, rows[i].ram_base, rows[i].ram_size, + row_read, row_readw, row_readl, + row_write, row_writew, row_writel, + rows[i].buf + rows[i].ram_base, MEM_MAPPING_INTERNAL, &(rows[i])); + mem_mapping_disable(&rows[i].mapping); + + shift = (i & 1) << 2; + boundary = ((uint32_t) drb_defaults[i]) + ((((uint32_t) drb_defaults[(i >> 1) + 8]) >> shift) << 8); + row_set_boundary(i, boundary); + + last_drb = cur_drb; + last_drbe = cur_drbe; + } + + flushmmucache(); + + return new_rows; +} + + +/* NOTE: NOT const, so that we can patch it at init. */ +device_t row_device = { + .name = "DRAM Rows", + .internal_name = "dram_rows", + .flags = DEVICE_AT, + .local = 0x0000, + .init = row_init, + .close = row_close, + .reset = row_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/mem/smram.c b/src/mem/smram.c index 6057f0a3c..0532e2dd5 100644 --- a/src/mem/smram.c +++ b/src/mem/smram.c @@ -29,7 +29,8 @@ #include <86box/mem.h> #include <86box/smram.h> -static smram_t *base_smram, *last_smram; +static smram_t *base_smram; +static smram_t *last_smram; static uint8_t use_separate_smram = 0; static uint8_t smram[0x40000]; @@ -55,8 +56,8 @@ smram_log(const char *fmt, ...) static uint8_t smram_read(uint32_t addr, void *priv) { - smram_t *dev = (smram_t *) priv; - uint32_t new_addr = addr - dev->host_base + dev->ram_base; + const smram_t *dev = (smram_t *) priv; + uint32_t new_addr = addr - dev->host_base + dev->ram_base; if (new_addr >= (1 << 30)) return mem_read_ram_2gb(new_addr, priv); @@ -135,7 +136,8 @@ smram_writel(uint32_t addr, uint32_t val, void *priv) void smram_backup_all(void) { - smram_t *temp_smram = base_smram, *next; + smram_t *temp_smram = base_smram; + smram_t *next; while (temp_smram != NULL) { temp_smram->old_host_base = temp_smram->host_base; @@ -150,7 +152,8 @@ smram_backup_all(void) void smram_recalc_all(int ret) { - smram_t *temp_smram = base_smram, *next; + smram_t *temp_smram = base_smram; + smram_t *next; if (base_smram == NULL) return; @@ -316,7 +319,8 @@ smram_disable(smram_t *smr) void smram_disable_all(void) { - smram_t *temp_smram = base_smram, *next; + smram_t *temp_smram = base_smram; + smram_t *next; while (temp_smram != NULL) { smram_disable(temp_smram); @@ -339,7 +343,7 @@ smram_enable_ex(smram_t *smr, uint32_t host_base, uint32_t ram_base, uint32_t si if ((size != 0x00000000) && (flags_normal || flags_smm)) { smr->host_base = host_base; - smr->ram_base = ram_base, + smr->ram_base = ram_base; smr->size = size; mem_mapping_set_addr(&(smr->mapping), smr->host_base, smr->size); diff --git a/src/mem/spd.c b/src/mem/spd.c index b1f2b5ecd..cbc9ac2b7 100644 --- a/src/mem/spd.c +++ b/src/mem/spd.c @@ -27,11 +27,12 @@ #include <86box/spd.h> #include <86box/version.h> #include <86box/machine.h> +#include <86box/plat_unused.h> #define SPD_ROLLUP(x) ((x) >= 16 ? ((x) -15) : (x)) -int spd_present = 0; -spd_t *spd_modules[SPD_MAX_SLOTS]; +uint8_t spd_present = 0; +spd_t *spd_modules[SPD_MAX_SLOTS]; static const device_t spd_device; @@ -54,7 +55,7 @@ spd_log(const char *fmt, ...) #endif static void -spd_close(void *priv) +spd_close(UNUSED(void *priv)) { spd_log("SPD: close()\n"); @@ -67,7 +68,7 @@ spd_close(void *priv) } static void * -spd_init(const device_t *info) +spd_init(UNUSED(const device_t *info)) { spd_log("SPD: init()\n"); @@ -84,15 +85,17 @@ spd_init(const device_t *info) int comp_ui16_rev(const void *elem1, const void *elem2) { - uint16_t a = *((uint16_t *) elem1); - uint16_t b = *((uint16_t *) elem2); + const uint16_t a = *((const uint16_t *) elem1); + const uint16_t b = *((const uint16_t *) elem2); return ((a > b) ? -1 : ((a < b) ? 1 : 0)); } void spd_populate(uint16_t *rows, uint8_t slot_count, uint16_t total_size, uint16_t min_module_size, uint16_t max_module_size, uint8_t enable_asym) { - uint8_t row, next_empty_row, split, i; + uint8_t row; + uint8_t next_empty_row; + uint8_t split; uint16_t asym; /* Populate rows with modules in power-of-2 capacities. */ @@ -138,7 +141,7 @@ spd_populate(uint16_t *rows, uint8_t slot_count, uint16_t total_size, uint16_t m /* Find next empty row. */ next_empty_row = 0; - for (i = row + 1; i < slot_count && !next_empty_row; i++) { + for (uint8_t i = row + 1; i < slot_count && !next_empty_row; i++) { if (!rows[i]) next_empty_row = i; } @@ -176,8 +179,12 @@ spd_write_part_no(char *part_no, char *type, uint16_t size) void spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) { - uint8_t slot, slot_count, row, i; - uint16_t min_module_size, rows[SPD_MAX_SLOTS], asym; + uint8_t slot; + uint8_t slot_count; + uint8_t row; + uint16_t min_module_size; + uint16_t rows[SPD_MAX_SLOTS]; + uint16_t asym; spd_edo_t *edo_data; spd_sdram_t *sdram_data; @@ -255,7 +262,7 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) edo_data->dram_width = 8; edo_data->spd_rev = 0x12; - for (i = spd_write_part_no(edo_data->part_no, (ram_type == SPD_TYPE_FPM) ? "FPM" : "EDO", rows[row]); + for (int i = spd_write_part_no(edo_data->part_no, (ram_type == SPD_TYPE_FPM) ? "FPM" : "EDO", rows[row]); i < sizeof(edo_data->part_no); i++) edo_data->part_no[i] = ' '; /* part number should be space-padded */ edo_data->rev_code[0] = BCD8(EMU_VERSION_MAJ); @@ -263,9 +270,9 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) edo_data->mfg_year = 20; edo_data->mfg_week = 17; - for (i = 0; i < 63; i++) + for (uint8_t i = 0; i < 63; i++) edo_data->checksum += spd_modules[slot]->data[i]; - for (i = 0; i < 129; i++) + for (uint8_t i = 0; i < 129; i++) edo_data->checksum2 += spd_modules[slot]->data[i]; break; @@ -309,7 +316,7 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) sdram_data->ca_hold = sdram_data->data_hold = 0x08; sdram_data->spd_rev = 0x12; - for (i = spd_write_part_no(sdram_data->part_no, "SDR", rows[row]); + for (int i = spd_write_part_no(sdram_data->part_no, "SDR", rows[row]); i < sizeof(sdram_data->part_no); i++) sdram_data->part_no[i] = ' '; /* part number should be space-padded */ sdram_data->rev_code[0] = BCD8(EMU_VERSION_MAJ); @@ -320,11 +327,14 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) sdram_data->freq = 100; sdram_data->features = 0xFF; - for (i = 0; i < 63; i++) + for (uint8_t i = 0; i < 63; i++) sdram_data->checksum += spd_modules[slot]->data[i]; - for (i = 0; i < 129; i++) + for (uint8_t i = 0; i < 129; i++) sdram_data->checksum2 += spd_modules[slot]->data[i]; break; + + default: + break; } row++; @@ -336,8 +346,11 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) void spd_write_drbs(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit) { - uint8_t row, dimm, drb, apollo = 0; - uint16_t size, rows[SPD_MAX_SLOTS]; + uint8_t dimm; + uint8_t drb; + uint8_t apollo = 0; + uint16_t size; + uint16_t rows[SPD_MAX_SLOTS]; /* Special case for VIA Apollo Pro family, which jumps from 5F to 56. */ if (reg_max < reg_min) { @@ -353,7 +366,7 @@ spd_write_drbs(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit /* Write DRBs for each row. */ spd_log("SPD: Writing DRBs... regs=[%02X:%02X] unit=%d\n", reg_min, reg_max, drb_unit); - for (row = 0; row <= (reg_max - reg_min); row++) { + for (uint8_t row = 0; row <= (reg_max - reg_min); row++) { dimm = (row >> 1); size = 0; @@ -378,7 +391,7 @@ spd_write_drbs(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit /* Write DRB register, adding the previous DRB's value. */ if (row == 0) regs[drb] = 0; - else if ((apollo) && (drb == apollo)) + else if (apollo && (drb == apollo)) regs[drb] = regs[drb | 0xf]; /* 5F comes before 56 */ else regs[drb] = regs[drb - 1]; @@ -388,12 +401,15 @@ spd_write_drbs(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit } } -/* Needed for 430LX. */ +/* Needed for 430NX. */ void spd_write_drbs_with_ext(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit) { - uint8_t row, dimm, drb; - uint16_t size, row_val = 0, rows[SPD_MAX_SLOTS]; + uint8_t dimm; + uint8_t drb; + uint16_t size; + uint16_t row_val = 0; + uint16_t rows[SPD_MAX_SLOTS]; int shift; /* No SPD: split SIMMs into pairs as if they were "DIMM"s. */ @@ -404,7 +420,7 @@ spd_write_drbs_with_ext(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t /* Write DRBs for each row. */ spd_log("SPD: Writing DRBs... regs=[%02X:%02X] unit=%d\n", reg_min, reg_max, drb_unit); - for (row = 0; row <= (reg_max - reg_min); row++) { + for (uint8_t row = 0; row <= (reg_max - reg_min); row++) { dimm = (row >> 1); size = 0; @@ -431,8 +447,9 @@ spd_write_drbs_with_ext(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t row_val += size / drb_unit; /* this will intentionally overflow on 440GX with 2 GB */ regs[drb] = row_val & 0xff; drb = reg_min + 8 + (row >> 1); - shift = (row & 0x01) << 3; - regs[drb] = (((row_val & 0xfff) >> 8) << shift); + shift = (row & 0x01) << 2; + /* Limit to 1 GB space, per the 430NX datasheet. */ + regs[drb] = (regs[drb] & ~(0xf << shift)) | (((row_val >> 8) & 3) << shift); spd_log("SPD: DRB[%d] = %d MB (%02Xh raw)\n", row, size, regs[drb]); } } @@ -441,9 +458,10 @@ spd_write_drbs_with_ext(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t void spd_write_drbs_interleaved(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit) { - uint8_t row, dimm; + uint8_t dimm; uint8_t drb; - uint16_t size, size_acc = 0; + uint16_t size; + uint16_t size_acc = 0; uint16_t rows[SPD_MAX_SLOTS]; /* No SPD: split SIMMs into pairs as if they were "DIMM"s. */ @@ -454,7 +472,7 @@ spd_write_drbs_interleaved(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint /* Write DRBs for each row. */ spd_log("SPD: Writing DRBs... regs=[%02X:%02X] unit=%d\n", reg_min, reg_max, drb_unit); - for (row = 0; row <= (reg_max - reg_min); row += 2) { + for (uint8_t row = 0; row <= (reg_max - reg_min); row += 2) { dimm = (row >> 2); size = 0; @@ -493,7 +511,8 @@ spd_write_drbs_interleaved(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint void spd_write_drbs_ali1621(uint8_t *regs, uint8_t reg_min, uint8_t reg_max) { - uint8_t dimm, drb; + uint8_t dimm; + uint8_t drb; uint16_t size; uint16_t rows[SPD_MAX_SLOTS]; @@ -529,8 +548,8 @@ spd_write_drbs_ali1621(uint8_t *regs, uint8_t reg_min, uint8_t reg_max) regs[drb + 3] |= 0x06; switch (size) { - case 4: default: + case 4: regs[drb + 2] = 0x00; break; case 8: diff --git a/src/mem/sst_flash.c b/src/mem/sst_flash.c index 551e2da63..22b147933 100644 --- a/src/mem/sst_flash.c +++ b/src/mem/sst_flash.c @@ -17,7 +17,7 @@ * * Copyright 2008-2020 Sarah Walker. * Copyright 2016-2020 Miran Grca. - * Copyright 2020 Melissa Goad. + * Copyright 2020 Melody Goad. * Copyright 2022-2023 Jasmine Iwanek. */ #include @@ -35,21 +35,31 @@ #include <86box/m_xt_xi8088.h> typedef struct sst_t { - uint8_t manufacturer, id, has_bbp, is_39, - page_bytes, sdp, bbp_first_8k, bbp_last_8k; + uint8_t manufacturer; + uint8_t id; + uint8_t has_bbp; + uint8_t is_39; + uint8_t page_bytes; + uint8_t sdp; + uint8_t bbp_first_8k; + uint8_t bbp_last_8k; - int command_state, id_mode, - dirty; + int command_state; + int id_mode; + int dirty; - uint32_t size, mask, - page_mask, page_base, - last_addr; + uint32_t size; + uint32_t mask; + uint32_t page_mask; + uint32_t page_base; + uint32_t last_addr; - uint8_t page_buffer[128], - page_dirty[128]; + uint8_t page_buffer[128]; + uint8_t page_dirty[128]; uint8_t *array; - mem_mapping_t mapping[8], mapping_h[8]; + mem_mapping_t mapping[8]; + mem_mapping_t mapping_h[8]; pc_timer_t page_write_timer; } sst_t; @@ -89,7 +99,7 @@ static char flash_path[1024]; #define SST39LF080 0xd800 #define SST39LF016 0xd900 -/* +#if 0 // 16 wide #define SST39WF400 0x272f #define SST39WF400B 0x272e @@ -103,7 +113,7 @@ static char flash_path[1024]; #define SST39LF400 0x2780 #define SST39LF800 0x2781 #define SST39LF160 0x2782 -*/ +#endif #define SST49LF002 0x5700 #define SST49LF020 0x6100 @@ -150,7 +160,8 @@ sst_sector_erase(sst_t *dev, uint32_t addr) static void sst_new_command(sst_t *dev, uint32_t addr, uint8_t val) { - uint32_t base = 0x00000, size = dev->size; + uint32_t base = 0x00000; + uint32_t size = dev->size; if (dev->command_state == 5) switch (val) { @@ -230,11 +241,10 @@ static void sst_page_write(void *priv) { sst_t *dev = (sst_t *) priv; - int i; if (dev->last_addr != 0xffffffff) { dev->page_base = dev->last_addr & dev->page_mask; - for (i = 0; i < 128; i++) { + for (uint8_t i = 0; i < 128; i++) { if (dev->page_dirty[i]) { if (((dev->page_base + i) < 0x2000) && (dev->bbp_first_8k & 0x01)) continue; @@ -252,10 +262,10 @@ sst_page_write(void *priv) } static uint8_t -sst_read_id(uint32_t addr, void *p) +sst_read_id(uint32_t addr, void *priv) { - sst_t *dev = (sst_t *) p; - uint8_t ret = 0x00; + const sst_t *dev = (sst_t *) priv; + uint8_t ret = 0x00; if ((addr & 0xffff) == 0) ret = dev->manufacturer; @@ -291,9 +301,9 @@ sst_buf_write(sst_t *dev, uint32_t addr, uint8_t val) } static void -sst_write(uint32_t addr, uint8_t val, void *p) +sst_write(uint32_t addr, uint8_t val, void *priv) { - sst_t *dev = (sst_t *) p; + sst_t *dev = (sst_t *) priv; switch (dev->command_state) { case 0: @@ -359,19 +369,22 @@ sst_write(uint32_t addr, uint8_t val, void *p) dev->bbp_last_8k = 0xff; dev->command_state = 0; break; + + default: + break; } } static uint8_t -sst_read(uint32_t addr, void *p) +sst_read(uint32_t addr, void *priv) { - sst_t *dev = (sst_t *) p; - uint8_t ret = 0xff; + const sst_t *dev = (sst_t *) priv; + uint8_t ret = 0xff; addr &= 0x000fffff; if (dev->id_mode) - ret = sst_read_id(addr, p); + ret = sst_read_id(addr, priv); else { if ((addr >= biosaddr) && (addr <= (biosaddr + biosmask))) ret = dev->array[addr - biosaddr]; @@ -381,15 +394,15 @@ sst_read(uint32_t addr, void *p) } static uint16_t -sst_readw(uint32_t addr, void *p) +sst_readw(uint32_t addr, void *priv) { - sst_t *dev = (sst_t *) p; + sst_t *dev = (sst_t *) priv; uint16_t ret = 0xffff; addr &= 0x000fffff; if (dev->id_mode) - ret = sst_read(addr, p) | (sst_read(addr + 1, p) << 8); + ret = sst_read(addr, priv) | (sst_read(addr + 1, priv) << 8); else { if ((addr >= biosaddr) && (addr <= (biosaddr + biosmask))) ret = *(uint16_t *) &dev->array[addr - biosaddr]; @@ -399,15 +412,15 @@ sst_readw(uint32_t addr, void *p) } static uint32_t -sst_readl(uint32_t addr, void *p) +sst_readl(uint32_t addr, void *priv) { - sst_t *dev = (sst_t *) p; + sst_t *dev = (sst_t *) priv; uint32_t ret = 0xffffffff; addr &= 0x000fffff; if (dev->id_mode) - ret = sst_readw(addr, p) | (sst_readw(addr + 2, p) << 16); + ret = sst_readw(addr, priv) | (sst_readw(addr + 2, priv) << 16); else { if ((addr >= biosaddr) && (addr <= (biosaddr + biosmask))) ret = *(uint32_t *) &dev->array[addr - biosaddr]; @@ -419,14 +432,15 @@ sst_readl(uint32_t addr, void *p) static void sst_add_mappings(sst_t *dev) { - int i = 0, count; - uint32_t base, fbase; + int count; + uint32_t base; + uint32_t fbase; uint32_t root_base; count = dev->size >> 16; root_base = 0x100000 - dev->size; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { base = root_base + (i << 16); fbase = base & biosmask; @@ -498,10 +512,10 @@ sst_init(const device_t *info) } static void -sst_close(void *p) +sst_close(void *priv) { FILE *f; - sst_t *dev = (sst_t *) p; + sst_t *dev = (sst_t *) priv; if (dev->dirty) { f = nvr_fopen(flash_path, "wb"); diff --git a/src/minitrace/minitrace.c b/src/minitrace/minitrace.c index 0b2208605..36a3a535b 100644 --- a/src/minitrace/minitrace.c +++ b/src/minitrace/minitrace.c @@ -252,7 +252,6 @@ void mtr_init(const char *json_file) { } void mtr_shutdown(void) { - int i; #ifndef MTR_ENABLED return; #endif @@ -266,7 +265,7 @@ void mtr_shutdown(void) { f = 0; free(event_buffer); event_buffer = 0; - for (i = 0; i < STRING_POOL_SIZE; i++) { + for (uint8_t i = 0; i < STRING_POOL_SIZE; i++) { if (str_pool[i]) { free(str_pool[i]); str_pool[i] = 0; @@ -275,8 +274,7 @@ void mtr_shutdown(void) { } const char *mtr_pool_string(const char *str) { - int i; - for (i = 0; i < STRING_POOL_SIZE; i++) { + for (uint8_t i = 0; i < STRING_POOL_SIZE; i++) { if (!str_pool[i]) { str_pool[i] = (char*)malloc(strlen(str) + 1); strcpy(str_pool[i], str); diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index e14f979d3..ce1bba325 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -12,24 +12,16 @@ # # Copyright 2020-2021 David Hrdlička. # +set(net_sources) +list(APPEND net_sources network.c net_pcap.c net_slirp.c net_dp8390.c net_3c501.c + net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c net_null.c) -add_library(net OBJECT network.c net_pcap.c net_slirp.c net_dp8390.c net_3c501.c - net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c) +find_package(PkgConfig REQUIRED) +pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp) +target_link_libraries(86Box PkgConfig::SLIRP) -option(SLIRP_EXTERNAL "Link against the system-provided libslirp library" OFF) -mark_as_advanced(SLIRP_EXTERNAL) - -if(SLIRP_EXTERNAL) - find_package(PkgConfig REQUIRED) - pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp) - target_link_libraries(86Box PkgConfig::SLIRP) - - if(WIN32) - target_link_libraries(PkgConfig::SLIRP INTERFACE wsock32 ws2_32 iphlpapi iconv) - endif() -else() - add_subdirectory(slirp) - target_link_libraries(86Box slirp) +if(WIN32) + target_link_libraries(PkgConfig::SLIRP INTERFACE wsock32 ws2_32 iphlpapi iconv) endif() if (HAIKU) @@ -39,3 +31,18 @@ endif() if(WIN32) target_link_libraries(86Box ws2_32) endif() + +if (UNIX) + find_path(HAS_VDE "libvdeplug.h" PATHS ${VDE_INCLUDE_DIR} "/usr/include /usr/local/include" "/opt/homebrew/include" ) + if(HAS_VDE) + find_library(VDE_LIB vdeplug) + if (NOT VDE_LIB) + message(WARNING "Could not find VDE. The library will not be bundled and any related features will be disabled.") + else() + add_compile_definitions(HAS_VDE) + list(APPEND net_sources net_vde.c) + endif() + endif() +endif() + +add_library(net OBJECT ${net_sources}) diff --git a/src/network/net_3c501.c b/src/network/net_3c501.c index 5f542e41a..b3a903c7b 100644 --- a/src/network/net_3c501.c +++ b/src/network/net_3c501.c @@ -58,6 +58,7 @@ #include <86box/network.h> #include <86box/net_3c501.h> #include <86box/bswap.h> +#include <86box/plat_unused.h> /* Maximum number of times we report a link down to the guest (failure to send frame) */ #define ELNK_MAX_LINKDOWN_REPORTED 3 @@ -192,7 +193,7 @@ typedef struct ELNK_INTR_STAT { uint8_t unused : 5; } EL_INTR_STAT; -typedef struct { +typedef struct threec501_t { uint32_t base_address; int base_irq; uint32_t bios_addr; @@ -372,8 +373,8 @@ elnkR3HardReset(threec501_t *dev) static __inline int padr_match(threec501_t *dev, const uint8_t *buf) { - struct ether_header *hdr = (struct ether_header *) buf; - int result; + const struct ether_header *hdr = (struct ether_header *) buf; + int result; /* Checks own + broadcast as well as own + multicast. */ result = (dev->RcvCmd.adr_match >= EL_ADRM_BCAST) && !memcmp(hdr->ether_dhost, dev->aStationAddr, 6); @@ -387,9 +388,10 @@ padr_match(threec501_t *dev, const uint8_t *buf) static __inline int padr_bcast(threec501_t *dev, const uint8_t *buf) { - static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - struct ether_header *hdr = (struct ether_header *) buf; - int result = (dev->RcvCmd.adr_match == EL_ADRM_BCAST) && !memcmp(hdr->ether_dhost, aBCAST, 6); + static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + const struct ether_header *hdr = (struct ether_header *) buf; + int result = (dev->RcvCmd.adr_match == EL_ADRM_BCAST) && !memcmp(hdr->ether_dhost, aBCAST, 6); + return result; } @@ -401,6 +403,7 @@ padr_mcast(threec501_t *dev, const uint8_t *buf) { struct ether_header *hdr = (struct ether_header *) buf; int result = (dev->RcvCmd.adr_match == EL_ADRM_MCAST) && ETHER_IS_MULTICAST(hdr->ether_dhost); + return result; } @@ -473,7 +476,9 @@ static int elnkReceiveLocked(void *priv, uint8_t *src, int size) { threec501_t *dev = (threec501_t *) priv; - int is_padr = 0, is_bcast = 0, is_mcast = 0; + int is_padr = 0; + int is_bcast = 0; + int is_mcast = 0; bool fLoopback = dev->RcvCmd.adr_match == EL_BCTL_LOOPBACK; union { @@ -644,7 +649,7 @@ elnkAsyncTransmit(threec501_t *dev) return; } - if (((dev->AuxCmd.buf_ctl != EL_BCTL_XMT_RCV) && (dev->AuxCmd.buf_ctl != EL_BCTL_LOOPBACK))) { + if ((dev->AuxCmd.buf_ctl != EL_BCTL_XMT_RCV) && (dev->AuxCmd.buf_ctl != EL_BCTL_LOOPBACK)) { #ifdef ENABLE_3COM501_LOG threec501_log("3Com501: Nope, not in xmit-then-receive or loopback state\n"); #endif @@ -656,8 +661,8 @@ elnkAsyncTransmit(threec501_t *dev) */ do { /* Don't send anything when the link is down. */ - if ((!elnkIsLinkUp(dev) - && dev->cLinkDownReported > ELNK_MAX_LINKDOWN_REPORTED)) + if (!elnkIsLinkUp(dev) + && dev->cLinkDownReported > ELNK_MAX_LINKDOWN_REPORTED) break; bool const fLoopback = dev->AuxCmd.buf_ctl == EL_BCTL_LOOPBACK; @@ -690,7 +695,6 @@ elnkAsyncTransmit(threec501_t *dev) #ifdef ENABLE_3COM501_LOG threec501_log("3Com501: illegal giant frame (%u bytes) -> signalling error\n", cb); #endif - ; } } else { /* Signal a transmit error pretending there was a collision. */ @@ -919,13 +923,16 @@ threec501_read(uint16_t addr, void *priv) retval = dev->abPacketBuf[ELNK_GP(dev)]; dev->uGPBufPtr = (dev->uGPBufPtr + 1) & ELNK_GP_MASK; break; + + default: + break; } elnkUpdateIrq(dev); #ifdef ENABLE_3COM501_LOG threec501_log("3Com501: read addr %x, value %x\n", addr & 0x0f, retval); #endif - return (retval); + return retval; } static uint8_t @@ -1005,6 +1012,9 @@ threec501_write(uint16_t addr, uint8_t value, void *priv) dev->abPacketBuf[ELNK_GP(dev)] = value; dev->uGPBufPtr = (dev->uGPBufPtr + 1) & ELNK_GP_MASK; break; + + default: + break; } #ifdef ENABLE_3COM501_LOG @@ -1066,7 +1076,7 @@ elnkR3TimerRestore(void *priv) } static void * -threec501_nic_init(const device_t *info) +threec501_nic_init(UNUSED(const device_t *info)) { uint32_t mac; threec501_t *dev; @@ -1130,7 +1140,7 @@ threec501_nic_init(const device_t *info) timer_add(&dev->timer_restore, elnkR3TimerRestore, dev, 0); - return (dev); + return dev; } static void diff --git a/src/network/net_3c503.c b/src/network/net_3c503.c index 9e4f9c12b..d01b423ae 100644 --- a/src/network/net_3c503.c +++ b/src/network/net_3c503.c @@ -62,8 +62,9 @@ #include <86box/net_dp8390.h> #include <86box/net_3c503.h> #include <86box/bswap.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct threec503_t { dp8390_t *dp8390; mem_mapping_t ram_mapping; uint32_t base_address; @@ -129,6 +130,9 @@ threec503_interrupt(void *priv, int set) case 5: dev->regs.idcfr = 0x80; break; + + default: + break; } if (set) @@ -151,7 +155,7 @@ threec503_ram_write(uint32_t addr, uint8_t val, void *priv) static uint8_t threec503_ram_read(uint32_t addr, void *priv) { - threec503_t *dev = (threec503_t *) priv; + const threec503_t *dev = (threec503_t *) priv; if ((addr & 0x3fff) >= 0x2000) return 0xff; @@ -174,6 +178,9 @@ threec503_set_drq(threec503_t *dev) case 3: dev->regs.idcfr = 4; break; + + default: + break; } } @@ -223,6 +230,9 @@ threec503_nic_lo_read(uint16_t addr, void *priv) case 0x03: retval = 0xff; break; + + default: + break; } break; @@ -237,9 +247,12 @@ threec503_nic_lo_read(uint16_t addr, void *priv) case 0x03: retval = 0xff; break; + + default: + break; } - return (retval); + return retval; } static void @@ -272,6 +285,9 @@ threec503_nic_lo_write(uint16_t addr, uint8_t val, void *priv) case 0x03: break; + + default: + break; } break; @@ -279,6 +295,9 @@ threec503_nic_lo_write(uint16_t addr, uint8_t val, void *priv) case 0x02: case 0x03: break; + + default: + break; } threec503_log("3Com503: write addr %x, value %x\n", addr, val); @@ -338,7 +357,6 @@ threec503_nic_hi_read(uint16_t addr, void *priv) } return dev->regs.bcfr; - break; case 0x04: switch (dev->bios_addr) { @@ -357,10 +375,12 @@ threec503_nic_hi_read(uint16_t addr, void *priv) case 0xc8000: dev->regs.pcfr = 0x10; break; + + default: + break; } return dev->regs.pcfr; - break; case 0x05: return dev->regs.gacfr; @@ -397,6 +417,9 @@ threec503_nic_hi_read(uint16_t addr, void *priv) threec503_set_drq(dev); return dp8390_chipmem_read(dev->dp8390, dev->regs.da++, 1); + + default: + break; } return 0; @@ -527,6 +550,9 @@ threec503_nic_hi_write(uint16_t addr, uint8_t val, void *priv) dp8390_chipmem_write(dev->dp8390, dev->regs.da++, val, 1); break; + + default: + break; } } @@ -543,7 +569,7 @@ threec503_nic_ioset(threec503_t *dev, uint16_t addr) } static void * -threec503_nic_init(const device_t *info) +threec503_nic_init(UNUSED(const device_t *info)) { uint32_t mac; threec503_t *dev; @@ -605,13 +631,15 @@ threec503_nic_init(const device_t *info) threec503_ram_read, NULL, NULL, threec503_ram_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, dev); - // mem_mapping_disable(&dev->ram_mapping); +#if 0 + mem_mapping_disable(&dev->ram_mapping); +#endif dev->regs.gacfr = 0x09; /* Start with RAM mapping enabled. */ /* Attach ourselves to the network module. */ dev->dp8390->card = network_attach(dev->dp8390, dev->dp8390->physaddr, dp8390_rx, NULL); - return (dev); + return dev; } static void diff --git a/src/network/net_dp8390.c b/src/network/net_dp8390.c index 3b54fdb9d..1e50ddd45 100644 --- a/src/network/net_dp8390.c +++ b/src/network/net_dp8390.c @@ -29,6 +29,7 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/net_dp8390.h> +#include <86box/plat_unused.h> static void dp8390_tx(dp8390_t *dev, uint32_t val); static int dp8390_rx_common(void *priv, uint8_t *buf, int io_len); @@ -62,14 +63,14 @@ static int mcast_index(const void *dst) { #define POLYNOMIAL 0x04c11db6 - uint32_t crc = 0xffffffffL; - int carry, i, j; - uint8_t b; - uint8_t *ep = (uint8_t *) dst; + uint32_t crc = 0xffffffffL; + int carry; + uint8_t b; + const uint8_t *ep = (uint8_t *) dst; - for (i = 6; --i >= 0;) { + for (int8_t i = 6; --i >= 0;) { b = *ep++; - for (j = 8; --j >= 0;) { + for (int8_t j = 8; --j >= 0;) { carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); crc <<= 1; b >>= 1; @@ -93,7 +94,6 @@ mcast_index(const void *dst) uint32_t dp8390_chipmem_read(dp8390_t *dev, uint32_t addr, unsigned int len) { - int i; uint32_t retval = 0; #ifdef ENABLE_DP8390_LOG @@ -104,7 +104,7 @@ dp8390_chipmem_read(dp8390_t *dev, uint32_t addr, unsigned int len) dp8390_log("DP8390: Chipmem Read Address=%04x\n", addr); /* ROM'd MAC address */ - for (i = 0; i < len; i++) { + for (unsigned int i = 0; i < len; i++) { if ((addr >= dev->mem_start) && (addr < dev->mem_end)) retval |= (uint32_t) (dev->mem[addr - dev->mem_start]) << (i << 3); else if (addr < dev->macaddr_size) @@ -116,14 +116,12 @@ dp8390_chipmem_read(dp8390_t *dev, uint32_t addr, unsigned int len) addr++; } - return (retval); + return retval; } void dp8390_chipmem_write(dp8390_t *dev, uint32_t addr, uint32_t val, unsigned len) { - int i; - #ifdef ENABLE_DP8390_LOG if ((len > 1) && (addr & (len - 1))) dp8390_log("DP8390: unaligned chipmem word write\n"); @@ -131,7 +129,7 @@ dp8390_chipmem_write(dp8390_t *dev, uint32_t addr, uint32_t val, unsigned len) dp8390_log("DP8390: Chipmem Write Address=%04x\n", addr); - for (i = 0; i < len; i++) { + for (unsigned int i = 0; i < len; i++) { if ((addr < dev->mem_start) || (addr >= dev->mem_end)) { dp8390_log("DP8390: out-of-bounds chipmem write, %04X\n", addr); return; @@ -152,7 +150,7 @@ dp8390_read_cr(dp8390_t *dev) retval = (((dev->CR.pgsel & 0x03) << 6) | ((dev->CR.rdma_cmd & 0x07) << 3) | (dev->CR.tx_packet << 2) | (dev->CR.start << 1) | (dev->CR.stop)); dp8390_log("DP8390: read CR returns 0x%02x\n", retval); - return (retval); + return retval; } void @@ -198,7 +196,7 @@ dp8390_write_cr(dp8390_t *dev, uint32_t val) /* Check for start-tx */ if ((val & 0x04) && dev->TCR.loop_cntl) { if (dev->TCR.loop_cntl) { - dp8390_rx_common(dev, &dev->mem[(dev->tx_page_start * 256) - dev->mem_start], + dp8390_rx_common(dev, &dev->mem[((dev->tx_page_start * 256) - dev->mem_start) & dev->mem_wrap], dev->tx_bytes); } } else if (val & 0x04) { @@ -220,7 +218,7 @@ dp8390_write_cr(dp8390_t *dev, uint32_t val) /* TODO: report TX error to the driver ? */ if (!(dev->card->link_state & NET_LINK_DOWN)) - network_tx(dev->card, &dev->mem[(dev->tx_page_start * 256) - dev->mem_start], dev->tx_bytes); + network_tx(dev->card, &dev->mem[((dev->tx_page_start * 256) - dev->mem_start) & dev->mem_wrap], dev->tx_bytes); /* some more debug */ #ifdef ENABLE_DP8390_LOG @@ -245,7 +243,7 @@ dp8390_write_cr(dp8390_t *dev, uint32_t val) } static void -dp8390_tx(dp8390_t *dev, uint32_t val) +dp8390_tx(dp8390_t *dev, UNUSED(uint32_t val)) { dev->CR.tx_packet = 0; dev->TSR.tx_ok = 1; @@ -270,8 +268,10 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len) static uint8_t bcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; uint8_t pkthdr[4]; uint8_t *startptr; - int pages, avail; - int idx, nextpage; + int pages; + int avail; + int idx; + int nextpage; int endbytes; if (io_len != 60) @@ -391,7 +391,7 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len) } else { endbytes = (dev->page_stop - dev->curr_page) * 256; memcpy(startptr + sizeof(pkthdr), buf, endbytes - sizeof(pkthdr)); - startptr = &dev->mem[(dev->page_start * 256) - dev->mem_start]; + startptr = &dev->mem[((dev->tx_page_start * 256) - dev->mem_start) & dev->mem_wrap]; memcpy(startptr, buf + endbytes - sizeof(pkthdr), io_len - endbytes + 8); } dev->curr_page = nextpage; @@ -409,7 +409,7 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len) int dp8390_rx(void *priv, uint8_t *buf, int io_len) { - dp8390_t *dev = (dp8390_t *) priv; + const dp8390_t *dev = (dp8390_t *) priv; if ((dev->DCR.loop == 0) || (dev->TCR.loop_cntl != 0)) return 0; @@ -427,7 +427,7 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len) /* encountered with win98 hardware probe */ dp8390_log("DP8390: bad length! Page0 read from register 0x%02x, len=%u\n", off, len); - return (retval); + return retval; } switch (off) { @@ -503,11 +503,11 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len) dp8390_log("DP8390: Page0 read from register 0x%02x, value=0x%02x\n", off, retval); - return (retval); + return retval; } void -dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) +dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { uint8_t val2; @@ -698,7 +698,7 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) /* Handle reads/writes to the first page of the DS8390 register file. */ uint32_t -dp8390_page1_read(dp8390_t *dev, uint32_t off, unsigned int len) +dp8390_page1_read(dp8390_t *dev, uint32_t off, UNUSED(unsigned int len)) { dp8390_log("DP8390: Page1 read from register 0x%02x, len=%u\n", off, len); @@ -730,12 +730,12 @@ dp8390_page1_read(dp8390_t *dev, uint32_t off, unsigned int len) default: dp8390_log("DP8390: Page1 read register 0x%02x out of range\n", off); - return (0); + return 0; } } void -dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) +dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { dp8390_log("DP8390: Page1 write to register 0x%02x, len=%u, value=0x%04x\n", off, len, val); @@ -779,7 +779,7 @@ dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) /* Handle reads/writes to the second page of the DS8390 register file. */ uint32_t -dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len) +dp8390_page2_read(dp8390_t *dev, uint32_t off, UNUSED(unsigned int len)) { dp8390_log("DP8390: Page2 read from register 0x%02x, len=%u\n", off, len); @@ -812,7 +812,7 @@ dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len) case 0x0b: dp8390_log("DP8390: reserved Page2 read - register 0x%02x\n", off); - return (0xff); + return 0xff; case 0x0c: /* RCR */ return ((dev->RCR.monitor << 5) | (dev->RCR.promisc << 4) | (dev->RCR.multicast << 3) | (dev->RCR.broadcast << 2) | (dev->RCR.runts_ok << 1) | (dev->RCR.errors_ok)); @@ -832,11 +832,11 @@ dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len) break; } - return (0); + return 0; } void -dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) +dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { /* Maybe all writes here should be BX_PANIC()'d, since they affect internal operation, but let them through for now @@ -918,6 +918,7 @@ dp8390_mem_alloc(dp8390_t *dev, uint32_t start, uint32_t size) dev->mem_start = start; dev->mem_end = start + size; dev->mem_size = size; + dev->mem_wrap = size - 1; dp8390_log("DP8390: Mapped %i bytes of memory at address %04X in the address space\n", size, start); } @@ -931,7 +932,8 @@ dp8390_set_id(dp8390_t *dev, uint8_t id0, uint8_t id1) void dp8390_reset(dp8390_t *dev) { - int i, max, shift = 0; + int max; + int shift = 0; if (dev->flags & DP8390_FLAG_EVEN_MAC) shift = 1; @@ -939,7 +941,7 @@ dp8390_reset(dp8390_t *dev) max = 16 << shift; /* Initialize the MAC address area by doubling the physical address */ - for (i = 0; i < max; i++) { + for (int i = 0; i < max; i++) { if (i < (6 << shift)) dev->macaddr[i] = dev->physaddr[i >> shift]; else /* Signature */ @@ -998,7 +1000,7 @@ dp8390_soft_reset(dp8390_t *dev) } static void * -dp8390_init(const device_t *info) +dp8390_init(UNUSED(const device_t *info)) { dp8390_t *dp8390 = (dp8390_t *) malloc(sizeof(dp8390_t)); memset(dp8390, 0, sizeof(dp8390_t)); diff --git a/src/network/net_event.c b/src/network/net_event.c index 6e68f1fe3..c39c12254 100644 --- a/src/network/net_event.c +++ b/src/network/net_event.c @@ -7,6 +7,7 @@ #endif #include <86box/net_event.h> +#include <86box/plat_unused.h> #ifndef _WIN32 static void @@ -40,7 +41,7 @@ net_event_set(net_evt_t *event) } void -net_event_clear(net_evt_t *event) +net_event_clear(UNUSED(net_evt_t *event)) { #ifdef _WIN32 /* Do nothing on WIN32 since we use an auto-reset event */ diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 9a598538d..80dc4ec27 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -68,6 +68,8 @@ #include <86box/net_ne2000.h> #include <86box/bswap.h> #include <86box/isapnp.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> /* ROM BIOS file paths. */ #define ROM_PATH_NE1000 "roms/network/ne1000/ne1000.rom" @@ -93,28 +95,33 @@ static uint8_t rtl8019as_pnp_rom[] = { 0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */ }; -typedef struct { +typedef struct nic_t { dp8390_t *dp8390; const char *name; int board; - int is_pci, is_mca, is_8bit; + int is_pci; + int is_mca; + int is_8bit; uint32_t base_address; int base_irq; - uint32_t bios_addr, - bios_size, - bios_mask; - int card; /* PCI card slot */ - int has_bios, pad; - bar_t pci_bar[2]; - uint8_t pci_regs[PCI_REGSIZE]; - uint8_t eeprom[128]; /* for RTL8029AS */ - rom_t bios_rom; - void *pnp_card; - uint8_t pnp_csnsav; - uint8_t maclocal[6]; /* configured MAC (local) address */ + uint32_t bios_addr; + uint32_t bios_size; + uint32_t bios_mask; + int card; /* PCI card slot */ + int has_bios; + int pad; + bar_t pci_bar[2]; + uint8_t pci_regs[PCI_REGSIZE]; + uint8_t eeprom[128]; /* for RTL8029AS */ + rom_t bios_rom; + void *pnp_card; + uint8_t pnp_csnsav; + uint8_t maclocal[6]; /* configured MAC (local) address */ /* RTL8019AS/RTL8029AS registers */ - uint8_t config0, config2, config3; + uint8_t config0; + uint8_t config2; + uint8_t config3; uint8_t _9346cr; uint32_t pad0; @@ -143,7 +150,7 @@ nelog(int lvl, const char *fmt, ...) static void nic_interrupt(void *priv, int set) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; if (dev->is_pci) { if (set) @@ -251,7 +258,7 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len) break; } - return (retval); + return retval; } static void @@ -308,7 +315,7 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) /* Writes to this page are illegal. */ static uint32_t -page3_read(nic_t *dev, uint32_t off, unsigned int len) +page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) { if (dev->board >= NE2K_RTL8019AS) switch (off) { @@ -316,7 +323,7 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len) return (dev->_9346cr); case 0x3: /* CONFIG0 */ - return (0x00); /* Cable not BNC */ + return 0x00; /* Cable not BNC */ case 0x5: /* CONFIG2 */ return (dev->config2 & 0xe0); @@ -329,12 +336,12 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len) case 0xe: /* 8029ASID0 */ if (dev->board == NE2K_RTL8029AS) - return (0x29); + return 0x29; break; case 0xf: /* 8029ASID1 */ if (dev->board == NE2K_RTL8029AS) - return (0x80); + return 0x80; break; default: @@ -342,11 +349,11 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len) } nelog(3, "%s: Page3 read register 0x%02x attempted\n", dev->name, off); - return (0x00); + return 0x00; } static void -page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) +page3_write(nic_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { if (dev->board >= NE2K_RTL8019AS) { nelog(3, "%s: Page2 write to register 0x%02x, len=%u, value=0x%04x\n", @@ -409,7 +416,7 @@ nic_read(nic_t *dev, uint32_t addr, unsigned len) break; } - return (retval); + return retval; } static uint8_t @@ -521,7 +528,7 @@ nic_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv) if (ld != 0) return 0x00; - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; switch (reg) { case 0xF0: @@ -535,6 +542,9 @@ nic_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv) case 0xF5: return dev->pnp_csnsav; + + default: + break; } return 0x00; @@ -623,10 +633,10 @@ nic_update_bios(nic_t *dev) } static uint8_t -nic_pci_read(int func, int addr, void *priv) +nic_pci_read(UNUSED(int func), int addr, void *priv) { - nic_t *dev = (nic_t *) priv; - uint8_t ret = 0x00; + const nic_t *dev = (nic_t *) priv; + uint8_t ret = 0x00; switch (addr) { case 0x00: /* PCI_VID_LO */ @@ -707,15 +717,18 @@ nic_pci_read(int func, int addr, void *priv) case 0x3D: /* PCI_IPR */ ret = dev->pci_regs[addr]; break; + + default: + break; } nelog(2, "%s: PCI_Read(%d, %04x) = %02x\n", dev->name, func, addr, ret); - return (ret); + return ret; } static void -nic_pci_write(int func, int addr, uint8_t val, void *priv) +nic_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { nic_t *dev = (nic_t *) priv; uint8_t valxor; @@ -737,7 +750,9 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) case 0x10: /* PCI_BAR */ val &= 0xe0; /* 0xe0 acc to RTL DS */ val |= 0x01; /* re-enable IOIN bit */ - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: /* PCI_BAR */ case 0x12: /* PCI_BAR */ @@ -767,7 +782,9 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) case 0x32: /* PCI_ROMBAR */ case 0x33: /* PCI_ROMBAR */ dev->pci_bar[1].addr_regs[addr & 3] = val; - /* dev->pci_bar[1].addr_regs[1] &= dev->bios_mask; */ +#if 0 + dev->pci_bar[1].addr_regs[1] &= dev->bios_mask; +#endif dev->pci_bar[1].addr &= 0xffff8001; dev->bios_addr = dev->pci_bar[1].addr & 0xffff8000; nic_update_bios(dev); @@ -778,6 +795,9 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) dev->base_irq = val; dev->pci_regs[addr] = dev->base_irq; return; + + default: + break; } } @@ -823,7 +843,7 @@ nic_rom_init(nic_t *dev, char *s) static uint8_t nic_mca_read(int port, void *priv) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; return (dev->pos_regs[port & 7]); } @@ -888,7 +908,7 @@ nic_mca_write(int port, uint8_t val, void *priv) static uint8_t nic_mca_feedb(void *priv) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; return (dev->pos_regs[2] & 0x01); } @@ -1000,6 +1020,9 @@ nic_init(const device_t *info) dp8390_set_id(dev->dp8390, 0x50, (dev->board == NE2K_RTL8019AS) ? 0x70 : 0x43); dp8390_mem_alloc(dev->dp8390, 0x4000, 0x8000); break; + + default: + break; } memcpy(dev->dp8390->physaddr, dev->maclocal, sizeof(dev->maclocal)); @@ -1095,7 +1118,7 @@ nic_init(const device_t *info) nelog(1, "%s: %s attached IO=0x%X IRQ=%d\n", dev->name, dev->is_pci ? "PCI" : "ISA", dev->base_address, dev->base_irq); - return (dev); + return dev; } static void diff --git a/src/network/net_null.c b/src/network/net_null.c new file mode 100644 index 000000000..6fb3f3440 --- /dev/null +++ b/src/network/net_null.c @@ -0,0 +1,225 @@ +/* +* 86Box A hypervisor and IBM PC system emulator that specializes in +* running old operating systems and software designed for IBM +* PC systems and compatibles from 1981 through fairly recent +* system designs based on the PCI bus. +* +* This file is part of the 86Box distribution. +* +* Null network driver +* +* +* +* Authors: cold-brewed +* +* Copyright 2023 The 86Box development team +*/ + +#include +#include +#include +#include +#include +#include +#include +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#else +# include +#endif + +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/thread.h> +#include <86box/timer.h> +#include <86box/network.h> +#include <86box/net_event.h> +#include <86box/plat_unused.h> + +enum { + NET_EVENT_STOP = 0, + NET_EVENT_TX, + NET_EVENT_RX, + NET_EVENT_MAX +}; + +/* Special define for the windows portion. Because we are not interested + * in NET_EVENT_RX for the null driver, we only need to poll up to + * NET_EVENT_TX. NET_EVENT_RX gives us a different NET_EVENT_MAX + * excluding NET_EVENT_RX. */ +#define NET_EVENT_TX_MAX NET_EVENT_RX + +#define NULL_PKT_BATCH NET_QUEUE_LEN + +typedef struct net_null_t { + uint8_t mac_addr[6]; + netcard_t *card; + thread_t *poll_tid; + net_evt_t tx_event; + net_evt_t stop_event; + netpkt_t pkt; + netpkt_t pktv[NULL_PKT_BATCH]; +} net_null_t; + +#ifdef ENABLE_NET_NULL_LOG +int net_null_do_log = ENABLE_NET_NULL_LOG; + +static void +net_null_log(const char *fmt, ...) +{ + va_list ap; + + if (net_null_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define net_null_log(fmt, ...) +#endif + +#ifdef _WIN32 +static void +net_null_thread(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: polling started.\n"); + + HANDLE events[NET_EVENT_TX_MAX]; + events[NET_EVENT_STOP] = net_event_get_handle(&net_null->stop_event); + events[NET_EVENT_TX] = net_event_get_handle(&net_null->tx_event); + + bool run = true; + + while (run) { + int ret = WaitForMultipleObjects(NET_EVENT_TX_MAX, events, FALSE, INFINITE); + + switch (ret - WAIT_OBJECT_0) { + case NET_EVENT_STOP: + net_event_clear(&net_null->stop_event); + run = false; + break; + + case NET_EVENT_TX: + net_event_clear(&net_null->tx_event); + int packets = network_tx_popv(net_null->card, net_null->pktv, NULL_PKT_BATCH); + for (int i = 0; i < packets; i++) { + net_null_log("Null Network: Ignoring TX packet (%d bytes)\n", net_null->pktv[i].len); + } + break; + + default: + net_null_log("Null Network: Unknown event.\n"); + break; + } + } + + net_null_log("Null Network: polling stopped.\n"); +} +#else +static void +net_null_thread(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: polling started.\n"); + + struct pollfd pfd[NET_EVENT_MAX]; + pfd[NET_EVENT_STOP].fd = net_event_get_fd(&net_null->stop_event); + pfd[NET_EVENT_STOP].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_TX].fd = net_event_get_fd(&net_null->tx_event); + pfd[NET_EVENT_TX].events = POLLIN | POLLPRI; + + while (1) { + poll(pfd, NET_EVENT_MAX, -1); + + if (pfd[NET_EVENT_STOP].revents & POLLIN) { + net_event_clear(&net_null->stop_event); + break; + } + + if (pfd[NET_EVENT_TX].revents & POLLIN) { + net_event_clear(&net_null->tx_event); + + int packets = network_tx_popv(net_null->card, net_null->pktv, NULL_PKT_BATCH); + for (int i = 0; i < packets; i++) { + net_null_log("Null Network: Ignoring TX packet (%d bytes)\n", net_null->pktv[i].len); + } + } + } + + net_null_log("Null Network: polling stopped.\n"); +} +#endif + +void * +net_null_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv), UNUSED(char *netdrv_errbuf)) +{ + net_null_log("Null Network: Init\n"); + + net_null_t *net_null = calloc(1, sizeof(net_null_t)); + net_null->card = (netcard_t *) card; + memcpy(net_null->mac_addr, mac_addr, sizeof(net_null->mac_addr)); + + for (int i = 0; i < NULL_PKT_BATCH; i++) { + net_null->pktv[i].data = calloc(1, NET_MAX_FRAME); + } + net_null->pkt.data = calloc(1, NET_MAX_FRAME); + + net_event_init(&net_null->tx_event); + net_event_init(&net_null->stop_event); + net_null->poll_tid = thread_create(net_null_thread, net_null); + + return net_null; +} + + + +void +net_null_in_available(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + net_event_set(&net_null->tx_event); +} + +void +net_null_close(void *priv) +{ + if (!priv) + return; + + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: closing.\n"); + + /* Tell the thread to terminate. */ + net_event_set(&net_null->stop_event); + + /* Wait for the thread to finish. */ + net_null_log("Null Network: waiting for thread to end...\n"); + thread_wait(net_null->poll_tid); + net_null_log("Null Network: thread ended\n"); + + for (int i = 0; i < NULL_PKT_BATCH; i++) { + free(net_null->pktv[i].data); + } + free(net_null->pkt.data); + + net_event_close(&net_null->tx_event); + net_event_close(&net_null->stop_event); + + free(net_null); +} + +const netdrv_t net_null_drv = { + &net_null_in_available, + &net_null_init, + &net_null_close, + NULL +}; diff --git a/src/network/net_pcap.c b/src/network/net_pcap.c index 8c9326ec3..4981fb9a3 100644 --- a/src/network/net_pcap.c +++ b/src/network/net_pcap.c @@ -247,7 +247,7 @@ net_pcap_in(void *pcap, uint8_t *bufp, int len) if (pcap == NULL) return; - f_pcap_sendpacket((void *) pcap, bufp, len); + f_pcap_sendpacket(pcap, bufp, len); } void @@ -268,7 +268,7 @@ net_pcap_thread(void *priv) HANDLE events[NET_EVENT_MAX]; events[NET_EVENT_STOP] = net_event_get_handle(&pcap->stop_event); events[NET_EVENT_TX] = net_event_get_handle(&pcap->tx_event); - events[NET_EVENT_RX] = f_pcap_getevent((void *) pcap->pcap); + events[NET_EVENT_RX] = f_pcap_getevent(pcap->pcap); bool run = true; @@ -296,6 +296,9 @@ net_pcap_thread(void *priv) case NET_EVENT_RX: f_pcap_dispatch(pcap->pcap, PCAP_PKT_BATCH, net_pcap_rx_handler, (u_char *) pcap); break; + + default: + break; } } @@ -357,7 +360,7 @@ int net_pcap_prepare(netdev_t *list) { char errbuf[PCAP_ERRBUF_SIZE]; - pcap_if_t *devlist, *dev; + pcap_if_t *devlist; int i = 0; /* Try loading the DLL. */ @@ -379,7 +382,7 @@ net_pcap_prepare(netdev_t *list) return (-1); } - for (dev = devlist; dev != NULL; dev = dev->next) { + for (pcap_if_t *dev = devlist; dev != NULL; dev = dev->next) { if (i >= (NET_HOST_INTF_MAX - 1)) break; @@ -405,7 +408,16 @@ net_pcap_prepare(netdev_t *list) /* Release the memory. */ f_pcap_freealldevs(devlist); - return (i); + return i; +} + +/* + * Copy error message to the error buffer + * and log if enabled. + */ +void net_pcap_error(char *errbuf, const char *message) { + strncpy(errbuf, message, NET_DRV_ERRBUF_SIZE); + pcap_log("PCAP: %s\n", message); } /* @@ -416,18 +428,19 @@ net_pcap_prepare(netdev_t *list) * tries to attach to the network module. */ void * -net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) +net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, char *netdrv_errbuf) { char errbuf[PCAP_ERRBUF_SIZE]; char *str; char filter_exp[255]; struct bpf_program fp; + char errbuf_prep[NET_DRV_ERRBUF_SIZE]; char *intf_name = (char *) priv; /* Did we already load the library? */ if (libpcap_handle == NULL) { - pcap_log("PCAP: net_pcap_init without handle.\n"); + net_pcap_error(netdrv_errbuf, "net_pcap_init without handle"); return NULL; } @@ -440,7 +453,7 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) /* Get the value of our capture interface. */ if ((intf_name[0] == '\0') || !strcmp(intf_name, "none")) { - pcap_log("PCAP: no interface configured!\n"); + net_pcap_error(netdrv_errbuf, "No interface configured"); return NULL; } @@ -451,26 +464,28 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) memcpy(pcap->mac_addr, mac_addr, sizeof(pcap->mac_addr)); if ((pcap->pcap = f_pcap_create(intf_name, errbuf)) == NULL) { - pcap_log(" Unable to open device: %s!\n", intf_name); + snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, " Unable to open device: %s!\n", intf_name); + net_pcap_error(netdrv_errbuf, errbuf_prep); free(pcap); return NULL; } - if (f_pcap_setnonblock((void *) pcap->pcap, 1, errbuf) != 0) + if (f_pcap_setnonblock(pcap->pcap, 1, errbuf) != 0) pcap_log("PCAP: failed nonblock %s\n", errbuf); - if (f_pcap_set_immediate_mode((void *) pcap->pcap, 1) != 0) + if (f_pcap_set_immediate_mode(pcap->pcap, 1) != 0) pcap_log("PCAP: error setting immediate mode\n"); - if (f_pcap_set_promisc((void *) pcap->pcap, 1) != 0) + if (f_pcap_set_promisc(pcap->pcap, 1) != 0) pcap_log("PCAP: error enabling promiscuous mode\n"); - if (f_pcap_set_snaplen((void *) pcap->pcap, NET_MAX_FRAME) != 0) + if (f_pcap_set_snaplen(pcap->pcap, NET_MAX_FRAME) != 0) pcap_log("PCAP: error setting snaplen\n"); - if (f_pcap_activate((void *) pcap->pcap) != 0) { - pcap_log("PCAP: failed pcap_activate"); - f_pcap_close((void *) pcap->pcap); + if (f_pcap_activate(pcap->pcap) != 0) { + snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, "%s", (char *)f_pcap_geterr(pcap->pcap)); + net_pcap_error(netdrv_errbuf, errbuf_prep); + f_pcap_close(pcap->pcap); free(pcap); return NULL; } @@ -482,16 +497,18 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) "( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); - if (f_pcap_compile((void *) pcap->pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { - if (f_pcap_setfilter((void *) pcap->pcap, &fp) != 0) { - pcap_log("PCAP: error installing filter (%s) !\n", filter_exp); - f_pcap_close((void *) pcap->pcap); + if (f_pcap_compile(pcap->pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { + if (f_pcap_setfilter(pcap->pcap, &fp) != 0) { + snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, "Error installing filter (%s)\n", filter_exp); + net_pcap_error(netdrv_errbuf, errbuf_prep); + f_pcap_close(pcap->pcap); free(pcap); return NULL; } } else { - pcap_log("PCAP: could not compile filter (%s) : %s!\n", filter_exp, f_pcap_geterr((void *) pcap->pcap)); - f_pcap_close((void *) pcap->pcap); + snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, "Could not compile filter (%s) : %s!\n", filter_exp, (char *)f_pcap_geterr(pcap->pcap)); + net_pcap_error(netdrv_errbuf, errbuf_prep); + f_pcap_close(pcap->pcap); free(pcap); return NULL; } @@ -540,7 +557,7 @@ net_pcap_close(void *priv) f_pcap_sendqueue_destroy((void *) pcap->pcap_queue); #endif /* OK, now shut down Pcap itself. */ - f_pcap_close((void *) pcap->pcap); + f_pcap_close(pcap->pcap); net_event_close(&pcap->tx_event); net_event_close(&pcap->stop_event); diff --git a/src/network/net_pcnet.c b/src/network/net_pcnet.c index 7b48b063f..85d2cb8bb 100644 --- a/src/network/net_pcnet.c +++ b/src/network/net_pcnet.c @@ -47,6 +47,7 @@ #include <86box/network.h> #include <86box/net_pcnet.h> #include <86box/bswap.h> +#include <86box/plat_unused.h> /* PCI info. */ #define PCI_VENDID 0x1022 /* AMD */ @@ -446,7 +447,8 @@ pcnetIsLinkUp(nic_t *dev) static __inline int pcnetTmdLoad(nic_t *dev, TMD *tmd, uint32_t addr, int fRetIfNotOwn) { - uint8_t ownbyte, bytes[4] = { 0, 0, 0, 0 }; + uint8_t ownbyte; + uint8_t bytes[4] = { 0, 0, 0, 0 }; uint16_t xda[4]; uint32_t xda32[4]; @@ -539,7 +541,8 @@ pcnetTmdStorePassHost(nic_t *dev, TMD *tmd, uint32_t addr) static __inline int pcnetRmdLoad(nic_t *dev, RMD *rmd, uint32_t addr, int fRetIfNotOwn) { - uint8_t ownbyte, bytes[4] = { 0, 0, 0, 0 }; + uint8_t ownbyte; + uint8_t bytes[4] = { 0, 0, 0, 0 }; uint16_t rda[4]; uint32_t rda32[4]; @@ -654,10 +657,10 @@ lnc_mchash(const uint8_t *ether_addr) { #define LNC_POLYNOMIAL 0xEDB88320UL uint32_t crc = 0xFFFFFFFF; - int idx, bit; + int bit; uint8_t data; - for (idx = 0; idx < ETHER_ADDR_LEN; idx++) { + for (uint8_t idx = 0; idx < ETHER_ADDR_LEN; idx++) { for (data = *ether_addr++, bit = 0; bit < MULTICAST_FILTER_LEN; bit++) { crc = (crc >> 1) ^ (((crc ^ data) & 1) ? LNC_POLYNOMIAL : 0); data >>= 1; @@ -742,11 +745,12 @@ static const uint32_t crctab[256] = }; static __inline int -padr_match(nic_t *dev, const uint8_t *buf, int size) +padr_match(nic_t *dev, const uint8_t *buf, UNUSED(int size)) { - struct ether_header *hdr = (struct ether_header *) buf; - int result; - uint8_t padr[6]; + const struct ether_header *hdr = (struct ether_header *) buf; + int result; + uint8_t padr[6]; + padr[0] = dev->aCSR[12] & 0xff; padr[1] = dev->aCSR[12] >> 8; padr[2] = dev->aCSR[13] & 0xff; @@ -766,19 +770,22 @@ padr_match(nic_t *dev, const uint8_t *buf, int size) } static __inline int -padr_bcast(nic_t *dev, const uint8_t *buf, size_t size) +padr_bcast(nic_t *dev, const uint8_t *buf, UNUSED(size_t size)) { - static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - struct ether_header *hdr = (struct ether_header *) buf; - int result = !CSR_DRCVBC(dev) && !memcmp(hdr->ether_dhost, aBCAST, 6); + static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + const struct ether_header *hdr = (struct ether_header *) buf; + int result = !CSR_DRCVBC(dev) && !memcmp(hdr->ether_dhost, aBCAST, 6); + pcnet_log(3, "%s: padr_bcast result=%d\n", dev->name, result); + return result; } static int -ladr_match(nic_t *dev, const uint8_t *buf, size_t size) +ladr_match(nic_t *dev, const uint8_t *buf, UNUSED(size_t size)) { - struct ether_header *hdr = (struct ether_header *) buf; + const struct ether_header *hdr = (struct ether_header *) buf; + if ((hdr->ether_dhost[0] & 0x01) && ((uint64_t *) &dev->aCSR[8])[0] != 0LL) { int index; uint8_t ladr[8]; @@ -859,6 +866,9 @@ pcnetSoftReset(nic_t *dev) dev->aCSR[88] = 0x3003; dev->aCSR[89] = 0x0262; break; + + default: + break; } dev->aCSR[94] = 0x0000; @@ -915,7 +925,6 @@ pcnetUpdateIrq(nic_t *dev) static void pcnetInit(nic_t *dev) { - int i; pcnet_log(3, "%s: pcnetInit: init_addr=%#010x\n", dev->name, PHYSADDR(dev, CSR_IADR(dev))); /** @todo Documentation says that RCVRL and XMTRL are stored as two's complement! @@ -956,7 +965,7 @@ pcnetInit(nic_t *dev) #undef PCNET_INIT size_t cbRxBuffers = 0; - for (i = CSR_RCVRL(dev); i >= 1; i--) { + for (int i = CSR_RCVRL(dev); i >= 1; i--) { RMD rmd; uint32_t rdaddr = PHYSADDR(dev, pcnetRdraAddr(dev, i)); @@ -1200,11 +1209,14 @@ pcnetCalcPacketLen(nic_t *dev, int cb) static int pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) { - nic_t *dev = (nic_t *) priv; - int is_padr = 0, is_bcast = 0, is_ladr = 0; + nic_t *dev = (nic_t *) priv; + int is_padr = 0; + int is_bcast = 0; + int is_ladr = 0; uint32_t iRxDesc; int cbPacket; uint8_t buf1[60]; + RMD rmd = { 0 }; if (CSR_DRX(dev) || CSR_STOP(dev) || CSR_SPND(dev) || !size) return 0; @@ -1251,7 +1263,6 @@ pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) iRxDesc = CSR_RCVRL(dev); while (iRxDesc-- > 0) { - RMD rmd; pcnetRmdLoad(dev, &rmd, PHYSADDR(dev, GCPhys), 0); GCPhys += cb; } @@ -1260,13 +1271,14 @@ pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) ++; pcnet_log(2, "%s: pcnetReceiveNoSync: packet missed\n", dev->name); } else { - RTNETETHERHDR *pEth = (RTNETETHERHDR *) buf; - int fStrip = 0; - size_t len_802_3; - uint8_t *src = &dev->abRecvBuf[8]; - uint32_t crda = CSR_CRDA(dev); - uint32_t next_crda; - RMD rmd, next_rmd; + const RTNETETHERHDR *pEth = (RTNETETHERHDR *) buf; + int fStrip = 0; + size_t len_802_3; + uint8_t *src = &dev->abRecvBuf[8]; + uint32_t crda = CSR_CRDA(dev); + uint32_t next_crda; + RMD rmd; + RMD next_rmd; /* * Ethernet framing considers these two octets to be @@ -1293,8 +1305,8 @@ pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) while (size < 60) src[size++] = 0; - uint32_t fcs = UINT32_MAX; - uint8_t *p = src; + uint32_t fcs = UINT32_MAX; + const uint8_t *p = src; while (p != &src[size]) CRC(fcs, *p++); @@ -1304,7 +1316,7 @@ pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) size += 4; } - cbPacket = (int) size; + cbPacket = size; pcnetRmdLoad(dev, &rmd, PHYSADDR(dev, crda), 0); /* if (!CSR_LAPPEN(dev)) */ @@ -1473,8 +1485,8 @@ pcnetAsyncTransmit(nic_t *dev) break; /* Don't continue sending packets when the link is down. */ - if ((!pcnetIsLinkUp(dev) - && dev->cLinkDownReported > PCNET_MAX_LINKDOWN_REPORTED)) + if (!pcnetIsLinkUp(dev) + && dev->cLinkDownReported > PCNET_MAX_LINKDOWN_REPORTED) break; pcnet_log(3, "%s: TMDLOAD %#010x\n", dev->name, PHYSADDR(dev, CSR_CXDA(dev))); @@ -1488,7 +1500,7 @@ pcnetAsyncTransmit(nic_t *dev) const int cb = 4096 - tmd.tmd1.bcnt; pcnet_log(3, "%s: pcnetAsyncTransmit: stp&enp: cb=%d xmtrc=%#x\n", dev->name, cb, CSR_XMTRC(dev)); - if ((pcnetIsLinkUp(dev) || fLoopback)) { + if (pcnetIsLinkUp(dev) || fLoopback) { /* From the manual: ``A zero length buffer is acceptable as * long as it is not the last buffer in a chain (STP = 0 and @@ -1676,9 +1688,9 @@ pcnetPollRxTx(nic_t *dev) } static void -pcnetPollTimer(void *p) +pcnetPollTimer(void *priv) { - nic_t *dev = (nic_t *) p; + nic_t *dev = (nic_t *) priv; timer_advance_u64(&dev->timer, 2000 * TIMER_USEC); @@ -2024,7 +2036,10 @@ static uint16_t pcnet_mii_readw(nic_t *dev, uint16_t miiaddr) { uint16_t val; - int autoneg, duplex, fast, isolate; + int autoneg; + int duplex; + int fast; + int isolate; /* If the DANAS (BCR32.7) bit is set, the MAC does not do any * auto-negotiation and the PHY must be set up explicitly. DANAS @@ -2216,6 +2231,9 @@ pcnet_word_write(nic_t *dev, uint32_t addr, uint16_t val) case 0x06: pcnet_bcr_writew(dev, dev->u32RAP, val); break; + + default: + break; } } } @@ -2231,6 +2249,9 @@ pcnet_byte_read(nic_t *dev, uint32_t addr) pcnetSoftReset(dev); val = 0; break; + + default: + break; } } @@ -2238,7 +2259,7 @@ pcnet_byte_read(nic_t *dev, uint32_t addr) pcnet_log(3, "%s: pcnet_word_read: addr = %04x, val = %04x, DWIO not set = %04x\n", dev->name, addr & 0x0f, val, !BCR_DWIO(dev)); - return (val); + return val; } static uint16_t @@ -2268,6 +2289,9 @@ pcnet_word_read(nic_t *dev, uint32_t addr) case 0x06: val = pcnet_bcr_readw(dev, dev->u32RAP); break; + + default: + break; } } @@ -2276,7 +2300,7 @@ pcnet_word_read(nic_t *dev, uint32_t addr) skip_update_irq: pcnet_log(3, "%s: pcnet_word_read: addr = %04x, val = %04x, DWIO not set = %04x\n", dev->name, addr & 0x0f, val, !BCR_DWIO(dev)); - return (val); + return val; } static void @@ -2295,12 +2319,15 @@ pcnet_dword_write(nic_t *dev, uint32_t addr, uint32_t val) case 0x0c: pcnet_bcr_writew(dev, dev->u32RAP, val & 0xffff); break; + + default: + break; } } else if ((addr & 0x0f) == 0) { /* switch device to dword i/o mode */ pcnet_bcr_writew(dev, BCR_BSBC, pcnet_bcr_readw(dev, BCR_BSBC) | 0x0080); pcnet_log(3, "%s: device switched into dword i/o mode\n", dev->name); - }; + } } static uint32_t @@ -2327,6 +2354,9 @@ pcnet_dword_read(nic_t *dev, uint32_t addr) case 0x0c: val = pcnet_bcr_readw(dev, dev->u32RAP); break; + + default: + break; } } @@ -2334,7 +2364,7 @@ pcnet_dword_read(nic_t *dev, uint32_t addr) skip_update_irq: pcnet_log(3, "%s: Read Long mode, addr = %08x, val = %08x\n", dev->name, addr, val); - return (val); + return val; } static void @@ -2424,7 +2454,7 @@ pcnet_read(nic_t *dev, uint32_t addr, int len) } pcnet_log(3, "%s: value in read - %08x\n", dev->name, retval); - return (retval); + return retval; } static uint8_t @@ -2533,9 +2563,9 @@ pcnet_ioset(nic_t *dev, uint16_t addr, int len) } static void -pcnet_pci_write(int func, int addr, uint8_t val, void *p) +pcnet_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - nic_t *dev = (nic_t *) p; + nic_t *dev = (nic_t *) priv; uint8_t valxor; pcnet_log(4, "%s: Write value %02X to register %02X\n", dev->name, val, addr & 0xff); @@ -2609,13 +2639,16 @@ pcnet_pci_write(int func, int addr, uint8_t val, void *p) dev->base_irq = val; pcnet_pci_regs[addr] = val; return; + + default: + break; } } static uint8_t -pcnet_pci_read(int func, int addr, void *p) +pcnet_pci_read(UNUSED(int func), int addr, void *priv) { - nic_t *dev = (nic_t *) p; + const nic_t *dev = (nic_t *) priv; pcnet_log(4, "%s: Read to register %02X\n", dev->name, addr & 0xff); @@ -2680,9 +2713,12 @@ pcnet_pci_read(int func, int addr, void *p) return 0x06; case 0x3F: return 0xff; + + default: + break; } - return (0); + return 0; } static void @@ -2724,7 +2760,7 @@ pcnet_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) static uint8_t pcnet_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; if (!ld && (reg == 0xf0)) return dev->aPROM[50]; @@ -3005,7 +3041,7 @@ pcnet_init(const device_t *info) timer_add(&dev->timer_restore, pcnetTimerRestore, dev, 0); - return (dev); + return dev; } static void diff --git a/src/network/net_plip.c b/src/network/net_plip.c index 58274e62a..f622d455b 100644 --- a/src/network/net_plip.c +++ b/src/network/net_plip.c @@ -35,6 +35,7 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/net_plip.h> +#include <86box/plat_unused.h> enum { PLIP_START = 0x00, @@ -57,20 +58,28 @@ enum { PLIP_END = 0x40 }; -typedef struct -{ +typedef struct plip_t { uint8_t mac[6]; void *lpt; pc_timer_t rx_timer; pc_timer_t timeout_timer; - uint8_t status, ctrl; + uint8_t status; + uint8_t ctrl; - uint8_t state, ack, tx_checksum, tx_checksum_calc, *tx_pkt; - uint16_t tx_len, tx_ptr; + uint8_t state; + uint8_t ack; + uint8_t tx_checksum; + uint8_t tx_checksum_calc; + uint8_t *tx_pkt; + uint16_t tx_len; + uint16_t tx_ptr; - uint8_t *rx_pkt, rx_checksum, rx_return_state; - uint16_t rx_len, rx_ptr; + uint8_t *rx_pkt; + uint8_t rx_checksum; + uint8_t rx_return_state; + uint16_t rx_len; + uint16_t rx_ptr; netcard_t *card; } plip_t; @@ -334,6 +343,9 @@ plip_write_data(uint8_t val, void *priv) /* Disengage timeout timer. */ timer_disable(&dev->timeout_timer); return; + + default: + break; } /* Engage timeout timer unless otherwise specified. */ @@ -356,7 +368,7 @@ plip_write_ctrl(uint8_t val, void *priv) static uint8_t plip_read_status(void *priv) { - plip_t *dev = (plip_t *) priv; + const plip_t *dev = (plip_t *) priv; plip_log(3, "PLIP: read_status() = %02X\n", dev->status); @@ -454,7 +466,7 @@ plip_lpt_init(void *lpt) } static void * -plip_net_init(const device_t *info) +plip_net_init(UNUSED(const device_t *info)) { plip_log(1, "PLIP: net_init()"); diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index 7651464a2..6aff76a90 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -58,7 +58,7 @@ enum { NET_EVENT_MAX }; -typedef struct { +typedef struct net_slirp_t { Slirp *slirp; uint8_t mac_addr[6]; netcard_t *card; /* netcard attached to us */ @@ -68,9 +68,10 @@ typedef struct { netpkt_t pkt; netpkt_t pkt_tx_v[SLIRP_PKT_BATCH]; #ifdef _WIN32 - HANDLE sock_event; + HANDLE sock_event; #else - uint32_t pfd_len, pfd_size; + uint32_t pfd_len; + uint32_t pfd_size; struct pollfd *pfd; #endif } net_slirp_t; @@ -94,19 +95,19 @@ slirp_log(const char *fmt, ...) #endif static void -net_slirp_guest_error(const char *msg, void *opaque) +net_slirp_guest_error(UNUSED(const char *msg), UNUSED(void *opaque)) { slirp_log("SLiRP: guest_error(): %s\n", msg); } static int64_t -net_slirp_clock_get_ns(void *opaque) +net_slirp_clock_get_ns(UNUSED(void *opaque)) { return (int64_t) ((double) tsc / cpuclock * 1000000000.0); } static void * -net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, void *opaque) +net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, UNUSED(void *opaque)) { pc_timer_t *timer = malloc(sizeof(pc_timer_t)); timer_add(timer, cb, cb_opaque, 0); @@ -114,14 +115,14 @@ net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, void *opaque) } static void -net_slirp_timer_free(void *timer, void *opaque) +net_slirp_timer_free(void *timer, UNUSED(void *opaque)) { timer_stop(timer); free(timer); } static void -net_slirp_timer_mod(void *timer, int64_t expire_timer, void *opaque) +net_slirp_timer_mod(void *timer, int64_t expire_timer, UNUSED(void *opaque)) { timer_on_auto(timer, expire_timer * 1000); } @@ -384,7 +385,7 @@ static int slirp_card_num = 2; /* Initialize SLiRP for use. */ void * -net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) +net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv), char *netdrv_errbuf) { slirp_log("SLiRP: initializing...\n"); net_slirp_t *slirp = calloc(1, sizeof(net_slirp_t)); @@ -410,12 +411,16 @@ net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) slirp->slirp = slirp_init(0, 1, net, mask, host, 0, ipv6_dummy, 0, ipv6_dummy, NULL, NULL, NULL, NULL, dhcp, dns, ipv6_dummy, NULL, NULL, &slirp_cb, slirp); if (!slirp->slirp) { slirp_log("SLiRP: initialization failed\n"); + snprintf(netdrv_errbuf, NET_DRV_ERRBUF_SIZE, "SLiRP initialization failed"); free(slirp); return NULL; } /* Set up port forwarding. */ - int udp, external, internal, i = 0; + int udp; + int i = 0; + int external; + int internal; char category[32]; snprintf(category, sizeof(category), "SLiRP Port Forwarding #%d", card->card_num + 1); char key[20]; @@ -489,15 +494,3 @@ const netdrv_t net_slirp_drv = { &net_slirp_init, &net_slirp_close }; - -/* Stubs to stand in for the parts of libslirp we skip compiling. */ -void ncsi_input(void *slirp, const uint8_t *pkt, int pkt_len) {} -void ip6_init(void *slirp) {} -void in6_compute_ethaddr(struct in6_addr ip, uint8_t *eth) {} -bool in6_equal(const void *a, const void *b) { return 0; } -const struct in6_addr in6addr_any = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }; -const struct in6_addr in6addr_loopback = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }; -void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, - uint8_t ethaddr[6]) {} /* IPv6 */ -bool ndp_table_search(void *slirp, struct in6_addr ip_addr, uint8_t *out_ethaddr) { return 0; } -void tftp_input(void *srcsas, void *m) {} diff --git a/src/network/net_vde.c b/src/network/net_vde.c new file mode 100644 index 000000000..afeeaac9c --- /dev/null +++ b/src/network/net_vde.c @@ -0,0 +1,310 @@ + /* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * VDE networking for 86box + * See https://wiki.virtualsquare.org/#!tutorials/vdebasics.md + * for basic information about VDE. You can browse the source + * code at https://github.com/virtualsquare/vde-2 + * + * VDE support is only available in Linux and MacOS. It _should_ + * be available in BSD*, and if someday there is a BSD version of + * 86box this _could_ work out of the box. + * + * Authors: jguillaumes + * Copyright 2023 jguillaumes. + * + * See the COPYING file at the top of the 86box for license details. + * TL;DR: GPL version 2. + */ +#include +#include +#include +#include +#include + +#if !defined(_WIN32) +#include +#include +#else +#error VDE is not supported under windows +#endif + +#include + +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/plat.h> +#include <86box/plat_dynld.h> +#include <86box/thread.h> +#include <86box/timer.h> +#include <86box/network.h> +#include <86box/net_event.h> + +#define VDE_PKT_BATCH NET_QUEUE_LEN +#define VDE_DESCRIPTION "86Box virtual card" + +enum { + NET_EVENT_STOP = 0, + NET_EVENT_TX, + NET_EVENT_RX, + NET_EVENT_VDE, + NET_EVENT_MAX +}; + +static volatile void *libvde_handle = NULL; + +//+ +// VDE connection structure +//- +typedef struct net_vde_t { + void *vdeconn; // VDEPLUG Connection + netcard_t *card; // NIC linked to + thread_t *poll_tid; // Polling thread + net_evt_t tx_event; // Packets to transmit event + net_evt_t stop_event; // Stop thread event + netpkt_t pkt; // Packet read/sent + netpkt_t pktv[VDE_PKT_BATCH]; // Packet queue + uint8_t mac_addr[6]; // MAC Address +} net_vde_t; + +//+ +// VDE libvdeplug function pointers +//- +static VDECONN *(*f_vde_open)(char *, char *, int, struct vde_open_args *); // This is vde_open_real() +static void (*f_vde_close)(VDECONN *); +static int (*f_vde_datafd)(VDECONN *); // Get the data (read/write) handle +static int (*f_vde_ctlfd)(VDECONN *); // Get the control handle +static ssize_t (*f_vde_recv)(VDECONN *, void *, size_t, int); // Receive a packet +static ssize_t (*f_vde_send)(VDECONN *, const void *, size_t, int); // Send a packet + +//+ +// VDE libvdeplug function table (for import) +//- +static dllimp_t vde_imports[] = { + {"vde_open_real", &f_vde_open}, + {"vde_close", &f_vde_close}, + {"vde_datafd", &f_vde_datafd}, + {"vde_ctlfd", &f_vde_ctlfd}, + {"vde_recv", &f_vde_recv}, + {"vde_send", &f_vde_send}, + { NULL, NULL} +}; + +#ifdef ENABLE_VDE_LOG +#include +int vde_do_log = ENABLE_VDE_LOG; + +static void +vde_log(const char *fmt, ...) { + va_list ap; + + if (vde_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define vde_log(fmt, ...) +#endif + +#ifdef _WIN32 +#error VDE networking is not supported under windows +#else + +//+ +// VDE thread +//- +static void net_vde_thread(void *priv) { + net_vde_t *vde = (net_vde_t *) priv; + vde_log("VDE: Polling started.\n"); + + struct pollfd pfd[NET_EVENT_MAX]; + pfd[NET_EVENT_STOP].fd = net_event_get_fd(&vde->stop_event); + pfd[NET_EVENT_STOP].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_TX].fd = net_event_get_fd(&vde->tx_event); + pfd[NET_EVENT_TX].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_RX].fd = f_vde_datafd(vde->vdeconn); + pfd[NET_EVENT_RX].events = POLLIN; + + pfd[NET_EVENT_VDE].fd = f_vde_ctlfd(vde->vdeconn); + pfd[NET_EVENT_VDE].events = POLLIN; + + while(1) { + poll(pfd, NET_EVENT_MAX, -1); + + // Acvity in the control handle means the link is closed + // We send ourselves a STOP event + if (pfd[NET_EVENT_VDE].revents & POLLIN) { + net_event_set(&vde->stop_event); + } + + // There are packets queued to transmit + if (pfd[NET_EVENT_TX].revents & POLLIN) { + net_event_clear(&vde->tx_event); + int packets = network_tx_popv(vde->card, vde->pktv, VDE_PKT_BATCH); + for (int i=0; ivdeconn, vde->pktv[i].data,vde->pktv[i].len, 0 ); + if (nc == 0) { + vde_log("VDE: Problem, no bytes sent.\n"); + } + } + } + + // Packets are available for reading. Read packet and queue it + if (pfd[NET_EVENT_RX].revents & POLLIN) { + int nc = f_vde_recv(vde->vdeconn, vde->pkt.data, NET_MAX_FRAME, 0); + vde->pkt.len = nc; + network_rx_put_pkt(vde->card, &vde->pkt); + } + + // We have been told to close + if (pfd[NET_EVENT_STOP].revents & POLLIN) { + net_event_clear(&vde->stop_event); + break; + } + } + vde_log("VDE: Polling stopped.\n"); +} +#endif + + +//+ +// Prepare the VDE libvdeplug interface. +// Load the dynamic library libvdeplug. +// Returns zero if the library has been loaded, -1 in case of error. +//- +int net_vde_prepare(void) { + +#if defined(_WIN32) + #error VDE is not supported in Windows +#elif defined(__APPLE__) + libvde_handle = dynld_module("libvdeplug.dylib", vde_imports); +#else + libvde_handle = dynld_module("libvdeplug.so", vde_imports); +#endif + + if (libvde_handle == NULL) { + vde_log("VDE: error loading VDEPLUG module\n"); + return -1; + } else { + network_devmap.has_vde = 1; + } + return 0; +} + +//+ +// Close a VDE socket connection +//- +void net_vde_close(void *priv) { + int i; + + if (!priv) return; + + net_vde_t *vde = (net_vde_t *) priv; + vde_log("VDE: closing.\n"); + net_event_set(&vde->stop_event); // Tell the thread to finish + vde_log("VDE: Waiting for the thread to finish...\n"); + thread_wait(vde->poll_tid); + vde_log("VDE: Thread finished.\n"); + + // Free all the mallocs! + for(i=0;ipktv[i].data); + } + free(vde->pkt.data); + f_vde_close(vde->vdeconn); + net_event_close(&vde->tx_event); + net_event_close(&vde->stop_event); + free(vde); +} + +//+ +// Signal packets are available to be transmitted +//- +void net_vde_in_available(void *priv) { + net_vde_t *vde = (net_vde_t *) priv; + net_event_set(&vde->tx_event); +} + +//+ +// Copy error message to the error buffer +// and log if enabled. +//- +void net_vde_error(char *errbuf, const char *message) { + strncpy(errbuf, message, NET_DRV_ERRBUF_SIZE); + vde_log("VDE: %s\n", message); +} + +//+ +// Initialize VDE for use +// At this point the vdeplug library is already loaded +// card: network card we are attaching +// mac_addr: MAC address we are using +// priv: Name of the VDE contol socket directory +//- +void *net_vde_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, char *netdrv_errbuf) { + struct vde_open_args vde_args; + + char *socket_name = (char *) priv; + + if (libvde_handle == NULL) { + net_vde_error(netdrv_errbuf, "net_vde_init without library handle"); + return NULL; + } + + if ((socket_name[0] == '\0') || !strcmp(socket_name, "none")) { + net_vde_error(netdrv_errbuf, "No socket name configured"); + return NULL; + } + + vde_log("VDE: Attaching to virtual switch at %s\n", socket_name); + + net_vde_t *vde = calloc(1, sizeof(net_vde_t)); + vde->card = (netcard_t *) card; + memcpy(vde->mac_addr, mac_addr, sizeof(vde->mac_addr)); + + vde_args.group = 0; + vde_args.port = 0; + vde_args.mode = 0; + + // We are calling vde_open_real(), not the vde_open() macro... + if ((vde->vdeconn = f_vde_open(socket_name, VDE_DESCRIPTION, + LIBVDEPLUG_INTERFACE_VERSION, &vde_args)) == NULL) { + char buf[NET_DRV_ERRBUF_SIZE]; + snprintf(buf, NET_DRV_ERRBUF_SIZE, "Unable to open socket %s (%s)", socket_name, strerror(errno)); + net_vde_error(netdrv_errbuf, buf); + free(vde); + return NULL; + } + vde_log("VDE: Socket opened (%s).\n", socket_name); + + for(uint8_t i = 0; i < VDE_PKT_BATCH; i++) { + vde->pktv[i].data = calloc(1, NET_MAX_FRAME); + } + vde->pkt.data = calloc(1,NET_MAX_FRAME); + net_event_init(&vde->tx_event); + net_event_init(&vde->stop_event); + vde->poll_tid = thread_create(net_vde_thread, vde); // Fire up the read-write thread! + + return vde; +} + +//+ +// VDE Driver structure +//- +const netdrv_t net_vde_drv = { + &net_vde_in_available, + &net_vde_init, + &net_vde_close, + NULL +}; + diff --git a/src/network/net_wd8003.c b/src/network/net_wd8003.c index c820e7444..61c35986d 100644 --- a/src/network/net_wd8003.c +++ b/src/network/net_wd8003.c @@ -64,6 +64,8 @@ #include <86box/net_dp8390.h> #include <86box/net_wd8003.h> #include <86box/bswap.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include "cpu.h" @@ -98,12 +100,14 @@ #define WE_ID_EXTRA_RAM 0x40 #define WE_ID_BUS_MCA 0x80 -typedef struct { +typedef struct wd_t { dp8390_t *dp8390; mem_mapping_t ram_mapping; - uint32_t ram_addr, ram_size; + uint32_t ram_addr; + uint32_t ram_size; uint8_t maclocal[6]; /* configured MAC (local) address */ - uint8_t bit16, pad; + uint8_t bit16; + uint8_t pad; int board; const char *name; uint32_t base_address; @@ -113,11 +117,12 @@ typedef struct { uint8_t pos_regs[8]; /* Memory for WD cards*/ - uint8_t msr, /* Memory Select Register (MSR) */ - icr, /* Interface Configuration Register (ICR) */ - irr, /* Interrupt Request Register (IRR) */ - laar, /* LA Address Register (read by Windows 98!) */ - if_chip, board_chip; + uint8_t msr; /* Memory Select Register (MSR) */ + uint8_t icr; /* Interface Configuration Register (ICR) */ + uint8_t irr; /* Interrupt Request Register (IRR) */ + uint8_t laar; /* LA Address Register (read by Windows 98!) */ + uint8_t if_chip; + uint8_t board_chip; } wd_t; #ifdef ENABLE_WD_LOG @@ -143,7 +148,7 @@ static const int we_int_table[4] = { 2, 3, 4, 7 }; static void wd_interrupt(void *priv, int set) { - wd_t *dev = (wd_t *) priv; + const wd_t *dev = (wd_t *) priv; if (!(dev->irr & WE_IRR_ENABLE_IRQ)) return; @@ -176,7 +181,7 @@ wd_soft_reset(void *priv) static uint8_t wd_ram_read(uint32_t addr, void *priv) { - wd_t *dev = (wd_t *) priv; + const wd_t *dev = (wd_t *) priv; wdlog("WD80x3: RAM Read: addr=%06x, val=%02x\n", addr & (dev->ram_size - 1), dev->dp8390->mem[addr & (dev->ram_size - 1)]); return dev->dp8390->mem[addr & (dev->ram_size - 1)]; @@ -194,9 +199,9 @@ wd_ram_write(uint32_t addr, uint8_t val, void *priv) static int wd_get_irq_index(wd_t *dev) { - uint8_t i, irq = 255; + uint8_t irq = 255; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { if (we_int_table[i] == dev->irq) irq = i; } @@ -280,12 +285,15 @@ wd_smc_read(wd_t *dev, uint32_t off) retval = 0xff - (checksum & 0xff); break; + + default: + break; } wdlog("%s: ASIC read addr=0x%02x, value=0x%04x\n", dev->name, (unsigned) off, (unsigned) retval); - return (retval); + return retval; } static void @@ -423,7 +431,7 @@ wd_read(uint16_t addr, void *priv, int len) } } - return (retval); + return retval; } static uint8_t @@ -513,7 +521,7 @@ wd_io_remove(wd_t *dev, uint16_t addr) static uint8_t wd_mca_read(int port, void *priv) { - wd_t *dev = (wd_t *) priv; + const wd_t *dev = (wd_t *) priv; return (dev->pos_regs[port & 7]); } @@ -602,6 +610,9 @@ wd_8013epa_mca_write(int port, uint8_t val, void *priv) case 0x0c: dev->irq = 14; break; + + default: + break; } if (dev->pos_regs[3] & 0x10) @@ -629,7 +640,7 @@ wd_8013epa_mca_write(int port, uint8_t val, void *priv) } static uint8_t -wd_mca_feedb(void *priv) +wd_mca_feedb(UNUSED(void *priv)) { return 1; } @@ -724,6 +735,9 @@ wd_init(const device_t *info) /* Ethernet, MCA, 5x3 interface chip, RAM 16k */ case WD8003EA: dev->board_chip = WE_ID_SOFT_CONFIG; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif /* Ethernet, MCA, no interface chip, RAM 16k */ case WD8003ETA: dev->board_chip |= WE_TYPE_WD8013EBT | WE_ID_BUS_MCA; @@ -740,6 +754,9 @@ wd_init(const device_t *info) dev->pos_regs[1] = 0x61; dev->bit16 = 3; break; + + default: + break; } dev->irr |= WE_IRR_ENABLE_IRQ; @@ -776,7 +793,7 @@ wd_init(const device_t *info) dev->base_address, dev->irq, dev->ram_addr); } - return (dev); + return dev; } static void diff --git a/src/network/network.c b/src/network/network.c index f6e9eb565..eec85fcb0 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -123,7 +123,8 @@ netcard_conf_t net_cards_conf[NET_CARD_MAX]; uint16_t net_card_current = 0; /* Global variables. */ -int network_ndev; +network_devmap_t network_devmap = {0}; +int network_ndev; netdev_t network_devs[NET_HOST_INTF_MAX]; /* Local variables. */ @@ -214,9 +215,20 @@ network_init(void) network_ndev = 1; /* Initialize the Pcap system module, if present. */ + + network_devmap.has_slirp = 1; i = net_pcap_prepare(&network_devs[network_ndev]); - if (i > 0) + if (i > 0) { + network_devmap.has_pcap = 1; network_ndev += i; + } + +#ifdef HAS_VDE + // Try to load the VDE plug library + if(net_vde_prepare()==0) { + network_devmap.has_vde = 1; + } +#endif #if defined ENABLE_NETWORK_LOG && !defined(_WIN32) /* Start packet dump. */ @@ -286,6 +298,17 @@ int network_queue_put_swap(netqueue_t *queue, netpkt_t *src_pkt) { if (src_pkt->len == 0 || src_pkt->len > NET_MAX_FRAME || network_queue_full(queue)) { +#ifdef DEBUG + if (src_pkt->len == 0) { + network_log("Discarded zero length packet.\n"); + } else if (src_pkt->len > NET_MAX_FRAME) { + network_log("Discarded oversized packet of len=%d.\n", src_pkt->len); + network_dump_packet(src_pkt); + } else { + network_log("Discarded %d bytes packet because the queue is full.\n", src_pkt->len); + network_dump_packet(src_pkt); + } +#endif return 0; } @@ -419,33 +442,69 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin card->card_num = net_card_current; card->byte_period = NET_PERIOD_10M; - for (int i = 0; i < 3; i++) { + char net_drv_error[NET_DRV_ERRBUF_SIZE]; + wchar_t tempmsg[NET_DRV_ERRBUF_SIZE * 2]; + + for (int i = 0; i < NET_QUEUE_COUNT; i++) { network_queue_init(&card->queues[i]); } switch (net_cards_conf[net_card_current].net_type) { case NET_TYPE_SLIRP: - default: card->host_drv = net_slirp_drv; - card->host_drv.priv = card->host_drv.init(card, mac, NULL); + card->host_drv.priv = card->host_drv.init(card, mac, NULL, net_drv_error); break; case NET_TYPE_PCAP: card->host_drv = net_pcap_drv; - card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name); + card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name, net_drv_error); + break; +#ifdef HAS_VDE + case NET_TYPE_VDE: + card->host_drv = net_vde_drv; + card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name, net_drv_error); + break; +#endif + default: + card->host_drv.priv = NULL; break; } + // Use null driver on: + // * No specific driver selected (card->host_drv.priv is set to null above) + // * Failure to init a specific driver (in which case card->host_drv.priv is null) if (!card->host_drv.priv) { - thread_close_mutex(card->tx_mutex); - thread_close_mutex(card->rx_mutex); - for (int i = 0; i < 3; i++) { - network_queue_clear(&card->queues[i]); + + if(net_cards_conf[net_card_current].net_type != NET_TYPE_NONE) { + // We're here because of a failure + swprintf(tempmsg, sizeof_w(tempmsg), L"%ls:

%s

%ls", plat_get_string(IDS_2167), net_drv_error, plat_get_string(IDS_2168)); + ui_msgbox(MBX_ERROR, tempmsg); + net_cards_conf[net_card_current].net_type = NET_TYPE_NONE; + } + + // Init null driver + card->host_drv = net_null_drv; + card->host_drv.priv = card->host_drv.init(card, mac, NULL, net_drv_error); + // Set link state to disconnected by default + network_connect(card->card_num, 0); + ui_sb_update_icon_state(SB_NETWORK | card->card_num, 1); + + // If null fails, something is very wrong + // Clean up and fatal + if(!card->host_drv.priv) { + thread_close_mutex(card->tx_mutex); + thread_close_mutex(card->rx_mutex); + for (int i = 0; i < NET_QUEUE_COUNT; i++) { + network_queue_clear(&card->queues[i]); + } + + free(card->queued_pkt.data); + free(card); + // Placeholder - insert the error message + fatal("Error initializing the network device: Null driver initialization failed"); + return NULL; } - free(card->queued_pkt.data); - free(card); - return NULL; } timer_add(&card->timer, network_rx_queue, card, 0); @@ -462,7 +521,7 @@ netcard_close(netcard_t *card) thread_close_mutex(card->tx_mutex); thread_close_mutex(card->rx_mutex); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NET_QUEUE_COUNT; i++) { network_queue_clear(&card->queues[i]); } @@ -493,15 +552,13 @@ network_close(void) void network_reset(void) { - int i = -1; - ui_sb_update_icon(SB_NETWORK, 0); #if defined ENABLE_NETWORK_LOG && !defined(_WIN32) network_dump_mutex = thread_create_mutex(); #endif - for (i = 0; i < NET_CARD_MAX; i++) { + for (uint8_t i = 0; i < NET_CARD_MAX; i++) { if (!network_dev_available(i)) { continue; } @@ -597,26 +654,26 @@ network_is_connected(int id) int network_dev_to_id(char *devname) { - int i = 0; - - for (i = 0; i < network_ndev; i++) { + for (int i = 0; i < network_ndev; i++) { if (!strcmp((char *) network_devs[i].device, devname)) { - return (i); + return i; } } - return (-1); + return -1; } /* UI */ int network_dev_available(int id) { - int available = (net_cards_conf[id].device_num > 0) && (net_cards_conf[id].net_type != NET_TYPE_NONE); + int available = (net_cards_conf[id].device_num > 0); - if ((net_cards_conf[id].net_type == NET_TYPE_PCAP && (network_dev_to_id(net_cards_conf[id].host_dev_name) <= 0))) + if (net_cards_conf[id].net_type == NET_TYPE_PCAP && (network_dev_to_id(net_cards_conf[id].host_dev_name) <= 0)) available = 0; + // TODO: Handle VDE device + return available; } @@ -639,7 +696,7 @@ network_card_available(int card) if (net_cards[card]) return (device_available(net_cards[card])); - return (1); + return 1; } /* UI */ @@ -654,7 +711,7 @@ int network_card_has_config(int card) { if (!net_cards[card]) - return (0); + return 0; return (device_has_config(net_cards[card]) ? 1 : 0); } @@ -674,9 +731,9 @@ network_card_get_from_internal_name(char *s) while (net_cards[c] != NULL) { if (!strcmp((char *) net_cards[c]->internal_name, s)) - return (c); + return c; c++; } return 0; -} \ No newline at end of file +} diff --git a/src/network/pcap_if.c b/src/network/pcap_if.c index 56fa3eaf1..1d3e39221 100644 --- a/src/network/pcap_if.c +++ b/src/network/pcap_if.c @@ -87,7 +87,7 @@ static int get_devlist(capdev_t *list) { char errbuf[PCAP_ERRBUF_SIZE]; - pcap_if_t *devlist, *dev; + pcap_if_t *devlist; int i = 0; /* Retrieve the device list from the local machine */ @@ -96,7 +96,7 @@ get_devlist(capdev_t *list) return (-1); } - for (dev = devlist; dev != NULL; dev = dev->next) { + for (pcap_if_t *dev = devlist; dev != NULL; dev = dev->next) { strcpy(list->device, dev->name); if (dev->description) strcpy(list->description, dev->description); @@ -109,7 +109,7 @@ get_devlist(capdev_t *list) /* Release the memory. */ f_pcap_freealldevs(devlist); - return (i); + return i; } /* Simple HEXDUMP routine for raw data. */ @@ -127,7 +127,7 @@ hex_dump(unsigned char *bufp, int len) printf("%04lx %02x", addr, c); else printf(" %02x", c); - asci[(addr & 15)] = (uint8_t) isprint(c) ? c : '.'; + asci[addr & 15] = (uint8_t) isprint(c) ? c : '.'; if ((++addr % 16) == 0) { asci[16] = '\0'; printf(" | %s |\n", asci); @@ -137,7 +137,7 @@ hex_dump(unsigned char *bufp, int len) if (addr % 16) { while (addr % 16) { printf(" "); - asci[(addr & 15)] = ' '; + asci[addr & 15] = ' '; addr++; } asci[16] = '\0'; @@ -166,7 +166,7 @@ eth_prhdr(unsigned char *ptr) type = (ptr[12] << 8) | ptr[13]; printf(" type %04x\n", type); - return (14); + return 14; } /* Capture packets from the network, and print them. */ @@ -176,7 +176,7 @@ start_cap(char *dev) char temp[PCAP_ERRBUF_SIZE]; struct pcap_pkthdr *hdr; const unsigned char *pkt; - struct tm *ltime; + const struct tm *ltime; time_t now; pcap_t *pcap; int rc; @@ -189,7 +189,7 @@ start_cap(char *dev) temp); if (pcap == NULL) { fprintf(stderr, "Pcap: open_live(%s): %s\n", dev, temp); - return (2); + return 2; } printf("Listening on '%s'..\n", dev); @@ -217,19 +217,17 @@ start_cap(char *dev) /* All done, close up. */ f_pcap_close(pcap); - return (0); + return 0; } /* Show a list of available network interfaces. */ static void show_devs(capdev_t *list, int num) { - int i; - if (num > 0) { printf("Available network interfaces:\n\n"); - for (i = 0; i < num; i++) { + for (int i = 0; i < num; i++) { printf(" %d - %s\n", i + 1, list->device); if (list->description[0] != '\0') printf(" (%s)\n", list->description); @@ -247,7 +245,8 @@ int main(int argc, char **argv) { capdev_t interfaces[32]; - int numdev, i; + int numdev; + int i; /* Try loading the DLL. */ #ifdef _WIN32 @@ -263,7 +262,7 @@ main(int argc, char **argv) #else fprintf(stderr, "Unable to load libpcap.so !\n"); #endif - return (1); + return 1; } /* Get the list. */ @@ -275,7 +274,7 @@ main(int argc, char **argv) dynld_close(pcap_handle); - return (numdev); + return numdev; } /* Assume argument to be the interface number to listen on. */ @@ -285,7 +284,7 @@ main(int argc, char **argv) dynld_close(pcap_handle); - return (1); + return 1; } /* Looks good, go and listen.. */ @@ -293,5 +292,5 @@ main(int argc, char **argv) dynld_close(pcap_handle); - return (i); + return i; } diff --git a/src/network/slirp/CMakeLists.txt b/src/network/slirp/CMakeLists.txt deleted file mode 100644 index 60993ad84..000000000 --- a/src/network/slirp/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# -# 86Box A hypervisor and IBM PC system emulator that specializes in -# running old operating systems and software designed for IBM -# PC systems and compatibles from 1981 through fairly recent -# system designs based on the PCI bus. -# -# This file is part of the 86Box distribution. -# -# CMake build script. -# -# Authors: David Hrdlička, -# -# Copyright 2020-2021 David Hrdlička. -# - -add_library(slirp STATIC arp_table.c bootp.c cksum.c dhcpv6.c dnssearch.c if.c - ip_icmp.c ip_input.c ip_output.c - ip6_icmp.c ip6_input.c ip6_output.c - mbuf.c misc.c sbuf.c slirp.c socket.c - tcp_input.c tcp_output.c tcp_subr.c tcp_timer.c - udp.c udp6.c - util.c version.c) - -if(WIN32) - target_link_libraries(slirp wsock32 iphlpapi) -endif() - -if(APPLE) - target_link_libraries(slirp resolv) -endif() - -# tinyglib conflicts with the real GLib used by Qt, let's just be safe -if(QT AND UNIX AND NOT APPLE) - set(SLIRP_TINYGLIB OFF) -endif() - -option(SLIRP_TINYGLIB "Use a minimal GLib stub (`tinyglib`) with SLiRP" ON) - -if(SLIRP_TINYGLIB) - target_sources(slirp PRIVATE tinyglib.c) -else() - find_package(PkgConfig REQUIRED) - pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) - target_link_libraries(slirp PkgConfig::GLIB) - - target_compile_definitions(slirp PRIVATE TINYGLIB_USE_GLIB) -endif() diff --git a/src/network/slirp/arp_table.c b/src/network/slirp/arp_table.c deleted file mode 100644 index d0c9111d6..000000000 --- a/src/network/slirp/arp_table.c +++ /dev/null @@ -1,104 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * ARP table - * - * Copyright (c) 2011 AdaCore - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "slirp.h" - -#include - -void arp_table_add(Slirp *slirp, uint32_t ip_addr, - const uint8_t ethaddr[ETH_ALEN]) -{ - const uint32_t broadcast_addr = - ~slirp->vnetwork_mask.s_addr | slirp->vnetwork_addr.s_addr; - ArpTable *arptbl = &slirp->arp_table; - int i; -/* - char ethaddr_str[ETH_ADDRSTRLEN]; - char addr[INET_ADDRSTRLEN]; - - DEBUG_CALL("arp_table_add"); - DEBUG_ARG("ip = %s", inet_ntop(AF_INET, &(struct in_addr){ .s_addr = ip_addr }, - addr, sizeof(addr))); - DEBUG_ARG("hw addr = %s", slirp_ether_ntoa(ethaddr, ethaddr_str, - sizeof(ethaddr_str))); -*/ - - if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) { - /* Do not register broadcast addresses */ - return; - } - - /* Search for an entry */ - for (i = 0; i < ARP_TABLE_SIZE; i++) { - if (arptbl->table[i].ar_sip == ip_addr) { - /* Update the entry */ - memcpy(arptbl->table[i].ar_sha, ethaddr, ETH_ALEN); - return; - } - } - - /* No entry found, create a new one */ - arptbl->table[arptbl->next_victim].ar_sip = ip_addr; - memcpy(arptbl->table[arptbl->next_victim].ar_sha, ethaddr, ETH_ALEN); - arptbl->next_victim = (arptbl->next_victim + 1) % ARP_TABLE_SIZE; -} - -bool arp_table_search(Slirp *slirp, uint32_t ip_addr, - uint8_t out_ethaddr[ETH_ALEN]) -{ - const uint32_t broadcast_addr = - ~slirp->vnetwork_mask.s_addr | slirp->vnetwork_addr.s_addr; - ArpTable *arptbl = &slirp->arp_table; - int i; -/* - char ethaddr_str[ETH_ADDRSTRLEN]; - char addr[INET_ADDRSTRLEN]; - - DEBUG_CALL("arp_table_search"); - DEBUG_ARG("ip = %s", inet_ntop(AF_INET, &(struct in_addr){ .s_addr = ip_addr }, - addr, sizeof(addr))); -*/ - - /* If broadcast address */ - if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) { - /* return Ethernet broadcast address */ - memset(out_ethaddr, 0xff, ETH_ALEN); - return 1; - } - - for (i = 0; i < ARP_TABLE_SIZE; i++) { - if (arptbl->table[i].ar_sip == ip_addr) { - memcpy(out_ethaddr, arptbl->table[i].ar_sha, ETH_ALEN); -/* - DEBUG_ARG("found hw addr = %s", - slirp_ether_ntoa(out_ethaddr, ethaddr_str, - sizeof(ethaddr_str))); -*/ - return 1; - } - } - - return 0; -} diff --git a/src/network/slirp/bootp.c b/src/network/slirp/bootp.c deleted file mode 100644 index a0eb17a9d..000000000 --- a/src/network/slirp/bootp.c +++ /dev/null @@ -1,398 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * QEMU BOOTP/DHCP server - * - * Copyright (c) 2004 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "slirp.h" - -#if defined(_WIN32) -/* Windows ntohl() returns an u_long value. - * Add a type cast to match the format strings. */ -#define ntohl(n) ((uint32_t)ntohl(n)) -#endif - -/* XXX: only DHCP is supported */ - -#define LEASE_TIME (24 * 3600) - -#define UEFI_HTTP_VENDOR_CLASS_ID "HTTPClient" - -static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE }; - -#define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__) - -static BOOTPClient *get_new_addr(Slirp *slirp, struct in_addr *paddr, - const uint8_t *macaddr) -{ - BOOTPClient *bc; - int i; - - for (i = 0; i < NB_BOOTP_CLIENTS; i++) { - bc = &slirp->bootp_clients[i]; - if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6)) - goto found; - } - return NULL; -found: - bc = &slirp->bootp_clients[i]; - bc->allocated = 1; - paddr->s_addr = slirp->vdhcp_startaddr.s_addr + htonl(i); - return bc; -} - -static BOOTPClient *request_addr(Slirp *slirp, const struct in_addr *paddr, - const uint8_t *macaddr) -{ - uint32_t req_addr = ntohl(paddr->s_addr); - uint32_t dhcp_addr = ntohl(slirp->vdhcp_startaddr.s_addr); - BOOTPClient *bc; - - if (req_addr >= dhcp_addr && req_addr < (dhcp_addr + NB_BOOTP_CLIENTS)) { - bc = &slirp->bootp_clients[req_addr - dhcp_addr]; - if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6)) { - bc->allocated = 1; - return bc; - } - } - return NULL; -} - -static BOOTPClient *find_addr(Slirp *slirp, struct in_addr *paddr, - const uint8_t *macaddr) -{ - BOOTPClient *bc; - int i; - - for (i = 0; i < NB_BOOTP_CLIENTS; i++) { - if (!memcmp(macaddr, slirp->bootp_clients[i].macaddr, 6)) - goto found; - } - return NULL; -found: - bc = &slirp->bootp_clients[i]; - bc->allocated = 1; - paddr->s_addr = slirp->vdhcp_startaddr.s_addr + htonl(i); - return bc; -} - -static void dhcp_decode(const struct bootp_t *bp, - const uint8_t *bp_end, - int *pmsg_type, - struct in_addr *preq_addr) -{ - const uint8_t *p; - int len, tag; - - *pmsg_type = 0; - preq_addr->s_addr = htonl(0L); - - p = bp->bp_vend; - if (memcmp(p, rfc1533_cookie, 4) != 0) - return; - p += 4; - while (p < bp_end) { - tag = p[0]; - if (tag == RFC1533_PAD) { - p++; - } else if (tag == RFC1533_END) { - break; - } else { - p++; - if (p >= bp_end) - break; - len = *p++; - if (p + len > bp_end) { - break; - } - DPRINTF("dhcp: tag=%d len=%d\n", tag, len); - - switch (tag) { - case RFC2132_MSG_TYPE: - if (len >= 1) - *pmsg_type = p[0]; - break; - case RFC2132_REQ_ADDR: - if (len >= 4) { - memcpy(&(preq_addr->s_addr), p, 4); - } - break; - default: - break; - } - p += len; - } - } - if (*pmsg_type == DHCPREQUEST && preq_addr->s_addr == htonl(0L) && - bp->bp_ciaddr.s_addr) { - memcpy(&(preq_addr->s_addr), &bp->bp_ciaddr, 4); - } -} - -static void bootp_reply(Slirp *slirp, - const struct bootp_t *bp, - const uint8_t *bp_end) -{ - BOOTPClient *bc = NULL; - struct mbuf *m; - struct bootp_t *rbp; - struct sockaddr_in saddr, daddr; - struct in_addr preq_addr; - int dhcp_msg_type, val; - uint8_t *q; - uint8_t *end; - uint8_t client_ethaddr[ETH_ALEN]; - - /* extract exact DHCP msg type */ - dhcp_decode(bp, bp_end, &dhcp_msg_type, &preq_addr); - DPRINTF("bootp packet op=%d msgtype=%d", bp->bp_op, dhcp_msg_type); - if (preq_addr.s_addr != htonl(0L)) - DPRINTF(" req_addr=%08" PRIx32 "\n", ntohl(preq_addr.s_addr)); - else { - DPRINTF("\n"); - } - - if (dhcp_msg_type == 0) - dhcp_msg_type = DHCPREQUEST; /* Force reply for old BOOTP clients */ - - if (dhcp_msg_type != DHCPDISCOVER && dhcp_msg_type != DHCPREQUEST) - return; - - /* Get client's hardware address from bootp request */ - memcpy(client_ethaddr, bp->bp_hwaddr, ETH_ALEN); - - m = m_get(slirp); - if (!m) { - return; - } - m->m_data += IF_MAXLINKHDR; - m_inc(m, sizeof(struct bootp_t) + DHCP_OPT_LEN); - rbp = (struct bootp_t *)m->m_data; - m->m_data += sizeof(struct udpiphdr); - memset(rbp, 0, sizeof(struct bootp_t) + DHCP_OPT_LEN); - - if (dhcp_msg_type == DHCPDISCOVER) { - if (preq_addr.s_addr != htonl(0L)) { - bc = request_addr(slirp, &preq_addr, client_ethaddr); - if (bc) { - daddr.sin_addr = preq_addr; - } - } - if (!bc) { - new_addr: - bc = get_new_addr(slirp, &daddr.sin_addr, client_ethaddr); - if (!bc) { - DPRINTF("no address left\n"); - return; - } - } - memcpy(bc->macaddr, client_ethaddr, ETH_ALEN); - } else if (preq_addr.s_addr != htonl(0L)) { - bc = request_addr(slirp, &preq_addr, client_ethaddr); - if (bc) { - daddr.sin_addr = preq_addr; - memcpy(bc->macaddr, client_ethaddr, ETH_ALEN); - } else { - /* DHCPNAKs should be sent to broadcast */ - daddr.sin_addr.s_addr = 0xffffffff; - } - } else { - bc = find_addr(slirp, &daddr.sin_addr, bp->bp_hwaddr); - if (!bc) { - /* if never assigned, behaves as if it was already - assigned (windows fix because it remembers its address) */ - goto new_addr; - } - } - - /* Update ARP table for this IP address */ - arp_table_add(slirp, daddr.sin_addr.s_addr, client_ethaddr); - - saddr.sin_addr = slirp->vhost_addr; - saddr.sin_port = htons(BOOTP_SERVER); - - daddr.sin_port = htons(BOOTP_CLIENT); - - rbp->bp_op = BOOTP_REPLY; - rbp->bp_xid = bp->bp_xid; - rbp->bp_htype = 1; - rbp->bp_hlen = 6; - memcpy(rbp->bp_hwaddr, bp->bp_hwaddr, ETH_ALEN); - - rbp->bp_yiaddr = daddr.sin_addr; /* Client IP address */ - rbp->bp_siaddr = saddr.sin_addr; /* Server IP address */ - - q = rbp->bp_vend; - end = rbp->bp_vend + DHCP_OPT_LEN; - memcpy(q, rfc1533_cookie, 4); - q += 4; - - if (bc) { - DPRINTF("%s addr=%08" PRIx32 "\n", - (dhcp_msg_type == DHCPDISCOVER) ? "offered" : "ack'ed", - ntohl(daddr.sin_addr.s_addr)); - - if (dhcp_msg_type == DHCPDISCOVER) { - *q++ = RFC2132_MSG_TYPE; - *q++ = 1; - *q++ = DHCPOFFER; - } else /* DHCPREQUEST */ { - *q++ = RFC2132_MSG_TYPE; - *q++ = 1; - *q++ = DHCPACK; - } - - if (slirp->bootp_filename) { - g_assert(strlen(slirp->bootp_filename) < sizeof(rbp->bp_file)); - strcpy(rbp->bp_file, slirp->bootp_filename); - } - - *q++ = RFC2132_SRV_ID; - *q++ = 4; - memcpy(q, &saddr.sin_addr, 4); - q += 4; - - *q++ = RFC1533_NETMASK; - *q++ = 4; - memcpy(q, &slirp->vnetwork_mask, 4); - q += 4; - - if (!slirp->restricted) { - *q++ = RFC1533_GATEWAY; - *q++ = 4; - memcpy(q, &saddr.sin_addr, 4); - q += 4; - - *q++ = RFC1533_DNS; - *q++ = 4; - memcpy(q, &slirp->vnameserver_addr, 4); - q += 4; - } - - *q++ = RFC2132_LEASE_TIME; - *q++ = 4; - val = htonl(LEASE_TIME); - memcpy(q, &val, 4); - q += 4; - - if (*slirp->client_hostname) { - val = strlen(slirp->client_hostname); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting host name option."); - } else { - *q++ = RFC1533_HOSTNAME; - *q++ = val; - memcpy(q, slirp->client_hostname, val); - q += val; - } - } - - if (slirp->vdomainname) { - val = strlen(slirp->vdomainname); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting domain name option."); - } else { - *q++ = RFC1533_DOMAINNAME; - *q++ = val; - memcpy(q, slirp->vdomainname, val); - q += val; - } - } - - if (slirp->tftp_server_name) { - val = strlen(slirp->tftp_server_name); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting tftp-server-name option."); - } else { - *q++ = RFC2132_TFTP_SERVER_NAME; - *q++ = val; - memcpy(q, slirp->tftp_server_name, val); - q += val; - } - } - - if (slirp->vdnssearch) { - val = slirp->vdnssearch_len; - if (q + val >= end) { - g_warning("DHCP packet size exceeded, " - "omitting domain-search option."); - } else { - memcpy(q, slirp->vdnssearch, val); - q += val; - } - } - - /* this allows to support UEFI HTTP boot: according to the UEFI - specification, DHCP server must send vendor class identifier option - set to "HTTPClient" string, when responding to DHCP requests as part - of the UEFI HTTP boot - - we assume that, if the bootfile parameter was configured as an http - URL, the user intends to perform UEFI HTTP boot, so send this option - automatically */ - if (slirp->bootp_filename && g_str_has_prefix(slirp->bootp_filename, "http://")) { - val = strlen(UEFI_HTTP_VENDOR_CLASS_ID); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting vendor class id option."); - } else { - *q++ = RFC2132_VENDOR_CLASS_ID; - *q++ = val; - memcpy(q, UEFI_HTTP_VENDOR_CLASS_ID, val); - q += val; - } - } - } else { - static const char nak_msg[] = "requested address not available"; - - DPRINTF("nak'ed addr=%08" PRIx32 "\n", ntohl(preq_addr.s_addr)); - - *q++ = RFC2132_MSG_TYPE; - *q++ = 1; - *q++ = DHCPNAK; - - *q++ = RFC2132_MESSAGE; - *q++ = sizeof(nak_msg) - 1; - memcpy(q, nak_msg, sizeof(nak_msg) - 1); - q += sizeof(nak_msg) - 1; - } - assert(q < end); - *q++ = RFC1533_END; - - daddr.sin_addr.s_addr = 0xffffffffu; - - assert(q <= end); - - m->m_len = sizeof(struct bootp_t) + (end - rbp->bp_vend) - sizeof(struct ip) - sizeof(struct udphdr); - udp_output(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); -} - -void bootp_input(struct mbuf *m) -{ - struct bootp_t *bp = mtod_check(m, sizeof(struct bootp_t)); - - if (!m->slirp->disable_dhcp && bp && bp->bp_op == BOOTP_REQUEST) { - bootp_reply(m->slirp, bp, m_end(m)); - } -} diff --git a/src/network/slirp/bootp.h b/src/network/slirp/bootp.h deleted file mode 100644 index cf7797fac..000000000 --- a/src/network/slirp/bootp.h +++ /dev/null @@ -1,130 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* bootp/dhcp defines */ - -#ifndef SLIRP_BOOTP_H -#define SLIRP_BOOTP_H - -#define BOOTP_SERVER 67 -#define BOOTP_CLIENT 68 - -#define BOOTP_REQUEST 1 -#define BOOTP_REPLY 2 - -#define RFC1533_COOKIE 99, 130, 83, 99 -#define RFC1533_PAD 0 -#define RFC1533_NETMASK 1 -#define RFC1533_TIMEOFFSET 2 -#define RFC1533_GATEWAY 3 -#define RFC1533_TIMESERVER 4 -#define RFC1533_IEN116NS 5 -#define RFC1533_DNS 6 -#define RFC1533_LOGSERVER 7 -#define RFC1533_COOKIESERVER 8 -#define RFC1533_LPRSERVER 9 -#define RFC1533_IMPRESSSERVER 10 -#define RFC1533_RESOURCESERVER 11 -#define RFC1533_HOSTNAME 12 -#define RFC1533_BOOTFILESIZE 13 -#define RFC1533_MERITDUMPFILE 14 -#define RFC1533_DOMAINNAME 15 -#define RFC1533_SWAPSERVER 16 -#define RFC1533_ROOTPATH 17 -#define RFC1533_EXTENSIONPATH 18 -#define RFC1533_IPFORWARDING 19 -#define RFC1533_IPSOURCEROUTING 20 -#define RFC1533_IPPOLICYFILTER 21 -#define RFC1533_IPMAXREASSEMBLY 22 -#define RFC1533_IPTTL 23 -#define RFC1533_IPMTU 24 -#define RFC1533_IPMTUPLATEAU 25 -#define RFC1533_INTMTU 26 -#define RFC1533_INTLOCALSUBNETS 27 -#define RFC1533_INTBROADCAST 28 -#define RFC1533_INTICMPDISCOVER 29 -#define RFC1533_INTICMPRESPOND 30 -#define RFC1533_INTROUTEDISCOVER 31 -#define RFC1533_INTROUTESOLICIT 32 -#define RFC1533_INTSTATICROUTES 33 -#define RFC1533_LLTRAILERENCAP 34 -#define RFC1533_LLARPCACHETMO 35 -#define RFC1533_LLETHERNETENCAP 36 -#define RFC1533_TCPTTL 37 -#define RFC1533_TCPKEEPALIVETMO 38 -#define RFC1533_TCPKEEPALIVEGB 39 -#define RFC1533_NISDOMAIN 40 -#define RFC1533_NISSERVER 41 -#define RFC1533_NTPSERVER 42 -#define RFC1533_VENDOR 43 -#define RFC1533_NBNS 44 -#define RFC1533_NBDD 45 -#define RFC1533_NBNT 46 -#define RFC1533_NBSCOPE 47 -#define RFC1533_XFS 48 -#define RFC1533_XDM 49 - -#define RFC2132_REQ_ADDR 50 -#define RFC2132_LEASE_TIME 51 -#define RFC2132_MSG_TYPE 53 -#define RFC2132_SRV_ID 54 -#define RFC2132_PARAM_LIST 55 -#define RFC2132_MESSAGE 56 -#define RFC2132_MAX_SIZE 57 -#define RFC2132_RENEWAL_TIME 58 -#define RFC2132_REBIND_TIME 59 -#define RFC2132_VENDOR_CLASS_ID 60 -#define RFC2132_TFTP_SERVER_NAME 66 - -#define DHCPDISCOVER 1 -#define DHCPOFFER 2 -#define DHCPREQUEST 3 -#define DHCPACK 5 -#define DHCPNAK 6 - -#define RFC1533_VENDOR_MAJOR 0 -#define RFC1533_VENDOR_MINOR 0 - -#define RFC1533_VENDOR_MAGIC 128 -#define RFC1533_VENDOR_ADDPARM 129 -#define RFC1533_VENDOR_ETHDEV 130 -#define RFC1533_VENDOR_HOWTO 132 -#define RFC1533_VENDOR_MNUOPTS 160 -#define RFC1533_VENDOR_SELECTION 176 -#define RFC1533_VENDOR_MOTD 184 -#define RFC1533_VENDOR_NUMOFMOTD 8 -#define RFC1533_VENDOR_IMG 192 -#define RFC1533_VENDOR_NUMOFIMG 16 - -#define RFC1533_END 255 -#define BOOTP_VENDOR_LEN 64 -#define DHCP_OPT_LEN 312 - -struct bootp_t { - struct ip ip; - struct udphdr udp; - uint8_t bp_op; - uint8_t bp_htype; - uint8_t bp_hlen; - uint8_t bp_hops; - uint32_t bp_xid; - uint16_t bp_secs; - uint16_t unused; - struct in_addr bp_ciaddr; - struct in_addr bp_yiaddr; - struct in_addr bp_siaddr; - struct in_addr bp_giaddr; - uint8_t bp_hwaddr[16]; - uint8_t bp_sname[64]; - char bp_file[128]; - uint8_t bp_vend[]; -}; - -typedef struct { - uint16_t allocated; - uint8_t macaddr[6]; -} BOOTPClient; - -#define NB_BOOTP_CLIENTS 16 - -void bootp_input(struct mbuf *m); - -#endif diff --git a/src/network/slirp/cksum.c b/src/network/slirp/cksum.c deleted file mode 100644 index b1cb97b7e..000000000 --- a/src/network/slirp/cksum.c +++ /dev/null @@ -1,179 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1988, 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93 - * in_cksum.c,v 1.2 1994/08/02 07:48:16 davidg Exp - */ - -#include "slirp.h" - -/* - * Checksum routine for Internet Protocol family headers (Portable Version). - * - * This routine is very heavily used in the network - * code and should be modified for each CPU to be as fast as possible. - * - * XXX Since we will never span more than 1 mbuf, we can optimise this - */ - -#define ADDCARRY(x) (x > 65535 ? x -= 65535 : x) -#define REDUCE \ - { \ - l_util.l = sum; \ - sum = l_util.s[0] + l_util.s[1]; \ - ADDCARRY(sum); \ - } - -int cksum(struct mbuf *m, int len) -{ - register uint16_t *w; - register int sum = 0; - register int mlen = 0; - int byte_swapped = 0; - - union { - uint8_t c[2]; - uint16_t s; - } s_util; - union { - uint16_t s[2]; - uint32_t l; - } l_util; - - if (m->m_len == 0) - goto cont; - w = mtod(m, uint16_t *); - - mlen = m->m_len; - - if (len < mlen) - mlen = len; - len -= mlen; - /* - * Force to even boundary. - */ - if ((1 & (uintptr_t)w) && (mlen > 0)) { - REDUCE; - sum <<= 8; - s_util.c[0] = *(uint8_t *)w; - w = (uint16_t *)((int8_t *)w + 1); - mlen--; - byte_swapped = 1; - } - /* - * Unroll the loop to make overhead from - * branches &c small. - */ - while ((mlen -= 32) >= 0) { - sum += w[0]; - sum += w[1]; - sum += w[2]; - sum += w[3]; - sum += w[4]; - sum += w[5]; - sum += w[6]; - sum += w[7]; - sum += w[8]; - sum += w[9]; - sum += w[10]; - sum += w[11]; - sum += w[12]; - sum += w[13]; - sum += w[14]; - sum += w[15]; - w += 16; - } - mlen += 32; - while ((mlen -= 8) >= 0) { - sum += w[0]; - sum += w[1]; - sum += w[2]; - sum += w[3]; - w += 4; - } - mlen += 8; - if (mlen == 0 && byte_swapped == 0) - goto cont; - REDUCE; - while ((mlen -= 2) >= 0) { - sum += *w++; - } - - if (byte_swapped) { - REDUCE; - sum <<= 8; - if (mlen == -1) { - s_util.c[1] = *(uint8_t *)w; - sum += s_util.s; - mlen = 0; - } else - - mlen = -1; - } else if (mlen == -1) - s_util.c[0] = *(uint8_t *)w; - -cont: - if (len) { - DEBUG_ERROR("cksum: out of data"); - DEBUG_ERROR(" len = %d", len); - } - if (mlen == -1) { - /* The last mbuf has odd # of bytes. Follow the - standard (the odd byte may be shifted left by 8 bits - or not as determined by endian-ness of the machine) */ - s_util.c[1] = 0; - sum += s_util.s; - } - REDUCE; - return (~sum & 0xffff); -} - -int ip6_cksum(struct mbuf *m) -{ - /* TODO: Optimize this by being able to pass the ip6_pseudohdr to cksum - * separately from the mbuf */ - struct ip6 save_ip, *ip = mtod(m, struct ip6 *); - struct ip6_pseudohdr *ih = mtod(m, struct ip6_pseudohdr *); - int sum; - - save_ip = *ip; - - ih->ih_src = save_ip.ip_src; - ih->ih_dst = save_ip.ip_dst; - ih->ih_pl = htonl((uint32_t)ntohs(save_ip.ip_pl)); - ih->ih_zero_hi = 0; - ih->ih_zero_lo = 0; - ih->ih_nh = save_ip.ip_nh; - - sum = cksum(m, ((int)sizeof(struct ip6_pseudohdr)) + ntohl(ih->ih_pl)); - - *ip = save_ip; - - return sum; -} diff --git a/src/network/slirp/debug.h b/src/network/slirp/debug.h deleted file mode 100644 index 0f9f3eff3..000000000 --- a/src/network/slirp/debug.h +++ /dev/null @@ -1,59 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef DEBUG_H_ -#define DEBUG_H_ - -#define DBG_CALL (1 << 0) -#define DBG_MISC (1 << 1) -#define DBG_ERROR (1 << 2) -#define DBG_TFTP (1 << 3) -#define DBG_VERBOSE_CALL (1 << 4) - -extern int slirp_debug; - -#define DEBUG_CALL(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_CALL)) { \ - g_debug(fmt "...", ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_VERBOSE_CALL(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_VERBOSE_CALL)) { \ - g_debug(fmt "...", ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_ARG(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_CALL)) { \ - g_debug(" " fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_MISC(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_MISC)) { \ - g_debug(fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_ERROR(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_ERROR)) { \ - g_debug(fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_TFTP(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_TFTP)) { \ - g_debug(fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#endif /* DEBUG_H_ */ diff --git a/src/network/slirp/dhcpv6.c b/src/network/slirp/dhcpv6.c deleted file mode 100644 index 77b451b91..000000000 --- a/src/network/slirp/dhcpv6.c +++ /dev/null @@ -1,224 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * SLIRP stateless DHCPv6 - * - * We only support stateless DHCPv6, e.g. for network booting. - * See RFC 3315, RFC 3736, RFC 3646 and RFC 5970 for details. - * - * Copyright 2016 Thomas Huth, Red Hat Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "slirp.h" -#include "dhcpv6.h" - -/* DHCPv6 message types */ -#define MSGTYPE_REPLY 7 -#define MSGTYPE_INFO_REQUEST 11 - -/* DHCPv6 option types */ -#define OPTION_CLIENTID 1 -#define OPTION_IAADDR 5 -#define OPTION_ORO 6 -#define OPTION_DNS_SERVERS 23 -#define OPTION_BOOTFILE_URL 59 - -struct requested_infos { - uint8_t *client_id; - int client_id_len; - bool want_dns; - bool want_boot_url; -}; - -/** - * Analyze the info request message sent by the client to see what data it - * provided and what it wants to have. The information is gathered in the - * "requested_infos" struct. Note that client_id (if provided) points into - * the odata region, thus the caller must keep odata valid as long as it - * needs to access the requested_infos struct. - */ -static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen, - struct requested_infos *ri) -{ - int i, req_opt; - - while (olen > 4) { - /* Parse one option */ - int option = odata[0] << 8 | odata[1]; - int len = odata[2] << 8 | odata[3]; - - if (len + 4 > olen) { - slirp->cb->guest_error("Guest sent bad DHCPv6 packet!", - slirp->opaque); - return -E2BIG; - } - - switch (option) { - case OPTION_IAADDR: - /* According to RFC3315, we must discard requests with IA option */ - return -EINVAL; - case OPTION_CLIENTID: - if (len > 256) { - /* Avoid very long IDs which could cause problems later */ - return -E2BIG; - } - ri->client_id = odata + 4; - ri->client_id_len = len; - break; - case OPTION_ORO: /* Option request option */ - if (len & 1) { - return -EINVAL; - } - /* Check which options the client wants to have */ - for (i = 0; i < len; i += 2) { - req_opt = odata[4 + i] << 8 | odata[4 + i + 1]; - switch (req_opt) { - case OPTION_DNS_SERVERS: - ri->want_dns = true; - break; - case OPTION_BOOTFILE_URL: - ri->want_boot_url = true; - break; - default: - DEBUG_MISC("dhcpv6: Unsupported option request %d", - req_opt); - } - } - break; - default: - DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d", option, - len); - } - - odata += len + 4; - olen -= len + 4; - } - - return 0; -} - - -/** - * Handle information request messages - */ -static void dhcpv6_info_request(Slirp *slirp, struct sockaddr_in6 *srcsas, - uint32_t xid, uint8_t *odata, int olen) -{ - struct requested_infos ri = { NULL }; - struct sockaddr_in6 sa6, da6; - struct mbuf *m; - uint8_t *resp; - - if (dhcpv6_parse_info_request(slirp, odata, olen, &ri) < 0) { - return; - } - - m = m_get(slirp); - if (!m) { - return; - } - memset(m->m_data, 0, m->m_size); - m->m_data += IF_MAXLINKHDR; - resp = (uint8_t *)m->m_data + sizeof(struct ip6) + sizeof(struct udphdr); - - /* Fill in response */ - *resp++ = MSGTYPE_REPLY; - *resp++ = (uint8_t)(xid >> 16); - *resp++ = (uint8_t)(xid >> 8); - *resp++ = (uint8_t)xid; - - if (ri.client_id) { - *resp++ = OPTION_CLIENTID >> 8; /* option-code high byte */ - *resp++ = OPTION_CLIENTID; /* option-code low byte */ - *resp++ = ri.client_id_len >> 8; /* option-len high byte */ - *resp++ = ri.client_id_len; /* option-len low byte */ - memcpy(resp, ri.client_id, ri.client_id_len); - resp += ri.client_id_len; - } - if (ri.want_dns) { - *resp++ = OPTION_DNS_SERVERS >> 8; /* option-code high byte */ - *resp++ = OPTION_DNS_SERVERS; /* option-code low byte */ - *resp++ = 0; /* option-len high byte */ - *resp++ = 16; /* option-len low byte */ - memcpy(resp, &slirp->vnameserver_addr6, 16); - resp += 16; - } - if (ri.want_boot_url) { - uint8_t *sa = slirp->vhost_addr6.s6_addr; - int slen, smaxlen; - - *resp++ = OPTION_BOOTFILE_URL >> 8; /* option-code high byte */ - *resp++ = OPTION_BOOTFILE_URL; /* option-code low byte */ - smaxlen = (uint8_t *)m->m_data + slirp->if_mtu - (resp + 2); - slen = slirp_fmt((char *)resp + 2, smaxlen, - "tftp://[%02x%02x:%02x%02x:%02x%02x:%02x%02x:" - "%02x%02x:%02x%02x:%02x%02x:%02x%02x]/%s", - sa[0], sa[1], sa[2], sa[3], sa[4], sa[5], sa[6], sa[7], - sa[8], sa[9], sa[10], sa[11], sa[12], sa[13], sa[14], - sa[15], slirp->bootp_filename); - *resp++ = slen >> 8; /* option-len high byte */ - *resp++ = slen; /* option-len low byte */ - resp += slen; - } - - sa6.sin6_addr = slirp->vhost_addr6; - sa6.sin6_port = DHCPV6_SERVER_PORT; - da6.sin6_addr = srcsas->sin6_addr; - da6.sin6_port = srcsas->sin6_port; - m->m_data += sizeof(struct ip6) + sizeof(struct udphdr); - m->m_len = resp - (uint8_t *)m->m_data; - udp6_output(NULL, m, &sa6, &da6); -} - -/** - * Handle DHCPv6 messages sent by the client - */ -void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m) -{ - uint8_t *data = (uint8_t *)m->m_data + sizeof(struct udphdr); - int data_len = m->m_len - sizeof(struct udphdr); - uint32_t xid; - - if (data_len < 4) { - return; - } - - xid = ntohl(*(uint32_t *)data) & 0xffffff; - - switch (data[0]) { - case MSGTYPE_INFO_REQUEST: - dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4); - break; - default: - DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x", data[0]); - } -} diff --git a/src/network/slirp/dhcpv6.h b/src/network/slirp/dhcpv6.h deleted file mode 100644 index d12c49b36..000000000 --- a/src/network/slirp/dhcpv6.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Definitions and prototypes for SLIRP stateless DHCPv6 - * - * Copyright 2016 Thomas Huth, Red Hat Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef SLIRP_DHCPV6_H -#define SLIRP_DHCPV6_H - -#define DHCPV6_SERVER_PORT 547 - -#define ALLDHCP_MULTICAST \ - { \ - .s6_addr = { \ - 0xff, \ - 0x02, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x01, \ - 0x00, \ - 0x02 \ - } \ - } - -#define in6_dhcp_multicast(a) in6_equal(a, &(struct in6_addr)ALLDHCP_MULTICAST) - -void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m); - -#endif diff --git a/src/network/slirp/dnssearch.c b/src/network/slirp/dnssearch.c deleted file mode 100644 index 55497e860..000000000 --- a/src/network/slirp/dnssearch.c +++ /dev/null @@ -1,306 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * Domain search option for DHCP (RFC 3397) - * - * Copyright (c) 2012 Klaus Stengel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "slirp.h" - -static const uint8_t RFC3397_OPT_DOMAIN_SEARCH = 119; -static const uint8_t MAX_OPT_LEN = 255; -static const uint8_t OPT_HEADER_LEN = 2; -static const uint8_t REFERENCE_LEN = 2; - -struct compact_domain; - -typedef struct compact_domain { - struct compact_domain *self; - struct compact_domain *refdom; - uint8_t *labels; - size_t len; - size_t common_octets; -} CompactDomain; - -static size_t domain_suffix_diffoff(const CompactDomain *a, - const CompactDomain *b) -{ - size_t la = a->len, lb = b->len; - uint8_t *da = a->labels + la, *db = b->labels + lb; - size_t i, lm = (la < lb) ? la : lb; - - for (i = 0; i < lm; i++) { - da--; - db--; - if (*da != *db) { - break; - } - } - return i; -} - -static int domain_suffix_ord(const void *cva, const void *cvb) -{ - const CompactDomain *a = cva, *b = cvb; - size_t la = a->len, lb = b->len; - size_t doff = domain_suffix_diffoff(a, b); - uint8_t ca = a->labels[la - doff]; - uint8_t cb = b->labels[lb - doff]; - - if (ca < cb) { - return -1; - } - if (ca > cb) { - return 1; - } - if (la < lb) { - return -1; - } - if (la > lb) { - return 1; - } - return 0; -} - -static size_t domain_common_label(CompactDomain *a, CompactDomain *b) -{ - size_t res, doff = domain_suffix_diffoff(a, b); - uint8_t *first_eq_pos = a->labels + (a->len - doff); - uint8_t *label = a->labels; - - while (*label && label < first_eq_pos) { - label += *label + 1; - } - res = a->len - (label - a->labels); - /* only report if it can help to reduce the packet size */ - return (res > REFERENCE_LEN) ? res : 0; -} - -static void domain_fixup_order(CompactDomain *cd, size_t n) -{ - size_t i; - - for (i = 0; i < n; i++) { - CompactDomain *cur = cd + i, *next = cd[i].self; - - while (!cur->common_octets) { - CompactDomain *tmp = next->self; /* backup target value */ - - next->self = cur; - cur->common_octets++; - - cur = next; - next = tmp; - } - } -} - -static void domain_mklabels(CompactDomain *cd, const char *input) -{ - uint8_t *len_marker = cd->labels; - uint8_t *output = len_marker; /* pre-incremented */ - const char *in = input; - char cur_chr; - size_t len = 0; - - if (cd->len == 0) { - goto fail; - } - cd->len++; - - do { - cur_chr = *in++; - if (cur_chr == '.' || cur_chr == '\0') { - len = output - len_marker; - if ((len == 0 && cur_chr == '.') || len >= 64) { - goto fail; - } - *len_marker = len; - - output++; - len_marker = output; - } else { - output++; - *output = cur_chr; - } - } while (cur_chr != '\0'); - - /* ensure proper zero-termination */ - if (len != 0) { - *len_marker = 0; - cd->len++; - } - return; - -fail: - g_warning("failed to parse domain name '%s'\n", input); - cd->len = 0; -} - -static void domain_mkxrefs(CompactDomain *doms, CompactDomain *last, - size_t depth) -{ - CompactDomain *i = doms, *target = doms; - - do { - if (i->labels < target->labels) { - target = i; - } - } while (i++ != last); - - for (i = doms; i != last; i++) { - CompactDomain *group_last; - size_t next_depth; - - if (i->common_octets == depth) { - continue; - } - - next_depth = -1; - for (group_last = i; group_last != last; group_last++) { - size_t co = group_last->common_octets; - if (co <= depth) { - break; - } - if (co < next_depth) { - next_depth = co; - } - } - domain_mkxrefs(i, group_last, next_depth); - - i = group_last; - if (i == last) { - break; - } - } - - if (depth == 0) { - return; - } - - i = doms; - do { - if (i != target && i->refdom == NULL) { - i->refdom = target; - i->common_octets = depth; - } - } while (i++ != last); -} - -static size_t domain_compactify(CompactDomain *domains, size_t n) -{ - uint8_t *start = domains->self->labels, *outptr = start; - size_t i; - - for (i = 0; i < n; i++) { - CompactDomain *cd = domains[i].self; - CompactDomain *rd = cd->refdom; - - if (rd != NULL) { - size_t moff = (rd->labels - start) + (rd->len - cd->common_octets); - if (moff < 0x3FFFu) { - cd->len -= cd->common_octets - 2; - cd->labels[cd->len - 1] = moff & 0xFFu; - cd->labels[cd->len - 2] = 0xC0u | (moff >> 8); - } - } - - if (cd->labels != outptr) { - memmove(outptr, cd->labels, cd->len); - cd->labels = outptr; - } - outptr += cd->len; - } - return outptr - start; -} - -int translate_dnssearch(Slirp *s, const char **names) -{ - size_t blocks, bsrc_start, bsrc_end, bdst_start; - size_t i, num_domains, memreq = 0; - uint8_t *result = NULL, *outptr; - CompactDomain *domains = NULL; - - num_domains = g_strv_length((GStrv)(void *)names); - if (num_domains == 0) { - return -2; - } - - domains = g_malloc(num_domains * sizeof(*domains)); - - for (i = 0; i < num_domains; i++) { - size_t nlen = strlen(names[i]); - memreq += nlen + 2; /* 1 zero octet + 1 label length octet */ - domains[i].self = domains + i; - domains[i].len = nlen; - domains[i].common_octets = 0; - domains[i].refdom = NULL; - } - - /* reserve extra 2 header bytes for each 255 bytes of output */ - memreq += DIV_ROUND_UP(memreq, MAX_OPT_LEN) * OPT_HEADER_LEN; - result = g_malloc(memreq * sizeof(*result)); - - outptr = result; - for (i = 0; i < num_domains; i++) { - domains[i].labels = outptr; - domain_mklabels(domains + i, names[i]); - outptr += domains[i].len; - } - - if (outptr == result) { - g_free(domains); - g_free(result); - return -1; - } - - qsort(domains, num_domains, sizeof(*domains), domain_suffix_ord); - domain_fixup_order(domains, num_domains); - - for (i = 1; i < num_domains; i++) { - size_t cl = domain_common_label(domains + i - 1, domains + i); - domains[i - 1].common_octets = cl; - } - - domain_mkxrefs(domains, domains + num_domains - 1, 0); - memreq = domain_compactify(domains, num_domains); - - blocks = DIV_ROUND_UP(memreq, MAX_OPT_LEN); - bsrc_end = memreq; - bsrc_start = (blocks - 1) * MAX_OPT_LEN; - bdst_start = bsrc_start + blocks * OPT_HEADER_LEN; - memreq += blocks * OPT_HEADER_LEN; - - while (blocks--) { - size_t len = bsrc_end - bsrc_start; - memmove(result + bdst_start, result + bsrc_start, len); - result[bdst_start - 2] = RFC3397_OPT_DOMAIN_SEARCH; - result[bdst_start - 1] = len; - bsrc_end = bsrc_start; - bsrc_start -= MAX_OPT_LEN; - bdst_start -= MAX_OPT_LEN + OPT_HEADER_LEN; - } - - g_free(domains); - s->vdnssearch = result; - s->vdnssearch_len = memreq; - return 0; -} diff --git a/src/network/slirp/if.c b/src/network/slirp/if.c deleted file mode 100644 index 741473dc4..000000000 --- a/src/network/slirp/if.c +++ /dev/null @@ -1,216 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead) -{ - ifm->ifs_next = ifmhead->ifs_next; - ifmhead->ifs_next = ifm; - ifm->ifs_prev = ifmhead; - ifm->ifs_next->ifs_prev = ifm; -} - -static void ifs_remque(struct mbuf *ifm) -{ - ifm->ifs_prev->ifs_next = ifm->ifs_next; - ifm->ifs_next->ifs_prev = ifm->ifs_prev; -} - -void if_init(Slirp *slirp) -{ - slirp->if_fastq.qh_link = slirp->if_fastq.qh_rlink = &slirp->if_fastq; - slirp->if_batchq.qh_link = slirp->if_batchq.qh_rlink = &slirp->if_batchq; -} - -/* - * if_output: Queue packet into an output queue. - * There are 2 output queue's, if_fastq and if_batchq. - * Each output queue is a doubly linked list of double linked lists - * of mbufs, each list belonging to one "session" (socket). This - * way, we can output packets fairly by sending one packet from each - * session, instead of all the packets from one session, then all packets - * from the next session, etc. Packets on the if_fastq get absolute - * priority, but if one session hogs the link, it gets "downgraded" - * to the batchq until it runs out of packets, then it'll return - * to the fastq (eg. if the user does an ls -alR in a telnet session, - * it'll temporarily get downgraded to the batchq) - */ -void if_output(struct socket *so, struct mbuf *ifm) -{ - Slirp *slirp = ifm->slirp; - M_DUP_DEBUG(slirp, ifm, 0, 0); - - struct mbuf *ifq; - int on_fastq = 1; - - DEBUG_CALL("if_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("ifm = %p", ifm); - - /* - * First remove the mbuf from m_usedlist, - * since we're gonna use m_next and m_prev ourselves - * XXX Shouldn't need this, gotta change dtom() etc. - */ - if (ifm->m_flags & M_USEDLIST) { - slirp_remque(ifm); - ifm->m_flags &= ~M_USEDLIST; - } - - /* - * See if there's already a batchq list for this session. - * This can include an interactive session, which should go on fastq, - * but gets too greedy... hence it'll be downgraded from fastq to batchq. - * We mustn't put this packet back on the fastq (or we'll send it out of - * order) - * XXX add cache here? - */ - if (so) { - for (ifq = (struct mbuf *)slirp->if_batchq.qh_rlink; - (struct slirp_quehead *)ifq != &slirp->if_batchq; - ifq = ifq->ifq_prev) { - if (so == ifq->ifq_so) { - /* A match! */ - ifm->ifq_so = so; - ifs_insque(ifm, ifq->ifs_prev); - goto diddit; - } - } - } - - /* No match, check which queue to put it on */ - if (so && (so->so_iptos & IPTOS_LOWDELAY)) { - ifq = (struct mbuf *)slirp->if_fastq.qh_rlink; - on_fastq = 1; - /* - * Check if this packet is a part of the last - * packet's session - */ - if (ifq->ifq_so == so) { - ifm->ifq_so = so; - ifs_insque(ifm, ifq->ifs_prev); - goto diddit; - } - } else { - ifq = (struct mbuf *)slirp->if_batchq.qh_rlink; - } - - /* Create a new doubly linked list for this session */ - ifm->ifq_so = so; - ifs_init(ifm); - slirp_insque(ifm, ifq); - -diddit: - if (so) { - /* Update *_queued */ - so->so_queued++; - so->so_nqueued++; - /* - * Check if the interactive session should be downgraded to - * the batchq. A session is downgraded if it has queued 6 - * packets without pausing, and at least 3 of those packets - * have been sent over the link - * (XXX These are arbitrary numbers, probably not optimal..) - */ - if (on_fastq && - ((so->so_nqueued >= 6) && (so->so_nqueued - so->so_queued) >= 3)) { - /* Remove from current queue... */ - slirp_remque(ifm->ifs_next); - - /* ...And insert in the new. That'll teach ya! */ - slirp_insque(ifm->ifs_next, &slirp->if_batchq); - } - } - - /* - * This prevents us from malloc()ing too many mbufs - */ - if_start(ifm->slirp); -} - -/* - * Send one packet from each session. - * If there are packets on the fastq, they are sent FIFO, before - * everything else. Then we choose the first packet from each - * batchq session (socket) and send it. - * For example, if there are 3 ftp sessions fighting for bandwidth, - * one packet will be sent from the first session, then one packet - * from the second session, then one packet from the third. - */ -void if_start(Slirp *slirp) -{ - uint64_t now = slirp->cb->clock_get_ns(slirp->opaque); - bool from_batchq = false; - struct mbuf *ifm, *ifm_next, *ifqt; - - DEBUG_VERBOSE_CALL("if_start"); - - if (slirp->if_start_busy) { - return; - } - slirp->if_start_busy = true; - - struct mbuf *batch_head = NULL; - if (slirp->if_batchq.qh_link != &slirp->if_batchq) { - batch_head = (struct mbuf *)slirp->if_batchq.qh_link; - } - - if (slirp->if_fastq.qh_link != &slirp->if_fastq) { - ifm_next = (struct mbuf *)slirp->if_fastq.qh_link; - } else if (batch_head) { - /* Nothing on fastq, pick up from batchq */ - ifm_next = batch_head; - from_batchq = true; - } else { - ifm_next = NULL; - } - - while (ifm_next) { - ifm = ifm_next; - - ifm_next = ifm->ifq_next; - if ((struct slirp_quehead *)ifm_next == &slirp->if_fastq) { - /* No more packets in fastq, switch to batchq */ - ifm_next = batch_head; - from_batchq = true; - } - if ((struct slirp_quehead *)ifm_next == &slirp->if_batchq) { - /* end of batchq */ - ifm_next = NULL; - } - - /* Try to send packet unless it already expired */ - if (ifm->expiration_date >= now && !if_encap(slirp, ifm)) { - /* Packet is delayed due to pending ARP or NDP resolution */ - continue; - } - - /* Remove it from the queue */ - ifqt = ifm->ifq_prev; - slirp_remque(ifm); - - /* If there are more packets for this session, re-queue them */ - if (ifm->ifs_next != ifm) { - struct mbuf *next = ifm->ifs_next; - - slirp_insque(next, ifqt); - ifs_remque(ifm); - if (!from_batchq) { - ifm_next = next; - } - } - - /* Update so_queued */ - if (ifm->ifq_so && --ifm->ifq_so->so_queued == 0) { - /* If there's no more queued, reset nqueued */ - ifm->ifq_so->so_nqueued = 0; - } - - m_free(ifm); - } - - slirp->if_start_busy = false; -} diff --git a/src/network/slirp/if.h b/src/network/slirp/if.h deleted file mode 100644 index 7cf9d2750..000000000 --- a/src/network/slirp/if.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef IF_H -#define IF_H - -#define IF_COMPRESS 0x01 /* We want compression */ -#define IF_NOCOMPRESS 0x02 /* Do not do compression */ -#define IF_AUTOCOMP 0x04 /* Autodetect (default) */ -#define IF_NOCIDCOMP 0x08 /* CID compression */ - -#define IF_MTU_DEFAULT 1500 -#define IF_MTU_MIN 68 -#define IF_MTU_MAX 65521 -#define IF_MRU_DEFAULT 1500 -#define IF_MRU_MIN 68 -#define IF_MRU_MAX 65521 -#define IF_COMP IF_AUTOCOMP /* Flags for compression */ - -/* 2 for alignment, 14 for ethernet */ -#define IF_MAXLINKHDR (2 + ETH_HLEN) - -#endif diff --git a/src/network/slirp/ip.h b/src/network/slirp/ip.h deleted file mode 100644 index c4203f635..000000000 --- a/src/network/slirp/ip.h +++ /dev/null @@ -1,272 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip.h 8.1 (Berkeley) 6/10/93 - * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp - */ - -#ifndef IP_H -#define IP_H - -#include - -#if G_BYTE_ORDER == G_BIG_ENDIAN -#undef NTOHL -#undef NTOHS -#undef HTONL -#undef HTONS -#define NTOHL(d) -#define NTOHS(d) -#define HTONL(d) -#define HTONS(d) -#else -#ifndef NTOHL -#define NTOHL(d) ((d) = ntohl((d))) -#endif -#ifndef NTOHS -#define NTOHS(d) ((d) = ntohs((uint16_t)(d))) -#endif -#ifndef HTONL -#define HTONL(d) ((d) = htonl((d))) -#endif -#ifndef HTONS -#define HTONS(d) ((d) = htons((uint16_t)(d))) -#endif -#endif - -typedef uint32_t n_long; /* long as received from the net */ - -/* - * Definitions for internet protocol version 4. - * Per RFC 791, September 1981. - */ -#define IPVERSION 4 - -/* - * Structure of an internet header, naked of options. - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ip { -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t ip_v : 4, /* version */ - ip_hl : 4; /* header length */ -#else - uint8_t ip_hl : 4, /* header length */ - ip_v : 4; /* version */ -#endif - uint8_t ip_tos; /* type of service */ - uint16_t ip_len; /* total length */ - uint16_t ip_id; /* identification */ - uint16_t ip_off; /* fragment offset field */ -#define IP_DF 0x4000 /* don't fragment flag */ -#define IP_MF 0x2000 /* more fragments flag */ -#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ - uint8_t ip_ttl; /* time to live */ - uint8_t ip_p; /* protocol */ - uint16_t ip_sum; /* checksum */ - struct in_addr ip_src, ip_dst; /* source and dest address */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#define IP_MAXPACKET 65535 /* maximum packet size */ - -/* - * Definitions for IP type of service (ip_tos) - */ -#define IPTOS_LOWDELAY 0x10 -#define IPTOS_THROUGHPUT 0x08 -#define IPTOS_RELIABILITY 0x04 - -/* - * Definitions for options. - */ -#define IPOPT_COPIED(o) ((o)&0x80) -#define IPOPT_CLASS(o) ((o)&0x60) -#define IPOPT_NUMBER(o) ((o)&0x1f) - -#define IPOPT_CONTROL 0x00 -#define IPOPT_RESERVED1 0x20 -#define IPOPT_DEBMEAS 0x40 -#define IPOPT_RESERVED2 0x60 - -#define IPOPT_EOL 0 /* end of option list */ -#define IPOPT_NOP 1 /* no operation */ - -#define IPOPT_RR 7 /* record packet route */ -#define IPOPT_TS 68 /* timestamp */ -#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ -#define IPOPT_LSRR 131 /* loose source route */ -#define IPOPT_SATID 136 /* satnet id */ -#define IPOPT_SSRR 137 /* strict source route */ - -/* - * Offsets to fields in options other than EOL and NOP. - */ -#define IPOPT_OPTVAL 0 /* option ID */ -#define IPOPT_OLEN 1 /* option length */ -#define IPOPT_OFFSET 2 /* offset within option */ -#define IPOPT_MINOFF 4 /* min value of above */ - -/* - * Time stamp option structure. - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ip_timestamp { - uint8_t ipt_code; /* IPOPT_TS */ - uint8_t ipt_len; /* size of structure (variable) */ - uint8_t ipt_ptr; /* index of current entry */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t ipt_oflw : 4, /* overflow counter */ - ipt_flg : 4; /* flags, see below */ -#else - uint8_t ipt_flg : 4, /* flags, see below */ - ipt_oflw : 4; /* overflow counter */ -#endif - union ipt_timestamp { - n_long ipt_time[1]; - struct ipt_ta { - struct in_addr ipt_addr; - n_long ipt_time; - } ipt_ta[1]; - } ipt_timestamp; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* flag bits for ipt_flg */ -#define IPOPT_TS_TSONLY 0 /* timestamps only */ -#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ -#define IPOPT_TS_PRESPEC 3 /* specified modules only */ - -/* bits for security (not byte swapped) */ -#define IPOPT_SECUR_UNCLASS 0x0000 -#define IPOPT_SECUR_CONFID 0xf135 -#define IPOPT_SECUR_EFTO 0x789a -#define IPOPT_SECUR_MMMM 0xbc4d -#define IPOPT_SECUR_RESTR 0xaf13 -#define IPOPT_SECUR_SECRET 0xd788 -#define IPOPT_SECUR_TOPSECRET 0x6bc5 - -/* - * Internet implementation parameters. - */ -#define MAXTTL 255 /* maximum time to live (seconds) */ -#define IPDEFTTL 64 /* default ttl, from RFC 1340 */ -#define IPFRAGTTL 60 /* time to live for frags, slowhz */ -#define IPTTLDEC 1 /* subtracted when forwarding */ - -#define IP_MSS 576 /* default maximum segment size */ - -#if GLIB_SIZEOF_VOID_P == 4 -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct mbuf_ptr { - struct mbuf *mptr; - uint32_t dummy; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#else -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct mbuf_ptr { - struct mbuf *mptr; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#endif -struct qlink { - void *next, *prev; -}; - -/* - * Overlay for ip header used by other protocols (tcp, udp). - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ipovly { - struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */ - uint8_t ih_x1; /* (unused) */ - uint8_t ih_pr; /* protocol */ - uint16_t ih_len; /* protocol length */ - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* - * Ip reassembly queue structure. Each fragment - * being reassembled is attached to one of these structures. - * They are timed out after ipq_ttl drops to 0, and may also - * be reclaimed if memory becomes tight. - * size 28 bytes - */ -struct ipq { - struct qlink frag_link; /* to ip headers of fragments */ - struct qlink ip_link; /* to other reass headers */ - uint8_t ipq_ttl; /* time for reass q to live */ - uint8_t ipq_p; /* protocol of this fragment */ - uint16_t ipq_id; /* sequence id for reassembly */ - struct in_addr ipq_src, ipq_dst; -}; - -/* - * Ip header, when holding a fragment. - * - * Note: ipf_link must be at same offset as frag_link above - */ -struct ipasfrag { - struct qlink ipf_link; - struct ip ipf_ip; -}; - -G_STATIC_ASSERT(offsetof(struct ipq, frag_link) == - offsetof(struct ipasfrag, ipf_link)); - -#define ipf_off ipf_ip.ip_off -#define ipf_tos ipf_ip.ip_tos -#define ipf_len ipf_ip.ip_len -#define ipf_next ipf_link.next -#define ipf_prev ipf_link.prev - -#endif diff --git a/src/network/slirp/ip6.h b/src/network/slirp/ip6.h deleted file mode 100644 index 73a00b114..000000000 --- a/src/network/slirp/ip6.h +++ /dev/null @@ -1,214 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#ifndef SLIRP_IP6_H -#define SLIRP_IP6_H - -#include -#include - -#define ALLNODES_MULTICAST \ - { \ - .s6_addr = { \ - 0xff, \ - 0x02, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x01 \ - } \ - } - -#define SOLICITED_NODE_PREFIX \ - { \ - .s6_addr = { \ - 0xff, \ - 0x02, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x01, \ - 0xff, \ - 0x00, \ - 0x00, \ - 0x00 \ - } \ - } - -#define LINKLOCAL_ADDR \ - { \ - .s6_addr = { \ - 0xfe, \ - 0x80, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x02 \ - } \ - } - -#define ZERO_ADDR \ - { \ - .s6_addr = { \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00 \ - } \ - } - -static inline bool in6_equal(const struct in6_addr *a, const struct in6_addr *b) -{ - return memcmp(a, b, sizeof(*a)) == 0; -} - -static inline bool in6_equal_net(const struct in6_addr *a, - const struct in6_addr *b, int prefix_len) -{ - if (memcmp(a, b, prefix_len / 8) != 0) { - return 0; - } - - if (prefix_len % 8 == 0) { - return 1; - } - - return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)) == - b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)); -} - -static inline bool in6_equal_mach(const struct in6_addr *a, - const struct in6_addr *b, int prefix_len) -{ - if (memcmp(&(a->s6_addr[DIV_ROUND_UP(prefix_len, 8)]), - &(b->s6_addr[DIV_ROUND_UP(prefix_len, 8)]), - 16 - DIV_ROUND_UP(prefix_len, 8)) != 0) { - return 0; - } - - if (prefix_len % 8 == 0) { - return 1; - } - - return (a->s6_addr[prefix_len / 8] & - ((1U << (8 - (prefix_len % 8))) - 1)) == - (b->s6_addr[prefix_len / 8] & ((1U << (8 - (prefix_len % 8))) - 1)); -} - - -#define in6_equal_router(a) \ - ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len) && \ - in6_equal_mach(a, &slirp->vhost_addr6, slirp->vprefix_len)) || \ - (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64) && \ - in6_equal_mach(a, &slirp->vhost_addr6, 64))) - -#define in6_equal_dns(a) \ - ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len) && \ - in6_equal_mach(a, &slirp->vnameserver_addr6, slirp->vprefix_len)) || \ - (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64) && \ - in6_equal_mach(a, &slirp->vnameserver_addr6, 64))) - -#define in6_equal_host(a) (in6_equal_router(a) || in6_equal_dns(a)) - -#define in6_solicitednode_multicast(a) \ - (in6_equal_net(a, &(struct in6_addr)SOLICITED_NODE_PREFIX, 104)) - -#define in6_zero(a) (in6_equal(a, &(struct in6_addr)ZERO_ADDR)) - -/* Compute emulated host MAC address from its ipv6 address */ -static inline void in6_compute_ethaddr(struct in6_addr ip, - uint8_t eth[ETH_ALEN]) -{ - eth[0] = 0x52; - eth[1] = 0x56; - memcpy(ð[2], &ip.s6_addr[16 - (ETH_ALEN - 2)], ETH_ALEN - 2); -} - -/* - * Definitions for internet protocol version 6. - * Per RFC 2460, December 1998. - */ -#define IP6VERSION 6 -#define IP6_HOP_LIMIT 255 - -/* - * Structure of an internet header, naked of options. - */ -struct ip6 { -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint32_t ip_v : 4, /* version */ - ip_tc_hi : 4, /* traffic class */ - ip_tc_lo : 4, ip_fl_hi : 4, /* flow label */ - ip_fl_lo : 16; -#else - uint32_t ip_tc_hi : 4, ip_v : 4, ip_fl_hi : 4, ip_tc_lo : 4, ip_fl_lo : 16; -#endif - uint16_t ip_pl; /* payload length */ - uint8_t ip_nh; /* next header */ - uint8_t ip_hl; /* hop limit */ - struct in6_addr ip_src, ip_dst; /* source and dest address */ -}; - -/* - * IPv6 pseudo-header used by upper-layer protocols - */ -struct ip6_pseudohdr { - struct in6_addr ih_src; /* source internet address */ - struct in6_addr ih_dst; /* destination internet address */ - uint32_t ih_pl; /* upper-layer packet length */ - uint16_t ih_zero_hi; /* zero */ - uint8_t ih_zero_lo; /* zero */ - uint8_t ih_nh; /* next header */ -}; - -/* - * We don't want to mark these ip6 structs as packed as they are naturally - * correctly aligned; instead assert that there is no stray padding. - * If we marked the struct as packed then we would be unable to take - * the address of any of the fields in it. - */ -G_STATIC_ASSERT(sizeof(struct ip6) == 40); -G_STATIC_ASSERT(sizeof(struct ip6_pseudohdr) == 40); - -#endif diff --git a/src/network/slirp/ip6_icmp.c b/src/network/slirp/ip6_icmp.c deleted file mode 100644 index 0d7ee69ca..000000000 --- a/src/network/slirp/ip6_icmp.c +++ /dev/null @@ -1,442 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" -#include "ip6_icmp.h" - -#define NDP_Interval \ - g_rand_int_range(slirp->grand, NDP_MinRtrAdvInterval, NDP_MaxRtrAdvInterval) - -void icmp6_post_init(Slirp *slirp) -{ - if (!slirp->in6_enabled) { - return; - } - - slirp->ra_timer = - slirp_timer_new(slirp, SLIRP_TIMER_RA, NULL); - slirp->cb->timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + - NDP_Interval, - slirp->opaque); -} - -void icmp6_cleanup(Slirp *slirp) -{ - if (!slirp->in6_enabled) { - return; - } - - slirp->cb->timer_free(slirp->ra_timer, slirp->opaque); -} - -static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip, - struct icmp6 *icmp) -{ - struct mbuf *t = m_get(slirp); - t->m_len = sizeof(struct ip6) + ntohs(ip->ip_pl); - memcpy(t->m_data, m->m_data, t->m_len); - - /* IPv6 Packet */ - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_dst = ip->ip_src; - rip->ip_src = ip->ip_dst; - - /* ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_ECHO_REPLY; - ricmp->icmp6_cksum = 0; - - /* Checksum */ - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src) -{ - Slirp *slirp = m->slirp; - struct mbuf *t; - struct ip6 *ip = mtod(m, struct ip6 *); - char addrstr[INET6_ADDRSTRLEN]; - - DEBUG_CALL("icmp6_send_error"); - DEBUG_ARG("type = %d, code = %d", type, code); - - if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) || in6_zero(&ip->ip_src)) { - /* TODO icmp error? */ - return; - } - - t = m_get(slirp); - - /* IPv6 packet */ - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_src = *src; - rip->ip_dst = ip->ip_src; - inet_ntop(AF_INET6, &rip->ip_dst, addrstr, INET6_ADDRSTRLEN); - DEBUG_ARG("target = %s", addrstr); - - rip->ip_nh = IPPROTO_ICMPV6; - const int error_data_len = MIN( - m->m_len, slirp->if_mtu - (sizeof(struct ip6) + ICMP6_ERROR_MINLEN)); - rip->ip_pl = htons(ICMP6_ERROR_MINLEN + error_data_len); - t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl); - - /* ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = type; - ricmp->icmp6_code = code; - ricmp->icmp6_cksum = 0; - - switch (type) { - case ICMP6_UNREACH: - case ICMP6_TIMXCEED: - ricmp->icmp6_err.unused = 0; - break; - case ICMP6_TOOBIG: - ricmp->icmp6_err.mtu = htonl(slirp->if_mtu); - break; - case ICMP6_PARAMPROB: - /* TODO: Handle this case */ - break; - default: - g_assert_not_reached(); - } - t->m_data += ICMP6_ERROR_MINLEN; - memcpy(t->m_data, m->m_data, error_data_len); - - /* Checksum */ - t->m_data -= ICMP6_ERROR_MINLEN; - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code) -{ - struct in6_addr src = LINKLOCAL_ADDR; - icmp6_forward_error(m, type, code, &src); -} - -/* - * Send NDP Router Advertisement - */ -static void ndp_send_ra(Slirp *slirp) -{ - DEBUG_CALL("ndp_send_ra"); - - /* Build IPv6 packet */ - struct mbuf *t = m_get(slirp); - struct ip6 *rip = mtod(t, struct ip6 *); - size_t pl_size = 0; - struct in6_addr addr; - uint32_t scope_id; - - rip->ip_src = (struct in6_addr)LINKLOCAL_ADDR; - rip->ip_dst = (struct in6_addr)ALLNODES_MULTICAST; - rip->ip_nh = IPPROTO_ICMPV6; - - /* Build ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_NDP_RA; - ricmp->icmp6_code = 0; - ricmp->icmp6_cksum = 0; - - /* NDP */ - ricmp->icmp6_nra.chl = NDP_AdvCurHopLimit; - ricmp->icmp6_nra.M = NDP_AdvManagedFlag; - ricmp->icmp6_nra.O = NDP_AdvOtherConfigFlag; - ricmp->icmp6_nra.reserved = 0; - ricmp->icmp6_nra.lifetime = htons(NDP_AdvDefaultLifetime); - ricmp->icmp6_nra.reach_time = htonl(NDP_AdvReachableTime); - ricmp->icmp6_nra.retrans_time = htonl(NDP_AdvRetransTime); - t->m_data += ICMP6_NDP_RA_MINLEN; - pl_size += ICMP6_NDP_RA_MINLEN; - - /* Source link-layer address (NDP option) */ - struct ndpopt *opt = mtod(t, struct ndpopt *); - opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE; - opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8; - in6_compute_ethaddr(rip->ip_src, opt->ndpopt_linklayer); - t->m_data += NDPOPT_LINKLAYER_LEN; - pl_size += NDPOPT_LINKLAYER_LEN; - - /* Prefix information (NDP option) */ - struct ndpopt *opt2 = mtod(t, struct ndpopt *); - opt2->ndpopt_type = NDPOPT_PREFIX_INFO; - opt2->ndpopt_len = NDPOPT_PREFIXINFO_LEN / 8; - opt2->ndpopt_prefixinfo.prefix_length = slirp->vprefix_len; - opt2->ndpopt_prefixinfo.L = 1; - opt2->ndpopt_prefixinfo.A = 1; - opt2->ndpopt_prefixinfo.reserved1 = 0; - opt2->ndpopt_prefixinfo.valid_lt = htonl(NDP_AdvValidLifetime); - opt2->ndpopt_prefixinfo.pref_lt = htonl(NDP_AdvPrefLifetime); - opt2->ndpopt_prefixinfo.reserved2 = 0; - opt2->ndpopt_prefixinfo.prefix = slirp->vprefix_addr6; - t->m_data += NDPOPT_PREFIXINFO_LEN; - pl_size += NDPOPT_PREFIXINFO_LEN; - - /* Prefix information (NDP option) */ - if (get_dns6_addr(&addr, &scope_id) >= 0) { - /* Host system does have an IPv6 DNS server, announce our proxy. */ - struct ndpopt *opt3 = mtod(t, struct ndpopt *); - opt3->ndpopt_type = NDPOPT_RDNSS; - opt3->ndpopt_len = NDPOPT_RDNSS_LEN / 8; - opt3->ndpopt_rdnss.reserved = 0; - opt3->ndpopt_rdnss.lifetime = htonl(2 * NDP_MaxRtrAdvInterval); - opt3->ndpopt_rdnss.addr = slirp->vnameserver_addr6; - t->m_data += NDPOPT_RDNSS_LEN; - pl_size += NDPOPT_RDNSS_LEN; - } - - rip->ip_pl = htons(pl_size); - t->m_data -= sizeof(struct ip6) + pl_size; - t->m_len = sizeof(struct ip6) + pl_size; - - /* ICMPv6 Checksum */ - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -void ra_timer_handler(Slirp *slirp, void *unused) -{ - slirp->cb->timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + - NDP_Interval, - slirp->opaque); - ndp_send_ra(slirp); -} - -/* - * Send NDP Neighbor Solitication - */ -void ndp_send_ns(Slirp *slirp, struct in6_addr addr) -{ - char addrstr[INET6_ADDRSTRLEN]; - - inet_ntop(AF_INET6, &addr, addrstr, INET6_ADDRSTRLEN); - - DEBUG_CALL("ndp_send_ns"); - DEBUG_ARG("target = %s", addrstr); - - /* Build IPv6 packet */ - struct mbuf *t = m_get(slirp); - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_src = slirp->vhost_addr6; - rip->ip_dst = (struct in6_addr)SOLICITED_NODE_PREFIX; - memcpy(&rip->ip_dst.s6_addr[13], &addr.s6_addr[13], 3); - rip->ip_nh = IPPROTO_ICMPV6; - rip->ip_pl = htons(ICMP6_NDP_NS_MINLEN + NDPOPT_LINKLAYER_LEN); - t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl); - - /* Build ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_NDP_NS; - ricmp->icmp6_code = 0; - ricmp->icmp6_cksum = 0; - - /* NDP */ - ricmp->icmp6_nns.reserved = 0; - ricmp->icmp6_nns.target = addr; - - /* Build NDP option */ - t->m_data += ICMP6_NDP_NS_MINLEN; - struct ndpopt *opt = mtod(t, struct ndpopt *); - opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE; - opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8; - in6_compute_ethaddr(slirp->vhost_addr6, opt->ndpopt_linklayer); - - /* ICMPv6 Checksum */ - t->m_data -= ICMP6_NDP_NA_MINLEN; - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 1); -} - -/* - * Send NDP Neighbor Advertisement - */ -static void ndp_send_na(Slirp *slirp, struct ip6 *ip, struct icmp6 *icmp) -{ - /* Build IPv6 packet */ - struct mbuf *t = m_get(slirp); - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_src = icmp->icmp6_nns.target; - if (in6_zero(&ip->ip_src)) { - rip->ip_dst = (struct in6_addr)ALLNODES_MULTICAST; - } else { - rip->ip_dst = ip->ip_src; - } - rip->ip_nh = IPPROTO_ICMPV6; - rip->ip_pl = htons(ICMP6_NDP_NA_MINLEN + NDPOPT_LINKLAYER_LEN); - t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl); - - /* Build ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_NDP_NA; - ricmp->icmp6_code = 0; - ricmp->icmp6_cksum = 0; - - /* NDP */ - ricmp->icmp6_nna.R = NDP_IsRouter; - ricmp->icmp6_nna.S = !IN6_IS_ADDR_MULTICAST(&rip->ip_dst); - ricmp->icmp6_nna.O = 1; - ricmp->icmp6_nna.reserved_hi = 0; - ricmp->icmp6_nna.reserved_lo = 0; - ricmp->icmp6_nna.target = icmp->icmp6_nns.target; - - /* Build NDP option */ - t->m_data += ICMP6_NDP_NA_MINLEN; - struct ndpopt *opt = mtod(t, struct ndpopt *); - opt->ndpopt_type = NDPOPT_LINKLAYER_TARGET; - opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8; - in6_compute_ethaddr(ricmp->icmp6_nna.target, opt->ndpopt_linklayer); - - /* ICMPv6 Checksum */ - t->m_data -= ICMP6_NDP_NA_MINLEN; - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -/* - * Process a NDP message - */ -static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip, - struct icmp6 *icmp) -{ - g_assert(M_ROOMBEFORE(m) >= ETH_HLEN); - - m->m_len += ETH_HLEN; - m->m_data -= ETH_HLEN; - struct ethhdr *eth = mtod(m, struct ethhdr *); - m->m_len -= ETH_HLEN; - m->m_data += ETH_HLEN; - - switch (icmp->icmp6_type) { - case ICMP6_NDP_RS: - DEBUG_CALL(" type = Router Solicitation"); - if (ip->ip_hl == 255 && icmp->icmp6_code == 0 && - ntohs(ip->ip_pl) >= ICMP6_NDP_RS_MINLEN) { - /* Gratuitous NDP */ - ndp_table_add(slirp, ip->ip_src, eth->h_source); - - ndp_send_ra(slirp); - } - break; - - case ICMP6_NDP_RA: - DEBUG_CALL(" type = Router Advertisement"); - slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't", - slirp->opaque); - break; - - case ICMP6_NDP_NS: - DEBUG_CALL(" type = Neighbor Solicitation"); - if (ip->ip_hl == 255 && icmp->icmp6_code == 0 && - !IN6_IS_ADDR_MULTICAST(&icmp->icmp6_nns.target) && - ntohs(ip->ip_pl) >= ICMP6_NDP_NS_MINLEN && - (!in6_zero(&ip->ip_src) || - in6_solicitednode_multicast(&ip->ip_dst))) { - if (in6_equal_host(&icmp->icmp6_nns.target)) { - /* Gratuitous NDP */ - ndp_table_add(slirp, ip->ip_src, eth->h_source); - ndp_send_na(slirp, ip, icmp); - } - } - break; - - case ICMP6_NDP_NA: - DEBUG_CALL(" type = Neighbor Advertisement"); - if (ip->ip_hl == 255 && icmp->icmp6_code == 0 && - ntohs(ip->ip_pl) >= ICMP6_NDP_NA_MINLEN && - !IN6_IS_ADDR_MULTICAST(&icmp->icmp6_nna.target) && - (!IN6_IS_ADDR_MULTICAST(&ip->ip_dst) || icmp->icmp6_nna.S == 0)) { - ndp_table_add(slirp, ip->ip_src, eth->h_source); - } - break; - - case ICMP6_NDP_REDIRECT: - DEBUG_CALL(" type = Redirect"); - slirp->cb->guest_error( - "Warning: guest sent NDP REDIRECT, but shouldn't", slirp->opaque); - break; - } -} - -/* - * Process a received ICMPv6 message. - */ -void icmp6_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - /* NDP reads the ethernet header for gratuitous NDP */ - M_DUP_DEBUG(slirp, m, 1, ETH_HLEN); - - struct icmp6 *icmp; - struct ip6 *ip = mtod(m, struct ip6 *); - int hlen = sizeof(struct ip6); - - DEBUG_CALL("icmp6_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - if (ntohs(ip->ip_pl) < ICMP6_MINLEN) { - goto end; - } - - if (ip6_cksum(m)) { - goto end; - } - - m->m_len -= hlen; - m->m_data += hlen; - icmp = mtod(m, struct icmp6 *); - m->m_len += hlen; - m->m_data -= hlen; - - DEBUG_ARG("icmp6_type = %d", icmp->icmp6_type); - switch (icmp->icmp6_type) { - case ICMP6_ECHO_REQUEST: - if (in6_equal_host(&ip->ip_dst)) { - icmp6_send_echoreply(m, slirp, ip, icmp); - } else { - /* TODO */ - g_critical("external icmpv6 not supported yet"); - } - break; - - case ICMP6_NDP_RS: - case ICMP6_NDP_RA: - case ICMP6_NDP_NS: - case ICMP6_NDP_NA: - case ICMP6_NDP_REDIRECT: - ndp_input(m, slirp, ip, icmp); - break; - - case ICMP6_UNREACH: - case ICMP6_TOOBIG: - case ICMP6_TIMXCEED: - case ICMP6_PARAMPROB: - /* XXX? report error? close socket? */ - default: - break; - } - -end: - m_free(m); -} diff --git a/src/network/slirp/ip6_icmp.h b/src/network/slirp/ip6_icmp.h deleted file mode 100644 index 02761b726..000000000 --- a/src/network/slirp/ip6_icmp.h +++ /dev/null @@ -1,238 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#ifndef SLIRP_IP6_ICMP_H -#define SLIRP_IP6_ICMP_H - -/* - * Interface Control Message Protocol version 6 Definitions. - * Per RFC 4443, March 2006. - * - * Network Discover Protocol Definitions. - * Per RFC 4861, September 2007. - */ - -struct icmp6_echo { /* Echo Messages */ - uint16_t id; - uint16_t seq_num; -}; - -union icmp6_error_body { - uint32_t unused; - uint32_t pointer; - uint32_t mtu; -}; - -/* - * NDP Messages - */ -struct ndp_rs { /* Router Solicitation Message */ - uint32_t reserved; -}; - -struct ndp_ra { /* Router Advertisement Message */ - uint8_t chl; /* Cur Hop Limit */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t M : 1, O : 1, reserved : 6; -#else - uint8_t reserved : 6, O : 1, M : 1; -#endif - uint16_t lifetime; /* Router Lifetime */ - uint32_t reach_time; /* Reachable Time */ - uint32_t retrans_time; /* Retrans Timer */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_ra) == 12); - -struct ndp_ns { /* Neighbor Solicitation Message */ - uint32_t reserved; - struct in6_addr target; /* Target Address */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_ns) == 20); - -struct ndp_na { /* Neighbor Advertisement Message */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint32_t R : 1, /* Router Flag */ - S : 1, /* Solicited Flag */ - O : 1, /* Override Flag */ - reserved_hi : 5, reserved_lo : 24; -#else - uint32_t reserved_hi : 5, O : 1, S : 1, R : 1, reserved_lo : 24; -#endif - struct in6_addr target; /* Target Address */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_na) == 20); - -struct ndp_redirect { - uint32_t reserved; - struct in6_addr target; /* Target Address */ - struct in6_addr dest; /* Destination Address */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_redirect) == 36); - -/* - * Structure of an icmpv6 header. - */ -struct icmp6 { - uint8_t icmp6_type; /* type of message, see below */ - uint8_t icmp6_code; /* type sub code */ - uint16_t icmp6_cksum; /* ones complement cksum of struct */ - union { - union icmp6_error_body error_body; - struct icmp6_echo echo; - struct ndp_rs ndp_rs; - struct ndp_ra ndp_ra; - struct ndp_ns ndp_ns; - struct ndp_na ndp_na; - struct ndp_redirect ndp_redirect; - } icmp6_body; -#define icmp6_err icmp6_body.error_body -#define icmp6_echo icmp6_body.echo -#define icmp6_nrs icmp6_body.ndp_rs -#define icmp6_nra icmp6_body.ndp_ra -#define icmp6_nns icmp6_body.ndp_ns -#define icmp6_nna icmp6_body.ndp_na -#define icmp6_redirect icmp6_body.ndp_redirect -}; - -G_STATIC_ASSERT(sizeof(struct icmp6) == 40); - -#define ICMP6_MINLEN 4 -#define ICMP6_ERROR_MINLEN 8 -#define ICMP6_ECHO_MINLEN 8 -#define ICMP6_NDP_RS_MINLEN 8 -#define ICMP6_NDP_RA_MINLEN 16 -#define ICMP6_NDP_NS_MINLEN 24 -#define ICMP6_NDP_NA_MINLEN 24 -#define ICMP6_NDP_REDIRECT_MINLEN 40 - -/* - * NDP Options - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ndpopt { - uint8_t ndpopt_type; /* Option type */ - uint8_t ndpopt_len; /* /!\ In units of 8 octets */ - union { - unsigned char linklayer_addr[6]; /* Source/Target Link-layer */ -#define ndpopt_linklayer ndpopt_body.linklayer_addr -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif - struct prefixinfo { /* Prefix Information */ - uint8_t prefix_length; -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t L : 1, A : 1, reserved1 : 6; -#else - uint8_t reserved1 : 6, A : 1, L : 1; -#endif - uint32_t valid_lt; /* Valid Lifetime */ - uint32_t pref_lt; /* Preferred Lifetime */ - uint32_t reserved2; - struct in6_addr prefix; - } SLIRP_PACKED prefixinfo; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#define ndpopt_prefixinfo ndpopt_body.prefixinfo -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif - struct rdnss { - uint16_t reserved; - uint32_t lifetime; - struct in6_addr addr; - } SLIRP_PACKED rdnss; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#define ndpopt_rdnss ndpopt_body.rdnss - } ndpopt_body; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* NDP options type */ -#define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */ -#define NDPOPT_LINKLAYER_TARGET 2 /* Target Link-Layer Address */ -#define NDPOPT_PREFIX_INFO 3 /* Prefix Information */ -#define NDPOPT_RDNSS 25 /* Recursive DNS Server Address */ - -/* NDP options size, in octets. */ -#define NDPOPT_LINKLAYER_LEN 8 -#define NDPOPT_PREFIXINFO_LEN 32 -#define NDPOPT_RDNSS_LEN 24 - -/* - * Definition of type and code field values. - * Per https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xml - * Last Updated 2012-11-12 - */ - -/* Errors */ -#define ICMP6_UNREACH 1 /* Destination Unreachable */ -#define ICMP6_UNREACH_NO_ROUTE 0 /* no route to dest */ -#define ICMP6_UNREACH_DEST_PROHIB 1 /* com with dest prohibited */ -#define ICMP6_UNREACH_SCOPE 2 /* beyond scope of src addr */ -#define ICMP6_UNREACH_ADDRESS 3 /* address unreachable */ -#define ICMP6_UNREACH_PORT 4 /* port unreachable */ -#define ICMP6_UNREACH_SRC_FAIL 5 /* src addr failed */ -#define ICMP6_UNREACH_REJECT_ROUTE 6 /* reject route to dest */ -#define ICMP6_UNREACH_SRC_HDR_ERROR 7 /* error in src routing header */ -#define ICMP6_TOOBIG 2 /* Packet Too Big */ -#define ICMP6_TIMXCEED 3 /* Time Exceeded */ -#define ICMP6_TIMXCEED_INTRANS 0 /* hop limit exceeded in transit */ -#define ICMP6_TIMXCEED_REASS 1 /* ttl=0 in reass */ -#define ICMP6_PARAMPROB 4 /* Parameter Problem */ -#define ICMP6_PARAMPROB_HDR_FIELD 0 /* err header field */ -#define ICMP6_PARAMPROB_NXTHDR_TYPE 1 /* unrecognized Next Header type */ -#define ICMP6_PARAMPROB_IPV6_OPT 2 /* unrecognized IPv6 option */ - -/* Informational Messages */ -#define ICMP6_ECHO_REQUEST 128 /* Echo Request */ -#define ICMP6_ECHO_REPLY 129 /* Echo Reply */ -#define ICMP6_NDP_RS 133 /* Router Solicitation (NDP) */ -#define ICMP6_NDP_RA 134 /* Router Advertisement (NDP) */ -#define ICMP6_NDP_NS 135 /* Neighbor Solicitation (NDP) */ -#define ICMP6_NDP_NA 136 /* Neighbor Advertisement (NDP) */ -#define ICMP6_NDP_REDIRECT 137 /* Redirect Message (NDP) */ - -/* - * Router Configuration Variables (rfc4861#section-6) - */ -#define NDP_IsRouter 1 -#define NDP_AdvSendAdvertisements 1 -#define NDP_MaxRtrAdvInterval 600000 -#define NDP_MinRtrAdvInterval \ - ((NDP_MaxRtrAdvInterval >= 9) ? NDP_MaxRtrAdvInterval / 3 : \ - NDP_MaxRtrAdvInterval) -#define NDP_AdvManagedFlag 0 -#define NDP_AdvOtherConfigFlag 0 -#define NDP_AdvLinkMTU 0 -#define NDP_AdvReachableTime 0 -#define NDP_AdvRetransTime 0 -#define NDP_AdvCurHopLimit 64 -#define NDP_AdvDefaultLifetime ((3 * NDP_MaxRtrAdvInterval) / 1000) -#define NDP_AdvValidLifetime 86400 -#define NDP_AdvOnLinkFlag 1 -#define NDP_AdvPrefLifetime 14400 -#define NDP_AdvAutonomousFlag 1 - -void icmp6_post_init(Slirp *slirp); -void icmp6_cleanup(Slirp *slirp); -void icmp6_input(struct mbuf *); -void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src); -void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code); -void ndp_send_ns(Slirp *slirp, struct in6_addr addr); -void ra_timer_handler(Slirp *slirp, void *unused); - -#endif diff --git a/src/network/slirp/ip6_input.c b/src/network/slirp/ip6_input.c deleted file mode 100644 index 4aca08285..000000000 --- a/src/network/slirp/ip6_input.c +++ /dev/null @@ -1,88 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" -#include "ip6_icmp.h" - -/* - * IP initialization: fill in IP protocol switch table. - * All protocols not implemented in kernel go to raw IP protocol handler. - */ -void ip6_post_init(Slirp *slirp) -{ - icmp6_post_init(slirp); -} - -void ip6_cleanup(Slirp *slirp) -{ - icmp6_cleanup(slirp); -} - -void ip6_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - /* NDP reads the ethernet header for gratuitous NDP */ - M_DUP_DEBUG(slirp, m, 1, TCPIPHDR_DELTA + 2 + ETH_HLEN); - - struct ip6 *ip6; - - if (!slirp->in6_enabled) { - goto bad; - } - - DEBUG_CALL("ip6_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - if (m->m_len < sizeof(struct ip6)) { - goto bad; - } - - ip6 = mtod(m, struct ip6 *); - - if (ip6->ip_v != IP6VERSION) { - goto bad; - } - - if (ntohs(ip6->ip_pl) + sizeof(struct ip6) > slirp->if_mtu) { - icmp6_send_error(m, ICMP6_TOOBIG, 0); - goto bad; - } - - // Check if the message size is big enough to hold what's - // set in the payload length header. If not this is an invalid - // packet - if (m->m_len < ntohs(ip6->ip_pl) + sizeof(struct ip6)) { - goto bad; - } - - /* check ip_ttl for a correct ICMP reply */ - if (ip6->ip_hl == 0) { - icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS); - goto bad; - } - - /* - * Switch out to protocol's input routine. - */ - switch (ip6->ip_nh) { - case IPPROTO_TCP: - NTOHS(ip6->ip_pl); - tcp_input(m, sizeof(struct ip6), (struct socket *)NULL, AF_INET6); - break; - case IPPROTO_UDP: - udp6_input(m); - break; - case IPPROTO_ICMPV6: - icmp6_input(m); - break; - default: - m_free(m); - } - return; -bad: - m_free(m); -} diff --git a/src/network/slirp/ip6_output.c b/src/network/slirp/ip6_output.c deleted file mode 100644 index 834f1c0a3..000000000 --- a/src/network/slirp/ip6_output.c +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" - -/* Number of packets queued before we start sending - * (to prevent allocing too many mbufs) */ -#define IF6_THRESH 10 - -/* - * IPv6 output. The packet in mbuf chain m contains a IP header - */ -int ip6_output(struct socket *so, struct mbuf *m, int fast) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - struct ip6 *ip = mtod(m, struct ip6 *); - - DEBUG_CALL("ip6_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - /* Fill IPv6 header */ - ip->ip_v = IP6VERSION; - ip->ip_hl = IP6_HOP_LIMIT; - ip->ip_tc_hi = 0; - ip->ip_tc_lo = 0; - ip->ip_fl_hi = 0; - ip->ip_fl_lo = 0; - - if (fast) { - /* We cannot fast-send non-multicast, we'd need a NDP NS */ - assert(IN6_IS_ADDR_MULTICAST(&ip->ip_dst)); - if_encap(m->slirp, m); - m_free(m); - } else { - if_output(so, m); - } - - return 0; -} diff --git a/src/network/slirp/ip_icmp.c b/src/network/slirp/ip_icmp.c deleted file mode 100644 index 6ae523c69..000000000 --- a/src/network/slirp/ip_icmp.c +++ /dev/null @@ -1,541 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94 - * ip_icmp.c,v 1.7 1995/05/30 08:09:42 rgrimes Exp - */ - -#include "slirp.h" -#include "ip_icmp.h" - -#ifndef WITH_ICMP_ERROR_MSG -#define WITH_ICMP_ERROR_MSG 0 -#endif - -/* The message sent when emulating PING */ -/* Be nice and tell them it's just a pseudo-ping packet */ -static const char icmp_ping_msg[] = - "This is a pseudo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST " - "packets.\n"; - -/* list of actions for icmp_send_error() on RX of an icmp message */ -static const int icmp_flush[19] = { - /* ECHO REPLY (0) */ 0, - 1, - 1, - /* DEST UNREACH (3) */ 1, - /* SOURCE QUENCH (4)*/ 1, - /* REDIRECT (5) */ 1, - 1, - 1, - /* ECHO (8) */ 0, - /* ROUTERADVERT (9) */ 1, - /* ROUTERSOLICIT (10) */ 1, - /* TIME EXCEEDED (11) */ 1, - /* PARAMETER PROBLEM (12) */ 1, - /* TIMESTAMP (13) */ 0, - /* TIMESTAMP REPLY (14) */ 0, - /* INFO (15) */ 0, - /* INFO REPLY (16) */ 0, - /* ADDR MASK (17) */ 0, - /* ADDR MASK REPLY (18) */ 0 -}; - -void icmp_init(Slirp *slirp) -{ - slirp->icmp.so_next = slirp->icmp.so_prev = &slirp->icmp; - slirp->icmp_last_so = &slirp->icmp; -} - -void icmp_cleanup(Slirp *slirp) -{ - struct socket *so, *so_next; - - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so_next) { - so_next = so->so_next; - icmp_detach(so); - } -} - -static int icmp_send(struct socket *so, struct mbuf *m, int hlen) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - struct ip *ip = mtod(m, struct ip *); - struct sockaddr_in addr; - - /* - * The behavior of reading SOCK_DGRAM+IPPROTO_ICMP sockets is inconsistent - * between host OSes. On Linux, only the ICMP header and payload is - * included. On macOS/Darwin, the socket acts like a raw socket and - * includes the IP header as well. On other BSDs, SOCK_DGRAM+IPPROTO_ICMP - * sockets aren't supported at all, so we treat them like raw sockets. It - * isn't possible to detect this difference at runtime, so we must use an - * #ifdef to determine if we need to remove the IP header. - */ -#ifdef CONFIG_BSD - so->so_type = IPPROTO_IP; -#else - so->so_type = IPPROTO_ICMP; -#endif - - so->s = slirp_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); - if (so->s == -1) { - if (errno == EAFNOSUPPORT - || errno == EPROTONOSUPPORT - || errno == EACCES) { - /* Kernel doesn't support or allow ping sockets. */ - so->so_type = IPPROTO_IP; - so->s = slirp_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); - } - } - if (so->s == -1) { - return -1; - } - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - - if (slirp_bind_outbound(so, AF_INET) != 0) { - // bind failed - close socket - closesocket(so->s); - so->s = -1; - return -1; - } - - so->so_m = m; - so->so_faddr = ip->ip_dst; - so->so_laddr = ip->ip_src; - so->so_iptos = ip->ip_tos; - so->so_state = SS_ISFCONNECTED; - so->so_expire = curtime + SO_EXPIRE; - - addr.sin_family = AF_INET; - addr.sin_addr = so->so_faddr; - - slirp_insque(so, &so->slirp->icmp); - - if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0, - (struct sockaddr *)&addr, sizeof(addr)) == -1) { - DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s", errno, - strerror(errno)); - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); - icmp_detach(so); - } - - return 0; -} - -void icmp_detach(struct socket *so) -{ - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); -} - -/* - * Process a received ICMP message. - */ -void icmp_input(struct mbuf *m, int hlen) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - register struct icmp *icp; - register struct ip *ip = mtod(m, struct ip *); - int icmplen = ip->ip_len; - - DEBUG_CALL("icmp_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - /* - * Locate icmp structure in mbuf, and check - * that its not corrupted and of at least minimum length. - */ - if (icmplen < ICMP_MINLEN) { /* min 8 bytes payload */ - freeit: - m_free(m); - goto end_error; - } - - m->m_len -= hlen; - m->m_data += hlen; - icp = mtod(m, struct icmp *); - if (cksum(m, icmplen)) { - goto freeit; - } - m->m_len += hlen; - m->m_data -= hlen; - - DEBUG_ARG("icmp_type = %d", icp->icmp_type); - switch (icp->icmp_type) { - case ICMP_ECHO: - ip->ip_len += hlen; /* since ip_input subtracts this */ - if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr || - ip->ip_dst.s_addr == slirp->vnameserver_addr.s_addr) { - icmp_reflect(m); - } else if (slirp->restricted) { - goto freeit; - } else { - struct socket *so; - struct sockaddr_storage addr; - int ttl; - - so = socreate(slirp, IPPROTO_ICMP); - if (icmp_send(so, m, hlen) == 0) { - /* We could send this as ICMP, good! */ - return; - } - - /* We could not send this as ICMP, try to send it on UDP echo - * service (7), wishfully hoping that it is open there. */ - - if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC("icmp_input udp_attach errno = %d-%s", errno, - strerror(errno)); - sofree(so); - m_free(m); - goto end_error; - } - so->so_m = m; - so->so_ffamily = AF_INET; - so->so_faddr = ip->ip_dst; - so->so_fport = htons(7); - so->so_lfamily = AF_INET; - so->so_laddr = ip->ip_src; - so->so_lport = htons(9); - so->so_iptos = ip->ip_tos; - so->so_state = SS_ISFCONNECTED; - - /* Send the packet */ - addr = so->fhost.ss; - if (sotranslate_out(so, &addr) < 0) { - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, - strerror(errno)); - udp_detach(so); - return; - } - - /* - * Check for TTL - */ - ttl = ip->ip_ttl-1; - if (ttl <= 0) { - DEBUG_MISC("udp ttl exceeded"); - icmp_send_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, - NULL); - udp_detach(so); - break; - } - setsockopt(so->s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); - - if (sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0, - (struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) { - DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s", errno, - strerror(errno)); - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, - strerror(errno)); - udp_detach(so); - } - } /* if ip->ip_dst.s_addr == alias_addr.s_addr */ - break; - case ICMP_UNREACH: - /* XXX? report error? close socket? */ - case ICMP_TIMXCEED: - case ICMP_PARAMPROB: - case ICMP_SOURCEQUENCH: - case ICMP_TSTAMP: - case ICMP_MASKREQ: - case ICMP_REDIRECT: - m_free(m); - break; - - default: - m_free(m); - } /* switch */ - -end_error: - /* m is m_free()'d xor put in a socket xor or given to ip_send */ - return; -} - - -/* - * Send an ICMP message in response to a situation - * - * RFC 1122: 3.2.2 MUST send at least the IP header and 8 bytes of header. - *MAY send more (we do). MUST NOT change this header information. MUST NOT reply - *to a multicast/broadcast IP address. MUST NOT reply to a multicast/broadcast - *MAC address. MUST reply to only the first fragment. - */ -/* - * Send ICMP_UNREACH back to the source regarding msrc. - * mbuf *msrc is used as a template, but is NOT m_free()'d. - * It is reported as the bad ip packet. The header should - * be fully correct and in host byte order. - * ICMP fragmentation is illegal. All machines must accept 576 bytes in one - * packet. The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548 - */ - -#define ICMP_MAXDATALEN (IP_MSS - 28) -void icmp_forward_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message, struct in_addr *src) -{ - unsigned hlen, shlen, s_ip_len; - register struct ip *ip; - register struct icmp *icp; - register struct mbuf *m; - - DEBUG_CALL("icmp_send_error"); - DEBUG_ARG("msrc = %p", msrc); - DEBUG_ARG("msrc_len = %d", msrc->m_len); - - if (type != ICMP_UNREACH && type != ICMP_TIMXCEED) - goto end_error; - - /* check msrc */ - if (!msrc) - goto end_error; - ip = mtod(msrc, struct ip *); - if (slirp_debug & DBG_MISC) { - char addr_src[INET_ADDRSTRLEN]; - char addr_dst[INET_ADDRSTRLEN]; - - inet_ntop(AF_INET, &ip->ip_src, addr_src, sizeof(addr_src)); - inet_ntop(AF_INET, &ip->ip_dst, addr_dst, sizeof(addr_dst)); - DEBUG_MISC(" %.16s to %.16s", addr_src, addr_dst); - } - if (ip->ip_off & IP_OFFMASK) - goto end_error; /* Only reply to fragment 0 */ - - /* Do not reply to source-only IPs */ - if ((ip->ip_src.s_addr & htonl(~(0xf << 28))) == 0) { - goto end_error; - } - - shlen = ip->ip_hl << 2; - s_ip_len = ip->ip_len; - if (ip->ip_p == IPPROTO_ICMP) { - icp = (struct icmp *)((char *)ip + shlen); - /* - * Assume any unknown ICMP type is an error. This isn't - * specified by the RFC, but think about it.. - */ - if (icp->icmp_type > 18 || icmp_flush[icp->icmp_type]) - goto end_error; - } - - /* make a copy */ - m = m_get(msrc->slirp); - if (!m) { - goto end_error; - } - - { - int new_m_size; - new_m_size = - sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN; - if (new_m_size > m->m_size) - m_inc(m, new_m_size); - } - memcpy(m->m_data, msrc->m_data, msrc->m_len); - m->m_len = msrc->m_len; /* copy msrc to m */ - - /* make the header of the reply packet */ - ip = mtod(m, struct ip *); - hlen = sizeof(struct ip); /* no options in reply */ - - /* fill in icmp */ - m->m_data += hlen; - m->m_len -= hlen; - - icp = mtod(m, struct icmp *); - - if (minsize) - s_ip_len = shlen + ICMP_MINLEN; /* return header+8b only */ - else if (s_ip_len > ICMP_MAXDATALEN) /* maximum size */ - s_ip_len = ICMP_MAXDATALEN; - - m->m_len = ICMP_MINLEN + s_ip_len; /* 8 bytes ICMP header */ - - /* min. size = 8+sizeof(struct ip)+8 */ - - icp->icmp_type = type; - icp->icmp_code = code; - icp->icmp_id = 0; - icp->icmp_seq = 0; - - memcpy(&icp->icmp_ip, msrc->m_data, s_ip_len); /* report the ip packet */ - HTONS(icp->icmp_ip.ip_len); - HTONS(icp->icmp_ip.ip_id); - HTONS(icp->icmp_ip.ip_off); - - if (message && WITH_ICMP_ERROR_MSG) { /* append message to ICMP packet */ - int message_len; - char *cpnt; - message_len = strlen(message); - if (message_len > ICMP_MAXDATALEN) - message_len = ICMP_MAXDATALEN; - cpnt = (char *)m->m_data + m->m_len; - memcpy(cpnt, message, message_len); - m->m_len += message_len; - } - - icp->icmp_cksum = 0; - icp->icmp_cksum = cksum(m, m->m_len); - - m->m_data -= hlen; - m->m_len += hlen; - - /* fill in ip */ - ip->ip_hl = hlen >> 2; - ip->ip_len = m->m_len; - - ip->ip_tos = ((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */ - - ip->ip_ttl = MAXTTL; - ip->ip_p = IPPROTO_ICMP; - ip->ip_dst = ip->ip_src; /* ip addresses */ - ip->ip_src = *src; - - ip_output((struct socket *)NULL, m); - -end_error: - return; -} -#undef ICMP_MAXDATALEN - -void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message) -{ - icmp_forward_error(msrc, type, code, minsize, message, &msrc->slirp->vhost_addr); -} - -/* - * Reflect the ip packet back to the source - */ -void icmp_reflect(struct mbuf *m) -{ - register struct ip *ip = mtod(m, struct ip *); - int hlen = ip->ip_hl << 2; - int optlen = hlen - sizeof(struct ip); - register struct icmp *icp; - - /* - * Send an icmp packet back to the ip level, - * after supplying a checksum. - */ - m->m_data += hlen; - m->m_len -= hlen; - icp = mtod(m, struct icmp *); - - icp->icmp_type = ICMP_ECHOREPLY; - icp->icmp_cksum = 0; - icp->icmp_cksum = cksum(m, ip->ip_len - hlen); - - m->m_data -= hlen; - m->m_len += hlen; - - /* fill in ip */ - if (optlen > 0) { - /* - * Strip out original options by copying rest of first - * mbuf's data back, and adjust the IP length. - */ - memmove((char *)(ip + 1), (char *)ip + hlen, - (unsigned)(m->m_len - hlen)); - hlen -= optlen; - ip->ip_hl = hlen >> 2; - ip->ip_len -= optlen; - m->m_len -= optlen; - } - - ip->ip_ttl = MAXTTL; - { /* swap */ - struct in_addr icmp_dst; - icmp_dst = ip->ip_dst; - ip->ip_dst = ip->ip_src; - ip->ip_src = icmp_dst; - } - - ip_output((struct socket *)NULL, m); -} - -void icmp_receive(struct socket *so) -{ - struct mbuf *m = so->so_m; - struct ip *ip = mtod(m, struct ip *); - int hlen = ip->ip_hl << 2; - uint8_t error_code; - struct icmp *icp; - int id, len; - - m->m_data += hlen; - m->m_len -= hlen; - icp = mtod(m, struct icmp *); - - id = icp->icmp_id; - len = recv(so->s, icp, M_ROOM(m), 0); - - if (so->so_type == IPPROTO_IP) { - if (len >= sizeof(struct ip)) { - struct ip *inner_ip = mtod(m, struct ip *); - int inner_hlen = inner_ip->ip_hl << 2; - if (inner_hlen > len) { - len = -1; - errno = -EINVAL; - } else { - len -= inner_hlen; - memmove(icp, (unsigned char *)icp + inner_hlen, len); - } - } else { - len = -1; - errno = -EINVAL; - } - } - - icp->icmp_id = id; - - m->m_data -= hlen; - m->m_len += hlen; - - if (len == -1 || len == 0) { - if (errno == ENETUNREACH) { - error_code = ICMP_UNREACH_NET; - } else { - error_code = ICMP_UNREACH_HOST; - } - DEBUG_MISC(" udp icmp rx errno = %d-%s", errno, strerror(errno)); - icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno)); - } else { - icmp_reflect(so->so_m); - so->so_m = NULL; /* Don't m_free() it again! */ - } - icmp_detach(so); -} diff --git a/src/network/slirp/ip_icmp.h b/src/network/slirp/ip_icmp.h deleted file mode 100644 index 569a08306..000000000 --- a/src/network/slirp/ip_icmp.h +++ /dev/null @@ -1,168 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 - * ip_icmp.h,v 1.4 1995/05/30 08:09:43 rgrimes Exp - */ - -#ifndef NETINET_IP_ICMP_H -#define NETINET_IP_ICMP_H - -/* - * Interface Control Message Protocol Definitions. - * Per RFC 792, September 1981. - */ - -typedef uint32_t n_time; - -/* - * Structure of an icmp header. - */ -struct icmp { - uint8_t icmp_type; /* type of message, see below */ - uint8_t icmp_code; /* type sub code */ - uint16_t icmp_cksum; /* ones complement cksum of struct */ - union { - uint8_t ih_pptr; /* ICMP_PARAMPROB */ - struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ - struct ih_idseq { - uint16_t icd_id; - uint16_t icd_seq; - } ih_idseq; - int ih_void; - - /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ - struct ih_pmtu { - uint16_t ipm_void; - uint16_t ipm_nextmtu; - } ih_pmtu; - } icmp_hun; -#define icmp_pptr icmp_hun.ih_pptr -#define icmp_gwaddr icmp_hun.ih_gwaddr -#define icmp_id icmp_hun.ih_idseq.icd_id -#define icmp_seq icmp_hun.ih_idseq.icd_seq -#define icmp_void icmp_hun.ih_void -#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void -#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu - union { - struct id_ts { - n_time its_otime; - n_time its_rtime; - n_time its_ttime; - } id_ts; - struct id_ip { - struct ip idi_ip; - /* options and then 64 bits of data */ - } id_ip; - uint32_t id_mask; - char id_data[1]; - } icmp_dun; -#define icmp_otime icmp_dun.id_ts.its_otime -#define icmp_rtime icmp_dun.id_ts.its_rtime -#define icmp_ttime icmp_dun.id_ts.its_ttime -#define icmp_ip icmp_dun.id_ip.idi_ip -#define icmp_mask icmp_dun.id_mask -#define icmp_data icmp_dun.id_data -}; - -/* - * Lower bounds on packet lengths for various types. - * For the error advice packets must first ensure that the - * packet is large enough to contain the returned ip header. - * Only then can we do the check to see if 64 bits of packet - * data have been returned, since we need to check the returned - * ip header length. - */ -#define ICMP_MINLEN 8 /* abs minimum */ -#define ICMP_TSLEN (8 + 3 * sizeof(n_time)) /* timestamp */ -#define ICMP_MASKLEN 12 /* address mask */ -#define ICMP_ADVLENMIN (8 + sizeof(struct ip) + 8) /* min */ -#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) -/* N.B.: must separately check that ip_hl >= 5 */ - -/* - * Definition of type and code field values. - */ -#define ICMP_ECHOREPLY 0 /* echo reply */ -#define ICMP_UNREACH 3 /* dest unreachable, codes: */ -#define ICMP_UNREACH_NET 0 /* bad net */ -#define ICMP_UNREACH_HOST 1 /* bad host */ -#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ -#define ICMP_UNREACH_PORT 3 /* bad port */ -#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ -#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ -#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ -#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ -#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ -#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ -#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ -#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ -#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ -#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ -#define ICMP_REDIRECT 5 /* shorter route, codes: */ -#define ICMP_REDIRECT_NET 0 /* for network */ -#define ICMP_REDIRECT_HOST 1 /* for host */ -#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ -#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ -#define ICMP_ECHO 8 /* echo service */ -#define ICMP_ROUTERADVERT 9 /* router advertisement */ -#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ -#define ICMP_TIMXCEED 11 /* time exceeded, code: */ -#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ -#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ -#define ICMP_PARAMPROB 12 /* ip header bad */ -#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ -#define ICMP_TSTAMP 13 /* timestamp request */ -#define ICMP_TSTAMPREPLY 14 /* timestamp reply */ -#define ICMP_IREQ 15 /* information request */ -#define ICMP_IREQREPLY 16 /* information reply */ -#define ICMP_MASKREQ 17 /* address mask request */ -#define ICMP_MASKREPLY 18 /* address mask reply */ - -#define ICMP_MAXTYPE 18 - -#define ICMP_INFOTYPE(type) \ - ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ - (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ - (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ - (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ - (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) - -void icmp_init(Slirp *slirp); -void icmp_cleanup(Slirp *slirp); -void icmp_input(struct mbuf *, int); -void icmp_forward_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message, struct in_addr *src); -void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message); -void icmp_reflect(struct mbuf *); -void icmp_receive(struct socket *so); -void icmp_detach(struct socket *so); - -#endif diff --git a/src/network/slirp/ip_input.c b/src/network/slirp/ip_input.c deleted file mode 100644 index b0a64da19..000000000 --- a/src/network/slirp/ip_input.c +++ /dev/null @@ -1,464 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 - * ip_input.c,v 1.11 1994/11/16 10:17:08 jkh Exp - */ - -/* - * Changes and additions relating to SLiRP are - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include "ip_icmp.h" -#include - -static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp); -static void ip_freef(Slirp *slirp, struct ipq *fp); -static void ip_enq(register struct ipasfrag *p, register struct ipasfrag *prev); -static void ip_deq(register struct ipasfrag *p); - -/* - * IP initialization: fill in IP protocol switch table. - * All protocols not implemented in kernel go to raw IP protocol handler. - */ -void ip_init(Slirp *slirp) -{ - slirp->ipq.ip_link.next = slirp->ipq.ip_link.prev = &slirp->ipq.ip_link; - udp_init(slirp); - tcp_init(slirp); - icmp_init(slirp); -} - -void ip_cleanup(Slirp *slirp) -{ - udp_cleanup(slirp); - tcp_cleanup(slirp); - icmp_cleanup(slirp); -} - -/* - * Ip input routine. Checksum and byte swap header. If fragmented - * try to reassemble. Process options. Pass to next level. - */ -void ip_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, TCPIPHDR_DELTA); - - register struct ip *ip; - int hlen; - - if (!slirp->in_enabled) { - goto bad; - } - - DEBUG_CALL("ip_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - if (m->m_len < sizeof(struct ip)) { - goto bad; - } - - ip = mtod(m, struct ip *); - - if (ip->ip_v != IPVERSION) { - goto bad; - } - - hlen = ip->ip_hl << 2; - if (hlen < sizeof(struct ip) || hlen > m->m_len) { /* min header length */ - goto bad; /* or packet too short */ - } - - /* keep ip header intact for ICMP reply - * ip->ip_sum = cksum(m, hlen); - * if (ip->ip_sum) { - */ - if (cksum(m, hlen)) { - goto bad; - } - - /* - * Convert fields to host representation. - */ - NTOHS(ip->ip_len); - if (ip->ip_len < hlen) { - goto bad; - } - NTOHS(ip->ip_id); - NTOHS(ip->ip_off); - - /* - * Check that the amount of data in the buffers - * is as at least much as the IP header would have us expect. - * Trim mbufs if longer than we expect. - * Drop packet if shorter than we expect. - */ - if (m->m_len < ip->ip_len) { - goto bad; - } - - /* Should drop packet if mbuf too long? hmmm... */ - if (m->m_len > ip->ip_len) - m_adj(m, ip->ip_len - m->m_len); - - /* check ip_ttl for a correct ICMP reply */ - if (ip->ip_ttl == 0) { - icmp_send_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, "ttl"); - goto bad; - } - - /* - * If offset or IP_MF are set, must reassemble. - * Otherwise, nothing need be done. - * (We could look in the reassembly queue to see - * if the packet was previously fragmented, - * but it's not worth the time; just let them time out.) - * - * XXX This should fail, don't fragment yet - */ - if (ip->ip_off & ~IP_DF) { - register struct ipq *fp; - struct qlink *l; - /* - * Look for queue of fragments - * of this datagram. - */ - for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link; - l = l->next) { - fp = container_of(l, struct ipq, ip_link); - if (ip->ip_id == fp->ipq_id && - ip->ip_src.s_addr == fp->ipq_src.s_addr && - ip->ip_dst.s_addr == fp->ipq_dst.s_addr && - ip->ip_p == fp->ipq_p) - goto found; - } - fp = NULL; - found: - - /* - * Adjust ip_len to not reflect header, - * set ip_mff if more fragments are expected, - * convert offset of this to bytes. - */ - ip->ip_len -= hlen; - if (ip->ip_off & IP_MF) - ip->ip_tos |= 1; - else - ip->ip_tos &= ~1; - - ip->ip_off <<= 3; - - /* - * If datagram marked as having more fragments - * or if this is not the first fragment, - * attempt reassembly; if it succeeds, proceed. - */ - if (ip->ip_tos & 1 || ip->ip_off) { - ip = ip_reass(slirp, ip, fp); - if (ip == NULL) - return; - m = dtom(slirp, ip); - } else if (fp) - ip_freef(slirp, fp); - - } else - ip->ip_len -= hlen; - - /* - * Switch out to protocol's input routine. - */ - switch (ip->ip_p) { - case IPPROTO_TCP: - tcp_input(m, hlen, (struct socket *)NULL, AF_INET); - break; - case IPPROTO_UDP: - udp_input(m, hlen); - break; - case IPPROTO_ICMP: - icmp_input(m, hlen); - break; - default: - m_free(m); - } - return; -bad: - m_free(m); -} - -#define iptofrag(P) ((struct ipasfrag *)(((char *)(P)) - sizeof(struct qlink))) -#define fragtoip(P) ((struct ip *)(((char *)(P)) + sizeof(struct qlink))) -/* - * Take incoming datagram fragment and try to - * reassemble it into whole datagram. If a chain for - * reassembly of this datagram already exists, then it - * is given as fp; otherwise have to make a chain. - */ -static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp) -{ - register struct mbuf *m = dtom(slirp, ip); - register struct ipasfrag *q; - int hlen = ip->ip_hl << 2; - int i, next; - - DEBUG_CALL("ip_reass"); - DEBUG_ARG("ip = %p", ip); - DEBUG_ARG("fp = %p", fp); - DEBUG_ARG("m = %p", m); - - /* - * Presence of header sizes in mbufs - * would confuse code below. - * Fragment m_data is concatenated. - */ - m->m_data += hlen; - m->m_len -= hlen; - - /* - * If first fragment to arrive, create a reassembly queue. - */ - if (fp == NULL) { - struct mbuf *t = m_get(slirp); - - if (t == NULL) { - goto dropfrag; - } - fp = mtod(t, struct ipq *); - slirp_insque(&fp->ip_link, &slirp->ipq.ip_link); - fp->ipq_ttl = IPFRAGTTL; - fp->ipq_p = ip->ip_p; - fp->ipq_id = ip->ip_id; - fp->frag_link.next = fp->frag_link.prev = &fp->frag_link; - fp->ipq_src = ip->ip_src; - fp->ipq_dst = ip->ip_dst; - q = (struct ipasfrag *)fp; - goto insert; - } - - /* - * Find a segment which begins after this one does. - */ - for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link; - q = q->ipf_next) - if (q->ipf_off > ip->ip_off) - break; - - /* - * If there is a preceding segment, it may provide some of - * our data already. If so, drop the data from the incoming - * segment. If it provides all of our data, drop us. - */ - if (q->ipf_prev != &fp->frag_link) { - struct ipasfrag *pq = q->ipf_prev; - i = pq->ipf_off + pq->ipf_len - ip->ip_off; - if (i > 0) { - if (i >= ip->ip_len) - goto dropfrag; - m_adj(dtom(slirp, ip), i); - ip->ip_off += i; - ip->ip_len -= i; - } - } - - /* - * While we overlap succeeding segments trim them or, - * if they are completely covered, dequeue them. - */ - while (q != (struct ipasfrag *)&fp->frag_link && - ip->ip_off + ip->ip_len > q->ipf_off) { - struct ipasfrag *prev; - i = (ip->ip_off + ip->ip_len) - q->ipf_off; - if (i < q->ipf_len) { - q->ipf_len -= i; - q->ipf_off += i; - m_adj(dtom(slirp, q), i); - break; - } - prev = q; - q = q->ipf_next; - ip_deq(prev); - m_free(dtom(slirp, prev)); - } - -insert: - /* - * Stick new segment in its place; - * check for complete reassembly. - */ - ip_enq(iptofrag(ip), q->ipf_prev); - next = 0; - for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link; - q = q->ipf_next) { - if (q->ipf_off != next) - return NULL; - next += q->ipf_len; - } - if (((struct ipasfrag *)(q->ipf_prev))->ipf_tos & 1) - return NULL; - - /* - * Reassembly is complete; concatenate fragments. - */ - q = fp->frag_link.next; - m = dtom(slirp, q); - int delta = (char *)q - (m->m_flags & M_EXT ? m->m_ext : m->m_dat); - - q = (struct ipasfrag *)q->ipf_next; - while (q != (struct ipasfrag *)&fp->frag_link) { - struct mbuf *t = dtom(slirp, q); - q = (struct ipasfrag *)q->ipf_next; - m_cat(m, t); - } - - /* - * Create header for new ip packet by - * modifying header of first packet; - * dequeue and discard fragment reassembly header. - * Make header visible. - */ - q = fp->frag_link.next; - - /* - * If the fragments concatenated to an mbuf that's bigger than the total - * size of the fragment and the mbuf was not already using an m_ext buffer, - * then an m_ext buffer was allocated. But fp->ipq_next points to the old - * buffer (in the mbuf), so we must point ip into the new buffer. - */ - if (m->m_flags & M_EXT) { - q = (struct ipasfrag *)(m->m_ext + delta); - } - - ip = fragtoip(q); - ip->ip_len = next; - ip->ip_tos &= ~1; - ip->ip_src = fp->ipq_src; - ip->ip_dst = fp->ipq_dst; - slirp_remque(&fp->ip_link); - m_free(dtom(slirp, fp)); - m->m_len += (ip->ip_hl << 2); - m->m_data -= (ip->ip_hl << 2); - - return ip; - -dropfrag: - m_free(m); - return NULL; -} - -/* - * Free a fragment reassembly header and all - * associated datagrams. - */ -static void ip_freef(Slirp *slirp, struct ipq *fp) -{ - register struct ipasfrag *q, *p; - - for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link; - q = p) { - p = q->ipf_next; - ip_deq(q); - m_free(dtom(slirp, q)); - } - slirp_remque(&fp->ip_link); - m_free(dtom(slirp, fp)); -} - -/* - * Put an ip fragment on a reassembly chain. - * Like slirp_insque, but pointers in middle of structure. - */ -static void ip_enq(register struct ipasfrag *p, register struct ipasfrag *prev) -{ - DEBUG_CALL("ip_enq"); - DEBUG_ARG("prev = %p", prev); - p->ipf_prev = prev; - p->ipf_next = prev->ipf_next; - ((struct ipasfrag *)(prev->ipf_next))->ipf_prev = p; - prev->ipf_next = p; -} - -/* - * To ip_enq as slirp_remque is to slirp_insque. - */ -static void ip_deq(register struct ipasfrag *p) -{ - ((struct ipasfrag *)(p->ipf_prev))->ipf_next = p->ipf_next; - ((struct ipasfrag *)(p->ipf_next))->ipf_prev = p->ipf_prev; -} - -/* - * IP timer processing; - * if a timer expires on a reassembly - * queue, discard it. - */ -void ip_slowtimo(Slirp *slirp) -{ - struct qlink *l; - - DEBUG_CALL("ip_slowtimo"); - - l = slirp->ipq.ip_link.next; - - if (l == NULL) - return; - - while (l != &slirp->ipq.ip_link) { - struct ipq *fp = container_of(l, struct ipq, ip_link); - l = l->next; - if (--fp->ipq_ttl == 0) { - ip_freef(slirp, fp); - } - } -} - -/* - * Strip out IP options, at higher - * level protocol in the kernel. - * Second argument is buffer to which options - * will be moved, and return value is their length. - * (XXX) should be deleted; last arg currently ignored. - */ -void ip_stripoptions(register struct mbuf *m, struct mbuf *mopt) -{ - register int i; - struct ip *ip = mtod(m, struct ip *); - register char *opts; - int olen; - - olen = (ip->ip_hl << 2) - sizeof(struct ip); - opts = (char *)(ip + 1); - i = m->m_len - (sizeof(struct ip) + olen); - memmove(opts, opts + olen, (unsigned)i); - m->m_len -= olen; - - ip->ip_hl = sizeof(struct ip) >> 2; -} diff --git a/src/network/slirp/ip_output.c b/src/network/slirp/ip_output.c deleted file mode 100644 index 4f6260591..000000000 --- a/src/network/slirp/ip_output.c +++ /dev/null @@ -1,171 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 - * ip_output.c,v 1.9 1994/11/16 10:17:10 jkh Exp - */ - -/* - * Changes and additions relating to SLiRP are - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -/* Number of packets queued before we start sending - * (to prevent allocing too many mbufs) */ -#define IF_THRESH 10 - -/* - * IP output. The packet in mbuf chain m contains a skeletal IP - * header (with len, off, ttl, proto, tos, src, dst). - * The mbuf chain containing the packet will be freed. - * The mbuf opt, if present, will not be freed. - */ -int ip_output(struct socket *so, struct mbuf *m0) -{ - Slirp *slirp = m0->slirp; - M_DUP_DEBUG(slirp, m0, 0, 0); - - register struct ip *ip; - register struct mbuf *m = m0; - register int hlen = sizeof(struct ip); - int len, off, error = 0; - - DEBUG_CALL("ip_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m0 = %p", m0); - - ip = mtod(m, struct ip *); - /* - * Fill in IP header. - */ - ip->ip_v = IPVERSION; - ip->ip_off &= IP_DF; - ip->ip_id = htons(slirp->ip_id++); - ip->ip_hl = hlen >> 2; - - /* - * If small enough for interface, can just send directly. - */ - if ((uint16_t)ip->ip_len <= slirp->if_mtu) { - ip->ip_len = htons((uint16_t)ip->ip_len); - ip->ip_off = htons((uint16_t)ip->ip_off); - ip->ip_sum = 0; - ip->ip_sum = cksum(m, hlen); - - if_output(so, m); - goto done; - } - - /* - * Too large for interface; fragment if possible. - * Must be able to put at least 8 bytes per fragment. - */ - if (ip->ip_off & IP_DF) { - error = -1; - goto bad; - } - - len = (slirp->if_mtu - hlen) & ~7; /* ip databytes per packet */ - if (len < 8) { - error = -1; - goto bad; - } - - { - int mhlen, firstlen = len; - struct mbuf **mnext = &m->m_nextpkt; - - /* - * Loop through length of segment after first fragment, - * make new header and copy data of each part and link onto chain. - */ - m0 = m; - mhlen = sizeof(struct ip); - for (off = hlen + len; off < (uint16_t)ip->ip_len; off += len) { - register struct ip *mhip; - m = m_get(slirp); - if (m == NULL) { - error = -1; - goto sendorfree; - } - m->m_data += IF_MAXLINKHDR; - mhip = mtod(m, struct ip *); - *mhip = *ip; - - m->m_len = mhlen; - mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF); - if (ip->ip_off & IP_MF) - mhip->ip_off |= IP_MF; - if (off + len >= (uint16_t)ip->ip_len) - len = (uint16_t)ip->ip_len - off; - else - mhip->ip_off |= IP_MF; - mhip->ip_len = htons((uint16_t)(len + mhlen)); - - if (m_copy(m, m0, off, len) < 0) { - error = -1; - goto sendorfree; - } - - mhip->ip_off = htons((uint16_t)mhip->ip_off); - mhip->ip_sum = 0; - mhip->ip_sum = cksum(m, mhlen); - *mnext = m; - mnext = &m->m_nextpkt; - } - /* - * Update first fragment by trimming what's been copied out - * and updating header, then send each fragment (in order). - */ - m = m0; - m_adj(m, hlen + firstlen - (uint16_t)ip->ip_len); - ip->ip_len = htons((uint16_t)m->m_len); - ip->ip_off = htons((uint16_t)(ip->ip_off | IP_MF)); - ip->ip_sum = 0; - ip->ip_sum = cksum(m, hlen); - sendorfree: - for (m = m0; m; m = m0) { - m0 = m->m_nextpkt; - m->m_nextpkt = NULL; - if (error == 0) - if_output(so, m); - else - m_free(m); - } - } - -done: - return (error); - -bad: - m_free(m0); - goto done; -} diff --git a/src/network/slirp/libslirp-version.h b/src/network/slirp/libslirp-version.h deleted file mode 100644 index b68906957..000000000 --- a/src/network/slirp/libslirp-version.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef LIBSLIRP_VERSION_H_ -#define LIBSLIRP_VERSION_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#define SLIRP_MAJOR_VERSION 4 -#define SLIRP_MINOR_VERSION 7 -#define SLIRP_MICRO_VERSION 0 -#define SLIRP_VERSION_STRING "4.7.0-86Box" - -#define SLIRP_CHECK_VERSION(major,minor,micro) \ - (SLIRP_MAJOR_VERSION > (major) || \ - (SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION > (minor)) || \ - (SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION == (minor) && \ - SLIRP_MICRO_VERSION >= (micro))) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* LIBSLIRP_VERSION_H_ */ diff --git a/src/network/slirp/libslirp.h b/src/network/slirp/libslirp.h deleted file mode 100644 index 7a6c9a4da..000000000 --- a/src/network/slirp/libslirp.h +++ /dev/null @@ -1,273 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef LIBSLIRP_H -#define LIBSLIRP_H - -#include -#include -#include - -#ifdef _WIN32 -#include -#include -#include -#else -#include -#include -#endif - -#include "libslirp-version.h" - -/* Windows does not define ssize_t, so we need to define it here. */ -#ifndef _SSIZE_T_DEFINED -# define _SSIZE_T_DEFINED -# undef ssize_t -# ifdef _WIN64 -# define ssize_t int64_t -# else -# define ssize_t int32_t -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Opaque structure containing the slirp state */ -typedef struct Slirp Slirp; - -/* Flags passed to SlirpAddPollCb and to be returned by SlirpGetREventsCb. */ -enum { - SLIRP_POLL_IN = 1 << 0, - SLIRP_POLL_OUT = 1 << 1, - SLIRP_POLL_PRI = 1 << 2, - SLIRP_POLL_ERR = 1 << 3, - SLIRP_POLL_HUP = 1 << 4, -}; - -typedef ssize_t (*SlirpReadCb)(void *buf, size_t len, void *opaque); -typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); -typedef void (*SlirpTimerCb)(void *opaque); -typedef int (*SlirpAddPollCb)(int fd, int events, void *opaque); -typedef int (*SlirpGetREventsCb)(int idx, void *opaque); - -typedef enum SlirpTimerId { - SLIRP_TIMER_RA, - SLIRP_TIMER_NUM, -} SlirpTimerId; - -/* - * Callbacks from slirp, to be set by the application. - * - * The opaque parameter is set to the opaque pointer given in the slirp_new / - * slirp_init call. - */ -typedef struct SlirpCb { - /* - * Send an ethernet frame to the guest network. The opaque parameter is the - * one given to slirp_init(). If the guest is not ready to receive a frame, - * the function can just drop the data. TCP will then handle retransmissions - * at a lower pace. - * <0 reports an IO error. - */ - SlirpWriteCb send_packet; - /* Print a message for an error due to guest misbehavior. */ - void (*guest_error)(const char *msg, void *opaque); - /* Return the virtual clock value in nanoseconds */ - int64_t (*clock_get_ns)(void *opaque); - /* Create a new timer with the given callback and opaque data. Not - * needed if timer_new_opaque is provided. */ - void *(*timer_new)(SlirpTimerCb cb, void *cb_opaque, void *opaque); - /* Remove and free a timer */ - void (*timer_free)(void *timer, void *opaque); - /* Modify a timer to expire at @expire_time (ms) */ - void (*timer_mod)(void *timer, int64_t expire_time, void *opaque); - /* Register a fd for future polling */ - void (*register_poll_fd)(int fd, void *opaque); - /* Unregister a fd */ - void (*unregister_poll_fd)(int fd, void *opaque); - /* Kick the io-thread, to signal that new events may be processed because some TCP buffer - * can now receive more data, i.e. slirp_socket_can_recv will return 1. */ - void (*notify)(void *opaque); - - /* - * Fields introduced in SlirpConfig version 4 begin - */ - - /* Initialization has completed and a Slirp* has been created. */ - void (*init_completed)(Slirp *slirp, void *opaque); - /* Create a new timer. When the timer fires, the application passes - * the SlirpTimerId and cb_opaque to slirp_handle_timer. */ - void *(*timer_new_opaque)(SlirpTimerId id, void *cb_opaque, void *opaque); -} SlirpCb; - -#define SLIRP_CONFIG_VERSION_MIN 1 -#define SLIRP_CONFIG_VERSION_MAX 4 - -typedef struct SlirpConfig { - /* Version must be provided */ - uint32_t version; - /* - * Fields introduced in SlirpConfig version 1 begin - */ - int restricted; - bool in_enabled; - struct in_addr vnetwork; - struct in_addr vnetmask; - struct in_addr vhost; - bool in6_enabled; - struct in6_addr vprefix_addr6; - uint8_t vprefix_len; - struct in6_addr vhost6; - const char *vhostname; - const char *tftp_server_name; - const char *tftp_path; - const char *bootfile; - struct in_addr vdhcp_start; - struct in_addr vnameserver; - struct in6_addr vnameserver6; - const char **vdnssearch; - const char *vdomainname; - /* Default: IF_MTU_DEFAULT */ - size_t if_mtu; - /* Default: IF_MRU_DEFAULT */ - size_t if_mru; - /* Prohibit connecting to 127.0.0.1:* */ - bool disable_host_loopback; - /* - * Enable emulation code (*warning*: this code isn't safe, it is not - * recommended to enable it) - */ - bool enable_emu; - /* - * Fields introduced in SlirpConfig version 2 begin - */ - struct sockaddr_in *outbound_addr; - struct sockaddr_in6 *outbound_addr6; - /* - * Fields introduced in SlirpConfig version 3 begin - */ - bool disable_dns; /* slirp will not redirect/serve any DNS packet */ - /* - * Fields introduced in SlirpConfig version 4 begin - */ - bool disable_dhcp; /* slirp will not reply to any DHCP requests */ -} SlirpConfig; - -/* Create a new instance of a slirp stack */ -Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, - void *opaque); -/* slirp_init is deprecated in favor of slirp_new */ -Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, - struct in_addr vnetmask, struct in_addr vhost, - bool in6_enabled, struct in6_addr vprefix_addr6, - uint8_t vprefix_len, struct in6_addr vhost6, - const char *vhostname, const char *tftp_server_name, - const char *tftp_path, const char *bootfile, - struct in_addr vdhcp_start, struct in_addr vnameserver, - struct in6_addr vnameserver6, const char **vdnssearch, - const char *vdomainname, const SlirpCb *callbacks, - void *opaque); -/* Shut down an instance of a slirp stack */ -void slirp_cleanup(Slirp *slirp); - -/* This is called by the application when it is about to sleep through poll(). - * *timeout is set to the amount of virtual time (in ms) that the application intends to - * wait (UINT32_MAX if infinite). slirp_pollfds_fill updates it according to - * e.g. TCP timers, so the application knows it should sleep a smaller amount of - * time. slirp_pollfds_fill calls add_poll for each file descriptor - * that should be monitored along the sleep. The opaque pointer is passed as - * such to add_poll, and add_poll returns an index. */ -void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout, - SlirpAddPollCb add_poll, void *opaque); - -/* This is called by the application after sleeping, to report which file - * descriptors are available. slirp_pollfds_poll calls get_revents on each file - * descriptor, giving it the index that add_poll returned during the - * slirp_pollfds_fill call, to know whether the descriptor is available for - * read/write/etc. (SLIRP_POLL_*) - * select_error should be passed 1 if poll() returned an error. */ -void slirp_pollfds_poll(Slirp *slirp, int select_error, - SlirpGetREventsCb get_revents, void *opaque); - -/* This is called by the application when the guest emits a packet on the - * guest network, to be interpreted by slirp. */ -void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); - -/* This is called by the application when a timer expires, if it provides - * the timer_new_opaque callback. It is not needed if the application only - * uses timer_new. */ -void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque); - -/* These set up / remove port forwarding between a host port in the real world - * and the guest network. */ -int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port, struct in_addr guest_addr, int guest_port); -int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port); - -#define SLIRP_HOSTFWD_UDP 1 -#define SLIRP_HOSTFWD_V6ONLY 2 -int slirp_add_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *gaddr, socklen_t gaddrlen, - int flags); -int slirp_remove_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - int flags); - -/* Set up port forwarding between a port in the guest network and a - * command running on the host */ -int slirp_add_exec(Slirp *slirp, const char *cmdline, - struct in_addr *guest_addr, int guest_port); -/* Set up port forwarding between a port in the guest network and a - * Unix port on the host */ -int slirp_add_unix(Slirp *slirp, const char *unixsock, - struct in_addr *guest_addr, int guest_port); -/* Set up port forwarding between a port in the guest network and a - * callback that will receive the data coming from the port */ -int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque, - struct in_addr *guest_addr, int guest_port); - -/* TODO: rather identify a guestfwd through an opaque pointer instead of through - * the guest_addr */ - -/* This is called by the application for a guestfwd, to determine how much data - * can be received by the forwarded port through a call to slirp_socket_recv. */ -size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr, - int guest_port); -/* This is called by the application for a guestfwd, to provide the data to be - * sent on the forwarded port */ -void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, - const uint8_t *buf, int size); - -/* Remove entries added by slirp_add_exec, slirp_add_unix or slirp_add_guestfwd */ -int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr, - int guest_port); - -/* Return a human-readable state of the slirp stack */ -char *slirp_connection_info(Slirp *slirp); - -/* Return a human-readable state of the NDP/ARP tables */ -char *slirp_neighbor_info(Slirp *slirp); - -/* Save the slirp state through the write_cb. The opaque pointer is passed as - * such to the write_cb. */ -void slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque); - -/* Returns the version of the slirp state, to be saved along the state */ -int slirp_state_version(void); - -/* Load the slirp state through the read_cb. The opaque pointer is passed as - * such to the read_cb. The version should be given as it was obtained from - * slirp_state_version when slirp_state_save was called. */ -int slirp_state_load(Slirp *s, int version_id, SlirpReadCb read_cb, - void *opaque); - -/* Return the version of the slirp implementation */ -const char *slirp_version_string(void); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* LIBSLIRP_H */ diff --git a/src/network/slirp/main.h b/src/network/slirp/main.h deleted file mode 100644 index 3b3f88370..000000000 --- a/src/network/slirp/main.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef SLIRP_MAIN_H -#define SLIRP_MAIN_H - -extern unsigned curtime; -extern struct in_addr loopback_addr; -extern unsigned long loopback_mask; - -int if_encap(Slirp *slirp, struct mbuf *ifm); -ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags); - -#endif diff --git a/src/network/slirp/mbuf.c b/src/network/slirp/mbuf.c deleted file mode 100644 index 153b36c03..000000000 --- a/src/network/slirp/mbuf.c +++ /dev/null @@ -1,282 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski - */ - -/* - * mbuf's in SLiRP are much simpler than the real mbufs in - * FreeBSD. They are fixed size, determined by the MTU, - * so that one whole packet can fit. Mbuf's cannot be - * chained together. If there's more data than the mbuf - * could hold, an external g_malloced buffer is pointed to - * by m_ext (and the data pointers) and M_EXT is set in - * the flags - */ - -#include "slirp.h" -#include - -#define MBUF_THRESH 30 - -/* - * Find a nice value for msize - */ -#define SLIRP_MSIZE(mtu) \ - (offsetof(struct mbuf, m_dat) + IF_MAXLINKHDR + TCPIPHDR_DELTA + (mtu)) - -void m_init(Slirp *slirp) -{ - slirp->m_freelist.qh_link = slirp->m_freelist.qh_rlink = &slirp->m_freelist; - slirp->m_usedlist.qh_link = slirp->m_usedlist.qh_rlink = &slirp->m_usedlist; -} - -static void m_cleanup_list(struct slirp_quehead *list_head) -{ - struct mbuf *m, *next; - - m = (struct mbuf *)list_head->qh_link; - while ((struct slirp_quehead *)m != list_head) { - next = m->m_next; - if (m->m_flags & M_EXT) { - g_free(m->m_ext); - } - g_free(m); - m = next; - } - list_head->qh_link = list_head; - list_head->qh_rlink = list_head; -} - -void m_cleanup(Slirp *slirp) -{ - m_cleanup_list(&slirp->m_usedlist); - m_cleanup_list(&slirp->m_freelist); - m_cleanup_list(&slirp->if_batchq); - m_cleanup_list(&slirp->if_fastq); -} - -/* - * Get an mbuf from the free list, if there are none - * allocate one - * - * Because fragmentation can occur if we alloc new mbufs and - * free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE, - * which tells m_free to actually g_free() it - */ -struct mbuf *m_get(Slirp *slirp) -{ - register struct mbuf *m; - int flags = 0; - - DEBUG_CALL("m_get"); - - if (MBUF_DEBUG || slirp->m_freelist.qh_link == &slirp->m_freelist) { - m = g_malloc(SLIRP_MSIZE(slirp->if_mtu)); - slirp->mbuf_alloced++; - if (MBUF_DEBUG || slirp->mbuf_alloced > MBUF_THRESH) - flags = M_DOFREE; - m->slirp = slirp; - } else { - m = (struct mbuf *)slirp->m_freelist.qh_link; - slirp_remque(m); - } - - /* Insert it in the used list */ - slirp_insque(m, &slirp->m_usedlist); - m->m_flags = (flags | M_USEDLIST); - - /* Initialise it */ - m->m_size = SLIRP_MSIZE(slirp->if_mtu) - offsetof(struct mbuf, m_dat); - m->m_data = m->m_dat; - m->m_len = 0; - m->m_nextpkt = NULL; - m->m_prevpkt = NULL; - m->resolution_requested = false; - m->expiration_date = (uint64_t)-1; - DEBUG_ARG("m = %p", m); - return m; -} - -void m_free(struct mbuf *m) -{ - DEBUG_CALL("m_free"); - DEBUG_ARG("m = %p", m); - - if (m) { - /* Remove from m_usedlist */ - if (m->m_flags & M_USEDLIST) - slirp_remque(m); - - /* If it's M_EXT, free() it */ - if (m->m_flags & M_EXT) { - g_free(m->m_ext); - m->m_flags &= ~M_EXT; - } - /* - * Either free() it or put it on the free list - */ - if (m->m_flags & M_DOFREE) { - m->slirp->mbuf_alloced--; - g_free(m); - } else if ((m->m_flags & M_FREELIST) == 0) { - slirp_insque(m, &m->slirp->m_freelist); - m->m_flags = M_FREELIST; /* Clobber other flags */ - } - } /* if(m) */ -} - -/* - * Copy data from one mbuf to the end of - * the other.. if result is too big for one mbuf, allocate - * an M_EXT data segment - */ -void m_cat(struct mbuf *m, struct mbuf *n) -{ - /* - * If there's no room, realloc - */ - if (M_FREEROOM(m) < n->m_len) - m_inc(m, m->m_len + n->m_len); - - memcpy(m->m_data + m->m_len, n->m_data, n->m_len); - m->m_len += n->m_len; - - m_free(n); -} - - -/* make m 'size' bytes large from m_data */ -void m_inc(struct mbuf *m, int size) -{ - int gapsize; - - /* some compilers throw up on gotos. This one we can fake. */ - if (M_ROOM(m) > size) { - return; - } - - if (m->m_flags & M_EXT) { - gapsize = m->m_data - m->m_ext; - m->m_ext = g_realloc(m->m_ext, size + gapsize); - } else { - gapsize = m->m_data - m->m_dat; - m->m_ext = g_malloc(size + gapsize); - memcpy(m->m_ext, m->m_dat, m->m_size); - m->m_flags |= M_EXT; - } - - m->m_data = m->m_ext + gapsize; - m->m_size = size + gapsize; -} - - -void m_adj(struct mbuf *m, int len) -{ - if (m == NULL) - return; - if (len >= 0) { - /* Trim from head */ - m->m_data += len; - m->m_len -= len; - } else { - /* Trim from tail */ - len = -len; - m->m_len -= len; - } -} - - -/* - * Copy len bytes from m, starting off bytes into n - */ -int m_copy(struct mbuf *n, struct mbuf *m, int off, int len) -{ - if (len > M_FREEROOM(n)) - return -1; - - memcpy((n->m_data + n->m_len), (m->m_data + off), len); - n->m_len += len; - return 0; -} - - -/* - * Given a pointer into an mbuf, return the mbuf - * XXX This is a kludge, I should eliminate the need for it - * Fortunately, it's not used often - */ -struct mbuf *dtom(Slirp *slirp, void *dat) -{ - struct mbuf *m; - - DEBUG_CALL("dtom"); - DEBUG_ARG("dat = %p", dat); - - /* bug corrected for M_EXT buffers */ - for (m = (struct mbuf *)slirp->m_usedlist.qh_link; - (struct slirp_quehead *)m != &slirp->m_usedlist; m = m->m_next) { - if (m->m_flags & M_EXT) { - if ((char *)dat >= m->m_ext && (char *)dat < (m->m_ext + m->m_size)) - return m; - } else { - if ((char *)dat >= m->m_dat && (char *)dat < (m->m_dat + m->m_size)) - return m; - } - } - - DEBUG_ERROR("dtom failed"); - - return (struct mbuf *)0; -} - -/* - * Duplicate the mbuf - * - * copy_header specifies whether the bytes before m_data should also be copied. - * header_size specifies how many bytes are to be reserved before m_data. - */ -struct mbuf *m_dup(Slirp *slirp, struct mbuf *m, - bool copy_header, - size_t header_size) -{ - struct mbuf *n; - int mcopy_result; - - /* The previous mbuf was supposed to have it already, we can check it along - * the way */ - assert(M_ROOMBEFORE(m) >= header_size); - - n = m_get(slirp); - m_inc(n, m->m_len + header_size); - - if (copy_header) { - m->m_len += header_size; - m->m_data -= header_size; - mcopy_result = m_copy(n, m, 0, m->m_len + header_size); - n->m_data += header_size; - m->m_len -= header_size; - m->m_data += header_size; - } else { - n->m_data += header_size; - mcopy_result = m_copy(n, m, 0, m->m_len); - } - g_assert(mcopy_result == 0); - - return n; -} - -void *mtod_check(struct mbuf *m, size_t len) -{ - if (m->m_len >= len) { - return m->m_data; - } - - DEBUG_ERROR("mtod failed"); - - return NULL; -} - -void *m_end(struct mbuf *m) -{ - return m->m_data + m->m_len; -} diff --git a/src/network/slirp/mbuf.h b/src/network/slirp/mbuf.h deleted file mode 100644 index aedfc712e..000000000 --- a/src/network/slirp/mbuf.h +++ /dev/null @@ -1,192 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mbuf.h 8.3 (Berkeley) 1/21/94 - * mbuf.h,v 1.9 1994/11/14 13:54:20 bde Exp - */ - -#ifndef MBUF_H -#define MBUF_H - -/* - * Macros for type conversion - * mtod(m,t) - convert mbuf pointer to data pointer of correct type - */ -#define mtod(m, t) ((t)(m)->m_data) - -/* XXX About mbufs for slirp: - * Only one mbuf is ever used in a chain, for each "cell" of data. - * m_nextpkt points to the next packet, if fragmented. - * If the data is too large, the M_EXT is used, and a larger block - * is alloced. Therefore, m_free[m] must check for M_EXT and if set - * free the m_ext. This is inefficient memory-wise, but who cares. - */ - -/* - * mbufs allow to have a gap between the start of the allocated buffer (m_ext if - * M_EXT is set, m_dat otherwise) and the in-use data: - * - * |--gapsize----->|---m_len-------> - * |----------m_size------------------------------> - * |----M_ROOM--------------------> - * |-M_FREEROOM--> - * - * ^ ^ ^ - * m_dat/m_ext m_data end of buffer - */ - -/* - * How much room is in the mbuf, from m_data to the end of the mbuf - */ -#define M_ROOM(m) \ - ((m->m_flags & M_EXT) ? (((m)->m_ext + (m)->m_size) - (m)->m_data) : \ - (((m)->m_dat + (m)->m_size) - (m)->m_data)) - -/* - * How much free room there is - */ -#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len) - -/* - * How much free room there is before m_data - */ -#define M_ROOMBEFORE(m) \ - (((m)->m_flags & M_EXT) ? (m)->m_data - (m)->m_ext \ - : (m)->m_data - (m)->m_dat) - -struct mbuf { - /* XXX should union some of these! */ - /* header at beginning of each mbuf: */ - struct mbuf *m_next; /* Linked list of mbufs */ - struct mbuf *m_prev; - struct mbuf *m_nextpkt; /* Next packet in queue/record */ - struct mbuf *m_prevpkt; /* Flags aren't used in the output queue */ - int m_flags; /* Misc flags */ - - int m_size; /* Size of mbuf, from m_dat or m_ext */ - struct socket *m_so; - - char *m_data; /* Current location of data */ - int m_len; /* Amount of data in this mbuf, from m_data */ - - Slirp *slirp; - bool resolution_requested; - uint64_t expiration_date; - char *m_ext; - /* start of dynamic buffer area, must be last element */ - char m_dat[]; -}; - -#define ifq_prev m_prev -#define ifq_next m_next -#define ifs_prev m_prevpkt -#define ifs_next m_nextpkt -#define ifq_so m_so - -#define M_EXT 0x01 /* m_ext points to more (malloced) data */ -#define M_FREELIST 0x02 /* mbuf is on free list */ -#define M_USEDLIST 0x04 /* XXX mbuf is on used list (for dtom()) */ -#define M_DOFREE \ - 0x08 /* when m_free is called on the mbuf, free() \ - * it rather than putting it on the free list */ - -void m_init(Slirp *); -void m_cleanup(Slirp *slirp); -struct mbuf *m_get(Slirp *); -void m_free(struct mbuf *); -void m_cat(register struct mbuf *, register struct mbuf *); -void m_inc(struct mbuf *, int); -void m_adj(struct mbuf *, int); -int m_copy(struct mbuf *, struct mbuf *, int, int); -struct mbuf *m_dup(Slirp *slirp, struct mbuf *m, bool copy_header, size_t header_size); -struct mbuf *dtom(Slirp *, void *); -void *mtod_check(struct mbuf *, size_t len); -void *m_end(struct mbuf *); - -static inline void ifs_init(struct mbuf *ifm) -{ - ifm->ifs_next = ifm->ifs_prev = ifm; -} - -#ifdef SLIRP_DEBUG -# define MBUF_DEBUG 1 -#else -# ifdef HAVE_VALGRIND -# include -# define MBUF_DEBUG RUNNING_ON_VALGRIND -# else -# define MBUF_DEBUG 0 -# endif -#endif - -/* - * When a function is given an mbuf as well as the responsibility to free it, we - * want valgrind etc. to properly identify the new responsible for the - * free. Achieve this by making a new copy. For instance: - * - * f0(void) { - * struct mbuf *m = m_get(slirp); - * [...] - * switch (something) { - * case 1: - * f1(m); - * break; - * case 2: - * f2(m); - * break; - * [...] - * } - * } - * - * f1(struct mbuf *m) { - * M_DUP_DEBUG(m->slirp, m); - * [...] - * m_free(m); // but author of f1 might be forgetting this - * } - * - * f0 transfers the freeing responsibility to f1, f2, etc. Without the - * M_DUP_DEBUG call in f1, valgrind would tell us that it is f0 where the buffer - * was allocated, but it's difficult to know whether a leak is actually in f0, - * or in f1, or in f2, etc. Duplicating the mbuf in M_DUP_DEBUG each time the - * responsibility is transferred allows to immediately know where the leak - * actually is. - */ -#define M_DUP_DEBUG(slirp, m, copy_header, header_size) do { \ - if (MBUF_DEBUG) { \ - struct mbuf *__n; \ - __n = m_dup((slirp), (m), (copy_header), (header_size)); \ - m_free(m); \ - (m) = __n; \ - } else { \ - (void) (slirp); (void) (copy_header); \ - g_assert(M_ROOMBEFORE(m) >= (header_size)); \ - } \ -} while(0) - -#endif diff --git a/src/network/slirp/misc.c b/src/network/slirp/misc.c deleted file mode 100644 index 220506328..000000000 --- a/src/network/slirp/misc.c +++ /dev/null @@ -1,459 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include -#ifdef G_OS_UNIX -#include -#include -#ifdef BSD -#define g_strlcpy strlcpy -#else -extern gsize g_strlcpy(gchar* dest, const gchar* src, gsize dest_size); -#endif -#endif - -#ifdef __APPLE__ -#include -#endif - -extern inline void slirp_insque(void *a, void *b) -{ - register struct slirp_quehead *element = (struct slirp_quehead *)a; - register struct slirp_quehead *head = (struct slirp_quehead *)b; - element->qh_link = head->qh_link; - head->qh_link = (struct slirp_quehead *)element; - element->qh_rlink = (struct slirp_quehead *)head; - ((struct slirp_quehead *)(element->qh_link))->qh_rlink = - (struct slirp_quehead *)element; -} - -extern inline void slirp_remque(void *a) -{ - register struct slirp_quehead *element = (struct slirp_quehead *)a; - ((struct slirp_quehead *)(element->qh_link))->qh_rlink = element->qh_rlink; - ((struct slirp_quehead *)(element->qh_rlink))->qh_link = element->qh_link; - element->qh_rlink = NULL; -} - -/* TODO: IPv6 */ -struct gfwd_list *add_guestfwd(struct gfwd_list **ex_ptr, SlirpWriteCb write_cb, - void *opaque, struct in_addr addr, int port) -{ - struct gfwd_list *f = g_new0(struct gfwd_list, 1); - - f->write_cb = write_cb; - f->opaque = opaque; - f->ex_fport = port; - f->ex_addr = addr; - f->ex_next = *ex_ptr; - *ex_ptr = f; - - return f; -} - -struct gfwd_list *add_exec(struct gfwd_list **ex_ptr, const char *cmdline, - struct in_addr addr, int port) -{ - struct gfwd_list *f = add_guestfwd(ex_ptr, NULL, NULL, addr, port); - - f->ex_exec = g_strdup(cmdline); - - return f; -} - -struct gfwd_list *add_unix(struct gfwd_list **ex_ptr, const char *unixsock, - struct in_addr addr, int port) -{ - struct gfwd_list *f = add_guestfwd(ex_ptr, NULL, NULL, addr, port); - - f->ex_unix = g_strdup(unixsock); - - return f; -} - -int remove_guestfwd(struct gfwd_list **ex_ptr, struct in_addr addr, int port) -{ - for (; *ex_ptr != NULL; ex_ptr = &((*ex_ptr)->ex_next)) { - struct gfwd_list *f = *ex_ptr; - if (f->ex_addr.s_addr == addr.s_addr && f->ex_fport == port) { - *ex_ptr = f->ex_next; - g_free(f->ex_exec); - g_free(f); - return 0; - } - } - return -1; -} - -static int slirp_socketpair_with_oob(int sv[2]) -{ - struct sockaddr_in addr = { - .sin_family = AF_INET, - .sin_port = 0, - .sin_addr.s_addr = htonl(INADDR_LOOPBACK), - }; - socklen_t addrlen = sizeof(addr); - int ret, s; - - sv[1] = -1; - s = slirp_socket(AF_INET, SOCK_STREAM, 0); - if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || - listen(s, 1) < 0 || - getsockname(s, (struct sockaddr *)&addr, &addrlen) < 0) { - goto err; - } - - sv[1] = slirp_socket(AF_INET, SOCK_STREAM, 0); - if (sv[1] < 0) { - goto err; - } - /* - * This connect won't block because we've already listen()ed on - * the server end (even though we won't accept() the connection - * until later on). - */ - do { - ret = connect(sv[1], (struct sockaddr *)&addr, addrlen); - } while (ret < 0 && errno == EINTR); - if (ret < 0) { - goto err; - } - - do { - sv[0] = accept(s, (struct sockaddr *)&addr, &addrlen); - } while (sv[0] < 0 && errno == EINTR); - if (sv[0] < 0) { - goto err; - } - - closesocket(s); - return 0; - -err: - g_critical("slirp_socketpair(): %s", strerror(errno)); - if (s >= 0) { - closesocket(s); - } - if (sv[1] >= 0) { - closesocket(sv[1]); - } - return -1; -} - -static void fork_exec_child_setup(gpointer data) -{ -#ifndef _WIN32 - setsid(); - - /* Unblock all signals and leave our exec()-ee to block what it wants */ - sigset_t ss; - sigemptyset(&ss); - sigprocmask(SIG_SETMASK, &ss, NULL); - - /* POSIX is obnoxious about SIGCHLD specifically across exec() */ - signal(SIGCHLD, SIG_DFL); -#endif -} - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -#if !GLIB_CHECK_VERSION(2, 58, 0) -typedef struct SlirpGSpawnFds { - GSpawnChildSetupFunc child_setup; - gpointer user_data; - gint stdin_fd; - gint stdout_fd; - gint stderr_fd; -} SlirpGSpawnFds; - -static inline void slirp_gspawn_fds_setup(gpointer user_data) -{ - SlirpGSpawnFds *q = (SlirpGSpawnFds *)user_data; - - dup2(q->stdin_fd, 0); - dup2(q->stdout_fd, 1); - dup2(q->stderr_fd, 2); - q->child_setup(q->user_data); -} -#endif - -static inline gboolean -g_spawn_async_with_fds_slirp(const gchar *working_directory, gchar **argv, - gchar **envp, GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, GPid *child_pid, gint stdin_fd, - gint stdout_fd, gint stderr_fd, GError **error) -{ -#if GLIB_CHECK_VERSION(2, 58, 0) - return g_spawn_async_with_fds(working_directory, argv, envp, flags, - child_setup, user_data, child_pid, stdin_fd, - stdout_fd, stderr_fd, error); -#else - SlirpGSpawnFds setup = { - .child_setup = child_setup, - .user_data = user_data, - .stdin_fd = stdin_fd, - .stdout_fd = stdout_fd, - .stderr_fd = stderr_fd, - }; - - return g_spawn_async(working_directory, argv, envp, flags, - slirp_gspawn_fds_setup, &setup, child_pid, error); -#endif -} - -#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, err) \ - g_spawn_async_with_fds_slirp(wd, argv, env, f, c, d, p, ifd, ofd, efd, err) - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - -int fork_exec(struct socket *so, const char *ex) -{ - GError *err = NULL; - gint argc = 0; - gchar **argv = NULL; - int opt, sp[2]; - - DEBUG_CALL("fork_exec"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("ex = %p", ex); - - if (slirp_socketpair_with_oob(sp) < 0) { - return 0; - } - - if (!g_shell_parse_argv(ex, &argc, &argv, &err)) { - g_critical("fork_exec invalid command: %s\nerror: %s", ex, err->message); - g_error_free(err); - return 0; - } - - g_spawn_async_with_fds(NULL /* cwd */, argv, NULL /* env */, - G_SPAWN_SEARCH_PATH, fork_exec_child_setup, - NULL /* data */, NULL /* child_pid */, sp[1], sp[1], - sp[1], &err); - g_strfreev(argv); - - if (err) { - g_critical("fork_exec: %s", err->message); - g_error_free(err); - closesocket(sp[0]); - closesocket(sp[1]); - return 0; - } - - so->s = sp[0]; - closesocket(sp[1]); - slirp_socket_set_fast_reuse(so->s); - opt = 1; - setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - slirp_set_nonblock(so->s); - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - return 1; -} - -int open_unix(struct socket *so, const char *unixpath) -{ -#ifdef G_OS_UNIX - struct sockaddr_un sa; - int s; - - DEBUG_CALL("open_unix"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("unixpath = %s", unixpath); - - memset(&sa, 0, sizeof(sa)); - sa.sun_family = AF_UNIX; - if (g_strlcpy(sa.sun_path, unixpath, sizeof(sa.sun_path)) >= sizeof(sa.sun_path)) { - g_critical("Bad unix path: %s", unixpath); - return 0; - } - - s = slirp_socket(PF_UNIX, SOCK_STREAM, 0); - if (s < 0) { - g_critical("open_unix(): %s", strerror(errno)); - return 0; - } - - if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) { - g_critical("open_unix(): %s", strerror(errno)); - closesocket(s); - return 0; - } - - so->s = s; - slirp_set_nonblock(so->s); - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - - return 1; -#else - g_assert_not_reached(); -#endif -} - -char *slirp_connection_info(Slirp *slirp) -{ - GString *str = g_string_new(NULL); - const char *const tcpstates[] = { - [TCPS_CLOSED] = "CLOSED", [TCPS_LISTEN] = "LISTEN", - [TCPS_SYN_SENT] = "SYN_SENT", [TCPS_SYN_RECEIVED] = "SYN_RCVD", - [TCPS_ESTABLISHED] = "ESTABLISHED", [TCPS_CLOSE_WAIT] = "CLOSE_WAIT", - [TCPS_FIN_WAIT_1] = "FIN_WAIT_1", [TCPS_CLOSING] = "CLOSING", - [TCPS_LAST_ACK] = "LAST_ACK", [TCPS_FIN_WAIT_2] = "FIN_WAIT_2", - [TCPS_TIME_WAIT] = "TIME_WAIT", - }; - struct in_addr dst_addr; - struct sockaddr_in src; - socklen_t src_len; - uint16_t dst_port; - struct socket *so; - const char *state; - char addr[INET_ADDRSTRLEN]; - char buf[20]; - - g_string_append_printf(str, - " Protocol[State] FD Source Address Port " - "Dest. Address Port RecvQ SendQ\n"); - - /* TODO: IPv6 */ - - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so->so_next) { - if (so->so_state & SS_HOSTFWD) { - state = "HOST_FORWARD"; - } else if (so->so_tcpcb) { - state = tcpstates[so->so_tcpcb->t_state]; - } else { - state = "NONE"; - } - if (so->so_state & (SS_HOSTFWD | SS_INCOMING)) { - src_len = sizeof(src); - getsockname(so->s, (struct sockaddr *)&src, &src_len); - dst_addr = so->so_laddr; - dst_port = so->so_lport; - } else { - src.sin_addr = so->so_laddr; - src.sin_port = so->so_lport; - dst_addr = so->so_faddr; - dst_port = so->so_fport; - } - slirp_fmt0(buf, sizeof(buf), " TCP[%s]", state); - g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s, - src.sin_addr.s_addr ? - inet_ntop(AF_INET, &src.sin_addr, addr, sizeof(addr)) : "*", - ntohs(src.sin_port)); - g_string_append_printf(str, "%15s %5d %5d %5d\n", - inet_ntop(AF_INET, &dst_addr, addr, sizeof(addr)), - ntohs(dst_port), so->so_rcv.sb_cc, - so->so_snd.sb_cc); - } - - for (so = slirp->udb.so_next; so != &slirp->udb; so = so->so_next) { - if (so->so_state & SS_HOSTFWD) { - slirp_fmt0(buf, sizeof(buf), " UDP[HOST_FORWARD]"); - src_len = sizeof(src); - getsockname(so->s, (struct sockaddr *)&src, &src_len); - dst_addr = so->so_laddr; - dst_port = so->so_lport; - } else { - slirp_fmt0(buf, sizeof(buf), " UDP[%d sec]", - (so->so_expire - curtime) / 1000); - src.sin_addr = so->so_laddr; - src.sin_port = so->so_lport; - dst_addr = so->so_faddr; - dst_port = so->so_fport; - } - g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s, - src.sin_addr.s_addr ? - inet_ntop(AF_INET, &src.sin_addr, addr, sizeof(addr)) : "*", - ntohs(src.sin_port)); - g_string_append_printf(str, "%15s %5d %5d %5d\n", - inet_ntop(AF_INET, &dst_addr, addr, sizeof(addr)), - ntohs(dst_port), so->so_rcv.sb_cc, - so->so_snd.sb_cc); - } - - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so->so_next) { - slirp_fmt0(buf, sizeof(buf), " ICMP[%d sec]", - (so->so_expire - curtime) / 1000); - src.sin_addr = so->so_laddr; - dst_addr = so->so_faddr; - g_string_append_printf(str, "%-19s %3d %15s - ", buf, so->s, - src.sin_addr.s_addr ? - inet_ntop(AF_INET, &src.sin_addr, addr, sizeof(addr)) : "*"); - g_string_append_printf(str, "%15s - %5d %5d\n", - inet_ntop(AF_INET, &dst_addr, addr, sizeof(addr)), - so->so_rcv.sb_cc, so->so_snd.sb_cc); - } - - return g_string_free(str, false); -} - -char *slirp_neighbor_info(Slirp *slirp) -{ - GString *str = g_string_new(NULL); - ArpTable *arp_table = &slirp->arp_table; - NdpTable *ndp_table = &slirp->ndp_table; - char ip_addr[INET6_ADDRSTRLEN]; - char eth_addr[ETH_ADDRSTRLEN]; - const char *ip; - - g_string_append_printf(str, " %5s %-17s %s\n", - "Table", "MacAddr", "IP Address"); - - for (int i = 0; i < ARP_TABLE_SIZE; ++i) { - struct in_addr addr; - addr.s_addr = arp_table->table[i].ar_sip; - if (!addr.s_addr) { - continue; - } - ip = inet_ntop(AF_INET, &addr, ip_addr, sizeof(ip_addr)); - g_assert(ip != NULL); - g_string_append_printf(str, " %5s %-17s %s\n", "ARP", - slirp_ether_ntoa(arp_table->table[i].ar_sha, - eth_addr, sizeof(eth_addr)), - ip); - } - - for (int i = 0; i < NDP_TABLE_SIZE; ++i) { - if (in6_zero(&ndp_table->table[i].ip_addr)) { - continue; - } - ip = inet_ntop(AF_INET6, &ndp_table->table[i].ip_addr, ip_addr, - sizeof(ip_addr)); - g_assert(ip != NULL); - g_string_append_printf(str, " %5s %-17s %s\n", "NDP", - slirp_ether_ntoa(ndp_table->table[i].eth_addr, - eth_addr, sizeof(eth_addr)), - ip); - } - - return g_string_free(str, false); -} - -int slirp_bind_outbound(struct socket *so, unsigned short af) -{ - int ret = 0; - struct sockaddr *addr = NULL; - int addr_size = 0; - - if (af == AF_INET && so->slirp->outbound_addr != NULL) { - addr = (struct sockaddr *)so->slirp->outbound_addr; - addr_size = sizeof(struct sockaddr_in); - } else if (af == AF_INET6 && so->slirp->outbound_addr6 != NULL) { - addr = (struct sockaddr *)so->slirp->outbound_addr6; - addr_size = sizeof(struct sockaddr_in6); - } - - if (addr != NULL) { - ret = bind(so->s, addr, addr_size); - } - return ret; -} diff --git a/src/network/slirp/misc.h b/src/network/slirp/misc.h deleted file mode 100644 index 81b370cfb..000000000 --- a/src/network/slirp/misc.h +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef MISC_H -#define MISC_H - -#include "libslirp.h" - -struct gfwd_list { - SlirpWriteCb write_cb; - void *opaque; - struct in_addr ex_addr; /* Server address */ - int ex_fport; /* Port to telnet to */ - char *ex_exec; /* Command line of what to exec */ - char *ex_unix; /* unix socket */ - struct gfwd_list *ex_next; -}; - -#define EMU_NONE 0x0 - -/* TCP emulations */ -#define EMU_CTL 0x1 -#define EMU_FTP 0x2 -#define EMU_KSH 0x3 -#define EMU_IRC 0x4 -#define EMU_REALAUDIO 0x5 -#define EMU_RLOGIN 0x6 -#define EMU_IDENT 0x7 - -#define EMU_NOCONNECT 0x10 /* Don't connect */ - -struct tos_t { - uint16_t lport; - uint16_t fport; - uint8_t tos; - uint8_t emu; -}; - -struct emu_t { - uint16_t lport; - uint16_t fport; - uint8_t tos; - uint8_t emu; - struct emu_t *next; -}; - -struct slirp_quehead { - struct slirp_quehead *qh_link; - struct slirp_quehead *qh_rlink; -}; - -void slirp_insque(void *, void *); -void slirp_remque(void *); -int fork_exec(struct socket *so, const char *ex); -int open_unix(struct socket *so, const char *unixsock); - -struct gfwd_list *add_guestfwd(struct gfwd_list **ex_ptr, SlirpWriteCb write_cb, - void *opaque, struct in_addr addr, int port); - -struct gfwd_list *add_exec(struct gfwd_list **ex_ptr, const char *cmdline, - struct in_addr addr, int port); - -struct gfwd_list *add_unix(struct gfwd_list **ex_ptr, const char *unixsock, - struct in_addr addr, int port); - -int remove_guestfwd(struct gfwd_list **ex_ptr, struct in_addr addr, int port); - -int slirp_bind_outbound(struct socket *so, unsigned short af); - -#endif diff --git a/src/network/slirp/ncsi-pkt.h b/src/network/slirp/ncsi-pkt.h deleted file mode 100644 index 7694e68ff..000000000 --- a/src/network/slirp/ncsi-pkt.h +++ /dev/null @@ -1,616 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright Gavin Shan, IBM Corporation 2016. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef NCSI_PKT_H -#define NCSI_PKT_H - -/* from linux/net/ncsi/ncsi-pkt.h */ -#define __be32 uint32_t -#define __be16 uint16_t - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_pkt_hdr { - unsigned char mc_id; /* Management controller ID */ - unsigned char revision; /* NCSI version - 0x01 */ - unsigned char reserved; /* Reserved */ - unsigned char id; /* Packet sequence number */ - unsigned char type; /* Packet type */ - unsigned char channel; /* Network controller ID */ - __be16 length; /* Payload length */ - __be32 reserved1[2]; /* Reserved */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_pkt_hdr { - struct ncsi_pkt_hdr common; /* Common NCSI packet header */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_pkt_hdr { - struct ncsi_pkt_hdr common; /* Common NCSI packet header */ - __be16 code; /* Response code */ - __be16 reason; /* Response reason */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_pkt_hdr { - struct ncsi_pkt_hdr common; /* Common NCSI packet header */ - unsigned char reserved2[3]; /* Reserved */ - unsigned char type; /* AEN packet type */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* NCSI common command packet */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 checksum; /* Checksum */ - unsigned char pad[26]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Select Package */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_sp_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char hw_arbitration; /* HW arbitration */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Disable Channel */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_dc_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char ald; /* Allow link down */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Reset Channel */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_rc_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 reserved; /* Reserved */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN Enable */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_ae_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char mc_id; /* MC ID */ - __be32 mode; /* AEN working mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set Link */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_sl_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 mode; /* Link working mode */ - __be32 oem_mode; /* OEM link mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set VLAN Filter */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_svf_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be16 reserved; /* Reserved */ - __be16 vlan; /* VLAN ID */ - __be16 reserved1; /* Reserved */ - unsigned char index; /* VLAN table index */ - unsigned char enable; /* Enable or disable */ - __be32 checksum; /* Checksum */ - unsigned char pad[14]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Enable VLAN */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_ev_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char mode; /* VLAN filter mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set MAC Address */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_sma_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char mac[6]; /* MAC address */ - unsigned char index; /* MAC table index */ - unsigned char at_e; /* Addr type and operation */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Enable Broadcast Filter */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_ebf_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 mode; /* Filter mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Enable Global Multicast Filter */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_egmf_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 mode; /* Global MC mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set NCSI Flow Control */ -struct ncsi_cmd_snfc_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char mode; /* Flow control mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Link Status */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gls_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 status; /* Link status */ - __be32 other; /* Other indications */ - __be32 oem_status; /* OEM link status */ - __be32 checksum; - unsigned char pad[10]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Version ID */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gvi_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 ncsi_version; /* NCSI version */ - unsigned char reserved[3]; /* Reserved */ - unsigned char alpha2; /* NCSI version */ - unsigned char fw_name[12]; /* f/w name string */ - __be32 fw_version; /* f/w version */ - __be16 pci_ids[4]; /* PCI IDs */ - __be32 mf_id; /* Manufacture ID */ - __be32 checksum; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Capabilities */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gc_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 cap; /* Capabilities */ - __be32 bc_cap; /* Broadcast cap */ - __be32 mc_cap; /* Multicast cap */ - __be32 buf_cap; /* Buffering cap */ - __be32 aen_cap; /* AEN cap */ - unsigned char vlan_cnt; /* VLAN filter count */ - unsigned char mixed_cnt; /* Mix filter count */ - unsigned char mc_cnt; /* MC filter count */ - unsigned char uc_cnt; /* UC filter count */ - unsigned char reserved[2]; /* Reserved */ - unsigned char vlan_mode; /* VLAN mode */ - unsigned char channel_cnt; /* Channel count */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Parameters */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gp_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - unsigned char mac_cnt; /* Number of MAC addr */ - unsigned char reserved[2]; /* Reserved */ - unsigned char mac_enable; /* MAC addr enable flags */ - unsigned char vlan_cnt; /* VLAN tag count */ - unsigned char reserved1; /* Reserved */ - __be16 vlan_enable; /* VLAN tag enable flags */ - __be32 link_mode; /* Link setting */ - __be32 bc_mode; /* BC filter mode */ - __be32 valid_modes; /* Valid mode parameters */ - unsigned char vlan_mode; /* VLAN mode */ - unsigned char fc_mode; /* Flow control mode */ - unsigned char reserved2[2]; /* Reserved */ - __be32 aen_mode; /* AEN mode */ - unsigned char mac[6]; /* Supported MAC addr */ - __be16 vlan; /* Supported VLAN tags */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Controller Packet Statistics */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gcps_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 cnt_hi; /* Counter cleared */ - __be32 cnt_lo; /* Counter cleared */ - __be32 rx_bytes; /* Rx bytes */ - __be32 tx_bytes; /* Tx bytes */ - __be32 rx_uc_pkts; /* Rx UC packets */ - __be32 rx_mc_pkts; /* Rx MC packets */ - __be32 rx_bc_pkts; /* Rx BC packets */ - __be32 tx_uc_pkts; /* Tx UC packets */ - __be32 tx_mc_pkts; /* Tx MC packets */ - __be32 tx_bc_pkts; /* Tx BC packets */ - __be32 fcs_err; /* FCS errors */ - __be32 align_err; /* Alignment errors */ - __be32 false_carrier; /* False carrier detection */ - __be32 runt_pkts; /* Rx runt packets */ - __be32 jabber_pkts; /* Rx jabber packets */ - __be32 rx_pause_xon; /* Rx pause XON frames */ - __be32 rx_pause_xoff; /* Rx XOFF frames */ - __be32 tx_pause_xon; /* Tx XON frames */ - __be32 tx_pause_xoff; /* Tx XOFF frames */ - __be32 tx_s_collision; /* Single collision frames */ - __be32 tx_m_collision; /* Multiple collision frames */ - __be32 l_collision; /* Late collision frames */ - __be32 e_collision; /* Excessive collision frames */ - __be32 rx_ctl_frames; /* Rx control frames */ - __be32 rx_64_frames; /* Rx 64-bytes frames */ - __be32 rx_127_frames; /* Rx 65-127 bytes frames */ - __be32 rx_255_frames; /* Rx 128-255 bytes frames */ - __be32 rx_511_frames; /* Rx 256-511 bytes frames */ - __be32 rx_1023_frames; /* Rx 512-1023 bytes frames */ - __be32 rx_1522_frames; /* Rx 1024-1522 bytes frames */ - __be32 rx_9022_frames; /* Rx 1523-9022 bytes frames */ - __be32 tx_64_frames; /* Tx 64-bytes frames */ - __be32 tx_127_frames; /* Tx 65-127 bytes frames */ - __be32 tx_255_frames; /* Tx 128-255 bytes frames */ - __be32 tx_511_frames; /* Tx 256-511 bytes frames */ - __be32 tx_1023_frames; /* Tx 512-1023 bytes frames */ - __be32 tx_1522_frames; /* Tx 1024-1522 bytes frames */ - __be32 tx_9022_frames; /* Tx 1523-9022 bytes frames */ - __be32 rx_valid_bytes; /* Rx valid bytes */ - __be32 rx_runt_pkts; /* Rx error runt packets */ - __be32 rx_jabber_pkts; /* Rx error jabber packets */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get NCSI Statistics */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gns_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 rx_cmds; /* Rx NCSI commands */ - __be32 dropped_cmds; /* Dropped commands */ - __be32 cmd_type_errs; /* Command type errors */ - __be32 cmd_csum_errs; /* Command checksum errors */ - __be32 rx_pkts; /* Rx NCSI packets */ - __be32 tx_pkts; /* Tx NCSI packets */ - __be32 tx_aen_pkts; /* Tx AEN packets */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get NCSI Pass-through Statistics */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gnpts_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 tx_pkts; /* Tx packets */ - __be32 tx_dropped; /* Tx dropped packets */ - __be32 tx_channel_err; /* Tx channel errors */ - __be32 tx_us_err; /* Tx undersize errors */ - __be32 rx_pkts; /* Rx packets */ - __be32 rx_dropped; /* Rx dropped packets */ - __be32 rx_channel_err; /* Rx channel errors */ - __be32 rx_us_err; /* Rx undersize errors */ - __be32 rx_os_err; /* Rx oversize errors */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get package status */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gps_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 status; /* Hardware arbitration status */ - __be32 checksum; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get package UUID */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gpuuid_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - unsigned char uuid[16]; /* UUID */ - __be32 checksum; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN: Link State Change */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_lsc_pkt { - struct ncsi_aen_pkt_hdr aen; /* AEN header */ - __be32 status; /* Link status */ - __be32 oem_status; /* OEM link status */ - __be32 checksum; /* Checksum */ - unsigned char pad[14]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN: Configuration Required */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_cr_pkt { - struct ncsi_aen_pkt_hdr aen; /* AEN header */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN: Host Network Controller Driver Status Change */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_hncdsc_pkt { - struct ncsi_aen_pkt_hdr aen; /* AEN header */ - __be32 status; /* Status */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* NCSI packet revision */ -#define NCSI_PKT_REVISION 0x01 - -/* NCSI packet commands */ -#define NCSI_PKT_CMD_CIS 0x00 /* Clear Initial State */ -#define NCSI_PKT_CMD_SP 0x01 /* Select Package */ -#define NCSI_PKT_CMD_DP 0x02 /* Deselect Package */ -#define NCSI_PKT_CMD_EC 0x03 /* Enable Channel */ -#define NCSI_PKT_CMD_DC 0x04 /* Disable Channel */ -#define NCSI_PKT_CMD_RC 0x05 /* Reset Channel */ -#define NCSI_PKT_CMD_ECNT 0x06 /* Enable Channel Network Tx */ -#define NCSI_PKT_CMD_DCNT 0x07 /* Disable Channel Network Tx */ -#define NCSI_PKT_CMD_AE 0x08 /* AEN Enable */ -#define NCSI_PKT_CMD_SL 0x09 /* Set Link */ -#define NCSI_PKT_CMD_GLS 0x0a /* Get Link */ -#define NCSI_PKT_CMD_SVF 0x0b /* Set VLAN Filter */ -#define NCSI_PKT_CMD_EV 0x0c /* Enable VLAN */ -#define NCSI_PKT_CMD_DV 0x0d /* Disable VLAN */ -#define NCSI_PKT_CMD_SMA 0x0e /* Set MAC address */ -#define NCSI_PKT_CMD_EBF 0x10 /* Enable Broadcast Filter */ -#define NCSI_PKT_CMD_DBF 0x11 /* Disable Broadcast Filter */ -#define NCSI_PKT_CMD_EGMF 0x12 /* Enable Global Multicast Filter */ -#define NCSI_PKT_CMD_DGMF 0x13 /* Disable Global Multicast Filter */ -#define NCSI_PKT_CMD_SNFC 0x14 /* Set NCSI Flow Control */ -#define NCSI_PKT_CMD_GVI 0x15 /* Get Version ID */ -#define NCSI_PKT_CMD_GC 0x16 /* Get Capabilities */ -#define NCSI_PKT_CMD_GP 0x17 /* Get Parameters */ -#define NCSI_PKT_CMD_GCPS 0x18 /* Get Controller Packet Statistics */ -#define NCSI_PKT_CMD_GNS 0x19 /* Get NCSI Statistics */ -#define NCSI_PKT_CMD_GNPTS 0x1a /* Get NCSI Pass-throu Statistics */ -#define NCSI_PKT_CMD_GPS 0x1b /* Get package status */ -#define NCSI_PKT_CMD_OEM 0x50 /* OEM */ -#define NCSI_PKT_CMD_PLDM 0x51 /* PLDM request over NCSI over RBT */ -#define NCSI_PKT_CMD_GPUUID 0x52 /* Get package UUID */ - -/* NCSI packet responses */ -#define NCSI_PKT_RSP_CIS (NCSI_PKT_CMD_CIS + 0x80) -#define NCSI_PKT_RSP_SP (NCSI_PKT_CMD_SP + 0x80) -#define NCSI_PKT_RSP_DP (NCSI_PKT_CMD_DP + 0x80) -#define NCSI_PKT_RSP_EC (NCSI_PKT_CMD_EC + 0x80) -#define NCSI_PKT_RSP_DC (NCSI_PKT_CMD_DC + 0x80) -#define NCSI_PKT_RSP_RC (NCSI_PKT_CMD_RC + 0x80) -#define NCSI_PKT_RSP_ECNT (NCSI_PKT_CMD_ECNT + 0x80) -#define NCSI_PKT_RSP_DCNT (NCSI_PKT_CMD_DCNT + 0x80) -#define NCSI_PKT_RSP_AE (NCSI_PKT_CMD_AE + 0x80) -#define NCSI_PKT_RSP_SL (NCSI_PKT_CMD_SL + 0x80) -#define NCSI_PKT_RSP_GLS (NCSI_PKT_CMD_GLS + 0x80) -#define NCSI_PKT_RSP_SVF (NCSI_PKT_CMD_SVF + 0x80) -#define NCSI_PKT_RSP_EV (NCSI_PKT_CMD_EV + 0x80) -#define NCSI_PKT_RSP_DV (NCSI_PKT_CMD_DV + 0x80) -#define NCSI_PKT_RSP_SMA (NCSI_PKT_CMD_SMA + 0x80) -#define NCSI_PKT_RSP_EBF (NCSI_PKT_CMD_EBF + 0x80) -#define NCSI_PKT_RSP_DBF (NCSI_PKT_CMD_DBF + 0x80) -#define NCSI_PKT_RSP_EGMF (NCSI_PKT_CMD_EGMF + 0x80) -#define NCSI_PKT_RSP_DGMF (NCSI_PKT_CMD_DGMF + 0x80) -#define NCSI_PKT_RSP_SNFC (NCSI_PKT_CMD_SNFC + 0x80) -#define NCSI_PKT_RSP_GVI (NCSI_PKT_CMD_GVI + 0x80) -#define NCSI_PKT_RSP_GC (NCSI_PKT_CMD_GC + 0x80) -#define NCSI_PKT_RSP_GP (NCSI_PKT_CMD_GP + 0x80) -#define NCSI_PKT_RSP_GCPS (NCSI_PKT_CMD_GCPS + 0x80) -#define NCSI_PKT_RSP_GNS (NCSI_PKT_CMD_GNS + 0x80) -#define NCSI_PKT_RSP_GNPTS (NCSI_PKT_CMD_GNPTS + 0x80) -#define NCSI_PKT_RSP_GPS (NCSI_PKT_CMD_GPS + 0x80) -#define NCSI_PKT_RSP_OEM (NCSI_PKT_CMD_OEM + 0x80) -#define NCSI_PKT_RSP_PLDM (NCSI_PKT_CMD_PLDM + 0x80) -#define NCSI_PKT_RSP_GPUUID (NCSI_PKT_CMD_GPUUID + 0x80) - -/* NCSI response code/reason */ -#define NCSI_PKT_RSP_C_COMPLETED 0x0000 /* Command Completed */ -#define NCSI_PKT_RSP_C_FAILED 0x0001 /* Command Failed */ -#define NCSI_PKT_RSP_C_UNAVAILABLE 0x0002 /* Command Unavailable */ -#define NCSI_PKT_RSP_C_UNSUPPORTED 0x0003 /* Command Unsupported */ -#define NCSI_PKT_RSP_R_NO_ERROR 0x0000 /* No Error */ -#define NCSI_PKT_RSP_R_INTERFACE 0x0001 /* Interface not ready */ -#define NCSI_PKT_RSP_R_PARAM 0x0002 /* Invalid Parameter */ -#define NCSI_PKT_RSP_R_CHANNEL 0x0003 /* Channel not Ready */ -#define NCSI_PKT_RSP_R_PACKAGE 0x0004 /* Package not Ready */ -#define NCSI_PKT_RSP_R_LENGTH 0x0005 /* Invalid payload length */ -#define NCSI_PKT_RSP_R_UNKNOWN 0x7fff /* Command type unsupported */ - -/* NCSI AEN packet type */ -#define NCSI_PKT_AEN 0xFF /* AEN Packet */ -#define NCSI_PKT_AEN_LSC 0x00 /* Link status change */ -#define NCSI_PKT_AEN_CR 0x01 /* Configuration required */ -#define NCSI_PKT_AEN_HNCDSC 0x02 /* HNC driver status change */ - -#endif /* NCSI_PKT_H */ diff --git a/src/network/slirp/ncsi.c b/src/network/slirp/ncsi.c deleted file mode 100644 index f3427bd66..000000000 --- a/src/network/slirp/ncsi.c +++ /dev/null @@ -1,197 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * NC-SI (Network Controller Sideband Interface) "echo" model - * - * Copyright (C) 2016-2018 IBM Corp. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "slirp.h" - -#include "ncsi-pkt.h" - -static uint32_t ncsi_calculate_checksum(uint8_t *data, int len) -{ - uint32_t checksum = 0; - int i; - - /* - * 32-bit unsigned sum of the NC-SI packet header and NC-SI packet - * payload interpreted as a series of 16-bit unsigned integer values. - */ - for (i = 0; i < len; i += 2) { - checksum += (((uint16_t) data[i]) << 8) + data[i+1]; - } - - checksum = (~checksum + 1); - return checksum; -} - -/* Get Capabilities */ -static int ncsi_rsp_handler_gc(struct ncsi_rsp_pkt_hdr *rnh) -{ - struct ncsi_rsp_gc_pkt *rsp = (struct ncsi_rsp_gc_pkt *)rnh; - - rsp->cap = htonl(~0); - rsp->bc_cap = htonl(~0); - rsp->mc_cap = htonl(~0); - rsp->buf_cap = htonl(~0); - rsp->aen_cap = htonl(~0); - rsp->vlan_mode = 0xff; - rsp->uc_cnt = 2; - return 0; -} - -/* Get Link status */ -static int ncsi_rsp_handler_gls(struct ncsi_rsp_pkt_hdr *rnh) -{ - struct ncsi_rsp_gls_pkt *rsp = (struct ncsi_rsp_gls_pkt *)rnh; - - rsp->status = htonl(0x1); - return 0; -} - -/* Get Parameters */ -static int ncsi_rsp_handler_gp(struct ncsi_rsp_pkt_hdr *rnh) -{ - struct ncsi_rsp_gp_pkt *rsp = (struct ncsi_rsp_gp_pkt *)rnh; - - /* no MAC address filters or VLAN filters on the channel */ - rsp->mac_cnt = 0; - rsp->mac_enable = 0; - rsp->vlan_cnt = 0; - rsp->vlan_enable = 0; - - return 0; -} - -static const struct ncsi_rsp_handler { - unsigned char type; - int payload; - int (*handler)(struct ncsi_rsp_pkt_hdr *rnh); -} ncsi_rsp_handlers[] = { { NCSI_PKT_RSP_CIS, 4, NULL }, - { NCSI_PKT_RSP_SP, 4, NULL }, - { NCSI_PKT_RSP_DP, 4, NULL }, - { NCSI_PKT_RSP_EC, 4, NULL }, - { NCSI_PKT_RSP_DC, 4, NULL }, - { NCSI_PKT_RSP_RC, 4, NULL }, - { NCSI_PKT_RSP_ECNT, 4, NULL }, - { NCSI_PKT_RSP_DCNT, 4, NULL }, - { NCSI_PKT_RSP_AE, 4, NULL }, - { NCSI_PKT_RSP_SL, 4, NULL }, - { NCSI_PKT_RSP_GLS, 16, ncsi_rsp_handler_gls }, - { NCSI_PKT_RSP_SVF, 4, NULL }, - { NCSI_PKT_RSP_EV, 4, NULL }, - { NCSI_PKT_RSP_DV, 4, NULL }, - { NCSI_PKT_RSP_SMA, 4, NULL }, - { NCSI_PKT_RSP_EBF, 4, NULL }, - { NCSI_PKT_RSP_DBF, 4, NULL }, - { NCSI_PKT_RSP_EGMF, 4, NULL }, - { NCSI_PKT_RSP_DGMF, 4, NULL }, - { NCSI_PKT_RSP_SNFC, 4, NULL }, - { NCSI_PKT_RSP_GVI, 40, NULL }, - { NCSI_PKT_RSP_GC, 32, ncsi_rsp_handler_gc }, - { NCSI_PKT_RSP_GP, 40, ncsi_rsp_handler_gp }, - { NCSI_PKT_RSP_GCPS, 172, NULL }, - { NCSI_PKT_RSP_GNS, 172, NULL }, - { NCSI_PKT_RSP_GNPTS, 172, NULL }, - { NCSI_PKT_RSP_GPS, 8, NULL }, - { NCSI_PKT_RSP_OEM, 0, NULL }, - { NCSI_PKT_RSP_PLDM, 0, NULL }, - { NCSI_PKT_RSP_GPUUID, 20, NULL } }; - -/* - * packet format : ncsi header + payload + checksum - */ -#define NCSI_MAX_PAYLOAD 172 -#define NCSI_MAX_LEN (sizeof(struct ncsi_pkt_hdr) + NCSI_MAX_PAYLOAD + 4) - -void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) -{ - const struct ncsi_pkt_hdr *nh = - (const struct ncsi_pkt_hdr *)(pkt + ETH_HLEN); - uint8_t ncsi_reply[ETH_HLEN + NCSI_MAX_LEN]; - struct ethhdr *reh = (struct ethhdr *)ncsi_reply; - struct ncsi_rsp_pkt_hdr *rnh = - (struct ncsi_rsp_pkt_hdr *)(ncsi_reply + ETH_HLEN); - const struct ncsi_rsp_handler *handler = NULL; - int i; - int ncsi_rsp_len = sizeof(*nh); - uint32_t checksum; - uint32_t *pchecksum; - - if (pkt_len < ETH_HLEN + sizeof(struct ncsi_pkt_hdr)) { - return; /* packet too short */ - } - - memset(ncsi_reply, 0, sizeof(ncsi_reply)); - - memset(reh->h_dest, 0xff, ETH_ALEN); - memset(reh->h_source, 0xff, ETH_ALEN); - reh->h_proto = htons(ETH_P_NCSI); - - for (i = 0; i < G_N_ELEMENTS(ncsi_rsp_handlers); i++) { - if (ncsi_rsp_handlers[i].type == nh->type + 0x80) { - handler = &ncsi_rsp_handlers[i]; - break; - } - } - - rnh->common.mc_id = nh->mc_id; - rnh->common.revision = NCSI_PKT_REVISION; - rnh->common.id = nh->id; - rnh->common.type = nh->type + 0x80; - rnh->common.channel = nh->channel; - - if (handler) { - rnh->common.length = htons(handler->payload); - rnh->code = htons(NCSI_PKT_RSP_C_COMPLETED); - rnh->reason = htons(NCSI_PKT_RSP_R_NO_ERROR); - - if (handler->handler) { - /* TODO: handle errors */ - handler->handler(rnh); - } - ncsi_rsp_len += handler->payload; - } else { - rnh->common.length = 0; - rnh->code = htons(NCSI_PKT_RSP_C_UNAVAILABLE); - rnh->reason = htons(NCSI_PKT_RSP_R_UNKNOWN); - } - - /* Add the optional checksum at the end of the frame. */ - checksum = ncsi_calculate_checksum((uint8_t *)rnh, ncsi_rsp_len); - pchecksum = (uint32_t *)((void *)rnh + ncsi_rsp_len); - *pchecksum = htonl(checksum); - ncsi_rsp_len += 4; - - slirp_send_packet_all(slirp, ncsi_reply, ETH_HLEN + ncsi_rsp_len); -} diff --git a/src/network/slirp/ndp_table.c b/src/network/slirp/ndp_table.c deleted file mode 100644 index fdb189d59..000000000 --- a/src/network/slirp/ndp_table.c +++ /dev/null @@ -1,98 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" - -void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, - uint8_t ethaddr[ETH_ALEN]) -{ - char addrstr[INET6_ADDRSTRLEN]; - NdpTable *ndp_table = &slirp->ndp_table; - int i; - char ethaddr_str[ETH_ADDRSTRLEN]; - - inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN); - - DEBUG_CALL("ndp_table_add"); - DEBUG_ARG("ip = %s", addrstr); - DEBUG_ARG("hw addr = %s", slirp_ether_ntoa(ethaddr, ethaddr_str, - sizeof(ethaddr_str))); - - if (IN6_IS_ADDR_MULTICAST(&ip_addr) || in6_zero(&ip_addr)) { - /* Do not register multicast or unspecified addresses */ - DEBUG_CALL(" abort: do not register multicast or unspecified address"); - return; - } - - /* Search for an entry */ - for (i = 0; i < NDP_TABLE_SIZE; i++) { - if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) { - DEBUG_CALL(" already in table: update the entry"); - /* Update the entry */ - memcpy(ndp_table->table[i].eth_addr, ethaddr, ETH_ALEN); - return; - } - } - - /* No entry found, create a new one */ - DEBUG_CALL(" create new entry"); - /* Save the first entry, it is the guest. */ - if (in6_zero(&ndp_table->guest_in6_addr)) { - ndp_table->guest_in6_addr = ip_addr; - } - ndp_table->table[ndp_table->next_victim].ip_addr = ip_addr; - memcpy(ndp_table->table[ndp_table->next_victim].eth_addr, ethaddr, - ETH_ALEN); - ndp_table->next_victim = (ndp_table->next_victim + 1) % NDP_TABLE_SIZE; -} - -bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr, - uint8_t out_ethaddr[ETH_ALEN]) -{ - char addrstr[INET6_ADDRSTRLEN]; - NdpTable *ndp_table = &slirp->ndp_table; - int i; - char ethaddr_str[ETH_ADDRSTRLEN]; - - inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN); - - DEBUG_CALL("ndp_table_search"); - DEBUG_ARG("ip = %s", addrstr); - - /* If unspecified address */ - if (in6_zero(&ip_addr)) { - /* return Ethernet broadcast address */ - memset(out_ethaddr, 0xff, ETH_ALEN); - return 1; - } - - /* Multicast address: fec0::abcd:efgh/8 -> 33:33:ab:cd:ef:gh */ - if (IN6_IS_ADDR_MULTICAST(&ip_addr)) { - out_ethaddr[0] = 0x33; - out_ethaddr[1] = 0x33; - out_ethaddr[2] = ip_addr.s6_addr[12]; - out_ethaddr[3] = ip_addr.s6_addr[13]; - out_ethaddr[4] = ip_addr.s6_addr[14]; - out_ethaddr[5] = ip_addr.s6_addr[15]; - DEBUG_ARG("multicast addr = %s", - slirp_ether_ntoa(out_ethaddr, ethaddr_str, - sizeof(ethaddr_str))); - return 1; - } - - for (i = 0; i < NDP_TABLE_SIZE; i++) { - if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) { - memcpy(out_ethaddr, ndp_table->table[i].eth_addr, ETH_ALEN); - DEBUG_ARG("found hw addr = %s", - slirp_ether_ntoa(out_ethaddr, ethaddr_str, - sizeof(ethaddr_str))); - return 1; - } - } - - DEBUG_CALL(" ip not found in table"); - return 0; -} diff --git a/src/network/slirp/sbuf.c b/src/network/slirp/sbuf.c deleted file mode 100644 index b35709170..000000000 --- a/src/network/slirp/sbuf.c +++ /dev/null @@ -1,168 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -static void sbappendsb(struct sbuf *sb, struct mbuf *m); - -void sbfree(struct sbuf *sb) -{ - g_free(sb->sb_data); -} - -bool sbdrop(struct sbuf *sb, size_t num) -{ - int limit = sb->sb_datalen / 2; - - g_warn_if_fail(num <= sb->sb_cc); - if (num > sb->sb_cc) - num = sb->sb_cc; - - sb->sb_cc -= num; - sb->sb_rptr += num; - if (sb->sb_rptr >= sb->sb_data + sb->sb_datalen) - sb->sb_rptr -= sb->sb_datalen; - - if (sb->sb_cc < limit && sb->sb_cc + num >= limit) { - return true; - } - - return false; -} - -void sbreserve(struct sbuf *sb, size_t size) -{ - sb->sb_wptr = sb->sb_rptr = sb->sb_data = g_realloc(sb->sb_data, size); - sb->sb_cc = 0; - sb->sb_datalen = size; -} - -/* - * Try and write() to the socket, whatever doesn't get written - * append to the buffer... for a host with a fast net connection, - * this prevents an unnecessary copy of the data - * (the socket is non-blocking, so we won't hang) - */ -void sbappend(struct socket *so, struct mbuf *m) -{ - int ret = 0; - - DEBUG_CALL("sbappend"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m->m_len = %d", m->m_len); - - /* Shouldn't happen, but... e.g. foreign host closes connection */ - if (m->m_len <= 0) { - m_free(m); - return; - } - - /* - * If there is urgent data, call sosendoob - * if not all was sent, sowrite will take care of the rest - * (The rest of this function is just an optimisation) - */ - if (so->so_urgc) { - sbappendsb(&so->so_rcv, m); - m_free(m); - sosendoob(so); - return; - } - - /* - * We only write if there's nothing in the buffer, - * ottherwise it'll arrive out of order, and hence corrupt - */ - if (!so->so_rcv.sb_cc) - ret = slirp_send(so, m->m_data, m->m_len, 0); - - if (ret <= 0) { - /* - * Nothing was written - * It's possible that the socket has closed, but - * we don't need to check because if it has closed, - * it will be detected in the normal way by soread() - */ - sbappendsb(&so->so_rcv, m); - } else if (ret != m->m_len) { - /* - * Something was written, but not everything.. - * sbappendsb the rest - */ - m->m_len -= ret; - m->m_data += ret; - sbappendsb(&so->so_rcv, m); - } /* else */ - /* Whatever happened, we free the mbuf */ - m_free(m); -} - -/* - * Copy the data from m into sb - * The caller is responsible to make sure there's enough room - */ -static void sbappendsb(struct sbuf *sb, struct mbuf *m) -{ - int len, n, nn; - - len = m->m_len; - - if (sb->sb_wptr < sb->sb_rptr) { - n = sb->sb_rptr - sb->sb_wptr; - if (n > len) - n = len; - memcpy(sb->sb_wptr, m->m_data, n); - } else { - /* Do the right edge first */ - n = sb->sb_data + sb->sb_datalen - sb->sb_wptr; - if (n > len) - n = len; - memcpy(sb->sb_wptr, m->m_data, n); - len -= n; - if (len) { - /* Now the left edge */ - nn = sb->sb_rptr - sb->sb_data; - if (nn > len) - nn = len; - memcpy(sb->sb_data, m->m_data + n, nn); - n += nn; - } - } - - sb->sb_cc += n; - sb->sb_wptr += n; - if (sb->sb_wptr >= sb->sb_data + sb->sb_datalen) - sb->sb_wptr -= sb->sb_datalen; -} - -/* - * Copy data from sbuf to a normal, straight buffer - * Don't update the sbuf rptr, this will be - * done in sbdrop when the data is acked - */ -void sbcopy(struct sbuf *sb, size_t off, size_t len, char *to) -{ - char *from; - - g_assert(len + off <= sb->sb_cc); - - from = sb->sb_rptr + off; - if (from >= sb->sb_data + sb->sb_datalen) - from -= sb->sb_datalen; - - if (from < sb->sb_wptr) { - memcpy(to, from, len); - } else { - /* re-use off */ - off = (sb->sb_data + sb->sb_datalen) - from; - if (off > len) - off = len; - memcpy(to, from, off); - len -= off; - if (len) - memcpy(to + off, sb->sb_data, len); - } -} diff --git a/src/network/slirp/sbuf.h b/src/network/slirp/sbuf.h deleted file mode 100644 index 01886fbd0..000000000 --- a/src/network/slirp/sbuf.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef SBUF_H -#define SBUF_H - -#define sbspace(sb) ((sb)->sb_datalen - (sb)->sb_cc) - -struct sbuf { - uint32_t sb_cc; /* actual chars in buffer */ - uint32_t sb_datalen; /* Length of data */ - char *sb_wptr; /* write pointer. points to where the next - * bytes should be written in the sbuf */ - char *sb_rptr; /* read pointer. points to where the next - * byte should be read from the sbuf */ - char *sb_data; /* Actual data */ -}; - -void sbfree(struct sbuf *sb); -bool sbdrop(struct sbuf *sb, size_t len); -void sbreserve(struct sbuf *sb, size_t size); -void sbappend(struct socket *sb, struct mbuf *mb); -void sbcopy(struct sbuf *sb, size_t off, size_t len, char *p); - -#endif diff --git a/src/network/slirp/slirp.c b/src/network/slirp/slirp.c deleted file mode 100644 index 0c2a20a9b..000000000 --- a/src/network/slirp/slirp.c +++ /dev/null @@ -1,1592 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * libslirp glue - * - * Copyright (c) 2004-2008 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "slirp.h" - - -#ifndef _WIN32 -#include -#endif - -/* https://gitlab.freedesktop.org/slirp/libslirp/issues/18 */ -#if defined(__NetBSD__) && defined(if_mtu) -#undef if_mtu -#endif - -#if defined(_WIN32) - -#define INITIAL_DNS_ADDR_BUF_SIZE 32 * 1024 -#define REALLOC_RETRIES 5 - -// Broadcast site local DNS resolvers. We do not use these because they are -// highly unlikely to be valid. -// https://www.ietf.org/proceedings/52/I-D/draft-ietf-ipngwg-dns-discovery-03.txt -static const struct in6_addr SITE_LOCAL_DNS_BROADCAST_ADDRS[] = { - { - {{ - 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 - }} - }, - { - {{ - 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 - }} - }, - { - {{ - 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - }} - }, -}; - -#endif - -int slirp_debug; - -/* Define to 1 if you want KEEPALIVE timers */ -bool slirp_do_keepalive; - -/* host loopback address */ -struct in_addr loopback_addr; -/* host loopback network mask */ -unsigned long loopback_mask; - -/* emulated hosts use the MAC addr 52:55:IP:IP:IP:IP */ -static const uint8_t special_ethaddr[ETH_ALEN] = { 0x52, 0x55, 0x00, - 0x00, 0x00, 0x00 }; - -unsigned curtime; - -static struct in_addr dns_addr; -static struct in6_addr dns6_addr; -static uint32_t dns6_scope_id; -static unsigned dns_addr_time; -static unsigned dns6_addr_time; - -#define TIMEOUT_FAST 2 /* milliseconds */ -#define TIMEOUT_SLOW 499 /* milliseconds */ -/* for the aging of certain requests like DNS */ -#define TIMEOUT_DEFAULT 1000 /* milliseconds */ - -#if defined(_WIN32) - -int get_dns_addr(struct in_addr *pdns_addr) -{ - FIXED_INFO *FixedInfo = NULL; - ULONG BufLen; - DWORD ret; - IP_ADDR_STRING *pIPAddr; - struct in_addr tmp_addr; - - if (dns_addr.s_addr != 0 && (curtime - dns_addr_time) < TIMEOUT_DEFAULT) { - *pdns_addr = dns_addr; - return 0; - } - - FixedInfo = (FIXED_INFO *)GlobalAlloc(GPTR, sizeof(FIXED_INFO)); - BufLen = sizeof(FIXED_INFO); - - if (ERROR_BUFFER_OVERFLOW == GetNetworkParams(FixedInfo, &BufLen)) { - if (FixedInfo) { - GlobalFree(FixedInfo); - FixedInfo = NULL; - } - FixedInfo = GlobalAlloc(GPTR, BufLen); - } - - if ((ret = GetNetworkParams(FixedInfo, &BufLen)) != ERROR_SUCCESS) { - printf("GetNetworkParams failed. ret = %08x\n", (unsigned)ret); - if (FixedInfo) { - GlobalFree(FixedInfo); - FixedInfo = NULL; - } - return -1; - } - - pIPAddr = &(FixedInfo->DnsServerList); - inet_aton(pIPAddr->IpAddress.String, &tmp_addr); - *pdns_addr = tmp_addr; - dns_addr = tmp_addr; - dns_addr_time = curtime; - if (FixedInfo) { - GlobalFree(FixedInfo); - FixedInfo = NULL; - } - return 0; -} - -int is_site_local_dns_broadcast(struct in6_addr *address) -{ - int i; - for (i = 0; i < G_N_ELEMENTS(SITE_LOCAL_DNS_BROADCAST_ADDRS); i++) { - if (in6_equal(address, &SITE_LOCAL_DNS_BROADCAST_ADDRS[i])) { - return 1; - } - } - return 0; -} - -void print_dns_v6_address(struct in6_addr address) -{ - char address_str[INET6_ADDRSTRLEN] = ""; - if (inet_ntop(AF_INET6, &address, address_str, INET6_ADDRSTRLEN) - == NULL) { - DEBUG_ERROR("Failed to stringify IPv6 address for logging."); - return; - } - DEBUG_CALL("IPv6 DNS server found: %s", address_str); -} - -// Gets the first valid DNS resolver with an IPv6 address. -// Ignores any site local broadcast DNS servers, as these -// are on deprecated addresses and not generally expected -// to work. Further details at: -// https://www.ietf.org/proceedings/52/I-D/draft-ietf-ipngwg-dns-discovery-03.txt -int get_ipv6_dns_server(struct in6_addr *dns_server_address, uint32_t *scope_id) -{ - PIP_ADAPTER_ADDRESSES addresses = NULL; - PIP_ADAPTER_ADDRESSES address = NULL; - IP_ADAPTER_DNS_SERVER_ADDRESS *dns_server = NULL; - struct sockaddr_in6 *dns_v6_addr = NULL; - - ULONG buf_size = INITIAL_DNS_ADDR_BUF_SIZE; - DWORD res = ERROR_BUFFER_OVERFLOW; - int i; - - for (i = 0; i < REALLOC_RETRIES; i++) { - // If non null, we hit buffer overflow, free it so we can try again. - if (addresses != NULL) { - g_free(addresses); - } - - addresses = g_malloc(buf_size); - res = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, - addresses, &buf_size); - - if (res != ERROR_BUFFER_OVERFLOW) { - break; - } - } - - if (res != NO_ERROR) { - DEBUG_ERROR("Failed to get IPv6 DNS addresses due to error %lX", res); - goto failure; - } - - address = addresses; - for (address = addresses; address != NULL; address = address->Next) { - for (dns_server = address->FirstDnsServerAddress; - dns_server != NULL; - dns_server = dns_server->Next) { - - if (dns_server->Address.lpSockaddr->sa_family != AF_INET6) { - continue; - } - - dns_v6_addr = (struct sockaddr_in6 *)dns_server->Address.lpSockaddr; - if (is_site_local_dns_broadcast(&dns_v6_addr->sin6_addr) == 0) { - print_dns_v6_address(dns_v6_addr->sin6_addr); - *dns_server_address = dns_v6_addr->sin6_addr; - *scope_id = dns_v6_addr->sin6_scope_id; - - g_free(addresses); - return 0; - } - } - } - - DEBUG_ERROR("No IPv6 DNS servers found.\n"); - -failure: - g_free(addresses); - return -1; -} - -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id) -{ - if (!in6_zero(&dns6_addr) && (curtime - dns6_addr_time) < TIMEOUT_DEFAULT) { - *pdns6_addr = dns6_addr; - *scope_id = dns6_scope_id; - return 0; - } - - if (get_ipv6_dns_server(pdns6_addr, scope_id) == 0) { - dns6_addr = *pdns6_addr; - dns6_addr_time = curtime; - dns6_scope_id = *scope_id; - return 0; - } - - return -1; -} - -static void winsock_cleanup(void) -{ - WSACleanup(); -} - -#elif defined(__APPLE__) - -#include - -static int get_dns_addr_cached(void *pdns_addr, void *cached_addr, - socklen_t addrlen, unsigned *cached_time) -{ - if (curtime - *cached_time < TIMEOUT_DEFAULT) { - memcpy(pdns_addr, cached_addr, addrlen); - return 0; - } - return 1; -} - -static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr, - socklen_t addrlen, - uint32_t *scope_id, uint32_t *cached_scope_id, - unsigned *cached_time) -{ - struct __res_state state; - union res_sockaddr_union servers[NI_MAXSERV]; - int count; - int found; - void *addr; - - // we only support IPv4 and IPv4, we assume it's one or the other - assert(af == AF_INET || af == AF_INET6); - - if (res_ninit(&state) != 0) { - return -1; - } - - count = res_getservers(&state, servers, NI_MAXSERV); - found = 0; - DEBUG_MISC("IP address of your DNS(s):"); - for (int i = 0; i < count; i++) { - if (af == servers[i].sin.sin_family) { - found++; - } - if (af == AF_INET) { - addr = &servers[i].sin.sin_addr; - } else { // af == AF_INET6 - addr = &servers[i].sin6.sin6_addr; - } - - // we use the first found entry - if (found == 1) { - memcpy(pdns_addr, addr, addrlen); - memcpy(cached_addr, addr, addrlen); - if (scope_id) { - *scope_id = 0; - } - if (cached_scope_id) { - *cached_scope_id = 0; - } - *cached_time = curtime; - } - - if (found > 3) { - DEBUG_MISC(" (more)"); - break; - } else if (slirp_debug & DBG_MISC) { - char s[INET6_ADDRSTRLEN]; - const char *res = inet_ntop(af, addr, s, sizeof(s)); - if (!res) { - res = " (string conversion error)"; - } - DEBUG_MISC(" %s", res); - } - } - - res_ndestroy(&state); - if (!found) - return -1; - return 0; -} - -int get_dns_addr(struct in_addr *pdns_addr) -{ - if (dns_addr.s_addr != 0) { - int ret; - ret = get_dns_addr_cached(pdns_addr, &dns_addr, sizeof(dns_addr), - &dns_addr_time); - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_libresolv(AF_INET, pdns_addr, &dns_addr, - sizeof(dns_addr), NULL, NULL, &dns_addr_time); -} - -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id) -{ - if (!in6_zero(&dns6_addr)) { - int ret; - ret = get_dns_addr_cached(pdns6_addr, &dns6_addr, sizeof(dns6_addr), - &dns6_addr_time); - if (ret == 0) { - *scope_id = dns6_scope_id; - } - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_libresolv(AF_INET6, pdns6_addr, &dns6_addr, - sizeof(dns6_addr), - scope_id, &dns6_scope_id, &dns6_addr_time); -} - -#else // !defined(_WIN32) && !defined(__APPLE__) - -#if defined(__HAIKU__) -#define RESOLV_CONF_PATH "/boot/system/settings/network/resolv.conf" -#else -#define RESOLV_CONF_PATH "/etc/resolv.conf" -#endif - -static int get_dns_addr_cached(void *pdns_addr, void *cached_addr, - socklen_t addrlen, struct stat *cached_stat, - unsigned *cached_time) -{ - struct stat old_stat; - if (curtime - *cached_time < TIMEOUT_DEFAULT) { - memcpy(pdns_addr, cached_addr, addrlen); - return 0; - } - old_stat = *cached_stat; - if (stat(RESOLV_CONF_PATH, cached_stat) != 0) { - return -1; - } - if (cached_stat->st_dev == old_stat.st_dev && - cached_stat->st_ino == old_stat.st_ino && - cached_stat->st_size == old_stat.st_size && - cached_stat->st_mtime == old_stat.st_mtime) { - memcpy(pdns_addr, cached_addr, addrlen); - return 0; - } - return 1; -} - -static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, - socklen_t addrlen, - uint32_t *scope_id, uint32_t *cached_scope_id, - unsigned *cached_time) -{ - char buff[512]; - char buff2[257]; - FILE *f; - int found = 0; - union { - struct in_addr dns_addr; - struct in6_addr dns6_addr; - } tmp_addr; - unsigned if_index; - - assert(sizeof(tmp_addr) >= addrlen); - f = fopen(RESOLV_CONF_PATH, "r"); - if (!f) - return -1; - - DEBUG_MISC("IP address of your DNS(s):"); - while (fgets(buff, 512, f) != NULL) { - if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { - char *c = strchr(buff2, '%'); - if (c) { - if_index = if_nametoindex(c + 1); - *c = '\0'; - } else { - if_index = 0; - } - - if (!inet_pton(af, buff2, &tmp_addr)) { - continue; - } - /* If it's the first one, set it to dns_addr */ - if (!found) { - memcpy(pdns_addr, &tmp_addr, addrlen); - memcpy(cached_addr, &tmp_addr, addrlen); - if (scope_id) { - *scope_id = if_index; - } - if (cached_scope_id) { - *cached_scope_id = if_index; - } - *cached_time = curtime; - } - - if (++found > 3) { - DEBUG_MISC(" (more)"); - break; - } else if (slirp_debug & DBG_MISC) { - char s[INET6_ADDRSTRLEN]; - const char *res = inet_ntop(af, &tmp_addr, s, sizeof(s)); - if (!res) { - res = " (string conversion error)"; - } - DEBUG_MISC(" %s", res); - } - } - } - fclose(f); - if (!found) - return -1; - return 0; -} - -int get_dns_addr(struct in_addr *pdns_addr) -{ - static struct stat dns_addr_stat; - - if (dns_addr.s_addr != 0) { - int ret; - ret = get_dns_addr_cached(pdns_addr, &dns_addr, sizeof(dns_addr), - &dns_addr_stat, &dns_addr_time); - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_resolv_conf(AF_INET, pdns_addr, &dns_addr, - sizeof(dns_addr), - NULL, NULL, &dns_addr_time); -} - -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id) -{ - static struct stat dns6_addr_stat; - - if (!in6_zero(&dns6_addr)) { - int ret; - ret = get_dns_addr_cached(pdns6_addr, &dns6_addr, sizeof(dns6_addr), - &dns6_addr_stat, &dns6_addr_time); - if (ret == 0) { - *scope_id = dns6_scope_id; - } - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_resolv_conf(AF_INET6, pdns6_addr, &dns6_addr, - sizeof(dns6_addr), - scope_id, &dns6_scope_id, &dns6_addr_time); -} - -#endif - -static void slirp_init_once(void) -{ - static int initialized; - const char *debug; -#ifdef _WIN32 - WSADATA Data; -#endif - - if (initialized) { - return; - } - initialized = 1; - -#ifdef _WIN32 - WSAStartup(MAKEWORD(2, 0), &Data); - atexit(winsock_cleanup); -#endif - - loopback_addr.s_addr = htonl(INADDR_LOOPBACK); - loopback_mask = htonl(IN_CLASSA_NET); - - debug = g_getenv("SLIRP_DEBUG"); - if (debug) { - const GDebugKey keys[] = { - { "call", DBG_CALL }, - { "misc", DBG_MISC }, - { "error", DBG_ERROR }, - { "tftp", DBG_TFTP }, - { "verbose_call", DBG_VERBOSE_CALL }, - }; - slirp_debug = g_parse_debug_string(debug, keys, G_N_ELEMENTS(keys)); - } -} - -static void ra_timer_handler_cb(void *opaque) -{ - Slirp *slirp = opaque; - - return ra_timer_handler(slirp, NULL); -} - -void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque) -{ -// g_return_if_fail(id >= 0 && id < SLIRP_TIMER_NUM); - - switch (id) { - case SLIRP_TIMER_RA: - return ra_timer_handler(slirp, cb_opaque); - default: - abort(); - } -} - -void *slirp_timer_new(Slirp *slirp, SlirpTimerId id, void *cb_opaque) -{ - g_return_val_if_fail(id >= 0 && id < SLIRP_TIMER_NUM, NULL); - - if (slirp->cfg_version >= 4 && slirp->cb->timer_new_opaque) { - return slirp->cb->timer_new_opaque(id, cb_opaque, slirp->opaque); - } - - switch (id) { - case SLIRP_TIMER_RA: - g_return_val_if_fail(cb_opaque == NULL, NULL); - return slirp->cb->timer_new(ra_timer_handler_cb, slirp, slirp->opaque); - - default: - abort(); - } -} - -Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, void *opaque) -{ - Slirp *slirp; - - g_return_val_if_fail(cfg != NULL, NULL); - g_return_val_if_fail(cfg->version >= SLIRP_CONFIG_VERSION_MIN, NULL); - g_return_val_if_fail(cfg->version <= SLIRP_CONFIG_VERSION_MAX, NULL); - g_return_val_if_fail(cfg->if_mtu >= IF_MTU_MIN || cfg->if_mtu == 0, NULL); - g_return_val_if_fail(cfg->if_mtu <= IF_MTU_MAX, NULL); - g_return_val_if_fail(cfg->if_mru >= IF_MRU_MIN || cfg->if_mru == 0, NULL); - g_return_val_if_fail(cfg->if_mru <= IF_MRU_MAX, NULL); - g_return_val_if_fail(!cfg->bootfile || - (strlen(cfg->bootfile) < - G_SIZEOF_MEMBER(struct bootp_t, bp_file)), NULL); - - slirp = g_malloc0(sizeof(Slirp)); - - slirp_init_once(); - - slirp->cfg_version = cfg->version; - slirp->opaque = opaque; - slirp->cb = callbacks; - slirp->grand = g_rand_new(); - slirp->restricted = cfg->restricted; - - slirp->in_enabled = cfg->in_enabled; - slirp->in6_enabled = cfg->in6_enabled; - - if_init(slirp); - ip_init(slirp); - - m_init(slirp); - - slirp->vnetwork_addr = cfg->vnetwork; - slirp->vnetwork_mask = cfg->vnetmask; - slirp->vhost_addr = cfg->vhost; - slirp->vprefix_addr6 = cfg->vprefix_addr6; - slirp->vprefix_len = cfg->vprefix_len; - slirp->vhost_addr6 = cfg->vhost6; - if (cfg->vhostname) { - slirp_pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname), - cfg->vhostname); - } - slirp->tftp_prefix = g_strdup(cfg->tftp_path); - slirp->bootp_filename = g_strdup(cfg->bootfile); - slirp->vdomainname = g_strdup(cfg->vdomainname); - slirp->vdhcp_startaddr = cfg->vdhcp_start; - slirp->vnameserver_addr = cfg->vnameserver; - slirp->vnameserver_addr6 = cfg->vnameserver6; - slirp->tftp_server_name = g_strdup(cfg->tftp_server_name); - - if (cfg->vdnssearch) { - translate_dnssearch(slirp, cfg->vdnssearch); - } - slirp->if_mtu = cfg->if_mtu == 0 ? IF_MTU_DEFAULT : cfg->if_mtu; - slirp->if_mru = cfg->if_mru == 0 ? IF_MRU_DEFAULT : cfg->if_mru; - slirp->disable_host_loopback = cfg->disable_host_loopback; - slirp->enable_emu = cfg->enable_emu; - - if (cfg->version >= 2) { - slirp->outbound_addr = cfg->outbound_addr; - slirp->outbound_addr6 = cfg->outbound_addr6; - } else { - slirp->outbound_addr = NULL; - slirp->outbound_addr6 = NULL; - } - - if (cfg->version >= 3) { - slirp->disable_dns = cfg->disable_dns; - } else { - slirp->disable_dns = false; - } - - if (cfg->version >= 4) { - slirp->disable_dhcp = cfg->disable_dhcp; - } else { - slirp->disable_dhcp = false; - } - - if (slirp->cfg_version >= 4 && slirp->cb->init_completed) { - slirp->cb->init_completed(slirp, slirp->opaque); - } - - ip6_post_init(slirp); - return slirp; -} - -Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, - struct in_addr vnetmask, struct in_addr vhost, - bool in6_enabled, struct in6_addr vprefix_addr6, - uint8_t vprefix_len, struct in6_addr vhost6, - const char *vhostname, const char *tftp_server_name, - const char *tftp_path, const char *bootfile, - struct in_addr vdhcp_start, struct in_addr vnameserver, - struct in6_addr vnameserver6, const char **vdnssearch, - const char *vdomainname, const SlirpCb *callbacks, - void *opaque) -{ - SlirpConfig cfg; - memset(&cfg, 0, sizeof(cfg)); - cfg.version = 1; - cfg.restricted = restricted; - cfg.in_enabled = in_enabled; - cfg.vnetwork = vnetwork; - cfg.vnetmask = vnetmask; - cfg.vhost = vhost; - cfg.in6_enabled = in6_enabled; - cfg.vprefix_addr6 = vprefix_addr6; - cfg.vprefix_len = vprefix_len; - cfg.vhost6 = vhost6; - cfg.vhostname = vhostname; - cfg.tftp_server_name = tftp_server_name; - cfg.tftp_path = tftp_path; - cfg.bootfile = bootfile; - cfg.vdhcp_start = vdhcp_start; - cfg.vnameserver = vnameserver; - cfg.vnameserver6 = vnameserver6; - cfg.vdnssearch = vdnssearch; - cfg.vdomainname = vdomainname; - return slirp_new(&cfg, callbacks, opaque); -} - -void slirp_cleanup(Slirp *slirp) -{ - struct gfwd_list *e, *next; - - for (e = slirp->guestfwd_list; e; e = next) { - next = e->ex_next; - g_free(e->ex_exec); - g_free(e->ex_unix); - g_free(e); - } - - ip_cleanup(slirp); - ip6_cleanup(slirp); - m_cleanup(slirp); - - g_rand_free(slirp->grand); - - g_free(slirp->vdnssearch); - g_free(slirp->tftp_prefix); - g_free(slirp->bootp_filename); - g_free(slirp->vdomainname); - g_free(slirp); -} - -#define CONN_CANFSEND(so) \ - (((so)->so_state & (SS_FCANTSENDMORE | SS_ISFCONNECTED)) == SS_ISFCONNECTED) -#define CONN_CANFRCV(so) \ - (((so)->so_state & (SS_FCANTRCVMORE | SS_ISFCONNECTED)) == SS_ISFCONNECTED) - -static void slirp_update_timeout(Slirp *slirp, uint32_t *timeout) -{ - uint32_t t; - - if (*timeout <= TIMEOUT_FAST) { - return; - } - - t = MIN(1000, *timeout); - - /* If we have tcp timeout with slirp, then we will fill @timeout with - * more precise value. - */ - if (slirp->time_fasttimo) { - *timeout = TIMEOUT_FAST; - return; - } - if (slirp->do_slowtimo) { - t = MIN(TIMEOUT_SLOW, t); - } - *timeout = t; -} - -void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout, - SlirpAddPollCb add_poll, void *opaque) -{ - struct socket *so, *so_next; - - /* - * First, TCP sockets - */ - - /* - * *_slowtimo needs calling if there are IP fragments - * in the fragment queue, or there are TCP connections active - */ - slirp->do_slowtimo = ((slirp->tcb.so_next != &slirp->tcb) || - (&slirp->ipq.ip_link != slirp->ipq.ip_link.next)); - - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so_next) { - int events = 0; - - so_next = so->so_next; - - so->pollfds_idx = -1; - - /* - * See if we need a tcp_fasttimo - */ - if (slirp->time_fasttimo == 0 && so->so_tcpcb->t_flags & TF_DELACK) { - slirp->time_fasttimo = curtime; /* Flag when want a fasttimo */ - } - - /* - * NOFDREF can include still connecting to local-host, - * newly socreated() sockets etc. Don't want to select these. - */ - if (so->so_state & SS_NOFDREF || so->s == -1) { - continue; - } - - /* - * Set for reading sockets which are accepting - */ - if (so->so_state & SS_FACCEPTCONN) { - so->pollfds_idx = add_poll( - so->s, SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); - continue; - } - - /* - * Set for writing sockets which are connecting - */ - if (so->so_state & SS_ISFCONNECTING) { - so->pollfds_idx = - add_poll(so->s, SLIRP_POLL_OUT | SLIRP_POLL_ERR, opaque); - continue; - } - - /* - * Set for writing if we are connected, can send more, and - * we have something to send - */ - if (CONN_CANFSEND(so) && so->so_rcv.sb_cc) { - events |= SLIRP_POLL_OUT | SLIRP_POLL_ERR; - } - - /* - * Set for reading (and urgent data) if we are connected, can - * receive more, and we have room for it. - * - * If sb is already half full, we will wait for the guest to consume it, - * and notify again in sbdrop() when the sb becomes less than half full. - */ - if (CONN_CANFRCV(so) && - (so->so_snd.sb_cc < (so->so_snd.sb_datalen / 2))) { - events |= SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR | - SLIRP_POLL_PRI; - } - - if (events) { - so->pollfds_idx = add_poll(so->s, events, opaque); - } - } - - /* - * UDP sockets - */ - for (so = slirp->udb.so_next; so != &slirp->udb; so = so_next) { - so_next = so->so_next; - - so->pollfds_idx = -1; - - /* - * See if it's timed out - */ - if (so->so_expire) { - if (so->so_expire <= curtime) { - udp_detach(so); - continue; - } else { - slirp->do_slowtimo = true; /* Let socket expire */ - } - } - - /* - * When UDP packets are received from over the - * link, they're sendto()'d straight away, so - * no need for setting for writing - * Limit the number of packets queued by this session - * to 4. Note that even though we try and limit this - * to 4 packets, the session could have more queued - * if the packets needed to be fragmented - * (XXX <= 4 ?) - */ - if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <= 4) { - so->pollfds_idx = add_poll( - so->s, SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); - } - } - - /* - * ICMP sockets - */ - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so_next) { - so_next = so->so_next; - - so->pollfds_idx = -1; - - /* - * See if it's timed out - */ - if (so->so_expire) { - if (so->so_expire <= curtime) { - icmp_detach(so); - continue; - } else { - slirp->do_slowtimo = true; /* Let socket expire */ - } - } - - if (so->so_state & SS_ISFCONNECTED) { - so->pollfds_idx = add_poll( - so->s, SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); - } - } - - slirp_update_timeout(slirp, timeout); -} - -void slirp_pollfds_poll(Slirp *slirp, int select_error, - SlirpGetREventsCb get_revents, void *opaque) -{ - struct socket *so, *so_next; - int ret; - - curtime = slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS; - - /* - * See if anything has timed out - */ - if (slirp->time_fasttimo && - ((curtime - slirp->time_fasttimo) >= TIMEOUT_FAST)) { - tcp_fasttimo(slirp); - slirp->time_fasttimo = 0; - } - if (slirp->do_slowtimo && - ((curtime - slirp->last_slowtimo) >= TIMEOUT_SLOW)) { - ip_slowtimo(slirp); - tcp_slowtimo(slirp); - slirp->last_slowtimo = curtime; - } - - /* - * Check sockets - */ - if (!select_error) { - /* - * Check TCP sockets - */ - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so_next) { - int revents; - - so_next = so->so_next; - - revents = 0; - if (so->pollfds_idx != -1) { - revents = get_revents(so->pollfds_idx, opaque); - } - - if (so->so_state & SS_NOFDREF || so->s == -1) { - continue; - } - -#ifndef __APPLE__ - /* - * Check for URG data - * This will soread as well, so no need to - * test for SLIRP_POLL_IN below if this succeeds. - * - * This is however disabled on MacOS, which apparently always - * reports data as PRI when it is the last data of the - * connection. We would then report it out of band, which the guest - * would most probably not be ready for. - */ - if (revents & SLIRP_POLL_PRI) { - ret = sorecvoob(so); - if (ret < 0) { - /* Socket error might have resulted in the socket being - * removed, do not try to do anything more with it. */ - continue; - } - } - /* - * Check sockets for reading - */ - else -#endif - if (revents & - (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR | SLIRP_POLL_PRI)) { - /* - * Check for incoming connections - */ - if (so->so_state & SS_FACCEPTCONN) { - tcp_connect(so); - continue; - } /* else */ - ret = soread(so); - - /* Output it if we read something */ - if (ret > 0) { - tcp_output(sototcpcb(so)); - } - if (ret < 0) { - /* Socket error might have resulted in the socket being - * removed, do not try to do anything more with it. */ - continue; - } - } - - /* - * Check sockets for writing - */ - if (!(so->so_state & SS_NOFDREF) && - (revents & (SLIRP_POLL_OUT | SLIRP_POLL_ERR))) { - /* - * Check for non-blocking, still-connecting sockets - */ - if (so->so_state & SS_ISFCONNECTING) { - /* Connected */ - so->so_state &= ~SS_ISFCONNECTING; - - ret = send(so->s, (const void *)&ret, 0, 0); - if (ret < 0) { - /* XXXXX Must fix, zero bytes is a NOP */ - if (errno == EAGAIN || errno == EWOULDBLOCK || - errno == EINPROGRESS || errno == ENOTCONN) { - continue; - } - - /* else failed */ - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; - } - /* else so->so_state &= ~SS_ISFCONNECTING; */ - - /* - * Continue tcp_input - */ - tcp_input((struct mbuf *)NULL, sizeof(struct ip), so, - so->so_ffamily); - /* continue; */ - } else { - ret = sowrite(so); - if (ret > 0) { - /* Call tcp_output in case we need to send a window - * update to the guest, otherwise it will be stuck - * until it sends a window probe. */ - tcp_output(sototcpcb(so)); - } - } - } - } - - /* - * Now UDP sockets. - * Incoming packets are sent straight away, they're not buffered. - * Incoming UDP data isn't buffered either. - */ - for (so = slirp->udb.so_next; so != &slirp->udb; so = so_next) { - int revents; - - so_next = so->so_next; - - revents = 0; - if (so->pollfds_idx != -1) { - revents = get_revents(so->pollfds_idx, opaque); - } - - if (so->s != -1 && - (revents & (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR))) { - sorecvfrom(so); - } - } - - /* - * Check incoming ICMP relies. - */ - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so_next) { - int revents; - - so_next = so->so_next; - - revents = 0; - if (so->pollfds_idx != -1) { - revents = get_revents(so->pollfds_idx, opaque); - } - - if (so->s != -1 && - (revents & (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR))) { - icmp_receive(so); - } - } - } - - if_start(slirp); -} - -static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) -{ - const struct slirp_arphdr *ah = - (const struct slirp_arphdr *)(pkt + ETH_HLEN); - uint8_t arp_reply[MAX(ETH_HLEN + sizeof(struct slirp_arphdr), 64)]; - struct ethhdr *reh = (struct ethhdr *)arp_reply; - struct slirp_arphdr *rah = (struct slirp_arphdr *)(arp_reply + ETH_HLEN); - int ar_op; - struct gfwd_list *ex_ptr; - - if (!slirp->in_enabled) { - return; - } - - if (pkt_len < ETH_HLEN + sizeof(struct slirp_arphdr)) { - return; /* packet too short */ - } - - ar_op = ntohs(ah->ar_op); - switch (ar_op) { - case ARPOP_REQUEST: - if (ah->ar_tip == ah->ar_sip) { - /* Gratuitous ARP */ - arp_table_add(slirp, ah->ar_sip, ah->ar_sha); - return; - } - - if ((ah->ar_tip & slirp->vnetwork_mask.s_addr) == - slirp->vnetwork_addr.s_addr) { - if (ah->ar_tip == slirp->vnameserver_addr.s_addr || - ah->ar_tip == slirp->vhost_addr.s_addr) - goto arp_ok; - /* TODO: IPv6 */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; - ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_addr.s_addr == ah->ar_tip) - goto arp_ok; - } - return; - arp_ok: - memset(arp_reply, 0, sizeof(arp_reply)); - - arp_table_add(slirp, ah->ar_sip, ah->ar_sha); - - /* ARP request for alias/dns mac address */ - memcpy(reh->h_dest, pkt + ETH_ALEN, ETH_ALEN); - memcpy(reh->h_source, special_ethaddr, ETH_ALEN - 4); - memcpy(&reh->h_source[2], &ah->ar_tip, 4); - reh->h_proto = htons(ETH_P_ARP); - - rah->ar_hrd = htons(1); - rah->ar_pro = htons(ETH_P_IP); - rah->ar_hln = ETH_ALEN; - rah->ar_pln = 4; - rah->ar_op = htons(ARPOP_REPLY); - memcpy(rah->ar_sha, reh->h_source, ETH_ALEN); - rah->ar_sip = ah->ar_tip; - memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN); - rah->ar_tip = ah->ar_sip; - slirp_send_packet_all(slirp, arp_reply, sizeof(arp_reply)); - } - break; - case ARPOP_REPLY: - arp_table_add(slirp, ah->ar_sip, ah->ar_sha); - break; - default: - break; - } -} - -void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) -{ - struct mbuf *m; - int proto; - - if (pkt_len < ETH_HLEN) - return; - - proto = (((uint16_t)pkt[12]) << 8) + pkt[13]; - switch (proto) { - case ETH_P_ARP: - arp_input(slirp, pkt, pkt_len); - break; - case ETH_P_IP: - case ETH_P_IPV6: - m = m_get(slirp); - if (!m) - return; - /* Note: we add 2 to align the IP header on 4 bytes, - * and add the margin for the tcpiphdr overhead */ - if (M_FREEROOM(m) < pkt_len + TCPIPHDR_DELTA + 2) { - m_inc(m, pkt_len + TCPIPHDR_DELTA + 2); - } - m->m_len = pkt_len + TCPIPHDR_DELTA + 2; - memcpy(m->m_data + TCPIPHDR_DELTA + 2, pkt, pkt_len); - - m->m_data += TCPIPHDR_DELTA + 2 + ETH_HLEN; - m->m_len -= TCPIPHDR_DELTA + 2 + ETH_HLEN; - - if (proto == ETH_P_IP) { - ip_input(m); - } else if (proto == ETH_P_IPV6) { - ip6_input(m); - } - break; - - case ETH_P_NCSI: - ncsi_input(slirp, pkt, pkt_len); - break; - - default: - break; - } -} - -/* Prepare the IPv4 packet to be sent to the ethernet device. Returns 1 if no - * packet should be sent, 0 if the packet must be re-queued, 2 if the packet - * is ready to go. - */ -static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, - uint8_t ethaddr[ETH_ALEN]) -{ - const struct ip *iph = (const struct ip *)ifm->m_data; - - if (!arp_table_search(slirp, iph->ip_dst.s_addr, ethaddr)) { - uint8_t arp_req[ETH_HLEN + sizeof(struct slirp_arphdr)]; - struct ethhdr *reh = (struct ethhdr *)arp_req; - struct slirp_arphdr *rah = (struct slirp_arphdr *)(arp_req + ETH_HLEN); - - if (!ifm->resolution_requested) { - /* If the client addr is not known, send an ARP request */ - memset(reh->h_dest, 0xff, ETH_ALEN); - memcpy(reh->h_source, special_ethaddr, ETH_ALEN - 4); - memcpy(&reh->h_source[2], &slirp->vhost_addr, 4); - reh->h_proto = htons(ETH_P_ARP); - rah->ar_hrd = htons(1); - rah->ar_pro = htons(ETH_P_IP); - rah->ar_hln = ETH_ALEN; - rah->ar_pln = 4; - rah->ar_op = htons(ARPOP_REQUEST); - - /* source hw addr */ - memcpy(rah->ar_sha, special_ethaddr, ETH_ALEN - 4); - memcpy(&rah->ar_sha[2], &slirp->vhost_addr, 4); - - /* source IP */ - rah->ar_sip = slirp->vhost_addr.s_addr; - - /* target hw addr (none) */ - memset(rah->ar_tha, 0, ETH_ALEN); - - /* target IP */ - rah->ar_tip = iph->ip_dst.s_addr; - slirp->client_ipaddr = iph->ip_dst; - slirp_send_packet_all(slirp, arp_req, sizeof(arp_req)); - ifm->resolution_requested = true; - - /* Expire request and drop outgoing packet after 1 second */ - ifm->expiration_date = - slirp->cb->clock_get_ns(slirp->opaque) + 1000000000ULL; - } - return 0; - } else { - memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 4); - /* XXX: not correct */ - memcpy(&eh->h_source[2], &slirp->vhost_addr, 4); - eh->h_proto = htons(ETH_P_IP); - - /* Send this */ - return 2; - } -} - -/* Prepare the IPv6 packet to be sent to the ethernet device. Returns 1 if no - * packet should be sent, 0 if the packet must be re-queued, 2 if the packet - * is ready to go. - */ -static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, - uint8_t ethaddr[ETH_ALEN]) -{ - const struct ip6 *ip6h = mtod(ifm, const struct ip6 *); - if (!ndp_table_search(slirp, ip6h->ip_dst, ethaddr)) { - if (!ifm->resolution_requested) { - ndp_send_ns(slirp, ip6h->ip_dst); - ifm->resolution_requested = true; - ifm->expiration_date = - slirp->cb->clock_get_ns(slirp->opaque) + 1000000000ULL; - } - return 0; - } else { - eh->h_proto = htons(ETH_P_IPV6); - in6_compute_ethaddr(ip6h->ip_src, eh->h_source); - - /* Send this */ - return 2; - } -} - -/* Output the IP packet to the ethernet device. Returns 0 if the packet must be - * re-queued. - */ -int if_encap(Slirp *slirp, struct mbuf *ifm) -{ - uint8_t buf[IF_MTU_MAX + 100]; - struct ethhdr *eh = (struct ethhdr *)buf; - uint8_t ethaddr[ETH_ALEN]; - const struct ip *iph = (const struct ip *)ifm->m_data; - int ret; -// char ethaddr_str[ETH_ADDRSTRLEN]; - - if (ifm->m_len + ETH_HLEN > sizeof(buf)) { - return 1; - } - - switch (iph->ip_v) { - case IPVERSION: - ret = if_encap4(slirp, ifm, eh, ethaddr); - if (ret < 2) { - return ret; - } - break; - - case IP6VERSION: - ret = if_encap6(slirp, ifm, eh, ethaddr); - if (ret < 2) { - return ret; - } - break; - - default: - g_assert_not_reached(); - } - - memcpy(eh->h_dest, ethaddr, ETH_ALEN); -/* - DEBUG_ARG("src = %s", slirp_ether_ntoa(eh->h_source, ethaddr_str, - sizeof(ethaddr_str))); - DEBUG_ARG("dst = %s", slirp_ether_ntoa(eh->h_dest, ethaddr_str, - sizeof(ethaddr_str))); -*/ - memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len); - slirp_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN); - return 1; -} - -/* Drop host forwarding rule, return 0 if found. */ -int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port) -{ - struct socket *so; - struct socket *head = (is_udp ? &slirp->udb : &slirp->tcb); - struct sockaddr_in addr; - int port = htons(host_port); - socklen_t addr_len; - - for (so = head->so_next; so != head; so = so->so_next) { - addr_len = sizeof(addr); - if ((so->so_state & SS_HOSTFWD) && - getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 && - addr_len == sizeof(addr) && - addr.sin_family == AF_INET && - addr.sin_addr.s_addr == host_addr.s_addr && - addr.sin_port == port) { - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); - return 0; - } - } - - return -1; -} - -int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port, struct in_addr guest_addr, int guest_port) -{ - if (!guest_addr.s_addr) { - guest_addr = slirp->vdhcp_startaddr; - } - if (is_udp) { - if (!udp_listen(slirp, host_addr.s_addr, htons(host_port), - guest_addr.s_addr, htons(guest_port), SS_HOSTFWD)) - return -1; - } else { - if (!tcp_listen(slirp, host_addr.s_addr, htons(host_port), - guest_addr.s_addr, htons(guest_port), SS_HOSTFWD)) - return -1; - } - return 0; -} - -int slirp_remove_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - int flags) -{ - struct socket *so; - struct socket *head = (flags & SLIRP_HOSTFWD_UDP ? &slirp->udb : &slirp->tcb); - struct sockaddr_storage addr; - socklen_t addr_len; - - for (so = head->so_next; so != head; so = so->so_next) { - addr_len = sizeof(addr); - if ((so->so_state & SS_HOSTFWD) && - getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 && - sockaddr_equal(&addr, (const struct sockaddr_storage *) haddr)) { - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); - return 0; - } - } - - return -1; -} - -int slirp_add_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *gaddr, socklen_t gaddrlen, - int flags) -{ - struct sockaddr_in gdhcp_addr; - int fwd_flags = SS_HOSTFWD; - - if (flags & SLIRP_HOSTFWD_V6ONLY) - fwd_flags |= SS_HOSTFWD_V6ONLY; - - if (gaddr->sa_family == AF_INET) { - const struct sockaddr_in *gaddr_in = (const struct sockaddr_in *) gaddr; - - if (gaddrlen < sizeof(struct sockaddr_in)) { - errno = EINVAL; - return -1; - } - - if (!gaddr_in->sin_addr.s_addr) { - gdhcp_addr = *gaddr_in; - gdhcp_addr.sin_addr = slirp->vdhcp_startaddr; - gaddr = (struct sockaddr *) &gdhcp_addr; - gaddrlen = sizeof(gdhcp_addr); - } - } else { - if (gaddrlen < sizeof(struct sockaddr_in6)) { - errno = EINVAL; - return -1; - } - - /* - * Libslirp currently only provides a stateless DHCPv6 server, thus - * we can't translate "addr-any" to the guest here. Instead, we defer - * performing the translation to when it's needed. See - * soassign_guest_addr_if_needed(). - */ - } - - if (flags & SLIRP_HOSTFWD_UDP) { - if (!udpx_listen(slirp, haddr, haddrlen, - gaddr, gaddrlen, - fwd_flags)) - return -1; - } else { - if (!tcpx_listen(slirp, haddr, haddrlen, - gaddr, gaddrlen, - fwd_flags)) - return -1; - } - return 0; -} - -/* TODO: IPv6 */ -static bool check_guestfwd(Slirp *slirp, struct in_addr *guest_addr, - int guest_port) -{ - struct gfwd_list *tmp_ptr; - - if (!guest_addr->s_addr) { - guest_addr->s_addr = slirp->vnetwork_addr.s_addr | - (htonl(0x0204) & ~slirp->vnetwork_mask.s_addr); - } - if ((guest_addr->s_addr & slirp->vnetwork_mask.s_addr) != - slirp->vnetwork_addr.s_addr || - guest_addr->s_addr == slirp->vhost_addr.s_addr || - guest_addr->s_addr == slirp->vnameserver_addr.s_addr) { - return false; - } - - /* check if the port is "bound" */ - for (tmp_ptr = slirp->guestfwd_list; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) { - if (guest_port == tmp_ptr->ex_fport && - guest_addr->s_addr == tmp_ptr->ex_addr.s_addr) - return false; - } - - return true; -} - -int slirp_add_exec(Slirp *slirp, const char *cmdline, - struct in_addr *guest_addr, int guest_port) -{ - if (!check_guestfwd(slirp, guest_addr, guest_port)) { - return -1; - } - - add_exec(&slirp->guestfwd_list, cmdline, *guest_addr, htons(guest_port)); - return 0; -} - -int slirp_add_unix(Slirp *slirp, const char *unixsock, - struct in_addr *guest_addr, int guest_port) -{ -#ifdef G_OS_UNIX - if (!check_guestfwd(slirp, guest_addr, guest_port)) { - return -1; - } - - add_unix(&slirp->guestfwd_list, unixsock, *guest_addr, htons(guest_port)); - return 0; -#else - g_warn_if_reached(); - return -1; -#endif -} - -int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque, - struct in_addr *guest_addr, int guest_port) -{ - if (!check_guestfwd(slirp, guest_addr, guest_port)) { - return -1; - } - - add_guestfwd(&slirp->guestfwd_list, write_cb, opaque, *guest_addr, - htons(guest_port)); - return 0; -} - -int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr, - int guest_port) -{ - return remove_guestfwd(&slirp->guestfwd_list, guest_addr, - htons(guest_port)); -} - -ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags) -{ - if (so->s == -1 && so->guestfwd) { - /* XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks */ - so->guestfwd->write_cb(buf, len, so->guestfwd->opaque); - return len; - } - - if (so->s == -1) { - /* - * This should in theory not happen but it is hard to be - * sure because some code paths will end up with so->s == -1 - * on a failure but don't dispose of the struct socket. - * Check specifically, so we don't pass -1 to send(). - */ - errno = EBADF; - return -1; - } - - return send(so->s, buf, len, flags); -} - -struct socket *slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, - int guest_port) -{ - struct socket *so; - - /* TODO: IPv6 */ - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so->so_next) { - if (so->so_faddr.s_addr == guest_addr.s_addr && - htons(so->so_fport) == guest_port) { - return so; - } - } - return NULL; -} - -size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr, - int guest_port) -{ - struct iovec iov[2]; - struct socket *so; - - so = slirp_find_ctl_socket(slirp, guest_addr, guest_port); - - if (!so || so->so_state & SS_NOFDREF) { - return 0; - } - - if (!CONN_CANFRCV(so) || so->so_snd.sb_cc >= (so->so_snd.sb_datalen / 2)) { - /* If the sb is already half full, we will wait for the guest to consume it, - * and notify again in sbdrop() when the sb becomes less than half full. */ - return 0; - } - - return sopreprbuf(so, iov, NULL); -} - -void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, - const uint8_t *buf, int size) -{ - int ret; - struct socket *so = slirp_find_ctl_socket(slirp, guest_addr, guest_port); - - if (!so) - return; - - ret = soreadbuf(so, (const char *)buf, size); - - if (ret > 0) - tcp_output(sototcpcb(so)); -} - -void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len) -{ - ssize_t ret = slirp->cb->send_packet(buf, len, slirp->opaque); - - if (ret < 0) { - g_critical("Failed to send packet, ret: %ld", (long)ret); - } else if (ret < len) { - DEBUG_ERROR("send_packet() didn't send all data: %ld < %lu", (long)ret, - (unsigned long)len); - } -} diff --git a/src/network/slirp/slirp.h b/src/network/slirp/slirp.h deleted file mode 100644 index e50c2ffe4..000000000 --- a/src/network/slirp/slirp.h +++ /dev/null @@ -1,293 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef SLIRP_H -#define SLIRP_H - -#ifdef _WIN32 - -/* as defined in sdkddkver.h */ -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 /* Windows Vista */ -#endif -/* reduces the number of implicitly included headers */ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include -#include -#include -#include -#include - -#else -#define O_BINARY 0 -#endif - -#ifndef _WIN32 -#include -#include -#include -#include -#include -#endif - -#ifdef __APPLE__ -#include -#endif - -#include "debug.h" -#include "util.h" - -#include "libslirp.h" -#include "ip.h" -#include "ip6.h" -#include "tcp.h" -#include "tcp_timer.h" -#include "tcp_var.h" -#include "tcpip.h" -#include "udp.h" -#include "ip_icmp.h" -#include "ip6_icmp.h" -#include "mbuf.h" -#include "sbuf.h" -#include "socket.h" -#include "if.h" -#include "main.h" -#include "misc.h" - -#include "bootp.h" -#include "tftp.h" - -#define ARPOP_REQUEST 1 /* ARP request */ -#define ARPOP_REPLY 2 /* ARP reply */ - -struct ethhdr { - unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ - unsigned char h_source[ETH_ALEN]; /* source ether addr */ - unsigned short h_proto; /* packet type ID field */ -}; - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct slirp_arphdr { - unsigned short ar_hrd; /* format of hardware address */ - unsigned short ar_pro; /* format of protocol address */ - unsigned char ar_hln; /* length of hardware address */ - unsigned char ar_pln; /* length of protocol address */ - unsigned short ar_op; /* ARP opcode (command) */ - - /* - * Ethernet looks like this : This bit is variable sized however... - */ - uint8_t ar_sha[ETH_ALEN]; /* sender hardware address */ - uint32_t ar_sip; /* sender IP address */ - uint8_t ar_tha[ETH_ALEN]; /* target hardware address */ - uint32_t ar_tip; /* target IP address */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#define ARP_TABLE_SIZE 16 - -typedef struct ArpTable { - struct slirp_arphdr table[ARP_TABLE_SIZE]; - int next_victim; -} ArpTable; - -void arp_table_add(Slirp *slirp, uint32_t ip_addr, - const uint8_t ethaddr[ETH_ALEN]); - -bool arp_table_search(Slirp *slirp, uint32_t ip_addr, - uint8_t out_ethaddr[ETH_ALEN]); - -struct ndpentry { - uint8_t eth_addr[ETH_ALEN]; /* sender hardware address */ - struct in6_addr ip_addr; /* sender IP address */ -}; - -#define NDP_TABLE_SIZE 16 - -typedef struct NdpTable { - struct ndpentry table[NDP_TABLE_SIZE]; - /* - * The table is a cache with old entries overwritten when the table fills. - * Preserve the first entry: it is the guest, which is needed for lazy - * hostfwd guest address assignment. - */ - struct in6_addr guest_in6_addr; - int next_victim; -} NdpTable; - -void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, - uint8_t ethaddr[ETH_ALEN]); -bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr, - uint8_t out_ethaddr[ETH_ALEN]); - -struct Slirp { - int cfg_version; - - unsigned time_fasttimo; - unsigned last_slowtimo; - bool do_slowtimo; - - bool in_enabled, in6_enabled; - - /* virtual network configuration */ - struct in_addr vnetwork_addr; - struct in_addr vnetwork_mask; - struct in_addr vhost_addr; - struct in6_addr vprefix_addr6; - uint8_t vprefix_len; - struct in6_addr vhost_addr6; - bool disable_dhcp; /* slirp will not reply to any DHCP requests */ - struct in_addr vdhcp_startaddr; - struct in_addr vnameserver_addr; - struct in6_addr vnameserver_addr6; - - struct in_addr client_ipaddr; - char client_hostname[33]; - - int restricted; - struct gfwd_list *guestfwd_list; - - int if_mtu; - int if_mru; - - bool disable_host_loopback; - - /* mbuf states */ - struct slirp_quehead m_freelist; - struct slirp_quehead m_usedlist; - int mbuf_alloced; - - /* if states */ - struct slirp_quehead if_fastq; /* fast queue (for interactive data) */ - struct slirp_quehead if_batchq; /* queue for non-interactive data */ - bool if_start_busy; /* avoid if_start recursion */ - - /* ip states */ - struct ipq ipq; /* ip reass. queue */ - uint16_t ip_id; /* ip packet ctr, for ids */ - - /* bootp/dhcp states */ - BOOTPClient bootp_clients[NB_BOOTP_CLIENTS]; - char *bootp_filename; - size_t vdnssearch_len; - uint8_t *vdnssearch; - char *vdomainname; - - /* tcp states */ - struct socket tcb; - struct socket *tcp_last_so; - tcp_seq tcp_iss; /* tcp initial send seq # */ - uint32_t tcp_now; /* for RFC 1323 timestamps */ - - /* udp states */ - struct socket udb; - struct socket *udp_last_so; - - /* icmp states */ - struct socket icmp; - struct socket *icmp_last_so; - - /* tftp states */ - char *tftp_prefix; - struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX]; - char *tftp_server_name; - - ArpTable arp_table; - NdpTable ndp_table; - - GRand *grand; - void *ra_timer; - - bool enable_emu; - - const SlirpCb *cb; - void *opaque; - - struct sockaddr_in *outbound_addr; - struct sockaddr_in6 *outbound_addr6; - bool disable_dns; /* slirp will not redirect/serve any DNS packet */ -}; - -void if_start(Slirp *); - -int get_dns_addr(struct in_addr *pdns_addr); -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id); - -/* ncsi.c */ -void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); - -#ifndef _WIN32 -#include -#endif - - -extern bool slirp_do_keepalive; - -#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL) - -/* dnssearch.c */ -int translate_dnssearch(Slirp *s, const char **names); - -/* cksum.c */ -int cksum(struct mbuf *m, int len); -int ip6_cksum(struct mbuf *m); - -/* if.c */ -void if_init(Slirp *); -void if_output(struct socket *, struct mbuf *); - -/* ip_input.c */ -void ip_init(Slirp *); -void ip_cleanup(Slirp *); -void ip_input(struct mbuf *); -void ip_slowtimo(Slirp *); -void ip_stripoptions(register struct mbuf *, struct mbuf *); - -/* ip_output.c */ -int ip_output(struct socket *, struct mbuf *); - -/* ip6_input.c */ -void ip6_post_init(Slirp *); -void ip6_cleanup(Slirp *); -void ip6_input(struct mbuf *); - -/* ip6_output */ -int ip6_output(struct socket *, struct mbuf *, int fast); - -/* tcp_input.c */ -void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af); -int tcp_mss(register struct tcpcb *, unsigned); - -/* tcp_output.c */ -int tcp_output(register struct tcpcb *); -void tcp_setpersist(register struct tcpcb *); - -/* tcp_subr.c */ -void tcp_init(Slirp *); -void tcp_cleanup(Slirp *); -void tcp_template(struct tcpcb *); -void tcp_respond(struct tcpcb *, register struct tcpiphdr *, - register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short); -struct tcpcb *tcp_newtcpcb(struct socket *); -struct tcpcb *tcp_close(register struct tcpcb *); -void tcp_sockclosed(struct tcpcb *); -int tcp_fconnect(struct socket *, unsigned short af); -void tcp_connect(struct socket *); -void tcp_attach(struct socket *); -uint8_t tcp_tos(struct socket *); -int tcp_emu(struct socket *, struct mbuf *); -int tcp_ctl(struct socket *); -struct tcpcb *tcp_drop(struct tcpcb *tp, int err); - -struct socket *slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, - int guest_port); - -void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len); -void *slirp_timer_new(Slirp *slirp, SlirpTimerId id, void *cb_opaque); - -#endif diff --git a/src/network/slirp/socket.c b/src/network/slirp/socket.c deleted file mode 100644 index 22144ffb8..000000000 --- a/src/network/slirp/socket.c +++ /dev/null @@ -1,1233 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include "ip_icmp.h" -#ifdef __sun__ -#include -#endif -#ifdef __linux__ -#include -#endif - -static void sofcantrcvmore(struct socket *so); -static void sofcantsendmore(struct socket *so); - -struct socket *solookup(struct socket **last, struct socket *head, - struct sockaddr_storage *lhost, - struct sockaddr_storage *fhost) -{ - struct socket *so = *last; - - /* Optimisation */ - if (so != head && sockaddr_equal(&(so->lhost.ss), lhost) && - (!fhost || sockaddr_equal(&so->fhost.ss, fhost))) { - return so; - } - - for (so = head->so_next; so != head; so = so->so_next) { - if (sockaddr_equal(&(so->lhost.ss), lhost) && - (!fhost || sockaddr_equal(&so->fhost.ss, fhost))) { - *last = so; - return so; - } - } - - return (struct socket *)NULL; -} - -/* - * Create a new socket, initialise the fields - * It is the responsibility of the caller to - * slirp_insque() it into the correct linked-list - */ -struct socket *socreate(Slirp *slirp, int type) -{ - struct socket *so = g_new(struct socket, 1); - - memset(so, 0, sizeof(struct socket)); - so->so_type = type; - so->so_state = SS_NOFDREF; - so->s = -1; - so->s_aux = -1; - so->slirp = slirp; - so->pollfds_idx = -1; - - return so; -} - -/* - * Remove references to so from the given message queue. - */ -static void soqfree(struct socket *so, struct slirp_quehead *qh) -{ - struct mbuf *ifq; - - for (ifq = (struct mbuf *)qh->qh_link; (struct slirp_quehead *)ifq != qh; - ifq = ifq->ifq_next) { - if (ifq->ifq_so == so) { - struct mbuf *ifm; - ifq->ifq_so = NULL; - for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) { - ifm->ifq_so = NULL; - } - } - } -} - -/* - * slirp_remque and free a socket, clobber cache - */ -void sofree(struct socket *so) -{ - Slirp *slirp = so->slirp; - - if (so->s_aux != -1) { - closesocket(so->s_aux); - } - - soqfree(so, &slirp->if_fastq); - soqfree(so, &slirp->if_batchq); - - if (so == slirp->tcp_last_so) { - slirp->tcp_last_so = &slirp->tcb; - } else if (so == slirp->udp_last_so) { - slirp->udp_last_so = &slirp->udb; - } else if (so == slirp->icmp_last_so) { - slirp->icmp_last_so = &slirp->icmp; - } - m_free(so->so_m); - - if (so->so_next && so->so_prev) - slirp_remque(so); /* crashes if so is not in a queue */ - - if (so->so_tcpcb) { - g_free(so->so_tcpcb); - } - g_free(so); -} - -size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np) -{ - int n, lss, total; - struct sbuf *sb = &so->so_snd; - int len = sb->sb_datalen - sb->sb_cc; - int mss = so->so_tcpcb->t_maxseg; - - DEBUG_CALL("sopreprbuf"); - DEBUG_ARG("so = %p", so); - - if (len <= 0) - return 0; - - iov[0].iov_base = sb->sb_wptr; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; - if (sb->sb_wptr < sb->sb_rptr) { - iov[0].iov_len = sb->sb_rptr - sb->sb_wptr; - /* Should never succeed, but... */ - if (iov[0].iov_len > len) - iov[0].iov_len = len; - if (iov[0].iov_len > mss) - iov[0].iov_len -= iov[0].iov_len % mss; - n = 1; - } else { - iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr; - /* Should never succeed, but... */ - if (iov[0].iov_len > len) - iov[0].iov_len = len; - len -= iov[0].iov_len; - if (len) { - iov[1].iov_base = sb->sb_data; - iov[1].iov_len = sb->sb_rptr - sb->sb_data; - if (iov[1].iov_len > len) - iov[1].iov_len = len; - total = iov[0].iov_len + iov[1].iov_len; - if (total > mss) { - lss = total % mss; - if (iov[1].iov_len > lss) { - iov[1].iov_len -= lss; - n = 2; - } else { - lss -= iov[1].iov_len; - iov[0].iov_len -= lss; - n = 1; - } - } else - n = 2; - } else { - if (iov[0].iov_len > mss) - iov[0].iov_len -= iov[0].iov_len % mss; - n = 1; - } - } - if (np) - *np = n; - - return iov[0].iov_len + (n - 1) * iov[1].iov_len; -} - -/* - * Read from so's socket into sb_snd, updating all relevant sbuf fields - * NOTE: This will only be called if it is select()ed for reading, so - * a read() of 0 (or less) means it's disconnected - */ -int soread(struct socket *so) -{ - int n = 0, nn; - size_t buf_len; - struct sbuf *sb = &so->so_snd; - struct iovec iov[2] = {{0, 0}, {0, 0}}; - - DEBUG_CALL("soread"); - DEBUG_ARG("so = %p", so); - - /* - * No need to check if there's enough room to read. - * soread wouldn't have been called if there weren't - */ - buf_len = sopreprbuf(so, iov, &n); - assert(buf_len != 0); - - nn = recv(so->s, iov[0].iov_base, iov[0].iov_len, 0); - if (nn <= 0) { - if (nn < 0 && (errno == EINTR || errno == EAGAIN)) - return 0; - else { - int err; - socklen_t elen = sizeof err; - struct sockaddr_storage addr; - struct sockaddr *paddr = (struct sockaddr *)&addr; - socklen_t alen = sizeof addr; - - err = errno; - if (nn == 0) { - int shutdown_wr = so->so_state & SS_FCANTSENDMORE; - - if (!shutdown_wr && getpeername(so->s, paddr, &alen) < 0) { - err = errno; - } else { - getsockopt(so->s, SOL_SOCKET, SO_ERROR, &err, &elen); - } - } - - DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s", nn, - errno, strerror(errno)); - sofcantrcvmore(so); - - if (err == ECONNABORTED || err == ECONNRESET || err == ECONNREFUSED || - err == ENOTCONN || err == EPIPE) { - tcp_drop(sototcpcb(so), err); - } else { - tcp_sockclosed(sototcpcb(so)); - } - return -1; - } - } - - /* - * If there was no error, try and read the second time round - * We read again if n = 2 (ie, there's another part of the buffer) - * and we read as much as we could in the first read - * We don't test for <= 0 this time, because there legitimately - * might not be any more data (since the socket is non-blocking), - * a close will be detected on next iteration. - * A return of -1 won't (shouldn't) happen, since it didn't happen above - */ - if (n == 2 && nn == iov[0].iov_len) { - int ret; - ret = recv(so->s, iov[1].iov_base, iov[1].iov_len, 0); - if (ret > 0) - nn += ret; - } - - DEBUG_MISC(" ... read nn = %d bytes", nn); - - /* Update fields */ - sb->sb_cc += nn; - sb->sb_wptr += nn; - if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_wptr -= sb->sb_datalen; - return nn; -} - -int soreadbuf(struct socket *so, const char *buf, int size) -{ - int n, nn, copy = size; - struct sbuf *sb = &so->so_snd; - struct iovec iov[2] = {{0, 0}, {0, 0}}; - - DEBUG_CALL("soreadbuf"); - DEBUG_ARG("so = %p", so); - - /* - * No need to check if there's enough room to read. - * soread wouldn't have been called if there weren't - */ - assert(size > 0); - if (sopreprbuf(so, iov, &n) < size) - goto err; - - nn = MIN(iov[0].iov_len, copy); - memcpy(iov[0].iov_base, buf, nn); - - copy -= nn; - buf += nn; - - if (copy == 0) - goto done; - - memcpy(iov[1].iov_base, buf, copy); - -done: - /* Update fields */ - sb->sb_cc += size; - sb->sb_wptr += size; - if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_wptr -= sb->sb_datalen; - return size; -err: - - sofcantrcvmore(so); - tcp_sockclosed(sototcpcb(so)); - g_critical("soreadbuf buffer too small"); - return -1; -} - -/* - * Get urgent data - * - * When the socket is created, we set it SO_OOBINLINE, - * so when OOB data arrives, we soread() it and everything - * in the send buffer is sent as urgent data - */ -int sorecvoob(struct socket *so) -{ - struct tcpcb *tp = sototcpcb(so); - int ret; - - DEBUG_CALL("sorecvoob"); - DEBUG_ARG("so = %p", so); - - /* - * We take a guess at how much urgent data has arrived. - * In most situations, when urgent data arrives, the next - * read() should get all the urgent data. This guess will - * be wrong however if more data arrives just after the - * urgent data, or the read() doesn't return all the - * urgent data. - */ - ret = soread(so); - if (ret > 0) { - tp->snd_up = tp->snd_una + so->so_snd.sb_cc; - tp->t_force = 1; - tcp_output(tp); - tp->t_force = 0; - } - - return ret; -} - -/* - * Send urgent data - * There's a lot duplicated code here, but... - */ -int sosendoob(struct socket *so) -{ - struct sbuf *sb = &so->so_rcv; - char buff[2048]; /* XXX Shouldn't be sending more oob data than this */ - - int n; - - DEBUG_CALL("sosendoob"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("sb->sb_cc = %d", sb->sb_cc); - - if (so->so_urgc > sizeof(buff)) - so->so_urgc = sizeof(buff); /* XXXX */ - - if (sb->sb_rptr < sb->sb_wptr) { - /* We can send it directly */ - n = slirp_send(so, sb->sb_rptr, so->so_urgc, - (MSG_OOB)); /* |MSG_DONTWAIT)); */ - } else { - /* - * Since there's no sendv or sendtov like writev, - * we must copy all data to a linear buffer then - * send it all - */ - uint32_t urgc = so->so_urgc; /* Amount of room left in buff */ - int len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; - if (len > urgc) { - len = urgc; - } - memcpy(buff, sb->sb_rptr, len); - urgc -= len; - if (urgc) { - /* We still have some room for the rest */ - n = sb->sb_wptr - sb->sb_data; - if (n > urgc) { - n = urgc; - } - memcpy((buff + len), sb->sb_data, n); - len += n; - } - n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */ -#ifdef SLIRP_DEBUG - if (n != len) { - DEBUG_ERROR("Didn't send all data urgently XXXXX"); - } -#endif - } - - if (n < 0) { - return n; - } - so->so_urgc -= n; - DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left", n, - so->so_urgc); - - sb->sb_cc -= n; - sb->sb_rptr += n; - if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_rptr -= sb->sb_datalen; - - return n; -} - -/* - * Write data from so_rcv to so's socket, - * updating all sbuf field as necessary - */ -int sowrite(struct socket *so) -{ - int n, nn; - struct sbuf *sb = &so->so_rcv; - int len = sb->sb_cc; - struct iovec iov[2] = {{0, 0}, {0, 0}}; - - DEBUG_CALL("sowrite"); - DEBUG_ARG("so = %p", so); - - if (so->so_urgc) { - uint32_t expected = so->so_urgc; - if (sosendoob(so) < expected) { - /* Treat a short write as a fatal error too, - * rather than continuing on and sending the urgent - * data as if it were non-urgent and leaving the - * so_urgc count wrong. - */ - goto err_disconnected; - } - if (sb->sb_cc == 0) - return 0; - } - - /* - * No need to check if there's something to write, - * sowrite wouldn't have been called otherwise - */ - - iov[0].iov_base = sb->sb_rptr; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; - if (sb->sb_rptr < sb->sb_wptr) { - iov[0].iov_len = sb->sb_wptr - sb->sb_rptr; - /* Should never succeed, but... */ - if (iov[0].iov_len > len) - iov[0].iov_len = len; - n = 1; - } else { - iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; - if (iov[0].iov_len > len) - iov[0].iov_len = len; - len -= iov[0].iov_len; - if (len) { - iov[1].iov_base = sb->sb_data; - iov[1].iov_len = sb->sb_wptr - sb->sb_data; - if (iov[1].iov_len > len) - iov[1].iov_len = len; - n = 2; - } else - n = 1; - } - /* Check if there's urgent data to send, and if so, send it */ - - nn = slirp_send(so, iov[0].iov_base, iov[0].iov_len, 0); - /* This should never happen, but people tell me it does *shrug* */ - if (nn < 0 && (errno == EAGAIN || errno == EINTR)) - return 0; - - if (nn <= 0) { - goto err_disconnected; - } - - if (n == 2 && nn == iov[0].iov_len) { - int ret; - ret = slirp_send(so, iov[1].iov_base, iov[1].iov_len, 0); - if (ret > 0) - nn += ret; - } - DEBUG_MISC(" ... wrote nn = %d bytes", nn); - - /* Update sbuf */ - sb->sb_cc -= nn; - sb->sb_rptr += nn; - if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_rptr -= sb->sb_datalen; - - /* - * If in DRAIN mode, and there's no more data, set - * it CANTSENDMORE - */ - if ((so->so_state & SS_FWDRAIN) && sb->sb_cc == 0) - sofcantsendmore(so); - - return nn; - -err_disconnected: - DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d", - so->so_state, errno); - sofcantsendmore(so); - tcp_sockclosed(sototcpcb(so)); - return -1; -} - -/* - * recvfrom() a UDP socket - */ -void sorecvfrom(struct socket *so) -{ - struct sockaddr_storage addr; - struct sockaddr_storage saddr, daddr; - socklen_t addrlen = sizeof(struct sockaddr_storage); - char buff[256]; - -#ifdef __linux__ - ssize_t size; - struct msghdr msg; - struct iovec iov; - char control[1024]; - - /* First look for errors */ - memset(&msg, 0, sizeof(msg)); - msg.msg_name = &saddr; - msg.msg_namelen = sizeof(saddr); - msg.msg_control = control; - msg.msg_controllen = sizeof(control); - iov.iov_base = buff; - iov.iov_len = sizeof(buff); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - - size = recvmsg(so->s, &msg, MSG_ERRQUEUE); - if (size >= 0) { - struct cmsghdr *cmsg; - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { - - if (cmsg->cmsg_level == IPPROTO_IP && - cmsg->cmsg_type == IP_RECVERR) { - struct sock_extended_err *ee = - (struct sock_extended_err *) CMSG_DATA(cmsg); - - if (ee->ee_origin == SO_EE_ORIGIN_ICMP) { - /* Got an ICMP error, forward it */ - struct sockaddr_in *sin; - - sin = (struct sockaddr_in *) SO_EE_OFFENDER(ee); - icmp_forward_error(so->so_m, ee->ee_type, ee->ee_code, - 0, NULL, &sin->sin_addr); - } - } - else if (cmsg->cmsg_level == IPPROTO_IPV6 && - cmsg->cmsg_type == IPV6_RECVERR) { - struct sock_extended_err *ee = - (struct sock_extended_err *) CMSG_DATA(cmsg); - - if (ee->ee_origin == SO_EE_ORIGIN_ICMP6) { - /* Got an ICMPv6 error, forward it */ - struct sockaddr_in6 *sin6; - - sin6 = (struct sockaddr_in6 *) SO_EE_OFFENDER(ee); - icmp6_forward_error(so->so_m, ee->ee_type, ee->ee_code, - &sin6->sin6_addr); - } - } - } - return; - } -#endif - - DEBUG_CALL("sorecvfrom"); - DEBUG_ARG("so = %p", so); - - if (so->so_type == IPPROTO_ICMP) { /* This is a "ping" reply */ - int len; - - len = recvfrom(so->s, buff, 256, 0, (struct sockaddr *)&addr, &addrlen); - /* XXX Check if reply is "correct"? */ - - if (len == -1 || len == 0) { - uint8_t code = ICMP_UNREACH_PORT; - - if (errno == EHOSTUNREACH) - code = ICMP_UNREACH_HOST; - else if (errno == ENETUNREACH) - code = ICMP_UNREACH_NET; - - DEBUG_MISC(" udp icmp rx errno = %d-%s", errno, strerror(errno)); - icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno)); - } else { - icmp_reflect(so->so_m); - so->so_m = NULL; /* Don't m_free() it again! */ - } - /* No need for this socket anymore, udp_detach it */ - udp_detach(so); - } else { /* A "normal" UDP packet */ - struct mbuf *m; - int len; -#ifdef _WIN32 - unsigned long n; -#else - int n; -#endif - - if (ioctlsocket(so->s, FIONREAD, &n) != 0) { - DEBUG_MISC(" ioctlsocket errno = %d-%s\n", errno, strerror(errno)); - return; - } - - m = m_get(so->slirp); - if (!m) { - return; - } - switch (so->so_ffamily) { - case AF_INET: - m->m_data += IF_MAXLINKHDR + sizeof(struct udpiphdr); - break; - case AF_INET6: - m->m_data += - IF_MAXLINKHDR + sizeof(struct ip6) + sizeof(struct udphdr); - break; - default: - g_assert_not_reached(); - } - - /* - * XXX Shouldn't FIONREAD packets destined for port 53, - * but I don't know the max packet size for DNS lookups - */ - len = M_FREEROOM(m); - /* if (so->so_fport != htons(53)) { */ - - if (n > len) { - n = (m->m_data - m->m_dat) + m->m_len + n + 1; - m_inc(m, n); - len = M_FREEROOM(m); - } - /* } */ - - m->m_len = recvfrom(so->s, m->m_data, len, 0, (struct sockaddr *)&addr, - &addrlen); - DEBUG_MISC(" did recvfrom %d, errno = %d-%s", m->m_len, errno, - strerror(errno)); - if (m->m_len < 0) { - /* Report error as ICMP */ - switch (so->so_lfamily) { - uint8_t code; - case AF_INET: - code = ICMP_UNREACH_PORT; - - if (errno == EHOSTUNREACH) { - code = ICMP_UNREACH_HOST; - } else if (errno == ENETUNREACH) { - code = ICMP_UNREACH_NET; - } - - DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i", code); - icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, - strerror(errno)); - break; - case AF_INET6: - code = ICMP6_UNREACH_PORT; - - if (errno == EHOSTUNREACH) { - code = ICMP6_UNREACH_ADDRESS; - } else if (errno == ENETUNREACH) { - code = ICMP6_UNREACH_NO_ROUTE; - } - - DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i", code); - icmp6_send_error(so->so_m, ICMP6_UNREACH, code); - break; - default: - g_assert_not_reached(); - } - m_free(m); - } else { - /* - * Hack: domain name lookup will be used the most for UDP, - * and since they'll only be used once there's no need - * for the 4 minute (or whatever) timeout... So we time them - * out much quicker (10 seconds for now...) - */ - if (so->so_expire) { - if (so->so_fport == htons(53)) - so->so_expire = curtime + SO_EXPIREFAST; - else - so->so_expire = curtime + SO_EXPIRE; - } - - /* - * If this packet was destined for CTL_ADDR, - * make it look like that's where it came from - */ - saddr = addr; - sotranslate_in(so, &saddr); - - /* Perform lazy guest IP address resolution if needed. */ - if (so->so_state & SS_HOSTFWD) { - if (soassign_guest_addr_if_needed(so) < 0) { - DEBUG_MISC(" guest address not available yet"); - switch (so->so_lfamily) { - case AF_INET: - icmp_send_error(so->so_m, ICMP_UNREACH, - ICMP_UNREACH_HOST, 0, - "guest address not available yet"); - break; - case AF_INET6: - icmp6_send_error(so->so_m, ICMP6_UNREACH, - ICMP6_UNREACH_ADDRESS); - break; - default: - g_assert_not_reached(); - } - m_free(m); - return; - } - } - daddr = so->lhost.ss; - - switch (so->so_ffamily) { - case AF_INET: - udp_output(so, m, (struct sockaddr_in *)&saddr, - (struct sockaddr_in *)&daddr, so->so_iptos); - break; - case AF_INET6: - udp6_output(so, m, (struct sockaddr_in6 *)&saddr, - (struct sockaddr_in6 *)&daddr); - break; - default: - g_assert_not_reached(); - } - } /* rx error */ - } /* if ping packet */ -} - -/* - * sendto() a socket - */ -int sosendto(struct socket *so, struct mbuf *m) -{ - int ret; - struct sockaddr_storage addr; - - DEBUG_CALL("sosendto"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - addr = so->fhost.ss; - DEBUG_CALL(" sendto()ing)"); - if (sotranslate_out(so, &addr) < 0) { - return -1; - } - - /* Don't care what port we get */ - ret = sendto(so->s, m->m_data, m->m_len, 0, (struct sockaddr *)&addr, - sockaddr_size(&addr)); - if (ret < 0) - return -1; - - /* - * Kill the socket if there's no reply in 4 minutes, - * but only if it's an expirable socket - */ - if (so->so_expire) - so->so_expire = curtime + SO_EXPIRE; - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_ISFCONNECTED; /* So that it gets select()ed */ - return 0; -} - -/* - * Listen for incoming TCP connections - * On failure errno contains the reason. - */ -struct socket *tcpx_listen(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags) -{ - struct socket *so; - int s, opt = 1; - socklen_t addrlen; - - DEBUG_CALL("tcpx_listen"); - /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ - char addrstr[INET6_ADDRSTRLEN]; - char portstr[6]; - int ret; - switch (haddr->sa_family) { - case AF_INET: - case AF_INET6: - ret = getnameinfo(haddr, haddrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("hfamily = INET"); - DEBUG_ARG("haddr = %s", addrstr); - DEBUG_ARG("hport = %s", portstr); - break; -#ifndef _WIN32 - case AF_UNIX: - DEBUG_ARG("hfamily = UNIX"); - DEBUG_ARG("hpath = %s", ((struct sockaddr_un *) haddr)->sun_path); - break; -#endif - default: - g_assert_not_reached(); - } - switch (laddr->sa_family) { - case AF_INET: - case AF_INET6: - ret = getnameinfo(laddr, laddrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("laddr = %s", addrstr); - DEBUG_ARG("lport = %s", portstr); - break; - default: - g_assert_not_reached(); - } - DEBUG_ARG("flags = %x", flags); - - /* - * SS_HOSTFWD sockets can be accepted multiple times, so they can't be - * SS_FACCEPTONCE. Also, SS_HOSTFWD connections can be accepted and - * immediately closed if the guest address isn't available yet, which is - * incompatible with the "accept once" concept. Correct code will never - * request both, so disallow their combination by assertion. - */ - g_assert(!((flags & SS_HOSTFWD) && (flags & SS_FACCEPTONCE))); - - so = socreate(slirp, IPPROTO_TCP); - - /* Don't tcp_attach... we don't need so_snd nor so_rcv */ - so->so_tcpcb = tcp_newtcpcb(so); - slirp_insque(so, &slirp->tcb); - - /* - * SS_FACCEPTONCE sockets must time out. - */ - if (flags & SS_FACCEPTONCE) - so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT * 2; - - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= (SS_FACCEPTCONN | flags); - - sockaddr_copy(&so->lhost.sa, sizeof(so->lhost), laddr, laddrlen); - - s = slirp_socket(haddr->sa_family, SOCK_STREAM, 0); - if ((s < 0) || - (haddr->sa_family == AF_INET6 && slirp_socket_set_v6only(s, (flags & SS_HOSTFWD_V6ONLY) != 0) < 0) || - (slirp_socket_set_fast_reuse(s) < 0) || - (bind(s, haddr, haddrlen) < 0) || - (listen(s, 1) < 0)) { - int tmperrno = errno; /* Don't clobber the real reason we failed */ - if (s >= 0) { - closesocket(s); - } - sofree(so); - /* Restore the real errno */ -#ifdef _WIN32 - WSASetLastError(tmperrno); -#else - errno = tmperrno; -#endif - return NULL; - } - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - slirp_socket_set_nodelay(s); - - addrlen = sizeof(so->fhost); - getsockname(s, &so->fhost.sa, &addrlen); - sotranslate_accept(so); - - so->s = s; - return so; -} - -struct socket *tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, - uint32_t laddr, unsigned lport, int flags) -{ - struct sockaddr_in hsa, lsa; - - memset(&hsa, 0, sizeof(hsa)); - hsa.sin_family = AF_INET; - hsa.sin_addr.s_addr = haddr; - hsa.sin_port = hport; - - memset(&lsa, 0, sizeof(lsa)); - lsa.sin_family = AF_INET; - lsa.sin_addr.s_addr = laddr; - lsa.sin_port = lport; - - return tcpx_listen(slirp, (const struct sockaddr *) &hsa, sizeof(hsa), (struct sockaddr *) &lsa, sizeof(lsa), flags); -} - -/* - * Various session state calls - * XXX Should be #define's - * The socket state stuff needs work, these often get call 2 or 3 - * times each when only 1 was needed - */ -void soisfconnecting(struct socket *so) -{ - so->so_state &= ~(SS_NOFDREF | SS_ISFCONNECTED | SS_FCANTRCVMORE | - SS_FCANTSENDMORE | SS_FWDRAIN); - so->so_state |= SS_ISFCONNECTING; /* Clobber other states */ -} - -void soisfconnected(struct socket *so) -{ - so->so_state &= ~(SS_ISFCONNECTING | SS_FWDRAIN | SS_NOFDREF); - so->so_state |= SS_ISFCONNECTED; /* Clobber other states */ -} - -static void sofcantrcvmore(struct socket *so) -{ - if ((so->so_state & SS_NOFDREF) == 0) { - shutdown(so->s, 0); - } - so->so_state &= ~(SS_ISFCONNECTING); - if (so->so_state & SS_FCANTSENDMORE) { - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; /* Don't select it */ - } else { - so->so_state |= SS_FCANTRCVMORE; - } -} - -static void sofcantsendmore(struct socket *so) -{ - if ((so->so_state & SS_NOFDREF) == 0) { - shutdown(so->s, 1); /* send FIN to fhost */ - } - so->so_state &= ~(SS_ISFCONNECTING); - if (so->so_state & SS_FCANTRCVMORE) { - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; /* as above */ - } else { - so->so_state |= SS_FCANTSENDMORE; - } -} - -/* - * Set write drain mode - * Set CANTSENDMORE once all data has been write()n - */ -void sofwdrain(struct socket *so) -{ - if (so->so_rcv.sb_cc) - so->so_state |= SS_FWDRAIN; - else - sofcantsendmore(so); -} - -static bool sotranslate_out4(Slirp *s, struct socket *so, struct sockaddr_in *sin) -{ - if (!s->disable_dns && so->so_faddr.s_addr == s->vnameserver_addr.s_addr) { - return so->so_fport == htons(53) && get_dns_addr(&sin->sin_addr) >= 0; - } - - if (so->so_faddr.s_addr == s->vhost_addr.s_addr || - so->so_faddr.s_addr == 0xffffffff) { - if (s->disable_host_loopback) { - return false; - } - - sin->sin_addr = loopback_addr; - } - - return true; -} - -static bool sotranslate_out6(Slirp *s, struct socket *so, struct sockaddr_in6 *sin) -{ - if (!s->disable_dns && in6_equal(&so->so_faddr6, &s->vnameserver_addr6)) { - uint32_t scope_id; - if (so->so_fport == htons(53) && get_dns6_addr(&sin->sin6_addr, &scope_id) >= 0) { - sin->sin6_scope_id = scope_id; - return true; - } - return false; - } - - if (in6_equal_net(&so->so_faddr6, &s->vprefix_addr6, s->vprefix_len) || - in6_equal(&so->so_faddr6, &(struct in6_addr)ALLNODES_MULTICAST)) { - if (s->disable_host_loopback) { - return false; - } - - sin->sin6_addr = in6addr_loopback; - } - - return true; -} - - -/* - * Translate addr in host addr when it is a virtual address - */ -int sotranslate_out(struct socket *so, struct sockaddr_storage *addr) -{ - bool ok = true; - - switch (addr->ss_family) { - case AF_INET: - ok = sotranslate_out4(so->slirp, so, (struct sockaddr_in *)addr); - break; - case AF_INET6: - ok = sotranslate_out6(so->slirp, so, (struct sockaddr_in6 *)addr); - break; - } - - if (!ok) { - errno = EPERM; - return -1; - } - - return 0; -} - -void sotranslate_in(struct socket *so, struct sockaddr_storage *addr) -{ - Slirp *slirp = so->slirp; - struct sockaddr_in *sin = (struct sockaddr_in *)addr; - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; - - switch (addr->ss_family) { - case AF_INET: - if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) == - slirp->vnetwork_addr.s_addr) { - uint32_t inv_mask = ~slirp->vnetwork_mask.s_addr; - - if ((so->so_faddr.s_addr & inv_mask) == inv_mask) { - sin->sin_addr = slirp->vhost_addr; - } else if (sin->sin_addr.s_addr == loopback_addr.s_addr || - so->so_faddr.s_addr != slirp->vhost_addr.s_addr) { - sin->sin_addr = so->so_faddr; - } - } - break; - - case AF_INET6: - if (in6_equal_net(&so->so_faddr6, &slirp->vprefix_addr6, - slirp->vprefix_len)) { - if (in6_equal(&sin6->sin6_addr, &in6addr_loopback) || - !in6_equal(&so->so_faddr6, &slirp->vhost_addr6)) { - sin6->sin6_addr = so->so_faddr6; - } - } - break; - - default: - break; - } -} - -/* - * Translate connections from localhost to the real hostname - */ -void sotranslate_accept(struct socket *so) -{ - Slirp *slirp = so->slirp; - - switch (so->so_ffamily) { - case AF_INET: - if (so->so_faddr.s_addr == INADDR_ANY || - (so->so_faddr.s_addr & loopback_mask) == - (loopback_addr.s_addr & loopback_mask)) { - so->so_faddr = slirp->vhost_addr; - } - break; - - case AF_INET6: - if (in6_equal(&so->so_faddr6, &in6addr_any) || - in6_equal(&so->so_faddr6, &in6addr_loopback)) { - so->so_faddr6 = slirp->vhost_addr6; - } - break; - - case AF_UNIX: { - /* Translate Unix socket to random ephemeral source port. We obtain - * this source port by binding to port 0 so that the OS allocates a - * port for us. If this fails, we fall back to choosing a random port - * with a random number generator. */ - int s; - struct sockaddr_in in_addr; - struct sockaddr_in6 in6_addr; - socklen_t in_addr_len; - - if (so->slirp->in_enabled) { - so->so_ffamily = AF_INET; - so->so_faddr = slirp->vhost_addr; - so->so_fport = 0; - - switch (so->so_type) { - case IPPROTO_TCP: - s = slirp_socket(PF_INET, SOCK_STREAM, 0); - break; - case IPPROTO_UDP: - s = slirp_socket(PF_INET, SOCK_DGRAM, 0); - break; - default: - g_assert_not_reached(); - break; - } - if (s < 0) { - g_error("Ephemeral slirp_socket() allocation failed"); - goto unix2inet_cont; - } - memset(&in_addr, 0, sizeof(in_addr)); - in_addr.sin_family = AF_INET; - in_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - in_addr.sin_port = htons(0); - if (bind(s, (struct sockaddr *) &in_addr, sizeof(in_addr))) { - g_error("Ephemeral bind() failed"); - closesocket(s); - goto unix2inet_cont; - } - in_addr_len = sizeof(in_addr); - if (getsockname(s, (struct sockaddr *) &in_addr, &in_addr_len)) { - g_error("Ephemeral getsockname() failed"); - closesocket(s); - goto unix2inet_cont; - } - so->s_aux = s; - so->so_fport = in_addr.sin_port; - -unix2inet_cont: - if (!so->so_fport) { - g_warning("Falling back to random port allocation"); - so->so_fport = htons(g_rand_int_range(slirp->grand, 49152, 65536)); - } - } else if (so->slirp->in6_enabled) { - so->so_ffamily = AF_INET6; - so->so_faddr6 = slirp->vhost_addr6; - so->so_fport6 = 0; - - switch (so->so_type) { - case IPPROTO_TCP: - s = slirp_socket(PF_INET6, SOCK_STREAM, 0); - break; - case IPPROTO_UDP: - s = slirp_socket(PF_INET6, SOCK_DGRAM, 0); - break; - default: - g_assert_not_reached(); - break; - } - if (s < 0) { - g_error("Ephemeral slirp_socket() allocation failed"); - goto unix2inet6_cont; - } - memset(&in6_addr, 0, sizeof(in6_addr)); - in6_addr.sin6_family = AF_INET6; - in6_addr.sin6_addr = in6addr_loopback; - in6_addr.sin6_port = htons(0); - if (bind(s, (struct sockaddr *) &in6_addr, sizeof(in6_addr))) { - g_error("Ephemeral bind() failed"); - closesocket(s); - goto unix2inet6_cont; - } - in_addr_len = sizeof(in6_addr); - if (getsockname(s, (struct sockaddr *) &in6_addr, &in_addr_len)) { - g_error("Ephemeral getsockname() failed"); - closesocket(s); - goto unix2inet6_cont; - } - so->s_aux = s; - so->so_fport6 = in6_addr.sin6_port; - -unix2inet6_cont: - if (!so->so_fport6) { - g_warning("Falling back to random port allocation"); - so->so_fport6 = htons(g_rand_int_range(slirp->grand, 49152, 65536)); - } - } else { - g_assert_not_reached(); - } - break; - } /* case AF_UNIX */ - - default: - break; - } -} - -void sodrop(struct socket *s, int num) -{ - if (sbdrop(&s->so_snd, num)) { - s->slirp->cb->notify(s->slirp->opaque); - } -} - -/* - * Translate "addr-any" in so->lhost to the guest's actual address. - * Returns 0 for success, or -1 if the guest doesn't have an address yet - * with errno set to EHOSTUNREACH. - * - * The guest address is taken from the first entry in the ARP table for IPv4 - * and the first entry in the NDP table for IPv6. - * Note: The IPv4 path isn't exercised yet as all hostfwd "" guest translations - * are handled immediately by using slirp->vdhcp_startaddr. - */ -int soassign_guest_addr_if_needed(struct socket *so) -{ - Slirp *slirp = so->slirp; - /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ - char addrstr[INET6_ADDRSTRLEN]; - char portstr[6]; - - g_assert(so->so_state & SS_HOSTFWD); - - switch (so->so_ffamily) { - case AF_INET: - if (so->so_laddr.s_addr == INADDR_ANY) { - g_assert_not_reached(); - } - break; - - case AF_INET6: - if (in6_zero(&so->so_laddr6)) { - int ret; - if (in6_zero(&slirp->ndp_table.guest_in6_addr)) { - errno = EHOSTUNREACH; - return -1; - } - so->so_laddr6 = slirp->ndp_table.guest_in6_addr; - ret = getnameinfo((const struct sockaddr *) &so->lhost.ss, - sizeof(so->lhost.ss), addrstr, sizeof(addrstr), - portstr, sizeof(portstr), - NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_MISC("%s: new ip = [%s]:%s", __func__, addrstr, portstr); - } - break; - - default: - break; - } - - return 0; -} diff --git a/src/network/slirp/socket.h b/src/network/slirp/socket.h deleted file mode 100644 index ca8c103ec..000000000 --- a/src/network/slirp/socket.h +++ /dev/null @@ -1,206 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef SLIRP_SOCKET_H -#define SLIRP_SOCKET_H - -#include - -#ifndef _WIN32 -#include -#endif - -#include "misc.h" -#include "sbuf.h" - -#define SO_EXPIRE 240000 -#define SO_EXPIREFAST 10000 - -/* Helps unify some in/in6 routines. */ -union in4or6_addr { - struct in_addr addr4; - struct in6_addr addr6; -}; -typedef union in4or6_addr in4or6_addr; - -/* - * Our socket structure - */ - -union slirp_sockaddr { - struct sockaddr sa; - struct sockaddr_storage ss; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; -}; - -struct socket { - struct socket *so_next, *so_prev; /* For a linked list of sockets */ - - int s; /* The actual socket */ - int s_aux; /* An auxiliary socket for miscellaneous use. Currently used to - * reserve OS ports in UNIX-to-inet translation. */ - struct gfwd_list *guestfwd; - - int pollfds_idx; /* GPollFD GArray index */ - - Slirp *slirp; /* managing slirp instance */ - - /* XXX union these with not-yet-used sbuf params */ - struct mbuf *so_m; /* Pointer to the original SYN packet, - * for non-blocking connect()'s, and - * PING reply's */ - struct tcpiphdr *so_ti; /* Pointer to the original ti within - * so_mconn, for non-blocking connections */ - uint32_t so_urgc; - union slirp_sockaddr fhost; /* Foreign host */ -#define so_faddr fhost.sin.sin_addr -#define so_fport fhost.sin.sin_port -#define so_faddr6 fhost.sin6.sin6_addr -#define so_fport6 fhost.sin6.sin6_port -#define so_ffamily fhost.ss.ss_family - - union slirp_sockaddr lhost; /* Local host */ -#define so_laddr lhost.sin.sin_addr -#define so_lport lhost.sin.sin_port -#define so_laddr6 lhost.sin6.sin6_addr -#define so_lport6 lhost.sin6.sin6_port -#define so_lfamily lhost.ss.ss_family - - uint8_t so_iptos; /* Type of service */ - uint8_t so_emu; /* Is the socket emulated? */ - - uint8_t so_type; /* Protocol of the socket. May be 0 if loading old - * states. */ - int32_t so_state; /* internal state flags SS_*, below */ - - struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */ - unsigned so_expire; /* When the socket will expire */ - - int so_queued; /* Number of packets queued from this socket */ - int so_nqueued; /* Number of packets queued in a row - * Used to determine when to "downgrade" a session - * from fastq to batchq */ - - struct sbuf so_rcv; /* Receive buffer */ - struct sbuf so_snd; /* Send buffer */ -}; - - -/* - * Socket state bits. (peer means the host on the Internet, - * local host means the host on the other end of the modem) - */ -#define SS_NOFDREF 0x001 /* No fd reference */ - -#define SS_ISFCONNECTING \ - 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */ -#define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */ -#define SS_FCANTRCVMORE \ - 0x008 /* Socket can't receive more from peer (for half-closes) */ -#define SS_FCANTSENDMORE \ - 0x010 /* Socket can't send more to peer (for half-closes) */ -#define SS_FWDRAIN \ - 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */ - -#define SS_CTL 0x080 -#define SS_FACCEPTCONN \ - 0x100 /* Socket is accepting connections from a host on the internet */ -#define SS_FACCEPTONCE \ - 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */ - -#define SS_PERSISTENT_MASK 0xf000 /* Unremovable state bits */ -#define SS_HOSTFWD 0x1000 /* Socket describes host->guest forwarding */ -#define SS_INCOMING \ - 0x2000 /* Connection was initiated by a host on the internet */ -#define SS_HOSTFWD_V6ONLY 0x4000 /* Only bind on v6 addresses */ - -static inline int sockaddr_equal(const struct sockaddr_storage *a, - const struct sockaddr_storage *b) -{ - if (a->ss_family != b->ss_family) { - return 0; - } - - switch (a->ss_family) { - case AF_INET: { - const struct sockaddr_in *a4 = (const struct sockaddr_in *)a; - const struct sockaddr_in *b4 = (const struct sockaddr_in *)b; - return a4->sin_addr.s_addr == b4->sin_addr.s_addr && - a4->sin_port == b4->sin_port; - } - case AF_INET6: { - const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)a; - const struct sockaddr_in6 *b6 = (const struct sockaddr_in6 *)b; - return (in6_equal(&a6->sin6_addr, &b6->sin6_addr) && - a6->sin6_port == b6->sin6_port); - } -#ifndef _WIN32 - case AF_UNIX: { - const struct sockaddr_un *aun = (const struct sockaddr_un *)a; - const struct sockaddr_un *bun = (const struct sockaddr_un *)b; - return strncmp(aun->sun_path, bun->sun_path, sizeof(aun->sun_path)) == 0; - } -#endif - default: - g_assert_not_reached(); - } - - return 0; -} - -static inline socklen_t sockaddr_size(const struct sockaddr_storage *a) -{ - switch (a->ss_family) { - case AF_INET: - return sizeof(struct sockaddr_in); - case AF_INET6: - return sizeof(struct sockaddr_in6); -#ifndef _WIN32 - case AF_UNIX: - return sizeof(struct sockaddr_un); -#endif - default: - g_assert_not_reached(); - } -} - -static inline void sockaddr_copy(struct sockaddr *dst, socklen_t dstlen, const struct sockaddr *src, socklen_t srclen) -{ - socklen_t len = sockaddr_size((const struct sockaddr_storage *) src); - g_assert(len <= srclen); - g_assert(len <= dstlen); - memcpy(dst, src, len); -} - -struct socket *solookup(struct socket **, struct socket *, - struct sockaddr_storage *, struct sockaddr_storage *); -struct socket *socreate(Slirp *, int); -void sofree(struct socket *); -int soread(struct socket *); -int sorecvoob(struct socket *); -int sosendoob(struct socket *); -int sowrite(struct socket *); -void sorecvfrom(struct socket *); -int sosendto(struct socket *, struct mbuf *); -struct socket *tcp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int); -struct socket *tcpx_listen(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags); -void soisfconnecting(register struct socket *); -void soisfconnected(register struct socket *); -void sofwdrain(struct socket *); -struct iovec; /* For win32 */ -size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np); -int soreadbuf(struct socket *so, const char *buf, int size); - -int sotranslate_out(struct socket *, struct sockaddr_storage *); -void sotranslate_in(struct socket *, struct sockaddr_storage *); -void sotranslate_accept(struct socket *); -void sodrop(struct socket *, int num); -int soassign_guest_addr_if_needed(struct socket *so); - -#endif /* SLIRP_SOCKET_H */ diff --git a/src/network/slirp/state.c b/src/network/slirp/state.c deleted file mode 100644 index 870854747..000000000 --- a/src/network/slirp/state.c +++ /dev/null @@ -1,379 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * libslirp - * - * Copyright (c) 2004-2008 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "slirp.h" -#include "vmstate.h" -#include "stream.h" - -static int slirp_tcp_post_load(void *opaque, int version) -{ - tcp_template((struct tcpcb *)opaque); - - return 0; -} - -static const VMStateDescription vmstate_slirp_tcp = { - .name = "slirp-tcp", - .version_id = 0, - .post_load = slirp_tcp_post_load, - .fields = (VMStateField[]){ VMSTATE_INT16(t_state, struct tcpcb), - VMSTATE_INT16_ARRAY(t_timer, struct tcpcb, - TCPT_NTIMERS), - VMSTATE_INT16(t_rxtshift, struct tcpcb), - VMSTATE_INT16(t_rxtcur, struct tcpcb), - VMSTATE_INT16(t_dupacks, struct tcpcb), - VMSTATE_UINT16(t_maxseg, struct tcpcb), - VMSTATE_UINT8(t_force, struct tcpcb), - VMSTATE_UINT16(t_flags, struct tcpcb), - VMSTATE_UINT32(snd_una, struct tcpcb), - VMSTATE_UINT32(snd_nxt, struct tcpcb), - VMSTATE_UINT32(snd_up, struct tcpcb), - VMSTATE_UINT32(snd_wl1, struct tcpcb), - VMSTATE_UINT32(snd_wl2, struct tcpcb), - VMSTATE_UINT32(iss, struct tcpcb), - VMSTATE_UINT32(snd_wnd, struct tcpcb), - VMSTATE_UINT32(rcv_wnd, struct tcpcb), - VMSTATE_UINT32(rcv_nxt, struct tcpcb), - VMSTATE_UINT32(rcv_up, struct tcpcb), - VMSTATE_UINT32(irs, struct tcpcb), - VMSTATE_UINT32(rcv_adv, struct tcpcb), - VMSTATE_UINT32(snd_max, struct tcpcb), - VMSTATE_UINT32(snd_cwnd, struct tcpcb), - VMSTATE_UINT32(snd_ssthresh, struct tcpcb), - VMSTATE_INT16(t_idle, struct tcpcb), - VMSTATE_INT16(t_rtt, struct tcpcb), - VMSTATE_UINT32(t_rtseq, struct tcpcb), - VMSTATE_INT16(t_srtt, struct tcpcb), - VMSTATE_INT16(t_rttvar, struct tcpcb), - VMSTATE_UINT16(t_rttmin, struct tcpcb), - VMSTATE_UINT32(max_sndwnd, struct tcpcb), - VMSTATE_UINT8(t_oobflags, struct tcpcb), - VMSTATE_UINT8(t_iobc, struct tcpcb), - VMSTATE_INT16(t_softerror, struct tcpcb), - VMSTATE_UINT8(snd_scale, struct tcpcb), - VMSTATE_UINT8(rcv_scale, struct tcpcb), - VMSTATE_UINT8(request_r_scale, struct tcpcb), - VMSTATE_UINT8(requested_s_scale, struct tcpcb), - VMSTATE_UINT32(ts_recent, struct tcpcb), - VMSTATE_UINT32(ts_recent_age, struct tcpcb), - VMSTATE_UINT32(last_ack_sent, struct tcpcb), - VMSTATE_END_OF_LIST() } -}; - -/* The sbuf has a pair of pointers that are migrated as offsets; - * we calculate the offsets and restore the pointers using - * pre_save/post_load on a tmp structure. - */ -struct sbuf_tmp { - struct sbuf *parent; - uint32_t roff, woff; -}; - -static int sbuf_tmp_pre_save(void *opaque) -{ - struct sbuf_tmp *tmp = opaque; - tmp->woff = tmp->parent->sb_wptr - tmp->parent->sb_data; - tmp->roff = tmp->parent->sb_rptr - tmp->parent->sb_data; - - return 0; -} - -static int sbuf_tmp_post_load(void *opaque, int version) -{ - struct sbuf_tmp *tmp = opaque; - uint32_t requested_len = tmp->parent->sb_datalen; - - /* Allocate the buffer space used by the field after the tmp */ - sbreserve(tmp->parent, tmp->parent->sb_datalen); - - if (tmp->woff >= requested_len || tmp->roff >= requested_len) { - g_critical("invalid sbuf offsets r/w=%u/%u len=%u", tmp->roff, - tmp->woff, requested_len); - return -EINVAL; - } - - tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff; - tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff; - - return 0; -} - - -static const VMStateDescription vmstate_slirp_sbuf_tmp = { - .name = "slirp-sbuf-tmp", - .post_load = sbuf_tmp_post_load, - .pre_save = sbuf_tmp_pre_save, - .version_id = 0, - .fields = (VMStateField[]){ VMSTATE_UINT32(woff, struct sbuf_tmp), - VMSTATE_UINT32(roff, struct sbuf_tmp), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_sbuf = { - .name = "slirp-sbuf", - .version_id = 0, - .fields = (VMStateField[]){ VMSTATE_UINT32(sb_cc, struct sbuf), - VMSTATE_UINT32(sb_datalen, struct sbuf), - VMSTATE_WITH_TMP(struct sbuf, struct sbuf_tmp, - vmstate_slirp_sbuf_tmp), - VMSTATE_VBUFFER_UINT32(sb_data, struct sbuf, 0, - NULL, sb_datalen), - VMSTATE_END_OF_LIST() } -}; - -static bool slirp_older_than_v4(void *opaque, int version_id) -{ - return version_id < 4; -} - -static bool slirp_family_inet(void *opaque, int version_id) -{ - union slirp_sockaddr *ssa = (union slirp_sockaddr *)opaque; - return ssa->ss.ss_family == AF_INET; -} - -static int slirp_socket_pre_load(void *opaque) -{ - struct socket *so = opaque; - - tcp_attach(so); - /* Older versions don't load these fields */ - so->so_ffamily = AF_INET; - so->so_lfamily = AF_INET; - return 0; -} - -#ifndef _WIN32 -#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_UINT32_TEST(f, s, t) -#else -/* Win uses u_long rather than uint32_t - but it's still 32bits long */ -#define VMSTATE_SIN4_ADDR(f, s, t) \ - VMSTATE_SINGLE_TEST(f, s, t, 0, slirp_vmstate_info_uint32, u_long) -#endif - -/* The OS provided ss_family field isn't that portable; it's size - * and type varies (16/8 bit, signed, unsigned) - * and the values it contains aren't fully portable. - */ -typedef struct SS_FamilyTmpStruct { - union slirp_sockaddr *parent; - uint16_t portable_family; -} SS_FamilyTmpStruct; - -#define SS_FAMILY_MIG_IPV4 2 /* Linux, BSD, Win... */ -#define SS_FAMILY_MIG_IPV6 10 /* Linux */ -#define SS_FAMILY_MIG_OTHER 0xffff - -static int ss_family_pre_save(void *opaque) -{ - SS_FamilyTmpStruct *tss = opaque; - - tss->portable_family = SS_FAMILY_MIG_OTHER; - - if (tss->parent->ss.ss_family == AF_INET) { - tss->portable_family = SS_FAMILY_MIG_IPV4; - } else if (tss->parent->ss.ss_family == AF_INET6) { - tss->portable_family = SS_FAMILY_MIG_IPV6; - } - - return 0; -} - -static int ss_family_post_load(void *opaque, int version_id) -{ - SS_FamilyTmpStruct *tss = opaque; - - switch (tss->portable_family) { - case SS_FAMILY_MIG_IPV4: - tss->parent->ss.ss_family = AF_INET; - break; - case SS_FAMILY_MIG_IPV6: - case 23: /* compatibility: AF_INET6 from mingw */ - case 28: /* compatibility: AF_INET6 from FreeBSD sys/socket.h */ - tss->parent->ss.ss_family = AF_INET6; - break; - default: - g_critical("invalid ss_family type %x", tss->portable_family); - return -EINVAL; - } - - return 0; -} - -static const VMStateDescription vmstate_slirp_ss_family = { - .name = "slirp-socket-addr/ss_family", - .pre_save = ss_family_pre_save, - .post_load = ss_family_post_load, - .fields = - (VMStateField[]){ VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_socket_addr = { - .name = "slirp-socket-addr", - .version_id = 4, - .fields = - (VMStateField[]){ - VMSTATE_WITH_TMP(union slirp_sockaddr, SS_FamilyTmpStruct, - vmstate_slirp_ss_family), - VMSTATE_SIN4_ADDR(sin.sin_addr.s_addr, union slirp_sockaddr, - slirp_family_inet), - VMSTATE_UINT16_TEST(sin.sin_port, union slirp_sockaddr, - slirp_family_inet), - -#if 0 - /* Untested: Needs checking by someone with IPv6 test */ - VMSTATE_BUFFER_TEST(sin6.sin6_addr, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT16_TEST(sin6.sin6_port, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT32_TEST(sin6.sin6_flowinfo, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT32_TEST(sin6.sin6_scope_id, union slirp_sockaddr, - slirp_family_inet6), -#endif - - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_socket = { - .name = "slirp-socket", - .version_id = 4, - .pre_load = slirp_socket_pre_load, - .fields = - (VMStateField[]){ - VMSTATE_UINT32(so_urgc, struct socket), - /* Pre-v4 versions */ - VMSTATE_SIN4_ADDR(so_faddr.s_addr, struct socket, - slirp_older_than_v4), - VMSTATE_SIN4_ADDR(so_laddr.s_addr, struct socket, - slirp_older_than_v4), - VMSTATE_UINT16_TEST(so_fport, struct socket, slirp_older_than_v4), - VMSTATE_UINT16_TEST(so_lport, struct socket, slirp_older_than_v4), - /* v4 and newer */ - VMSTATE_STRUCT(fhost, struct socket, 4, vmstate_slirp_socket_addr, - union slirp_sockaddr), - VMSTATE_STRUCT(lhost, struct socket, 4, vmstate_slirp_socket_addr, - union slirp_sockaddr), - - VMSTATE_UINT8(so_iptos, struct socket), - VMSTATE_UINT8(so_emu, struct socket), - VMSTATE_UINT8(so_type, struct socket), - VMSTATE_INT32(so_state, struct socket), - VMSTATE_STRUCT(so_rcv, struct socket, 0, vmstate_slirp_sbuf, - struct sbuf), - VMSTATE_STRUCT(so_snd, struct socket, 0, vmstate_slirp_sbuf, - struct sbuf), - VMSTATE_STRUCT_POINTER(so_tcpcb, struct socket, vmstate_slirp_tcp, - struct tcpcb), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_bootp_client = { - .name = "slirp_bootpclient", - .fields = (VMStateField[]){ VMSTATE_UINT16(allocated, BOOTPClient), - VMSTATE_BUFFER(macaddr, BOOTPClient), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp = { - .name = "slirp", - .version_id = 4, - .fields = (VMStateField[]){ VMSTATE_UINT16_V(ip_id, Slirp, 2), - VMSTATE_STRUCT_ARRAY( - bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3, - vmstate_slirp_bootp_client, BOOTPClient), - VMSTATE_END_OF_LIST() } -}; - -void slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque) -{ - struct gfwd_list *ex_ptr; - SlirpOStream f = { - .write_cb = write_cb, - .opaque = opaque, - }; - - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) - if (ex_ptr->write_cb) { - struct socket *so; - so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, - ntohs(ex_ptr->ex_fport)); - if (!so) { - continue; - } - - slirp_ostream_write_u8(&f, 42); - slirp_vmstate_save_state(&f, &vmstate_slirp_socket, so); - } - slirp_ostream_write_u8(&f, 0); - - slirp_vmstate_save_state(&f, &vmstate_slirp, slirp); -} - - -int slirp_state_load(Slirp *slirp, int version_id, SlirpReadCb read_cb, - void *opaque) -{ - struct gfwd_list *ex_ptr; - SlirpIStream f = { - .read_cb = read_cb, - .opaque = opaque, - }; - - while (slirp_istream_read_u8(&f)) { - int ret; - struct socket *so = socreate(slirp, -1); - - ret = - slirp_vmstate_load_state(&f, &vmstate_slirp_socket, so, version_id); - if (ret < 0) { - return ret; - } - - if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) != - slirp->vnetwork_addr.s_addr) { - return -EINVAL; - } - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->write_cb && - so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr && - so->so_fport == ex_ptr->ex_fport) { - break; - } - } - if (!ex_ptr) { - return -EINVAL; - } - - so->guestfwd = ex_ptr; - } - - return slirp_vmstate_load_state(&f, &vmstate_slirp, slirp, version_id); -} - -int slirp_state_version(void) -{ - return 4; -} diff --git a/src/network/slirp/stream.c b/src/network/slirp/stream.c deleted file mode 100644 index 541986e6c..000000000 --- a/src/network/slirp/stream.c +++ /dev/null @@ -1,120 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * libslirp io streams - * - * Copyright (c) 2018 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "stream.h" -#include - -bool slirp_istream_read(SlirpIStream *f, void *buf, size_t size) -{ - return f->read_cb(buf, size, f->opaque) == size; -} - -bool slirp_ostream_write(SlirpOStream *f, const void *buf, size_t size) -{ - return f->write_cb(buf, size, f->opaque) == size; -} - -uint8_t slirp_istream_read_u8(SlirpIStream *f) -{ - uint8_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return b; - } - - return 0; -} - -bool slirp_ostream_write_u8(SlirpOStream *f, uint8_t b) -{ - return slirp_ostream_write(f, &b, sizeof(b)); -} - -uint16_t slirp_istream_read_u16(SlirpIStream *f) -{ - uint16_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GUINT16_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_u16(SlirpOStream *f, uint16_t b) -{ - b = GUINT16_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} - -uint32_t slirp_istream_read_u32(SlirpIStream *f) -{ - uint32_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GUINT32_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_u32(SlirpOStream *f, uint32_t b) -{ - b = GUINT32_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} - -int16_t slirp_istream_read_i16(SlirpIStream *f) -{ - int16_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GINT16_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_i16(SlirpOStream *f, int16_t b) -{ - b = GINT16_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} - -int32_t slirp_istream_read_i32(SlirpIStream *f) -{ - int32_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GINT32_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_i32(SlirpOStream *f, int32_t b) -{ - b = GINT32_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} diff --git a/src/network/slirp/stream.h b/src/network/slirp/stream.h deleted file mode 100644 index 08bb5b661..000000000 --- a/src/network/slirp/stream.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef STREAM_H_ -#define STREAM_H_ - -#include "libslirp.h" - -typedef struct SlirpIStream { - SlirpReadCb read_cb; - void *opaque; -} SlirpIStream; - -typedef struct SlirpOStream { - SlirpWriteCb write_cb; - void *opaque; -} SlirpOStream; - -bool slirp_istream_read(SlirpIStream *f, void *buf, size_t size); -bool slirp_ostream_write(SlirpOStream *f, const void *buf, size_t size); - -uint8_t slirp_istream_read_u8(SlirpIStream *f); -bool slirp_ostream_write_u8(SlirpOStream *f, uint8_t b); - -uint16_t slirp_istream_read_u16(SlirpIStream *f); -bool slirp_ostream_write_u16(SlirpOStream *f, uint16_t b); - -uint32_t slirp_istream_read_u32(SlirpIStream *f); -bool slirp_ostream_write_u32(SlirpOStream *f, uint32_t b); - -int16_t slirp_istream_read_i16(SlirpIStream *f); -bool slirp_ostream_write_i16(SlirpOStream *f, int16_t b); - -int32_t slirp_istream_read_i32(SlirpIStream *f); -bool slirp_ostream_write_i32(SlirpOStream *f, int32_t b); - -#endif /* STREAM_H_ */ diff --git a/src/network/slirp/tcp.h b/src/network/slirp/tcp.h deleted file mode 100644 index 211dfec39..000000000 --- a/src/network/slirp/tcp.h +++ /dev/null @@ -1,169 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp.h 8.1 (Berkeley) 6/10/93 - * tcp.h,v 1.3 1994/08/21 05:27:34 paul Exp - */ - -#ifndef TCP_H -#define TCP_H - -#include - -typedef uint32_t tcp_seq; - -#define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */ -#define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */ - -#define TCP_SNDSPACE 1024 * 128 -#define TCP_RCVSPACE 1024 * 128 -#define TCP_MAXSEG_MAX 32768 - -/* - * TCP header. - * Per RFC 793, September, 1981. - */ -#define tcphdr slirp_tcphdr -struct tcphdr { - uint16_t th_sport; /* source port */ - uint16_t th_dport; /* destination port */ - tcp_seq th_seq; /* sequence number */ - tcp_seq th_ack; /* acknowledgement number */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t th_off : 4, /* data offset */ - th_x2 : 4; /* (unused) */ -#else - uint8_t th_x2 : 4, /* (unused) */ - th_off : 4; /* data offset */ -#endif - uint8_t th_flags; - uint16_t th_win; /* window */ - uint16_t th_sum; /* checksum */ - uint16_t th_urp; /* urgent pointer */ -}; - -#include "tcp_var.h" - -#ifndef TH_FIN -#define TH_FIN 0x01 -#define TH_SYN 0x02 -#define TH_RST 0x04 -#define TH_PUSH 0x08 -#define TH_ACK 0x10 -#define TH_URG 0x20 -#endif - -#ifndef TCPOPT_EOL -#define TCPOPT_EOL 0 -#define TCPOPT_NOP 1 -#define TCPOPT_MAXSEG 2 -#define TCPOPT_WINDOW 3 -#define TCPOPT_SACK_PERMITTED 4 /* Experimental */ -#define TCPOPT_SACK 5 /* Experimental */ -#define TCPOPT_TIMESTAMP 8 - -#define TCPOPT_TSTAMP_HDR \ - (TCPOPT_NOP << 24 | TCPOPT_NOP << 16 | TCPOPT_TIMESTAMP << 8 | \ - TCPOLEN_TIMESTAMP) -#endif - -#ifndef TCPOLEN_MAXSEG -#define TCPOLEN_MAXSEG 4 -#define TCPOLEN_WINDOW 3 -#define TCPOLEN_SACK_PERMITTED 2 -#define TCPOLEN_TIMESTAMP 10 -#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP + 2) /* appendix A */ -#endif - -#undef TCP_MAXWIN -#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ - -#undef TCP_MAX_WINSHIFT -#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ - -/* - * User-settable options (used with setsockopt). - * - * We don't use the system headers on unix because we have conflicting - * local structures. We can't avoid the system definitions on Windows, - * so we undefine them. - */ -#undef TCP_NODELAY -#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ -#undef TCP_MAXSEG - -/* - * TCP FSM state definitions. - * Per RFC793, September, 1981. - */ - -#define TCP_NSTATES 11 - -#define TCPS_CLOSED 0 /* closed */ -#define TCPS_LISTEN 1 /* listening for connection */ -#define TCPS_SYN_SENT 2 /* active, have sent syn */ -#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ -/* states < TCPS_ESTABLISHED are those where connections not established */ -#define TCPS_ESTABLISHED 4 /* established */ -#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ -/* states > TCPS_CLOSE_WAIT are those where user has closed */ -#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ -#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ -#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ -/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ -#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ -#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ - -#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED) -#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED) -#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT) - -/* - * TCP sequence numbers are 32 bit integers operated - * on with modular arithmetic. These macros can be - * used to compare such integers. - */ -#define SEQ_LT(a, b) ((int)((a) - (b)) < 0) -#define SEQ_LEQ(a, b) ((int)((a) - (b)) <= 0) -#define SEQ_GT(a, b) ((int)((a) - (b)) > 0) -#define SEQ_GEQ(a, b) ((int)((a) - (b)) >= 0) - -/* - * Macros to initialize tcp sequence numbers for - * send and receive from initial send and receive - * sequence numbers. - */ -#define tcp_rcvseqinit(tp) (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1 - -#define tcp_sendseqinit(tp) \ - (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = (tp)->iss - -#define TCP_ISSINCR (125 * 1024) /* increment for tcp_iss each second */ - -#endif diff --git a/src/network/slirp/tcp_input.c b/src/network/slirp/tcp_input.c deleted file mode 100644 index ecca972ee..000000000 --- a/src/network/slirp/tcp_input.c +++ /dev/null @@ -1,1552 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_input.c 8.5 (Berkeley) 4/10/94 - * tcp_input.c,v 1.10 1994/10/13 18:36:32 wollman Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include "ip_icmp.h" - -#define TCPREXMTTHRESH 3 - -#define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * PR_SLOWHZ) - -/* for modulo comparisons of timestamps */ -#define TSTMP_LT(a, b) ((int)((a) - (b)) < 0) -#define TSTMP_GEQ(a, b) ((int)((a) - (b)) >= 0) - -/* - * Insert segment ti into reassembly queue of tcp with - * control block tp. Return TH_FIN if reassembly now includes - * a segment with FIN. The macro form does the common case inline - * (segment is the next to be received on an established connection, - * and the queue is empty), avoiding linkage into and removal - * from the queue and repetition of various conversions. - * Set DELACK for segments received in order, but ack immediately - * when segments are out of order (so fast retransmit can work). - */ -#define TCP_REASS(tp, ti, m, so, flags) \ - { \ - if ((ti)->ti_seq == (tp)->rcv_nxt && tcpfrag_list_empty(tp) && \ - (tp)->t_state == TCPS_ESTABLISHED) { \ - tp->t_flags |= TF_DELACK; \ - (tp)->rcv_nxt += (ti)->ti_len; \ - flags = (ti)->ti_flags & TH_FIN; \ - if (so->so_emu) { \ - if (tcp_emu((so), (m))) \ - sbappend(so, (m)); \ - } else \ - sbappend((so), (m)); \ - } else { \ - (flags) = tcp_reass((tp), (ti), (m)); \ - tp->t_flags |= TF_ACKNOW; \ - } \ - } - -static void tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt, - struct tcpiphdr *ti); -static void tcp_xmit_timer(register struct tcpcb *tp, int rtt); - -static int tcp_reass(register struct tcpcb *tp, register struct tcpiphdr *ti, - struct mbuf *m) -{ - register struct tcpiphdr *q; - struct socket *so = tp->t_socket; - int flags; - - /* - * Call with ti==NULL after become established to - * force pre-ESTABLISHED data up to user socket. - */ - if (ti == NULL) - goto present; - - /* - * Find a segment which begins after this one does. - */ - for (q = tcpfrag_list_first(tp); !tcpfrag_list_end(q, tp); - q = tcpiphdr_next(q)) - if (SEQ_GT(q->ti_seq, ti->ti_seq)) - break; - - /* - * If there is a preceding segment, it may provide some of - * our data already. If so, drop the data from the incoming - * segment. If it provides all of our data, drop us. - */ - if (!tcpfrag_list_end(tcpiphdr_prev(q), tp)) { - register int i; - q = tcpiphdr_prev(q); - /* conversion to int (in i) handles seq wraparound */ - i = q->ti_seq + q->ti_len - ti->ti_seq; - if (i > 0) { - if (i >= ti->ti_len) { - m_free(m); - /* - * Try to present any queued data - * at the left window edge to the user. - * This is needed after the 3-WHS - * completes. - */ - goto present; /* ??? */ - } - m_adj(m, i); - ti->ti_len -= i; - ti->ti_seq += i; - } - q = tcpiphdr_next(q); - } - ti->ti_mbuf = m; - - /* - * While we overlap succeeding segments trim them or, - * if they are completely covered, dequeue them. - */ - while (!tcpfrag_list_end(q, tp)) { - register int i = (ti->ti_seq + ti->ti_len) - q->ti_seq; - if (i <= 0) - break; - if (i < q->ti_len) { - q->ti_seq += i; - q->ti_len -= i; - m_adj(q->ti_mbuf, i); - break; - } - q = tcpiphdr_next(q); - m = tcpiphdr_prev(q)->ti_mbuf; - slirp_remque(tcpiphdr2qlink(tcpiphdr_prev(q))); - m_free(m); - } - - /* - * Stick new segment in its place. - */ - slirp_insque(tcpiphdr2qlink(ti), tcpiphdr2qlink(tcpiphdr_prev(q))); - -present: - /* - * Present data to user, advancing rcv_nxt through - * completed sequence space. - */ - if (!TCPS_HAVEESTABLISHED(tp->t_state)) - return (0); - ti = tcpfrag_list_first(tp); - if (tcpfrag_list_end(ti, tp) || ti->ti_seq != tp->rcv_nxt) - return (0); - if (tp->t_state == TCPS_SYN_RECEIVED && ti->ti_len) - return (0); - do { - tp->rcv_nxt += ti->ti_len; - flags = ti->ti_flags & TH_FIN; - slirp_remque(tcpiphdr2qlink(ti)); - m = ti->ti_mbuf; - ti = tcpiphdr_next(ti); - if (so->so_state & SS_FCANTSENDMORE) - m_free(m); - else { - if (so->so_emu) { - if (tcp_emu(so, m)) - sbappend(so, m); - } else - sbappend(so, m); - } - } while (ti != (struct tcpiphdr *)tp && ti->ti_seq == tp->rcv_nxt); - return (flags); -} - -/* - * TCP input routine, follows pages 65-76 of the - * protocol specification dated September, 1981 very closely. - */ -void tcp_input(struct mbuf *m, int iphlen, struct socket *inso, - unsigned short af) -{ - struct ip save_ip, *ip; - struct ip6 save_ip6, *ip6; - register struct tcpiphdr *ti; - char *optp = NULL; - int optlen = 0; - int len, tlen, off; - register struct tcpcb *tp = NULL; - register int tiflags; - struct socket *so = NULL; - int todrop, acked, ourfinisacked, needoutput = 0; - int iss = 0; - uint32_t tiwin; - int ret; - struct sockaddr_storage lhost, fhost; - struct sockaddr_in *lhost4, *fhost4; - struct sockaddr_in6 *lhost6, *fhost6; - struct gfwd_list *ex_ptr; - Slirp *slirp; - - DEBUG_CALL("tcp_input"); - DEBUG_ARG("m = %p iphlen = %2d inso = %p", m, iphlen, inso); - - memset(&lhost, 0, sizeof(struct sockaddr_storage)); - memset(&fhost, 0, sizeof(struct sockaddr_storage)); - - /* - * If called with m == 0, then we're continuing the connect - */ - if (m == NULL) { - so = inso; - slirp = so->slirp; - - /* Re-set a few variables */ - tp = sototcpcb(so); - m = so->so_m; - so->so_m = NULL; - ti = so->so_ti; - tiwin = ti->ti_win; - tiflags = ti->ti_flags; - - goto cont_conn; - } - slirp = m->slirp; - switch (af) { - case AF_INET: - M_DUP_DEBUG(slirp, m, 0, - sizeof(struct tcpiphdr) - sizeof(struct ip) - sizeof(struct tcphdr)); - break; - case AF_INET6: - M_DUP_DEBUG(slirp, m, 0, - sizeof(struct tcpiphdr) - sizeof(struct ip6) - sizeof(struct tcphdr)); - break; - } - - ip = mtod(m, struct ip *); - ip6 = mtod(m, struct ip6 *); - - switch (af) { - case AF_INET: - if (iphlen > sizeof(struct ip)) { - ip_stripoptions(m, (struct mbuf *)0); - iphlen = sizeof(struct ip); - } - /* XXX Check if too short */ - - - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip = *ip; - save_ip.ip_len += iphlen; - - /* - * Get IP and TCP header together in first mbuf. - * Note: IP leaves IP header in first mbuf. - */ - m->m_data -= - sizeof(struct tcpiphdr) - sizeof(struct ip) - sizeof(struct tcphdr); - m->m_len += - sizeof(struct tcpiphdr) - sizeof(struct ip) - sizeof(struct tcphdr); - ti = mtod(m, struct tcpiphdr *); - - /* - * Checksum extended TCP header and data. - */ - tlen = ip->ip_len; - tcpiphdr2qlink(ti)->next = tcpiphdr2qlink(ti)->prev = NULL; - memset(&ti->ih_mbuf, 0, sizeof(struct mbuf_ptr)); - memset(&ti->ti, 0, sizeof(ti->ti)); - ti->ti_x0 = 0; - ti->ti_src = save_ip.ip_src; - ti->ti_dst = save_ip.ip_dst; - ti->ti_pr = save_ip.ip_p; - ti->ti_len = htons((uint16_t)tlen); - break; - - case AF_INET6: - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip6 = *ip6; - /* - * Get IP and TCP header together in first mbuf. - * Note: IP leaves IP header in first mbuf. - */ - m->m_data -= sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - m->m_len += sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - ti = mtod(m, struct tcpiphdr *); - - tlen = ip6->ip_pl; - tcpiphdr2qlink(ti)->next = tcpiphdr2qlink(ti)->prev = NULL; - memset(&ti->ih_mbuf, 0, sizeof(struct mbuf_ptr)); - memset(&ti->ti, 0, sizeof(ti->ti)); - ti->ti_x0 = 0; - ti->ti_src6 = save_ip6.ip_src; - ti->ti_dst6 = save_ip6.ip_dst; - ti->ti_nh6 = save_ip6.ip_nh; - ti->ti_len = htons((uint16_t)tlen); - break; - - default: - g_assert_not_reached(); - } - - len = ((sizeof(struct tcpiphdr) - sizeof(struct tcphdr)) + tlen); - if (cksum(m, len)) { - goto drop; - } - - /* - * Check that TCP offset makes sense, - * pull out TCP options and adjust length. XXX - */ - off = ti->ti_off << 2; - if (off < sizeof(struct tcphdr) || off > tlen) { - goto drop; - } - tlen -= off; - ti->ti_len = tlen; - if (off > sizeof(struct tcphdr)) { - optlen = off - sizeof(struct tcphdr); - optp = mtod(m, char *) + sizeof(struct tcpiphdr); - } - tiflags = ti->ti_flags; - - /* - * Convert TCP protocol specific fields to host format. - */ - NTOHL(ti->ti_seq); - NTOHL(ti->ti_ack); - NTOHS(ti->ti_win); - NTOHS(ti->ti_urp); - - /* - * Drop TCP, IP headers and TCP options. - */ - m->m_data += sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - m->m_len -= sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - - /* - * Locate pcb for segment. - */ -findso: - lhost.ss_family = af; - fhost.ss_family = af; - switch (af) { - case AF_INET: - lhost4 = (struct sockaddr_in *)&lhost; - lhost4->sin_addr = ti->ti_src; - lhost4->sin_port = ti->ti_sport; - fhost4 = (struct sockaddr_in *)&fhost; - fhost4->sin_addr = ti->ti_dst; - fhost4->sin_port = ti->ti_dport; - break; - case AF_INET6: - lhost6 = (struct sockaddr_in6 *)&lhost; - lhost6->sin6_addr = ti->ti_src6; - lhost6->sin6_port = ti->ti_sport; - fhost6 = (struct sockaddr_in6 *)&fhost; - fhost6->sin6_addr = ti->ti_dst6; - fhost6->sin6_port = ti->ti_dport; - break; - default: - g_assert_not_reached(); - } - - so = solookup(&slirp->tcp_last_so, &slirp->tcb, &lhost, &fhost); - - /* - * If the state is CLOSED (i.e., TCB does not exist) then - * all data in the incoming segment is discarded. - * If the TCB exists but is in CLOSED state, it is embryonic, - * but should either do a listen or a connect soon. - * - * state == CLOSED means we've done socreate() but haven't - * attached it to a protocol yet... - * - * XXX If a TCB does not exist, and the TH_SYN flag is - * the only flag set, then create a session, mark it - * as if it was LISTENING, and continue... - */ - if (so == NULL) { - /* TODO: IPv6 */ - if (slirp->restricted) { - /* Any hostfwds will have an existing socket, so we only get here - * for non-hostfwd connections. These should be dropped, unless it - * happens to be a guestfwd. - */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; - ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_fport == ti->ti_dport && - ti->ti_dst.s_addr == ex_ptr->ex_addr.s_addr) { - break; - } - } - if (!ex_ptr) { - goto dropwithreset; - } - } - - if ((tiflags & (TH_SYN | TH_FIN | TH_RST | TH_URG | TH_ACK)) != TH_SYN) - goto dropwithreset; - - so = socreate(slirp, IPPROTO_TCP); - tcp_attach(so); - - sbreserve(&so->so_snd, TCP_SNDSPACE); - sbreserve(&so->so_rcv, TCP_RCVSPACE); - - so->lhost.ss = lhost; - so->fhost.ss = fhost; - - so->so_iptos = tcp_tos(so); - if (so->so_iptos == 0) { - switch (af) { - case AF_INET: - so->so_iptos = ((struct ip *)ti)->ip_tos; - break; - case AF_INET6: - break; - default: - g_assert_not_reached(); - } - } - - tp = sototcpcb(so); - tp->t_state = TCPS_LISTEN; - } - - /* - * If this is a still-connecting socket, this probably - * a retransmit of the SYN. Whether it's a retransmit SYN - * or something else, we nuke it. - */ - if (so->so_state & SS_ISFCONNECTING) - goto drop; - - tp = sototcpcb(so); - - /* XXX Should never fail */ - if (tp == NULL) - goto dropwithreset; - if (tp->t_state == TCPS_CLOSED) - goto drop; - - tiwin = ti->ti_win; - - /* - * Segment received on connection. - * Reset idle time and keep-alive timer. - */ - tp->t_idle = 0; - if (slirp_do_keepalive) - tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL; - else - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE; - - /* - * Process options if not in LISTEN state, - * else do it below (after getting remote address). - */ - if (optp && tp->t_state != TCPS_LISTEN) - tcp_dooptions(tp, (uint8_t *)optp, optlen, ti); - - /* - * Header prediction: check for the two common cases - * of a uni-directional data xfer. If the packet has - * no control flags, is in-sequence, the window didn't - * change and we're not retransmitting, it's a - * candidate. If the length is zero and the ack moved - * forward, we're the sender side of the xfer. Just - * free the data acked & wake any higher level process - * that was blocked waiting for space. If the length - * is non-zero and the ack didn't move, we're the - * receiver side. If we're getting packets in-order - * (the reassembly queue is empty), add the data to - * the socket buffer and note that we need a delayed ack. - * - * XXX Some of these tests are not needed - * eg: the tiwin == tp->snd_wnd prevents many more - * predictions.. with no *real* advantage.. - */ - if (tp->t_state == TCPS_ESTABLISHED && - (tiflags & (TH_SYN | TH_FIN | TH_RST | TH_URG | TH_ACK)) == TH_ACK && - ti->ti_seq == tp->rcv_nxt && tiwin && tiwin == tp->snd_wnd && - tp->snd_nxt == tp->snd_max) { - if (ti->ti_len == 0) { - if (SEQ_GT(ti->ti_ack, tp->snd_una) && - SEQ_LEQ(ti->ti_ack, tp->snd_max) && - tp->snd_cwnd >= tp->snd_wnd) { - /* - * this is a pure ack for outstanding data. - */ - if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq)) - tcp_xmit_timer(tp, tp->t_rtt); - acked = ti->ti_ack - tp->snd_una; - sodrop(so, acked); - tp->snd_una = ti->ti_ack; - m_free(m); - - /* - * If all outstanding data are acked, stop - * retransmit timer, otherwise restart timer - * using current (possibly backed-off) value. - * If process is waiting for space, - * wakeup/selwakeup/signal. If data - * are ready to send, let tcp_output - * decide between more output or persist. - */ - if (tp->snd_una == tp->snd_max) - tp->t_timer[TCPT_REXMT] = 0; - else if (tp->t_timer[TCPT_PERSIST] == 0) - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - - /* - * This is called because sowwakeup might have - * put data into so_snd. Since we don't so sowwakeup, - * we don't need this.. XXX??? - */ - if (so->so_snd.sb_cc) - tcp_output(tp); - - return; - } - } else if (ti->ti_ack == tp->snd_una && tcpfrag_list_empty(tp) && - ti->ti_len <= sbspace(&so->so_rcv)) { - /* - * this is a pure, in-sequence data packet - * with nothing on the reassembly queue and - * we have enough buffer space to take it. - */ - tp->rcv_nxt += ti->ti_len; - /* - * Add data to socket buffer. - */ - if (so->so_emu) { - if (tcp_emu(so, m)) - sbappend(so, m); - } else - sbappend(so, m); - - /* - * If this is a short packet, then ACK now - with Nagel - * congestion avoidance sender won't send more until - * he gets an ACK. - * - * It is better to not delay acks at all to maximize - * TCP throughput. See RFC 2581. - */ - tp->t_flags |= TF_ACKNOW; - tcp_output(tp); - return; - } - } /* header prediction */ - /* - * Calculate amount of space in receive window, - * and then do TCP input processing. - * Receive window is amount of space in rcv queue, - * but not less than advertised window. - */ - { - int win; - win = sbspace(&so->so_rcv); - if (win < 0) - win = 0; - tp->rcv_wnd = MAX(win, (int)(tp->rcv_adv - tp->rcv_nxt)); - } - - switch (tp->t_state) { - /* - * If the state is LISTEN then ignore segment if it contains an RST. - * If the segment contains an ACK then it is bad and send a RST. - * If it does not contain a SYN then it is not interesting; drop it. - * Don't bother responding if the destination was a broadcast. - * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial - * tp->iss, and send a segment: - * - * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss. - * Fill in remote peer address fields if not previously specified. - * Enter SYN_RECEIVED state, and process any other fields of this - * segment in this state. - */ - case TCPS_LISTEN: { - if (tiflags & TH_RST) - goto drop; - if (tiflags & TH_ACK) - goto dropwithreset; - if ((tiflags & TH_SYN) == 0) - goto drop; - - /* - * This has way too many gotos... - * But a bit of spaghetti code never hurt anybody :) - */ - - /* - * If this is destined for the control address, then flag to - * tcp_ctl once connected, otherwise connect - */ - /* TODO: IPv6 */ - if (af == AF_INET && - (so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) == - slirp->vnetwork_addr.s_addr) { - if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr && - so->so_faddr.s_addr != slirp->vnameserver_addr.s_addr) { - /* May be an add exec */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; - ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_fport == so->so_fport && - so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { - so->so_state |= SS_CTL; - break; - } - } - if (so->so_state & SS_CTL) { - goto cont_input; - } - } - /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */ - } - - if (so->so_emu & EMU_NOCONNECT) { - so->so_emu &= ~EMU_NOCONNECT; - goto cont_input; - } - - if ((tcp_fconnect(so, so->so_ffamily) == -1) && (errno != EAGAIN) && - (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) { - uint8_t code; - DEBUG_MISC(" tcp fconnect errno = %d-%s", errno, strerror(errno)); - if (errno == ECONNREFUSED) { - /* ACK the SYN, send RST to refuse the connection */ - tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq)0, - TH_RST | TH_ACK, af); - } else { - switch (af) { - case AF_INET: - code = ICMP_UNREACH_NET; - if (errno == EHOSTUNREACH) { - code = ICMP_UNREACH_HOST; - } - break; - case AF_INET6: - code = ICMP6_UNREACH_NO_ROUTE; - if (errno == EHOSTUNREACH) { - code = ICMP6_UNREACH_ADDRESS; - } - break; - default: - g_assert_not_reached(); - } - HTONL(ti->ti_seq); /* restore tcp header */ - HTONL(ti->ti_ack); - HTONS(ti->ti_win); - HTONS(ti->ti_urp); - m->m_data -= - sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - m->m_len += - sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - switch (af) { - case AF_INET: - m->m_data += sizeof(struct tcpiphdr) - sizeof(struct ip) - - sizeof(struct tcphdr); - m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct ip) - - sizeof(struct tcphdr); - *ip = save_ip; - icmp_send_error(m, ICMP_UNREACH, code, 0, strerror(errno)); - break; - case AF_INET6: - m->m_data += sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - m->m_len -= sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - *ip6 = save_ip6; - icmp6_send_error(m, ICMP6_UNREACH, code); - break; - default: - g_assert_not_reached(); - } - } - tcp_close(tp); - m_free(m); - } else { - /* - * Haven't connected yet, save the current mbuf - * and ti, and return - * XXX Some OS's don't tell us whether the connect() - * succeeded or not. So we must time it out. - */ - so->so_m = m; - so->so_ti = ti; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - tp->t_state = TCPS_SYN_RECEIVED; - /* - * Initialize receive sequence numbers now so that we can send a - * valid RST if the remote end rejects our connection. - */ - tp->irs = ti->ti_seq; - tcp_rcvseqinit(tp); - tcp_template(tp); - } - return; - - cont_conn: - /* m==NULL - * Check if the connect succeeded - */ - if (so->so_state & SS_NOFDREF) { - tp = tcp_close(tp); - goto dropwithreset; - } - cont_input: - tcp_template(tp); - - if (optp) - tcp_dooptions(tp, (uint8_t *)optp, optlen, ti); - - if (iss) - tp->iss = iss; - else - tp->iss = slirp->tcp_iss; - slirp->tcp_iss += TCP_ISSINCR / 2; - tp->irs = ti->ti_seq; - tcp_sendseqinit(tp); - tcp_rcvseqinit(tp); - tp->t_flags |= TF_ACKNOW; - tp->t_state = TCPS_SYN_RECEIVED; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - goto trimthenstep6; - } /* case TCPS_LISTEN */ - - /* - * If the state is SYN_SENT: - * if seg contains an ACK, but not for our SYN, drop the input. - * if seg contains a RST, then drop the connection. - * if seg does not contain SYN, then drop it. - * Otherwise this is an acceptable SYN segment - * initialize tp->rcv_nxt and tp->irs - * if seg contains ack then advance tp->snd_una - * if SYN has been acked change to ESTABLISHED else SYN_RCVD state - * arrange for segment to be acked (eventually) - * continue processing rest of data/controls, beginning with URG - */ - case TCPS_SYN_SENT: - if ((tiflags & TH_ACK) && - (SEQ_LEQ(ti->ti_ack, tp->iss) || SEQ_GT(ti->ti_ack, tp->snd_max))) - goto dropwithreset; - - if (tiflags & TH_RST) { - if (tiflags & TH_ACK) { - tcp_drop(tp, 0); /* XXX Check t_softerror! */ - } - goto drop; - } - - if ((tiflags & TH_SYN) == 0) - goto drop; - if (tiflags & TH_ACK) { - tp->snd_una = ti->ti_ack; - if (SEQ_LT(tp->snd_nxt, tp->snd_una)) - tp->snd_nxt = tp->snd_una; - } - - tp->t_timer[TCPT_REXMT] = 0; - tp->irs = ti->ti_seq; - tcp_rcvseqinit(tp); - tp->t_flags |= TF_ACKNOW; - if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss)) { - soisfconnected(so); - tp->t_state = TCPS_ESTABLISHED; - - tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); - /* - * if we didn't have to retransmit the SYN, - * use its rtt as our initial srtt & rtt var. - */ - if (tp->t_rtt) - tcp_xmit_timer(tp, tp->t_rtt); - } else - tp->t_state = TCPS_SYN_RECEIVED; - - trimthenstep6: - /* - * Advance ti->ti_seq to correspond to first data byte. - * If data, trim to stay within window, - * dropping FIN if necessary. - */ - ti->ti_seq++; - if (ti->ti_len > tp->rcv_wnd) { - todrop = ti->ti_len - tp->rcv_wnd; - m_adj(m, -todrop); - ti->ti_len = tp->rcv_wnd; - tiflags &= ~TH_FIN; - } - tp->snd_wl1 = ti->ti_seq - 1; - tp->rcv_up = ti->ti_seq; - goto step6; - } /* switch tp->t_state */ - /* - * States other than LISTEN or SYN_SENT. - * Check that at least some bytes of segment are within - * receive window. If segment begins before rcv_nxt, - * drop leading data (and SYN); if nothing left, just ack. - */ - todrop = tp->rcv_nxt - ti->ti_seq; - if (todrop > 0) { - if (tiflags & TH_SYN) { - tiflags &= ~TH_SYN; - ti->ti_seq++; - if (ti->ti_urp > 1) - ti->ti_urp--; - else - tiflags &= ~TH_URG; - todrop--; - } - /* - * Following if statement from Stevens, vol. 2, p. 960. - */ - if (todrop > ti->ti_len || - (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) { - /* - * Any valid FIN must be to the left of the window. - * At this point the FIN must be a duplicate or out - * of sequence; drop it. - */ - tiflags &= ~TH_FIN; - - /* - * Send an ACK to resynchronize and drop any data. - * But keep on processing for RST or ACK. - */ - tp->t_flags |= TF_ACKNOW; - todrop = ti->ti_len; - } - m_adj(m, todrop); - ti->ti_seq += todrop; - ti->ti_len -= todrop; - if (ti->ti_urp > todrop) - ti->ti_urp -= todrop; - else { - tiflags &= ~TH_URG; - ti->ti_urp = 0; - } - } - /* - * If new data are received on a connection after the - * user processes are gone, then RST the other end. - */ - if ((so->so_state & SS_NOFDREF) && tp->t_state > TCPS_CLOSE_WAIT && - ti->ti_len) { - tp = tcp_close(tp); - goto dropwithreset; - } - - /* - * If segment ends after window, drop trailing data - * (and PUSH and FIN); if nothing left, just ACK. - */ - todrop = (ti->ti_seq + ti->ti_len) - (tp->rcv_nxt + tp->rcv_wnd); - if (todrop > 0) { - if (todrop >= ti->ti_len) { - /* - * If a new connection request is received - * while in TIME_WAIT, drop the old connection - * and start over if the sequence numbers - * are above the previous ones. - */ - if (tiflags & TH_SYN && tp->t_state == TCPS_TIME_WAIT && - SEQ_GT(ti->ti_seq, tp->rcv_nxt)) { - iss = tp->rcv_nxt + TCP_ISSINCR; - tp = tcp_close(tp); - goto findso; - } - /* - * If window is closed can only take segments at - * window edge, and have to drop data and PUSH from - * incoming segments. Continue processing, but - * remember to ack. Otherwise, drop segment - * and ack. - */ - if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) { - tp->t_flags |= TF_ACKNOW; - } else { - goto dropafterack; - } - } - m_adj(m, -todrop); - ti->ti_len -= todrop; - tiflags &= ~(TH_PUSH | TH_FIN); - } - - /* - * If the RST bit is set examine the state: - * SYN_RECEIVED STATE: - * If passive open, return to LISTEN state. - * If active open, inform user that connection was refused. - * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES: - * Inform user that connection was reset, and close tcb. - * CLOSING, LAST_ACK, TIME_WAIT STATES - * Close the tcb. - */ - if (tiflags & TH_RST) - switch (tp->t_state) { - case TCPS_SYN_RECEIVED: - case TCPS_ESTABLISHED: - case TCPS_FIN_WAIT_1: - case TCPS_FIN_WAIT_2: - case TCPS_CLOSE_WAIT: - tp->t_state = TCPS_CLOSED; - tcp_close(tp); - goto drop; - - case TCPS_CLOSING: - case TCPS_LAST_ACK: - case TCPS_TIME_WAIT: - tcp_close(tp); - goto drop; - } - - /* - * If a SYN is in the window, then this is an - * error and we send an RST and drop the connection. - */ - if (tiflags & TH_SYN) { - tp = tcp_drop(tp, 0); - goto dropwithreset; - } - - /* - * If the ACK bit is off we drop the segment and return. - */ - if ((tiflags & TH_ACK) == 0) - goto drop; - - /* - * Ack processing. - */ - switch (tp->t_state) { - /* - * In SYN_RECEIVED state if the ack ACKs our SYN then enter - * ESTABLISHED state and continue processing, otherwise - * send an RST. una<=ack<=max - */ - case TCPS_SYN_RECEIVED: - - if (SEQ_GT(tp->snd_una, ti->ti_ack) || SEQ_GT(ti->ti_ack, tp->snd_max)) - goto dropwithreset; - tp->t_state = TCPS_ESTABLISHED; - /* - * The sent SYN is ack'ed with our sequence number +1 - * The first data byte already in the buffer will get - * lost if no correction is made. This is only needed for - * SS_CTL since the buffer is empty otherwise. - * tp->snd_una++; or: - */ - tp->snd_una = ti->ti_ack; - if (so->so_state & SS_CTL) { - /* So tcp_ctl reports the right state */ - ret = tcp_ctl(so); - if (ret == 1) { - soisfconnected(so); - so->so_state &= ~SS_CTL; /* success XXX */ - } else if (ret == 2) { - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; /* CTL_CMD */ - } else { - needoutput = 1; - tp->t_state = TCPS_FIN_WAIT_1; - } - } else { - soisfconnected(so); - } - - tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); - tp->snd_wl1 = ti->ti_seq - 1; - /* Avoid ack processing; snd_una==ti_ack => dup ack */ - goto synrx_to_est; - /* fall into ... */ - - /* - * In ESTABLISHED state: drop duplicate ACKs; ACK out of range - * ACKs. If the ack is in the range - * tp->snd_una < ti->ti_ack <= tp->snd_max - * then advance tp->snd_una to ti->ti_ack and drop - * data from the retransmission queue. If this ACK reflects - * more up to date window information we update our window information. - */ - case TCPS_ESTABLISHED: - case TCPS_FIN_WAIT_1: - case TCPS_FIN_WAIT_2: - case TCPS_CLOSE_WAIT: - case TCPS_CLOSING: - case TCPS_LAST_ACK: - case TCPS_TIME_WAIT: - - if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) { - if (ti->ti_len == 0 && tiwin == tp->snd_wnd) { - DEBUG_MISC(" dup ack m = %p so = %p", m, so); - /* - * If we have outstanding data (other than - * a window probe), this is a completely - * duplicate ack (ie, window info didn't - * change), the ack is the biggest we've - * seen and we've seen exactly our rexmt - * threshold of them, assume a packet - * has been dropped and retransmit it. - * Kludge snd_nxt & the congestion - * window so we send only this one - * packet. - * - * We know we're losing at the current - * window size so do congestion avoidance - * (set ssthresh to half the current window - * and pull our congestion window back to - * the new ssthresh). - * - * Dup acks mean that packets have left the - * network (they're now cached at the receiver) - * so bump cwnd by the amount in the receiver - * to keep a constant cwnd packets in the - * network. - */ - if (tp->t_timer[TCPT_REXMT] == 0 || ti->ti_ack != tp->snd_una) - tp->t_dupacks = 0; - else if (++tp->t_dupacks == TCPREXMTTHRESH) { - tcp_seq onxt = tp->snd_nxt; - unsigned win = - MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; - - if (win < 2) - win = 2; - tp->snd_ssthresh = win * tp->t_maxseg; - tp->t_timer[TCPT_REXMT] = 0; - tp->t_rtt = 0; - tp->snd_nxt = ti->ti_ack; - tp->snd_cwnd = tp->t_maxseg; - tcp_output(tp); - tp->snd_cwnd = - tp->snd_ssthresh + tp->t_maxseg * tp->t_dupacks; - if (SEQ_GT(onxt, tp->snd_nxt)) - tp->snd_nxt = onxt; - goto drop; - } else if (tp->t_dupacks > TCPREXMTTHRESH) { - tp->snd_cwnd += tp->t_maxseg; - tcp_output(tp); - goto drop; - } - } else - tp->t_dupacks = 0; - break; - } - synrx_to_est: - /* - * If the congestion window was inflated to account - * for the other side's cached packets, retract it. - */ - if (tp->t_dupacks > TCPREXMTTHRESH && tp->snd_cwnd > tp->snd_ssthresh) - tp->snd_cwnd = tp->snd_ssthresh; - tp->t_dupacks = 0; - if (SEQ_GT(ti->ti_ack, tp->snd_max)) { - goto dropafterack; - } - acked = ti->ti_ack - tp->snd_una; - - /* - * If transmit timer is running and timed sequence - * number was acked, update smoothed round trip time. - * Since we now have an rtt measurement, cancel the - * timer backoff (cf., Phil Karn's retransmit alg.). - * Recompute the initial retransmit timer. - */ - if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq)) - tcp_xmit_timer(tp, tp->t_rtt); - - /* - * If all outstanding data is acked, stop retransmit - * timer and remember to restart (more output or persist). - * If there is more data to be acked, restart retransmit - * timer, using current (possibly backed-off) value. - */ - if (ti->ti_ack == tp->snd_max) { - tp->t_timer[TCPT_REXMT] = 0; - needoutput = 1; - } else if (tp->t_timer[TCPT_PERSIST] == 0) - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - /* - * When new data is acked, open the congestion window. - * If the window gives us less than ssthresh packets - * in flight, open exponentially (maxseg per packet). - * Otherwise open linearly: maxseg per window - * (maxseg^2 / cwnd per packet). - */ - { - register unsigned cw = tp->snd_cwnd; - register unsigned incr = tp->t_maxseg; - - if (cw > tp->snd_ssthresh) - incr = incr * incr / cw; - tp->snd_cwnd = MIN(cw + incr, TCP_MAXWIN << tp->snd_scale); - } - if (acked > so->so_snd.sb_cc) { - tp->snd_wnd -= so->so_snd.sb_cc; - sodrop(so, (int)so->so_snd.sb_cc); - ourfinisacked = 1; - } else { - sodrop(so, acked); - tp->snd_wnd -= acked; - ourfinisacked = 0; - } - tp->snd_una = ti->ti_ack; - if (SEQ_LT(tp->snd_nxt, tp->snd_una)) - tp->snd_nxt = tp->snd_una; - - switch (tp->t_state) { - /* - * In FIN_WAIT_1 STATE in addition to the processing - * for the ESTABLISHED state if our FIN is now acknowledged - * then enter FIN_WAIT_2. - */ - case TCPS_FIN_WAIT_1: - if (ourfinisacked) { - /* - * If we can't receive any more - * data, then closing user can proceed. - * Starting the timer is contrary to the - * specification, but if we don't get a FIN - * we'll hang forever. - */ - if (so->so_state & SS_FCANTRCVMORE) { - tp->t_timer[TCPT_2MSL] = TCP_MAXIDLE; - } - tp->t_state = TCPS_FIN_WAIT_2; - } - break; - - /* - * In CLOSING STATE in addition to the processing for - * the ESTABLISHED state if the ACK acknowledges our FIN - * then enter the TIME-WAIT state, otherwise ignore - * the segment. - */ - case TCPS_CLOSING: - if (ourfinisacked) { - tp->t_state = TCPS_TIME_WAIT; - tcp_canceltimers(tp); - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - } - break; - - /* - * In LAST_ACK, we may still be waiting for data to drain - * and/or to be acked, as well as for the ack of our FIN. - * If our FIN is now acknowledged, delete the TCB, - * enter the closed state and return. - */ - case TCPS_LAST_ACK: - if (ourfinisacked) { - tcp_close(tp); - goto drop; - } - break; - - /* - * In TIME_WAIT state the only thing that should arrive - * is a retransmission of the remote FIN. Acknowledge - * it and restart the finack timer. - */ - case TCPS_TIME_WAIT: - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - goto dropafterack; - } - } /* switch(tp->t_state) */ - -step6: - /* - * Update window information. - * Don't look at window if no ACK: TAC's send garbage on first SYN. - */ - if ((tiflags & TH_ACK) && - (SEQ_LT(tp->snd_wl1, ti->ti_seq) || - (tp->snd_wl1 == ti->ti_seq && - (SEQ_LT(tp->snd_wl2, ti->ti_ack) || - (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) { - tp->snd_wnd = tiwin; - tp->snd_wl1 = ti->ti_seq; - tp->snd_wl2 = ti->ti_ack; - if (tp->snd_wnd > tp->max_sndwnd) - tp->max_sndwnd = tp->snd_wnd; - needoutput = 1; - } - - /* - * Process segments with URG. - */ - if ((tiflags & TH_URG) && ti->ti_urp && - TCPS_HAVERCVDFIN(tp->t_state) == 0) { - /* - * This is a kludge, but if we receive and accept - * random urgent pointers, we'll crash in - * soreceive. It's hard to imagine someone - * actually wanting to send this much urgent data. - */ - if (ti->ti_urp + so->so_rcv.sb_cc > so->so_rcv.sb_datalen) { - ti->ti_urp = 0; - tiflags &= ~TH_URG; - goto dodata; - } - /* - * If this segment advances the known urgent pointer, - * then mark the data stream. This should not happen - * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since - * a FIN has been received from the remote side. - * In these states we ignore the URG. - * - * According to RFC961 (Assigned Protocols), - * the urgent pointer points to the last octet - * of urgent data. We continue, however, - * to consider it to indicate the first octet - * of data past the urgent section as the original - * spec states (in one of two places). - */ - if (SEQ_GT(ti->ti_seq + ti->ti_urp, tp->rcv_up)) { - tp->rcv_up = ti->ti_seq + ti->ti_urp; - so->so_urgc = - so->so_rcv.sb_cc + (tp->rcv_up - tp->rcv_nxt); /* -1; */ - tp->rcv_up = ti->ti_seq + ti->ti_urp; - } - } else - /* - * If no out of band data is expected, - * pull receive urgent pointer along - * with the receive window. - */ - if (SEQ_GT(tp->rcv_nxt, tp->rcv_up)) - tp->rcv_up = tp->rcv_nxt; -dodata: - - /* - * If this is a small packet, then ACK now - with Nagel - * congestion avoidance sender won't send more until - * he gets an ACK. - */ - if (ti->ti_len && (unsigned)ti->ti_len <= 5 && - ((struct tcpiphdr_2 *)ti)->first_char == (char)27) { - tp->t_flags |= TF_ACKNOW; - } - - /* - * Process the segment text, merging it into the TCP sequencing queue, - * and arranging for acknowledgment of receipt if necessary. - * This process logically involves adjusting tp->rcv_wnd as data - * is presented to the user (this happens in tcp_usrreq.c, - * case PRU_RCVD). If a FIN has already been received on this - * connection then we just ignore the text. - */ - if ((ti->ti_len || (tiflags & TH_FIN)) && - TCPS_HAVERCVDFIN(tp->t_state) == 0) { - TCP_REASS(tp, ti, m, so, tiflags); - } else { - m_free(m); - tiflags &= ~TH_FIN; - } - - /* - * If FIN is received ACK the FIN and let the user know - * that the connection is closing. - */ - if (tiflags & TH_FIN) { - if (TCPS_HAVERCVDFIN(tp->t_state) == 0) { - /* - * If we receive a FIN we can't send more data, - * set it SS_FDRAIN - * Shutdown the socket if there is no rx data in the - * buffer. - * soread() is called on completion of shutdown() and - * will got to TCPS_LAST_ACK, and use tcp_output() - * to send the FIN. - */ - sofwdrain(so); - - tp->t_flags |= TF_ACKNOW; - tp->rcv_nxt++; - } - switch (tp->t_state) { - /* - * In SYN_RECEIVED and ESTABLISHED STATES - * enter the CLOSE_WAIT state. - */ - case TCPS_SYN_RECEIVED: - case TCPS_ESTABLISHED: - if (so->so_emu == EMU_CTL) /* no shutdown on socket */ - tp->t_state = TCPS_LAST_ACK; - else - tp->t_state = TCPS_CLOSE_WAIT; - break; - - /* - * If still in FIN_WAIT_1 STATE FIN has not been acked so - * enter the CLOSING state. - */ - case TCPS_FIN_WAIT_1: - tp->t_state = TCPS_CLOSING; - break; - - /* - * In FIN_WAIT_2 state enter the TIME_WAIT state, - * starting the time-wait timer, turning off the other - * standard timers. - */ - case TCPS_FIN_WAIT_2: - tp->t_state = TCPS_TIME_WAIT; - tcp_canceltimers(tp); - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - break; - - /* - * In TIME_WAIT state restart the 2 MSL time_wait timer. - */ - case TCPS_TIME_WAIT: - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - break; - } - } - - /* - * Return any desired output. - */ - if (needoutput || (tp->t_flags & TF_ACKNOW)) { - tcp_output(tp); - } - return; - -dropafterack: - /* - * Generate an ACK dropping incoming segment if it occupies - * sequence space, where the ACK reflects our state. - */ - if (tiflags & TH_RST) - goto drop; - m_free(m); - tp->t_flags |= TF_ACKNOW; - tcp_output(tp); - return; - -dropwithreset: - /* reuses m if m!=NULL, m_free() unnecessary */ - if (tiflags & TH_ACK) - tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST, af); - else { - if (tiflags & TH_SYN) - ti->ti_len++; - tcp_respond(tp, ti, m, ti->ti_seq + ti->ti_len, (tcp_seq)0, - TH_RST | TH_ACK, af); - } - - return; - -drop: - /* - * Drop space held by incoming segment and return. - */ - m_free(m); -} - -static void tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt, - struct tcpiphdr *ti) -{ - uint16_t mss; - int opt, optlen; - - DEBUG_CALL("tcp_dooptions"); - DEBUG_ARG("tp = %p cnt=%i", tp, cnt); - - for (; cnt > 0; cnt -= optlen, cp += optlen) { - opt = cp[0]; - if (opt == TCPOPT_EOL) - break; - if (opt == TCPOPT_NOP) - optlen = 1; - else { - optlen = cp[1]; - if (optlen <= 0) - break; - } - switch (opt) { - default: - continue; - - case TCPOPT_MAXSEG: - if (optlen != TCPOLEN_MAXSEG) - continue; - if (!(ti->ti_flags & TH_SYN)) - continue; - memcpy((char *)&mss, (char *)cp + 2, sizeof(mss)); - NTOHS(mss); - tcp_mss(tp, mss); /* sets t_maxseg */ - break; - } - } -} - -/* - * Collect new round-trip time estimate - * and update averages and current timeout. - */ - -static void tcp_xmit_timer(register struct tcpcb *tp, int rtt) -{ - register short delta; - - DEBUG_CALL("tcp_xmit_timer"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("rtt = %d", rtt); - - if (tp->t_srtt != 0) { - /* - * srtt is stored as fixed point with 3 bits after the - * binary point (i.e., scaled by 8). The following magic - * is equivalent to the smoothing algorithm in rfc793 with - * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed - * point). Adjust rtt to origin 0. - */ - delta = rtt - 1 - (tp->t_srtt >> TCP_RTT_SHIFT); - if ((tp->t_srtt += delta) <= 0) - tp->t_srtt = 1; - /* - * We accumulate a smoothed rtt variance (actually, a - * smoothed mean difference), then set the retransmit - * timer to smoothed rtt + 4 times the smoothed variance. - * rttvar is stored as fixed point with 2 bits after the - * binary point (scaled by 4). The following is - * equivalent to rfc793 smoothing with an alpha of .75 - * (rttvar = rttvar*3/4 + |delta| / 4). This replaces - * rfc793's wired-in beta. - */ - if (delta < 0) - delta = -delta; - delta -= (tp->t_rttvar >> TCP_RTTVAR_SHIFT); - if ((tp->t_rttvar += delta) <= 0) - tp->t_rttvar = 1; - } else { - /* - * No rtt measurement yet - use the unsmoothed rtt. - * Set the variance to half the rtt (so our first - * retransmit happens at 3*rtt). - */ - tp->t_srtt = rtt << TCP_RTT_SHIFT; - tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1); - } - tp->t_rtt = 0; - tp->t_rxtshift = 0; - - /* - * the retransmit should happen at rtt + 4 * rttvar. - * Because of the way we do the smoothing, srtt and rttvar - * will each average +1/2 tick of bias. When we compute - * the retransmit timer, we want 1/2 tick of rounding and - * 1 extra tick because of +-1/2 tick uncertainty in the - * firing of the timer. The bias will give us exactly the - * 1.5 tick we need. But, because the bias is - * statistical, we have to test that we don't drop below - * the minimum feasible timer (which is 2 ticks). - */ - TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp), (short)tp->t_rttmin, - TCPTV_REXMTMAX); /* XXX */ - - /* - * We received an ack for a packet that wasn't retransmitted; - * it is probably safe to discard any error indications we've - * received recently. This isn't quite right, but close enough - * for now (a route might have failed after we sent a segment, - * and the return path might not be symmetrical). - */ - tp->t_softerror = 0; -} - -/* - * Determine a reasonable value for maxseg size. - * If the route is known, check route for mtu. - * If none, use an mss that can be handled on the outgoing - * interface without forcing IP to fragment; if bigger than - * an mbuf cluster (MCLBYTES), round down to nearest multiple of MCLBYTES - * to utilize large mbufs. If no route is found, route has no mtu, - * or the destination isn't local, use a default, hopefully conservative - * size (usually 512 or the default IP max size, but no more than the mtu - * of the interface), as we can't discover anything about intervening - * gateways or networks. We also initialize the congestion/slow start - * window to be a single segment if the destination isn't local. - * While looking at the routing entry, we also initialize other path-dependent - * parameters from pre-set or cached values in the routing entry. - */ - -int tcp_mss(struct tcpcb *tp, unsigned offer) -{ - struct socket *so = tp->t_socket; - int mss; - - DEBUG_CALL("tcp_mss"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("offer = %d", offer); - - switch (so->so_ffamily) { - case AF_INET: - mss = MIN(so->slirp->if_mtu, so->slirp->if_mru) - - sizeof(struct tcphdr) - sizeof(struct ip); - break; - case AF_INET6: - mss = MIN(so->slirp->if_mtu, so->slirp->if_mru) - - sizeof(struct tcphdr) - sizeof(struct ip6); - break; - default: - g_assert_not_reached(); - } - - if (offer) - mss = MIN(mss, offer); - mss = MAX(mss, 32); - if (mss < tp->t_maxseg || offer != 0) - tp->t_maxseg = MIN(mss, TCP_MAXSEG_MAX); - - tp->snd_cwnd = mss; - - sbreserve(&so->so_snd, - TCP_SNDSPACE + - ((TCP_SNDSPACE % mss) ? (mss - (TCP_SNDSPACE % mss)) : 0)); - sbreserve(&so->so_rcv, - TCP_RCVSPACE + - ((TCP_RCVSPACE % mss) ? (mss - (TCP_RCVSPACE % mss)) : 0)); - - DEBUG_MISC(" returning mss = %d", mss); - - return mss; -} diff --git a/src/network/slirp/tcp_output.c b/src/network/slirp/tcp_output.c deleted file mode 100644 index 383fe31dc..000000000 --- a/src/network/slirp/tcp_output.c +++ /dev/null @@ -1,516 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_output.c 8.3 (Berkeley) 12/30/93 - * tcp_output.c,v 1.3 1994/09/15 10:36:55 davidg Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -static const uint8_t tcp_outflags[TCP_NSTATES] = { - TH_RST | TH_ACK, 0, TH_SYN, TH_SYN | TH_ACK, - TH_ACK, TH_ACK, TH_FIN | TH_ACK, TH_FIN | TH_ACK, - TH_FIN | TH_ACK, TH_ACK, TH_ACK, -}; - - -#undef MAX_TCPOPTLEN -#define MAX_TCPOPTLEN 32 /* max # bytes that go in options */ - -/* - * Tcp output routine: figure out what should be sent and send it. - */ -int tcp_output(struct tcpcb *tp) -{ - register struct socket *so = tp->t_socket; - register long len, win; - int off, flags, error; - register struct mbuf *m; - register struct tcpiphdr *ti, tcpiph_save; - struct ip *ip; - struct ip6 *ip6; - uint8_t opt[MAX_TCPOPTLEN]; - unsigned optlen, hdrlen; - int idle, sendalot; - - DEBUG_CALL("tcp_output"); - DEBUG_ARG("tp = %p", tp); - - /* - * Determine length of data that should be transmitted, - * and flags that will be used. - * If there is some data or critical controls (SYN, RST) - * to send, then transmit; otherwise, investigate further. - */ - idle = (tp->snd_max == tp->snd_una); - if (idle && tp->t_idle >= tp->t_rxtcur) - /* - * We have been idle for "a while" and no acks are - * expected to clock out any data we send -- - * slow start to get ack "clock" running again. - */ - tp->snd_cwnd = tp->t_maxseg; -again: - sendalot = 0; - off = tp->snd_nxt - tp->snd_una; - win = MIN(tp->snd_wnd, tp->snd_cwnd); - - flags = tcp_outflags[tp->t_state]; - - DEBUG_MISC(" --- tcp_output flags = 0x%x", flags); - - /* - * If in persist timeout with window of 0, send 1 byte. - * Otherwise, if window is small but nonzero - * and timer expired, we will send what we can - * and go to transmit state. - */ - if (tp->t_force) { - if (win == 0) { - /* - * If we still have some data to send, then - * clear the FIN bit. Usually this would - * happen below when it realizes that we - * aren't sending all the data. However, - * if we have exactly 1 byte of unset data, - * then it won't clear the FIN bit below, - * and if we are in persist state, we wind - * up sending the packet without recording - * that we sent the FIN bit. - * - * We can't just blindly clear the FIN bit, - * because if we don't have any more data - * to send then the probe will be the FIN - * itself. - */ - if (off < so->so_snd.sb_cc) - flags &= ~TH_FIN; - win = 1; - } else { - tp->t_timer[TCPT_PERSIST] = 0; - tp->t_rxtshift = 0; - } - } - - len = MIN(so->so_snd.sb_cc, win) - off; - - if (len < 0) { - /* - * If FIN has been sent but not acked, - * but we haven't been called to retransmit, - * len will be -1. Otherwise, window shrank - * after we sent into it. If window shrank to 0, - * cancel pending retransmit and pull snd_nxt - * back to (closed) window. We will enter persist - * state below. If the window didn't close completely, - * just wait for an ACK. - */ - len = 0; - if (win == 0) { - tp->t_timer[TCPT_REXMT] = 0; - tp->snd_nxt = tp->snd_una; - } - } - - if (len > tp->t_maxseg) { - len = tp->t_maxseg; - sendalot = 1; - } - if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc)) - flags &= ~TH_FIN; - - win = sbspace(&so->so_rcv); - - /* - * Sender silly window avoidance. If connection is idle - * and can send all data, a maximum segment, - * at least a maximum default-size segment do it, - * or are forced, do it; otherwise don't bother. - * If peer's buffer is tiny, then send - * when window is at least half open. - * If retransmitting (possibly after persist timer forced us - * to send into a small window), then must resend. - */ - if (len) { - if (len == tp->t_maxseg) - goto send; - if ((1 || idle || tp->t_flags & TF_NODELAY) && - len + off >= so->so_snd.sb_cc) - goto send; - if (tp->t_force) - goto send; - if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0) - goto send; - if (SEQ_LT(tp->snd_nxt, tp->snd_max)) - goto send; - } - - /* - * Compare available window to amount of window - * known to peer (as advertised window less - * next expected input). If the difference is at least two - * max size segments, or at least 50% of the maximum possible - * window, then want to send a window update to peer. - */ - if (win > 0) { - /* - * "adv" is the amount we can increase the window, - * taking into account that we are limited by - * TCP_MAXWIN << tp->rcv_scale. - */ - long adv = MIN(win, (long)TCP_MAXWIN << tp->rcv_scale) - - (tp->rcv_adv - tp->rcv_nxt); - - if (adv >= (long)(2 * tp->t_maxseg)) - goto send; - if (2 * adv >= (long)so->so_rcv.sb_datalen) - goto send; - } - - /* - * Send if we owe peer an ACK. - */ - if (tp->t_flags & TF_ACKNOW) - goto send; - if (flags & (TH_SYN | TH_RST)) - goto send; - if (SEQ_GT(tp->snd_up, tp->snd_una)) - goto send; - /* - * If our state indicates that FIN should be sent - * and we have not yet done so, or we're retransmitting the FIN, - * then we need to send. - */ - if (flags & TH_FIN && - ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una)) - goto send; - - /* - * TCP window updates are not reliable, rather a polling protocol - * using ``persist'' packets is used to insure receipt of window - * updates. The three ``states'' for the output side are: - * idle not doing retransmits or persists - * persisting to move a small or zero window - * (re)transmitting and thereby not persisting - * - * tp->t_timer[TCPT_PERSIST] - * is set when we are in persist state. - * tp->t_force - * is set when we are called to send a persist packet. - * tp->t_timer[TCPT_REXMT] - * is set when we are retransmitting - * The output side is idle when both timers are zero. - * - * If send window is too small, there is data to transmit, and no - * retransmit or persist is pending, then go to persist state. - * If nothing happens soon, send when timer expires: - * if window is nonzero, transmit what we can, - * otherwise force out a byte. - */ - if (so->so_snd.sb_cc && tp->t_timer[TCPT_REXMT] == 0 && - tp->t_timer[TCPT_PERSIST] == 0) { - tp->t_rxtshift = 0; - tcp_setpersist(tp); - } - - /* - * No reason to send a segment, just return. - */ - return (0); - -send: - /* - * Before ESTABLISHED, force sending of initial options - * unless TCP set not to do any options. - * NOTE: we assume that the IP/TCP header plus TCP options - * always fit in a single mbuf, leaving room for a maximum - * link header, i.e. - * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MHLEN - */ - optlen = 0; - hdrlen = sizeof(struct tcpiphdr); - if (flags & TH_SYN) { - tp->snd_nxt = tp->iss; - if ((tp->t_flags & TF_NOOPT) == 0) { - uint16_t mss; - - opt[0] = TCPOPT_MAXSEG; - opt[1] = 4; - mss = htons((uint16_t)tcp_mss(tp, 0)); - memcpy((char *)(opt + 2), (char *)&mss, sizeof(mss)); - optlen = 4; - } - } - - hdrlen += optlen; - - /* - * Adjust data length if insertion of options will - * bump the packet length beyond the t_maxseg length. - */ - if (len > tp->t_maxseg - optlen) { - len = tp->t_maxseg - optlen; - sendalot = 1; - } - - /* - * Grab a header mbuf, attaching a copy of data to - * be transmitted, and initialize the header from - * the template for sends on this connection. - */ - if (len) { - m = m_get(so->slirp); - if (m == NULL) { - error = 1; - goto out; - } - m->m_data += IF_MAXLINKHDR; - m->m_len = hdrlen; - - sbcopy(&so->so_snd, off, (int)len, mtod(m, char *) + hdrlen); - m->m_len += len; - - /* - * If we're sending everything we've got, set PUSH. - * (This will keep happy those implementations which only - * give data to the user when a buffer fills or - * a PUSH comes in.) - */ - if (off + len == so->so_snd.sb_cc) - flags |= TH_PUSH; - } else { - m = m_get(so->slirp); - if (m == NULL) { - error = 1; - goto out; - } - m->m_data += IF_MAXLINKHDR; - m->m_len = hdrlen; - } - - ti = mtod(m, struct tcpiphdr *); - - memcpy((char *)ti, &tp->t_template, sizeof(struct tcpiphdr)); - - /* - * Fill in fields, remembering maximum advertised - * window for use in delaying messages about window sizes. - * If resending a FIN, be sure not to use a new sequence number. - */ - if (flags & TH_FIN && tp->t_flags & TF_SENTFIN && - tp->snd_nxt == tp->snd_max) - tp->snd_nxt--; - /* - * If we are doing retransmissions, then snd_nxt will - * not reflect the first unsent octet. For ACK only - * packets, we do not want the sequence number of the - * retransmitted packet, we want the sequence number - * of the next unsent octet. So, if there is no data - * (and no SYN or FIN), use snd_max instead of snd_nxt - * when filling in ti_seq. But if we are in persist - * state, snd_max might reflect one byte beyond the - * right edge of the window, so use snd_nxt in that - * case, since we know we aren't doing a retransmission. - * (retransmit and persist are mutually exclusive...) - */ - if (len || (flags & (TH_SYN | TH_FIN)) || tp->t_timer[TCPT_PERSIST]) - ti->ti_seq = htonl(tp->snd_nxt); - else - ti->ti_seq = htonl(tp->snd_max); - ti->ti_ack = htonl(tp->rcv_nxt); - if (optlen) { - memcpy((char *)(ti + 1), (char *)opt, optlen); - ti->ti_off = (sizeof(struct tcphdr) + optlen) >> 2; - } - ti->ti_flags = flags; - /* - * Calculate receive window. Don't shrink window, - * but avoid silly window syndrome. - */ - if (win < (long)(so->so_rcv.sb_datalen / 4) && win < (long)tp->t_maxseg) - win = 0; - if (win > (long)TCP_MAXWIN << tp->rcv_scale) - win = (long)TCP_MAXWIN << tp->rcv_scale; - if (win < (long)(tp->rcv_adv - tp->rcv_nxt)) - win = (long)(tp->rcv_adv - tp->rcv_nxt); - ti->ti_win = htons((uint16_t)(win >> tp->rcv_scale)); - - if (SEQ_GT(tp->snd_up, tp->snd_una)) { - ti->ti_urp = htons((uint16_t)(tp->snd_up - ntohl(ti->ti_seq))); - ti->ti_flags |= TH_URG; - } else - /* - * If no urgent pointer to send, then we pull - * the urgent pointer to the left edge of the send window - * so that it doesn't drift into the send window on sequence - * number wraparound. - */ - tp->snd_up = tp->snd_una; /* drag it along */ - - /* - * Put TCP length in extended header, and then - * checksum extended header and data. - */ - if (len + optlen) - ti->ti_len = htons((uint16_t)(sizeof(struct tcphdr) + optlen + len)); - ti->ti_sum = cksum(m, (int)(hdrlen + len)); - - /* - * In transmit state, time the transmission and arrange for - * the retransmit. In persist state, just set snd_max. - */ - if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) { - tcp_seq startseq = tp->snd_nxt; - - /* - * Advance snd_nxt over sequence space of this segment. - */ - if (flags & (TH_SYN | TH_FIN)) { - if (flags & TH_SYN) - tp->snd_nxt++; - if (flags & TH_FIN) { - tp->snd_nxt++; - tp->t_flags |= TF_SENTFIN; - } - } - tp->snd_nxt += len; - if (SEQ_GT(tp->snd_nxt, tp->snd_max)) { - tp->snd_max = tp->snd_nxt; - /* - * Time this transmission if not a retransmission and - * not currently timing anything. - */ - if (tp->t_rtt == 0) { - tp->t_rtt = 1; - tp->t_rtseq = startseq; - } - } - - /* - * Set retransmit timer if not currently set, - * and not doing an ack or a keep-alive probe. - * Initial value for retransmit timer is smoothed - * round-trip time + 2 * round-trip time variance. - * Initialize shift counter which is used for backoff - * of retransmit time. - */ - if (tp->t_timer[TCPT_REXMT] == 0 && tp->snd_nxt != tp->snd_una) { - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - if (tp->t_timer[TCPT_PERSIST]) { - tp->t_timer[TCPT_PERSIST] = 0; - tp->t_rxtshift = 0; - } - } - } else if (SEQ_GT(tp->snd_nxt + len, tp->snd_max)) - tp->snd_max = tp->snd_nxt + len; - - /* - * Fill in IP length and desired time to live and - * send to IP level. There should be a better way - * to handle ttl and tos; we could keep them in - * the template, but need a way to checksum without them. - */ - m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */ - tcpiph_save = *mtod(m, struct tcpiphdr *); - - switch (so->so_ffamily) { - case AF_INET: - m->m_data += - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - m->m_len -= - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - ip = mtod(m, struct ip *); - - ip->ip_len = m->m_len; - ip->ip_dst = tcpiph_save.ti_dst; - ip->ip_src = tcpiph_save.ti_src; - ip->ip_p = tcpiph_save.ti_pr; - - ip->ip_ttl = IPDEFTTL; - ip->ip_tos = so->so_iptos; - error = ip_output(so, m); - break; - - case AF_INET6: - m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - ip6 = mtod(m, struct ip6 *); - - ip6->ip_pl = tcpiph_save.ti_len; - ip6->ip_dst = tcpiph_save.ti_dst6; - ip6->ip_src = tcpiph_save.ti_src6; - ip6->ip_nh = tcpiph_save.ti_nh6; - - error = ip6_output(so, m, 0); - break; - - default: - g_assert_not_reached(); - } - - if (error) { - out: - return (error); - } - - /* - * Data sent (as far as we can tell). - * If this advertises a larger window than any other segment, - * then remember the size of the advertised window. - * Any pending ACK has now been sent. - */ - if (win > 0 && SEQ_GT(tp->rcv_nxt + win, tp->rcv_adv)) - tp->rcv_adv = tp->rcv_nxt + win; - tp->last_ack_sent = tp->rcv_nxt; - tp->t_flags &= ~(TF_ACKNOW | TF_DELACK); - if (sendalot) - goto again; - - return (0); -} - -void tcp_setpersist(struct tcpcb *tp) -{ - int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1; - - /* - * Start/restart persistence timer. - */ - TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], t * tcp_backoff[tp->t_rxtshift], - TCPTV_PERSMIN, TCPTV_PERSMAX); - if (tp->t_rxtshift < TCP_MAXRXTSHIFT) - tp->t_rxtshift++; -} diff --git a/src/network/slirp/tcp_subr.c b/src/network/slirp/tcp_subr.c deleted file mode 100644 index 112448483..000000000 --- a/src/network/slirp/tcp_subr.c +++ /dev/null @@ -1,1023 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_subr.c 8.1 (Berkeley) 6/10/93 - * tcp_subr.c,v 1.5 1994/10/08 22:39:58 phk Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -/* patchable/settable parameters for tcp */ -/* Don't do rfc1323 performance enhancements */ -#define TCP_DO_RFC1323 0 - -/* - * Tcp initialization - */ -void tcp_init(Slirp *slirp) -{ - slirp->tcp_iss = 1; /* wrong */ - slirp->tcb.so_next = slirp->tcb.so_prev = &slirp->tcb; - slirp->tcp_last_so = &slirp->tcb; -} - -void tcp_cleanup(Slirp *slirp) -{ - while (slirp->tcb.so_next != &slirp->tcb) { - tcp_close(sototcpcb(slirp->tcb.so_next)); - } -} - -/* - * Create template to be used to send tcp packets on a connection. - * Call after host entry created, fills - * in a skeletal tcp/ip header, minimizing the amount of work - * necessary when the connection is used. - */ -void tcp_template(struct tcpcb *tp) -{ - struct socket *so = tp->t_socket; - register struct tcpiphdr *n = &tp->t_template; - - n->ti_mbuf = NULL; - memset(&n->ti, 0, sizeof(n->ti)); - n->ti_x0 = 0; - switch (so->so_ffamily) { - case AF_INET: - n->ti_pr = IPPROTO_TCP; - n->ti_len = htons(sizeof(struct tcphdr)); - n->ti_src = so->so_faddr; - n->ti_dst = so->so_laddr; - n->ti_sport = so->so_fport; - n->ti_dport = so->so_lport; - break; - - case AF_INET6: - n->ti_nh6 = IPPROTO_TCP; - n->ti_len = htons(sizeof(struct tcphdr)); - n->ti_src6 = so->so_faddr6; - n->ti_dst6 = so->so_laddr6; - n->ti_sport = so->so_fport6; - n->ti_dport = so->so_lport6; - break; - - default: - g_assert_not_reached(); - } - - n->ti_seq = 0; - n->ti_ack = 0; - n->ti_x2 = 0; - n->ti_off = 5; - n->ti_flags = 0; - n->ti_win = 0; - n->ti_sum = 0; - n->ti_urp = 0; -} - -/* - * Send a single message to the TCP at address specified by - * the given TCP/IP header. If m == 0, then we make a copy - * of the tcpiphdr at ti and send directly to the addressed host. - * This is used to force keep alive messages out using the TCP - * template for a connection tp->t_template. If flags are given - * then we send a message back to the TCP which originated the - * segment ti, and discard the mbuf containing it and any other - * attached mbufs. - * - * In any case the ack and sequence number of the transmitted - * segment are as specified by the parameters. - */ -void tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, - tcp_seq ack, tcp_seq seq, int flags, unsigned short af) -{ - register int tlen; - int win = 0; - - DEBUG_CALL("tcp_respond"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("ti = %p", ti); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("ack = %u", ack); - DEBUG_ARG("seq = %u", seq); - DEBUG_ARG("flags = %x", flags); - - if (tp) - win = sbspace(&tp->t_socket->so_rcv); - if (m == NULL) { - if (!tp || (m = m_get(tp->t_socket->slirp)) == NULL) - return; - tlen = 0; - m->m_data += IF_MAXLINKHDR; - *mtod(m, struct tcpiphdr *) = *ti; - ti = mtod(m, struct tcpiphdr *); - switch (af) { - case AF_INET: - ti->ti.ti_i4.ih_x1 = 0; - break; - case AF_INET6: - ti->ti.ti_i6.ih_x1 = 0; - break; - default: - g_assert_not_reached(); - } - flags = TH_ACK; - } else { - /* - * ti points into m so the next line is just making - * the mbuf point to ti - */ - m->m_data = (char *)ti; - - m->m_len = sizeof(struct tcpiphdr); - tlen = 0; -#define xchg(a, b, type) \ - { \ - type t; \ - t = a; \ - a = b; \ - b = t; \ - } - switch (af) { - case AF_INET: - xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, uint32_t); - xchg(ti->ti_dport, ti->ti_sport, uint16_t); - break; - case AF_INET6: - xchg(ti->ti_dst6, ti->ti_src6, struct in6_addr); - xchg(ti->ti_dport, ti->ti_sport, uint16_t); - break; - default: - g_assert_not_reached(); - } -#undef xchg - } - ti->ti_len = htons((uint16_t)(sizeof(struct tcphdr) + tlen)); - tlen += sizeof(struct tcpiphdr); - m->m_len = tlen; - - ti->ti_mbuf = NULL; - ti->ti_x0 = 0; - ti->ti_seq = htonl(seq); - ti->ti_ack = htonl(ack); - ti->ti_x2 = 0; - ti->ti_off = sizeof(struct tcphdr) >> 2; - ti->ti_flags = flags; - if (tp) - ti->ti_win = htons((uint16_t)(win >> tp->rcv_scale)); - else - ti->ti_win = htons((uint16_t)win); - ti->ti_urp = 0; - ti->ti_sum = 0; - ti->ti_sum = cksum(m, tlen); - - struct tcpiphdr tcpiph_save = *(mtod(m, struct tcpiphdr *)); - struct ip *ip; - struct ip6 *ip6; - - switch (af) { - case AF_INET: - m->m_data += - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - m->m_len -= - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - ip = mtod(m, struct ip *); - ip->ip_len = m->m_len; - ip->ip_dst = tcpiph_save.ti_dst; - ip->ip_src = tcpiph_save.ti_src; - ip->ip_p = tcpiph_save.ti_pr; - - if (flags & TH_RST) { - ip->ip_ttl = MAXTTL; - } else { - ip->ip_ttl = IPDEFTTL; - } - - ip_output(NULL, m); - break; - - case AF_INET6: - m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - ip6 = mtod(m, struct ip6 *); - ip6->ip_pl = tcpiph_save.ti_len; - ip6->ip_dst = tcpiph_save.ti_dst6; - ip6->ip_src = tcpiph_save.ti_src6; - ip6->ip_nh = tcpiph_save.ti_nh6; - - ip6_output(NULL, m, 0); - break; - - default: - g_assert_not_reached(); - } -} - -/* - * Create a new TCP control block, making an - * empty reassembly queue and hooking it to the argument - * protocol control block. - */ -struct tcpcb *tcp_newtcpcb(struct socket *so) -{ - register struct tcpcb *tp; - - tp = g_new0(struct tcpcb, 1); - tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp; - /* - * 40: length of IPv4 header (20) + TCP header (20) - * 60: length of IPv6 header (40) + TCP header (20) - */ - tp->t_maxseg = - MIN(so->slirp->if_mtu - ((so->so_ffamily == AF_INET) ? 40 : 60), - TCP_MAXSEG_MAX); - - tp->t_flags = TCP_DO_RFC1323 ? (TF_REQ_SCALE | TF_REQ_TSTMP) : 0; - tp->t_socket = so; - - /* - * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no - * rtt estimate. Set rttvar so that srtt + 2 * rttvar gives - * reasonable initial retransmit time. - */ - tp->t_srtt = TCPTV_SRTTBASE; - tp->t_rttvar = TCPTV_SRTTDFLT << 2; - tp->t_rttmin = TCPTV_MIN; - - TCPT_RANGESET(tp->t_rxtcur, - ((TCPTV_SRTTBASE >> 2) + (TCPTV_SRTTDFLT << 2)) >> 1, - TCPTV_MIN, TCPTV_REXMTMAX); - - tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT; - tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; - tp->t_state = TCPS_CLOSED; - - so->so_tcpcb = tp; - - return (tp); -} - -/* - * Drop a TCP connection, reporting - * the specified error. If connection is synchronized, - * then send a RST to peer. - */ -struct tcpcb *tcp_drop(struct tcpcb *tp, int err) -{ - DEBUG_CALL("tcp_drop"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("errno = %d", errno); - - if (TCPS_HAVERCVDSYN(tp->t_state)) { - tp->t_state = TCPS_CLOSED; - tcp_output(tp); - } - return (tcp_close(tp)); -} - -/* - * Close a TCP control block: - * discard all space held by the tcp - * discard internet protocol block - * wake up any sleepers - */ -struct tcpcb *tcp_close(struct tcpcb *tp) -{ - register struct tcpiphdr *t; - struct socket *so = tp->t_socket; - Slirp *slirp = so->slirp; - register struct mbuf *m; - - DEBUG_CALL("tcp_close"); - DEBUG_ARG("tp = %p", tp); - - /* free the reassembly queue, if any */ - t = tcpfrag_list_first(tp); - while (!tcpfrag_list_end(t, tp)) { - t = tcpiphdr_next(t); - m = tcpiphdr_prev(t)->ti_mbuf; - slirp_remque(tcpiphdr2qlink(tcpiphdr_prev(t))); - m_free(m); - } - g_free(tp); - so->so_tcpcb = NULL; - /* clobber input socket cache if we're closing the cached connection */ - if (so == slirp->tcp_last_so) - slirp->tcp_last_so = &slirp->tcb; - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sbfree(&so->so_rcv); - sbfree(&so->so_snd); - sofree(so); - return ((struct tcpcb *)0); -} - -/* - * TCP protocol interface to socket abstraction. - */ - -/* - * User issued close, and wish to trail through shutdown states: - * if never received SYN, just forget it. If got a SYN from peer, - * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN. - * If already got a FIN from peer, then almost done; go to LAST_ACK - * state. In all other cases, have already sent FIN to peer (e.g. - * after PRU_SHUTDOWN), and just have to play tedious game waiting - * for peer to send FIN or not respond to keep-alives, etc. - * We can let the user exit from the close as soon as the FIN is acked. - */ -void tcp_sockclosed(struct tcpcb *tp) -{ - DEBUG_CALL("tcp_sockclosed"); - DEBUG_ARG("tp = %p", tp); - - if (!tp) { - return; - } - - switch (tp->t_state) { - case TCPS_CLOSED: - case TCPS_LISTEN: - case TCPS_SYN_SENT: - tp->t_state = TCPS_CLOSED; - tcp_close(tp); - return; - - case TCPS_SYN_RECEIVED: - case TCPS_ESTABLISHED: - tp->t_state = TCPS_FIN_WAIT_1; - break; - - case TCPS_CLOSE_WAIT: - tp->t_state = TCPS_LAST_ACK; - break; - } - tcp_output(tp); -} - -/* - * Connect to a host on the Internet - * Called by tcp_input - * Only do a connect, the tcp fields will be set in tcp_input - * return 0 if there's a result of the connect, - * else return -1 means we're still connecting - * The return value is almost always -1 since the socket is - * nonblocking. Connect returns after the SYN is sent, and does - * not wait for ACK+SYN. - */ -int tcp_fconnect(struct socket *so, unsigned short af) -{ - int ret = 0; - - DEBUG_CALL("tcp_fconnect"); - DEBUG_ARG("so = %p", so); - - ret = so->s = slirp_socket(af, SOCK_STREAM, 0); - if (ret >= 0) { - ret = slirp_bind_outbound(so, af); - if (ret < 0) { - // bind failed - close socket - closesocket(so->s); - so->s = -1; - return (ret); - } - } - - if (ret >= 0) { - int opt, s = so->s; - struct sockaddr_storage addr; - - slirp_set_nonblock(s); - so->slirp->cb->register_poll_fd(s, so->slirp->opaque); - slirp_socket_set_fast_reuse(s); - opt = 1; - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); - opt = 1; - setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); - - addr = so->fhost.ss; - DEBUG_CALL(" connect()ing"); - if (sotranslate_out(so, &addr) < 0) { - return -1; - } - - /* We don't care what port we get */ - ret = connect(s, (struct sockaddr *)&addr, sockaddr_size(&addr)); - - /* - * If it's not in progress, it failed, so we just return 0, - * without clearing SS_NOFDREF - */ - soisfconnecting(so); - } - - return (ret); -} - -/* - * Accept the socket and connect to the local-host - * - * We have a problem. The correct thing to do would be - * to first connect to the local-host, and only if the - * connection is accepted, then do an accept() here. - * But, a) we need to know who's trying to connect - * to the socket to be able to SYN the local-host, and - * b) we are already connected to the foreign host by - * the time it gets to accept(), so... We simply accept - * here and SYN the local-host. - */ -void tcp_connect(struct socket *inso) -{ - Slirp *slirp = inso->slirp; - struct socket *so; - struct sockaddr_storage addr; - socklen_t addrlen; - struct tcpcb *tp; - int s, opt, ret; - /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ - char addrstr[INET6_ADDRSTRLEN]; - char portstr[6]; - - DEBUG_CALL("tcp_connect"); - DEBUG_ARG("inso = %p", inso); - switch (inso->lhost.ss.ss_family) { - case AF_INET: - addrlen = sizeof(struct sockaddr_in); - break; - case AF_INET6: - addrlen = sizeof(struct sockaddr_in6); - break; - default: - g_assert_not_reached(); - } - ret = getnameinfo((const struct sockaddr *) &inso->lhost.ss, addrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("ip = [%s]:%s", addrstr, portstr); - DEBUG_ARG("so_state = 0x%x", inso->so_state); - - /* Perform lazy guest IP address resolution if needed. */ - if (inso->so_state & SS_HOSTFWD) { - /* - * We can only reject the connection request by accepting it and - * then immediately closing it. Note that SS_FACCEPTONCE sockets can't - * get here. - */ - if (soassign_guest_addr_if_needed(inso) < 0) { - /* - * Guest address isn't available yet. We could either try to defer - * completing this connection request until the guest address is - * available, or punt. It's easier to punt. Otherwise we need to - * complicate the mechanism by which we're called to defer calling - * us again until the guest address is available. - */ - DEBUG_MISC(" guest address not available yet"); - addrlen = sizeof(addr); - s = accept(inso->s, (struct sockaddr *)&addr, &addrlen); - if (s >= 0) { - closesocket(s); - } - return; - } - } - - /* - * If it's an SS_ACCEPTONCE socket, no need to socreate() - * another socket, just use the accept() socket. - */ - if (inso->so_state & SS_FACCEPTONCE) { - /* FACCEPTONCE already have a tcpcb */ - so = inso; - } else { - so = socreate(slirp, IPPROTO_TCP); - tcp_attach(so); - so->lhost = inso->lhost; - so->so_ffamily = inso->so_ffamily; - } - - tcp_mss(sototcpcb(so), 0); - - addrlen = sizeof(addr); - s = accept(inso->s, (struct sockaddr *)&addr, &addrlen); - if (s < 0) { - tcp_close(sototcpcb(so)); /* This will sofree() as well */ - return; - } - slirp_set_nonblock(s); - so->slirp->cb->register_poll_fd(s, so->slirp->opaque); - slirp_socket_set_fast_reuse(s); - opt = 1; - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - slirp_socket_set_nodelay(s); - - so->fhost.ss = addr; - sotranslate_accept(so); - - /* Close the accept() socket, set right state */ - if (inso->so_state & SS_FACCEPTONCE) { - /* If we only accept once, close the accept() socket */ - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - - /* Don't select it yet, even though we have an FD */ - /* if it's not FACCEPTONCE, it's already NOFDREF */ - so->so_state = SS_NOFDREF; - } - so->s = s; - so->so_state |= SS_INCOMING; - - so->so_iptos = tcp_tos(so); - tp = sototcpcb(so); - - tcp_template(tp); - - tp->t_state = TCPS_SYN_SENT; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - tp->iss = slirp->tcp_iss; - slirp->tcp_iss += TCP_ISSINCR / 2; - tcp_sendseqinit(tp); - tcp_output(tp); -} - -/* - * Attach a TCPCB to a socket. - */ -void tcp_attach(struct socket *so) -{ - so->so_tcpcb = tcp_newtcpcb(so); - slirp_insque(so, &so->slirp->tcb); -} - -/* - * Set the socket's type of service field - */ -static const struct tos_t tcptos[] = { - { 0, 20, IPTOS_THROUGHPUT, 0 }, /* ftp data */ - { 21, 21, IPTOS_LOWDELAY, EMU_FTP }, /* ftp control */ - { 0, 23, IPTOS_LOWDELAY, 0 }, /* telnet */ - { 0, 80, IPTOS_THROUGHPUT, 0 }, /* WWW */ - { 0, 513, IPTOS_LOWDELAY, EMU_RLOGIN | EMU_NOCONNECT }, /* rlogin */ - { 0, 544, IPTOS_LOWDELAY, EMU_KSH }, /* kshell */ - { 0, 543, IPTOS_LOWDELAY, 0 }, /* klogin */ - { 0, 6667, IPTOS_THROUGHPUT, EMU_IRC }, /* IRC */ - { 0, 6668, IPTOS_THROUGHPUT, EMU_IRC }, /* IRC undernet */ - { 0, 7070, IPTOS_LOWDELAY, EMU_REALAUDIO }, /* RealAudio control */ - { 0, 113, IPTOS_LOWDELAY, EMU_IDENT }, /* identd protocol */ - { 0, 0, 0, 0 } -}; - -/* - * Return TOS according to the above table - */ -uint8_t tcp_tos(struct socket *so) -{ - int i = 0; - - while (tcptos[i].tos) { - if ((tcptos[i].fport && (ntohs(so->so_fport) == tcptos[i].fport)) || - (tcptos[i].lport && (ntohs(so->so_lport) == tcptos[i].lport))) { - if (so->slirp->enable_emu) - so->so_emu = tcptos[i].emu; - return tcptos[i].tos; - } - i++; - } - return 0; -} - -/* - * Emulate programs that try and connect to us - * This includes ftp (the data connection is - * initiated by the server) and IRC (DCC CHAT and - * DCC SEND) for now - * - * NOTE: It's possible to crash SLiRP by sending it - * unstandard strings to emulate... if this is a problem, - * more checks are needed here - * - * XXX Assumes the whole command came in one packet - * XXX If there is more than one command in the packet, the others may - * be truncated. - * XXX If the command is too long, it may be truncated. - * - * XXX Some ftp clients will have their TOS set to - * LOWDELAY and so Nagel will kick in. Because of this, - * we'll get the first letter, followed by the rest, so - * we simply scan for ORT instead of PORT... - * DCC doesn't have this problem because there's other stuff - * in the packet before the DCC command. - * - * Return 1 if the mbuf m is still valid and should be - * sbappend()ed - * - * NOTE: if you return 0 you MUST m_free() the mbuf! - */ -int tcp_emu(struct socket *so, struct mbuf *m) -{ - Slirp *slirp = so->slirp; - unsigned n1, n2, n3, n4, n5, n6; - char buff[257]; - uint32_t laddr; - unsigned lport; - char *bptr; - - DEBUG_CALL("tcp_emu"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - switch (so->so_emu) { - int x, i; - - /* TODO: IPv6 */ - case EMU_IDENT: - /* - * Identification protocol as per rfc-1413 - */ - - { - struct socket *tmpso; - struct sockaddr_in addr; - socklen_t addrlen = sizeof(struct sockaddr_in); - char *eol = g_strstr_len(m->m_data, m->m_len, "\r\n"); - - if (!eol) { - return 1; - } - - *eol = '\0'; - if (sscanf(m->m_data, "%u%*[ ,]%u", &n1, &n2) == 2) { - HTONS(n1); - HTONS(n2); - /* n2 is the one on our host */ - for (tmpso = slirp->tcb.so_next; tmpso != &slirp->tcb; - tmpso = tmpso->so_next) { - if (tmpso->so_laddr.s_addr == so->so_laddr.s_addr && - tmpso->so_lport == n2 && - tmpso->so_faddr.s_addr == so->so_faddr.s_addr && - tmpso->so_fport == n1) { - if (getsockname(tmpso->s, (struct sockaddr *)&addr, - &addrlen) == 0) - n2 = addr.sin_port; - break; - } - } - NTOHS(n1); - NTOHS(n2); - m_inc(m, g_snprintf(NULL, 0, "%d,%d\r\n", n1, n2) + 1); - m->m_len = slirp_fmt(m->m_data, M_ROOM(m), "%d,%d\r\n", n1, n2); - } else { - *eol = '\r'; - } - - return 1; - } - - case EMU_FTP: /* ftp */ - m_inc(m, m->m_len + 1); - *(m->m_data + m->m_len) = 0; /* NUL terminate for strstr */ - if ((bptr = (char *)strstr(m->m_data, "ORT")) != NULL) { - /* - * Need to emulate the PORT command - */ - x = sscanf(bptr, "ORT %u,%u,%u,%u,%u,%u\r\n%256[^\177]", &n1, &n2, - &n3, &n4, &n5, &n6, buff); - if (x < 6) - return 1; - - laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); - lport = htons((n5 << 8) | (n6)); - - if ((so = tcp_listen(slirp, INADDR_ANY, 0, laddr, lport, - SS_FACCEPTONCE)) == NULL) { - return 1; - } - n6 = ntohs(so->so_fport); - - n5 = (n6 >> 8) & 0xff; - n6 &= 0xff; - - laddr = ntohl(so->so_faddr.s_addr); - - n1 = ((laddr >> 24) & 0xff); - n2 = ((laddr >> 16) & 0xff); - n3 = ((laddr >> 8) & 0xff); - n4 = (laddr & 0xff); - - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "ORT %d,%d,%d,%d,%d,%d\r\n%s", - n1, n2, n3, n4, n5, n6, x == 7 ? buff : ""); - return 1; - } else if ((bptr = (char *)strstr(m->m_data, "27 Entering")) != NULL) { - /* - * Need to emulate the PASV response - */ - x = sscanf( - bptr, - "27 Entering Passive Mode (%u,%u,%u,%u,%u,%u)\r\n%256[^\177]", - &n1, &n2, &n3, &n4, &n5, &n6, buff); - if (x < 6) - return 1; - - laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); - lport = htons((n5 << 8) | (n6)); - - if ((so = tcp_listen(slirp, INADDR_ANY, 0, laddr, lport, - SS_FACCEPTONCE)) == NULL) { - return 1; - } - n6 = ntohs(so->so_fport); - - n5 = (n6 >> 8) & 0xff; - n6 &= 0xff; - - laddr = ntohl(so->so_faddr.s_addr); - - n1 = ((laddr >> 24) & 0xff); - n2 = ((laddr >> 16) & 0xff); - n3 = ((laddr >> 8) & 0xff); - n4 = (laddr & 0xff); - - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s", - n1, n2, n3, n4, n5, n6, x == 7 ? buff : ""); - return 1; - } - - return 1; - - case EMU_KSH: - /* - * The kshell (Kerberos rsh) and shell services both pass - * a local port port number to carry signals to the server - * and stderr to the client. It is passed at the beginning - * of the connection as a NUL-terminated decimal ASCII string. - */ - so->so_emu = 0; - for (lport = 0, i = 0; i < m->m_len - 1; ++i) { - if (m->m_data[i] < '0' || m->m_data[i] > '9') - return 1; /* invalid number */ - lport *= 10; - lport += m->m_data[i] - '0'; - } - if (m->m_data[m->m_len - 1] == '\0' && lport != 0 && - (so = tcp_listen(slirp, INADDR_ANY, 0, so->so_laddr.s_addr, - htons(lport), SS_FACCEPTONCE)) != NULL) - m->m_len = slirp_fmt0(m->m_data, M_ROOM(m), - "%d", ntohs(so->so_fport)); - return 1; - - case EMU_IRC: - /* - * Need to emulate DCC CHAT, DCC SEND and DCC MOVE - */ - m_inc(m, m->m_len + 1); - *(m->m_data + m->m_len) = 0; /* NULL terminate the string for strstr */ - if ((bptr = (char *)strstr(m->m_data, "DCC")) == NULL) - return 1; - - /* The %256s is for the broken mIRC */ - if (sscanf(bptr, "DCC CHAT %256s %u %u", buff, &laddr, &lport) == 3) { - if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), - htons(lport), SS_FACCEPTONCE)) == NULL) { - return 1; - } - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "DCC CHAT chat %lu %u%c\n", - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), 1); - } else if (sscanf(bptr, "DCC SEND %256s %u %u %u", buff, &laddr, &lport, - &n1) == 4) { - if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), - htons(lport), SS_FACCEPTONCE)) == NULL) { - return 1; - } - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "DCC SEND %s %lu %u %u%c\n", buff, - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), n1, 1); - } else if (sscanf(bptr, "DCC MOVE %256s %u %u %u", buff, &laddr, &lport, - &n1) == 4) { - if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), - htons(lport), SS_FACCEPTONCE)) == NULL) { - return 1; - } - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "DCC MOVE %s %lu %u %u%c\n", buff, - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), n1, 1); - } - return 1; - - case EMU_REALAUDIO: - /* - * RealAudio emulation - JP. We must try to parse the incoming - * data and try to find the two characters that contain the - * port number. Then we redirect an udp port and replace the - * number with the real port we got. - * - * The 1.0 beta versions of the player are not supported - * any more. - * - * A typical packet for player version 1.0 (release version): - * - * 0000:50 4E 41 00 05 - * 0000:00 01 00 02 1B D7 00 00 67 E6 6C DC 63 00 12 50 ........g.l.c..P - * 0010:4E 43 4C 49 45 4E 54 20 31 30 31 20 41 4C 50 48 NCLIENT 101 ALPH - * 0020:41 6C 00 00 52 00 17 72 61 66 69 6C 65 73 2F 76 Al..R..rafiles/v - * 0030:6F 61 2F 65 6E 67 6C 69 73 68 5F 2E 72 61 79 42 oa/english_.rayB - * - * Now the port number 0x1BD7 is found at offset 0x04 of the - * Now the port number 0x1BD7 is found at offset 0x04 of the - * second packet. This time we received five bytes first and - * then the rest. You never know how many bytes you get. - * - * A typical packet for player version 2.0 (beta): - * - * 0000:50 4E 41 00 06 00 02 00 00 00 01 00 02 1B C1 00 PNA............. - * 0010:00 67 75 78 F5 63 00 0A 57 69 6E 32 2E 30 2E 30 .gux.c..Win2.0.0 - * 0020:2E 35 6C 00 00 52 00 1C 72 61 66 69 6C 65 73 2F .5l..R..rafiles/ - * 0030:77 65 62 73 69 74 65 2F 32 30 72 65 6C 65 61 73 website/20releas - * 0040:65 2E 72 61 79 53 00 00 06 36 42 e.rayS...6B - * - * Port number 0x1BC1 is found at offset 0x0d. - * - * This is just a horrible switch statement. Variable ra tells - * us where we're going. - */ - - bptr = m->m_data; - while (bptr < m->m_data + m->m_len) { - uint16_t p; - static int ra = 0; - char ra_tbl[4]; - - ra_tbl[0] = 0x50; - ra_tbl[1] = 0x4e; - ra_tbl[2] = 0x41; - ra_tbl[3] = 0; - - switch (ra) { - case 0: - case 2: - case 3: - if (*bptr++ != ra_tbl[ra]) { - ra = 0; - continue; - } - break; - - case 1: - /* - * We may get 0x50 several times, ignore them - */ - if (*bptr == 0x50) { - ra = 1; - bptr++; - continue; - } else if (*bptr++ != ra_tbl[ra]) { - ra = 0; - continue; - } - break; - - case 4: - /* - * skip version number - */ - bptr++; - break; - - case 5: - if (bptr == m->m_data + m->m_len - 1) - return 1; /* We need two bytes */ - - /* - * The difference between versions 1.0 and - * 2.0 is here. For future versions of - * the player this may need to be modified. - */ - if (*(bptr + 1) == 0x02) - bptr += 8; - else - bptr += 4; - break; - - case 6: - /* This is the field containing the port - * number that RA-player is listening to. - */ - - if (bptr == m->m_data + m->m_len - 1) - return 1; /* We need two bytes */ - - lport = (((uint8_t *)bptr)[0] << 8) + ((uint8_t *)bptr)[1]; - if (lport < 6970) - lport += 256; /* don't know why */ - if (lport < 6970 || lport > 7170) - return 1; /* failed */ - - /* try to get udp port between 6970 - 7170 */ - for (p = 6970; p < 7071; p++) { - if (udp_listen(slirp, INADDR_ANY, htons(p), - so->so_laddr.s_addr, htons(lport), - SS_FACCEPTONCE)) { - break; - } - } - if (p == 7071) - p = 0; - *(uint8_t *)bptr++ = (p >> 8) & 0xff; - *(uint8_t *)bptr = p & 0xff; - ra = 0; - return 1; /* port redirected, we're done */ - break; - - default: - ra = 0; - } - ra++; - } - return 1; - - default: - /* Ooops, not emulated, won't call tcp_emu again */ - so->so_emu = 0; - return 1; - } -} - -/* - * Do misc. config of SLiRP while its running. - * Return 0 if this connections is to be closed, 1 otherwise, - * return 2 if this is a command-line connection - */ -int tcp_ctl(struct socket *so) -{ - Slirp *slirp = so->slirp; - struct sbuf *sb = &so->so_snd; - struct gfwd_list *ex_ptr; - - DEBUG_CALL("tcp_ctl"); - DEBUG_ARG("so = %p", so); - - /* TODO: IPv6 */ - if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr) { - /* Check if it's pty_exec */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_fport == so->so_fport && - so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { - if (ex_ptr->write_cb) { - so->s = -1; - so->guestfwd = ex_ptr; - return 1; - } - DEBUG_MISC(" executing %s", ex_ptr->ex_exec); - if (ex_ptr->ex_unix) - return open_unix(so, ex_ptr->ex_unix); - else - return fork_exec(so, ex_ptr->ex_exec); - } - } - } - sb->sb_cc = slirp_fmt(sb->sb_wptr, sb->sb_datalen - (sb->sb_wptr - sb->sb_data), - "Error: No application configured.\r\n"); - sb->sb_wptr += sb->sb_cc; - return 0; -} diff --git a/src/network/slirp/tcp_timer.c b/src/network/slirp/tcp_timer.c deleted file mode 100644 index bc4db2d15..000000000 --- a/src/network/slirp/tcp_timer.c +++ /dev/null @@ -1,286 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_timer.c 8.1 (Berkeley) 6/10/93 - * tcp_timer.c,v 1.2 1994/08/02 07:49:10 davidg Exp - */ - -#include "slirp.h" - -static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer); - -/* - * Fast timeout routine for processing delayed acks - */ -void tcp_fasttimo(Slirp *slirp) -{ - register struct socket *so; - register struct tcpcb *tp; - - DEBUG_CALL("tcp_fasttimo"); - - so = slirp->tcb.so_next; - if (so) - for (; so != &slirp->tcb; so = so->so_next) - if ((tp = (struct tcpcb *)so->so_tcpcb) && - (tp->t_flags & TF_DELACK)) { - tp->t_flags &= ~TF_DELACK; - tp->t_flags |= TF_ACKNOW; - tcp_output(tp); - } -} - -/* - * Tcp protocol timeout routine called every 500 ms. - * Updates the timers in all active tcb's and - * causes finite state machine actions if timers expire. - */ -void tcp_slowtimo(Slirp *slirp) -{ - register struct socket *ip, *ipnxt; - register struct tcpcb *tp; - register int i; - - DEBUG_CALL("tcp_slowtimo"); - - /* - * Search through tcb's and update active timers. - */ - ip = slirp->tcb.so_next; - if (ip == NULL) { - return; - } - for (; ip != &slirp->tcb; ip = ipnxt) { - ipnxt = ip->so_next; - tp = sototcpcb(ip); - if (tp == NULL) { - continue; - } - for (i = 0; i < TCPT_NTIMERS; i++) { - if (tp->t_timer[i] && --tp->t_timer[i] == 0) { - tcp_timers(tp, i); - if (ipnxt->so_prev != ip) - goto tpgone; - } - } - tp->t_idle++; - if (tp->t_rtt) - tp->t_rtt++; - tpgone:; - } - slirp->tcp_iss += TCP_ISSINCR / PR_SLOWHZ; /* increment iss */ - slirp->tcp_now++; /* for timestamps */ -} - -/* - * Cancel all timers for TCP tp. - */ -void tcp_canceltimers(struct tcpcb *tp) -{ - register int i; - - for (i = 0; i < TCPT_NTIMERS; i++) - tp->t_timer[i] = 0; -} - -const int tcp_backoff[TCP_MAXRXTSHIFT + 1] = { 1, 2, 4, 8, 16, 32, 64, - 64, 64, 64, 64, 64, 64 }; - -/* - * TCP timer processing. - */ -static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer) -{ - register int rexmt; - - DEBUG_CALL("tcp_timers"); - - switch (timer) { - /* - * 2 MSL timeout in shutdown went off. If we're closed but - * still waiting for peer to close and connection has been idle - * too long, or if 2MSL time is up from TIME_WAIT, delete connection - * control block. Otherwise, check again in a bit. - */ - case TCPT_2MSL: - if (tp->t_state != TCPS_TIME_WAIT && tp->t_idle <= TCP_MAXIDLE) - tp->t_timer[TCPT_2MSL] = TCPTV_KEEPINTVL; - else - tp = tcp_close(tp); - break; - - /* - * Retransmission timer went off. Message has not - * been acked within retransmit interval. Back off - * to a longer retransmit interval and retransmit one segment. - */ - case TCPT_REXMT: - - /* - * XXXXX If a packet has timed out, then remove all the queued - * packets for that session. - */ - - if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) { - /* - * This is a hack to suit our terminal server here at the uni of - * canberra since they have trouble with zeroes... It usually lets - * them through unharmed, but under some conditions, it'll eat the - * zeros. If we keep retransmitting it, it'll keep eating the - * zeroes, so we keep retransmitting, and eventually the connection - * dies... (this only happens on incoming data) - * - * So, if we were gonna drop the connection from too many - * retransmits, don't... instead halve the t_maxseg, which might - * break up the NULLs and let them through - * - * *sigh* - */ - - tp->t_maxseg >>= 1; - if (tp->t_maxseg < 32) { - /* - * We tried our best, now the connection must die! - */ - tp->t_rxtshift = TCP_MAXRXTSHIFT; - tp = tcp_drop(tp, tp->t_softerror); - /* tp->t_softerror : ETIMEDOUT); */ /* XXX */ - return (tp); /* XXX */ - } - - /* - * Set rxtshift to 6, which is still at the maximum - * backoff time - */ - tp->t_rxtshift = 6; - } - rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift]; - TCPT_RANGESET(tp->t_rxtcur, rexmt, (short)tp->t_rttmin, - TCPTV_REXMTMAX); /* XXX */ - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - /* - * If losing, let the lower level know and try for - * a better route. Also, if we backed off this far, - * our srtt estimate is probably bogus. Clobber it - * so we'll take the next rtt measurement as our srtt; - * move the current srtt into rttvar to keep the current - * retransmit times until then. - */ - if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) { - tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT); - tp->t_srtt = 0; - } - tp->snd_nxt = tp->snd_una; - /* - * If timing a segment in this window, stop the timer. - */ - tp->t_rtt = 0; - /* - * Close the congestion window down to one segment - * (we'll open it by one segment for each ack we get). - * Since we probably have a window's worth of unacked - * data accumulated, this "slow start" keeps us from - * dumping all that data as back-to-back packets (which - * might overwhelm an intermediate gateway). - * - * There are two phases to the opening: Initially we - * open by one mss on each ack. This makes the window - * size increase exponentially with time. If the - * window is larger than the path can handle, this - * exponential growth results in dropped packet(s) - * almost immediately. To get more time between - * drops but still "push" the network to take advantage - * of improving conditions, we switch from exponential - * to linear window opening at some threshold size. - * For a threshold, we use half the current window - * size, truncated to a multiple of the mss. - * - * (the minimum cwnd that will give us exponential - * growth is 2 mss. We don't allow the threshold - * to go below this.) - */ - { - unsigned win = MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; - if (win < 2) - win = 2; - tp->snd_cwnd = tp->t_maxseg; - tp->snd_ssthresh = win * tp->t_maxseg; - tp->t_dupacks = 0; - } - tcp_output(tp); - break; - - /* - * Persistence timer into zero window. - * Force a byte to be output, if possible. - */ - case TCPT_PERSIST: - tcp_setpersist(tp); - tp->t_force = 1; - tcp_output(tp); - tp->t_force = 0; - break; - - /* - * Keep-alive timer went off; send something - * or drop connection if idle for too long. - */ - case TCPT_KEEP: - if (tp->t_state < TCPS_ESTABLISHED) - goto dropit; - - if (slirp_do_keepalive && tp->t_state <= TCPS_CLOSE_WAIT) { - if (tp->t_idle >= TCPTV_KEEP_IDLE + TCP_MAXIDLE) - goto dropit; - /* - * Send a packet designed to force a response - * if the peer is up and reachable: - * either an ACK if the connection is still alive, - * or an RST if the peer has closed the connection - * due to timeout or reboot. - * Using sequence number tp->snd_una-1 - * causes the transmitted zero-length segment - * to lie outside the receive window; - * by the protocol spec, this requires the - * correspondent TCP to respond. - */ - tcp_respond(tp, &tp->t_template, (struct mbuf *)NULL, tp->rcv_nxt, - tp->snd_una - 1, 0, tp->t_socket->so_ffamily); - tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL; - } else - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE; - break; - - dropit: - tp = tcp_drop(tp, 0); - break; - } - - return (tp); -} diff --git a/src/network/slirp/tcp_timer.h b/src/network/slirp/tcp_timer.h deleted file mode 100644 index 584a5594e..000000000 --- a/src/network/slirp/tcp_timer.h +++ /dev/null @@ -1,130 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 - * tcp_timer.h,v 1.4 1994/08/21 05:27:38 paul Exp - */ - -#ifndef TCP_TIMER_H -#define TCP_TIMER_H - -/* - * Definitions of the TCP timers. These timers are counted - * down PR_SLOWHZ times a second. - */ -#define TCPT_NTIMERS 4 - -#define TCPT_REXMT 0 /* retransmit */ -#define TCPT_PERSIST 1 /* retransmit persistence */ -#define TCPT_KEEP 2 /* keep alive */ -#define TCPT_2MSL 3 /* 2*msl quiet time timer */ - -/* - * The TCPT_REXMT timer is used to force retransmissions. - * The TCP has the TCPT_REXMT timer set whenever segments - * have been sent for which ACKs are expected but not yet - * received. If an ACK is received which advances tp->snd_una, - * then the retransmit timer is cleared (if there are no more - * outstanding segments) or reset to the base value (if there - * are more ACKs expected). Whenever the retransmit timer goes off, - * we retransmit one unacknowledged segment, and do a backoff - * on the retransmit timer. - * - * The TCPT_PERSIST timer is used to keep window size information - * flowing even if the window goes shut. If all previous transmissions - * have been acknowledged (so that there are no retransmissions in progress), - * and the window is too small to bother sending anything, then we start - * the TCPT_PERSIST timer. When it expires, if the window is nonzero, - * we go to transmit state. Otherwise, at intervals send a single byte - * into the peer's window to force him to update our window information. - * We do this at most as often as TCPT_PERSMIN time intervals, - * but no more frequently than the current estimate of round-trip - * packet time. The TCPT_PERSIST timer is cleared whenever we receive - * a window update from the peer. - * - * The TCPT_KEEP timer is used to keep connections alive. If an - * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, - * but not yet established, then we drop the connection. Once the connection - * is established, if the connection is idle for TCPTV_KEEP_IDLE time - * (and keepalives have been enabled on the socket), we begin to probe - * the connection. We force the peer to send us a segment by sending: - * - * This segment is (deliberately) outside the window, and should elicit - * an ack segment in response from the peer. If, despite the TCPT_KEEP - * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE - * amount of time probing, then we drop the connection. - */ - -/* - * Time constants. - */ -#define TCPTV_MSL (5 * PR_SLOWHZ) /* max seg lifetime (hah!) */ - -#define TCPTV_SRTTBASE \ - 0 /* base roundtrip time; \ - if 0, no idea yet */ -#define TCPTV_SRTTDFLT (3 * PR_SLOWHZ) /* assumed RTT if no info */ - -#define TCPTV_PERSMIN (5 * PR_SLOWHZ) /* retransmit persistence */ -#define TCPTV_PERSMAX (60 * PR_SLOWHZ) /* maximum persist interval */ - -#define TCPTV_KEEP_INIT (75 * PR_SLOWHZ) /* initial connect keep alive */ -#define TCPTV_KEEP_IDLE (120 * 60 * PR_SLOWHZ) /* dflt time before probing */ -#define TCPTV_KEEPINTVL (75 * PR_SLOWHZ) /* default probe interval */ -#define TCPTV_KEEPCNT 8 /* max probes before drop */ - -#define TCPTV_MIN (1 * PR_SLOWHZ) /* minimum allowable value */ -#define TCPTV_REXMTMAX (12 * PR_SLOWHZ) /* max allowable REXMT value */ - -#define TCP_LINGERTIME 120 /* linger at most 2 minutes */ - -#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ - - -/* - * Force a time value to be in a certain range. - */ -#define TCPT_RANGESET(tv, value, tvmin, tvmax) \ - { \ - (tv) = (value); \ - if ((tv) < (tvmin)) \ - (tv) = (tvmin); \ - else if ((tv) > (tvmax)) \ - (tv) = (tvmax); \ - } - -extern const int tcp_backoff[]; - -struct tcpcb; - -void tcp_fasttimo(Slirp *); -void tcp_slowtimo(Slirp *); -void tcp_canceltimers(struct tcpcb *); - -#endif diff --git a/src/network/slirp/tcp_var.h b/src/network/slirp/tcp_var.h deleted file mode 100644 index c8da8cbd1..000000000 --- a/src/network/slirp/tcp_var.h +++ /dev/null @@ -1,161 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_var.h 8.3 (Berkeley) 4/10/94 - * tcp_var.h,v 1.3 1994/08/21 05:27:39 paul Exp - */ - -#ifndef TCP_VAR_H -#define TCP_VAR_H - -#include "tcpip.h" -#include "tcp_timer.h" - -/* - * Tcp control block, one per tcp; fields: - */ -struct tcpcb { - struct tcpiphdr *seg_next; /* sequencing queue */ - struct tcpiphdr *seg_prev; - short t_state; /* state of this connection */ - short t_timer[TCPT_NTIMERS]; /* tcp timers */ - short t_rxtshift; /* log(2) of rexmt exp. backoff */ - short t_rxtcur; /* current retransmit value */ - short t_dupacks; /* consecutive dup acks recd */ - uint16_t t_maxseg; /* maximum segment size */ - uint8_t t_force; /* 1 if forcing out a byte */ - uint16_t t_flags; -#define TF_ACKNOW 0x0001 /* ack peer immediately */ -#define TF_DELACK 0x0002 /* ack, but try to delay it */ -#define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ -#define TF_NOOPT 0x0008 /* don't use tcp options */ -#define TF_SENTFIN 0x0010 /* have sent FIN */ -#define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ -#define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ -#define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ -#define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ -#define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ - - struct tcpiphdr t_template; /* static skeletal packet for xmit */ - - struct socket *t_socket; /* back pointer to socket */ - /* - * The following fields are used as in the protocol specification. - * See RFC783, Dec. 1981, page 21. - */ - /* send sequence variables */ - tcp_seq snd_una; /* send unacknowledged */ - tcp_seq snd_nxt; /* send next */ - tcp_seq snd_up; /* send urgent pointer */ - tcp_seq snd_wl1; /* window update seg seq number */ - tcp_seq snd_wl2; /* window update seg ack number */ - tcp_seq iss; /* initial send sequence number */ - uint32_t snd_wnd; /* send window */ - /* receive sequence variables */ - uint32_t rcv_wnd; /* receive window */ - tcp_seq rcv_nxt; /* receive next */ - tcp_seq rcv_up; /* receive urgent pointer */ - tcp_seq irs; /* initial receive sequence number */ - /* - * Additional variables for this implementation. - */ - /* receive variables */ - tcp_seq rcv_adv; /* advertised window */ - /* retransmit variables */ - tcp_seq snd_max; /* highest sequence number sent; - * used to recognize retransmits - */ - /* congestion control (for slow start, source quench, retransmit after loss) - */ - uint32_t snd_cwnd; /* congestion-controlled window */ - uint32_t snd_ssthresh; /* snd_cwnd size threshold for - * for slow start exponential to - * linear switch - */ - /* - * transmit timing stuff. See below for scale of srtt and rttvar. - * "Variance" is actually smoothed difference. - */ - short t_idle; /* inactivity time */ - short t_rtt; /* round trip time */ - tcp_seq t_rtseq; /* sequence number being timed */ - short t_srtt; /* smoothed round-trip time */ - short t_rttvar; /* variance in round-trip time */ - uint16_t t_rttmin; /* minimum rtt allowed */ - uint32_t max_sndwnd; /* largest window peer has offered */ - - /* out-of-band data */ - uint8_t t_oobflags; /* have some */ - uint8_t t_iobc; /* input character */ -#define TCPOOB_HAVEDATA 0x01 -#define TCPOOB_HADDATA 0x02 - short t_softerror; /* possible error not yet reported */ - - /* RFC 1323 variables */ - uint8_t snd_scale; /* window scaling for send window */ - uint8_t rcv_scale; /* window scaling for recv window */ - uint8_t request_r_scale; /* pending window scaling */ - uint8_t requested_s_scale; - uint32_t ts_recent; /* timestamp echo data */ - uint32_t ts_recent_age; /* when last updated */ - tcp_seq last_ack_sent; -}; - -#define sototcpcb(so) ((so)->so_tcpcb) - -/* - * The smoothed round-trip time and estimated variance - * are stored as fixed point numbers scaled by the values below. - * For convenience, these scales are also used in smoothing the average - * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). - * With these scales, srtt has 3 bits to the right of the binary point, - * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the - * binary point, and is smoothed with an ALPHA of 0.75. - */ -#define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ -#define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ -#define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ -#define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */ - -/* - * The initial retransmission should happen at rtt + 4 * rttvar. - * Because of the way we do the smoothing, srtt and rttvar - * will each average +1/2 tick of bias. When we compute - * the retransmit timer, we want 1/2 tick of rounding and - * 1 extra tick because of +-1/2 tick uncertainty in the - * firing of the timer. The bias will give us exactly the - * 1.5 tick we need. But, because the bias is - * statistical, we have to test that we don't drop below - * the minimum feasible timer (which is 2 ticks). - * This macro assumes that the value of TCP_RTTVAR_SCALE - * is the same as the multiplier for rttvar. - */ -#define TCP_REXMTVAL(tp) (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) - -#endif diff --git a/src/network/slirp/tcpip.h b/src/network/slirp/tcpip.h deleted file mode 100644 index a0fb2282f..000000000 --- a/src/network/slirp/tcpip.h +++ /dev/null @@ -1,104 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcpip.h 8.1 (Berkeley) 6/10/93 - * tcpip.h,v 1.3 1994/08/21 05:27:40 paul Exp - */ - -#ifndef TCPIP_H -#define TCPIP_H - -/* - * Tcp+ip header, after ip options removed. - */ -struct tcpiphdr { - struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */ - union { - struct { - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ - uint8_t ih_x1; /* (unused) */ - uint8_t ih_pr; /* protocol */ - } ti_i4; - struct { - struct in6_addr ih_src; - struct in6_addr ih_dst; - uint8_t ih_x1; - uint8_t ih_nh; - } ti_i6; - } ti; - uint16_t ti_x0; - uint16_t ti_len; /* protocol length */ - struct tcphdr ti_t; /* tcp header */ -}; -#define ti_mbuf ih_mbuf.mptr -#define ti_pr ti.ti_i4.ih_pr -#define ti_src ti.ti_i4.ih_src -#define ti_dst ti.ti_i4.ih_dst -#define ti_src6 ti.ti_i6.ih_src -#define ti_dst6 ti.ti_i6.ih_dst -#define ti_nh6 ti.ti_i6.ih_nh -#define ti_sport ti_t.th_sport -#define ti_dport ti_t.th_dport -#define ti_seq ti_t.th_seq -#define ti_ack ti_t.th_ack -#define ti_x2 ti_t.th_x2 -#define ti_off ti_t.th_off -#define ti_flags ti_t.th_flags -#define ti_win ti_t.th_win -#define ti_sum ti_t.th_sum -#define ti_urp ti_t.th_urp - -#define tcpiphdr2qlink(T) \ - ((struct qlink *)(((char *)(T)) - sizeof(struct qlink))) -#define qlink2tcpiphdr(Q) \ - ((struct tcpiphdr *)(((char *)(Q)) + sizeof(struct qlink))) -#define tcpiphdr_next(T) qlink2tcpiphdr(tcpiphdr2qlink(T)->next) -#define tcpiphdr_prev(T) qlink2tcpiphdr(tcpiphdr2qlink(T)->prev) -#define tcpfrag_list_first(T) qlink2tcpiphdr((T)->seg_next) -#define tcpfrag_list_end(F, T) (tcpiphdr2qlink(F) == (struct qlink *)(T)) -#define tcpfrag_list_empty(T) ((T)->seg_next == (struct tcpiphdr *)(T)) - -/* This is the difference between the size of a tcpiphdr structure, and the - * size of actual ip+tcp headers, rounded up since we need to align data. */ -#define TCPIPHDR_DELTA \ - (MAX(0, ((int) sizeof(struct tcpiphdr) - (int) sizeof(struct ip) - \ - (int) sizeof(struct tcphdr) + 3) & \ - ~3)) - -/* - * Just a clean way to get to the first byte - * of the packet - */ -struct tcpiphdr_2 { - struct tcpiphdr dummy; - char first_char; -}; - -#endif diff --git a/src/network/slirp/tftp.c b/src/network/slirp/tftp.c deleted file mode 100644 index a19c889d3..000000000 --- a/src/network/slirp/tftp.c +++ /dev/null @@ -1,470 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * tftp.c - a simple, read-only tftp server for qemu - * - * Copyright (c) 2004 Magnus Damm - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "slirp.h" - -#include -#include -#include - -static inline int tftp_session_in_use(struct tftp_session *spt) -{ - return (spt->slirp != NULL); -} - -static inline void tftp_session_update(struct tftp_session *spt) -{ - spt->timestamp = curtime; -} - -static void tftp_session_terminate(struct tftp_session *spt) -{ - if (spt->fd >= 0) { - close(spt->fd); - spt->fd = -1; - } - g_free(spt->filename); - spt->slirp = NULL; -} - -static int tftp_session_allocate(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - struct tftp_session *spt; - int k; - - for (k = 0; k < TFTP_SESSIONS_MAX; k++) { - spt = &slirp->tftp_sessions[k]; - - if (!tftp_session_in_use(spt)) - goto found; - - /* sessions time out after 5 inactive seconds */ - if ((int)(curtime - spt->timestamp) > 5000) { - tftp_session_terminate(spt); - goto found; - } - } - - return -1; - -found: - memset(spt, 0, sizeof(*spt)); - memcpy(&spt->client_addr, srcsas, sockaddr_size(srcsas)); - spt->fd = -1; - spt->block_size = 512; - spt->client_port = hdr->udp.uh_sport; - spt->slirp = slirp; - - tftp_session_update(spt); - - return k; -} - -static int tftp_session_find(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - struct tftp_session *spt; - int k; - - for (k = 0; k < TFTP_SESSIONS_MAX; k++) { - spt = &slirp->tftp_sessions[k]; - - if (tftp_session_in_use(spt)) { - if (sockaddr_equal(&spt->client_addr, srcsas)) { - if (spt->client_port == hdr->udp.uh_sport) { - return k; - } - } - } - } - - return -1; -} - -static int tftp_read_data(struct tftp_session *spt, uint32_t block_nr, - uint8_t *buf, int len) -{ - int bytes_read = 0; - - if (spt->fd < 0) { - spt->fd = open(spt->filename, O_RDONLY | O_BINARY); - } - - if (spt->fd < 0) { - return -1; - } - - if (len) { - if (lseek(spt->fd, block_nr * spt->block_size, SEEK_SET) == (off_t)-1) { - return -1; - } - - bytes_read = read(spt->fd, buf, len); - } - - return bytes_read; -} - -static struct tftp_t *tftp_prep_mbuf_data(struct tftp_session *spt, - struct mbuf *m) -{ - struct tftp_t *tp; - - memset(m->m_data, 0, m->m_size); - - m->m_data += IF_MAXLINKHDR; - if (spt->client_addr.ss_family == AF_INET6) { - m->m_data += sizeof(struct ip6); - } else { - m->m_data += sizeof(struct ip); - } - tp = (void *)m->m_data; - m->m_data += sizeof(struct udphdr); - - return tp; -} - -static void tftp_udp_output(struct tftp_session *spt, struct mbuf *m, - struct tftphdr *hdr) -{ - if (spt->client_addr.ss_family == AF_INET6) { - struct sockaddr_in6 sa6, da6; - - sa6.sin6_addr = spt->slirp->vhost_addr6; - sa6.sin6_port = hdr->udp.uh_dport; - da6.sin6_addr = ((struct sockaddr_in6 *)&spt->client_addr)->sin6_addr; - da6.sin6_port = spt->client_port; - - udp6_output(NULL, m, &sa6, &da6); - } else { - struct sockaddr_in sa4, da4; - - sa4.sin_addr = spt->slirp->vhost_addr; - sa4.sin_port = hdr->udp.uh_dport; - da4.sin_addr = ((struct sockaddr_in *)&spt->client_addr)->sin_addr; - da4.sin_port = spt->client_port; - - udp_output(NULL, m, &sa4, &da4, IPTOS_LOWDELAY); - } -} - -static int tftp_send_oack(struct tftp_session *spt, const char *keys[], - uint32_t values[], int nb, struct tftp_t *recv_tp) -{ - struct mbuf *m; - struct tftp_t *tp; - int i, n = 0; - - m = m_get(spt->slirp); - - if (!m) - return -1; - - tp = tftp_prep_mbuf_data(spt, m); - - tp->hdr.tp_op = htons(TFTP_OACK); - for (i = 0; i < nb; i++) { - n += slirp_fmt0(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s", keys[i]); - n += slirp_fmt0(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u", values[i]); - } - - m->m_len = G_SIZEOF_MEMBER(struct tftp_t, hdr.tp_op) + n; - tftp_udp_output(spt, m, &recv_tp->hdr); - - return 0; -} - -static void tftp_send_error(struct tftp_session *spt, uint16_t errorcode, - const char *msg, struct tftp_t *recv_tp) -{ - struct mbuf *m; - struct tftp_t *tp; - - DEBUG_TFTP("tftp error msg: %s", msg); - - m = m_get(spt->slirp); - - if (!m) { - goto out; - } - - tp = tftp_prep_mbuf_data(spt, m); - - tp->hdr.tp_op = htons(TFTP_ERROR); - tp->x.tp_error.tp_error_code = htons(errorcode); - slirp_pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), - msg); - - m->m_len = sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX + 2) + 3 + - strlen(msg) - sizeof(struct udphdr); - tftp_udp_output(spt, m, &recv_tp->hdr); - -out: - tftp_session_terminate(spt); -} - -static void tftp_send_next_block(struct tftp_session *spt, - struct tftphdr *hdr) -{ - struct mbuf *m; - struct tftp_t *tp; - int nobytes; - - m = m_get(spt->slirp); - - if (!m) { - return; - } - - tp = tftp_prep_mbuf_data(spt, m); - - tp->hdr.tp_op = htons(TFTP_DATA); - tp->x.tp_data.tp_block_nr = htons((spt->block_nr + 1) & 0xffff); - - nobytes = tftp_read_data(spt, spt->block_nr, tp->x.tp_data.tp_buf, - spt->block_size); - - if (nobytes < 0) { - m_free(m); - - /* send "file not found" error back */ - - tftp_send_error(spt, 1, "File not found", tp); - - return; - } - - m->m_len = sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX - nobytes) - - sizeof(struct udphdr); - tftp_udp_output(spt, m, hdr); - - if (nobytes == spt->block_size) { - tftp_session_update(spt); - } else { - tftp_session_terminate(spt); - } - - spt->block_nr++; -} - -static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftp_t *tp, int pktlen) -{ - struct tftp_session *spt; - int s, k; - size_t prefix_len; - char *req_fname; - const char *option_name[2]; - uint32_t option_value[2]; - int nb_options = 0; - - /* check if a session already exists and if so terminate it */ - s = tftp_session_find(slirp, srcsas, &tp->hdr); - if (s >= 0) { - tftp_session_terminate(&slirp->tftp_sessions[s]); - } - - s = tftp_session_allocate(slirp, srcsas, &tp->hdr); - - if (s < 0) { - return; - } - - spt = &slirp->tftp_sessions[s]; - - /* unspecified prefix means service disabled */ - if (!slirp->tftp_prefix) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - /* skip header fields */ - k = 0; - pktlen -= offsetof(struct tftp_t, x.tp_buf); - - /* prepend tftp_prefix */ - prefix_len = strlen(slirp->tftp_prefix); - spt->filename = g_malloc(prefix_len + TFTP_FILENAME_MAX + 2); - memcpy(spt->filename, slirp->tftp_prefix, prefix_len); - spt->filename[prefix_len] = '/'; - - /* get name */ - req_fname = spt->filename + prefix_len + 1; - - while (1) { - if (k >= TFTP_FILENAME_MAX || k >= pktlen) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - req_fname[k] = tp->x.tp_buf[k]; - if (req_fname[k++] == '\0') { - break; - } - } - - DEBUG_TFTP("tftp rrq file: %s", req_fname); - - /* check mode */ - if ((pktlen - k) < 6) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) { - tftp_send_error(spt, 4, "Unsupported transfer mode", tp); - return; - } - - k += 6; /* skipping octet */ - - /* do sanity checks on the filename */ - if ( -#ifdef G_OS_WIN32 - strstr(req_fname, "..\\") || - req_fname[strlen(req_fname) - 1] == '\\' || -#endif - strstr(req_fname, "../") || - req_fname[strlen(req_fname) - 1] == '/') { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - /* check if the file exists */ - if (tftp_read_data(spt, 0, NULL, 0) < 0) { - tftp_send_error(spt, 1, "File not found", tp); - return; - } - - if (tp->x.tp_buf[pktlen - 1] != 0) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - while (k < pktlen && nb_options < G_N_ELEMENTS(option_name)) { - const char *key, *value; - - key = &tp->x.tp_buf[k]; - k += strlen(key) + 1; - - if (k >= pktlen) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - value = &tp->x.tp_buf[k]; - k += strlen(value) + 1; - - if (strcasecmp(key, "tsize") == 0) { - int tsize = atoi(value); - struct stat stat_p; - - if (tsize == 0) { - if (stat(spt->filename, &stat_p) == 0) - tsize = stat_p.st_size; - else { - tftp_send_error(spt, 1, "File not found", tp); - return; - } - } - - option_name[nb_options] = "tsize"; - option_value[nb_options] = tsize; - nb_options++; - } else if (strcasecmp(key, "blksize") == 0) { - int blksize = atoi(value); - - /* Accept blksize up to our maximum size */ - if (blksize > 0) { - spt->block_size = MIN(blksize, TFTP_BLOCKSIZE_MAX); - option_name[nb_options] = "blksize"; - option_value[nb_options] = spt->block_size; - nb_options++; - } - } - } - - if (nb_options > 0) { - assert(nb_options <= G_N_ELEMENTS(option_name)); - tftp_send_oack(spt, option_name, option_value, nb_options, tp); - return; - } - - spt->block_nr = 0; - tftp_send_next_block(spt, &tp->hdr); -} - -static void tftp_handle_ack(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - int s; - - s = tftp_session_find(slirp, srcsas, hdr); - - if (s < 0) { - return; - } - - tftp_send_next_block(&slirp->tftp_sessions[s], hdr); -} - -static void tftp_handle_error(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - int s; - - s = tftp_session_find(slirp, srcsas, hdr); - - if (s < 0) { - return; - } - - tftp_session_terminate(&slirp->tftp_sessions[s]); -} - -void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m) -{ - struct tftphdr *hdr = mtod_check(m, sizeof(struct tftphdr)); - - if (hdr == NULL) { - return; - } - - switch (ntohs(hdr->tp_op)) { - case TFTP_RRQ: - tftp_handle_rrq(m->slirp, srcsas, - mtod(m, struct tftp_t *), - m->m_len); - break; - - case TFTP_ACK: - tftp_handle_ack(m->slirp, srcsas, hdr); - break; - - case TFTP_ERROR: - tftp_handle_error(m->slirp, srcsas, hdr); - break; - } -} diff --git a/src/network/slirp/tftp.h b/src/network/slirp/tftp.h deleted file mode 100644 index a0784885c..000000000 --- a/src/network/slirp/tftp.h +++ /dev/null @@ -1,70 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* tftp defines */ - -#ifndef SLIRP_TFTP_H -#define SLIRP_TFTP_H - -#include "util.h" - -#define TFTP_SESSIONS_MAX 20 - -#define TFTP_SERVER 69 - -#define TFTP_RRQ 1 -#define TFTP_WRQ 2 -#define TFTP_DATA 3 -#define TFTP_ACK 4 -#define TFTP_ERROR 5 -#define TFTP_OACK 6 - -#define TFTP_FILENAME_MAX 512 -#define TFTP_BLOCKSIZE_MAX 1428 - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct tftphdr { - struct udphdr udp; - uint16_t tp_op; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct tftp_t { - struct tftphdr hdr; - union { - struct { - uint16_t tp_block_nr; - uint8_t tp_buf[TFTP_BLOCKSIZE_MAX]; - } tp_data; - struct { - uint16_t tp_error_code; - uint8_t tp_msg[TFTP_BLOCKSIZE_MAX]; - } tp_error; - char tp_buf[TFTP_BLOCKSIZE_MAX + 2]; - } x; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -struct tftp_session { - Slirp *slirp; - char *filename; - int fd; - uint16_t block_size; - - struct sockaddr_storage client_addr; - uint16_t client_port; - uint32_t block_nr; - - int timestamp; -}; - -void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m); - -#endif diff --git a/src/network/slirp/tinyglib.c b/src/network/slirp/tinyglib.c deleted file mode 100644 index 7b1e27bc5..000000000 --- a/src/network/slirp/tinyglib.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Minimal reimplementation of GLib for libslirp. - * - * - * - * Author: RichardG, - * - * Copyright 2020 RichardG. - */ -#include -#include -#include - -/* Must be a function, as libslirp redefines it as a macro. */ -gboolean -g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, - gchar **envp, GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, GPid *child_pid, gint stdin_fd, - gint stdout_fd, gint stderr_fd, GError **error) -{ - return 0; -} - -/* Implementation borrowed from GLib itself. */ -gboolean -g_str_has_prefix (const gchar *str, - const gchar *prefix) -{ - g_return_val_if_fail (str != NULL, false); - g_return_val_if_fail (prefix != NULL, false); - - return strncmp (str, prefix, strlen (prefix)) == 0; -} - -/* Needs bounds checking, but not really used by libslirp. */ -GString * -g_string_new(gchar *base) -{ - char *ret = malloc(4096); - if (base) - strcpy(ret, base); - return ret; -} - -/* Unimplemented, as with anything related to GString. */ -gchar * -g_string_free(GString *string, gboolean free_segment) -{ - return (free_segment ? NULL : string); -} - -/* Implementation borrowed from GLib itself. */ -gchar * -g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle) -{ - if (haystack_len < 0) - return strstr(haystack, needle); - else { - const gchar *p = haystack; - gsize needle_len = strlen(needle); - gsize haystack_len_unsigned = haystack_len; - const gchar *end; - gsize i; - - if (needle_len == 0) - return (gchar *) haystack; - - if (haystack_len_unsigned < needle_len) - return NULL; - - end = haystack + haystack_len - needle_len; - - while (p <= end && *p) { - for (i = 0; i < needle_len; i++) - if (p[i] != needle[i]) - goto next; - - return (gchar *) p; - -next: - p++; - } - - return NULL; - } -} - -/* Implementation borrowed from GLib itself. */ -guint -g_strv_length(gchar **str_array) -{ - guint i = 0; - while (str_array[i] != NULL) - ++i; - return i; -} - -/* Implementation borrowed from GLib itself. */ -gsize -g_strlcpy(gchar *dest, - const gchar *src, - gsize dest_size) -{ - gchar *d = dest; - const gchar *s = src; - gsize n = dest_size; - - if (dest == NULL) - return 0; - if (src == NULL) - return 0; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) - do { - gchar c = *s++; - - *d++ = c; - if (c == 0) - break; - } while (--n != 0); - - /* If not enough room in dest, add NUL and traverse rest of src */ - if (n == 0) { - if (dest_size != 0) - *d = 0; - while (*s++) - ; - } - - return s - src - 1; /* count does not include NUL */ -} diff --git a/src/network/slirp/udp.c b/src/network/slirp/udp.c deleted file mode 100644 index bd4dbebde..000000000 --- a/src/network/slirp/udp.c +++ /dev/null @@ -1,429 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)udp_usrreq.c 8.4 (Berkeley) 1/21/94 - * udp_usrreq.c,v 1.4 1994/10/02 17:48:45 phk Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - * - * Please read the file COPYRIGHT for the - * terms and conditions of the copyright. - */ - -#include "slirp.h" -#include "ip_icmp.h" - -static uint8_t udp_tos(struct socket *so); - -void udp_init(Slirp *slirp) -{ - slirp->udb.so_next = slirp->udb.so_prev = &slirp->udb; - slirp->udp_last_so = &slirp->udb; -} - -void udp_cleanup(Slirp *slirp) -{ - struct socket *so, *so_next; - - for (so = slirp->udb.so_next; so != &slirp->udb; so = so_next) { - so_next = so->so_next; - udp_detach(slirp->udb.so_next); - } -} - -/* m->m_data points at ip packet header - * m->m_len length ip packet - * ip->ip_len length data (IPDU) - */ -void udp_input(register struct mbuf *m, int iphlen) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - register struct ip *ip; - register struct udphdr *uh; - int len; - struct ip save_ip; - struct socket *so; - struct sockaddr_storage lhost; - struct sockaddr_in *lhost4; - int ttl; - - DEBUG_CALL("udp_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("iphlen = %d", iphlen); - - /* - * Strip IP options, if any; should skip this, - * make available to user, and use on returned packets, - * but we don't yet have a way to check the checksum - * with options still present. - */ - if (iphlen > sizeof(struct ip)) { - ip_stripoptions(m, (struct mbuf *)0); - iphlen = sizeof(struct ip); - } - - /* - * Get IP and UDP header together in first mbuf. - */ - ip = mtod_check(m, iphlen + sizeof(struct udphdr)); - if (ip == NULL) { - goto bad; - } - uh = (struct udphdr *)((char *)ip + iphlen); - - /* - * Make mbuf data length reflect UDP length. - * If not enough data to reflect UDP length, drop. - */ - len = ntohs((uint16_t)uh->uh_ulen); - - if (ip->ip_len != len) { - if (len > ip->ip_len) { - goto bad; - } - m_adj(m, len - ip->ip_len); - ip->ip_len = len; - } - - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip = *ip; - save_ip.ip_len += iphlen; /* tcp_input subtracts this */ - - /* - * Checksum extended UDP header and data. - */ - if (uh->uh_sum) { - memset(&((struct ipovly *)ip)->ih_mbuf, 0, sizeof(struct mbuf_ptr)); - ((struct ipovly *)ip)->ih_x1 = 0; - ((struct ipovly *)ip)->ih_len = uh->uh_ulen; - if (cksum(m, len + sizeof(struct ip))) { - goto bad; - } - } - - lhost.ss_family = AF_INET; - lhost4 = (struct sockaddr_in *)&lhost; - lhost4->sin_addr = ip->ip_src; - lhost4->sin_port = uh->uh_sport; - - /* - * handle DHCP/BOOTP - */ - if (ntohs(uh->uh_dport) == BOOTP_SERVER && - (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr || - ip->ip_dst.s_addr == 0xffffffff)) { - bootp_input(m); - goto bad; - } - - /* - * handle TFTP - */ - if (ntohs(uh->uh_dport) == TFTP_SERVER && - ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) { - m->m_data += iphlen; - m->m_len -= iphlen; - tftp_input(&lhost, m); - m->m_data -= iphlen; - m->m_len += iphlen; - goto bad; - } - - if (slirp->restricted) { - goto bad; - } - - /* - * Locate pcb for datagram. - */ - so = solookup(&slirp->udp_last_so, &slirp->udb, &lhost, NULL); - - if (so == NULL) { - /* - * If there's no socket for this packet, - * create one - */ - so = socreate(slirp, IPPROTO_UDP); - if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC(" udp_attach errno = %d-%s", errno, strerror(errno)); - sofree(so); - goto bad; - } - - /* - * Setup fields - */ - so->so_lfamily = AF_INET; - so->so_laddr = ip->ip_src; - so->so_lport = uh->uh_sport; - - if ((so->so_iptos = udp_tos(so)) == 0) - so->so_iptos = ip->ip_tos; - - /* - * XXXXX Here, check if it's in udpexec_list, - * and if it is, do the fork_exec() etc. - */ - } - - so->so_ffamily = AF_INET; - so->so_faddr = ip->ip_dst; /* XXX */ - so->so_fport = uh->uh_dport; /* XXX */ - - iphlen += sizeof(struct udphdr); - m->m_len -= iphlen; - m->m_data += iphlen; - - /* - * Check for TTL - */ - ttl = save_ip.ip_ttl-1; - if (ttl <= 0) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp ttl exceeded"); - icmp_send_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, NULL); - goto bad; - } - setsockopt(so->s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); - - /* - * Now we sendto() the packet. - */ - if (sosendto(so, m) == -1) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); - goto bad; - } - - m_free(so->so_m); /* used for ICMP if error on sorecvfrom */ - - /* restore the orig mbuf packet */ - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - so->so_m = m; /* ICMP backup */ - - return; -bad: - m_free(m); -} - -int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, - struct sockaddr_in *daddr, int iptos) -{ - Slirp *slirp = m->slirp; -// char addr[INET_ADDRSTRLEN]; - - M_DUP_DEBUG(slirp, m, 0, sizeof(struct udpiphdr)); - - register struct udpiphdr *ui; - int error = 0; - -/* - DEBUG_CALL("udp_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("saddr = %s", inet_ntop(AF_INET, &saddr->sin_addr, addr, sizeof(addr))); - DEBUG_ARG("daddr = %s", inet_ntop(AF_INET, &daddr->sin_addr, addr, sizeof(addr))); -*/ - - /* - * Adjust for header - */ - m->m_data -= sizeof(struct udpiphdr); - m->m_len += sizeof(struct udpiphdr); - - /* - * Fill in mbuf with extended UDP header - * and addresses and length put into network format. - */ - ui = mtod(m, struct udpiphdr *); - memset(&ui->ui_i.ih_mbuf, 0, sizeof(struct mbuf_ptr)); - ui->ui_x1 = 0; - ui->ui_pr = IPPROTO_UDP; - ui->ui_len = htons(m->m_len - sizeof(struct ip)); - /* XXXXX Check for from-one-location sockets, or from-any-location sockets - */ - ui->ui_src = saddr->sin_addr; - ui->ui_dst = daddr->sin_addr; - ui->ui_sport = saddr->sin_port; - ui->ui_dport = daddr->sin_port; - ui->ui_ulen = ui->ui_len; - - /* - * Stuff checksum and output datagram. - */ - ui->ui_sum = 0; - if ((ui->ui_sum = cksum(m, m->m_len)) == 0) - ui->ui_sum = 0xffff; - ((struct ip *)ui)->ip_len = m->m_len; - - ((struct ip *)ui)->ip_ttl = IPDEFTTL; - ((struct ip *)ui)->ip_tos = iptos; - - error = ip_output(so, m); - - return (error); -} - -int udp_attach(struct socket *so, unsigned short af) -{ - so->s = slirp_socket(af, SOCK_DGRAM, 0); - if (so->s != -1) { - if (slirp_bind_outbound(so, af) != 0) { - // bind failed - close socket - closesocket(so->s); - so->s = -1; - return -1; - } - -#ifdef __linux__ - { - int opt = 1; - switch (af) { - case AF_INET: - setsockopt(so->s, IPPROTO_IP, IP_RECVERR, &opt, sizeof(opt)); - break; - case AF_INET6: - setsockopt(so->s, IPPROTO_IPV6, IPV6_RECVERR, &opt, sizeof(opt)); - break; - default: - g_assert_not_reached(); - } - } -#endif - - so->so_expire = curtime + SO_EXPIRE; - slirp_insque(so, &so->slirp->udb); - } - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - return (so->s); -} - -void udp_detach(struct socket *so) -{ - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); -} - -static const struct tos_t udptos[] = { { 0, 53, IPTOS_LOWDELAY, 0 }, /* DNS */ - { 0, 0, 0, 0 } }; - -static uint8_t udp_tos(struct socket *so) -{ - int i = 0; - - while (udptos[i].tos) { - if ((udptos[i].fport && ntohs(so->so_fport) == udptos[i].fport) || - (udptos[i].lport && ntohs(so->so_lport) == udptos[i].lport)) { - if (so->slirp->enable_emu) - so->so_emu = udptos[i].emu; - return udptos[i].tos; - } - i++; - } - - return 0; -} - -struct socket *udpx_listen(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags) -{ - struct socket *so; - socklen_t addrlen; - int save_errno; - - so = socreate(slirp, IPPROTO_UDP); - so->s = slirp_socket(haddr->sa_family, SOCK_DGRAM, 0); - if (so->s < 0) { - save_errno = errno; - sofree(so); - errno = save_errno; - return NULL; - } - if (haddr->sa_family == AF_INET6) - slirp_socket_set_v6only(so->s, (flags & SS_HOSTFWD_V6ONLY) != 0); - so->so_expire = curtime + SO_EXPIRE; - slirp_insque(so, &slirp->udb); - - if (bind(so->s, haddr, haddrlen) < 0) { - save_errno = errno; - udp_detach(so); - errno = save_errno; - return NULL; - } - slirp_socket_set_fast_reuse(so->s); - - addrlen = sizeof(so->fhost); - getsockname(so->s, &so->fhost.sa, &addrlen); - sotranslate_accept(so); - - sockaddr_copy(&so->lhost.sa, sizeof(so->lhost), laddr, laddrlen); - - if (flags != SS_FACCEPTONCE) - so->so_expire = 0; - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_ISFCONNECTED | flags; - - return so; -} - -struct socket *udp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, - uint32_t laddr, unsigned lport, int flags) -{ - struct sockaddr_in hsa, lsa; - - memset(&hsa, 0, sizeof(hsa)); - hsa.sin_family = AF_INET; - hsa.sin_addr.s_addr = haddr; - hsa.sin_port = hport; - - memset(&lsa, 0, sizeof(lsa)); - lsa.sin_family = AF_INET; - lsa.sin_addr.s_addr = laddr; - lsa.sin_port = lport; - - return udpx_listen(slirp, (const struct sockaddr *) &hsa, sizeof(hsa), (struct sockaddr *) &lsa, sizeof(lsa), flags); -} diff --git a/src/network/slirp/udp.h b/src/network/slirp/udp.h deleted file mode 100644 index 47f4ed34d..000000000 --- a/src/network/slirp/udp.h +++ /dev/null @@ -1,96 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)udp.h 8.1 (Berkeley) 6/10/93 - * udp.h,v 1.3 1994/08/21 05:27:41 paul Exp - */ - -#ifndef UDP_H -#define UDP_H - -#include "socket.h" - -#define UDP_TTL 0x60 -#define UDP_UDPDATALEN 16192 - -/* - * Udp protocol header. - * Per RFC 768, September, 1981. - */ -struct udphdr { - uint16_t uh_sport; /* source port */ - uint16_t uh_dport; /* destination port */ - int16_t uh_ulen; /* udp length */ - uint16_t uh_sum; /* udp checksum */ -}; - -/* - * UDP kernel structures and variables. - */ -struct udpiphdr { - struct ipovly ui_i; /* overlaid ip structure */ - struct udphdr ui_u; /* udp header */ -}; -#define ui_mbuf ui_i.ih_mbuf.mptr -#define ui_x1 ui_i.ih_x1 -#define ui_pr ui_i.ih_pr -#define ui_len ui_i.ih_len -#define ui_src ui_i.ih_src -#define ui_dst ui_i.ih_dst -#define ui_sport ui_u.uh_sport -#define ui_dport ui_u.uh_dport -#define ui_ulen ui_u.uh_ulen -#define ui_sum ui_u.uh_sum - -/* - * Names for UDP sysctl objects - */ -#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ -#define UDPCTL_MAXID 2 - -struct mbuf; - -void udp_init(Slirp *); -void udp_cleanup(Slirp *); -void udp_input(register struct mbuf *, int); -int udp_attach(struct socket *, unsigned short af); -void udp_detach(struct socket *); -struct socket *udp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int); -struct socket *udpx_listen(Slirp *, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags); -int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, - struct sockaddr_in *daddr, int iptos); - -void udp6_input(register struct mbuf *); -int udp6_output(struct socket *so, struct mbuf *m, struct sockaddr_in6 *saddr, - struct sockaddr_in6 *daddr); - -#endif diff --git a/src/network/slirp/udp6.c b/src/network/slirp/udp6.c deleted file mode 100644 index effdf77d0..000000000 --- a/src/network/slirp/udp6.c +++ /dev/null @@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron - */ - -#include "slirp.h" -#include "udp.h" -#include "dhcpv6.h" - -void udp6_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - struct ip6 *ip, save_ip; - struct udphdr *uh; - int iphlen = sizeof(struct ip6); - int len; - struct socket *so; - struct sockaddr_in6 lhost; - int hop_limit; - - DEBUG_CALL("udp6_input"); - DEBUG_ARG("m = %p", m); - - if (slirp->restricted) { - goto bad; - } - - ip = mtod(m, struct ip6 *); - m->m_len -= iphlen; - m->m_data += iphlen; - uh = mtod_check(m, sizeof(struct udphdr)); - if (uh == NULL) { - goto bad; - } - m->m_len += iphlen; - m->m_data -= iphlen; - - if (ip6_cksum(m)) { - goto bad; - } - - len = ntohs((uint16_t)uh->uh_ulen); - - /* - * Make mbuf data length reflect UDP length. - * If not enough data to reflect UDP length, drop. - */ - if (ntohs(ip->ip_pl) != len) { - if (len > ntohs(ip->ip_pl)) { - goto bad; - } - m_adj(m, len - ntohs(ip->ip_pl)); - ip->ip_pl = htons(len); - } - - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip = *ip; - - /* Locate pcb for datagram. */ - lhost.sin6_family = AF_INET6; - lhost.sin6_addr = ip->ip_src; - lhost.sin6_port = uh->uh_sport; - - /* handle DHCPv6 */ - if (ntohs(uh->uh_dport) == DHCPV6_SERVER_PORT && - (in6_equal(&ip->ip_dst, &slirp->vhost_addr6) || - in6_dhcp_multicast(&ip->ip_dst))) { - m->m_data += iphlen; - m->m_len -= iphlen; - dhcpv6_input(&lhost, m); - m->m_data -= iphlen; - m->m_len += iphlen; - goto bad; - } - - /* handle TFTP */ - if (ntohs(uh->uh_dport) == TFTP_SERVER && - !memcmp(ip->ip_dst.s6_addr, slirp->vhost_addr6.s6_addr, 16)) { - m->m_data += iphlen; - m->m_len -= iphlen; - tftp_input((struct sockaddr_storage *)&lhost, m); - m->m_data -= iphlen; - m->m_len += iphlen; - goto bad; - } - - so = solookup(&slirp->udp_last_so, &slirp->udb, - (struct sockaddr_storage *)&lhost, NULL); - - if (so == NULL) { - /* If there's no socket for this packet, create one. */ - so = socreate(slirp, IPPROTO_UDP); - if (udp_attach(so, AF_INET6) == -1) { - DEBUG_MISC(" udp6_attach errno = %d-%s", errno, strerror(errno)); - sofree(so); - goto bad; - } - - /* Setup fields */ - so->so_lfamily = AF_INET6; - so->so_laddr6 = ip->ip_src; - so->so_lport6 = uh->uh_sport; - } - - so->so_ffamily = AF_INET6; - so->so_faddr6 = ip->ip_dst; /* XXX */ - so->so_fport6 = uh->uh_dport; /* XXX */ - - iphlen += sizeof(struct udphdr); - m->m_len -= iphlen; - m->m_data += iphlen; - - /* - * Check for TTL - */ - hop_limit = save_ip.ip_hl-1; - if (hop_limit <= 0) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp ttl exceeded"); - icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS); - goto bad; - } - setsockopt(so->s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hop_limit, sizeof(hop_limit)); - - /* - * Now we sendto() the packet. - */ - if (sosendto(so, m) == -1) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); - icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE); - goto bad; - } - - m_free(so->so_m); /* used for ICMP if error on sorecvfrom */ - - /* restore the orig mbuf packet */ - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - so->so_m = m; - - return; -bad: - m_free(m); -} - -int udp6_output(struct socket *so, struct mbuf *m, struct sockaddr_in6 *saddr, - struct sockaddr_in6 *daddr) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, sizeof(struct ip6) + sizeof(struct udphdr)); - - struct ip6 *ip; - struct udphdr *uh; - - DEBUG_CALL("udp6_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - /* adjust for header */ - m->m_data -= sizeof(struct udphdr); - m->m_len += sizeof(struct udphdr); - uh = mtod(m, struct udphdr *); - m->m_data -= sizeof(struct ip6); - m->m_len += sizeof(struct ip6); - ip = mtod(m, struct ip6 *); - - /* Build IP header */ - ip->ip_pl = htons(m->m_len - sizeof(struct ip6)); - ip->ip_nh = IPPROTO_UDP; - ip->ip_src = saddr->sin6_addr; - ip->ip_dst = daddr->sin6_addr; - - /* Build UDP header */ - uh->uh_sport = saddr->sin6_port; - uh->uh_dport = daddr->sin6_port; - uh->uh_ulen = ip->ip_pl; - uh->uh_sum = 0; - uh->uh_sum = ip6_cksum(m); - if (uh->uh_sum == 0) { - uh->uh_sum = 0xffff; - } - - return ip6_output(so, m, 0); -} diff --git a/src/network/slirp/util.c b/src/network/slirp/util.c deleted file mode 100644 index 7297e5022..000000000 --- a/src/network/slirp/util.c +++ /dev/null @@ -1,442 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * util.c (mostly based on QEMU os-win32.c) - * - * Copyright (c) 2003-2008 Fabrice Bellard - * Copyright (c) 2010-2016 Red Hat, Inc. - * - * QEMU library functions for win32 which are shared between QEMU and - * the QEMU tools. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "util.h" - -#include -#include -#include -#include - -#if defined(_WIN32) -int slirp_inet_aton(const char *cp, struct in_addr *ia) -{ - uint32_t addr = inet_addr(cp); - if (addr == 0xffffffff) { - return 0; - } - ia->s_addr = addr; - return 1; -} -#endif - -void slirp_set_nonblock(int fd) -{ -#ifndef _WIN32 - int f; - f = fcntl(fd, F_GETFL); - assert(f != -1); - f = fcntl(fd, F_SETFL, f | O_NONBLOCK); - assert(f != -1); -#else - unsigned long opt = 1; - ioctlsocket(fd, FIONBIO, &opt); -#endif -} - -static void slirp_set_cloexec(int fd) -{ -#ifndef _WIN32 - int f; - f = fcntl(fd, F_GETFD); - assert(f != -1); - f = fcntl(fd, F_SETFD, f | FD_CLOEXEC); - assert(f != -1); -#endif -} - -/* - * Opens a socket with FD_CLOEXEC set - * On failure errno contains the reason. - */ -int slirp_socket(int domain, int type, int protocol) -{ - int ret; - -#ifdef SOCK_CLOEXEC - ret = socket(domain, type | SOCK_CLOEXEC, protocol); - if (ret != -1 || errno != EINVAL) { - return ret; - } -#endif - ret = socket(domain, type, protocol); - if (ret >= 0) { - slirp_set_cloexec(ret); - } - - return ret; -} - -#ifdef _WIN32 -static int socket_error(void) -{ - switch (WSAGetLastError()) { - case 0: - return 0; - case WSAEINTR: - return EINTR; - case WSAEINVAL: - return EINVAL; - case WSA_INVALID_HANDLE: - return EBADF; - case WSA_NOT_ENOUGH_MEMORY: - return ENOMEM; - case WSA_INVALID_PARAMETER: - return EINVAL; - case WSAENAMETOOLONG: - return ENAMETOOLONG; - case WSAENOTEMPTY: - return ENOTEMPTY; - case WSAEWOULDBLOCK: - /* not using EWOULDBLOCK as we don't want code to have - * to check both EWOULDBLOCK and EAGAIN */ - return EAGAIN; - case WSAEINPROGRESS: - return EINPROGRESS; - case WSAEALREADY: - return EALREADY; - case WSAENOTSOCK: - return ENOTSOCK; - case WSAEDESTADDRREQ: - return EDESTADDRREQ; - case WSAEMSGSIZE: - return EMSGSIZE; - case WSAEPROTOTYPE: - return EPROTOTYPE; - case WSAENOPROTOOPT: - return ENOPROTOOPT; - case WSAEPROTONOSUPPORT: - return EPROTONOSUPPORT; - case WSAEOPNOTSUPP: - return EOPNOTSUPP; - case WSAEAFNOSUPPORT: - return EAFNOSUPPORT; - case WSAEADDRINUSE: - return EADDRINUSE; - case WSAEADDRNOTAVAIL: - return EADDRNOTAVAIL; - case WSAENETDOWN: - return ENETDOWN; - case WSAENETUNREACH: - return ENETUNREACH; - case WSAENETRESET: - return ENETRESET; - case WSAECONNABORTED: - return ECONNABORTED; - case WSAECONNRESET: - return ECONNRESET; - case WSAENOBUFS: - return ENOBUFS; - case WSAEISCONN: - return EISCONN; - case WSAENOTCONN: - return ENOTCONN; - case WSAETIMEDOUT: - return ETIMEDOUT; - case WSAECONNREFUSED: - return ECONNREFUSED; - case WSAELOOP: - return ELOOP; - case WSAEHOSTUNREACH: - return EHOSTUNREACH; - default: - return EIO; - } -} - -#undef ioctlsocket -int slirp_ioctlsocket_wrap(int fd, int req, void *val) -{ - int ret; - ret = ioctlsocket(fd, req, val); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef closesocket -int slirp_closesocket_wrap(int fd) -{ - int ret; - ret = closesocket(fd); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef connect -int slirp_connect_wrap(int sockfd, const struct sockaddr *addr, int addrlen) -{ - int ret; - ret = connect(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef listen -int slirp_listen_wrap(int sockfd, int backlog) -{ - int ret; - ret = listen(sockfd, backlog); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef bind -int slirp_bind_wrap(int sockfd, const struct sockaddr *addr, int addrlen) -{ - int ret; - ret = bind(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef socket -int slirp_socket_wrap(int domain, int type, int protocol) -{ - int ret; - ret = socket(domain, type, protocol); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef accept -int slirp_accept_wrap(int sockfd, struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = accept(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef shutdown -int slirp_shutdown_wrap(int sockfd, int how) -{ - int ret; - ret = shutdown(sockfd, how); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef getsockopt -int slirp_getsockopt_wrap(int sockfd, int level, int optname, void *optval, - int *optlen) -{ - int ret; - ret = getsockopt(sockfd, level, optname, optval, optlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef setsockopt -int slirp_setsockopt_wrap(int sockfd, int level, int optname, - const void *optval, int optlen) -{ - int ret; - ret = setsockopt(sockfd, level, optname, optval, optlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef getpeername -int slirp_getpeername_wrap(int sockfd, struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = getpeername(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef getsockname -int slirp_getsockname_wrap(int sockfd, struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = getsockname(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef send -ssize_t slirp_send_wrap(int sockfd, const void *buf, size_t len, int flags) -{ - int ret; - ret = send(sockfd, buf, len, flags); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef sendto -ssize_t slirp_sendto_wrap(int sockfd, const void *buf, size_t len, int flags, - const struct sockaddr *addr, int addrlen) -{ - int ret; - ret = sendto(sockfd, buf, len, flags, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef recv -ssize_t slirp_recv_wrap(int sockfd, void *buf, size_t len, int flags) -{ - int ret; - ret = recv(sockfd, buf, len, flags); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef recvfrom -ssize_t slirp_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags, - struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = recvfrom(sockfd, buf, len, flags, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} -#endif /* WIN32 */ - -void slirp_pstrcpy(char *buf, int buf_size, const char *str) -{ - int c; - char *q = buf; - - if (buf_size <= 0) - return; - - for (;;) { - c = *str++; - if (c == 0 || q >= buf + buf_size - 1) - break; - *q++ = c; - } - *q = '\0'; -} - -G_GNUC_PRINTF(3, 0) -static int slirp_vsnprintf(char *str, size_t size, - const char *format, va_list args) -{ - int rv = g_vsnprintf(str, size, format, args); - - if (rv < 0) { - g_error("g_vsnprintf() failed: %s", g_strerror(errno)); - } - - return rv; -} - -/* - * A snprintf()-like function that: - * - returns the number of bytes written (excluding optional \0-ending) - * - dies on error - * - warn on truncation - */ -int slirp_fmt(char *str, size_t size, const char *format, ...) -{ - va_list args; - int rv; - - va_start(args, format); - rv = slirp_vsnprintf(str, size, format, args); - va_end(args); - - if (rv >= size) { - g_critical("slirp_fmt() truncation"); - } - - return MIN(rv, size); -} - -/* - * A snprintf()-like function that: - * - always \0-end (unless size == 0) - * - returns the number of bytes actually written, including \0 ending - * - dies on error - * - warn on truncation - */ -int slirp_fmt0(char *str, size_t size, const char *format, ...) -{ - va_list args; - int rv; - - va_start(args, format); - rv = slirp_vsnprintf(str, size, format, args); - va_end(args); - - if (rv >= size) { - g_critical("slirp_fmt0() truncation"); - if (size > 0) - str[size - 1] = '\0'; - rv = size; - } else { - rv += 1; /* include \0 */ - } - - return rv; -} - -const char *slirp_ether_ntoa(const uint8_t *addr, char *out_str, - size_t out_str_size) -{ - assert(out_str_size >= ETH_ADDRSTRLEN); - - slirp_fmt0(out_str, out_str_size, "%02x:%02x:%02x:%02x:%02x:%02x", - addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); - - return out_str; -} diff --git a/src/network/slirp/util.h b/src/network/slirp/util.h deleted file mode 100644 index 0f0123a34..000000000 --- a/src/network/slirp/util.h +++ /dev/null @@ -1,201 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * Copyright (c) 2003-2008 Fabrice Bellard - * Copyright (c) 2010-2019 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef UTIL_H_ -#define UTIL_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include -#include -#include -#else -#include -#include -#include -#include -#endif - -#if defined(_MSC_VER) && !defined(__clang__) -#define SLIRP_PACKED -#elif defined(_WIN32) && (defined(__x86_64__) || defined(__i386__)) && !defined(__clang__) -#define SLIRP_PACKED __attribute__((gcc_struct, packed)) -#else -#define SLIRP_PACKED __attribute__((packed)) -#endif - -#ifndef DIV_ROUND_UP -#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d)) -#endif - -#ifndef container_of -#define container_of(ptr, type, member) \ - ((type *) (((char *)(ptr)) - offsetof(type, member))); -#endif - -#ifndef G_SIZEOF_MEMBER -#define G_SIZEOF_MEMBER(type, member) sizeof(((type *)0)->member) -#endif - -#if defined(_WIN32) /* CONFIG_IOVEC */ -#if !defined(IOV_MAX) /* XXX: to avoid duplicate with QEMU osdep.h */ -struct iovec { - void *iov_base; - size_t iov_len; -}; -#endif -#else -#include -#endif - -#define stringify(s) tostring(s) -#define tostring(s) #s - -#define SCALE_MS 1000000 - -#define ETH_ALEN 6 -#define ETH_ADDRSTRLEN 18 /* "xx:xx:xx:xx:xx:xx", with trailing NUL */ -#define ETH_HLEN 14 -#define ETH_P_IP (0x0800) /* Internet Protocol packet */ -#define ETH_P_ARP (0x0806) /* Address Resolution packet */ -#define ETH_P_IPV6 (0x86dd) -#define ETH_P_VLAN (0x8100) -#define ETH_P_DVLAN (0x88a8) -#define ETH_P_NCSI (0x88f8) -#define ETH_P_UNKNOWN (0xffff) - -/* FIXME: remove me when made standalone */ -#ifdef _WIN32 -#undef accept -#undef bind -#undef closesocket -#undef connect -#undef getpeername -#undef getsockname -#undef getsockopt -#undef ioctlsocket -#undef listen -#undef recv -#undef recvfrom -#undef send -#undef sendto -#undef setsockopt -#undef shutdown -#undef socket -#endif - -#ifdef _WIN32 -#define connect slirp_connect_wrap -int slirp_connect_wrap(int fd, const struct sockaddr *addr, int addrlen); -#define listen slirp_listen_wrap -int slirp_listen_wrap(int fd, int backlog); -#define bind slirp_bind_wrap -int slirp_bind_wrap(int fd, const struct sockaddr *addr, int addrlen); -#define socket slirp_socket_wrap -int slirp_socket_wrap(int domain, int type, int protocol); -#define accept slirp_accept_wrap -int slirp_accept_wrap(int fd, struct sockaddr *addr, int *addrlen); -#define shutdown slirp_shutdown_wrap -int slirp_shutdown_wrap(int fd, int how); -#define getpeername slirp_getpeername_wrap -int slirp_getpeername_wrap(int fd, struct sockaddr *addr, int *addrlen); -#define getsockname slirp_getsockname_wrap -int slirp_getsockname_wrap(int fd, struct sockaddr *addr, int *addrlen); -#define send slirp_send_wrap -ssize_t slirp_send_wrap(int fd, const void *buf, size_t len, int flags); -#define sendto slirp_sendto_wrap -ssize_t slirp_sendto_wrap(int fd, const void *buf, size_t len, int flags, - const struct sockaddr *dest_addr, int addrlen); -#define recv slirp_recv_wrap -ssize_t slirp_recv_wrap(int fd, void *buf, size_t len, int flags); -#define recvfrom slirp_recvfrom_wrap -ssize_t slirp_recvfrom_wrap(int fd, void *buf, size_t len, int flags, - struct sockaddr *src_addr, int *addrlen); -#define closesocket slirp_closesocket_wrap -int slirp_closesocket_wrap(int fd); -#define ioctlsocket slirp_ioctlsocket_wrap -int slirp_ioctlsocket_wrap(int fd, int req, void *val); -#define getsockopt slirp_getsockopt_wrap -int slirp_getsockopt_wrap(int sockfd, int level, int optname, void *optval, - int *optlen); -#define setsockopt slirp_setsockopt_wrap -int slirp_setsockopt_wrap(int sockfd, int level, int optname, - const void *optval, int optlen); -#define inet_aton slirp_inet_aton -int slirp_inet_aton(const char *cp, struct in_addr *ia); -#else -#define closesocket(s) close(s) -#define ioctlsocket(s, r, v) ioctl(s, r, v) -#endif - -int slirp_socket(int domain, int type, int protocol); -void slirp_set_nonblock(int fd); - -static inline int slirp_socket_set_v6only(int fd, int v) -{ - return setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v, sizeof(v)); -} - -static inline int slirp_socket_set_nodelay(int fd) -{ - int v = 1; - return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)); -} - -static inline int slirp_socket_set_fast_reuse(int fd) -{ -#ifndef _WIN32 - int v = 1; - return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)); -#else - /* Enabling the reuse of an endpoint that was used by a socket still in - * TIME_WAIT state is usually performed by setting SO_REUSEADDR. On Windows - * fast reuse is the default and SO_REUSEADDR does strange things. So we - * don't have to do anything here. More info can be found at: - * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.aspx */ - return 0; -#endif -} - -void slirp_pstrcpy(char *buf, int buf_size, const char *str); - -int slirp_fmt(char *str, size_t size, const char *format, ...) G_GNUC_PRINTF(3, 4); -int slirp_fmt0(char *str, size_t size, const char *format, ...) G_GNUC_PRINTF(3, 4); - -/* - * Pretty print a MAC address into out_str. - * As a convenience returns out_str. - */ -const char *slirp_ether_ntoa(const uint8_t *addr, char *out_str, - size_t out_str_len); - -#endif diff --git a/src/network/slirp/version.c b/src/network/slirp/version.c deleted file mode 100644 index 93e0be9c2..000000000 --- a/src/network/slirp/version.c +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#include "libslirp.h" - -const char * -slirp_version_string(void) -{ - return SLIRP_VERSION_STRING; -} diff --git a/src/network/slirp/vmstate.c b/src/network/slirp/vmstate.c deleted file mode 100644 index b9926ea41..000000000 --- a/src/network/slirp/vmstate.c +++ /dev/null @@ -1,444 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * VMState interpreter - * - * Copyright (c) 2009-2018 Red Hat Inc - * - * Authors: - * Juan Quintela - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#include - -#include "stream.h" -#include "vmstate.h" - -static int get_nullptr(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - if (slirp_istream_read_u8(f) == VMS_NULLPTR_MARKER) { - return 0; - } - g_warning("vmstate: get_nullptr expected VMS_NULLPTR_MARKER"); - return -EINVAL; -} - -static int put_nullptr(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) - -{ - if (pv == NULL) { - slirp_ostream_write_u8(f, VMS_NULLPTR_MARKER); - return 0; - } - g_warning("vmstate: put_nullptr must be called with pv == NULL"); - return -EINVAL; -} - -const VMStateInfo slirp_vmstate_info_nullptr = { - .name = "uint64", - .get = get_nullptr, - .put = put_nullptr, -}; - -/* 8 bit unsigned int */ - -static int get_uint8(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint8_t *v = pv; - *v = slirp_istream_read_u8(f); - return 0; -} - -static int put_uint8(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint8_t *v = pv; - slirp_ostream_write_u8(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_uint8 = { - .name = "uint8", - .get = get_uint8, - .put = put_uint8, -}; - -/* 16 bit unsigned int */ - -static int get_uint16(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint16_t *v = pv; - *v = slirp_istream_read_u16(f); - return 0; -} - -static int put_uint16(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint16_t *v = pv; - slirp_ostream_write_u16(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_uint16 = { - .name = "uint16", - .get = get_uint16, - .put = put_uint16, -}; - -/* 32 bit unsigned int */ - -static int get_uint32(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint32_t *v = pv; - *v = slirp_istream_read_u32(f); - return 0; -} - -static int put_uint32(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint32_t *v = pv; - slirp_ostream_write_u32(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_uint32 = { - .name = "uint32", - .get = get_uint32, - .put = put_uint32, -}; - -/* 16 bit int */ - -static int get_int16(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int16_t *v = pv; - *v = slirp_istream_read_i16(f); - return 0; -} - -static int put_int16(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int16_t *v = pv; - slirp_ostream_write_i16(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_int16 = { - .name = "int16", - .get = get_int16, - .put = put_int16, -}; - -/* 32 bit int */ - -static int get_int32(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int32_t *v = pv; - *v = slirp_istream_read_i32(f); - return 0; -} - -static int put_int32(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int32_t *v = pv; - slirp_ostream_write_i32(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_int32 = { - .name = "int32", - .get = get_int32, - .put = put_int32, -}; - -/* vmstate_info_tmp, see VMSTATE_WITH_TMP, the idea is that we allocate - * a temporary buffer and the pre_load/pre_save methods in the child vmsd - * copy stuff from the parent into the child and do calculations to fill - * in fields that don't really exist in the parent but need to be in the - * stream. - */ -static int get_tmp(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int ret; - const VMStateDescription *vmsd = field->vmsd; - int version_id = field->version_id; - void *tmp = g_malloc(size); - - /* Writes the parent field which is at the start of the tmp */ - *(void **)tmp = pv; - ret = slirp_vmstate_load_state(f, vmsd, tmp, version_id); - g_free(tmp); - return ret; -} - -static int put_tmp(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - const VMStateDescription *vmsd = field->vmsd; - void *tmp = g_malloc(size); - int ret; - - /* Writes the parent field which is at the start of the tmp */ - *(void **)tmp = pv; - ret = slirp_vmstate_save_state(f, vmsd, tmp); - g_free(tmp); - - return ret; -} - -const VMStateInfo slirp_vmstate_info_tmp = { - .name = "tmp", - .get = get_tmp, - .put = put_tmp, -}; - -/* uint8_t buffers */ - -static int get_buffer(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - slirp_istream_read(f, pv, size); - return 0; -} - -static int put_buffer(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - slirp_ostream_write(f, pv, size); - return 0; -} - -const VMStateInfo slirp_vmstate_info_buffer = { - .name = "buffer", - .get = get_buffer, - .put = put_buffer, -}; - -static int vmstate_n_elems(void *opaque, const VMStateField *field) -{ - int n_elems = 1; - - if (field->flags & VMS_ARRAY) { - n_elems = field->num; - } else if (field->flags & VMS_VARRAY_INT32) { - n_elems = *(int32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT32) { - n_elems = *(uint32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT16) { - n_elems = *(uint16_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT8) { - n_elems = *(uint8_t *)(opaque + field->num_offset); - } - - if (field->flags & VMS_MULTIPLY_ELEMENTS) { - n_elems *= field->num; - } - - return n_elems; -} - -static int vmstate_size(void *opaque, const VMStateField *field) -{ - int size = field->size; - - if (field->flags & VMS_VBUFFER) { - size = *(int32_t *)(opaque + field->size_offset); - if (field->flags & VMS_MULTIPLY) { - size *= field->size; - } - } - - return size; -} - -static int vmstate_save_state_v(SlirpOStream *f, const VMStateDescription *vmsd, - void *opaque, int version_id) -{ - int ret = 0; - const VMStateField *field = vmsd->fields; - - if (vmsd->pre_save) { - ret = vmsd->pre_save(opaque); - if (ret) { - g_warning("pre-save failed: %s", vmsd->name); - return ret; - } - } - - while (field->name) { - if ((field->field_exists && field->field_exists(opaque, version_id)) || - (!field->field_exists && field->version_id <= version_id)) { - void *first_elem = opaque + field->offset; - int i, n_elems = vmstate_n_elems(opaque, field); - int size = vmstate_size(opaque, field); - - if (field->flags & VMS_POINTER) { - first_elem = *(void **)first_elem; - assert(first_elem || !n_elems || !size); - } - for (i = 0; i < n_elems; i++) { - void *curr_elem = first_elem + size * i; - - if (field->flags & VMS_ARRAY_OF_POINTER) { - assert(curr_elem); - curr_elem = *(void **)curr_elem; - } - if (!curr_elem && size) { - /* if null pointer write placeholder and do not follow */ - assert(field->flags & VMS_ARRAY_OF_POINTER); - ret = slirp_vmstate_info_nullptr.put(f, curr_elem, size, - NULL); - } else if (field->flags & VMS_STRUCT) { - ret = slirp_vmstate_save_state(f, field->vmsd, curr_elem); - } else if (field->flags & VMS_VSTRUCT) { - ret = vmstate_save_state_v(f, field->vmsd, curr_elem, - field->struct_version_id); - } else { - ret = field->info->put(f, curr_elem, size, field); - } - if (ret) { - g_warning("Save of field %s/%s failed", vmsd->name, - field->name); - return ret; - } - } - } else { - if (field->flags & VMS_MUST_EXIST) { - g_warning("Output state validation failed: %s/%s", vmsd->name, - field->name); - assert(!(field->flags & VMS_MUST_EXIST)); - } - } - field++; - } - - return 0; -} - -int slirp_vmstate_save_state(SlirpOStream *f, const VMStateDescription *vmsd, - void *opaque) -{ - return vmstate_save_state_v(f, vmsd, opaque, vmsd->version_id); -} - -static void vmstate_handle_alloc(void *ptr, VMStateField *field, void *opaque) -{ - if (field->flags & VMS_POINTER && field->flags & VMS_ALLOC) { - size_t size = vmstate_size(opaque, field); - size *= vmstate_n_elems(opaque, field); - if (size) { - *(void **)ptr = g_malloc(size); - } - } -} - -int slirp_vmstate_load_state(SlirpIStream *f, const VMStateDescription *vmsd, - void *opaque, int version_id) -{ - VMStateField *field = vmsd->fields; - int ret = 0; - - if (version_id > vmsd->version_id) { - g_warning("%s: incoming version_id %d is too new " - "for local version_id %d", - vmsd->name, version_id, vmsd->version_id); - return -EINVAL; - } - if (vmsd->pre_load) { - int ret = vmsd->pre_load(opaque); - if (ret) { - return ret; - } - } - while (field->name) { - if ((field->field_exists && field->field_exists(opaque, version_id)) || - (!field->field_exists && field->version_id <= version_id)) { - void *first_elem = opaque + field->offset; - int i, n_elems = vmstate_n_elems(opaque, field); - int size = vmstate_size(opaque, field); - - vmstate_handle_alloc(first_elem, field, opaque); - if (field->flags & VMS_POINTER) { - first_elem = *(void **)first_elem; - assert(first_elem || !n_elems || !size); - } - for (i = 0; i < n_elems; i++) { - void *curr_elem = first_elem + size * i; - - if (field->flags & VMS_ARRAY_OF_POINTER) { - curr_elem = *(void **)curr_elem; - } - if (!curr_elem && size) { - /* if null pointer check placeholder and do not follow */ - assert(field->flags & VMS_ARRAY_OF_POINTER); - ret = slirp_vmstate_info_nullptr.get(f, curr_elem, size, - NULL); - } else if (field->flags & VMS_STRUCT) { - ret = slirp_vmstate_load_state(f, field->vmsd, curr_elem, - field->vmsd->version_id); - } else if (field->flags & VMS_VSTRUCT) { - ret = slirp_vmstate_load_state(f, field->vmsd, curr_elem, - field->struct_version_id); - } else { - ret = field->info->get(f, curr_elem, size, field); - } - if (ret < 0) { - g_warning("Failed to load %s:%s", vmsd->name, field->name); - return ret; - } - } - } else if (field->flags & VMS_MUST_EXIST) { - g_warning("Input validation failed: %s/%s", vmsd->name, - field->name); - return -1; - } - field++; - } - if (vmsd->post_load) { - ret = vmsd->post_load(opaque, version_id); - } - return ret; -} diff --git a/src/network/slirp/vmstate.h b/src/network/slirp/vmstate.h deleted file mode 100644 index b1d40e892..000000000 --- a/src/network/slirp/vmstate.h +++ /dev/null @@ -1,404 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * QEMU migration/snapshot declarations - * - * Copyright (c) 2009-2011 Red Hat, Inc. - * - * Original author: Juan Quintela - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef VMSTATE_H_ -#define VMSTATE_H_ - -#ifndef _WIN32 -#include -#endif -#include -#include -#include "slirp.h" -#include "stream.h" - -#define stringify(s) tostring(s) -#define tostring(s) #s - -typedef struct VMStateInfo VMStateInfo; -typedef struct VMStateDescription VMStateDescription; -typedef struct VMStateField VMStateField; - -int slirp_vmstate_save_state(SlirpOStream *f, const VMStateDescription *vmsd, - void *opaque); -int slirp_vmstate_load_state(SlirpIStream *f, const VMStateDescription *vmsd, - void *opaque, int version_id); - -/* VMStateInfo allows customized migration of objects that don't fit in - * any category in VMStateFlags. Additional information is always passed - * into get and put in terms of field and vmdesc parameters. However - * these two parameters should only be used in cases when customized - * handling is needed, such as QTAILQ. For primitive data types such as - * integer, field and vmdesc parameters should be ignored inside get/put. - */ -struct VMStateInfo { - const char *name; - int (*get)(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field); - int (*put)(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field); -}; - -enum VMStateFlags { - /* Ignored */ - VMS_SINGLE = 0x001, - - /* The struct member at opaque + VMStateField.offset is a pointer - * to the actual field (e.g. struct a { uint8_t *b; - * }). Dereference the pointer before using it as basis for - * further pointer arithmetic (see e.g. VMS_ARRAY). Does not - * affect the meaning of VMStateField.num_offset or - * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for - * those. */ - VMS_POINTER = 0x002, - - /* The field is an array of fixed size. VMStateField.num contains - * the number of entries in the array. The size of each entry is - * given by VMStateField.size and / or opaque + - * VMStateField.size_offset; see VMS_VBUFFER and - * VMS_MULTIPLY. Each array entry will be processed individually - * (VMStateField.info.get()/put() if VMS_STRUCT is not set, - * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not - * be combined with VMS_VARRAY*. */ - VMS_ARRAY = 0x004, - - /* The field is itself a struct, containing one or more - * fields. Recurse into VMStateField.vmsd. Most useful in - * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each - * array entry. */ - VMS_STRUCT = 0x008, - - /* The field is an array of variable size. The int32_t at opaque + - * VMStateField.num_offset contains the number of entries in the - * array. See the VMS_ARRAY description regarding array handling - * in general. May not be combined with VMS_ARRAY or any other - * VMS_VARRAY*. */ - VMS_VARRAY_INT32 = 0x010, - - /* Ignored */ - VMS_BUFFER = 0x020, - - /* The field is a (fixed-size or variable-size) array of pointers - * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry - * before using it. Note: Does not imply any one of VMS_ARRAY / - * VMS_VARRAY*; these need to be set explicitly. */ - VMS_ARRAY_OF_POINTER = 0x040, - - /* The field is an array of variable size. The uint16_t at opaque - * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT16 = 0x080, - - /* The size of the individual entries (a single array entry if - * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if - * neither is set) is variable (i.e. not known at compile-time), - * but the same for all entries. Use the int32_t at opaque + - * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine - * the size of each (and every) entry. */ - VMS_VBUFFER = 0x100, - - /* Multiply the entry size given by the int32_t at opaque + - * VMStateField.size_offset (see VMS_VBUFFER description) with - * VMStateField.size to determine the number of bytes to be - * allocated. Only valid in combination with VMS_VBUFFER. */ - VMS_MULTIPLY = 0x200, - - /* The field is an array of variable size. The uint8_t at opaque + - * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT8 = 0x400, - - /* The field is an array of variable size. The uint32_t at opaque - * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT32 = 0x800, - - /* Fail loading the serialised VM state if this field is missing - * from the input. */ - VMS_MUST_EXIST = 0x1000, - - /* When loading serialised VM state, allocate memory for the - * (entire) field. Only valid in combination with - * VMS_POINTER. Note: Not all combinations with other flags are - * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't - * cause the individual entries to be allocated. */ - VMS_ALLOC = 0x2000, - - /* Multiply the number of entries given by the integer at opaque + - * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num - * to determine the number of entries in the array. Only valid in - * combination with one of VMS_VARRAY*. */ - VMS_MULTIPLY_ELEMENTS = 0x4000, - - /* A structure field that is like VMS_STRUCT, but uses - * VMStateField.struct_version_id to tell which version of the - * structure we are referencing to use. */ - VMS_VSTRUCT = 0x8000, - - /* Marker for end of list */ - VMS_END = 0x10000 -}; - -struct VMStateField { - const char *name; - size_t offset; - size_t size; - size_t start; - int num; - size_t num_offset; - size_t size_offset; - const VMStateInfo *info; - enum VMStateFlags flags; - const VMStateDescription *vmsd; - int version_id; - int struct_version_id; - bool (*field_exists)(void *opaque, int version_id); -}; - -struct VMStateDescription { - const char *name; - int version_id; - int (*pre_load)(void *opaque); - int (*post_load)(void *opaque, int version_id); - int (*pre_save)(void *opaque); - VMStateField *fields; -}; - - -extern const VMStateInfo slirp_vmstate_info_int16; -extern const VMStateInfo slirp_vmstate_info_int32; -extern const VMStateInfo slirp_vmstate_info_uint8; -extern const VMStateInfo slirp_vmstate_info_uint16; -extern const VMStateInfo slirp_vmstate_info_uint32; - -/** Put this in the stream when migrating a null pointer.*/ -#define VMS_NULLPTR_MARKER (0x30U) /* '0' */ -extern const VMStateInfo slirp_vmstate_info_nullptr; - -extern const VMStateInfo slirp_vmstate_info_buffer; -extern const VMStateInfo slirp_vmstate_info_tmp; - -#ifdef __GNUC__ -#define type_check_array(t1, t2, n) ((t1(*)[n])0 - (t2 *)0) -#define type_check_pointer(t1, t2) ((t1 **)0 - (t2 *)0) -#define typeof_field(type, field) typeof(((type *)0)->field) -#define type_check(t1, t2) ((t1 *)0 - (t2 *)0) -#else -#define type_check_array(t1, t2, n) 0 -#define type_check_pointer(t1, t2) 0 -#define typeof_field(type, field) (((type *)0)->field) -#define type_check(t1, t2) 0 -#endif - -#define vmstate_offset_value(_state, _field, _type) \ - (offsetof(_state, _field) + type_check(_type, typeof_field(_state, _field))) - -#define vmstate_offset_pointer(_state, _field, _type) \ - (offsetof(_state, _field) + \ - type_check_pointer(_type, typeof_field(_state, _field))) - -#define vmstate_offset_array(_state, _field, _type, _num) \ - (offsetof(_state, _field) + \ - type_check_array(_type, typeof_field(_state, _field), _num)) - -#define vmstate_offset_buffer(_state, _field) \ - vmstate_offset_array(_state, _field, uint8_t, \ - sizeof(typeof_field(_state, _field))) - -/* In the macros below, if there is a _version, that means the macro's - * field will be processed only if the version being received is >= - * the _version specified. In general, if you add a new field, you - * would increment the structure's version and put that version - * number into the new field so it would only be processed with the - * new version. - * - * In particular, for VMSTATE_STRUCT() and friends the _version does - * *NOT* pick the version of the sub-structure. It works just as - * specified above. The version of the top-level structure received - * is passed down to all sub-structures. This means that the - * sub-structures must have version that are compatible with all the - * structures that use them. - * - * If you want to specify the version of the sub-structure, use - * VMSTATE_VSTRUCT(), which allows the specific sub-structure version - * to be directly specified. - */ - -#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), .size = sizeof(_type), .info = &(_info), \ - .flags = VMS_SINGLE, \ - .offset = vmstate_offset_value(_state, _field, _type), \ - } - -#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), .num = (_num), \ - .info = &(_info), .size = sizeof(_type), .flags = VMS_ARRAY, \ - .offset = vmstate_offset_array(_state, _field, _type, _num), \ - } - -#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), .vmsd = &(_vmsd), .size = sizeof(_type), \ - .flags = VMS_STRUCT, \ - .offset = vmstate_offset_value(_state, _field, _type), \ - } - -#define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .vmsd = &(_vmsd), .size = sizeof(_type *), \ - .flags = VMS_STRUCT | VMS_POINTER, \ - .offset = vmstate_offset_pointer(_state, _field, _type), \ - } - -#define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, \ - _vmsd, _type) \ - { \ - .name = (stringify(_field)), .num = (_num), .field_exists = (_test), \ - .version_id = (_version), .vmsd = &(_vmsd), .size = sizeof(_type), \ - .flags = VMS_STRUCT | VMS_ARRAY, \ - .offset = vmstate_offset_array(_state, _field, _type, _num), \ - } - -#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), .size = (_size - _start), \ - .info = &slirp_vmstate_info_buffer, .flags = VMS_BUFFER, \ - .offset = vmstate_offset_buffer(_state, _field) + _start, \ - } - -#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), \ - .size_offset = vmstate_offset_value(_state, _field_size, uint32_t), \ - .info = &slirp_vmstate_info_buffer, \ - .flags = VMS_VBUFFER | VMS_POINTER, \ - .offset = offsetof(_state, _field), \ - } - -#define QEMU_BUILD_BUG_ON_STRUCT(x) \ - struct { \ - int : (x) ? -1 : 1; \ - } - -#define QEMU_BUILD_BUG_ON_ZERO(x) \ - (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - sizeof(QEMU_BUILD_BUG_ON_STRUCT(x))) - -/* Allocate a temporary of type 'tmp_type', set tmp->parent to _state - * and execute the vmsd on the temporary. Note that we're working with - * the whole of _state here, not a field within it. - * We compile time check that: - * That _tmp_type contains a 'parent' member that's a pointer to the - * '_state' type - * That the pointer is right at the start of _tmp_type. - */ -#define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) \ - { \ - .name = "tmp", \ - .size = sizeof(_tmp_type) + \ - QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \ - type_check_pointer(_state, typeof_field(_tmp_type, parent)), \ - .vmsd = &(_vmsd), .info = &slirp_vmstate_info_tmp, \ - } - -#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ - VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) - -#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ - VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) - -#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \ - VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type) - -#define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \ - VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, _vmsd, \ - _type) - -#define VMSTATE_INT16_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_int16, int16_t) -#define VMSTATE_INT32_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_int32, int32_t) - -#define VMSTATE_UINT8_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_uint8, uint8_t) -#define VMSTATE_UINT16_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_uint16, uint16_t) -#define VMSTATE_UINT32_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_uint32, uint32_t) - -#define VMSTATE_INT16(_f, _s) VMSTATE_INT16_V(_f, _s, 0) -#define VMSTATE_INT32(_f, _s) VMSTATE_INT32_V(_f, _s, 0) - -#define VMSTATE_UINT8(_f, _s) VMSTATE_UINT8_V(_f, _s, 0) -#define VMSTATE_UINT16(_f, _s) VMSTATE_UINT16_V(_f, _s, 0) -#define VMSTATE_UINT32(_f, _s) VMSTATE_UINT32_V(_f, _s, 0) - -#define VMSTATE_UINT16_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, slirp_vmstate_info_uint16, uint16_t) - -#define VMSTATE_UINT32_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, slirp_vmstate_info_uint32, uint32_t) - -#define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \ - VMSTATE_ARRAY(_f, _s, _n, _v, slirp_vmstate_info_int16, int16_t) - -#define VMSTATE_INT16_ARRAY(_f, _s, _n) VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) - -#define VMSTATE_BUFFER_V(_f, _s, _v) \ - VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) - -#define VMSTATE_BUFFER(_f, _s) VMSTATE_BUFFER_V(_f, _s, 0) - -#define VMSTATE_END_OF_LIST() \ - { \ - .flags = VMS_END, \ - } - -#endif /* VMSTATE_H_ */ diff --git a/src/nmi.c b/src/nmi.c index 4fde00765..fbe3bee19 100644 --- a/src/nmi.c +++ b/src/nmi.c @@ -7,11 +7,12 @@ #include #include <86box/io.h> #include <86box/nmi.h> +#include <86box/plat_unused.h> int nmi_mask; void -nmi_write(uint16_t port, uint8_t val, void *p) +nmi_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) { nmi_mask = val & 0x80; } diff --git a/src/nvr.c b/src/nvr.c index 4b073c48f..f403984e4 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -89,13 +89,13 @@ int nvr_is_leap(int year) { if (year % 400 == 0) - return (1); + return 1; if (year % 100 == 0) - return (0); + return 0; if (year % 4 == 0) - return (1); + return 1; - return (0); + return 0; } /* Determine the days in the current month. */ @@ -207,7 +207,7 @@ nvr_path(char *str) path_slash(temp); strcat(temp, str); - return (temp); + return temp; } /* @@ -224,13 +224,13 @@ nvr_path(char *str) int nvr_load(void) { - char *path; - FILE *fp; - uint8_t regs[NVR_MAXSIZE] = { 0 }; + const char *path; + FILE *fp; + uint8_t regs[NVR_MAXSIZE] = { 0 }; /* Make sure we have been initialized. */ if (saved_nvr == NULL) - return (0); + return 0; /* Clear out any old data. */ memset(saved_nvr->regs, 0x00, sizeof(saved_nvr->regs)); @@ -261,7 +261,7 @@ nvr_load(void) if (saved_nvr->start != NULL) saved_nvr->start(saved_nvr); - return (1); + return 1; } void @@ -279,7 +279,7 @@ nvr_save(void) /* Make sure we have been initialized. */ if (saved_nvr == NULL) - return (0); + return 0; if (saved_nvr->size != 0) { path = nvr_path(saved_nvr->fn); @@ -298,7 +298,7 @@ nvr_save(void) /* Device is clean again. */ nvr_dosave = 0; - return (1); + return 1; } void @@ -328,8 +328,12 @@ nvr_time_sync(void) void nvr_time_get(struct tm *tm) { - uint8_t dom, mon, sum, wd; - uint16_t cent, yr; + uint8_t dom; + uint8_t mon; + uint8_t sum; + uint8_t wd; + uint16_t cent; + uint16_t yr; tm->tm_sec = intclk.tm_sec; tm->tm_min = intclk.tm_min; diff --git a/src/nvr_at.c b/src/nvr_at.c index bd0bbe34e..1ba9fd2b2 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -1,1344 +1,1358 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Implement a more-or-less defacto-standard RTC/NVRAM. - * - * When IBM released the PC/AT machine, it came standard with a - * battery-backed RTC chip to keep the time of day, something - * that was optional on standard PC's with a myriad variants - * being put on the market, often on cheap multi-I/O cards. - * - * The PC/AT had an on-board DS12885-series chip ("the black - * block") which was an RTC/clock chip with onboard oscillator - * and a backup battery (hence the big size.) The chip also had - * a small amount of RAM bytes available to the user, which was - * used by IBM's ROM BIOS to store machine configuration data. - * Later versions and clones used the 12886 and/or 1288(C)7 - * series, or the MC146818 series, all with an external battery. - * Many of those batteries would create corrosion issues later - * on in mainboard life... - * - * Since then, pretty much any PC has an implementation of that - * device, which became known as the "nvr" or "cmos". - * - * NOTES Info extracted from the data sheets: - * - * * The century register at location 32h is a BCD register - * designed to automatically load the BCD value 20 as the - * year register changes from 99 to 00. The MSB of this - * register is not affected when the load of 20 occurs, - * and remains at the value written by the user. - * - * * Rate Selector (RS3:RS0) - * These four rate-selection bits select one of the 13 - * taps on the 15-stage divider or disable the divider - * output. The tap selected can be used to generate an - * output square wave (SQW pin) and/or a periodic interrupt. - * - * The user can do one of the following: - * - enable the interrupt with the PIE bit; - * - enable the SQW output pin with the SQWE bit; - * - enable both at the same time and the same rate; or - * - enable neither. - * - * Table 3 lists the periodic interrupt rates and the square - * wave frequencies that can be chosen with the RS bits. - * These four read/write bits are not affected by !RESET. - * - * * Oscillator (DV2:DV0) - * These three bits are used to turn the oscillator on or - * off and to reset the countdown chain. A pattern of 010 - * is the only combination of bits that turn the oscillator - * on and allow the RTC to keep time. A pattern of 11x - * enables the oscillator but holds the countdown chain in - * reset. The next update occurs at 500ms after a pattern - * of 010 is written to DV0, DV1, and DV2. - * - * * Update-In-Progress (UIP) - * This bit is a status flag that can be monitored. When the - * UIP bit is a 1, the update transfer occurs soon. When - * UIP is a 0, the update transfer does not occur for at - * least 244us. The time, calendar, and alarm information - * in RAM is fully available for access when the UIP bit - * is 0. The UIP bit is read-only and is not affected by - * !RESET. Writing the SET bit in Register B to a 1 - * inhibits any update transfer and clears the UIP status bit. - * - * * Daylight Saving Enable (DSE) - * This bit is a read/write bit that enables two daylight - * saving adjustments when DSE is set to 1. On the first - * Sunday in April (or the last Sunday in April in the - * MC146818A), the time increments from 1:59:59 AM to - * 3:00:00 AM. On the last Sunday in October when the time - * first reaches 1:59:59 AM, it changes to 1:00:00 AM. - * - * When DSE is enabled, the internal logic test for the - * first/last Sunday condition at midnight. If the DSE bit - * is not set when the test occurs, the daylight saving - * function does not operate correctly. These adjustments - * do not occur when the DSE bit is 0. This bit is not - * affected by internal functions or !RESET. - * - * * 24/12 - * The 24/12 control bit establishes the format of the hours - * byte. A 1 indicates the 24-hour mode and a 0 indicates - * the 12-hour mode. This bit is read/write and is not - * affected by internal functions or !RESET. - * - * * Data Mode (DM) - * This bit indicates whether time and calendar information - * is in binary or BCD format. The DM bit is set by the - * program to the appropriate format and can be read as - * required. This bit is not modified by internal functions - * or !RESET. A 1 in DM signifies binary data, while a 0 in - * DM specifies BCD data. - * - * * Square-Wave Enable (SQWE) - * When this bit is set to 1, a square-wave signal at the - * frequency set by the rate-selection bits RS3-RS0 is driven - * out on the SQW pin. When the SQWE bit is set to 0, the - * SQW pin is held low. SQWE is a read/write bit and is - * cleared by !RESET. SQWE is low if disabled, and is high - * impedance when VCC is below VPF. SQWE is cleared to 0 on - * !RESET. - * - * * Update-Ended Interrupt Enable (UIE) - * This bit is a read/write bit that enables the update-end - * flag (UF) bit in Register C to assert !IRQ. The !RESET - * pin going low or the SET bit going high clears the UIE bit. - * The internal functions of the device do not affect the UIE - * bit, but is cleared to 0 on !RESET. - * - * * Alarm Interrupt Enable (AIE) - * This bit is a read/write bit that, when set to 1, permits - * the alarm flag (AF) bit in Register C to assert !IRQ. An - * alarm interrupt occurs for each second that the three time - * bytes equal the three alarm bytes, including a don't-care - * alarm code of binary 11XXXXXX. The AF bit does not - * initiate the !IRQ signal when the AIE bit is set to 0. - * The internal functions of the device do not affect the AIE - * bit, but is cleared to 0 on !RESET. - * - * * Periodic Interrupt Enable (PIE) - * The PIE bit is a read/write bit that allows the periodic - * interrupt flag (PF) bit in Register C to drive the !IRQ pin - * low. When the PIE bit is set to 1, periodic interrupts are - * generated by driving the !IRQ pin low at a rate specified - * by the RS3-RS0 bits of Register A. A 0 in the PIE bit - * blocks the !IRQ output from being driven by a periodic - * interrupt, but the PF bit is still set at the periodic - * rate. PIE is not modified b any internal device functions, - * but is cleared to 0 on !RESET. - * - * * SET - * When the SET bit is 0, the update transfer functions - * normally by advancing the counts once per second. When - * the SET bit is written to 1, any update transfer is - * inhibited, and the program can initialize the time and - * calendar bytes without an update occurring in the midst of - * initializing. Read cycles can be executed in a similar - * manner. SET is a read/write bit and is not affected by - * !RESET or internal functions of the device. - * - * * Update-Ended Interrupt Flag (UF) - * This bit is set after each update cycle. When the UIE - * bit is set to 1, the 1 in UF causes the IRQF bit to be - * a 1, which asserts the !IRQ pin. This bit can be - * cleared by reading Register C or with a !RESET. - * - * * Alarm Interrupt Flag (AF) - * A 1 in the AF bit indicates that the current time has - * matched the alarm time. If the AIE bit is also 1, the - * !IRQ pin goes low and a 1 appears in the IRQF bit. This - * bit can be cleared by reading Register C or with a - * !RESET. - * - * * Periodic Interrupt Flag (PF) - * This bit is read-only and is set to 1 when an edge is - * detected on the selected tap of the divider chain. The - * RS3 through RS0 bits establish the periodic rate. PF is - * set to 1 independent of the state of the PIE bit. When - * both PF and PIE are 1s, the !IRQ signal is active and - * sets the IRQF bit. This bit can be cleared by reading - * Register C or with a !RESET. - * - * * Interrupt Request Flag (IRQF) - * The interrupt request flag (IRQF) is set to a 1 when one - * or more of the following are true: - * - PF == PIE == 1 - * - AF == AIE == 1 - * - UF == UIE == 1 - * Any time the IRQF bit is a 1, the !IRQ pin is driven low. - * All flag bits are cleared after Register C is read by the - * program or when the !RESET pin is low. - * - * * Valid RAM and Time (VRT) - * This bit indicates the condition of the battery connected - * to the VBAT pin. This bit is not writeable and should - * always be 1 when read. If a 0 is ever present, an - * exhausted internal lithium energy source is indicated and - * both the contents of the RTC data and RAM data are - * questionable. This bit is unaffected by !RESET. - * - * This file implements a generic version of the RTC/NVRAM chip, - * including the later update (DS12887A) which implemented a - * "century" register to be compatible with Y2K. - * - * - * - * Authors: Fred N. van Kempen, - * Miran Grca, - * Mahod, - * Sarah Walker, - * - * Copyright 2017-2020 Fred N. van Kempen. - * Copyright 2016-2020 Miran Grca. - * Copyright 2008-2020 Sarah Walker. - * - * 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 2 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, write to the: - * - * Free Software Foundation, Inc. - * 59 Temple Place - Suite 330 - * Boston, MA 02111-1307 - * USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include <86box/86box.h> -#include "cpu.h" -#include <86box/machine.h> -#include <86box/io.h> -#include <86box/mem.h> -#include <86box/nmi.h> -#include <86box/pic.h> -#include <86box/timer.h> -#include <86box/pit.h> -#include <86box/rom.h> -#include <86box/device.h> -#include <86box/nvr.h> - -/* RTC registers and bit definitions. */ -#define RTC_SECONDS 0 -#define RTC_ALSECONDS 1 -#define AL_DONTCARE 0xc0 /* Alarm time is not set */ -#define RTC_MINUTES 2 -#define RTC_ALMINUTES 3 -#define RTC_HOURS 4 -#define RTC_AMPM 0x80 /* PM flag if 12h format in use */ -#define RTC_ALHOURS 5 -#define RTC_DOW 6 -#define RTC_DOM 7 -#define RTC_MONTH 8 -#define RTC_YEAR 9 -#define RTC_REGA 10 -#define REGA_UIP 0x80 -#define REGA_DV2 0x40 -#define REGA_DV1 0x20 -#define REGA_DV0 0x10 -#define REGA_DV 0x70 -#define REGA_RS3 0x08 -#define REGA_RS2 0x04 -#define REGA_RS1 0x02 -#define REGA_RS0 0x01 -#define REGA_RS 0x0f -#define RTC_REGB 11 -#define REGB_SET 0x80 -#define REGB_PIE 0x40 -#define REGB_AIE 0x20 -#define REGB_UIE 0x10 -#define REGB_SQWE 0x08 -#define REGB_DM 0x04 -#define REGB_2412 0x02 -#define REGB_DSE 0x01 -#define RTC_REGC 12 -#define REGC_IRQF 0x80 -#define REGC_PF 0x40 -#define REGC_AF 0x20 -#define REGC_UF 0x10 -#define RTC_REGD 13 -#define REGD_VRT 0x80 -#define RTC_CENTURY_AT 0x32 /* century register for AT etc */ -#define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */ -#define RTC_CENTURY_ELT 0x1A /* century register for Epson Equity LT */ -#define RTC_ALDAY 0x7D /* VIA VT82C586B - alarm day */ -#define RTC_ALMONTH 0x7E /* VIA VT82C586B - alarm month */ -#define RTC_CENTURY_VIA 0x7F /* century register for VIA VT82C586B */ - -#define RTC_ALDAY_SIS 0x7E /* Day of Month Alarm for SiS */ -#define RTC_ALMONT_SIS 0x7F /* Month Alarm for SiS */ - -#define RTC_REGS 14 /* number of registers */ - -#define FLAG_NO_NMI 0x01 -#define FLAG_AMI_1992_HACK 0x02 -#define FLAG_AMI_1994_HACK 0x04 -#define FLAG_AMI_1995_HACK 0x08 -#define FLAG_P6RP4_HACK 0x10 -#define FLAG_PIIX4 0x20 - -typedef struct { - int8_t stat; - - uint8_t cent, def, - flags, read_addr, - wp_0d, wp_32, - pad, pad0; - - uint8_t addr[8], wp[2], - bank[8], *lock; - - int16_t count, state; - - uint64_t ecount, - rtc_time; - pc_timer_t update_timer, - rtc_timer; -} local_t; - -static uint8_t nvr_at_inited = 0; - -/* Get the current NVR time. */ -static void -time_get(nvr_t *nvr, struct tm *tm) -{ - local_t *local = (local_t *) nvr->data; - int8_t temp; - - if (nvr->regs[RTC_REGB] & REGB_DM) { - /* NVR is in Binary data mode. */ - tm->tm_sec = nvr->regs[RTC_SECONDS]; - tm->tm_min = nvr->regs[RTC_MINUTES]; - temp = nvr->regs[RTC_HOURS]; - tm->tm_wday = (nvr->regs[RTC_DOW] - 1); - tm->tm_mday = nvr->regs[RTC_DOM]; - tm->tm_mon = (nvr->regs[RTC_MONTH] - 1); - tm->tm_year = nvr->regs[RTC_YEAR]; - if (local->cent != 0xFF) - tm->tm_year += (nvr->regs[local->cent] * 100) - 1900; - } else { - /* NVR is in BCD data mode. */ - tm->tm_sec = RTC_DCB(nvr->regs[RTC_SECONDS]); - tm->tm_min = RTC_DCB(nvr->regs[RTC_MINUTES]); - temp = RTC_DCB(nvr->regs[RTC_HOURS]); - tm->tm_wday = (RTC_DCB(nvr->regs[RTC_DOW]) - 1); - tm->tm_mday = RTC_DCB(nvr->regs[RTC_DOM]); - tm->tm_mon = (RTC_DCB(nvr->regs[RTC_MONTH]) - 1); - tm->tm_year = RTC_DCB(nvr->regs[RTC_YEAR]); - if (local->cent != 0xFF) - tm->tm_year += (RTC_DCB(nvr->regs[local->cent]) * 100) - 1900; - } - - /* Adjust for 12/24 hour mode. */ - if (nvr->regs[RTC_REGB] & REGB_2412) - tm->tm_hour = temp; - else - tm->tm_hour = ((temp & ~RTC_AMPM) % 12) + ((temp & RTC_AMPM) ? 12 : 0); -} - -/* Set the current NVR time. */ -static void -time_set(nvr_t *nvr, struct tm *tm) -{ - local_t *local = (local_t *) nvr->data; - int year = (tm->tm_year + 1900); - - if (nvr->regs[RTC_REGB] & REGB_DM) { - /* NVR is in Binary data mode. */ - nvr->regs[RTC_SECONDS] = tm->tm_sec; - nvr->regs[RTC_MINUTES] = tm->tm_min; - nvr->regs[RTC_DOW] = (tm->tm_wday + 1); - nvr->regs[RTC_DOM] = tm->tm_mday; - nvr->regs[RTC_MONTH] = (tm->tm_mon + 1); - nvr->regs[RTC_YEAR] = (year % 100); - if (local->cent != 0xFF) - nvr->regs[local->cent] = (year / 100); - - if (nvr->regs[RTC_REGB] & REGB_2412) { - /* NVR is in 24h mode. */ - nvr->regs[RTC_HOURS] = tm->tm_hour; - } else { - /* NVR is in 12h mode. */ - nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) ? (tm->tm_hour % 12) : 12; - if (tm->tm_hour > 11) - nvr->regs[RTC_HOURS] |= RTC_AMPM; - } - } else { - /* NVR is in BCD data mode. */ - nvr->regs[RTC_SECONDS] = RTC_BCD(tm->tm_sec); - nvr->regs[RTC_MINUTES] = RTC_BCD(tm->tm_min); - nvr->regs[RTC_DOW] = RTC_BCD(tm->tm_wday + 1); - nvr->regs[RTC_DOM] = RTC_BCD(tm->tm_mday); - nvr->regs[RTC_MONTH] = RTC_BCD(tm->tm_mon + 1); - nvr->regs[RTC_YEAR] = RTC_BCD(year % 100); - if (local->cent != 0xFF) - nvr->regs[local->cent] = RTC_BCD(year / 100); - - if (nvr->regs[RTC_REGB] & REGB_2412) { - /* NVR is in 24h mode. */ - nvr->regs[RTC_HOURS] = RTC_BCD(tm->tm_hour); - } else { - /* NVR is in 12h mode. */ - nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) - ? RTC_BCD(tm->tm_hour % 12) - : RTC_BCD(12); - if (tm->tm_hour > 11) - nvr->regs[RTC_HOURS] |= RTC_AMPM; - } - } -} - -/* Check if the current time matches a set alarm time. */ -static int8_t -check_alarm(nvr_t *nvr, int8_t addr) -{ - return ((nvr->regs[addr + 1] == nvr->regs[addr]) || ((nvr->regs[addr + 1] & AL_DONTCARE) == AL_DONTCARE)); -} - -/* Check for VIA stuff. */ -static int8_t -check_alarm_via(nvr_t *nvr, int8_t addr, int8_t addr_2) -{ - local_t *local = (local_t *) nvr->data; - - if (local->cent == RTC_CENTURY_VIA) { - return ((nvr->regs[addr_2] == nvr->regs[addr]) || ((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE)); - } else - return 1; -} - -/* Update the NVR registers from the internal clock. */ -static void -timer_update(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - struct tm tm; - - local->ecount = 0LL; - - if (!(nvr->regs[RTC_REGB] & REGB_SET)) { - /* Get the current time from the internal clock. */ - nvr_time_get(&tm); - - /* Update registers with current time. */ - time_set(nvr, &tm); - - /* Clear update status. */ - local->stat = 0x00; - - /* Check for any alarms we need to handle. */ - if (check_alarm(nvr, RTC_SECONDS) && check_alarm(nvr, RTC_MINUTES) && check_alarm(nvr, RTC_HOURS) && check_alarm_via(nvr, RTC_DOM, RTC_ALDAY) && check_alarm_via(nvr, RTC_MONTH, RTC_ALMONTH) /* && - check_alarm_via(nvr, RTC_DOM, RTC_ALDAY_SIS) && - check_alarm_via(nvr, RTC_MONTH, RTC_ALMONT_SIS)*/ - ) { - nvr->regs[RTC_REGC] |= REGC_AF; - if (nvr->regs[RTC_REGB] & REGB_AIE) { - /* Generate an interrupt. */ - if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - } - } - - /* - * The flag and interrupt should be issued - * on update ended, not started. - */ - nvr->regs[RTC_REGC] |= REGC_UF; - if (nvr->regs[RTC_REGB] & REGB_UIE) { - /* Generate an interrupt. */ - if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - } - } -} - -static void -timer_load_count(nvr_t *nvr) -{ - int c = nvr->regs[RTC_REGA] & REGA_RS; - local_t *local = (local_t *) nvr->data; - - timer_disable(&local->rtc_timer); - - if ((nvr->regs[RTC_REGA] & 0x70) != 0x20) { - local->state = 0; - return; - } - - local->state = 1; - - switch (c) { - case 0: - local->state = 0; - break; - case 1: - case 2: - local->count = 1 << (c + 6); - timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); - break; - default: - local->count = 1 << (c - 1); - timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); - break; - } -} - -static void -timer_intr(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - - if (local->state == 1) { - timer_load_count(nvr); - - nvr->regs[RTC_REGC] |= REGC_PF; - if (nvr->regs[RTC_REGB] & REGB_PIE) { - /* Generate an interrupt. */ - if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - } - } -} - -/* Callback from internal clock, another second passed. */ -static void -timer_tick(nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - /* Only update it there is no SET in progress. */ - if (!(nvr->regs[RTC_REGB] & REGB_SET)) { - /* Set the UIP bit, announcing the update. */ - local->stat = REGA_UIP; - - rtc_tick(); - - /* Schedule the actual update. */ - local->ecount = (244ULL + 1984ULL) * TIMER_USEC; - timer_set_delay_u64(&local->update_timer, local->ecount); - } -} - -static void -nvr_reg_common_write(uint16_t reg, uint8_t val, nvr_t *nvr, local_t *local) -{ - if ((reg == 0x2c) && (local->flags & FLAG_AMI_1994_HACK)) - nvr->is_new = 0; - if ((reg == 0x2d) && (local->flags & FLAG_AMI_1992_HACK)) - nvr->is_new = 0; - if ((reg == 0x52) && (local->flags & FLAG_AMI_1995_HACK)) - nvr->is_new = 0; - if ((reg >= 0x38) && (reg <= 0x3f) && local->wp[0]) - return; - if ((reg >= 0xb8) && (reg <= 0xbf) && local->wp[1]) - return; - if (local->lock[reg]) - return; - if (nvr->regs[reg] != val) { - nvr->regs[reg] = val; - nvr_dosave = 1; - } -} - -/* This must be exposed because ACPI uses it. */ -void -nvr_reg_write(uint16_t reg, uint8_t val, void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - struct tm tm; - uint8_t old; - uint8_t irq = 0, old_irq = 0; - - old = nvr->regs[reg]; - switch (reg) { - case RTC_REGA: - nvr->regs[RTC_REGA] = val; - timer_load_count(nvr); - break; - - case RTC_REGB: - old_irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; - nvr->regs[RTC_REGB] = val; - if (((old ^ val) & REGB_SET) && (val & REGB_SET)) { - /* According to the datasheet... */ - nvr->regs[RTC_REGA] &= ~REGA_UIP; - nvr->regs[RTC_REGB] &= ~REGB_UIE; - } - irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; - if (old_irq && !irq) { - picintc(1 << nvr->irq); - nvr->regs[RTC_REGC] &= ~REGC_IRQF; - } else if (!old_irq && irq) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - break; - - case RTC_REGC: /* R/O */ - break; - - case RTC_REGD: /* R/O */ - /* This is needed for VIA, where writing to this register changes a write-only - bit whose value is read from power management register 42. */ - nvr->regs[RTC_REGD] = val & 0x80; - break; - - case 0x32: - if ((reg == 0x32) && (local->cent == RTC_CENTURY_VIA) && local->wp_32) - break; - nvr_reg_common_write(reg, val, nvr, local); - break; - - default: /* non-RTC registers are just NVRAM */ - nvr_reg_common_write(reg, val, nvr, local); - break; - } - - if ((reg < RTC_REGA) || ((local->cent != 0xff) && (reg == local->cent))) { - if ((reg != 1) && (reg != 3) && (reg != 5)) { - if ((old != val) && !(time_sync & TIME_SYNC_ENABLED)) { - /* Update internal clock. */ - time_get(nvr, &tm); - nvr_time_set(&tm); - nvr_dosave = 1; - } - } - } -} - -/* Write to one of the NVR registers. */ -static void -nvr_write(uint16_t addr, uint8_t val, void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - uint8_t addr_id = (addr & 0x0e) >> 1; - - cycles -= ISA_CYCLES(8); - - if (local->bank[addr_id] == 0xff) - return; - - if (addr & 1) { - // if (local->bank[addr_id] == 0xff) - // return; - nvr_reg_write(local->addr[addr_id], val, priv); - } else { - local->addr[addr_id] = (val & (nvr->size - 1)); - /* Some chipsets use a 256 byte NVRAM but ports 70h and 71h always access only 128 bytes. */ - if (addr_id == 0x0) - local->addr[addr_id] &= 0x7f; - else if ((addr_id == 0x1) && (local->flags & FLAG_PIIX4)) - local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | 0x80; - if (local->bank[addr_id] > 0) - local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | (0x80 * local->bank[addr_id]); - if (!(local->flags & FLAG_NO_NMI)) - nmi_mask = (~val & 0x80); - } -} - -/* Read from one of the NVR registers. */ -static uint8_t -nvr_read(uint16_t addr, void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - uint8_t ret; - uint8_t addr_id = (addr & 0x0e) >> 1; - uint16_t i, checksum = 0x0000; - - cycles -= ISA_CYCLES(8); - - if (local->bank[addr_id] == 0xff) - ret = 0xff; - else if (addr & 1) - switch (local->addr[addr_id]) { - case RTC_REGA: - ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat; - break; - - case RTC_REGC: - ret = nvr->regs[RTC_REGC]; - picintc(1 << nvr->irq); - nvr->regs[RTC_REGC] = 0x00; - break; - - case RTC_REGD: - /* Bits 6-0 of this register always read 0. Bit 7 is battery state, - we should always return it set, as that means the battery is OK. */ - ret = REGD_VRT; - break; - - case 0x2c: - if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) - ret = nvr->regs[local->addr[addr_id]] & 0x7f; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x2d: - if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) - ret = nvr->regs[local->addr[addr_id]] & 0xf7; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x2e: - case 0x2f: - if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) { - for (i = 0x10; i <= 0x2d; i++) { - if (i == 0x2d) - checksum += (nvr->regs[i] & 0xf7); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x2e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) { - for (i = 0x10; i <= 0x2d; i++) { - if (i == 0x2c) - checksum += (nvr->regs[i] & 0x7f); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x2e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x3e: - case 0x3f: - if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) { - /* The checksum at 3E-3F is for 37-3D and 40-7F. */ - for (i = 0x37; i <= 0x3d; i++) - checksum += nvr->regs[i]; - for (i = 0x40; i <= 0x7f; i++) { - if (i == 0x52) - checksum += (nvr->regs[i] & 0xf3); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x3e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) { - /* The checksum at 3E-3F is for 37-3D and 40-51. */ - for (i = 0x37; i <= 0x3d; i++) - checksum += nvr->regs[i]; - for (i = 0x40; i <= 0x51; i++) { - if (i == 0x43) - checksum += (nvr->regs[i] | 0x02); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x3e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x43: - if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) - ret = nvr->regs[local->addr[addr_id]] | 0x02; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x52: - if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) - ret = nvr->regs[local->addr[addr_id]] & 0xf3; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - default: - ret = nvr->regs[local->addr[addr_id]]; - break; - } - else { - ret = local->addr[addr_id]; - if (!local->read_addr) - ret &= 0x80; - if (alt_access) - ret = (ret & 0x7f) | (nmi_mask ? 0x00 : 0x80); - } - - return (ret); -} - -/* Secondary NVR write - used by SMC. */ -static void -nvr_sec_write(uint16_t addr, uint8_t val, void *priv) -{ - nvr_write(0x72 + (addr & 1), val, priv); -} - -/* Secondary NVR read - used by SMC. */ -static uint8_t -nvr_sec_read(uint16_t addr, void *priv) -{ - return nvr_read(0x72 + (addr & 1), priv); -} - -/* Reset the RTC state to 1980/01/01 00:00. */ -static void -nvr_reset(nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - /* memset(nvr->regs, local->def, RTC_REGS); */ - memset(nvr->regs, local->def, nvr->size); - nvr->regs[RTC_DOM] = 1; - nvr->regs[RTC_MONTH] = 1; - nvr->regs[RTC_YEAR] = RTC_BCD(80); - if (local->cent != 0xFF) - nvr->regs[local->cent] = RTC_BCD(19); - - nvr->regs[RTC_REGD] = REGD_VRT; -} - -/* Process after loading from file. */ -static void -nvr_start(nvr_t *nvr) -{ - int i; - local_t *local = (local_t *) nvr->data; - - struct tm tm; - int default_found = 0; - - for (i = 0; i < nvr->size; i++) { - if (nvr->regs[i] == local->def) - default_found++; - } - - if (default_found == nvr->size) - nvr->regs[0x0e] = 0xff; /* If load failed or it loaded an uninitialized NVR, - mark everything as bad. */ - - /* Initialize the internal and chip times. */ - if (time_sync & TIME_SYNC_ENABLED) { - /* Use the internal clock's time. */ - nvr_time_get(&tm); - time_set(nvr, &tm); - } else { - /* Set the internal clock from the chip time. */ - time_get(nvr, &tm); - nvr_time_set(&tm); - } - - /* Start the RTC. */ - nvr->regs[RTC_REGA] = (REGA_RS2 | REGA_RS1); - nvr->regs[RTC_REGB] = REGB_2412; -} - -static void -nvr_at_speed_changed(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - - timer_load_count(nvr); - - timer_disable(&local->update_timer); - if (local->ecount > 0ULL) - timer_set_delay_u64(&local->update_timer, local->ecount); - - timer_disable(&nvr->onesec_time); - timer_set_delay_u64(&nvr->onesec_time, (10000ULL * TIMER_USEC)); -} - -void -nvr_at_handler(int set, uint16_t base, nvr_t *nvr) -{ - io_handler(set, base, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); -} - -void -nvr_at_index_read_handler(int set, uint16_t base, nvr_t *nvr) -{ - io_handler(0, base, 1, - NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); - nvr_at_handler(0, base, nvr); - - if (set) - nvr_at_handler(1, base, nvr); - else { - io_handler(1, base, 1, - NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); - io_handler(1, base + 1, 1, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } -} - -void -nvr_at_sec_handler(int set, uint16_t base, nvr_t *nvr) -{ - io_handler(set, base, 2, - nvr_sec_read, NULL, NULL, nvr_sec_write, NULL, NULL, nvr); -} - -void -nvr_read_addr_set(int set, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - local->read_addr = set; -} - -void -nvr_wp_set(int set, int h, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - local->wp[h] = set; -} - -void -nvr_via_wp_set(int set, int reg, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - if (reg == 0x0d) - local->wp_0d = set; - else - local->wp_32 = set; -} - -void -nvr_bank_set(int base, uint8_t bank, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - local->bank[base] = bank; -} - -void -nvr_lock_set(int base, int size, int lock, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - int i; - - for (i = 0; i < size; i++) - local->lock[base + i] = lock; -} - -void -nvr_irq_set(int irq, nvr_t *nvr) -{ - nvr->irq = irq; -} - -static void -nvr_at_reset(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - - /* These bits are reset on reset. */ - nvr->regs[RTC_REGB] &= ~(REGB_PIE | REGB_AIE | REGB_UIE | REGB_SQWE); - nvr->regs[RTC_REGC] &= ~(REGC_PF | REGC_AF | REGC_UF | REGC_IRQF); -} - -static void * -nvr_at_init(const device_t *info) -{ - local_t *local; - nvr_t *nvr; - - /* Allocate an NVR for this machine. */ - nvr = (nvr_t *) malloc(sizeof(nvr_t)); - if (nvr == NULL) - return (NULL); - memset(nvr, 0x00, sizeof(nvr_t)); - - local = (local_t *) malloc(sizeof(local_t)); - memset(local, 0x00, sizeof(local_t)); - nvr->data = local; - - /* This is machine specific. */ - nvr->size = machines[machine].nvrmask + 1; - local->lock = (uint8_t *) malloc(nvr->size); - memset(local->lock, 0x00, nvr->size); - local->def = 0xff /*0x00*/; - local->flags = 0x00; - switch (info->local & 0x0f) { - case 0: /* standard AT, no century register */ - if (info->local == 32) { - local->flags |= FLAG_P6RP4_HACK; - nvr->irq = 8; - local->cent = RTC_CENTURY_AT; - } else { - nvr->irq = 8; - local->cent = 0xff; - } - break; - - case 1: /* standard AT */ - case 5: /* AMI WinBIOS 1994 */ - case 6: /* AMI BIOS 1995 */ - if ((info->local & 0x1f) == 0x11) - local->flags |= FLAG_PIIX4; - else { - local->def = 0x00; - if ((info->local & 0x1f) == 0x15) - local->flags |= FLAG_AMI_1994_HACK; - else if ((info->local & 0x1f) == 0x16) - local->flags |= FLAG_AMI_1995_HACK; - else - local->def = 0xff; - } - nvr->irq = 8; - local->cent = RTC_CENTURY_AT; - break; - - case 2: /* PS/1 or PS/2 */ - nvr->irq = 8; - local->cent = RTC_CENTURY_PS; - local->def = 0x00; - if (info->local & 0x10) - local->flags |= FLAG_NO_NMI; - break; - - case 3: /* Amstrad PC's */ - nvr->irq = 1; - local->cent = RTC_CENTURY_AT; - local->def = 0xff; - if (info->local & 0x10) - local->flags |= FLAG_NO_NMI; - break; - - case 4: /* IBM AT */ - if (info->local & 0x10) { - local->def = 0x00; - local->flags |= FLAG_AMI_1992_HACK; - } else if (info->local == 36) - local->def = 0x00; - else - local->def = 0xff; - nvr->irq = 8; - local->cent = RTC_CENTURY_AT; - break; - - case 7: /* VIA VT82C586B */ - nvr->irq = 8; - local->cent = RTC_CENTURY_VIA; - break; - case 8: /* Epson Equity LT */ - nvr->irq = -1; - local->cent = RTC_CENTURY_ELT; - break; - } - - local->read_addr = 1; - - /* Set up any local handlers here. */ - nvr->reset = nvr_reset; - nvr->start = nvr_start; - nvr->tick = timer_tick; - - /* Initialize the generic NVR. */ - nvr_init(nvr); - - if (nvr_at_inited == 0) { - /* Start the timers. */ - timer_add(&local->update_timer, timer_update, nvr, 0); - - timer_add(&local->rtc_timer, timer_intr, nvr, 0); - /* On power on, if the oscillator is disabled, it's reenabled. */ - if ((nvr->regs[RTC_REGA] & 0x70) == 0x00) - nvr->regs[RTC_REGA] = (nvr->regs[RTC_REGA] & 0x8f) | 0x20; - nvr_at_reset(nvr); - timer_load_count(nvr); - - /* Set up the I/O handler for this device. */ - if (info->local == 8) { - io_sethandler(0x11b4, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } else { - io_sethandler(0x0070, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } - if (((info->local & 0x1f) == 0x11) || ((info->local & 0x1f) == 0x17)) { - io_sethandler(0x0072, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } - - nvr_at_inited = 1; - } - - return (nvr); -} - -static void -nvr_at_close(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - - nvr_close(); - - timer_disable(&local->rtc_timer); - timer_disable(&local->update_timer); - timer_disable(&nvr->onesec_time); - - if (nvr != NULL) { - if (nvr->fn != NULL) - free(nvr->fn); - - if (nvr->data != NULL) - free(nvr->data); - - free(nvr); - } - - if (nvr_at_inited == 1) - nvr_at_inited = 0; -} - -const device_t at_nvr_old_device = { - .name = "PC/AT NVRAM (No century)", - .internal_name = "at_nvr_old", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t at_nvr_device = { - .name = "PC/AT NVRAM", - .internal_name = "at_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 1, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ps_nvr_device = { - .name = "PS/1 or PS/2 NVRAM", - .internal_name = "ps_nvr", - .flags = DEVICE_PS2, - .local = 2, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t amstrad_nvr_device = { - .name = "Amstrad NVRAM", - .internal_name = "amstrad_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 3, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ibmat_nvr_device = { - .name = "IBM AT NVRAM", - .internal_name = "ibmat_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 4, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t piix4_nvr_device = { - .name = "Intel PIIX4 PC/AT NVRAM", - .internal_name = "piix4_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 1, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ps_no_nmi_nvr_device = { - .name = "PS/1 or PS/2 NVRAM (No NMI)", - .internal_name = "ps1_nvr", - .flags = DEVICE_PS2, - .local = 0x10 | 2, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t amstrad_no_nmi_nvr_device = { - .name = "Amstrad NVRAM (No NMI)", - .internal_name = "amstrad_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 3, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ami_1992_nvr_device = { - .name = "AMI Color 1992 PC/AT NVRAM", - .internal_name = "ami_1992_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 4, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ami_1994_nvr_device = { - .name = "AMI WinBIOS 1994 PC/AT NVRAM", - .internal_name = "ami_1994_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 5, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ami_1995_nvr_device = { - .name = "AMI WinBIOS 1995 PC/AT NVRAM", - .internal_name = "ami_1995_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 6, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t via_nvr_device = { - .name = "VIA PC/AT NVRAM", - .internal_name = "via_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 7, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t p6rp4_nvr_device = { - .name = "ASUS P/I-P6RP4 PC/AT NVRAM", - .internal_name = "p6rp4_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 32, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t amstrad_megapc_nvr_device = { - .name = "Amstrad MegaPC NVRAM", - .internal_name = "amstrad_megapc_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 36, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t elt_nvr_device = { - .name = "Epson Equity LT NVRAM", - .internal_name = "elt_nvr", - .flags = DEVICE_ISA, - .local = 8, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Implement a more-or-less defacto-standard RTC/NVRAM. + * + * When IBM released the PC/AT machine, it came standard with a + * battery-backed RTC chip to keep the time of day, something + * that was optional on standard PC's with a myriad variants + * being put on the market, often on cheap multi-I/O cards. + * + * The PC/AT had an on-board DS12885-series chip ("the black + * block") which was an RTC/clock chip with onboard oscillator + * and a backup battery (hence the big size.) The chip also had + * a small amount of RAM bytes available to the user, which was + * used by IBM's ROM BIOS to store machine configuration data. + * Later versions and clones used the 12886 and/or 1288(C)7 + * series, or the MC146818 series, all with an external battery. + * Many of those batteries would create corrosion issues later + * on in mainboard life... + * + * Since then, pretty much any PC has an implementation of that + * device, which became known as the "nvr" or "cmos". + * + * NOTES Info extracted from the data sheets: + * + * * The century register at location 32h is a BCD register + * designed to automatically load the BCD value 20 as the + * year register changes from 99 to 00. The MSB of this + * register is not affected when the load of 20 occurs, + * and remains at the value written by the user. + * + * * Rate Selector (RS3:RS0) + * These four rate-selection bits select one of the 13 + * taps on the 15-stage divider or disable the divider + * output. The tap selected can be used to generate an + * output square wave (SQW pin) and/or a periodic interrupt. + * + * The user can do one of the following: + * - enable the interrupt with the PIE bit; + * - enable the SQW output pin with the SQWE bit; + * - enable both at the same time and the same rate; or + * - enable neither. + * + * Table 3 lists the periodic interrupt rates and the square + * wave frequencies that can be chosen with the RS bits. + * These four read/write bits are not affected by !RESET. + * + * * Oscillator (DV2:DV0) + * These three bits are used to turn the oscillator on or + * off and to reset the countdown chain. A pattern of 010 + * is the only combination of bits that turn the oscillator + * on and allow the RTC to keep time. A pattern of 11x + * enables the oscillator but holds the countdown chain in + * reset. The next update occurs at 500ms after a pattern + * of 010 is written to DV0, DV1, and DV2. + * + * * Update-In-Progress (UIP) + * This bit is a status flag that can be monitored. When the + * UIP bit is a 1, the update transfer occurs soon. When + * UIP is a 0, the update transfer does not occur for at + * least 244us. The time, calendar, and alarm information + * in RAM is fully available for access when the UIP bit + * is 0. The UIP bit is read-only and is not affected by + * !RESET. Writing the SET bit in Register B to a 1 + * inhibits any update transfer and clears the UIP status bit. + * + * * Daylight Saving Enable (DSE) + * This bit is a read/write bit that enables two daylight + * saving adjustments when DSE is set to 1. On the first + * Sunday in April (or the last Sunday in April in the + * MC146818A), the time increments from 1:59:59 AM to + * 3:00:00 AM. On the last Sunday in October when the time + * first reaches 1:59:59 AM, it changes to 1:00:00 AM. + * + * When DSE is enabled, the internal logic test for the + * first/last Sunday condition at midnight. If the DSE bit + * is not set when the test occurs, the daylight saving + * function does not operate correctly. These adjustments + * do not occur when the DSE bit is 0. This bit is not + * affected by internal functions or !RESET. + * + * * 24/12 + * The 24/12 control bit establishes the format of the hours + * byte. A 1 indicates the 24-hour mode and a 0 indicates + * the 12-hour mode. This bit is read/write and is not + * affected by internal functions or !RESET. + * + * * Data Mode (DM) + * This bit indicates whether time and calendar information + * is in binary or BCD format. The DM bit is set by the + * program to the appropriate format and can be read as + * required. This bit is not modified by internal functions + * or !RESET. A 1 in DM signifies binary data, while a 0 in + * DM specifies BCD data. + * + * * Square-Wave Enable (SQWE) + * When this bit is set to 1, a square-wave signal at the + * frequency set by the rate-selection bits RS3-RS0 is driven + * out on the SQW pin. When the SQWE bit is set to 0, the + * SQW pin is held low. SQWE is a read/write bit and is + * cleared by !RESET. SQWE is low if disabled, and is high + * impedance when VCC is below VPF. SQWE is cleared to 0 on + * !RESET. + * + * * Update-Ended Interrupt Enable (UIE) + * This bit is a read/write bit that enables the update-end + * flag (UF) bit in Register C to assert !IRQ. The !RESET + * pin going low or the SET bit going high clears the UIE bit. + * The internal functions of the device do not affect the UIE + * bit, but is cleared to 0 on !RESET. + * + * * Alarm Interrupt Enable (AIE) + * This bit is a read/write bit that, when set to 1, permits + * the alarm flag (AF) bit in Register C to assert !IRQ. An + * alarm interrupt occurs for each second that the three time + * bytes equal the three alarm bytes, including a don't-care + * alarm code of binary 11XXXXXX. The AF bit does not + * initiate the !IRQ signal when the AIE bit is set to 0. + * The internal functions of the device do not affect the AIE + * bit, but is cleared to 0 on !RESET. + * + * * Periodic Interrupt Enable (PIE) + * The PIE bit is a read/write bit that allows the periodic + * interrupt flag (PF) bit in Register C to drive the !IRQ pin + * low. When the PIE bit is set to 1, periodic interrupts are + * generated by driving the !IRQ pin low at a rate specified + * by the RS3-RS0 bits of Register A. A 0 in the PIE bit + * blocks the !IRQ output from being driven by a periodic + * interrupt, but the PF bit is still set at the periodic + * rate. PIE is not modified b any internal device functions, + * but is cleared to 0 on !RESET. + * + * * SET + * When the SET bit is 0, the update transfer functions + * normally by advancing the counts once per second. When + * the SET bit is written to 1, any update transfer is + * inhibited, and the program can initialize the time and + * calendar bytes without an update occurring in the midst of + * initializing. Read cycles can be executed in a similar + * manner. SET is a read/write bit and is not affected by + * !RESET or internal functions of the device. + * + * * Update-Ended Interrupt Flag (UF) + * This bit is set after each update cycle. When the UIE + * bit is set to 1, the 1 in UF causes the IRQF bit to be + * a 1, which asserts the !IRQ pin. This bit can be + * cleared by reading Register C or with a !RESET. + * + * * Alarm Interrupt Flag (AF) + * A 1 in the AF bit indicates that the current time has + * matched the alarm time. If the AIE bit is also 1, the + * !IRQ pin goes low and a 1 appears in the IRQF bit. This + * bit can be cleared by reading Register C or with a + * !RESET. + * + * * Periodic Interrupt Flag (PF) + * This bit is read-only and is set to 1 when an edge is + * detected on the selected tap of the divider chain. The + * RS3 through RS0 bits establish the periodic rate. PF is + * set to 1 independent of the state of the PIE bit. When + * both PF and PIE are 1s, the !IRQ signal is active and + * sets the IRQF bit. This bit can be cleared by reading + * Register C or with a !RESET. + * + * * Interrupt Request Flag (IRQF) + * The interrupt request flag (IRQF) is set to a 1 when one + * or more of the following are true: + * - PF == PIE == 1 + * - AF == AIE == 1 + * - UF == UIE == 1 + * Any time the IRQF bit is a 1, the !IRQ pin is driven low. + * All flag bits are cleared after Register C is read by the + * program or when the !RESET pin is low. + * + * * Valid RAM and Time (VRT) + * This bit indicates the condition of the battery connected + * to the VBAT pin. This bit is not writeable and should + * always be 1 when read. If a 0 is ever present, an + * exhausted internal lithium energy source is indicated and + * both the contents of the RTC data and RAM data are + * questionable. This bit is unaffected by !RESET. + * + * This file implements a generic version of the RTC/NVRAM chip, + * including the later update (DS12887A) which implemented a + * "century" register to be compatible with Y2K. + * + * + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * Mahod, + * Sarah Walker, + * + * Copyright 2017-2020 Fred N. van Kempen. + * Copyright 2016-2020 Miran Grca. + * Copyright 2008-2020 Sarah Walker. + * + * 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 2 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, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include "cpu.h" +#include <86box/machine.h> +#include <86box/io.h> +#include <86box/mem.h> +#include <86box/nmi.h> +#include <86box/pic.h> +#include <86box/timer.h> +#include <86box/pit.h> +#include <86box/rom.h> +#include <86box/device.h> +#include <86box/nvr.h> + +/* RTC registers and bit definitions. */ +#define RTC_SECONDS 0 +#define RTC_ALSECONDS 1 +#define AL_DONTCARE 0xc0 /* Alarm time is not set */ +#define RTC_MINUTES 2 +#define RTC_ALMINUTES 3 +#define RTC_HOURS 4 +#define RTC_AMPM 0x80 /* PM flag if 12h format in use */ +#define RTC_ALHOURS 5 +#define RTC_DOW 6 +#define RTC_DOM 7 +#define RTC_MONTH 8 +#define RTC_YEAR 9 +#define RTC_REGA 10 +#define REGA_UIP 0x80 +#define REGA_DV2 0x40 +#define REGA_DV1 0x20 +#define REGA_DV0 0x10 +#define REGA_DV 0x70 +#define REGA_RS3 0x08 +#define REGA_RS2 0x04 +#define REGA_RS1 0x02 +#define REGA_RS0 0x01 +#define REGA_RS 0x0f +#define RTC_REGB 11 +#define REGB_SET 0x80 +#define REGB_PIE 0x40 +#define REGB_AIE 0x20 +#define REGB_UIE 0x10 +#define REGB_SQWE 0x08 +#define REGB_DM 0x04 +#define REGB_2412 0x02 +#define REGB_DSE 0x01 +#define RTC_REGC 12 +#define REGC_IRQF 0x80 +#define REGC_PF 0x40 +#define REGC_AF 0x20 +#define REGC_UF 0x10 +#define RTC_REGD 13 +#define REGD_VRT 0x80 +#define RTC_CENTURY_AT 0x32 /* century register for AT etc */ +#define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */ +#define RTC_CENTURY_ELT 0x1A /* century register for Epson Equity LT */ +#define RTC_ALDAY 0x7D /* VIA VT82C586B - alarm day */ +#define RTC_ALMONTH 0x7E /* VIA VT82C586B - alarm month */ +#define RTC_CENTURY_VIA 0x7F /* century register for VIA VT82C586B */ + +#define RTC_ALDAY_SIS 0x7E /* Day of Month Alarm for SiS */ +#define RTC_ALMONT_SIS 0x7F /* Month Alarm for SiS */ + +#define RTC_REGS 14 /* number of registers */ + +#define FLAG_NO_NMI 0x01 +#define FLAG_AMI_1992_HACK 0x02 +#define FLAG_AMI_1994_HACK 0x04 +#define FLAG_AMI_1995_HACK 0x08 +#define FLAG_P6RP4_HACK 0x10 +#define FLAG_PIIX4 0x20 + +typedef struct local_t { + int8_t stat; + + uint8_t cent; + uint8_t def; + uint8_t flags; + uint8_t read_addr; + uint8_t wp_0d; + uint8_t wp_32; + uint8_t pad; + uint8_t pad0; + + uint8_t addr[8]; + uint8_t wp[2]; + uint8_t bank[8]; + uint8_t *lock; + + int16_t count; + int16_t state; + + uint64_t ecount; + uint64_t rtc_time; + pc_timer_t update_timer; + pc_timer_t rtc_timer; +} local_t; + +static uint8_t nvr_at_inited = 0; + +/* Get the current NVR time. */ +static void +time_get(nvr_t *nvr, struct tm *tm) +{ + const local_t *local = (local_t *) nvr->data; + int8_t temp; + + if (nvr->regs[RTC_REGB] & REGB_DM) { + /* NVR is in Binary data mode. */ + tm->tm_sec = nvr->regs[RTC_SECONDS]; + tm->tm_min = nvr->regs[RTC_MINUTES]; + temp = nvr->regs[RTC_HOURS]; + tm->tm_wday = (nvr->regs[RTC_DOW] - 1); + tm->tm_mday = nvr->regs[RTC_DOM]; + tm->tm_mon = (nvr->regs[RTC_MONTH] - 1); + tm->tm_year = nvr->regs[RTC_YEAR]; + if (local->cent != 0xFF) + tm->tm_year += (nvr->regs[local->cent] * 100) - 1900; + } else { + /* NVR is in BCD data mode. */ + tm->tm_sec = RTC_DCB(nvr->regs[RTC_SECONDS]); + tm->tm_min = RTC_DCB(nvr->regs[RTC_MINUTES]); + temp = RTC_DCB(nvr->regs[RTC_HOURS]); + tm->tm_wday = (RTC_DCB(nvr->regs[RTC_DOW]) - 1); + tm->tm_mday = RTC_DCB(nvr->regs[RTC_DOM]); + tm->tm_mon = (RTC_DCB(nvr->regs[RTC_MONTH]) - 1); + tm->tm_year = RTC_DCB(nvr->regs[RTC_YEAR]); + if (local->cent != 0xFF) + tm->tm_year += (RTC_DCB(nvr->regs[local->cent]) * 100) - 1900; + } + + /* Adjust for 12/24 hour mode. */ + if (nvr->regs[RTC_REGB] & REGB_2412) + tm->tm_hour = temp; + else + tm->tm_hour = ((temp & ~RTC_AMPM) % 12) + ((temp & RTC_AMPM) ? 12 : 0); +} + +/* Set the current NVR time. */ +static void +time_set(nvr_t *nvr, struct tm *tm) +{ + const local_t *local = (local_t *) nvr->data; + int year = (tm->tm_year + 1900); + + if (nvr->regs[RTC_REGB] & REGB_DM) { + /* NVR is in Binary data mode. */ + nvr->regs[RTC_SECONDS] = tm->tm_sec; + nvr->regs[RTC_MINUTES] = tm->tm_min; + nvr->regs[RTC_DOW] = (tm->tm_wday + 1); + nvr->regs[RTC_DOM] = tm->tm_mday; + nvr->regs[RTC_MONTH] = (tm->tm_mon + 1); + nvr->regs[RTC_YEAR] = (year % 100); + if (local->cent != 0xFF) + nvr->regs[local->cent] = (year / 100); + + if (nvr->regs[RTC_REGB] & REGB_2412) { + /* NVR is in 24h mode. */ + nvr->regs[RTC_HOURS] = tm->tm_hour; + } else { + /* NVR is in 12h mode. */ + nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) ? (tm->tm_hour % 12) : 12; + if (tm->tm_hour > 11) + nvr->regs[RTC_HOURS] |= RTC_AMPM; + } + } else { + /* NVR is in BCD data mode. */ + nvr->regs[RTC_SECONDS] = RTC_BCD(tm->tm_sec); + nvr->regs[RTC_MINUTES] = RTC_BCD(tm->tm_min); + nvr->regs[RTC_DOW] = RTC_BCD(tm->tm_wday + 1); + nvr->regs[RTC_DOM] = RTC_BCD(tm->tm_mday); + nvr->regs[RTC_MONTH] = RTC_BCD(tm->tm_mon + 1); + nvr->regs[RTC_YEAR] = RTC_BCD(year % 100); + if (local->cent != 0xFF) + nvr->regs[local->cent] = RTC_BCD(year / 100); + + if (nvr->regs[RTC_REGB] & REGB_2412) { + /* NVR is in 24h mode. */ + nvr->regs[RTC_HOURS] = RTC_BCD(tm->tm_hour); + } else { + /* NVR is in 12h mode. */ + nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) + ? RTC_BCD(tm->tm_hour % 12) + : RTC_BCD(12); + if (tm->tm_hour > 11) + nvr->regs[RTC_HOURS] |= RTC_AMPM; + } + } +} + +/* Check if the current time matches a set alarm time. */ +static int8_t +check_alarm(nvr_t *nvr, int8_t addr) +{ + return ((nvr->regs[addr + 1] == nvr->regs[addr]) || ((nvr->regs[addr + 1] & AL_DONTCARE) == AL_DONTCARE)); +} + +/* Check for VIA stuff. */ +static int8_t +check_alarm_via(nvr_t *nvr, int8_t addr, int8_t addr_2) +{ + const local_t *local = (local_t *) nvr->data; + + if (local->cent == RTC_CENTURY_VIA) { + return ((nvr->regs[addr_2] == nvr->regs[addr]) || ((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE)); + } else + return 1; +} + +/* Update the NVR registers from the internal clock. */ +static void +timer_update(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + struct tm tm; + + local->ecount = 0LL; + + if (!(nvr->regs[RTC_REGB] & REGB_SET)) { + /* Get the current time from the internal clock. */ + nvr_time_get(&tm); + + /* Update registers with current time. */ + time_set(nvr, &tm); + + /* Clear update status. */ + local->stat = 0x00; + + /* Check for any alarms we need to handle. */ + if (check_alarm(nvr, RTC_SECONDS) && check_alarm(nvr, RTC_MINUTES) && check_alarm(nvr, RTC_HOURS) && check_alarm_via(nvr, RTC_DOM, RTC_ALDAY) && check_alarm_via(nvr, RTC_MONTH, RTC_ALMONTH) /* && + check_alarm_via(nvr, RTC_DOM, RTC_ALDAY_SIS) && + check_alarm_via(nvr, RTC_MONTH, RTC_ALMONT_SIS)*/ + ) { + nvr->regs[RTC_REGC] |= REGC_AF; + if (nvr->regs[RTC_REGB] & REGB_AIE) { + /* Generate an interrupt. */ + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + } + } + + /* + * The flag and interrupt should be issued + * on update ended, not started. + */ + nvr->regs[RTC_REGC] |= REGC_UF; + if (nvr->regs[RTC_REGB] & REGB_UIE) { + /* Generate an interrupt. */ + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + } + } +} + +static void +timer_load_count(nvr_t *nvr) +{ + int c = nvr->regs[RTC_REGA] & REGA_RS; + local_t *local = (local_t *) nvr->data; + + timer_disable(&local->rtc_timer); + + if ((nvr->regs[RTC_REGA] & 0x70) != 0x20) { + local->state = 0; + return; + } + + local->state = 1; + + switch (c) { + case 0: + local->state = 0; + break; + case 1: + case 2: + local->count = 1 << (c + 6); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); + break; + default: + local->count = 1 << (c - 1); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); + break; + } +} + +static void +timer_intr(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + const local_t *local = (local_t *) nvr->data; + + if (local->state == 1) { + timer_load_count(nvr); + + nvr->regs[RTC_REGC] |= REGC_PF; + if (nvr->regs[RTC_REGB] & REGB_PIE) { + /* Generate an interrupt. */ + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + } + } +} + +/* Callback from internal clock, another second passed. */ +static void +timer_tick(nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + /* Only update it there is no SET in progress. */ + if (!(nvr->regs[RTC_REGB] & REGB_SET)) { + /* Set the UIP bit, announcing the update. */ + local->stat = REGA_UIP; + + rtc_tick(); + + /* Schedule the actual update. */ + local->ecount = (244ULL + 1984ULL) * TIMER_USEC; + timer_set_delay_u64(&local->update_timer, local->ecount); + } +} + +static void +nvr_reg_common_write(uint16_t reg, uint8_t val, nvr_t *nvr, local_t *local) +{ + if ((reg == 0x2c) && (local->flags & FLAG_AMI_1994_HACK)) + nvr->is_new = 0; + if ((reg == 0x2d) && (local->flags & FLAG_AMI_1992_HACK)) + nvr->is_new = 0; + if ((reg == 0x52) && (local->flags & FLAG_AMI_1995_HACK)) + nvr->is_new = 0; + if ((reg >= 0x38) && (reg <= 0x3f) && local->wp[0]) + return; + if ((reg >= 0xb8) && (reg <= 0xbf) && local->wp[1]) + return; + if (local->lock[reg]) + return; + if (nvr->regs[reg] != val) { + nvr->regs[reg] = val; + nvr_dosave = 1; + } +} + +/* This must be exposed because ACPI uses it. */ +void +nvr_reg_write(uint16_t reg, uint8_t val, void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + struct tm tm; + uint8_t old; + uint8_t irq = 0; + uint8_t old_irq = 0; + + old = nvr->regs[reg]; + switch (reg) { + case RTC_REGA: + nvr->regs[RTC_REGA] = val; + timer_load_count(nvr); + break; + + case RTC_REGB: + old_irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; + nvr->regs[RTC_REGB] = val; + if (((old ^ val) & REGB_SET) && (val & REGB_SET)) { + /* According to the datasheet... */ + nvr->regs[RTC_REGA] &= ~REGA_UIP; + nvr->regs[RTC_REGB] &= ~REGB_UIE; + } + irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; + if (old_irq && !irq) { + picintc(1 << nvr->irq); + nvr->regs[RTC_REGC] &= ~REGC_IRQF; + } else if (!old_irq && irq) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + break; + + case RTC_REGC: /* R/O */ + break; + + case RTC_REGD: /* R/O */ + /* This is needed for VIA, where writing to this register changes a write-only + bit whose value is read from power management register 42. */ + nvr->regs[RTC_REGD] = val & 0x80; + break; + + case 0x32: + if ((reg == 0x32) && (local->cent == RTC_CENTURY_VIA) && local->wp_32) + break; + nvr_reg_common_write(reg, val, nvr, local); + break; + + default: /* non-RTC registers are just NVRAM */ + nvr_reg_common_write(reg, val, nvr, local); + break; + } + + if ((reg < RTC_REGA) || ((local->cent != 0xff) && (reg == local->cent))) { + if ((reg != 1) && (reg != 3) && (reg != 5)) { + if ((old != val) && !(time_sync & TIME_SYNC_ENABLED)) { + /* Update internal clock. */ + time_get(nvr, &tm); + nvr_time_set(&tm); + nvr_dosave = 1; + } + } + } +} + +/* Write to one of the NVR registers. */ +static void +nvr_write(uint16_t addr, uint8_t val, void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + uint8_t addr_id = (addr & 0x0e) >> 1; + + cycles -= ISA_CYCLES(8); + + if (local->bank[addr_id] == 0xff) + return; + + if (addr & 1) { +#if 0 + if (local->bank[addr_id] == 0xff) + return; +#endif + nvr_reg_write(local->addr[addr_id], val, priv); + } else { + local->addr[addr_id] = (val & (nvr->size - 1)); + /* Some chipsets use a 256 byte NVRAM but ports 70h and 71h always access only 128 bytes. */ + if (addr_id == 0x0) + local->addr[addr_id] &= 0x7f; + else if ((addr_id == 0x1) && (local->flags & FLAG_PIIX4)) + local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | 0x80; + if (local->bank[addr_id] > 0) + local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | (0x80 * local->bank[addr_id]); + if (!(local->flags & FLAG_NO_NMI)) + nmi_mask = (~val & 0x80); + } +} + +/* Read from one of the NVR registers. */ +static uint8_t +nvr_read(uint16_t addr, void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + const local_t *local = (local_t *) nvr->data; + uint8_t ret; + uint8_t addr_id = (addr & 0x0e) >> 1; + uint16_t i; + uint16_t checksum = 0x0000; + + cycles -= ISA_CYCLES(8); + + if (local->bank[addr_id] == 0xff) + ret = 0xff; + else if (addr & 1) + switch (local->addr[addr_id]) { + case RTC_REGA: + ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat; + break; + + case RTC_REGC: + ret = nvr->regs[RTC_REGC]; + picintc(1 << nvr->irq); + nvr->regs[RTC_REGC] = 0x00; + break; + + case RTC_REGD: + /* Bits 6-0 of this register always read 0. Bit 7 is battery state, + we should always return it set, as that means the battery is OK. */ + ret = REGD_VRT; + break; + + case 0x2c: + if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) + ret = nvr->regs[local->addr[addr_id]] & 0x7f; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x2d: + if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) + ret = nvr->regs[local->addr[addr_id]] & 0xf7; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x2e: + case 0x2f: + if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) { + for (i = 0x10; i <= 0x2d; i++) { + if (i == 0x2d) + checksum += (nvr->regs[i] & 0xf7); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x2e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) { + for (i = 0x10; i <= 0x2d; i++) { + if (i == 0x2c) + checksum += (nvr->regs[i] & 0x7f); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x2e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x3e: + case 0x3f: + if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) { + /* The checksum at 3E-3F is for 37-3D and 40-7F. */ + for (i = 0x37; i <= 0x3d; i++) + checksum += nvr->regs[i]; + for (i = 0x40; i <= 0x7f; i++) { + if (i == 0x52) + checksum += (nvr->regs[i] & 0xf3); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x3e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) { + /* The checksum at 3E-3F is for 37-3D and 40-51. */ + for (i = 0x37; i <= 0x3d; i++) + checksum += nvr->regs[i]; + for (i = 0x40; i <= 0x51; i++) { + if (i == 0x43) + checksum += (nvr->regs[i] | 0x02); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x3e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x43: + if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) + ret = nvr->regs[local->addr[addr_id]] | 0x02; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x52: + if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) + ret = nvr->regs[local->addr[addr_id]] & 0xf3; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + default: + ret = nvr->regs[local->addr[addr_id]]; + break; + } + else { + ret = local->addr[addr_id]; + if (!local->read_addr) + ret &= 0x80; + if (alt_access) + ret = (ret & 0x7f) | (nmi_mask ? 0x00 : 0x80); + } + + return ret; +} + +/* Secondary NVR write - used by SMC. */ +static void +nvr_sec_write(uint16_t addr, uint8_t val, void *priv) +{ + nvr_write(0x72 + (addr & 1), val, priv); +} + +/* Secondary NVR read - used by SMC. */ +static uint8_t +nvr_sec_read(uint16_t addr, void *priv) +{ + return nvr_read(0x72 + (addr & 1), priv); +} + +/* Reset the RTC state to 1980/01/01 00:00. */ +static void +nvr_reset(nvr_t *nvr) +{ + const local_t *local = (local_t *) nvr->data; + +#if 0 + memset(nvr->regs, local->def, RTC_REGS); +#endif + memset(nvr->regs, local->def, nvr->size); + nvr->regs[RTC_DOM] = 1; + nvr->regs[RTC_MONTH] = 1; + nvr->regs[RTC_YEAR] = RTC_BCD(80); + if (local->cent != 0xFF) + nvr->regs[local->cent] = RTC_BCD(19); + + nvr->regs[RTC_REGD] = REGD_VRT; +} + +/* Process after loading from file. */ +static void +nvr_start(nvr_t *nvr) +{ + const local_t *local = (local_t *) nvr->data; + + struct tm tm; + int default_found = 0; + + for (uint16_t i = 0; i < nvr->size; i++) { + if (nvr->regs[i] == local->def) + default_found++; + } + + if (default_found == nvr->size) + nvr->regs[0x0e] = 0xff; /* If load failed or it loaded an uninitialized NVR, + mark everything as bad. */ + + /* Initialize the internal and chip times. */ + if (time_sync & TIME_SYNC_ENABLED) { + /* Use the internal clock's time. */ + nvr_time_get(&tm); + time_set(nvr, &tm); + } else { + /* Set the internal clock from the chip time. */ + time_get(nvr, &tm); + nvr_time_set(&tm); + } + + /* Start the RTC. */ + nvr->regs[RTC_REGA] = (REGA_RS2 | REGA_RS1); + nvr->regs[RTC_REGB] = REGB_2412; +} + +static void +nvr_at_speed_changed(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + + timer_load_count(nvr); + + timer_disable(&local->update_timer); + if (local->ecount > 0ULL) + timer_set_delay_u64(&local->update_timer, local->ecount); + + timer_disable(&nvr->onesec_time); + timer_set_delay_u64(&nvr->onesec_time, (10000ULL * TIMER_USEC)); +} + +void +nvr_at_handler(int set, uint16_t base, nvr_t *nvr) +{ + io_handler(set, base, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); +} + +void +nvr_at_index_read_handler(int set, uint16_t base, nvr_t *nvr) +{ + io_handler(0, base, 1, + NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); + nvr_at_handler(0, base, nvr); + + if (set) + nvr_at_handler(1, base, nvr); + else { + io_handler(1, base, 1, + NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); + io_handler(1, base + 1, 1, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } +} + +void +nvr_at_sec_handler(int set, uint16_t base, nvr_t *nvr) +{ + io_handler(set, base, 2, + nvr_sec_read, NULL, NULL, nvr_sec_write, NULL, NULL, nvr); +} + +void +nvr_read_addr_set(int set, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + local->read_addr = set; +} + +void +nvr_wp_set(int set, int h, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + local->wp[h] = set; +} + +void +nvr_via_wp_set(int set, int reg, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + if (reg == 0x0d) + local->wp_0d = set; + else + local->wp_32 = set; +} + +void +nvr_bank_set(int base, uint8_t bank, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + local->bank[base] = bank; +} + +void +nvr_lock_set(int base, int size, int lock, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + for (int i = 0; i < size; i++) + local->lock[base + i] = lock; +} + +void +nvr_irq_set(int irq, nvr_t *nvr) +{ + nvr->irq = irq; +} + +static void +nvr_at_reset(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + + /* These bits are reset on reset. */ + nvr->regs[RTC_REGB] &= ~(REGB_PIE | REGB_AIE | REGB_UIE | REGB_SQWE); + nvr->regs[RTC_REGC] &= ~(REGC_PF | REGC_AF | REGC_UF | REGC_IRQF); +} + +static void * +nvr_at_init(const device_t *info) +{ + local_t *local; + nvr_t *nvr; + + /* Allocate an NVR for this machine. */ + nvr = (nvr_t *) malloc(sizeof(nvr_t)); + if (nvr == NULL) + return (NULL); + memset(nvr, 0x00, sizeof(nvr_t)); + + local = (local_t *) malloc(sizeof(local_t)); + memset(local, 0x00, sizeof(local_t)); + nvr->data = local; + + /* This is machine specific. */ + nvr->size = machines[machine].nvrmask + 1; + local->lock = (uint8_t *) malloc(nvr->size); + memset(local->lock, 0x00, nvr->size); + local->def = 0xff /*0x00*/; + local->flags = 0x00; + switch (info->local & 0x0f) { + case 0: /* standard AT, no century register */ + if (info->local == 32) { + local->flags |= FLAG_P6RP4_HACK; + nvr->irq = 8; + local->cent = RTC_CENTURY_AT; + } else { + nvr->irq = 8; + local->cent = 0xff; + } + break; + + case 1: /* standard AT */ + case 5: /* AMI WinBIOS 1994 */ + case 6: /* AMI BIOS 1995 */ + if ((info->local & 0x1f) == 0x11) + local->flags |= FLAG_PIIX4; + else { + local->def = 0x00; + if ((info->local & 0x1f) == 0x15) + local->flags |= FLAG_AMI_1994_HACK; + else if ((info->local & 0x1f) == 0x16) + local->flags |= FLAG_AMI_1995_HACK; + else + local->def = 0xff; + } + nvr->irq = 8; + local->cent = RTC_CENTURY_AT; + break; + + case 2: /* PS/1 or PS/2 */ + nvr->irq = 8; + local->cent = RTC_CENTURY_PS; + local->def = 0x00; + if (info->local & 0x10) + local->flags |= FLAG_NO_NMI; + break; + + case 3: /* Amstrad PC's */ + nvr->irq = 1; + local->cent = RTC_CENTURY_AT; + local->def = 0xff; + if (info->local & 0x10) + local->flags |= FLAG_NO_NMI; + break; + + case 4: /* IBM AT */ + if (info->local & 0x10) { + local->def = 0x00; + local->flags |= FLAG_AMI_1992_HACK; + } else if (info->local == 36) + local->def = 0x00; + else + local->def = 0xff; + nvr->irq = 8; + local->cent = RTC_CENTURY_AT; + break; + + case 7: /* VIA VT82C586B */ + nvr->irq = 8; + local->cent = RTC_CENTURY_VIA; + break; + case 8: /* Epson Equity LT */ + nvr->irq = -1; + local->cent = RTC_CENTURY_ELT; + break; + + default: + break; + } + + local->read_addr = 1; + + /* Set up any local handlers here. */ + nvr->reset = nvr_reset; + nvr->start = nvr_start; + nvr->tick = timer_tick; + + /* Initialize the generic NVR. */ + nvr_init(nvr); + + if (nvr_at_inited == 0) { + /* Start the timers. */ + timer_add(&local->update_timer, timer_update, nvr, 0); + + timer_add(&local->rtc_timer, timer_intr, nvr, 0); + /* On power on, if the oscillator is disabled, it's reenabled. */ + if ((nvr->regs[RTC_REGA] & 0x70) == 0x00) + nvr->regs[RTC_REGA] = (nvr->regs[RTC_REGA] & 0x8f) | 0x20; + nvr_at_reset(nvr); + timer_load_count(nvr); + + /* Set up the I/O handler for this device. */ + if (info->local == 8) { + io_sethandler(0x11b4, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } else { + io_sethandler(0x0070, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } + if (((info->local & 0x1f) == 0x11) || ((info->local & 0x1f) == 0x17)) { + io_sethandler(0x0072, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } + + nvr_at_inited = 1; + } + + return nvr; +} + +static void +nvr_at_close(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + + nvr_close(); + + timer_disable(&local->rtc_timer); + timer_disable(&local->update_timer); + timer_disable(&nvr->onesec_time); + + if (nvr != NULL) { + if (nvr->fn != NULL) + free(nvr->fn); + + if (nvr->data != NULL) + free(nvr->data); + + free(nvr); + } + + if (nvr_at_inited == 1) + nvr_at_inited = 0; +} + +const device_t at_nvr_old_device = { + .name = "PC/AT NVRAM (No century)", + .internal_name = "at_nvr_old", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t at_nvr_device = { + .name = "PC/AT NVRAM", + .internal_name = "at_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 1, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ps_nvr_device = { + .name = "PS/1 or PS/2 NVRAM", + .internal_name = "ps_nvr", + .flags = DEVICE_PS2, + .local = 2, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t amstrad_nvr_device = { + .name = "Amstrad NVRAM", + .internal_name = "amstrad_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 3, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ibmat_nvr_device = { + .name = "IBM AT NVRAM", + .internal_name = "ibmat_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 4, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t piix4_nvr_device = { + .name = "Intel PIIX4 PC/AT NVRAM", + .internal_name = "piix4_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 1, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ps_no_nmi_nvr_device = { + .name = "PS/1 or PS/2 NVRAM (No NMI)", + .internal_name = "ps1_nvr", + .flags = DEVICE_PS2, + .local = 0x10 | 2, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t amstrad_no_nmi_nvr_device = { + .name = "Amstrad NVRAM (No NMI)", + .internal_name = "amstrad_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 3, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ami_1992_nvr_device = { + .name = "AMI Color 1992 PC/AT NVRAM", + .internal_name = "ami_1992_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 4, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ami_1994_nvr_device = { + .name = "AMI WinBIOS 1994 PC/AT NVRAM", + .internal_name = "ami_1994_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 5, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ami_1995_nvr_device = { + .name = "AMI WinBIOS 1995 PC/AT NVRAM", + .internal_name = "ami_1995_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 6, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t via_nvr_device = { + .name = "VIA PC/AT NVRAM", + .internal_name = "via_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 7, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t p6rp4_nvr_device = { + .name = "ASUS P/I-P6RP4 PC/AT NVRAM", + .internal_name = "p6rp4_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 32, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t amstrad_megapc_nvr_device = { + .name = "Amstrad MegaPC NVRAM", + .internal_name = "amstrad_megapc_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 36, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t elt_nvr_device = { + .name = "Epson Equity LT NVRAM", + .internal_name = "elt_nvr", + .flags = DEVICE_ISA, + .local = 8, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index 1ab97d8a3..b13312545 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -49,7 +49,7 @@ #include <86box/nvr_ps2.h> #include <86box/rom.h> -typedef struct { +typedef struct ps2_nvr_t { int addr; uint8_t *ram; @@ -61,8 +61,8 @@ typedef struct { static uint8_t ps2_nvr_read(uint16_t port, void *priv) { - ps2_nvr_t *nvr = (ps2_nvr_t *) priv; - uint8_t ret = 0xff; + const ps2_nvr_t *nvr = (ps2_nvr_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x74: @@ -76,9 +76,12 @@ ps2_nvr_read(uint16_t port, void *priv) case 0x76: ret = nvr->ram[nvr->addr]; break; + + default: + break; } - return (ret); + return ret; } static void @@ -98,6 +101,9 @@ ps2_nvr_write(uint16_t port, uint8_t val, void *priv) case 0x76: nvr->ram[nvr->addr] = val; break; + + default: + break; } } @@ -134,7 +140,7 @@ ps2_nvr_init(const device_t *info) fclose(f); } - return (nvr); + return nvr; } static void diff --git a/src/pci.c b/src/pci.c index f9155e2e3..c86006a1a 100644 --- a/src/pci.c +++ b/src/pci.c @@ -34,9 +34,12 @@ #include <86box/dma.h> #include <86box/pci.h> #include <86box/keyboard.h> +#include <86box/plat_unused.h> -typedef struct { - uint8_t bus, id, type; +typedef struct pci_card_t { + uint8_t bus; + uint8_t id; + uint8_t type; uint8_t irq_routing[4]; void *priv; @@ -44,30 +47,40 @@ typedef struct { uint8_t (*read)(int func, int addr, void *priv); } pci_card_t; -typedef struct { +typedef struct pci_mirq_t { uint8_t enabled; uint8_t irq_line; } pci_mirq_t; -int pci_burst_time, agp_burst_time, - pci_nonburst_time, agp_nonburst_time; +int pci_burst_time; +int agp_burst_time; +int pci_nonburst_time; +int agp_nonburst_time; +int pci_take_over_io; + +uint32_t pci_base = 0xc000; +uint32_t pci_size = 0x1000; static pci_card_t pci_cards[32]; -static uint8_t pci_pmc = 0, last_pci_card = 0, last_normal_pci_card = 0, last_pci_bus = 1; -static uint8_t pci_card_to_slot_mapping[256][32], pci_bus_number_to_index_mapping[256]; -static uint8_t pci_irqs[16], pci_irq_level[16]; +static uint8_t pci_pmc = 0; +static uint8_t last_pci_card = 0; +static uint8_t last_normal_pci_card = 0; +static uint8_t last_pci_bus = 1; +static uint8_t pci_card_to_slot_mapping[256][32]; +static uint8_t pci_bus_number_to_index_mapping[256]; +static uint8_t pci_irqs[16]; +static uint8_t pci_irq_level[16]; static uint64_t pci_irq_hold[16]; static pci_mirq_t pci_mirqs[8]; -static int pci_type, - pci_switch, - pci_index, - pci_func, - pci_card, - pci_bus, - pci_enable, - pci_key; +static int pci_type; +static int pci_switch; +static int pci_index; +static int pci_func; +static int pci_card; +static int pci_bus; +static int pci_enable; +static int pci_key; static int trc_reg = 0; -static uint32_t pci_base = 0xc000, pci_size = 0x1000; static void pci_reset_regs(void); @@ -92,14 +105,12 @@ pci_log(const char *fmt, ...) static void pci_clear_slot(int card) { - int i; - pci_card_to_slot_mapping[pci_cards[card].bus][pci_cards[card].id] = 0xff; pci_cards[card].id = 0xff; pci_cards[card].type = 0xff; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) pci_cards[card].irq_routing[i] = 0; pci_cards[card].read = NULL; @@ -110,14 +121,14 @@ pci_clear_slot(int card) void pci_relocate_slot(int type, int new_slot) { - int i, card = -1; + int card = -1; int old_slot; uint8_t mapping; if ((new_slot < 0) || (new_slot > 31)) return; - for (i = 0; i < 32; i++) { + for (uint8_t i = 0; i < 32; i++) { if ((pci_cards[i].bus == 0) && (pci_cards[i].type == type)) { card = i; break; @@ -135,7 +146,7 @@ pci_relocate_slot(int type, int new_slot) } static void -pci_cf8_write(uint16_t port, uint32_t val, void *priv) +pci_cf8_write(UNUSED(uint16_t port), uint32_t val, UNUSED(void *priv)) { pci_log("cf8 write: %08X\n", val); pci_index = val & 0xff; @@ -146,13 +157,13 @@ pci_cf8_write(uint16_t port, uint32_t val, void *priv) } static uint32_t -pci_cf8_read(uint16_t port, void *priv) +pci_cf8_read(UNUSED(uint16_t port), UNUSED(void *priv)) { return pci_index | (pci_func << 8) | (pci_card << 11) | (pci_bus << 16) | (pci_enable << 31); } static void -pci_write(uint16_t port, uint8_t val, void *priv) +pci_write(uint16_t port, uint8_t val, UNUSED(void *priv)) { uint8_t slot = 0; @@ -185,11 +196,14 @@ pci_write(uint16_t port, uint8_t val, void *priv) #endif break; + + default: + break; } } static void -pci_writew(uint16_t port, uint16_t val, void *priv) +pci_writew(uint16_t port, uint16_t val, UNUSED(void *priv)) { uint8_t slot = 0; @@ -223,11 +237,14 @@ pci_writew(uint16_t port, uint16_t val, void *priv) #endif break; + + default: + break; } } static void -pci_writel(uint16_t port, uint32_t val, void *priv) +pci_writel(uint16_t port, uint32_t val, UNUSED(void *priv)) { uint8_t slot = 0; @@ -263,11 +280,14 @@ pci_writel(uint16_t port, uint32_t val, void *priv) #endif break; + + default: + break; } } static uint8_t -pci_read(uint16_t port, void *priv) +pci_read(uint16_t port, UNUSED(void *priv)) { uint8_t slot = 0; uint8_t ret = 0xff; @@ -296,6 +316,10 @@ pci_read(uint16_t port, void *priv) else pci_log("Reading from unasisgned PCI card on slot %02X (pci_cards[%i]) (%02X:%02X)...\n", pci_card, slot, pci_func, pci_index | (port & 3)); #endif + break; + + default: + break; } pci_log("Reading %02X, from PCI card on bus %i, slot %02X (pci_cards[%i]) (%02X:%02X)...\n", ret, pci_bus, pci_card, slot, pci_func, pci_index | (port & 3)); @@ -304,7 +328,7 @@ pci_read(uint16_t port, void *priv) } static uint16_t -pci_readw(uint16_t port, void *priv) +pci_readw(uint16_t port, UNUSED(void *priv)) { uint8_t slot = 0; uint16_t ret = 0xffff; @@ -335,6 +359,10 @@ pci_readw(uint16_t port, void *priv) else pci_log("Reading from unasisgned PCI card on slot %02X (pci_cards[%i]) (%02X:%02X)...\n", pci_card, slot, pci_func, pci_index | (port & 3)); #endif + break; + + default: + break; } pci_log("Reading %04X, from PCI card on bus %i, slot %02X (pci_cards[%i]) (%02X:%02X)...\n", ret, pci_bus, pci_card, slot, pci_func, pci_index | (port & 3)); @@ -343,7 +371,7 @@ pci_readw(uint16_t port, void *priv) } static uint32_t -pci_readl(uint16_t port, void *priv) +pci_readl(uint16_t port, UNUSED(void *priv)) { uint8_t slot = 0; uint32_t ret = 0xffffffff; @@ -376,6 +404,10 @@ pci_readl(uint16_t port, void *priv) else pci_log("Reading from unasisgned PCI card on slot %02X (pci_cards[%i]) (%02X:%02X)...\n", pci_card, slot, pci_func, pci_index | (port & 3)); #endif + break; + + default: + break; } pci_log("Reading %08X, from PCI card on bus %i, slot %02X (pci_cards[%i]) (%02X:%02X)...\n", ret, pci_bus, pci_card, slot, pci_func, pci_index | (port & 3)); @@ -383,19 +415,17 @@ pci_readl(uint16_t port, void *priv) return ret; } -static void pci_type2_write(uint16_t port, uint8_t val, void *priv); -static uint8_t pci_type2_read(uint16_t port, void *priv); - void pci_set_pmc(uint8_t pmc) { pci_log("pci_set_pmc(%02X)\n", pmc); - // pci_reset_regs(); +#if 0 + pci_reset_regs(); +#endif if (!pci_pmc && (pmc & 0x01)) { - io_removehandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); + pci_log("PMC: Dellocating ports %04X-%04X...\n", pci_base, pci_base + pci_size - 1); + pci_take_over_io &= ~PCI_IO_ON; io_removehandler(0x0cf8, 1, pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL); @@ -408,13 +438,11 @@ pci_set_pmc(uint8_t pmc) io_sethandler(0x0cfc, 4, pci_read, pci_readw, pci_readl, pci_write, pci_writew, pci_writel, NULL); } else if (pci_pmc && !(pmc & 0x01)) { - io_removehandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); + pci_log("PMC: Redellocating ports %04X-%04X...\n", pci_base, pci_base + pci_size - 1); + pci_take_over_io &= ~PCI_IO_ON; if (pci_key) { - io_sethandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); + pci_log("PMC: Allocating ports %04X-%04X...\n", pci_base, pci_base + pci_size - 1); + pci_take_over_io |= PCI_IO_ON; } io_removehandler(0x0cf8, 1, @@ -433,71 +461,99 @@ pci_set_pmc(uint8_t pmc) } static void -pci_type2_write(uint16_t port, uint8_t val, void *priv) +pci_type2_write_reg(uint16_t port, uint8_t val) { uint8_t slot = 0; - if (port == 0xcf8) { - pci_func = (val >> 1) & 7; + pci_card = (port >> 8) & 0xf; + pci_index = port & 0xff; - if (!pci_key && (val & 0xf0)) { - io_removehandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); - io_sethandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); - } else if (pci_key && !(val & 0xf0)) - io_removehandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); - - pci_key = val & 0xf0; - } else if (port == 0xcfa) { - pci_bus = val; - - pci_log("Allocating ports %04X-%04X...\n", pci_base, pci_base + pci_size - 1); - - /* Evidently, writing here, we should also enable the - configuration space. */ - io_removehandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); - io_sethandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); - - /* Mark as enabled. */ - pci_key |= 0x100; - } else if (port == 0xcfb) { - pci_log("Write %02X to port 0CFB\n", val); - pci_set_pmc(val); - } else { - pci_card = (port >> 8) & 0xf; - pci_index = port & 0xff; - - slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card]; - if (slot != 0xff) { - if (pci_cards[slot].write) - pci_cards[slot].write(pci_func, pci_index | (port & 3), val, pci_cards[slot].priv); -#ifdef ENABLE_PCI_LOG - else - pci_log("Writing to empty PCI card on slot %02X (pci_cards[%i]) (%02X:%02X)...\n", pci_card, slot, pci_func, pci_index); -#endif - } + slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card]; + if (slot != 0xff) { + if (pci_cards[slot].write) + pci_cards[slot].write(pci_func, pci_index | (port & 3), val, pci_cards[slot].priv); #ifdef ENABLE_PCI_LOG else - pci_log("Writing to unassigned PCI card on slot %02X (pci_cards[%i]) (%02X:%02X)...\n", pci_card, slot, pci_func, pci_index); + pci_log("Writing to empty PCI card on slot %02X:%02X (pci_cards[%i]) (%02X:%02X)...\n", pci_bus, pci_card, slot, pci_func, pci_index); #endif } +#ifdef ENABLE_PCI_LOG + else + pci_log("Writing to unassigned PCI card on slot %02X:%02X (pci_cards[%i]) (%02X:%02X)...\n", pci_bus, pci_card, slot, pci_func, pci_index); +#endif +} + +void +pci_type2_write(uint16_t port, uint8_t val, UNUSED(void *priv)) +{ + switch (port) { + case 0xcf8: + pci_func = (val >> 1) & 7; + + if (val & 0xf0) { + pci_log("CF8: Allocating ports %04X-%04X...\n", pci_base, pci_base + pci_size - 1); + pci_take_over_io |= PCI_IO_ON; + } else { + pci_log("CF8: Dellocating ports %04X-%04X...\n", pci_base, pci_base + pci_size - 1); + pci_take_over_io &= ~PCI_IO_ON; + } + + pci_key = val & 0xf0; + break; + case 0xcfa: + pci_bus = val; + + pci_log("CFA: Allocating ports %04X-%04X...\n", pci_base, pci_base + pci_size - 1); + + /* Evidently, writing here, we should also enable the + configuration space. */ + pci_take_over_io |= PCI_IO_ON; + + /* Mark as enabled. */ + pci_key |= 0x100; + break; + case 0xcfb: + pci_log("Write %02X to port 0CFB\n", val); + pci_set_pmc(val); + break; + + case 0xc000 ... 0xc0ff: + if (pci_take_over_io == 0x00000000) + break; + + pci_type2_write_reg(port, val); + break; + + case 0xc100 ... 0xcfff: + if (!(pci_take_over_io & PCI_IO_ON)) + break; + + pci_type2_write_reg(port, val); + break; + + default: + break; + } } -static void +void +pci_type2_writew(uint16_t port, uint16_t val, void *priv) +{ + pci_type2_write(port, val & 0xff, priv); + pci_type2_write(port + 1, val >> 8, priv); +} + +void pci_type2_writel(uint16_t port, uint32_t val, void *priv) { - int i; + pci_type2_writew(port, val & 0xffff, priv); + pci_type2_writew(port + 2, val >> 16, priv); +} - for (i = 0; i < 4; i++) { +static void +pci_type2_cfb_writel(uint16_t port, uint32_t val, void *priv) +{ + for (uint8_t i = 0; i < 4; i++) { /* Make sure to have the DWORD write not pass through to PMC if mechanism 1 is in use, as otherwise, the PCI enable bits clobber it. */ if (!pci_pmc || ((port + i) != 0x0cfb)) @@ -506,41 +562,88 @@ pci_type2_writel(uint16_t port, uint32_t val, void *priv) } static uint8_t -pci_type2_read(uint16_t port, void *priv) +pci_type2_read_reg(uint16_t port) { uint8_t slot = 0; uint8_t ret = 0xff; - if (port == 0xcf8) - ret = pci_key | (pci_func << 1); - else if (port == 0xcfa) - ret = pci_bus; - else if (port == 0xcfb) - ret = pci_pmc; - else { - pci_card = (port >> 8) & 0xf; - pci_index = port & 0xff; + pci_card = (port >> 8) & 0xf; + pci_index = port & 0xff; - slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card]; - if (slot != 0xff) { - if (pci_cards[slot].read) - ret = pci_cards[slot].read(pci_func, pci_index | (port & 3), pci_cards[slot].priv); -#ifdef ENABLE_PCI_LOG - else - pci_log("Reading from empty PCI card on slot %02X (pci_cards[%i]) (%02X:%02X)...\n", pci_card, slot, pci_func, pci_index); -#endif - } + slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card]; + if (slot != 0xff) { + if (pci_cards[slot].read) + ret = pci_cards[slot].read(pci_func, pci_index | (port & 3), pci_cards[slot].priv); #ifdef ENABLE_PCI_LOG else - pci_log("Reading from unasisgned PCI card on slot %02X (pci_cards[%i]) (%02X:%02X)...\n", pci_card, slot, pci_func, pci_index); + pci_log("Reading from empty PCI card on slot %02X:%02X (pci_cards[%i]) (%02X:%02X)...\n", pci_bus, pci_card, slot, pci_func, pci_index); +#endif + } +#ifdef ENABLE_PCI_LOG + else + pci_log("Reading from unasisgned PCI card on slot %02X:%02X (pci_cards[%i]) (%02X:%02X)...\n", pci_bus, pci_card, slot, pci_func, pci_index); #endif - pci_log("Reading %02X at PCI register %02X at bus %02X, card %02X, function %02X\n", ret, pci_index, pci_bus, pci_card, pci_func); + pci_log("Reading %02X at PCI register %02X at bus %02X, card %02X, function %02X\n", ret, pci_index, pci_bus, pci_card, pci_func); + + return ret; +} + +uint8_t +pci_type2_read(uint16_t port, UNUSED(void *priv)) +{ + uint8_t ret = 0xff; + + switch (port) { + case 0xcf8: + ret = pci_key | (pci_func << 1); + break; + case 0xcfa: + ret = pci_bus; + break; + case 0xcfb: + ret = pci_pmc; + break; + + case 0xc000 ... 0xc0ff: + if (pci_take_over_io == 0x00000000) + break; + + ret = pci_type2_read_reg(port); + break; + + case 0xc100 ... 0xcfff: + if (!(pci_take_over_io & PCI_IO_ON)) + break; + + ret = pci_type2_read_reg(port); + break; + + default: + break; } return ret; } +uint16_t +pci_type2_readw(uint16_t port, void *priv) +{ + uint16_t ret = pci_type2_read(port, priv); + ret |= ((uint16_t) pci_type2_read(port + 1, priv)) << 8; + + return ret; +} + +uint32_t +pci_type2_readl(uint16_t port, void *priv) +{ + uint32_t ret = pci_type2_readw(port, priv); + ret |= ((uint32_t) pci_type2_readw(port + 2, priv)) << 16; + + return ret; +} + void pci_set_irq_routing(int pci_int, int irq) { @@ -822,9 +925,7 @@ pci_reset_regs(void) { pci_index = pci_card = pci_func = pci_bus = pci_key = 0; - io_removehandler(pci_base, pci_size, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); + pci_take_over_io &= ~PCI_IO_ON; } void @@ -837,11 +938,9 @@ pci_pic_reset(void) static void pci_reset_hard(void) { - int i; - pci_reset_regs(); - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { if (pci_irq_hold[i]) { pci_irq_hold[i] = 0; @@ -879,7 +978,7 @@ pci_reset(void) static void pci_slots_clear(void) { - uint8_t i, j; + uint8_t i; last_pci_card = last_normal_pci_card = 0; last_pci_bus = 1; @@ -889,7 +988,7 @@ pci_slots_clear(void) i = 0; do { - for (j = 0; j < 32; j++) + for (uint8_t j = 0; j < 32; j++) pci_card_to_slot_mapping[i][j] = 0xff; pci_bus_number_to_index_mapping[i] = 0xff; } while (i++ < 0xff); @@ -898,19 +997,19 @@ pci_slots_clear(void) } uint32_t -trc_readl(uint16_t port, void *priv) +trc_readl(UNUSED(uint16_t port), UNUSED(void *priv)) { return 0xffffffff; } uint16_t -trc_readw(uint16_t port, void *priv) +trc_readw(UNUSED(uint16_t port), UNUSED(void *priv)) { return 0xffff; } uint8_t -trc_read(uint16_t port, void *priv) +trc_read(UNUSED(uint16_t port), UNUSED(void *priv)) { return trc_reg & 0xfb; } @@ -922,12 +1021,11 @@ trc_reset(uint8_t val) dma_reset(); dma_set_at(1); - device_reset_all(); + device_reset_all(DEVICE_ALL); cpu_alt_reset = 0; pci_reset(); - keyboard_at_reset(); mem_a20_alt = 0; mem_a20_recalc(); @@ -939,17 +1037,19 @@ trc_reset(uint8_t val) } void -trc_writel(uint16_t port, uint32_t val, void *priv) +trc_writel(UNUSED(uint16_t port), UNUSED(uint32_t val), UNUSED(void *priv)) { + // } void -trc_writew(uint16_t port, uint16_t val, void *priv) +trc_writew(UNUSED(uint16_t port), UNUSED(uint16_t val), UNUSED(void *priv)) { + // } void -trc_write(uint16_t port, uint8_t val, void *priv) +trc_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) { pci_log("TRC Write: %02X\n", val); @@ -993,7 +1093,7 @@ pci_init(int type) pci_pmc = 0x00; io_sethandler(0x0cfb, 1, - pci_type2_read, NULL, NULL, pci_type2_write, NULL, pci_type2_writel, NULL); + pci_type2_read, NULL, NULL, pci_type2_write, NULL, pci_type2_cfb_writel, NULL); } if (type & PCI_NO_IRQ_STEERING) { @@ -1004,6 +1104,8 @@ pci_init(int type) pic_elcr_set_enabled(1); } + pci_take_over_io = 0x00000000; + if ((type & PCI_CONFIG_TYPE_MASK) == PCI_CONFIG_TYPE_1) { pci_log("PCI: Configuration mechanism #1\n"); io_sethandler(0x0cf8, 1, @@ -1024,9 +1126,7 @@ pci_init(int type) pci_base = 0xc100; pci_size = 0x0f00; - io_sethandler(0xc000, 0x0100, - pci_type2_read, NULL, NULL, - pci_type2_write, NULL, NULL, NULL); + pci_take_over_io |= PCI_IO_DEV0; } } @@ -1095,10 +1195,10 @@ pci_register_bus_slot(int bus, int card, int type, int inta, int intb, int intc, uint8_t pci_find_slot(uint8_t add_type, uint8_t ignore_slot) { - pci_card_t *dev; - uint8_t i, ret = 0xff; + const pci_card_t *dev; + uint8_t ret = 0xff; - for (i = 0; i < last_pci_card; i++) { + for (uint8_t i = 0; i < last_pci_card; i++) { dev = &pci_cards[i]; if (!dev->read && !dev->write && ((ignore_slot == 0xff) || (i != ignore_slot))) { @@ -1123,7 +1223,8 @@ uint8_t pci_add_card(uint8_t add_type, uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv) { pci_card_t *dev; - uint8_t i, j; + uint8_t i; + uint8_t j; if (add_type < PCI_ADD_AGP) pci_log("pci_add_card(): Adding PCI CARD at specific slot %02X [SPECIFIC]\n", add_type); diff --git a/src/pci_dummy.c b/src/pci_dummy.c index 1d0c95be2..8ed6f9f30 100644 --- a/src/pci_dummy.c +++ b/src/pci_dummy.c @@ -9,14 +9,16 @@ #include <86box/io.h> #include <86box/pci.h> #include <86box/pci_dummy.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> -typedef struct -{ +typedef struct pci_dummy_t { uint8_t pci_regs[256]; bar_t pci_bar[2]; - uint8_t card, interrupt_on; + uint8_t card; + uint8_t interrupt_on; } pci_dummy_t; static void @@ -29,12 +31,12 @@ pci_dummy_interrupt(int set, pci_dummy_t *dev) } static uint8_t -pci_dummy_read(uint16_t Port, void *p) +pci_dummy_read(uint16_t port, void *priv) { - pci_dummy_t *dev = (pci_dummy_t *) p; + pci_dummy_t *dev = (pci_dummy_t *) priv; uint8_t ret = 0xff; - switch (Port & 0x20) { + switch (port & 0x20) { case 0x00: ret = 0x1a; break; @@ -60,48 +62,54 @@ pci_dummy_read(uint16_t Port, void *p) dev->interrupt_on = 0; } break; + + default: + break; } return ret; } static uint16_t -pci_dummy_readw(uint16_t Port, void *p) +pci_dummy_readw(uint16_t port, void *priv) { - return pci_dummy_read(Port, p); + return pci_dummy_read(port, priv); } static uint32_t -pci_dummy_readl(uint16_t Port, void *p) +pci_dummy_readl(uint16_t port, void *priv) { - return pci_dummy_read(Port, p); + return pci_dummy_read(port, priv); } static void -pci_dummy_write(uint16_t Port, uint8_t Val, void *p) +pci_dummy_write(uint16_t port, UNUSED(uint8_t val), void *priv) { - pci_dummy_t *dev = (pci_dummy_t *) p; + pci_dummy_t *dev = (pci_dummy_t *) priv; - switch (Port & 0x20) { + switch (port & 0x20) { case 0x06: if (!dev->interrupt_on) { dev->interrupt_on = 1; pci_dummy_interrupt(1, dev); } break; + + default: + break; } } static void -pci_dummy_writew(uint16_t Port, uint16_t Val, void *p) +pci_dummy_writew(uint16_t port, uint16_t val, void *priv) { - pci_dummy_write(Port, Val & 0xFF, p); + pci_dummy_write(port, val & 0xFF, priv); } static void -pci_dummy_writel(uint16_t Port, uint32_t Val, void *p) +pci_dummy_writel(uint16_t port, uint32_t val, void *priv) { - pci_dummy_write(Port, Val & 0xFF, p); + pci_dummy_write(port, val & 0xFF, priv); } static void @@ -119,8 +127,8 @@ pci_dummy_io_set(pci_dummy_t *dev) static uint8_t pci_dummy_pci_read(int func, int addr, void *priv) { - pci_dummy_t *dev = (pci_dummy_t *) priv; - uint8_t ret = 0xff; + const pci_dummy_t *dev = (pci_dummy_t *) priv; + uint8_t ret = 0xff; if (func == 0x00) switch (addr) { @@ -172,7 +180,9 @@ pci_dummy_pci_read(int func, int addr, void *priv) break; } - // pclog("AB0B:071A: PCI_Read(%d, %04X) = %02X\n", func, addr, ret); +#if 0 + pclog("AB0B:071A: PCI_Read(%d, %04X) = %02X\n", func, addr, ret); +#endif return ret; } @@ -183,7 +193,9 @@ pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv) pci_dummy_t *dev = (pci_dummy_t *) priv; uint8_t valxor; - // pclog("AB0B:071A: PCI_Write(%d, %04X, %02X)\n", func, addr, val); +#if 0 + pclog("AB0B:071A: PCI_Write(%d, %04X, %02X)\n", func, addr, val); +#endif if (func == 0x00) switch (addr) { @@ -199,7 +211,9 @@ pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv) case 0x10: /* PCI_BAR */ val &= 0xe0; /* 0xe0 acc to RTL DS */ - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: /* PCI_BAR */ /* Remove old I/O. */ @@ -225,6 +239,9 @@ pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv) pclog("AB0B:071A Device %02X: IRQ now: %i\n", dev->card, val); dev->pci_regs[addr] = val; return; + + default: + break; } } @@ -252,7 +269,7 @@ pci_dummy_close(void *priv) } static void * -pci_dummy_card_init(const device_t *info) +pci_dummy_card_init(UNUSED(const device_t *info)) { pci_dummy_t *dev = (pci_dummy_t *) calloc(1, sizeof(pci_dummy_t)); @@ -278,9 +295,9 @@ const device_t pci_dummy_device = { void pci_dummy_init(int min_slot, int max_slot, int nb_slot, int sb_slot) { - int i = 0, j = 1; + int j = 1; - for (i = min_slot; i <= max_slot; i++) { + for (int i = min_slot; i <= max_slot; i++) { if ((i != nb_slot) && (i != sb_slot)) { pci_register_slot(i, PCI_CARD_NORMAL, 1, 3, 2, 4); device_add_inst(&pci_dummy_device, j); diff --git a/src/pic.c b/src/pic.c index bdff7f59c..6173291b4 100644 --- a/src/pic.c +++ b/src/pic.c @@ -37,6 +37,7 @@ #include <86box/apm.h> #include <86box/nvr.h> #include <86box/acpi.h> +#include <86box/plat_unused.h> enum { STATE_NONE = 0, @@ -45,16 +46,23 @@ enum { STATE_ICW4 }; -pic_t pic, pic2; +pic_t pic; +pic_t pic2; static pc_timer_t pic_timer; -static int shadow = 0, elcr_enabled = 0, - tmr_inited = 0, latched = 0, - pic_pci = 0; +static int shadow = 0; +static int elcr_enabled = 0; +static int tmr_inited = 0; +static int latched = 0; +static int pic_pci = 0; +static int kbd_latch = 0; +static int mouse_latch = 0; -static uint16_t smi_irq_mask = 0x0000, - smi_irq_status = 0x0000; +static uint16_t smi_irq_mask = 0x0000; +static uint16_t smi_irq_status = 0x0000; + +static uint16_t latched_irqs = 0x0000; static void (*update_pending)(void); @@ -133,9 +141,9 @@ pic_elcr_write(uint16_t port, uint8_t val, void *priv) } uint8_t -pic_elcr_read(uint16_t port, void *priv) +pic_elcr_read(UNUSED(uint16_t port), void *priv) { - pic_t *dev = (pic_t *) priv; + const pic_t *dev = (pic_t *) priv; pic_log("ELCR%i: READ %02X\n", port & 1, dev->elcr); @@ -184,10 +192,10 @@ find_best_interrupt(pic_t *dev) { uint8_t b; uint8_t intr; - int i, j; - int ret = -1; + uint8_t j; + int8_t ret = -1; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { j = (i + dev->priority) & 7; b = 1 << j; @@ -201,7 +209,7 @@ find_best_interrupt(pic_t *dev) intr = dev->interrupt = (ret == -1) ? 0x17 : ret; - if (dev->at && (ret != 1)) { + if (dev->at && (ret != -1)) { if (dev == &pic2) intr += 8; @@ -284,6 +292,12 @@ pic_set_shadow(int sh) shadow = sh; } +int +pic_get_pci_flag(void) +{ + return pic_pci; +} + void pic_set_pci_flag(int pci) { @@ -321,10 +335,11 @@ pic_acknowledge(pic_t *dev) static uint8_t pic_non_specific_find(pic_t *dev) { - int i, j; - uint8_t b, irq = 0xff; + uint8_t j; + uint8_t b; + uint8_t irq = 0xff; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { j = (i + dev->priority) & 7; b = (1 << j); @@ -383,6 +398,23 @@ pic_command(pic_t *dev) dev->auto_eoi_rotate = !!(dev->ocw2 & 0x80); } +uint8_t +pic_latch_read(UNUSED(uint16_t addr), UNUSED(void *priv)) +{ + uint8_t ret = 0xff; + + pic_log("pic_latch_read(%i, %i): %02X%02X\n", kbd_latch, mouse_latch, pic2.lines & 0x10, pic.lines & 0x02); + + if (kbd_latch && (latched_irqs & 0x0002)) + picintc(0x0002); + + if (mouse_latch && (latched_irqs & 0x1000)) + picintc(0x1000); + + /* Return FF - we just lower IRQ 1 and IRQ 12. */ + return ret; +} + uint8_t pic_read(uint16_t addr, void *priv) { @@ -464,6 +496,9 @@ pic_write(uint16_t addr, uint8_t val, void *priv) dev->imr = val; update_pending(); break; + + default: + break; } } else { if (val & 0x10) { @@ -500,24 +535,71 @@ pic_write(uint16_t addr, uint8_t val, void *priv) void pic_set_pci(void) { - int i; - - for (i = 0x0024; i < 0x0040; i += 4) { + for (uint8_t i = 0x0024; i < 0x0040; i += 4) { io_sethandler(i, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic); io_sethandler(i + 0x0080, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic2); } - for (i = 0x1120; i < 0x1140; i += 4) { + for (uint16_t i = 0x1120; i < 0x1140; i += 4) { io_sethandler(i, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic); io_sethandler(i + 0x0080, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic2); } } void -pic_init(void) +pic_kbd_latch(int enable) +{ + pic_log("PIC keyboard latch now %sabled\n", enable ? "en" : "dis"); + + if (!!(enable | mouse_latch) != !!(kbd_latch | mouse_latch)) + io_handler(!!(enable | mouse_latch), 0x0060, 0x0001, pic_latch_read, NULL, NULL, NULL, NULL, NULL, NULL); + + kbd_latch = !!enable; + + if (!enable) + picintc(0x0002); +} + +void +pic_mouse_latch(int enable) +{ + pic_log("PIC mouse latch now %sabled\n", enable ? "en" : "dis"); + + if (!!(kbd_latch | enable) != !!(kbd_latch | mouse_latch)) + io_handler(!!(kbd_latch | enable), 0x0060, 0x0001, pic_latch_read, NULL, NULL, NULL, NULL, NULL, NULL); + + mouse_latch = !!enable; + + if (!enable) + picintc(0x1000); +} + +static void +pic_reset_hard(void) { pic_reset(); + /* Explicitly reset the latches. */ + kbd_latch = mouse_latch = 0; + latched_irqs = 0x0000; + + /* The situation is as follows: There is a giant mess when it comes to these latches on real hardware, + to the point that there's even boards with board-level latched that get used in place of the latches + on the chipset, therefore, I'm just doing this here for the sake of simplicity. */ + if (machine_has_bus(machine, MACHINE_BUS_PS2_LATCH)) { + pic_kbd_latch(0x01); + pic_mouse_latch(0x01); + } else { + pic_kbd_latch(0x00); + pic_mouse_latch(0x00); + } +} + +void +pic_init(void) +{ + pic_reset_hard(); + shadow = 0; io_sethandler(0x0020, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic); } @@ -525,7 +607,7 @@ pic_init(void) void pic_init_pcjr(void) { - pic_reset(); + pic_reset_hard(); shadow = 0; io_sethandler(0x0020, 0x0008, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic); @@ -541,13 +623,14 @@ pic2_init(void) void picint_common(uint16_t num, int level, int set) { - int i, raise; - uint8_t b, slaves = 0; + int raise; + uint8_t b; + uint8_t slaves = 0; /* Make sure to ignore all slave IRQ's, and in case of AT+, translate IRQ 2 to IRQ 9. */ - for (i = 0; i < 8; i++) { - b = (1 << i); + for (uint8_t i = 0; i < 8; i++) { + b = (uint8_t) (1 << i); raise = num & b; if (pic.icw3 & b) { @@ -582,6 +665,10 @@ picint_common(uint16_t num, int level, int set) if (level) pic2.lines |= (num >> 8); + /* Latch IRQ 12 if the mouse latch is enabled. */ + if ((num & 0x1000) && mouse_latch) + latched_irqs |= 0x1000; + pic2.irr |= (num >> 8); } @@ -589,6 +676,10 @@ picint_common(uint16_t num, int level, int set) if (level) pic.lines |= (num & 0x00ff); + /* Latch IRQ 1 if the keyboard latch is enabled. */ + if (kbd_latch && (num & 0x0002)) + latched_irqs |= 0x0002; + pic.irr |= (num & 0x00ff); } } else { @@ -596,11 +687,21 @@ picint_common(uint16_t num, int level, int set) if (num & 0xff00) { pic2.lines &= ~(num >> 8); + + /* Unlatch IRQ 12 if the mouse latch is enabled. */ + if ((num & 0x1000) && mouse_latch) + latched_irqs &= 0xefff; + pic2.irr &= ~(num >> 8); } if (num & 0x00ff) { pic.lines &= ~(num & 0x00ff); + + /* Unlatch IRQ 1 if the keyboard latch is enabled. */ + if (kbd_latch && (num & 0x0002)) + latched_irqs &= 0xfffd; + pic.irr &= ~(num & 0x00ff); } } @@ -680,7 +781,7 @@ pic_irq_ack_read(pic_t *dev, int phase) uint8_t pic_irq_ack(void) { - int ret; + uint8_t ret; /* Needed for Xi8088. */ if ((pic.ack_bytes == 0) && pic.int_pending && pic_slave_on(&pic, pic.interrupt)) { @@ -688,7 +789,6 @@ pic_irq_ack(void) /* If we are on AT, IRQ 2 is pending, and we cannot find a pending IRQ on PIC 2, fatal out. */ fatal("IRQ %i pending on AT without a pending IRQ on PIC %i (normal)\n", pic.interrupt, pic.interrupt); exit(-1); - return -1; } pic.interrupt |= 0x40; /* Mark slave pending. */ @@ -711,7 +811,7 @@ pic_irq_ack(void) int picinterrupt(void) { - int i, ret = -1; + int ret = -1; if (pic.int_pending) { if (pic_slave_on(&pic, pic.interrupt)) { @@ -719,7 +819,6 @@ picinterrupt(void) /* If we are on AT, IRQ 2 is pending, and we cannot find a pending IRQ on PIC 2, fatal out. */ fatal("IRQ %i pending on AT without a pending IRQ on PIC %i (normal)\n", pic.interrupt, pic.interrupt); exit(-1); - return -1; } pic.interrupt |= 0x40; /* Mark slave pending. */ @@ -729,7 +828,7 @@ picinterrupt(void) pit_devs[1].set_gate(pit_devs[1].data, 0, 0); /* Two ACK's - do them in a loop to avoid potential compiler misoptimizations. */ - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { ret = pic_irq_ack_read(&pic, pic.ack_bytes); pic.ack_bytes = (pic.ack_bytes + 1) % (pic_i86_mode(&pic) ? 2 : 3); diff --git a/src/pit.c b/src/pit.c index 27e1beaad..648e0018b 100644 --- a/src/pit.c +++ b/src/pit.c @@ -41,23 +41,32 @@ #include <86box/sound.h> #include <86box/snd_speaker.h> #include <86box/video.h> +#include <86box/plat_unused.h> pit_intf_t pit_devs[2]; -double cpuclock, PITCONSTD, - SYSCLK, - isa_timing, - bus_timing, pci_timing, agp_timing, - PCICLK, AGPCLK; +double cpuclock; +double PITCONSTD; +double SYSCLK; +double isa_timing; +double bus_timing; +double pci_timing; +double agp_timing; +double PCICLK; +double AGPCLK; -uint64_t PITCONST, ISACONST, - CGACONST, - MDACONST, HERCCONST, - VGACONST1, VGACONST2, - RTCCONST, ACPICONST; +uint64_t PITCONST; +uint64_t ISACONST; +uint64_t CGACONST; +uint64_t MDACONST; +uint64_t HERCCONST; +uint64_t VGACONST1; +uint64_t VGACONST2; +uint64_t RTCCONST; +uint64_t ACPICONST; -int refresh_at_enable = 1, - io_delay = 5; +int refresh_at_enable = 1; +int io_delay = 5; int64_t firsttime = 1; @@ -131,6 +140,9 @@ ctr_load_count(ctr_t *ctr) pit_log("ctr->count = %i\n", l); ctr->null_count = 0; ctr->newcount = !!(l & 1); + + /* Undocumented feature - writing MSB after reload after writing LSB causes an instant reload. */ + ctr->incomplete = !!(ctr->wm & 0x80); } static void @@ -138,16 +150,13 @@ ctr_tick(ctr_t *ctr) { uint8_t state = ctr->state; - if (state == 1) { + if ((state & 0x03) == 0x01) { /* This is true for all modes */ ctr_load_count(ctr); - ctr->state = 2; - if ((ctr->m & 0x07) == 0x01) + ctr->state++; + if (((ctr->m & 0x07) == 0x01) && (ctr->state == 2)) ctr_set_out(ctr, 0); - return; - } - - switch (ctr->m & 0x07) { + } else switch (ctr->m & 0x07) { case 0: /* Interrupt on terminal count */ switch (state) { @@ -163,16 +172,14 @@ ctr_tick(ctr_t *ctr) case 3: ctr_decrease_count(ctr); break; + + default: + break; } break; case 1: /* Hardware retriggerable one-shot */ switch (state) { - case 1: - ctr_load_count(ctr); - ctr->state = 2; - ctr_set_out(ctr, 0); - break; case 2: if (ctr->count >= 1) { ctr_decrease_count(ctr); @@ -183,8 +190,12 @@ ctr_tick(ctr_t *ctr) } break; case 3: + case 6: ctr_decrease_count(ctr); break; + + default: + break; } break; case 2: @@ -207,6 +218,9 @@ ctr_tick(ctr_t *ctr) } } break; + + default: + break; } break; case 3: @@ -250,6 +264,9 @@ ctr_tick(ctr_t *ctr) ctr->newcount = 0; } break; + + default: + break; } break; case 4: @@ -259,6 +276,7 @@ ctr_tick(ctr_t *ctr) if ((ctr->gate != 0) || (ctr->m != 4)) { switch (state) { case 0: + case 6: ctr_decrease_count(ctr); break; case 2: @@ -274,6 +292,9 @@ ctr_tick(ctr_t *ctr) ctr->state = 0; ctr_set_out(ctr, 1); break; + + default: + break; } } break; @@ -302,9 +323,12 @@ static void ctr_set_state_1(ctr_t *ctr) { uint8_t mode = (ctr->m & 0x03); + int do_reload = !!ctr->incomplete || (mode == 0) || (ctr->state == 0); - if ((mode == 0) || ((mode > 1) && (ctr->state == 0))) - ctr->state = 1; + ctr->incomplete = 0; + + if (do_reload) + ctr->state = 1 + ((mode == 1) << 2); } static void @@ -361,6 +385,9 @@ ctr_latch_count(ctr_t *ctr) ctr->rl = count; ctr->latched = 2; break; + + default: + break; } pit_log("latched counter = %04X\n", ctr->rl & 0xffff); @@ -369,8 +396,8 @@ ctr_latch_count(ctr_t *ctr) uint16_t pit_ctr_get_count(void *data, int counter_id) { - pit_t *pit = (pit_t *) data; - ctr_t *ctr = &pit->counters[counter_id]; + const pit_t *pit = (pit_t *) data; + const ctr_t *ctr = &pit->counters[counter_id]; return (uint16_t) ctr->l; } @@ -431,6 +458,9 @@ pit_ctr_set_gate(void *data, int counter_id, int gate) ctr_set_out(ctr, 1); } break; + + default: + break; } } @@ -479,14 +509,13 @@ pit_ctr_set_using_timer(void *data, int counter_id, int using_timer) } static void -pit_timer_over(void *p) +pit_timer_over(void *priv) { - pit_t *dev = (pit_t *) p; - int i; + pit_t *dev = (pit_t *) priv; dev->clock ^= 1; - for (i = 0; i < 3; i++) + for (uint8_t i = 0; i < 3; i++) pit_ctr_set_clock_common(&dev->counters[i], dev->clock); timer_advance_u64(&dev->callback_timer, PITCONST >> 1ULL); @@ -595,17 +624,26 @@ pit_write(uint16_t addr, uint8_t val, void *priv) else ctr->wm |= 0x80; break; + + default: + break; } break; + + default: + break; } } +extern uint8_t *ram; + static uint8_t pit_read(uint16_t addr, void *priv) { pit_t *dev = (pit_t *) priv; uint8_t ret = 0xff; - int count, t = (addr & 3); + int count; + int t = (addr & 3); ctr_t *ctr; switch (addr & 3) { @@ -665,8 +703,14 @@ pit_read(uint16_t addr, void *priv) else ctr->rm |= 0x80; break; + + default: + break; } break; + + default: + break; } pit_log("[%04X:%08X] pit_read(%04X, %08X) = %02X\n", CS, cpu_state.pc, addr, priv, ret); @@ -704,7 +748,7 @@ pit_refresh_timer_at(int new_out, int old_out) } void -pit_speaker_timer(int new_out, int old_out) +pit_speaker_timer(int new_out, UNUSED(int old_out)) { int l; @@ -724,7 +768,7 @@ pit_speaker_timer(int new_out, int old_out) } void -pit_nmi_timer_ps2(int new_out, int old_out) +pit_nmi_timer_ps2(int new_out, UNUSED(int old_out)) { nmi = new_out; @@ -752,13 +796,11 @@ ctr_reset(ctr_t *ctr) void pit_reset(pit_t *dev) { - int i; - memset(dev, 0, sizeof(pit_t)); dev->clock = 0; - for (i = 0; i < 3; i++) + for (uint8_t i = 0; i < 3; i++) ctr_reset(&dev->counters[i]); /* Disable speaker gate. */ @@ -880,14 +922,13 @@ const device_t i8254_ps2_device = { pit_t * pit_common_init(int type, void (*out0)(int new_out, int old_out), void (*out1)(int new_out, int old_out)) { - int i; void *pit; pit_intf_t *pit_intf = &pit_devs[0]; switch (type) { - case PIT_8253: default: + case PIT_8253: pit = device_add(&i8253_device); *pit_intf = pit_classic_intf; break; @@ -907,7 +948,7 @@ pit_common_init(int type, void (*out0)(int new_out, int old_out), void (*out1)(i pit_intf->data = pit; - for (i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { pit_intf->set_gate(pit_intf->data, i, 1); pit_intf->set_using_timer(pit_intf->data, i, 1); } @@ -930,8 +971,8 @@ pit_ps2_init(int type) pit_intf_t *ps2_pit = &pit_devs[1]; switch (type) { - case PIT_8254: default: + case PIT_8254: pit = device_add(&i8254_ps2_device); *ps2_pit = pit_classic_intf; break; @@ -972,12 +1013,12 @@ pit_set_clock(int clock) cpuclock = (double) clock; PITCONSTD = (cpuclock / 1193182.0); - PITCONST = (uint64_t) (PITCONSTD * (double) (1ull << 32)); - CGACONST = (uint64_t) ((cpuclock / (19687503.0 / 11.0)) * (double) (1ull << 32)); - ISACONST = (uint64_t) ((cpuclock / (double) cpu_isa_speed) * (double) (1ull << 32)); + PITCONST = (uint64_t) (PITCONSTD * (double) (1ULL << 32)); + CGACONST = (uint64_t) ((cpuclock / (19687503.0 / 11.0)) * (double) (1ULL << 32)); + ISACONST = (uint64_t) ((cpuclock / (double) cpu_isa_speed) * (double) (1ULL << 32)); xt_cpu_multi = 1ULL; } else { - cpuclock = 14318184.0; + cpuclock = (157500000.0 / 11.0); PITCONSTD = 12.0; PITCONST = (12ULL << 32ULL); CGACONST = (8ULL << 32ULL); @@ -1022,8 +1063,8 @@ pit_set_clock(int clock) CGACONST = (16ULL << 32LL); } else if (cpuclock != 14318184.0) { PITCONSTD = (cpuclock / 1193182.0); - PITCONST = (uint64_t) (PITCONSTD * (double) (1ull << 32)); - CGACONST = (uint64_t) (((cpuclock / (19687503.0 / 11.0)) * (double) (1ull << 32))); + PITCONST = (uint64_t) (PITCONSTD * (double) (1ULL << 32)); + CGACONST = (uint64_t) ((cpuclock / (19687503.0 / 11.0)) * (double) (1ULL << 32)); } ISACONST = (1ULL << 32ULL); @@ -1033,13 +1074,13 @@ pit_set_clock(int clock) /* Delay for empty I/O ports. */ io_delay = (int) round(((double) cpu_s->rspeed) / 3000000.0); - MDACONST = (uint64_t) (cpuclock / 2032125.0 * (double) (1ull << 32)); + MDACONST = (uint64_t) (cpuclock / 2032125.0 * (double) (1ULL << 32)); HERCCONST = MDACONST; - VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double) (1ull << 32)); - VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double) (1ull << 32)); - RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double) (1ull << 32)); + VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double) (1ULL << 32)); + VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double) (1ULL << 32)); + RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double) (1ULL << 32)); - TIMER_USEC = (uint64_t) ((cpuclock / 1000000.0) * (double) (1ull << 32)); + TIMER_USEC = (uint64_t) ((cpuclock / 1000000.0) * (double) (1ULL << 32)); isa_timing = (cpuclock / (double) cpu_isa_speed); if (cpu_64bitbus) diff --git a/src/pit_fast.c b/src/pit_fast.c index dac71aaec..80e359eee 100644 --- a/src/pit_fast.c +++ b/src/pit_fast.c @@ -91,8 +91,9 @@ pitf_ctr_set_load_func(void *data, int counter_id, void (*func)(uint8_t new_m, i static uint16_t pitf_ctr_get_count(void *data, int counter_id) { - pitf_t *pit = (pitf_t *) data; - ctrf_t *ctr = &pit->counters[counter_id]; + const pitf_t *pit = (pitf_t *) data; + const ctrf_t *ctr = &pit->counters[counter_id]; + return (uint16_t) ctr->l; } @@ -207,6 +208,9 @@ pitf_ctr_load(ctrf_t *ctr) case 5: /*Hardware triggered stobe*/ ctr->enabled = 1; break; + + default: + break; } if (ctr->load_func != NULL) @@ -266,6 +270,9 @@ pitf_set_gate_no_timer(ctrf_t *ctr, int gate) } ctr->enabled = gate; break; + + default: + break; } ctr->gate = gate; ctr->running = ctr->enabled && ctr->using_timer && !ctr->disabled; @@ -327,7 +334,10 @@ pitf_over(ctrf_t *ctr) if (ctr->using_timer) timer_advance_u64(&ctr->timer, (uint64_t) (((l + 1) >> 1) * PITCONST)); } - // if (!t) pclog("pit_over: square wave mode c=%x %lli %f\n", pit.c[t], tsc, PITCONST); +#if 0 + if (!t) + pclog("pit_over: square wave mode c=%x %lli %f\n", pit.c[t], tsc, PITCONST); +#endif break; case 4: /*Software triggered strove*/ if (!ctr->thit) { @@ -356,6 +366,9 @@ pitf_over(ctrf_t *ctr) if (ctr->using_timer) timer_advance_u64(&ctr->timer, (uint64_t) (0xffff * PITCONST)); break; + + default: + break; } ctr->running = ctr->enabled && ctr->using_timer && !ctr->disabled; if (ctr->using_timer && !ctr->running) @@ -366,8 +379,10 @@ static __inline void pitf_ctr_latch_count(ctrf_t *ctr) { ctr->rl = pitf_read_timer(ctr); - // pclog("Timer latch %f %04X %04X\n",pit->c[0],pit->rl[0],pit->l[0]); - // pit->ctrl |= 0x30; +#if 0 + pclog("Timer latch %f %04X %04X\n",pit->c[0],pit->rl[0],pit->l[0]); + pit->ctrl |= 0x30; +#endif ctr->rereadlatch = 0; ctr->rm = 3; ctr->latched = 1; @@ -472,8 +487,14 @@ pitf_write(uint16_t addr, uint8_t val, void *priv) ctr->l |= val; ctr->wm = 0; break; + + default: + break; } break; + + default: + break; } } @@ -530,8 +551,14 @@ pitf_read(uint16_t addr, void *priv) else ctr->rm = 0; break; + + default: + break; } break; + + default: + break; } pit_log("[%04X:%08X] pit_read(%04X, %08X) = %02X\n", CS, cpu_state.pc, addr, priv, ret); @@ -540,9 +567,9 @@ pitf_read(uint16_t addr, void *priv) } static void -pitf_timer_over(void *p) +pitf_timer_over(void *priv) { - ctrf_t *ctr = (ctrf_t *) p; + ctrf_t *ctr = (ctrf_t *) priv; pitf_over(ctr); } @@ -577,11 +604,9 @@ ctr_reset(ctrf_t *ctr) static void pitf_reset(pitf_t *dev) { - int i; - memset(dev, 0, sizeof(pitf_t)); - for (i = 0; i < 3; i++) + for (uint8_t i = 0; i < 3; i++) ctr_reset(&dev->counters[i]); /* Disable speaker gate. */ diff --git a/src/port_6x.c b/src/port_6x.c index 88d8820b7..340d6df2b 100644 --- a/src/port_6x.c +++ b/src/port_6x.c @@ -36,6 +36,7 @@ #include <86box/ppi.h> #include <86box/video.h> #include <86box/port_6x.h> +#include <86box/plat_unused.h> #define PS2_REFRESH_TIME (16 * TIMER_USEC) @@ -47,7 +48,7 @@ static void port_6x_write(uint16_t port, uint8_t val, void *priv) { - port_6x_t *dev = (port_6x_t *) priv; + const port_6x_t *dev = (port_6x_t *) priv; port &= 3; @@ -68,25 +69,28 @@ port_6x_write(uint16_t port, uint8_t val, void *priv) if (dev->flags & PORT_6X_TURBO) xi8088_turbo_set(!!(val & 0x04)); break; + + default: + break; } } static uint8_t -port_61_read_simple(uint16_t port, void *priv) +port_61_read_simple(UNUSED(uint16_t port), UNUSED(void *priv)) { uint8_t ret = ppi.pb & 0x1f; if (ppispeakon) ret |= 0x20; - return (ret); + return ret; } static uint8_t -port_61_read(uint16_t port, void *priv) +port_61_read(UNUSED(uint16_t port), void *priv) { - port_6x_t *dev = (port_6x_t *) priv; - uint8_t ret = 0xff; + const port_6x_t *dev = (port_6x_t *) priv; + uint8_t ret = 0xff; if (dev->flags & PORT_6X_EXT_REF) { ret = ppi.pb & 0x0f; @@ -102,11 +106,11 @@ port_61_read(uint16_t port, void *priv) if (dev->flags & PORT_6X_TURBO) ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00); - return (ret); + return ret; } static uint8_t -port_62_read(uint16_t port, void *priv) +port_62_read(UNUSED(uint16_t port), UNUSED(void *priv)) { uint8_t ret = 0xff; @@ -114,8 +118,8 @@ port_62_read(uint16_t port, void *priv) ret = 0x00; if (ppi.pb & 0x8) { /* Switches 4, 5 - floppy drives (number) */ - int i, fdd_count = 0; - for (i = 0; i < FDD_NUM; i++) { + int fdd_count = 0; + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -138,7 +142,7 @@ port_62_read(uint16_t port, void *priv) ret |= 0x02; } - return (ret); + return ret; } static void diff --git a/src/port_92.c b/src/port_92.c index cbc419569..1307ecba9 100644 --- a/src/port_92.c +++ b/src/port_92.c @@ -29,6 +29,7 @@ #include <86box/mem.h> #include <86box/pit.h> #include <86box/port_92.h> +#include <86box/plat_unused.h> #define PORT_92_INV 1 #define PORT_92_WORD 2 @@ -39,8 +40,8 @@ static uint8_t port_92_readb(uint16_t port, void *priv) { - uint8_t ret = 0x00; - port_92_t *dev = (port_92_t *) priv; + uint8_t ret = 0x00; + const port_92_t *dev = (port_92_t *) priv; if (port == 0x92) { /* Return bit 1 directly from mem_a20_alt, so the @@ -60,8 +61,8 @@ port_92_readb(uint16_t port, void *priv) static uint16_t port_92_readw(uint16_t port, void *priv) { - uint16_t ret = 0xffff; - port_92_t *dev = (port_92_t *) priv; + uint16_t ret = 0xffff; + const port_92_t *dev = (port_92_t *) priv; if (!(dev->flags & PORT_92_PCI)) ret = port_92_readb(port, priv); @@ -69,11 +70,18 @@ port_92_readw(uint16_t port, void *priv) return ret; } +/* + This does the exact same thing as keyboard controller reset. + TODO: ALi M1543(c) behavior. + */ static void -port_92_pulse(void *priv) +port_92_pulse(UNUSED(void *priv)) { - resetx86(); + softresetx86(); /* Pulse reset! */ cpu_set_edx(); + flushmmucache(); + + cpu_alt_reset = 1; } static void @@ -105,7 +113,7 @@ port_92_writeb(uint16_t port, uint8_t val, void *priv) static void port_92_writew(uint16_t port, uint16_t val, void *priv) { - port_92_t *dev = (port_92_t *) priv; + const port_92_t *dev = (port_92_t *) priv; if (!(dev->flags & PORT_92_PCI)) port_92_writeb(port, val & 0xff, priv); @@ -166,6 +174,15 @@ port_92_remove(void *priv) port_92_readb, NULL, NULL, port_92_writeb, NULL, NULL, dev); } +static void +port_92_reset(UNUSED(void *priv)) +{ + cpu_alt_reset = 0; + + mem_a20_alt = 0x00; + mem_a20_recalc(); +} + static void port_92_close(void *priv) { @@ -252,7 +269,7 @@ const device_t port_92_pci_device = { .local = PORT_92_PCI, .init = port_92_init, .close = port_92_close, - .reset = NULL, + .reset = port_92_reset, { .available = NULL }, .speed_changed = NULL, .force_redraw = NULL, diff --git a/src/printer/CMakeLists.txt b/src/printer/CMakeLists.txt index ef7b1d5ec..dea0c7fbe 100644 --- a/src/printer/CMakeLists.txt +++ b/src/printer/CMakeLists.txt @@ -14,3 +14,21 @@ # add_library(print OBJECT png.c prt_cpmap.c prt_escp.c prt_text.c prt_ps.c) + +if(APPLE) + find_library(GHOSTSCRIPT_LIB gs) + if (NOT GHOSTSCRIPT_LIB) + message(WARNING "Could not find ghostscript. The library will not be bundled and any related features will not work.") + endif() +endif() + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FREETYPE REQUIRED IMPORTED_TARGET freetype2) +target_link_libraries(86Box PkgConfig::FREETYPE) +if(STATIC_BUILD) + if(QT) + # Qt provides its own version of harfbuzz which leads to duplicated symbols. + target_link_options(86Box PRIVATE "LINKER:--allow-multiple-definition") + endif() + target_link_libraries(86Box -static ${FREETYPE_STATIC_LIBRARIES}) +endif() diff --git a/src/printer/png.c b/src/printer/png.c index bb862a953..c7443252b 100644 --- a/src/printer/png.c +++ b/src/printer/png.c @@ -92,13 +92,13 @@ png_log(const char *fmt, ...) #endif static void -error_handler(png_structp arg, const char *str) +error_handler(UNUSED(png_structp arg), UNUSED(const char *str)) { png_log("PNG: stream 0x%08lx error '%s'\n", arg, str); } static void -warning_handler(png_structp arg, const char *str) +warning_handler(UNUSED(png_structp arg), UNUSED(const char *str)) { png_log("PNG: stream 0x%08lx warning '%s'\n", arg, str); } @@ -110,7 +110,6 @@ png_write_gray(char *fn, int inv, uint8_t *pix, int16_t w, int16_t h) png_structp png = NULL; png_infop info = NULL; png_bytep row; - int16_t x, y; FILE *fp; /* Create the image file. */ @@ -127,7 +126,7 @@ error: (&png, &info); if (fp != NULL) (void) fclose(fp); - return (0); + return 0; } /* Initialize PNG stuff. */ @@ -159,8 +158,8 @@ error: row = (png_bytep) malloc(PNGFUNC(get_rowbytes)(png, info)); /* Process all scanlines in the image. */ - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { + for (int16_t y = 0; y < h; y++) { + for (int16_t x = 0; x < w; x++) { /* Copy the pixel data. */ if (inv) row[x] = 255 - pix[(y * w) + x]; @@ -185,7 +184,7 @@ error: /* Clean up. */ (void) fclose(fp); - return (1); + return 1; } /* Write the given BITMAP-format image as an 8-bit RGBA PNG image file. */ @@ -197,7 +196,6 @@ png_write_rgb(char *fn, uint8_t *pix, int16_t w, int16_t h, uint16_t pitch, PALE png_bytep *rows; png_color palette[256]; FILE *fp; - int i; /* Create the image file. */ fp = plat_fopen(fn, "wb"); @@ -249,7 +247,7 @@ error: PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - for (i = 0; i < 256; i++) { + for (uint16_t i = 0; i < 256; i++) { palette[i].red = palcol[i].r; palette[i].green = palcol[i].g; palette[i].blue = palcol[i].b; @@ -260,7 +258,7 @@ error: /* Create a buffer for scanlines of pixels. */ rows = (png_bytep *) malloc(sizeof(png_bytep) * h); - for (i = 0; i < h; i++) { + for (int16_t i = 0; i < h; i++) { /* Create a buffer for this scanline. */ rows[i] = (pix + (i * pitch)); } diff --git a/src/printer/prt_cpmap.c b/src/printer/prt_cpmap.c index ba9e71085..153008f35 100644 --- a/src/printer/prt_cpmap.c +++ b/src/printer/prt_cpmap.c @@ -572,7 +572,7 @@ static const struct { void select_codepage(uint16_t code, uint16_t *curmap) { - int i = 0; + uint16_t i = 0; const uint16_t *map_to_use; map_to_use = maps[0].map; @@ -585,6 +585,6 @@ select_codepage(uint16_t code, uint16_t *curmap) i++; } - for (i = 0; i < 256; i++) - curmap[i] = map_to_use[i]; + for (uint16_t j = 0; j < 256; j++) + curmap[j] = map_to_use[j]; } diff --git a/src/printer/prt_escp.c b/src/printer/prt_escp.c index 1cca57da0..612a07cac 100644 --- a/src/printer/prt_escp.c +++ b/src/printer/prt_escp.c @@ -65,7 +65,6 @@ #include <86box/pit.h> #include <86box/path.h> #include <86box/plat.h> -#include <86box/plat_dynld.h> #include <86box/ui.h> #include <86box/lpt.h> #include <86box/video.h> @@ -85,45 +84,8 @@ #define PAGE_CPI 10.0 /* standard 10 cpi */ #define PAGE_LPI 6.0 /* standard 6 lpi */ -#ifdef _WIN32 -# define PATH_FREETYPE_DLL "freetype.dll" -#elif defined __APPLE__ -# define PATH_FREETYPE_DLL "libfreetype.6.dylib" -#else -# define PATH_FREETYPE_DLL "libfreetype.so.6" -#endif - /* FreeType library handles - global so they can be shared. */ -FT_Library ft_lib = NULL; -void *ft_handle = NULL; - -static int (*ft_Init_FreeType)(FT_Library *alibrary); -static int (*ft_Done_Face)(FT_Face face); -static int (*ft_New_Face)(FT_Library library, const char *filepathname, - FT_Long face_index, FT_Face *aface); -static int (*ft_Set_Char_Size)(FT_Face face, FT_F26Dot6 char_width, - FT_F26Dot6 char_height, - FT_UInt horz_resolution, - FT_UInt vert_resolution); -static int (*ft_Set_Transform)(FT_Face face, FT_Matrix *matrix, - FT_Vector *delta); -static int (*ft_Get_Char_Index)(FT_Face face, FT_ULong charcode); -static int (*ft_Load_Glyph)(FT_Face face, FT_UInt glyph_index, - FT_Int32 load_flags); -static int (*ft_Render_Glyph)(FT_GlyphSlot slot, - FT_Render_Mode render_mode); - -static dllimp_t ft_imports[] = { - {"FT_Init_FreeType", &ft_Init_FreeType }, - { "FT_New_Face", &ft_New_Face }, - { "FT_Done_Face", &ft_Done_Face }, - { "FT_Set_Char_Size", &ft_Set_Char_Size }, - { "FT_Set_Transform", &ft_Set_Transform }, - { "FT_Get_Char_Index", &ft_Get_Char_Index}, - { "FT_Load_Glyph", &ft_Load_Glyph }, - { "FT_Render_Glyph", &ft_Render_Glyph }, - { NULL, NULL } -}; +FT_Library ft_lib = NULL; /* The fonts. */ #define FONT_DEFAULT 0 @@ -181,7 +143,7 @@ static dllimp_t ft_imports[] = { #define PIXX ((unsigned) floor(dev->curr_x * dev->dpi + 0.5)) #define PIXY ((unsigned) floor(dev->curr_y * dev->dpi + 0.5)) -typedef struct { +typedef struct psurface_t { int8_t dirty; /* has the page been printed on? */ char pad; @@ -192,7 +154,7 @@ typedef struct { uint8_t *pixels; /* grayscale pixel data */ } psurface_t; -typedef struct { +typedef struct escp_t { const char *name; void *lpt; @@ -204,12 +166,12 @@ typedef struct { uint8_t color; /* page data (TODO: make configurable) */ - double page_width, /* all in inches */ - page_height, - left_margin, - top_margin, - right_margin, - bottom_margin; + double page_width; /* all in inches */ + double page_height; + double left_margin; + double top_margin; + double right_margin; + double bottom_margin; uint16_t dpi; double cpi; /* defined chars per inch */ double lpi; /* defined lines per inch */ @@ -255,7 +217,8 @@ typedef struct { char fontpath[1024]; char pagepath[1024]; psurface_t *page; - double curr_x, curr_y; /* print head position (inch) */ + double curr_x; /* print head position (x, inch) */ + double curr_y; /* print head position (y, inch) */ uint16_t current_font; FT_Face fontface; int8_t lq_typeface; @@ -442,7 +405,6 @@ static void fill_palette(uint8_t redmax, uint8_t greenmax, uint8_t bluemax, uint8_t colorID, escp_t *dev) { uint8_t colormask; - int i; double red = (double) redmax / (double) 30.9; double green = (double) greenmax / (double) 30.9; @@ -450,7 +412,7 @@ fill_palette(uint8_t redmax, uint8_t greenmax, uint8_t bluemax, uint8_t colorID, colormask = colorID <<= 5; - for (i = 0; i < 32; i++) { + for (uint8_t i = 0; i < 32; i++) { dev->palcol[i + colormask].r = 255 - (uint8_t) floor(red * (double) i); dev->palcol[i + colormask].g = 255 - (uint8_t) floor(green * (double) i); dev->palcol[i + colormask].b = 255 - (uint8_t) floor(blue * (double) i); @@ -460,8 +422,6 @@ fill_palette(uint8_t redmax, uint8_t greenmax, uint8_t bluemax, uint8_t colorID, static void reset_printer(escp_t *dev) { - int i; - /* TODO: these should be configurable. */ dev->color = COLOR_BLACK; dev->curr_x = dev->curr_y = 0.0; @@ -501,7 +461,7 @@ reset_printer(escp_t *dev) new_page(dev, 0, 1); - for (i = 0; i < 32; i++) + for (uint8_t i = 0; i < 32; i++) dev->horizontal_tabs[i] = i * 8.0 * (1.0 / dev->cpi); dev->num_horizontal_tabs = 32; dev->num_vertical_tabs = -1; @@ -534,11 +494,11 @@ init_codepage(escp_t *dev, uint16_t num) static void update_font(escp_t *dev) { - char path[1024]; - char *fn; - FT_Matrix matrix; - double hpoints = 10.5; - double vpoints = 10.5; + char path[1024]; + const char *fn; + FT_Matrix matrix; + double hpoints = 10.5; + double vpoints = 10.5; /* We need the FreeType library. */ if (ft_lib == NULL) @@ -546,7 +506,7 @@ update_font(escp_t *dev) /* Release current font if we have one. */ if (dev->fontface) - ft_Done_Face(dev->fontface); + FT_Done_Face(dev->fontface); if (dev->print_quality == QUALITY_DRAFT) fn = FONT_FILE_DOTMATRIX; @@ -582,7 +542,7 @@ update_font(escp_t *dev) escp_log("Temp file=%s\n", path); /* Load the new font. */ - if (ft_New_Face(ft_lib, path, 0, &dev->fontface)) { + if (FT_New_Face(ft_lib, path, 0, &dev->fontface)) { escp_log("ESC/P: unable to load font '%s'\n", path); dev->fontface = NULL; } @@ -628,7 +588,7 @@ update_font(escp_t *dev) dev->actual_cpi /= 2.0 / 3.0; } - ft_Set_Char_Size(dev->fontface, + FT_Set_Char_Size(dev->fontface, (uint16_t) (hpoints * 64), (uint16_t) (vpoints * 64), dev->dpi, dev->dpi); @@ -638,7 +598,7 @@ update_font(escp_t *dev) matrix.xy = (FT_Fixed) (0.20 * 0x10000L); matrix.yx = 0; matrix.yy = 0x10000L; - ft_Set_Transform(dev->fontface, &matrix, 0); + FT_Set_Transform(dev->fontface, &matrix, 0); } } @@ -646,11 +606,13 @@ update_font(escp_t *dev) static int process_char(escp_t *dev, uint8_t ch) { - double new_x, new_y; + double new_x; + double new_y; double move_to; double unit_size; double reverse; - double new_top, new_bottom; + double new_top; + double new_bottom; uint16_t rel_move; int16_t i; @@ -788,7 +750,6 @@ process_char(escp_t *dev, uint8_t ch) case 0x2e: fatal("ESC/P: Print Raster Graphics (2E) command is not implemented.\nTerminating the emulator to avoid endless PNG generation.\n"); exit(-1); - return 1; default: escp_log("ESC/P: Unknown command ESC %c (0x%02x). Unable to skip parameters.\n", @@ -1501,7 +1462,9 @@ process_char(escp_t *dev, uint8_t ch) dev->curr_x = dev->left_margin; if (!dev->autofeed) return 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x0a: /* Line feed */ if (dev->font_style & STYLE_DOUBLEWIDTHONELINE) { @@ -1562,19 +1525,19 @@ process_char(escp_t *dev, uint8_t ch) return 1; default: + /* This is a printable character -> print it. */ return 0; } - - /* This is a printable character -> print it. */ - return 0; } static void handle_char(escp_t *dev, uint8_t ch) { FT_UInt char_index; - uint16_t pen_x, pen_y; - uint16_t line_start, line_y; + uint16_t pen_x; + uint16_t pen_y; + uint16_t line_start; + uint16_t line_y; double x_advance; if (dev->page == NULL) @@ -1612,9 +1575,9 @@ handle_char(escp_t *dev, uint8_t ch) /* ok, so we need to print the character now */ if (ft_lib) { - char_index = ft_Get_Char_Index(dev->fontface, dev->curr_cpmap[ch]); - ft_Load_Glyph(dev->fontface, char_index, FT_LOAD_DEFAULT); - ft_Render_Glyph(dev->fontface->glyph, FT_RENDER_MODE_NORMAL); + char_index = FT_Get_Char_Index(dev->fontface, dev->curr_cpmap[ch]); + FT_Load_Glyph(dev->fontface, char_index, FT_LOAD_DEFAULT); + FT_Render_Glyph(dev->fontface->glyph, FT_RENDER_MODE_NORMAL); } pen_x = PIXX + dev->fontface->glyph->bitmap_left; @@ -1688,16 +1651,16 @@ handle_char(escp_t *dev, uint8_t ch) static void blit_glyph(escp_t *dev, unsigned destx, unsigned desty, int8_t add) { - FT_Bitmap *bitmap = &dev->fontface->glyph->bitmap; - unsigned x, y; - uint8_t src, *dst; + const FT_Bitmap *bitmap = &dev->fontface->glyph->bitmap; + uint8_t src; + uint8_t *dst; /* check if freetype is available */ if (ft_lib == NULL) return; - for (y = 0; y < bitmap->rows; y++) { - for (x = 0; x < bitmap->width; x++) { + for (unsigned int y = 0; y < bitmap->rows; y++) { + for (unsigned int x = 0; x < bitmap->width; x++) { src = *(bitmap->buffer + x + y * bitmap->pitch); /* ignore background, and respect page size */ if (src > 0 && (destx + x < (unsigned) dev->page->w) && (desty + y < (unsigned) dev->page->h)) { @@ -1724,9 +1687,8 @@ draw_hline(escp_t *dev, unsigned from_x, unsigned to_x, unsigned y, int8_t broke { unsigned breakmod = dev->dpi / 15; unsigned gapstart = (breakmod * 4) / 5; - unsigned x; - for (x = from_x; x <= to_x; x++) { + for (unsigned int x = from_x; x <= to_x; x++) { /* Skip parts if broken line or going over the border. */ if ((!broken || (x % breakmod <= gapstart)) && (x < dev->page->w)) { if (y > 0 && (y - 1) < dev->page->h) @@ -1856,7 +1818,6 @@ print_bit_graph(escp_t *dev, uint8_t ch) { uint8_t pixel_w; /* width of the "pixel" */ uint8_t pixel_h; /* height of the "pixel" */ - unsigned i, j, xx, yy; double old_y; dev->bg_column[dev->bg_bytes_read++] = ch; @@ -1877,14 +1838,14 @@ print_bit_graph(escp_t *dev, uint8_t ch) pixel_h = dev->dpi / dev->bg_v_density > 0 ? dev->dpi / dev->bg_v_density : 1; } - for (i = 0; i < dev->bg_bytes_per_column; i++) { + for (uint8_t i = 0; i < dev->bg_bytes_per_column; i++) { /* for each byte */ - for (j = 128; j != 0; j >>= 1) { + for (uint8_t j = 128; j != 0; j >>= 1) { /* for each bit */ if (dev->bg_column[i] & j) { /* draw a "pixel" */ - for (xx = 0; xx < pixel_w; xx++) { - for (yy = 0; yy < pixel_h; yy++) { + for (uint8_t xx = 0; xx < pixel_w; xx++) { + for (uint8_t yy = 0; yy < pixel_h; yy++) { if (((PIXX + xx) < (unsigned) dev->page->w) && ((PIXY + yy) < (unsigned) dev->page->h)) *((uint8_t *) dev->page->pixels + (PIXX + xx) + (PIXY + yy) * dev->page->pitch) |= (dev->color | 0x1f); } @@ -1959,7 +1920,7 @@ write_ctrl(uint8_t val, void *priv) static uint8_t read_data(void *priv) { - escp_t *dev = (escp_t *) priv; + const escp_t *dev = (escp_t *) priv; return dev->data; } @@ -1967,7 +1928,7 @@ read_data(void *priv) static uint8_t read_ctrl(void *priv) { - escp_t *dev = (escp_t *) priv; + const escp_t *dev = (escp_t *) priv; return 0xe0 | (dev->autofeed ? 0x02 : 0x00) | (dev->ctrl & 0xfd); } @@ -1975,7 +1936,7 @@ read_ctrl(void *priv) static uint8_t read_status(void *priv) { - escp_t *dev = (escp_t *) priv; + const escp_t *dev = (escp_t *) priv; uint8_t ret = 0x1f; ret |= 0x80; @@ -1983,30 +1944,18 @@ read_status(void *priv) if (!dev->ack) ret |= 0x40; - return (ret); + return ret; } static void * escp_init(void *lpt) { - const char *fn = PATH_FREETYPE_DLL; - escp_t *dev; - int i; - - /* Dynamically load FreeType. */ - if (ft_handle == NULL) { - ft_handle = dynld_module(fn, ft_imports); - if (ft_handle == NULL) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2111, (wchar_t *) IDS_2132); - return (NULL); - } - } + escp_t *dev; /* Initialize FreeType. */ if (ft_lib == NULL) { - if (ft_Init_FreeType(&ft_lib)) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2111, (wchar_t *) IDS_2132); - dynld_close(ft_lib); + if (FT_Init_FreeType(&ft_lib)) { + pclog("ESC/P: FT_Init_FreeType failed\n"); ft_lib = NULL; return (NULL); } @@ -2047,7 +1996,7 @@ escp_init(void *lpt) memset(dev->page->pixels, 0x00, (size_t) dev->page->pitch * dev->page->h); /* Initialize parameters. */ - for (i = 0; i < 32; i++) { + for (uint8_t i = 0; i < 32; i++) { dev->palcol[i].r = 255; dev->palcol[i].g = 255; dev->palcol[i].b = 255; @@ -2082,7 +2031,7 @@ escp_init(void *lpt) timer_add(&dev->pulse_timer, pulse_timer, dev, 0); timer_add(&dev->timeout_timer, timeout_timer, dev, 0); - return (dev); + return dev; } static void diff --git a/src/printer/prt_ps.c b/src/printer/prt_ps.c index 0de04926d..c0e3958b2 100644 --- a/src/printer/prt_ps.c +++ b/src/printer/prt_ps.c @@ -51,13 +51,14 @@ #elif defined __APPLE__ # define PATH_GHOSTSCRIPT_DLL "libgs.dylib" #else -# define PATH_GHOSTSCRIPT_DLL "libgs.so.9" +# define PATH_GHOSTSCRIPT_DLL "libgs.so.9" +# define PATH_GHOSTSCRIPT_DLL_ALT1 "libgs.so.10" +# define PATH_GHOSTSCRIPT_DLL_ALT2 "libgs.so" #endif #define POSTSCRIPT_BUFFER_LENGTH 65536 -typedef struct -{ +typedef struct ps_t { const char *name; void *lpt; @@ -143,7 +144,9 @@ convert_to_pdf(ps_t *dev) { volatile int code; void *instance = NULL; - char input_fn[1024], output_fn[1024], *gsargv[9]; + char input_fn[1024]; + char output_fn[1024]; + char *gsargv[9]; strcpy(input_fn, dev->printer_path); path_slash(input_fn); @@ -234,9 +237,9 @@ timeout_timer(void *priv) } static void -ps_write_data(uint8_t val, void *p) +ps_write_data(uint8_t val, void *priv) { - ps_t *dev = (ps_t *) p; + ps_t *dev = (ps_t *) priv; if (dev == NULL) return; @@ -283,9 +286,9 @@ process_data(ps_t *dev) } static void -ps_write_ctrl(uint8_t val, void *p) +ps_write_ctrl(uint8_t val, void *priv) { - ps_t *dev = (ps_t *) p; + ps_t *dev = (ps_t *) priv; if (dev == NULL) return; @@ -315,15 +318,15 @@ ps_write_ctrl(uint8_t val, void *p) } static uint8_t -ps_read_status(void *p) +ps_read_status(void *priv) { - ps_t *dev = (ps_t *) p; - uint8_t ret = 0x9f; + const ps_t *dev = (ps_t *) priv; + uint8_t ret = 0x9f; if (!dev->ack) ret |= 0x40; - return (ret); + return ret; } static void * @@ -339,12 +342,21 @@ ps_init(void *lpt) /* Try loading the DLL. */ ghostscript_handle = dynld_module(PATH_GHOSTSCRIPT_DLL, ghostscript_imports); - if (ghostscript_handle == NULL) +#ifdef PATH_GHOSTSCRIPT_DLL_ALT1 + if (ghostscript_handle == NULL) { + ghostscript_handle = dynld_module(PATH_GHOSTSCRIPT_DLL_ALT1, ghostscript_imports); +# ifdef PATH_GHOSTSCRIPT_DLL_ALT2 + if (ghostscript_handle == NULL) + ghostscript_handle = dynld_module(PATH_GHOSTSCRIPT_DLL_ALT2, ghostscript_imports); +# endif + } +#endif + if (ghostscript_handle == NULL) { ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2115, (wchar_t *) IDS_2133); - else { - if (gsapi_revision(&rev, sizeof(rev)) == 0) + } else { + if (gsapi_revision(&rev, sizeof(rev)) == 0) { pclog("Loaded %s, rev %ld (%ld)\n", rev.product, rev.revision, rev.revisiondate); - else { + } else { dynld_close(ghostscript_handle); ghostscript_handle = NULL; } @@ -362,13 +374,13 @@ ps_init(void *lpt) reset_ps(dev); - return (dev); + return dev; } static void -ps_close(void *p) +ps_close(void *priv) { - ps_t *dev = (ps_t *) p; + ps_t *dev = (ps_t *) priv; if (dev == NULL) return; diff --git a/src/printer/prt_text.c b/src/printer/prt_text.c index 506261ccf..e1183f0c0 100644 --- a/src/printer/prt_text.c +++ b/src/printer/prt_text.c @@ -81,7 +81,7 @@ #define PAGE_CPI 10.0 /* standard 10 cpi */ #define PAGE_LPI 6.0 /* standard 6 lpi */ -typedef struct { +typedef struct psurface_t { int8_t dirty; /* has the page been printed on? */ char pad; @@ -91,7 +91,7 @@ typedef struct { char *chars; /* character data */ } psurface_t; -typedef struct { +typedef struct prnt_t { const char *name; void *lpt; @@ -104,23 +104,23 @@ typedef struct { pc_timer_t timeout_timer; /* page data (TODO: make configurable) */ - double page_width, /* all in inches */ - page_height, - left_margin, - top_margin, - right_margin, - bot_margin; + double page_width; /* all in inches */ + double page_height; + double left_margin; + double top_margin; + double right_margin; + double bot_margin; /* internal page data */ psurface_t *page; - uint8_t max_chars, - max_lines; - uint8_t curr_x, /* print head position (chars) */ - curr_y; + uint8_t max_chars; + uint8_t max_lines; + uint8_t curr_x; /* print head position (x, chars) */ + uint8_t curr_y; /* print head position (y, chars) */ /* font data */ - double cpi, /* defined chars per inch */ - lpi; /* defined lines per inch */ + double cpi; /* defined chars per inch */ + double lpi; /* defined lines per inch */ /* handshake data */ uint8_t data; @@ -138,7 +138,6 @@ static void dump_page(prnt_t *dev) { char path[1024]; - uint16_t x, y; uint8_t ch; FILE *fp; @@ -162,8 +161,8 @@ dump_page(prnt_t *dev) if (ftell(fp) != 0) fputc('\014', fp); - for (y = 0; y < dev->curr_y; y++) { - for (x = 0; x < dev->page->w; x++) { + for (uint16_t y = 0; y < dev->curr_y; y++) { + for (uint16_t x = 0; x < dev->page->w; x++) { ch = dev->page->chars[(y * dev->page->w) + x]; if (ch == 0x00) { /* End of line marker. */ @@ -284,7 +283,9 @@ process_char(prnt_t *dev, uint8_t ch) dev->curr_x = 0; if (!dev->autofeed) return 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x0a: /* Line feed */ dev->curr_x = 0; @@ -329,7 +330,7 @@ process_char(prnt_t *dev, uint8_t ch) } /* Just a printable character. */ - return (0); + return 0; } static void @@ -408,15 +409,15 @@ write_ctrl(uint8_t val, void *priv) static uint8_t read_status(void *priv) { - prnt_t *dev = (prnt_t *) priv; - uint8_t ret = 0x1f; + const prnt_t *dev = (prnt_t *) priv; + uint8_t ret = 0x1f; ret |= 0x80; if (!dev->ack) ret |= 0x40; - return (ret); + return ret; } static void * @@ -443,7 +444,7 @@ prnt_init(void *lpt) timer_add(&dev->pulse_timer, pulse_timer, dev, 0); timer_add(&dev->timeout_timer, timeout_timer, dev, 0); - return (dev); + return dev; } static void diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 1cb26a239..7ef93b4c0 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -239,7 +239,6 @@ if (APPLE) if (NOT MOLTENVK_LIB) message(FATAL_ERROR "Could not find MoltenVK library") endif() - target_link_libraries(ui PRIVATE "${MOLTENVK_LIB}") endif() endif() @@ -299,7 +298,7 @@ endif() # loads a macro to install Qt5 plugins on macOS # based on https://stackoverflow.com/questions/35612687/cmake-macos-x-bundle-with-bundleutiliies-for-qt-application -macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var _prefix) +macro(install_qt5_plugin _qt_plugin_name _runtime_plugins_var _prefix) get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION) if(EXISTS "${_qt_plugin_path}") get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME) @@ -307,12 +306,26 @@ macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var _prefix) get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME) set(_qt_plugin_dest "${_prefix}/PlugIns/${_qt_plugin_type}") install(FILES "${_qt_plugin_path}" DESTINATION "${_qt_plugin_dest}") - list(APPEND ${_qt_plugins_var} "\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/${_qt_plugin_dest}/${_qt_plugin_file}") + list(APPEND ${_runtime_plugins_var} "\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/${_qt_plugin_dest}/${_qt_plugin_file}") else() message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found") endif() endmacro() +macro(install_bundle_library _library_path _installed_name _runtime_plugins_var _prefix) + if(EXISTS "${_library_path}") + file(REAL_PATH "${_library_path}" _lib_resolved) + if(EXISTS "${_lib_resolved}") + install(FILES "${_lib_resolved}" DESTINATION "${_prefix}" RENAME "${_installed_name}") + list(APPEND ${_runtime_plugins_var} "\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/${_prefix}/${_installed_name}") + else() + message(WARNING "Library ${_installed_name} will not be bundled: The library was found but could not be resolved.") + endif() + else() + message(STATUS "Library ${_installed_name} was not found - skipping") + endif() +endmacro() + if (APPLE AND CMAKE_MACOSX_BUNDLE) set(prefix "86Box.app/Contents") set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") @@ -320,10 +333,15 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE) set(INSTALL_LIB_DIR "${prefix}/Frameworks") # using the install_qt5_plugin to add Qt plugins into the macOS app bundle - install_qt5_plugin("Qt${QT_MAJOR}::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt${QT_MAJOR}::QMacStylePlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt${QT_MAJOR}::QICOPlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt${QT_MAJOR}::QICNSPlugin" QT_PLUGINS ${prefix}) + install_qt5_plugin("Qt${QT_MAJOR}::QCocoaIntegrationPlugin" RUNTIME_PLUGINS ${prefix}) + install_qt5_plugin("Qt${QT_MAJOR}::QMacStylePlugin" RUNTIME_PLUGINS ${prefix}) + install_qt5_plugin("Qt${QT_MAJOR}::QICOPlugin" RUNTIME_PLUGINS ${prefix}) + install_qt5_plugin("Qt${QT_MAJOR}::QICNSPlugin" RUNTIME_PLUGINS ${prefix}) + + # Install libraries that are loaded at runtime and not linked + install_bundle_library("${GHOSTSCRIPT_LIB}" "libgs.dylib" RUNTIME_PLUGINS ${INSTALL_LIB_DIR}) + install_bundle_library("${VDE_LIB}" "libvdeplug.dylib" RUNTIME_PLUGINS ${INSTALL_LIB_DIR}) + install_bundle_library("${MOLTENVK_LIB}" "libVulkan.dylib" RUNTIME_PLUGINS ${INSTALL_LIB_DIR}) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "[Paths]\nPlugins = PlugIns\n") @@ -345,27 +363,17 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE) install(CODE " include(BundleUtilities) get_filename_component(CMAKE_INSTALL_PREFIX_ABSOLUTE \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX} ABSOLUTE) - fixup_bundle(\"\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/86Box.app\" \"${QT_PLUGINS}\" \"${DIRS}\") + fixup_bundle(\"\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/86Box.app\" \"${RUNTIME_PLUGINS}\" \"${DIRS}\") execute_process( COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath \"@executable_path/../Frameworks/\" \"\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/${INSTALL_RUNTIME_DIR}/86Box\") ") - if(MOLTENVK) - install(CODE " - execute_process( - COMMAND bash -c \"set -e - echo \\\"-- Creating vulkan dylib symlink for QT (libVulkan.dylib -> libMoltenVK.dylib)\\\" - cd \${CMAKE_INSTALL_PREFIX_ABSOLUTE}/${INSTALL_LIB_DIR} - ln -sf libMoltenVK.dylib libVulkan.dylib - \") - ") - endif() endif() if (UNIX AND NOT APPLE AND NOT HAIKU) find_package(X11 REQUIRED) target_link_libraries(ui PRIVATE X11::X11 X11::Xi) - target_sources(ui PRIVATE xinput2_mouse.cpp) + target_sources(ui PRIVATE evdev_keyboard.cpp xinput2_mouse.cpp) find_package(PkgConfig REQUIRED) pkg_check_modules(LIBEVDEV IMPORTED_TARGET libevdev) if (LIBEVDEV_FOUND) @@ -373,6 +381,22 @@ if (UNIX AND NOT APPLE AND NOT HAIKU) target_link_libraries(ui PUBLIC PkgConfig::LIBEVDEV) target_sources(ui PRIVATE evdev_mouse.cpp) endif() + pkg_check_modules(XKBCOMMON IMPORTED_TARGET xkbcommon) + if (XKBCOMMON_FOUND) + target_compile_definitions(ui PRIVATE XKBCOMMON) + target_link_libraries(ui PUBLIC PkgConfig::XKBCOMMON) + target_sources(ui PRIVATE xkbcommon_keyboard.cpp) + + if (X11_xcb_FOUND) + pkg_check_modules(XKBCOMMON_X11 IMPORTED_TARGET xkbcommon-x11) + if (XKBCOMMON_X11_FOUND) + target_compile_definitions(ui PRIVATE XKBCOMMON_X11) + target_link_libraries(ui PRIVATE X11::xcb PUBLIC PkgConfig::XKBCOMMON_X11) + target_sources(ui PRIVATE xkbcommon_x11_keyboard.cpp) + set(QT5_PRIVATE_HEADERS ON) + endif() + endif() + endif() find_package(ECM NO_MODULE) if (ECM_FOUND) @@ -387,10 +411,22 @@ if (UNIX AND NOT APPLE AND NOT HAIKU) ecm_add_wayland_client_protocol(WL_SOURCE_VAR PROTOCOL ${CMAKE_SOURCE_DIR}/wl_protocols/pointer-constraints-unstable-v1.xml BASENAME pointer-constraints-unstable-v1) target_include_directories(ui PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${Qt${QT_MAJOR}Gui_PRIVATE_INCLUDE_DIRS}) target_sources(ui PRIVATE ${WL_SOURCE_VAR} wl_mouse.cpp) + if (XKBCOMMON_FOUND) + target_sources(ui PRIVATE xkbcommon_wl_keyboard.cpp) + endif() target_compile_definitions(ui PRIVATE WAYLAND) + set(QT5_PRIVATE_HEADERS ON) endif() endif() endif() + + # Add private headers for Qt5 if required. + if (NOT USE_QT6 AND DEFINED QT5_PRIVATE_HEADERS) + find_package(Qt${QT_MAJOR}Gui) + if (Qt${QT_MAJOR}Gui_FOUND) + include_directories(${Qt${QT_MAJOR}Gui_PRIVATE_INCLUDE_DIRS}) + endif() + endif() endif() set(QM_FILES) file(GLOB po_files "${CMAKE_CURRENT_SOURCE_DIR}/languages/*.po") diff --git a/src/qt/be_keyboard.hpp b/src/qt/be_keyboard.hpp new file mode 100644 index 000000000..cc2bbabac --- /dev/null +++ b/src/qt/be_keyboard.hpp @@ -0,0 +1,112 @@ +static std::unordered_map be_keycodes = { + {B_F1_KEY, 0x3b}, + {B_F2_KEY, 0x3c}, + {B_F3_KEY, 0x3d}, + {B_F4_KEY, 0x3e}, + {B_F5_KEY, 0x3f}, + {B_F6_KEY, 0x40}, + {B_F7_KEY, 0x41}, + {B_F8_KEY, 0x42}, + {B_F9_KEY, 0x43}, + {B_F10_KEY, 0x44}, + {B_F11_KEY, 0x57}, + {B_F12_KEY, 0x58}, + {B_PRINT_KEY, 0x137}, + {B_SCROLL_KEY, 0x46}, + {B_PAUSE_KEY, 0x145}, + {B_KATAKANA_HIRAGANA, 0x70}, + {B_HANKAKU_ZENKAKU, 0x76}, + + {0x01, 0x01}, /* Escape */ + {0x11, 0x29}, + {0x12, 0x02}, + {0x13, 0x03}, + {0x14, 0x04}, + {0x15, 0x05}, + {0x16, 0x06}, + {0x17, 0x07}, + {0x18, 0x08}, + {0x19, 0x09}, + {0x1a, 0x0a}, + {0x1b, 0x0b}, + {0x1c, 0x0c}, + {0x1d, 0x0d}, + {0x1e, 0x0e}, /* Backspace */ + {0x1f, 0x152}, /* Insert */ + {0x20, 0x147}, /* Home */ + {0x21, 0x149}, /* Page Up */ + {0x22, 0x45}, + {0x23, 0x135}, + {0x24, 0x37}, + {0x25, 0x4a}, + {0x26, 0x0f}, /* Tab */ + {0x27, 0x10}, + {0x28, 0x11}, + {0x29, 0x12}, + {0x2a, 0x13}, + {0x2b, 0x14}, + {0x2c, 0x15}, + {0x2d, 0x16}, + {0x2e, 0x17}, + {0x2f, 0x18}, + {0x30, 0x19}, + {0x31, 0x1a}, + {0x32, 0x1b}, + {0x33, 0x2b}, + {0x34, 0x153}, /* Delete */ + {0x35, 0x14f}, /* End */ + {0x36, 0x151}, /* Page Down */ + {0x37, 0x47}, + {0x38, 0x48}, + {0x39, 0x49}, + {0x3a, 0x4e}, + {0x3b, 0x3a}, + {0x3c, 0x1e}, + {0x3d, 0x1f}, + {0x3e, 0x20}, + {0x3f, 0x21}, + {0x40, 0x22}, + {0x41, 0x23}, + {0x42, 0x24}, + {0x43, 0x25}, + {0x44, 0x26}, + {0x45, 0x27}, + {0x46, 0x28}, + {0x47, 0x1c}, /* Enter */ + {0x48, 0x4b}, + {0x49, 0x4c}, + {0x4a, 0x4d}, + {0x4b, 0x2a}, + {0x4c, 0x2c}, + {0x4d, 0x2d}, + {0x4e, 0x2e}, + {0x4f, 0x2f}, + {0x50, 0x30}, + {0x51, 0x31}, + {0x52, 0x32}, + {0x53, 0x33}, + {0x54, 0x34}, + {0x55, 0x35}, + {0x56, 0x36}, + {0x57, 0x148}, /* up arrow */ + {0x58, 0x51}, + {0x59, 0x50}, + {0x5a, 0x4f}, + {0x5b, 0x11c}, + {0x5c, 0x1d}, + {0x5d, 0x38}, + {0x5e, 0x39}, /* space bar */ + {0x5f, 0x138}, + {0x60, 0x11d}, + {0x61, 0x14b}, /* left arrow */ + {0x62, 0x150}, /* down arrow */ + {0x63, 0x14d}, /* right arrow */ + {0x64, 0x52}, + {0x65, 0x53}, + {0x66, 0x15b}, + {0x67, 0x15c}, + {0x68, 0x15d}, + {0x69, 0x56}, + {0x7e, 0x137}, /* System Request */ + {0x7f, 0x145}, /* Break */ +}; diff --git a/src/qt/cocoa_keyboard.hpp b/src/qt/cocoa_keyboard.hpp new file mode 100644 index 000000000..da3161bb2 --- /dev/null +++ b/src/qt/cocoa_keyboard.hpp @@ -0,0 +1,135 @@ +static std::array cocoa_keycodes = { /* key names in parentheses are not declared by Apple headers */ + 0x1e, /* ANSI_A */ + 0x1f, /* ANSI_S */ + 0x20, /* ANSI_D */ + 0x21, /* ANSI_F */ + 0x23, /* ANSI_H */ + 0x22, /* ANSI_G */ + 0x2c, /* ANSI_Z */ + 0x2d, /* ANSI_X */ + 0x2e, /* ANSI_C */ + 0x2f, /* ANSI_V */ + 0x56, /* ISO_Section */ + 0x30, /* ANSI_B */ + 0x10, /* ANSI_Q */ + 0x11, /* ANSI_W */ + 0x12, /* ANSI_E */ + 0x13, /* ANSI_R */ + 0x15, /* ANSI_Y */ + 0x14, /* ANSI_T */ + 0x02, /* ANSI_1 */ + 0x03, /* ANSI_2 */ + 0x04, /* ANSI_3 */ + 0x05, /* ANSI_4 */ + 0x07, /* ANSI_6 */ + 0x06, /* ANSI_5 */ + 0x0d, /* ANSI_Equal */ + 0x0a, /* ANSI_9 */ + 0x08, /* ANSI_7 */ + 0x0c, /* ANSI_Minus */ + 0x09, /* ANSI_8 */ + 0x0b, /* ANSI_0 */ + 0x1b, /* ANSI_RightBracket */ + 0x18, /* ANSI_O */ + 0x16, /* ANSI_U */ + 0x1a, /* ANSI_LeftBracket */ + 0x17, /* ANSI_I */ + 0x19, /* ANSI_P */ + 0x1c, /* Return */ + 0x26, /* ANSI_L */ + 0x24, /* ANSI_J */ + 0x28, /* ANSI_Quote */ + 0x25, /* ANSI_K */ + 0x27, /* ANSI_Semicolon */ + 0x2b, /* ANSI_Backslash */ + 0x33, /* ANSI_Comma */ + 0x35, /* ANSI_Slash */ + 0x31, /* ANSI_N */ + 0x32, /* ANSI_M */ + 0x34, /* ANSI_Period */ + 0x0f, /* Tab */ + 0x39, /* Space */ + 0x29, /* ANSI_Grave */ + 0x0e, /* Delete => Backspace */ + 0x11c, /* (ANSI_KeypadEnter) */ + 0x01, /* Escape */ + 0x15c, /* (RightCommand) => Right Windows */ + 0x15b, /* (Left)Command => Left Windows */ + 0x2a, /* Shift */ + 0x3a, /* CapsLock */ + 0x38, /* Option */ + 0x1d, /* Control */ + 0x36, /* RightShift */ + 0x138, /* RightOption */ + 0x11d, /* RightControl */ + 0x15c, /* Function */ + 0x5e, /* F17 => F14 */ + 0x53, /* ANSI_KeypadDecimal */ + 0, + 0x37, /* ANSI_KeypadMultiply */ + 0, + 0x4e, /* ANSI_KeypadPlus */ + 0, + 0x45, /* ANSI_KeypadClear => Num Lock (location equivalent) */ + 0x130, /* VolumeUp */ + 0x12e, /* VolumeDown */ + 0x120, /* Mute */ + 0x135, /* ANSI_KeypadDivide */ + 0x11c, /* ANSI_KeypadEnter */ + 0, + 0x4a, /* ANSI_KeypadMinus */ + 0x5f, /* F18 => F15 */ + 0, /* F19 */ + 0x59, /* ANSI_KeypadEquals */ + 0x52, /* ANSI_Keypad0 */ + 0x4f, /* ANSI_Keypad1 */ + 0x50, /* ANSI_Keypad2 */ + 0x51, /* ANSI_Keypad3 */ + 0x4b, /* ANSI_Keypad4 */ + 0x4c, /* ANSI_Keypad5 */ + 0x4d, /* ANSI_Keypad6 */ + 0x47, /* ANSI_Keypad7 */ + 0, /* F20 */ + 0x48, /* ANSI_Keypad8 */ + 0x49, /* ANSI_Keypad9 */ + 0x7d, /* JIS_Yen */ + 0x73, /* JIS_Underscore */ + 0x5c, /* JIS_KeypadComma */ + 0x3f, /* F5 */ + 0x40, /* F6 */ + 0x41, /* F7 */ + 0x3d, /* F3 */ + 0x42, /* F8 */ + 0x43, /* F9 */ + 0x7b, /* JIS_Eisu => muhenkan (location equivalent) */ + 0x57, /* F11 */ + 0x79, /* JIS_Kana => henkan (location equivalent) */ + 0x137, /* F13 => SysRq (location equivalent) */ + 0x5d, /* F16 => F13 */ + 0x46, /* F14 => Scroll Lock (location equivalent) */ + 0, + 0x44, /* F10 */ + 0x15d, /* (Menu) */ + 0x58, /* F12 */ + 0, + 0x145, /* F15 => Pause (location equivalent) */ + 0x152, /* Help => Insert (location equivalent) */ + 0x147, /* Home */ + 0x149, /* PageUp */ + 0x153, /* ForwardDelete */ + 0x3e, /* F4 */ + 0x14f, /* End */ + 0x3c, /* F2 */ + 0x151, /* PageDown */ + 0x3b, /* F1 */ + 0x14b, /* LeftArrow */ + 0x14d, /* RightArrow */ + 0x150, /* DownArrow */ + 0x148, /* UpArrow */ +}; + +// https://developer.apple.com/documentation/appkit/nseventmodifierflags/ +qint32 NSEventModifierFlagCommand = 1 << 20; + +qint32 nvk_Delete = 0x75; +qint32 nvk_Insert = 0x72; \ No newline at end of file diff --git a/src/qt/evdev_keyboard.cpp b/src/qt/evdev_keyboard.cpp new file mode 100644 index 000000000..9bc2ebdb2 --- /dev/null +++ b/src/qt/evdev_keyboard.cpp @@ -0,0 +1,163 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * evdev keyboard input module. + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +#include +#include + +static std::unordered_map evdev_keycodes = { + {184, 0x46}, /* F14 => Scroll Lock (for Apple keyboards) */ + {86, 0x56}, /* 102ND */ + {87, 0x57}, /* F11 */ + {88, 0x58}, /* F12 */ + {186, 0x5d}, /* F16 => F13 */ + {187, 0x5e}, /* F17 => F14 */ + {188, 0x5f}, /* F18 => F15 */ + + /* Japanese keys. */ + {95, 0x5c}, /* KPJPCOMMA */ + {93, 0x70}, /* KATAKANAHIRAGANA */ + {89, 0x73}, /* RO */ + {85, 0x76}, /* ZENKAKUHANKAKU */ + {91, 0x77}, /* HIRAGANA */ + {90, 0x78}, /* KATAKANA */ + {92, 0x79}, /* HENKAN */ + {94, 0x7b}, /* MUHENKAN */ + {124, 0x7d}, /* YEN */ + {121, 0x7e}, /* KPCOMMA */ + + /* Korean keys. */ + {123, 0xf1}, /* HANJA */ + {122, 0xf2}, /* HANGUL */ + + {96, 0x11c}, /* KPENTER */ + {97, 0x11d}, /* RIGHTCTRL */ + {98, 0x135}, /* KPSLASH */ + {99, 0x137}, /* SYSRQ */ + {183, 0x137}, /* F13 => SysRq (for Apple keyboards) */ + {100, 0x138}, /* RIGHTALT */ + {119, 0x145}, /* PAUSE */ + {411, 0x145}, /* BREAK */ + {185, 0x145}, /* F15 => Pause (for Apple keyboards) */ + {102, 0x147}, /* HOME */ + {103, 0x148}, /* UP */ + {104, 0x149}, /* PAGEUP */ + {105, 0x14b}, /* LEFT */ + {106, 0x14d}, /* RIGHT */ + {107, 0x14f}, /* END */ + {108, 0x150}, /* DOWN */ + {109, 0x151}, /* PAGEDOWN */ + {110, 0x152}, /* INSERT */ + {111, 0x153}, /* DELETE */ + + {125, 0x15b}, /* LEFTMETA */ + {126, 0x15c}, /* RIGHTMETA */ + {127, 0x15d}, /* COMPOSE => Menu */ + + /* Multimedia keys. Guideline is to try and follow the Microsoft standard, then + fill in remaining scancodes with OEM-specific keys for redundancy sake. Keys + marked with # are not translated into evdev codes by the standard atkbd driver. */ + {634, 0x54}, /* SELECTIVE_SCREENSHOT# => Alt+SysRq */ + {117, 0x59}, /* KPEQUAL */ + {418, 0x6a}, /* ZOOMIN# => Logitech */ + {420, 0x6b}, /* ZOOMRESET# => Logitech */ + {223, 0x6d}, /* CANCEL# => Logitech */ + {132, 0x101}, /* # Logitech Task Select */ + {148, 0x102}, /* PROG1# => Samsung */ + {149, 0x103}, /* PROG2# => Samsung */ + {419, 0x104}, /* ZOOMOUT# => Logitech */ + {144, 0x105}, /* FILE# => Messenger/Files */ + {216, 0x105}, /* CHAT# => Messenger/Files */ + {430, 0x105}, /* MESSENGER# */ + {182, 0x107}, /* REDO# */ + {131, 0x108}, /* UNDO# */ + {135, 0x10a}, /* PASTE# */ + {177, 0x10b}, /* SCROLLUP# => normal speed */ + {165, 0x110}, /* PREVIOUSSONG */ + {136, 0x112}, /* FIND# => Logitech */ + {421, 0x113}, /* WORDPROCESSOR# => Word */ + {423, 0x114}, /* SPREADSHEET# => Excel */ + {397, 0x115}, /* CALENDAR# */ + {433, 0x116}, /* LOGOFF# */ + {137, 0x117}, /* CUT# */ + {133, 0x118}, /* COPY# */ + {163, 0x119}, /* NEXTSONG */ + {154, 0x11e}, /* CYCLEWINDOWS => Application Right (no left counterpart) */ + {113, 0x120}, /* MUTE */ + {140, 0x121}, /* CALC */ + {164, 0x122}, /* PLAYPAUSE */ + {432, 0x123}, /* SPELLCHECK# */ + {166, 0x124}, /* STOPCD */ + {139, 0x126}, /* MENU# => Shortcut/Menu/Help for a few OEMs */ + {114, 0x12e}, /* VOL- */ + {160, 0x12f}, /* CLOSECD# => Logitech Eject */ + {161, 0x12f}, /* EJECTCD# => Logitech */ + {162, 0x12f}, /* EJECTCLOSECD# => Logitech */ + {115, 0x130}, /* VOL+ */ + {150, 0x132}, /* WWW# */ + {172, 0x132}, /* HOMEPAGE */ + {138, 0x13b}, /* HELP# */ + {213, 0x13c}, /* SOUND# => My Music/Office Home */ + {360, 0x13c}, /* VENDOR# => My Music/Office Home */ + {204, 0x13d}, /* DASHBOARD# => Task Pane */ + {181, 0x13e}, /* NEW# */ + {134, 0x13f}, /* OPEN# */ + {206, 0x140}, /* CLOSE# */ + {232, 0x141}, /* REPLY# */ + {233, 0x142}, /* FORWARDMAIL# */ + {231, 0x143}, /* SEND# */ + {151, 0x144}, /* MSDOS# */ + {112, 0x14c}, /* MACRO */ + {179, 0x14c}, /* KPLEFTPAREN# */ + {118, 0x14e}, /* KPPLUSMINUS */ + {235, 0x155}, /* DOCUMENTS# => Logitech */ + {234, 0x157}, /* SAVE# */ + {210, 0x158}, /* PRINT# */ + {116, 0x15e}, /* POWER */ + {142, 0x15f}, /* SLEEP */ + {143, 0x163}, /* WAKEUP */ + {180, 0x164}, /* KPRIGHTPAREN# */ + {212, 0x164}, /* CAMERA# => My Pictures */ + {217, 0x165}, /* SEARCH */ + {156, 0x166}, /* BOOKMARKS => Favorites */ + {364, 0x166}, /* FAVORITES# */ + {173, 0x167}, /* REFRESH */ + {128, 0x168}, /* STOP */ + {159, 0x169}, /* FORWARD */ + {158, 0x16a}, /* BACK */ + {157, 0x16b}, /* COMPUTER */ + {155, 0x16c}, /* MAIL */ + {215, 0x16c}, /* EMAIL# */ + {226, 0x16d}, /* MEDIA */ + {167, 0x178}, /* RECORD# => Logitech */ + {152, 0x17a}, /* COFFEE/SCREENLOCK# */ + {178, 0x18b}, /* SCROLLDOWN# => normal speed */ +}; + +uint16_t +evdev_translate(uint32_t keycode) +{ + /* "for 1-83 (0x01-0x53) scancode equals keycode" */ + auto ret = (keycode <= 0x53) ? keycode : evdev_keycodes[keycode]; + + if (!ret) + qWarning() << "Evdev Keyboard: Unknown key" << keycode; +#if 0 + else + qInfo() << "Evdev Keyboard: Key" << keycode << "scancode" << QString::number(ret, 16); +#endif + + return ret; +} diff --git a/src/qt/evdev_keyboard.hpp b/src/qt/evdev_keyboard.hpp new file mode 100644 index 000000000..5efe5958d --- /dev/null +++ b/src/qt/evdev_keyboard.hpp @@ -0,0 +1,20 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Definitions for evdev keyboard input module. + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +#ifndef EVDEV_KEYBOARD_HPP +#define EVDEV_KEYBOARD_HPP +uint16_t evdev_translate(uint32_t keycode); +#endif diff --git a/src/qt/languages/cs-CZ.po b/src/qt/languages/cs-CZ.po index 5f85c4f81..7c82b6f4d 100644 --- a/src/qt/languages/cs-CZ.po +++ b/src/qt/languages/cs-CZ.po @@ -724,9 +724,6 @@ msgstr "Stiskněte F8+F12 pro uvolnění myši" msgid "Press F8+F12 or middle button to release mouse" msgstr "Stiskněte F8+F12 nebo prostřední tlačítko pro uvolnění myši" -msgid "Unable to initialize FluidSynth" -msgstr "Nastala chyba při inicializaci knihovny FluidSynth." - msgid "Bus" msgstr "Sběrnice" @@ -811,9 +808,6 @@ msgstr "Rozšířené sektorové obrazy" msgid "Flux images" msgstr "Obrazy magnetického toku" -msgid "Unable to initialize FreeType" -msgstr "Nastala chyba při inicializaci knihovny FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Nastala chyba při inicializaci knihovny SDL, je potřeba SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Ujistěte se, že je nainstalován libpcap a používáte síťové při msgid "Invalid configuration" msgstr "Neplatná konfigurace" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " je potřeba pro emulaci ESC/P tiskáren." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " je potřeba pro automatický převod PostScript dokumentů do PDF.\n\nJakékoliv dokumenty vytisknuté přes obecnou PostScriptovou tiskárnu budou uloženy jako PostScript (.ps) soubory." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " je potřeba pro MIDI výstup přes knihovnu FluidSynth." - msgid "Entering fullscreen mode" msgstr "Vstup do režimu celé obrazovky" @@ -1219,3 +1195,9 @@ msgstr "2% pod dokonalými ot./m" msgid "(System Default)" msgstr "(Výchozí nastavení systému)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/de-DE.po b/src/qt/languages/de-DE.po index efbd5f95e..0caf925b5 100644 --- a/src/qt/languages/de-DE.po +++ b/src/qt/languages/de-DE.po @@ -724,9 +724,6 @@ msgstr "Bitte F8+F12 zur Mausfreigabe drücken" msgid "Press F8+F12 or middle button to release mouse" msgstr "Bitte F8+F12 oder die mittlere Maustaste zur Mausfreigabe drücken" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynth konnte nicht initialisiert werden" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Fortgeschrittene Sektorimages" msgid "Flux images" msgstr "Fluximages" -msgid "Unable to initialize FreeType" -msgstr "FreeType konnte nicht initialisiert werden" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL konnte nicht initialisiert werden, die Datei SDL2.dll wird benötigt" @@ -877,15 +871,6 @@ msgstr "Bitte stellen Sie sicher, dass libpcap installiert ist und sie eine libp msgid "Invalid configuration" msgstr "Ungültige Konfiguration" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " wird für die ESC/P-Druckeremulation benötigt." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " wird zur automatischen Konversion von PostScript-Dateien in das PDF-Format benötigt.\n\nSämtliche an den generischen PostScript-Drucker gesendete Dateien werden als PostScript (.ps)-Dateien gesichert." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " wird für die FluidSynth-MIDI-Ausgabe benötigt." - msgid "Entering fullscreen mode" msgstr "Vollbildmodus wird aktiviert" @@ -1219,3 +1195,9 @@ msgstr "2% unterhalb der perfekten Drehzahl" msgid "(System Default)" msgstr "(Systemstandard)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/en-GB.po b/src/qt/languages/en-GB.po index 7613cf4b3..6a33f9bed 100644 --- a/src/qt/languages/en-GB.po +++ b/src/qt/languages/en-GB.po @@ -724,9 +724,6 @@ msgstr "Press F8+F12 to release mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Press F8+F12 or middle button to release mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Unable to initialize FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Advanced sector images" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Unable to initialize FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Unable to initialize SDL, SDL2.dll is required" @@ -877,15 +871,6 @@ msgstr "Make sure libpcap is installed and that you are on a libpcap-compatible msgid "Invalid configuration" msgstr "Invalid configuration" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " is required for ESC/P printer emulation." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " is required for FluidSynth MIDI output." - msgid "Entering fullscreen mode" msgstr "Entering fullscreen mode" @@ -1219,3 +1195,9 @@ msgstr "2% below perfect RPM" msgid "(System Default)" msgstr "(System Default)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/en-US.po b/src/qt/languages/en-US.po index bf822aceb..5e3afdc27 100644 --- a/src/qt/languages/en-US.po +++ b/src/qt/languages/en-US.po @@ -724,9 +724,6 @@ msgstr "Press F8+F12 to release mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Press F8+F12 or middle button to release mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Unable to initialize FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Advanced sector images" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Unable to initialize FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Unable to initialize SDL, SDL2.dll is required" @@ -877,15 +871,6 @@ msgstr "Make sure libpcap is installed and that you are on a libpcap-compatible msgid "Invalid configuration" msgstr "Invalid configuration" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " is required for ESC/P printer emulation." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " is required for FluidSynth MIDI output." - msgid "Entering fullscreen mode" msgstr "Entering fullscreen mode" @@ -1219,3 +1195,9 @@ msgstr "2% below perfect RPM" msgid "(System Default)" msgstr "(System Default)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/es-ES.po b/src/qt/languages/es-ES.po index 0c2bd6aa9..f864dce0d 100644 --- a/src/qt/languages/es-ES.po +++ b/src/qt/languages/es-ES.po @@ -724,9 +724,6 @@ msgstr "Pulsa F8+F12 para liberar el ratón" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pulsa F8+F12 o el botón central para liberar el ratón" -msgid "Unable to initialize FluidSynth" -msgstr "Incapaz de inicializar FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Advanced sector images" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Incapaz de inicializar FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Incapaz de inicializar SDL, se requiere SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Asegúrate de que libpcap está instalado y de que estás en una conexi msgid "Invalid configuration" msgstr "Configuración inválida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " es necesaria para emulación de impresión ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " es necesaria para la conversión automática de archivos PostScript a PDF.\n\nCualquier documento enviado a la impresora genérica postScript se guardará como archivo PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " es necesario para salida MIDI FluidSynth." - msgid "Entering fullscreen mode" msgstr "Entrando en modo pantalla completa" @@ -1219,3 +1195,9 @@ msgstr "2% por debajo de RPM perfectas" msgid "(System Default)" msgstr "(Por defecto del sistema)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/fi-FI.po b/src/qt/languages/fi-FI.po index 6224472fa..97ecf79d5 100644 --- a/src/qt/languages/fi-FI.po +++ b/src/qt/languages/fi-FI.po @@ -724,9 +724,6 @@ msgstr "Paina F8+F12 vapauttaaksesi hiiren" msgid "Press F8+F12 or middle button to release mouse" msgstr "Paina F8+F12 tai keskipainiketta vapauttaaksesi hiiren" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynthin alustus epäonnistui" - msgid "Bus" msgstr "Väylä" @@ -811,9 +808,6 @@ msgstr "Kehittyneet sektorilevykuvat" msgid "Flux images" msgstr "Flux-levykuvat" -msgid "Unable to initialize FreeType" -msgstr "FreeType:n alustus epäonnistui" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL:n alustus epäonnistui. Tarvitaan SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Varmista, että libpcap on asennettu ja että verkkoyhteytesi on libpcap msgid "Invalid configuration" msgstr "Virheelliset määritykset" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " vaaditaan ESC/P-tulostimen emuloimiseksi." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " vaaditaan PostScript-tiedostojen automaattiseen muuntamiseen PDF-tiedostoiksi.\n\nKaikki geneeriselle PostScript-tulostimelle lähetetyt asiakirjat tallennetaan PostScript (.ps) -tiedostoina." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " vaaditaan FluidSynth MIDI-ulostuloa varten." - msgid "Entering fullscreen mode" msgstr "Siirrytään koko näytön tilaan" @@ -1219,3 +1195,9 @@ msgstr "2% alle täydellisen RPM:n" msgid "(System Default)" msgstr "(Järjestelmän oletus)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/fr-FR.po b/src/qt/languages/fr-FR.po index 3ae18533d..1fbff4001 100644 --- a/src/qt/languages/fr-FR.po +++ b/src/qt/languages/fr-FR.po @@ -724,9 +724,6 @@ msgstr "Appuyer sur F8+F12 pour libérer la souris" msgid "Press F8+F12 or middle button to release mouse" msgstr "Appuyer sur F8+F12 ou le bouton central pour libérer la souris" -msgid "Unable to initialize FluidSynth" -msgstr "Impossible d'initialiser FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Images du secteur avancés" msgid "Flux images" msgstr "Images du flux" -msgid "Unable to initialize FreeType" -msgstr "Impossible d'initialiser FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Impossible d'initialiser SDL, SDL2.dll est nécessaire" @@ -877,15 +871,6 @@ msgstr "Assurez-vous que libpcap est installé et que vou utilisez une connexion msgid "Invalid configuration" msgstr "Configuration non valide" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " est nécessaire pour l'émulation de l'imprimante ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " est nécessair pour la conversion automatique des fichiers PostScript dans PDF.\n\nTous les documents envoyés à l'imprimante générique PostScript seront sauvés comme des fichiers PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " est nécessaire pour la sortie MIDI FluidSynth." - msgid "Entering fullscreen mode" msgstr "Entrer en mode plein écran" @@ -1219,3 +1195,9 @@ msgstr "Précision RPM de moins 2%" msgid "(System Default)" msgstr "(Défaut du système)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/hr-HR.po b/src/qt/languages/hr-HR.po index 06c3ad8b5..43f01d5de 100644 --- a/src/qt/languages/hr-HR.po +++ b/src/qt/languages/hr-HR.po @@ -724,9 +724,6 @@ msgstr "Pritisnite F8+F12 za otpustanje miša" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pritisnite F8+F12 ili srednji gumb miša za otpuštanje miša" -msgid "Unable to initialize FluidSynth" -msgstr "Nije moguće inicijalizirati FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Napredne sektorske slike" msgid "Flux images" msgstr "Flux slike" -msgid "Unable to initialize FreeType" -msgstr "Nije moguće inicijalizirati FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Nije moguće inicijalizirati SDL, SDL2.dll je potrebno" @@ -877,15 +871,6 @@ msgstr "Provjerite je li libpcap instaliran i jeste li na mreži, kompadibilnoj msgid "Invalid configuration" msgstr "Nevažeća konfiguracija" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " je potrebno za emuliranje ESC/P pisača." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " je potrebno za automatsku konverziju PostScript datoteke u PDF datoteke.\n\nSvi dokumenti poslani na generički PostScript pisač bit će spremljeni kao PostScript (.ps) datoteke." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " je potrebno za FluidSynth MIDI izlaz." - msgid "Entering fullscreen mode" msgstr "Ulazim u cijelozaslonski način" @@ -1219,3 +1195,9 @@ msgstr "2% ispod savršenog broja okretaja" msgid "(System Default)" msgstr "(Zadana postavka operativnog sustava)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/hu-HU.po b/src/qt/languages/hu-HU.po index 6658cbb00..bf4796ebb 100644 --- a/src/qt/languages/hu-HU.po +++ b/src/qt/languages/hu-HU.po @@ -724,9 +724,6 @@ msgstr "Nyomja meg az F8+F12-t az egér elengédéséhez" msgid "Press F8+F12 or middle button to release mouse" msgstr "Nyomja meg az F8+F12-t vagy a középső gombot az egér elengédéséhez" -msgid "Unable to initialize FluidSynth" -msgstr "Nem sikerült a FluidSynth inicializálása" - msgid "Bus" msgstr "Busz" @@ -811,9 +808,6 @@ msgstr "Továbbfejlesztett szektor képek" msgid "Flux images" msgstr "Flux képekfájlok" -msgid "Unable to initialize FreeType" -msgstr "A FreeType inicializálása nem lehetséges" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Az SDL inicializálása nem lehetséges, az SDL2.dll fájl szükséges" @@ -877,15 +871,6 @@ msgstr "Győződjön meg hogy a(z) libpcap telepítve van és jelenleg a libpcap msgid "Invalid configuration" msgstr "Érvénytelen konfiguráció" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " szükséges az ESC/P nyomtató emulációhoz." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " szükséges a PostScript fájlok PDF formátumba való automatikus konvertálásához.\n\nAz általános PostScript nyomtatóra küldött dokumentumok PostScript (.ps) fájlként kerülnek mentésre." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " szükséges a FluidSynth MIDI kimenethez." - msgid "Entering fullscreen mode" msgstr "Teljes képernyős módra váltás" @@ -1219,3 +1195,9 @@ msgstr "2%-kal a tökéletes RPM alatt" msgid "(System Default)" msgstr "(A rendszer nyelve)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/it-IT.po b/src/qt/languages/it-IT.po index c02e3510f..6c6d5f65f 100644 --- a/src/qt/languages/it-IT.po +++ b/src/qt/languages/it-IT.po @@ -724,9 +724,6 @@ msgstr "Premi F8+F12 per rilasciare il mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Premi F8+F12 o pulsante centrale per rilasciare il mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Impossibile inizializzare FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Immagini da settori avanzati" msgid "Flux images" msgstr "Immagini flusso" -msgid "Unable to initialize FreeType" -msgstr "Impossibile inizializzare FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Impossibile inizializzare SDL, SDL2.dll è necessario" @@ -877,15 +871,6 @@ msgstr "Controlla se libpcap è installato e che tu sia connesso ad una connessi msgid "Invalid configuration" msgstr "Configurazione invalida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " è richesto per l'emuazione di stampanti ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " è richiesto per la conversione automatica di file PostScript a file PDF.\n\nQualsiasi documento mandato alla stampante generica PostScript sarà salvato come file PostScript. (.ps)" -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " è richiesto per l'output FluidSynth MIDI." - msgid "Entering fullscreen mode" msgstr "Entrando nella modalità schermo intero" @@ -1219,3 +1195,9 @@ msgstr "RPM 2% sotto perfezione" msgid "(System Default)" msgstr "(Predefinito del sistema)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/ja-JP.po b/src/qt/languages/ja-JP.po index 420d34a2e..b35fa429e 100644 --- a/src/qt/languages/ja-JP.po +++ b/src/qt/languages/ja-JP.po @@ -724,9 +724,6 @@ msgstr "F8+F12キーでマウスを解放します" msgid "Press F8+F12 or middle button to release mouse" msgstr "F8+F12キーまたは中ボタンでマウスを解放します" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynthが初期化できません" - msgid "Bus" msgstr "バス" @@ -811,9 +808,6 @@ msgstr "アドバンスドセクターイメージ" msgid "Flux images" msgstr "フラックスイメージ" -msgid "Unable to initialize FreeType" -msgstr "FreeTypeが初期化できません" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDLが初期化できません。SDL2.dllが必要です" @@ -877,15 +871,6 @@ msgstr "がインストールされてるか、libpcapに対応したネット msgid "Invalid configuration" msgstr "不正な設定です" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/Pプリンタのエミュレーションにはlibfreetypeが必要です。" - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr "PostScriptファイルをPDFに自動変換するにはlibgsが必要です。\n\n汎用PostScriptプリンターに送信されたドキュメントは、PostScript(.ps)ファイルとして保存されます。" -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynthのMIDI出力にはlibfluidsynthが必要です。" - msgid "Entering fullscreen mode" msgstr "フルスクリーンに切り替えています" @@ -1219,3 +1195,9 @@ msgstr "2%低い回転数" msgid "(System Default)" msgstr "(システム既定値)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/ko-KR.po b/src/qt/languages/ko-KR.po index 6d189d8e3..bf9325675 100644 --- a/src/qt/languages/ko-KR.po +++ b/src/qt/languages/ko-KR.po @@ -724,9 +724,6 @@ msgstr "F12+F8키를 누르면 마우스를 해제합니다" msgid "Press F8+F12 or middle button to release mouse" msgstr "F12+F8키 또는 가운데 버튼을 클릭하면 마우스를 해제합니다" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynth를 초기화할 수 없습니다" - msgid "Bus" msgstr "버스" @@ -811,9 +808,6 @@ msgstr "어드밴스드 섹터 이미지" msgid "Flux images" msgstr "플럭스 이미지" -msgid "Unable to initialize FreeType" -msgstr "FreeType을 초기화할 수 없습니다" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL을 초기화할 수 없습니다. SDL2.dll이 필요합니다" @@ -877,15 +871,6 @@ msgstr "이 설치되었는지 libpcap에 대응하는 네트워크에 접속되 msgid "Invalid configuration" msgstr "올바르지 않은 설정입니다" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/P 프린터 에뮬레이션에 libfreetype이(가) 필요합니다." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr "은(는) PostScript 파일을 PDF로 자동변환하는 데에 필요합니다.\n\n표준 PostScript 프린터로 보내신 임의의 문서는 PostScript (.ps) 파일로 저장됩니다." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynth의 MIDI 출력에 libfluidsynth이(가) 필요합니다." - msgid "Entering fullscreen mode" msgstr "전체 화면으로 전환" @@ -1219,3 +1195,9 @@ msgstr "2% 낮은 회전수" msgid "(System Default)" msgstr "(시스템 기본값)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/pl-PL.po b/src/qt/languages/pl-PL.po index 26c652c87..6b017dfb5 100644 --- a/src/qt/languages/pl-PL.po +++ b/src/qt/languages/pl-PL.po @@ -724,9 +724,6 @@ msgstr "Naciśnij klawisze F8+F12 w celu uwolnienia myszy" msgid "Press F8+F12 or middle button to release mouse" msgstr "Naciśnij klawisze F8+F12 lub środkowy przycisk w celu uwolnienia myszy" -msgid "Unable to initialize FluidSynth" -msgstr "Nie można zainicjować FluidSynth" - msgid "Bus" msgstr "Magistrala" @@ -811,9 +808,6 @@ msgstr "Zaawansowane obrazy sektorów" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Nie można zainicjować FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Nie można zainicjować SDL, wymagany SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Sprawdź, czy libpcap jest zainstalowany i czy posiadasz połączenie si msgid "Invalid configuration" msgstr "Nieprawidłowa konfiguracja" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " jest wymagany do emulacji drukarki ESC-P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " jest wymagany do automatycznej konwersji plików PostScript do PDF.\n\nDokumenty wysłane do ogólnej drukarki PostScript zostaną zapisane jako pliki PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " jest wymagany dla wyjścia FluidSynth MIDI." - msgid "Entering fullscreen mode" msgstr "Przechodzenie do trybu pełnoekranowego" @@ -1219,3 +1195,9 @@ msgstr "2% poniżej idealnych obrotów" msgid "(System Default)" msgstr "(Domyślne ustawienie systemowe)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/pt-BR.po b/src/qt/languages/pt-BR.po index 0202b42a7..1771c1f4a 100644 --- a/src/qt/languages/pt-BR.po +++ b/src/qt/languages/pt-BR.po @@ -724,9 +724,6 @@ msgstr "Aperte F8+F12 para liberar o mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Aperte F8+F12 ou botão do meio para liberar o mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Não foi possível inicializar o FluidSynth" - msgid "Bus" msgstr "Barramento" @@ -811,9 +808,6 @@ msgstr "Imagens de setor avançado" msgid "Flux images" msgstr "Imagens de fluxo" -msgid "Unable to initialize FreeType" -msgstr "Não foi possível inicializar o FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Não é possível inicializar o SDL, é necessário o SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Certifique-se de que libpcap esteja instalado e que você tenha uma cone msgid "Invalid configuration" msgstr "Configuração inválida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " é necessário para emulação de impressora ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " é necessário para a conversão automática de arquivos PostScript para PDF.\n\nQualquer documento enviado para a impressora genérica PostScript será salvo como arquivos PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " é necessário para a saída MIDI FluidSynth." - msgid "Entering fullscreen mode" msgstr "Entrando no modo de tela cheia" @@ -1219,3 +1195,9 @@ msgstr "2% abaixo das RPM perfeita" msgid "(System Default)" msgstr "(Padrão do sistema)" +msgid "Failed to initialize network driver" +msgstr "Falha ao inicializar o driver de rede" + +msgid "The network configuration will be switched to the null driver" +msgstr "A configuração de rede será alterada para o driver nulo" + diff --git a/src/qt/languages/pt-PT.po b/src/qt/languages/pt-PT.po index a8ce8bbca..a45aa78c5 100644 --- a/src/qt/languages/pt-PT.po +++ b/src/qt/languages/pt-PT.po @@ -724,9 +724,6 @@ msgstr "Pressione F8+F12 para soltar o rato" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pressione F8+F12 ou tecla média para soltar o rato" -msgid "Unable to initialize FluidSynth" -msgstr "Não foi possível inicializar o FluidSynth" - msgid "Bus" msgstr "Barramento" @@ -811,9 +808,6 @@ msgstr "Imagens avançadas de sector" msgid "Flux images" msgstr "Imagens de fluxo" -msgid "Unable to initialize FreeType" -msgstr "Não foi possível inicializar o FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Não foi possível inicializar o SDL. O ficheiro SDL2.dll é necessário!" @@ -877,15 +871,6 @@ msgstr "Certifique-se de que a biblioteca libpcap está instalada e de que está msgid "Invalid configuration" msgstr "Configuração inválida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " é requerida para a emulação de impressora ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " é requerido para a conversão automática de ficheiros PostScript para ficheiros PDF.\n\nQualquer documento enviado para a impressora PostScript genérica será gravado como um ficheiro PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " é necessário para a saída MIDI FluidSynth MIDI." - msgid "Entering fullscreen mode" msgstr "A entrar no modo de ecrã cheio" @@ -1219,3 +1195,9 @@ msgstr "RPM 2% abaixo do RPM perfeito" msgid "(System Default)" msgstr "(Padrão do sistema)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/ru-RU.po b/src/qt/languages/ru-RU.po index a424c5f6f..cb14c193d 100644 --- a/src/qt/languages/ru-RU.po +++ b/src/qt/languages/ru-RU.po @@ -724,9 +724,6 @@ msgstr "Нажмите F8+F12 чтобы освободить курсор" msgid "Press F8+F12 or middle button to release mouse" msgstr "Нажмите F8+F12 или среднюю кнопку мыши чтобы освободить курсор" -msgid "Unable to initialize FluidSynth" -msgstr "Невозможно инициализировать FluidSynth" - msgid "Bus" msgstr "Шина" @@ -811,9 +808,6 @@ msgstr "Расширенные образы секторов" msgid "Flux images" msgstr "Образы Flux" -msgid "Unable to initialize FreeType" -msgstr "Невозможно инициализировать FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Невозможно инициализировать SDL, требуется SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Убедитесь, что libpcap установлен и ваше се msgid "Invalid configuration" msgstr "Недопустимая конфигурация" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "Для эмуляции принтера ESC/P требуется libfreetype." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " требуется для автоматического преобразования файлов PostScript в PDF.\n\nВсе документы, отправленные на общий принтер PostScript, будут сохранены в виде файлов PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "Для FluidSynth MIDI-вывода требуется libfluidsynth." - msgid "Entering fullscreen mode" msgstr "Вход в полноэкранный режим" @@ -1219,3 +1195,9 @@ msgstr "На 2% медленнее точного RPM" msgid "(System Default)" msgstr "(Системный)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/sl-SI.po b/src/qt/languages/sl-SI.po index ba11014d2..83b0d6774 100644 --- a/src/qt/languages/sl-SI.po +++ b/src/qt/languages/sl-SI.po @@ -724,9 +724,6 @@ msgstr "Pritisnite F8+F12 za izpust miške" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pritisnite F8+F12 ali srednji gumb za izpust miške" -msgid "Unable to initialize FluidSynth" -msgstr "Ne morem inicializirati FluidSynth" - msgid "Bus" msgstr "Vodilo" @@ -811,9 +808,6 @@ msgstr "Napredne sektorske slike" msgid "Flux images" msgstr "Tokovne slike" -msgid "Unable to initialize FreeType" -msgstr "Ne morem inicializirati FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Ne morem inicializirati SDL, potrebna je knjižica SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Prepičajte se, da je nameščen libpcap in da ste na omrežni povezavi, msgid "Invalid configuration" msgstr "Neveljavna konfiguracija" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " je potreben za emuliranje ESC/P tiskalnika." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " je potreben za samodejno pretvorbo PostScript datotek v PDF.\n\nVsi dokumenti, poslani generičnemu PostScript tiskalniku bodo shranjeni kot PostScript (.ps) datoteke." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " je potreben za FluidSynth MIDI izhod." - msgid "Entering fullscreen mode" msgstr "Preklapljam v celozaslonski način" @@ -1219,3 +1195,9 @@ msgstr "2% pod popolnimi obrati" msgid "(System Default)" msgstr "(Sistemsko privzeto)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/tr-TR.po b/src/qt/languages/tr-TR.po index f9608e9d0..551764016 100644 --- a/src/qt/languages/tr-TR.po +++ b/src/qt/languages/tr-TR.po @@ -724,9 +724,6 @@ msgstr "Farenin bırakılması için F8+F12 tuşlarına basın" msgid "Press F8+F12 or middle button to release mouse" msgstr "Farenin bırakılması için F8+F12 veya farenin orta tuşuna basın" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynth başlatılamadı" - msgid "Bus" msgstr "Veri yolu" @@ -811,9 +808,6 @@ msgstr "Gelişmiş sektör imajları" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "FreeType başlatılamadı" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL başlatılamadı, SDL2.dll gerekmektedir" @@ -877,15 +871,6 @@ msgstr "libpcap kurulu olduğundan ve libpcap-uyumlu bir internet ağında bulun msgid "Invalid configuration" msgstr "Geçersiz konfigürasyon" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " ESC/P yazıcı emülasyonu için gereklidir." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " PostScript dosyalarının otomatik olarak PDF dosyalarına çevirilmesi için gereklidir.\n\nGenel PostScript yazıcısına gönderilen tüm dökümanlar PostScript (.ps) dosyaları olarak kaydedilecektir." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " FluidSynth MIDI çıkışı için gereklidir." - msgid "Entering fullscreen mode" msgstr "Tam ekran moduna geçiliyor" @@ -1219,3 +1195,9 @@ msgstr "mükemmel RPM değerinin 2% altı" msgid "(System Default)" msgstr "(Sistem Varsayılanı)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/uk-UA.po b/src/qt/languages/uk-UA.po index 0ebe3e5cc..394a2905d 100644 --- a/src/qt/languages/uk-UA.po +++ b/src/qt/languages/uk-UA.po @@ -305,7 +305,7 @@ msgid "&Default" msgstr "&За замовчуванням" msgid "Language:" -msgstr "Язык:" +msgstr "Мова:" msgid "Icon set:" msgstr "Набір іконок:" @@ -446,7 +446,7 @@ msgid "PCap device:" msgstr "Пристрій PCap:" msgid "Network adapter:" -msgstr "Мережева карта:" +msgstr "Мережевий адаптер:" msgid "COM1 Device:" msgstr "Пристрій COM1:" @@ -724,9 +724,6 @@ msgstr "Натисніть F8+F12, щоб звільнити курсор" msgid "Press F8+F12 or middle button to release mouse" msgstr "Натисніть F8+F12 або середню кнопку миші, щоб звільнити курсор" -msgid "Unable to initialize FluidSynth" -msgstr "Неможливо ініціалізувати FluidSynth" - msgid "Bus" msgstr "Шина" @@ -811,9 +808,6 @@ msgstr "Розширені образи секторів" msgid "Flux images" msgstr "Образи Flux" -msgid "Unable to initialize FreeType" -msgstr "Неможливо ініціалізувати FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Неможливо ініціалізувати SDL, потрібно SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Переконайтесь, що libpcap встановлений і в msgid "Invalid configuration" msgstr "Неприпустима конфігурація" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "Для емуляції принтера ESC/P потрібно libfreetype." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " потрібно для автоматичного перетворення файлів PostScript в PDF.\n\nВсі документи, відправлені на загальний принтер PostScript, будуть збережені у вигляді файлів PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "Для FluidSynth MIDI-висновку потрібно libfluidsynth." - msgid "Entering fullscreen mode" msgstr "Вхід у повноекранний режим" @@ -1219,3 +1195,9 @@ msgstr "На 2% повільніше точного RPM" msgid "(System Default)" msgstr "(Системний)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/zh-CN.po b/src/qt/languages/zh-CN.po index 65977da27..5858b5ec3 100644 --- a/src/qt/languages/zh-CN.po +++ b/src/qt/languages/zh-CN.po @@ -724,9 +724,6 @@ msgstr "按下 F8+F12 释放鼠标" msgid "Press F8+F12 or middle button to release mouse" msgstr "按下 F8+F12 或鼠标中键释放鼠标" -msgid "Unable to initialize FluidSynth" -msgstr "无法初始化 FluidSynth" - msgid "Bus" msgstr "总线" @@ -811,9 +808,6 @@ msgstr "高级扇区镜像" msgid "Flux images" msgstr "Flux 镜像" -msgid "Unable to initialize FreeType" -msgstr "无法初始化 FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "无法初始化 SDL,需要 SDL2.dll" @@ -877,15 +871,6 @@ msgstr "请确认 libpcap 已安装且使用兼容 libpcap 的网络连接。" msgid "Invalid configuration" msgstr "无效配置" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/P 打印机模拟需要" - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " 是将 PostScript 文件转换为 PDF 所需要的库。\n\n使用通用 PostScript 打印机打印的文档将被保存为 PostScript (.ps) 文件。" -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynth MIDI 输出需要" - msgid "Entering fullscreen mode" msgstr "正在进入全屏模式" @@ -1219,3 +1195,9 @@ msgstr "低于标准转速的 2%" msgid "(System Default)" msgstr "(系统默认)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/languages/zh-TW.po b/src/qt/languages/zh-TW.po index b61613b89..94b0a7553 100644 --- a/src/qt/languages/zh-TW.po +++ b/src/qt/languages/zh-TW.po @@ -182,7 +182,7 @@ msgid "Take s&creenshot\tCtrl+F11" msgstr "擷圖(&C)\tCtrl+F11" msgid "&Preferences..." -msgstr "首選項(&P)..." +msgstr "偏好設定(&P)..." msgid "Enable &Discord integration" msgstr "啟用 Discord 整合(&D)" @@ -206,13 +206,13 @@ msgid "&About 86Box..." msgstr "關於 86Box(&A)..." msgid "&New image..." -msgstr "新增鏡像(&N)..." +msgstr "新增映像(&N)..." msgid "&Existing image..." -msgstr "開啟已存在的鏡像(&E)..." +msgstr "開啟已存在的映像(&E)..." msgid "Existing image (&Write-protected)..." -msgstr "開啟已存在的鏡像並寫保護(&W)..." +msgstr "開啟已存在的映像並寫保護(&W)..." msgid "&Record" msgstr "錄製(&R)" @@ -227,10 +227,10 @@ msgid "&Fast forward to the end" msgstr "快進至終點(&F)" msgid "E&ject" -msgstr "彈出(&J)" +msgstr "退出(&J)" msgid "&Image..." -msgstr "鏡像(&I)..." +msgstr "映像(&I)..." msgid "E&xport to 86F..." msgstr "匯出為 86F 格式(&x)..." @@ -242,7 +242,7 @@ msgid "E&mpty" msgstr "空置光碟機(&M)" msgid "&Reload previous image" -msgstr "載入上一個鏡像(&R)" +msgstr "載入上一個映像(&R)" msgid "&Folder..." msgstr "資料夾(&F)..." @@ -272,19 +272,19 @@ msgid "&VSync" msgstr "垂直同步(&V)" msgid "&Select shader..." -msgstr "選擇著色器(&S)..." +msgstr "選取著色器(&S)..." msgid "&Remove shader" msgstr "移除著色器(&R)" msgid "Preferences" -msgstr "首選項" +msgstr "偏好設定" msgid "Sound Gain" msgstr "音量增益" msgid "New Image" -msgstr "新增鏡像" +msgstr "新增映像" msgid "Settings" msgstr "設定" @@ -341,7 +341,7 @@ msgid "Machine:" msgstr "機型:" msgid "Configure" -msgstr "配置" +msgstr "設定" msgid "CPU type:" msgstr "CPU 類型:" @@ -407,16 +407,16 @@ msgid "Joystick 4..." msgstr "搖桿 4..." msgid "Sound card 1:" -msgstr "音訊卡 1:" +msgstr "音效卡 1:" msgid "Sound card 2:" -msgstr "音訊卡 2:" +msgstr "音效卡 2:" msgid "Sound card 3:" -msgstr "音訊卡 3:" +msgstr "音效卡 3:" msgid "Sound card 4:" -msgstr "音訊卡 4:" +msgstr "音效卡 4:" msgid "MIDI Out Device:" msgstr "MIDI 輸出裝置:" @@ -533,7 +533,7 @@ msgid "&New..." msgstr "新增(&N)..." msgid "&Existing..." -msgstr "已有鏡像(&E)..." +msgstr "已有映像(&E)..." msgid "&Remove" msgstr "移除(&R)" @@ -557,7 +557,7 @@ msgid "Heads:" msgstr "磁頭(H):" msgid "Cylinders:" -msgstr "柱面(C):" +msgstr "磁柱(C):" msgid "Size (MB):" msgstr "大小 (MB):" @@ -566,10 +566,10 @@ msgid "Type:" msgstr "類型:" msgid "Image Format:" -msgstr "鏡像格式:" +msgstr "映像格式:" msgid "Block Size:" -msgstr "塊大小:" +msgstr "區塊大小:" msgid "Floppy drives:" msgstr "軟碟機:" @@ -647,10 +647,10 @@ msgid "ZIP %03i %i (%s): %ls" msgstr "ZIP %03i %i (%s): %ls" msgid "ZIP images" -msgstr "ZIP 鏡像" +msgstr "ZIP 映像" msgid "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory." -msgstr "86Box 找不到任何可用的 ROM 鏡像。\n\n請下載ROM 包並將其解壓到 \"roms\" 資料夾。" +msgstr "86Box 找不到任何可用的 ROM 映像。\n\n請下載 ROM 套件並將其解壓到 \"roms\" 資料夾。" msgid "(empty)" msgstr "(空)" @@ -668,13 +668,13 @@ msgid "Off" msgstr "關" msgid "All images" -msgstr "所有鏡像" +msgstr "所有映像" msgid "Basic sector images" -msgstr "基本磁區鏡像" +msgstr "基本磁區映像" msgid "Surface images" -msgstr "表面鏡像" +msgstr "表面映像" msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." msgstr "由於 roms/machines 資料夾中缺少合適的 ROM,機型 \"%hs\" 不可用。將切換到其他可用機型。" @@ -710,7 +710,7 @@ msgid "Floppy & CD-ROM drives" msgstr "軟碟/光碟機" msgid "Other removable devices" -msgstr "其他可移除裝置" +msgstr "其他卸除式裝置" msgid "Other peripherals" msgstr "其他周邊裝置" @@ -724,9 +724,6 @@ msgstr "按下 F8+F12 釋放滑鼠" msgid "Press F8+F12 or middle button to release mouse" msgstr "按下 F8+F12 或滑鼠中鍵釋放滑鼠" -msgid "Unable to initialize FluidSynth" -msgstr "無法初始化 FluidSynth" - msgid "Bus" msgstr "匯流排" @@ -806,13 +803,10 @@ msgid "Floppy %i (%s): %ls" msgstr "軟碟 %i (%s): %ls" msgid "Advanced sector images" -msgstr "進階磁區鏡像" +msgstr "進階磁區映像" msgid "Flux images" -msgstr "Flux 鏡像" - -msgid "Unable to initialize FreeType" -msgstr "無法初始化 FreeType" +msgstr "Flux 映像" msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "無法初始化 SDL,需要 SDL2.dll" @@ -830,7 +824,7 @@ msgid "MO %i (%ls): %ls" msgstr "磁光碟 %i (%ls): %ls" msgid "MO images" -msgstr "磁光碟鏡像" +msgstr "磁光碟映像" msgid "Welcome to 86Box!" msgstr "歡迎使用 86Box!" @@ -845,13 +839,13 @@ msgid "No ROMs found" msgstr "找不到 ROM" msgid "Do you want to save the settings?" -msgstr "要保存設定嗎?" +msgstr "要儲存設定嗎?" msgid "This will hard reset the emulated machine." msgstr "此操作將硬重設模擬器。" msgid "Save" -msgstr "保存" +msgstr "儲存" msgid "About 86Box" msgstr "關於 86Box" @@ -875,16 +869,7 @@ msgid "Make sure libpcap is installed and that you are on a libpcap-compatible n msgstr "請確認 libpcap 已安裝且使用相容 libpcap 的網路連線。" msgid "Invalid configuration" -msgstr "無效配置" - -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/P 印表機模擬需要" +msgstr "無效設定" msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -893,16 +878,7 @@ msgid "libgs" msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -msgstr " 是將 PostScript 檔案轉換為 PDF 所需要的庫。\n\n使用通用 PostScript 印表機列印的文件將被保存為 PostScript (.ps) 檔案。" - -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynth MIDI 輸出需要" +msgstr " 是將 PostScript 檔案轉換為 PDF 所需要的庫。\n\n使用通用 PostScript 印表機列印的文件將被儲存為 PostScript (.ps) 檔案。" msgid "Entering fullscreen mode" msgstr "正在進入全螢幕模式" @@ -920,10 +896,10 @@ msgid "Don't reset" msgstr "不重設" msgid "CD-ROM images" -msgstr "光碟鏡像" +msgstr "光碟映像" msgid "%hs Device Configuration" -msgstr "%hs 裝置配置" +msgstr "%hs 裝置設定" msgid "Monitor in sleep mode" msgstr "顯示器處在睡眠狀態" @@ -935,7 +911,7 @@ msgid "OpenGL options" msgstr "OpenGL 選項" msgid "You are loading an unsupported configuration" -msgstr "正在載入一個不受支援的配置" +msgstr "正在載入一個不受支援的設定" msgid "CPU type filtering based on selected machine is disabled for this emulated machine.\n\nThis makes it possible to choose a CPU that is otherwise incompatible with the selected machine. However, you may run into incompatibilities with the machine BIOS or other software.\n\nEnabling this setting is not officially supported and any bug reports filed may be closed as invalid." msgstr "此模擬電腦禁用了基於選定電腦的 CPU 類型過濾。\n\n能夠選中與所選機器本不相容的 CPU,但是可能會遇到與機器 BIOS 或其他軟體不相容的問題。\n\n啟用此設定不受官方支援,並且提交的任何錯誤報告可能會視為無效而關閉。" @@ -947,13 +923,13 @@ msgid "Cassette: %s" msgstr "磁帶: %s" msgid "Cassette images" -msgstr "磁帶鏡像" +msgstr "磁帶映像" msgid "Cartridge %i: %ls" msgstr "卡帶 %i: %ls" msgid "Cartridge images" -msgstr "卡帶鏡像" +msgstr "卡帶映像" msgid "Error initializing renderer" msgstr "初始化渲染器時出錯" @@ -998,19 +974,19 @@ msgid "Custom (large)..." msgstr "自訂 (大容量)..." msgid "Add New Hard Disk" -msgstr "添加新硬碟" +msgstr "增加新硬碟" msgid "Add Existing Hard Disk" -msgstr "添加已存在的硬碟" +msgstr "增加已存在的硬碟" msgid "HDI disk images cannot be larger than 4 GB." -msgstr "HDI 磁碟鏡像不能超過 4 GB。" +msgstr "HDI 磁碟映像不能超過 4 GB。" msgid "Disk images cannot be larger than 127 GB." -msgstr "磁碟鏡像不能超過 127 GB。" +msgstr "磁碟映像不能超過 127 GB。" msgid "Hard disk images" -msgstr "硬碟鏡像" +msgstr "硬碟映像" msgid "Unable to read file" msgstr "無法讀取檔案" @@ -1019,37 +995,37 @@ msgid "Unable to write file" msgstr "無法寫入檔案" msgid "HDI or HDX images with a sector size other than 512 are not supported." -msgstr "不支援非 512 位元組磁區大小的 HDI 或 HDX 鏡像。" +msgstr "不支援非 512 位元組磁區大小的 HDI 或 HDX 映像。" msgid "USB is not yet supported" msgstr "尚未支援 USB" msgid "Disk image file already exists" -msgstr "磁碟鏡像檔案已存在" +msgstr "磁碟映像檔案已存在" msgid "Please specify a valid file name." msgstr "請指定有效的檔案名。" msgid "Disk image created" -msgstr "已創建磁碟鏡像" +msgstr "已創建磁碟映像" msgid "Make sure the file exists and is readable." msgstr "請確定此檔案已存在並可讀取。" msgid "Make sure the file is being saved to a writable directory." -msgstr "請確定此檔案保存在可寫目錄中。" +msgstr "請確定此檔案儲存在可寫目錄中。" msgid "Disk image too large" -msgstr "磁碟鏡像太大" +msgstr "磁碟映像太大" msgid "Remember to partition and format the newly-created drive." -msgstr "請記得為新創建的鏡像分區並格式化。" +msgstr "請記得為新創建的映像分區並格式化。" msgid "The selected file will be overwritten. Are you sure you want to use it?" msgstr "選定的檔案將被覆蓋。確定繼續使用此檔案嗎?" msgid "Unsupported disk image" -msgstr "不支援的磁碟鏡像" +msgstr "不支援的磁碟映像" msgid "Overwrite" msgstr "覆蓋" @@ -1058,13 +1034,13 @@ msgid "Don't overwrite" msgstr "不覆蓋" msgid "Raw image (.img)" -msgstr "原始鏡像 (.img)" +msgstr "原始映像 (.img)" msgid "HDI image (.hdi)" -msgstr "HDI 鏡像 (.hdi)" +msgstr "HDI 映像 (.hdi)" msgid "HDX image (.hdx)" -msgstr "HDX 鏡像 (.hdx)" +msgstr "HDX 映像 (.hdx)" msgid "Fixed-size VHD (.vhd)" msgstr "固定大小 VHD (.vhd)" @@ -1076,19 +1052,19 @@ msgid "Differencing VHD (.vhd)" msgstr "差分 VHD (.vhd)" msgid "Large blocks (2 MB)" -msgstr "大塊 (2 MB)" +msgstr "大區塊 (2 MB)" msgid "Small blocks (512 KB)" -msgstr "小塊 (512 KB)" +msgstr "小區塊 (512 KB)" msgid "VHD files" msgstr "VHD 檔案" msgid "Select the parent VHD" -msgstr "選擇父 VHD 檔案" +msgstr "選取父 VHD 檔案" msgid "This could mean that the parent image was modified after the differencing image was created.\n\nIt can also happen if the image files were moved or copied, or by a bug in the program that created this disk.\n\nDo you want to fix the timestamps?" -msgstr "父映像可能在創建差異鏡像後被修改。\n\n如果鏡像檔案被移動或複製,或創建此磁碟的程式中存在錯誤,也可能發生這種情況。\n\n是否需要修復時間戳?" +msgstr "父映像可能在創建差異映像後被修改。\n\n如果映像檔案被移動或複製,或創建此磁碟的程式中存在錯誤,也可能發生這種情況。\n\n是否需要修復時間戳?" msgid "Parent and child disk timestamps do not match" msgstr "父碟與子碟的時間戳不匹配" @@ -1175,34 +1151,34 @@ msgid "ZIP 100" msgstr "ZIP 100" msgid "3.5\" 128 MB (ISO 10090)" -msgstr "3.5 英寸 128 MB (ISO 10090)" +msgstr "3.5 英吋 128 MB (ISO 10090)" msgid "3.5\" 230 MB (ISO 13963)" -msgstr "3.5 英寸 230 MB (ISO 13963)" +msgstr "3.5 英吋 230 MB (ISO 13963)" msgid "3.5\" 540 MB (ISO 15498)" -msgstr "3.5 英寸 540 MB (ISO 15498)" +msgstr "3.5 英吋 540 MB (ISO 15498)" msgid "3.5\" 640 MB (ISO 15498)" -msgstr "3.5 英寸 640 MB (ISO 15498)" +msgstr "3.5 英吋 640 MB (ISO 15498)" msgid "3.5\" 1.3 GB (GigaMO)" -msgstr "3.5 英寸 1.3 GB (GigaMO)" +msgstr "3.5 英吋 1.3 GB (GigaMO)" msgid "3.5\" 2.3 GB (GigaMO 2)" -msgstr "3.5 英寸 2.3 GB (GigaMO 2)" +msgstr "3.5 英吋 2.3 GB (GigaMO 2)" msgid "5.25\" 600 MB" -msgstr "5.25 英寸 600 MB" +msgstr "5.25 英吋 600 MB" msgid "5.25\" 650 MB" -msgstr "5.25 英寸 650 MB" +msgstr "5.25 英吋 650 MB" msgid "5.25\" 1 GB" -msgstr "5.25 英寸 1 GB" +msgstr "5.25 英吋 1 GB" msgid "5.25\" 1.3 GB" -msgstr "5.25 英寸 1.3 GB" +msgstr "5.25 英吋 1.3 GB" msgid "Perfect RPM" msgstr "標準轉速 (RPM)" @@ -1219,3 +1195,9 @@ msgstr "低於標準轉速的 2%" msgid "(System Default)" msgstr "(系統預設)" +msgid "Failed to initialize network driver" +msgstr "Failed to initialize network driver" + +msgid "The network configuration will be switched to the null driver" +msgstr "The network configuration will be switched to the null driver" + diff --git a/src/qt/qt_d3d9renderer.cpp b/src/qt/qt_d3d9renderer.cpp index fed8e72b3..868f58274 100644 --- a/src/qt/qt_d3d9renderer.cpp +++ b/src/qt/qt_d3d9renderer.cpp @@ -24,11 +24,16 @@ D3D9Renderer::D3D9Renderer(QWidget *parent, int monitor_index) windowHandle = (HWND) winId(); surfaceInUse = true; + finalized = true; RendererCommon::parentWidget = parent; this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); this->m_monitor_index = monitor_index; + + d3d9surface = nullptr; + d3d9dev = nullptr; + d3d9 = nullptr; } D3D9Renderer::~D3D9Renderer() @@ -55,7 +60,7 @@ D3D9Renderer::finalize() if (d3d9) { d3d9->Release(); d3d9 = nullptr; - }; + } } void @@ -67,6 +72,7 @@ D3D9Renderer::hideEvent(QHideEvent *event) void D3D9Renderer::showEvent(QShowEvent *event) { + if (d3d9) finalize(); params = {}; if (FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9))) { @@ -80,7 +86,7 @@ D3D9Renderer::showEvent(QShowEvent *event) params.BackBufferCount = 1; params.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - params.hDeviceWindow = windowHandle; + params.hDeviceWindow = (HWND) winId(); HRESULT result = d3d9->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, windowHandle, D3DCREATE_MULTITHREADED | D3DCREATE_HARDWARE_VERTEXPROCESSING, ¶ms, nullptr, &d3d9dev); if (FAILED(result)) @@ -107,7 +113,8 @@ void D3D9Renderer::paintEvent(QPaintEvent *event) { IDirect3DSurface9 *backbuffer = nullptr; - RECT srcRect, dstRect; + RECT srcRect; + RECT dstRect; HRESULT result = d3d9dev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); if (FAILED(result)) { @@ -118,10 +125,10 @@ D3D9Renderer::paintEvent(QPaintEvent *event) srcRect.bottom = source.bottom(); srcRect.left = source.left(); srcRect.right = source.right(); - dstRect.top = destination.top(); - dstRect.bottom = destination.bottom(); - dstRect.left = destination.left(); - dstRect.right = destination.right(); + dstRect.top = destination.top() * devicePixelRatioF(); + dstRect.bottom = destination.bottom() * devicePixelRatioF(); + dstRect.left = destination.left() * devicePixelRatioF(); + dstRect.right = destination.right() * devicePixelRatioF(); d3d9dev->BeginScene(); d3d9dev->Clear(0, nullptr, D3DCLEAR_TARGET, 0xFF000000, 0, 0); while (surfaceInUse) { } diff --git a/src/qt/qt_d3d9renderer.hpp b/src/qt/qt_d3d9renderer.hpp index 2ec7b0327..37c27443b 100644 --- a/src/qt/qt_d3d9renderer.hpp +++ b/src/qt/qt_d3d9renderer.hpp @@ -36,7 +36,8 @@ private: IDirect3DDevice9Ex *d3d9dev = nullptr; IDirect3DSurface9 *d3d9surface = nullptr; - std::atomic surfaceInUse { false }, finalized { false }; + std::atomic surfaceInUse { false }; + std::atomic finalized { false }; bool alreadyInitialized = false; int m_monitor_index = 0; }; diff --git a/src/qt/qt_deviceconfig.cpp b/src/qt/qt_deviceconfig.cpp index 770e28157..eaa5e9566 100644 --- a/src/qt/qt_deviceconfig.cpp +++ b/src/qt/qt_deviceconfig.cpp @@ -66,7 +66,8 @@ DeviceConfig::~DeviceConfig() static QStringList EnumerateSerialDevices() { - QStringList serialDevices, ttyEntries; + QStringList serialDevices; + QStringList ttyEntries; QByteArray devstr(1024, 0); #ifdef Q_OS_LINUX QDir class_dir("/sys/class/tty/"); @@ -108,7 +109,8 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *se { DeviceConfig dc(settings); dc.setWindowTitle(QString("%1 Device Configuration").arg(device->name)); - int c, d, p, q; + int p; + int q; device_context_t device_context; device_set_context(&device_context, device, instance); @@ -213,17 +215,16 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *se char *selected; selected = config_get_string(device_context.name, const_cast(config->name), const_cast(config->default_string)); - c = q = 0; + q = 0; for (auto *bios = config->bios; (bios != nullptr) && (bios->name != nullptr) && (strlen(bios->name) > 0); ++bios) { p = 0; - for (d = 0; d < bios->files_no; d++) + for (int d = 0; d < bios->files_no; d++) p += !!rom_present(const_cast(bios->files[d])); if (p == bios->files_no) { int row = Models::AddEntry(model, bios->name, q); if (!strcmp(selected, bios->internal_name)) { currentIndex = row; } - c++; } q++; } diff --git a/src/qt/qt_filefield.cpp b/src/qt/qt_filefield.cpp index b6db5e611..9272e31a1 100644 --- a/src/qt/qt_filefield.cpp +++ b/src/qt/qt_filefield.cpp @@ -31,6 +31,12 @@ FileField::FileField(QWidget *parent) fileName_ = ui->label->text(); emit fileSelected(ui->label->text(), true); }); + + connect(ui->label, &QLineEdit::textChanged, this, [this]() { + fileName_ = ui->label->text(); + emit fileTextEntered(ui->label->text(), true); + }); + this->setFixedWidth(this->sizeHint().width() + ui->pushButton->sizeHint().width()); } diff --git a/src/qt/qt_filefield.hpp b/src/qt/qt_filefield.hpp index ee011a38b..e3569fd31 100644 --- a/src/qt/qt_filefield.hpp +++ b/src/qt/qt_filefield.hpp @@ -19,12 +19,14 @@ public: void setFilter(const QString &filter) { filter_ = filter; } QString selectedFilter() const { return selectedFilter_; } + void setselectedFilter(const QString &selectedFilter) { selectedFilter_ = selectedFilter; } void setCreateFile(bool createFile) { createFile_ = createFile; } bool createFile() { return createFile_; } signals: void fileSelected(const QString &fileName, bool precheck = false); + void fileTextEntered(const QString &fileName, bool precheck = false); private slots: void on_pushButton_clicked(); diff --git a/src/qt/qt_harddiskdialog.cpp b/src/qt/qt_harddiskdialog.cpp index e8ccccd6f..b640c086e 100644 --- a/src/qt/qt_harddiskdialog.cpp +++ b/src/qt/qt_harddiskdialog.cpp @@ -23,7 +23,6 @@ extern "C" { #include <86box/86box.h> #include <86box/hdd.h> #include "../disk/minivhd/minivhd.h" -#include "../disk/minivhd/minivhd_util.h" } #include @@ -76,7 +75,7 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) uint64_t size = ((uint64_t) hdd_table[i][0]) * hdd_table[i][1] * hdd_table[i][2]; uint32_t size_mb = size >> 11LL; // QString text = QString("%1 MiB (CHS: %2, %3, %4)").arg(size_mb).arg(hdd_table[i][0]).arg(hdd_table[i][1]).arg(hdd_table[i][2]); - QString text = QString::asprintf(tr("%u MB (CHS: %i, %i, %i)").toUtf8().constData(), (size_mb), (hdd_table[i][0]), (hdd_table[i][1]), (hdd_table[i][2])); + QString text = QString::asprintf(tr("%u MB (CHS: %i, %i, %i)").toUtf8().constData(), size_mb, (hdd_table[i][0]), (hdd_table[i][1]), (hdd_table[i][2])); Models::AddEntry(model, text, i); } Models::AddEntry(model, tr("Custom..."), 127); @@ -85,6 +84,13 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) ui->lineEditSize->setValidator(new QIntValidator()); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + filters = QStringList({ tr("Raw image") % util::DlgFilter({ "img" }, true), + tr("HDI image") % util::DlgFilter({ "hdi" }, true), + tr("HDX image") % util::DlgFilter({ "hdx" }, true), + tr("Fixed-size VHD") % util::DlgFilter({ "vhd" }, true), + tr("Dynamic-size VHD") % util::DlgFilter({ "vhd" }, true), + tr("Differencing VHD") % util::DlgFilter({ "vhd" }, true) }); + if (existing) { ui->fileField->setFilter(tr("Hard disk images") % util::DlgFilter({ "hd?", "im?", "vhd" }) % tr("All files") % util::DlgFilter({ "*" }, true)); @@ -100,24 +106,26 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) connect(ui->fileField, &FileField::fileSelected, this, &HarddiskDialog::onExistingFileSelected); } else { - QStringList filters({ tr("Raw image") % util::DlgFilter({ "img" }, true), - tr("HDI image") % util::DlgFilter({ "hdi" }, true), - tr("HDX image") % util::DlgFilter({ "hdx" }, true), - tr("Fixed-size VHD") % util::DlgFilter({ "vhd" }, true), - tr("Dynamic-size VHD") % util::DlgFilter({ "vhd" }, true), - tr("Differencing VHD") % util::DlgFilter({ "vhd" }, true) }); - ui->fileField->setFilter(filters.join(";;")); setWindowTitle(tr("Add New Hard Disk")); ui->fileField->setCreateFile(true); - connect(ui->fileField, &FileField::fileSelected, this, [this, filters] { + // Enable the OK button as long as the filename length is non-zero + connect(ui->fileField, &FileField::fileTextEntered, this, [this] { + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled((this->fileName().length() > 0)); + }); + + connect(ui->fileField, &FileField::fileSelected, this, [this] { int filter = filters.indexOf(ui->fileField->selectedFilter()); if (filter > -1) ui->comboBoxFormat->setCurrentIndex(filter); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); }); + // Set the default format to Dynamic-size VHD. Do it last after everything is set up + // so the currentIndexChanged signal can do what is needed + ui->comboBoxFormat->setCurrentIndex(DEFAULT_DISK_FORMAT); + ui->fileField->setselectedFilter(filters.value(DEFAULT_DISK_FORMAT)); } } @@ -180,6 +188,7 @@ HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index) ui->comboBoxBlockSize->show(); ui->labelBlockSize->show(); } + ui->fileField->setselectedFilter(filters.value(index)); } /* If the disk geometry requested in the 86Box GUI is not compatible with the internal VHD geometry, @@ -313,7 +322,7 @@ HarddiskDialog::onCreateNewFile() ui->progressBar->setEnabled(true); setResult(QDialog::Rejected); quint64 size = ui->lineEditSize->text().toULongLong() << 20U; - if (size > 0x1FFFFFFE00ll) { + if (size > 0x1FFFFFFE00LL) { QMessageBox::critical(this, tr("Disk image too large"), tr("Disk images cannot be larger than 127 GB.")); return; } @@ -358,7 +367,7 @@ HarddiskDialog::onCreateNewFile() if (img_format == IMG_FMT_HDI) { /* HDI file */ QDataStream stream(&file); stream.setByteOrder(QDataStream::LittleEndian); - if (size >= 0x100000000ll) { + if (size >= 0x100000000LL) { QMessageBox::critical(this, tr("Disk image too large"), tr("HDI disk images cannot be larger than 4 GB.")); return; } diff --git a/src/qt/qt_harddiskdialog.hpp b/src/qt/qt_harddiskdialog.hpp index 0d5fa13bc..9de61c51b 100644 --- a/src/qt/qt_harddiskdialog.hpp +++ b/src/qt/qt_harddiskdialog.hpp @@ -52,6 +52,11 @@ private: bool disallowSizeModifications = false; + QStringList filters; + // "Dynamic-size VHD" is number 4 in the `filters` list and the + // comboBoxFormat model + const uint8_t DEFAULT_DISK_FORMAT = 4; + bool checkAndAdjustCylinders(); bool checkAndAdjustHeads(); bool checkAndAdjustSectors(); diff --git a/src/qt/qt_hardwarerenderer.cpp b/src/qt/qt_hardwarerenderer.cpp index 647827e85..ee2ec07df 100644 --- a/src/qt/qt_hardwarerenderer.cpp +++ b/src/qt/qt_hardwarerenderer.cpp @@ -141,7 +141,8 @@ HardwareRenderer::paintGL() { m_context->makeCurrent(this); glClear(GL_COLOR_BUFFER_BIT); - QVector verts, texcoords; + QVector verts; + QVector texcoords; QMatrix4x4 mat; mat.setToIdentity(); mat.ortho(QRectF(0, 0, (qreal) width(), (qreal) height())); diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index 29b394114..e667ae4eb 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -355,15 +355,14 @@ static int hdd_count(int bus) { int c = 0; - int i; - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if (hdd[i].bus == bus) { c++; } } - return (c); + return c; } void diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 29f8af5aa..daf13f72d 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -86,8 +86,10 @@ void qt_set_sequence_auto_mnemonic(bool b); void main_thread_fn() { - uint64_t old_time, new_time; - int drawits, frames; + uint64_t old_time; + uint64_t new_time; + int drawits; + int frames; QThread::currentThread()->setPriority(QThread::HighestPriority); framecountx = 0; @@ -138,7 +140,11 @@ main_thread_fn() } is_quit = 1; - QTimer::singleShot(0, QApplication::instance(), []() { QApplication::instance()->quit(); }); + if (gfxcard[1]) { + ui_deinit_monitor(1); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + QTimer::singleShot(0, QApplication::instance(), []() { QApplication::processEvents(); QApplication::instance()->quit(); }); } static std::thread *main_thread; diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 65af4d8d3..ef39765dd 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -48,7 +48,9 @@ extern "C" { #include <86box/machine.h> #include <86box/vid_ega.h> #include <86box/version.h> -//#include <86box/acpi.h> /* Requires timer.h include, which conflicts with Qt headers */ +#if 0 +#include <86box/acpi.h> /* Requires timer.h include, which conflicts with Qt headers */ +#endif extern atomic_int acpi_pwrbut_pressed; extern int acpi_enabled; @@ -68,6 +70,7 @@ extern int qt_nvr_save(void); #include #include #include +#include #include #include #include @@ -96,8 +99,17 @@ extern int qt_nvr_save(void); #include "qt_util.hpp" #if defined __unix__ && !defined __HAIKU__ -# ifdef WAYLAND -# include "wl_mouse.hpp" +# ifndef Q_OS_MACOS +# include "evdev_keyboard.hpp" +# endif +# ifdef XKBCOMMON +# include "xkbcommon_keyboard.hpp" +# ifdef XKBCOMMON_X11 +# include "xkbcommon_x11_keyboard.hpp" +# endif +# ifdef WAYLAND +# include "xkbcommon_wl_keyboard.hpp" +# endif # endif # include # include @@ -106,6 +118,7 @@ extern int qt_nvr_save(void); #endif #ifdef Q_OS_MACOS +# include "cocoa_keyboard.hpp" // The namespace is required to avoid clashing typedefs; we only use this // header for its #defines anyway. namespace IOKit { @@ -116,6 +129,7 @@ namespace IOKit { #ifdef __HAIKU__ # include # include +# include "be_keyboard.hpp" extern MainWindow *main_window; @@ -402,19 +416,19 @@ MainWindow::MainWindow(QWidget *parent) newVidApi = RendererStack::Renderer::Software; break; case 1: - newVidApi = (RendererStack::Renderer::OpenGL); + newVidApi = RendererStack::Renderer::OpenGL; break; case 2: - newVidApi = (RendererStack::Renderer::OpenGLES); + newVidApi = RendererStack::Renderer::OpenGLES; break; case 3: - newVidApi = (RendererStack::Renderer::OpenGL3); + newVidApi = RendererStack::Renderer::OpenGL3; break; case 4: - newVidApi = (RendererStack::Renderer::Vulkan); + newVidApi = RendererStack::Renderer::Vulkan; break; case 5: - newVidApi = (RendererStack::Renderer::Direct3D9); + newVidApi = RendererStack::Renderer::Direct3D9; break; #ifdef USE_VNC case 6: @@ -569,7 +583,6 @@ MainWindow::MainWindow(QWidget *parent) } #ifdef Q_OS_MACOS - ui->actionFullscreen->setShortcutVisibleInContextMenu(true); ui->actionCtrl_Alt_Del->setShortcutVisibleInContextMenu(true); ui->actionTake_screenshot->setShortcutVisibleInContextMenu(true); #endif @@ -616,6 +629,8 @@ MainWindow::MainWindow(QWidget *parent) #endif setContextMenuPolicy(Qt::PreventContextMenu); + /* Remove default Shift+F10 handler, which unfocuses keyboard input even with no context menu. */ + connect(new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F10), this), &QShortcut::activated, this, [this](){}); connect(this, &MainWindow::initRendererMonitor, this, &MainWindow::initRendererMonitorSlot); connect(this, &MainWindow::initRendererMonitorForNonQtThread, this, &MainWindow::initRendererMonitorSlot, Qt::BlockingQueuedConnection); @@ -648,6 +663,20 @@ MainWindow::MainWindow(QWidget *parent) } else { ui->actionCursor_Puck->setChecked(true); } + +#ifdef XKBCOMMON +# ifdef XKBCOMMON_X11 + if (QApplication::platformName().contains("xcb")) + xkbcommon_x11_init(); + else +# endif +# ifdef WAYLAND + if (QApplication::platformName().contains("wayland")) + xkbcommon_wl_init(); + else +# endif + {} +#endif } void @@ -733,7 +762,9 @@ MainWindow::initRendererMonitorSlot(int monitor_index) secondaryRenderer->showMaximized(); } secondaryRenderer->switchRenderer((RendererStack::Renderer) vid_api); + secondaryRenderer->setMouseTracking(true); } + connect(this, &MainWindow::pollMouse, secondaryRenderer.get(), &RendererStack::mousePoll, Qt::DirectConnection); } } @@ -880,652 +911,78 @@ MainWindow::on_actionSettings_triggered() plat_pause(currentPause); } -#if defined(__unix__) && !defined(__HAIKU__) -std::array x11_to_xt_base { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0x01, - 0x02, - 0x03, - 0x04, - 0x05, - 0x06, - 0x07, - 0x08, - 0x09, - 0x0A, - 0x0B, - 0x0C, - 0x0D, - 0x0E, - 0x0F, - 0x10, - 0x11, - 0x12, - 0x13, - 0x14, - 0x15, - 0x16, - 0x17, - 0x18, - 0x19, - 0x1A, - 0x1B, - 0x1C, - 0x1D, - 0x1E, - 0x1F, - 0x20, - 0x21, - 0x22, - 0x23, - 0x24, - 0x25, - 0x26, - 0x27, - 0x28, - 0x29, - 0x2A, - 0x2B, - 0x2C, - 0x2D, - 0x2E, - 0x2F, - 0x30, - 0x31, - 0x32, - 0x33, - 0x34, - 0x35, - 0x36, - 0x37, - 0x38, - 0x39, - 0x3A, - 0x3B, - 0x3C, - 0x3D, - 0x3E, - 0x3F, - 0x40, - 0x41, - 0x42, - 0x43, - 0x44, - 0x45, - 0x46, - 0x47, - 0x48, - 0x49, - 0x4A, - 0x4B, - 0x4C, - 0x4D, - 0x4E, - 0x4F, - 0x50, - 0x51, - 0x52, - 0x53, - 0x54, - 0x55, - 0x56, - 0x57, - 0x58, - 0x147, - 0x148, - 0x149, - 0, - 0x14B, - 0, - 0x14D, - 0x14F, - 0x150, - 0x151, - 0x152, - 0x153, - 0x11C, - 0x11D, - 0, // Pause/Break key. - 0x137, - 0x135, - 0x138, - 0, // Ditto as above comment. - 0x15B, - 0x15C, - 0x15D, -}; - -std::array x11_to_xt_2 { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0x01, - 0x02, - 0x03, - 0x04, - 0x05, - 0x06, - 0x07, - 0x08, - 0x09, - 0x0A, - 0x0B, - 0x0C, - 0x0D, - 0x0E, - 0x0F, - 0x10, - 0x11, - 0x12, - 0x13, - 0x14, - 0x15, - 0x16, - 0x17, - 0x18, - 0x19, - 0x1A, - 0x1B, - 0x1C, - 0x1D, - 0x1E, - 0x1F, - 0x20, - 0x21, - 0x22, - 0x23, - 0x24, - 0x25, - 0x26, - 0x27, - 0x28, - 0x29, - 0x2A, - 0x2B, - 0x2C, - 0x2D, - 0x2E, - 0x2F, - 0x30, - 0x31, - 0x32, - 0x33, - 0x34, - 0x35, - 0x36, - 0x37, - 0x38, - 0x39, - 0x3A, - 0x3B, - 0x3C, - 0x3D, - 0x3E, - 0x3F, - 0x40, - 0x41, - 0x42, - 0x43, - 0x44, - 0x45, - 0x46, - 0x47, - 0x48, - 0x49, - 0x4A, - 0x4B, - 0x4C, - 0x4D, - 0x4E, - 0x4F, - 0x50, - 0x51, - 0x52, - 0x53, - 0x138, - 0x55, - 0x56, - 0x57, - 0x58, - 0x56, - 0x70, - 0x7B, - 0x7D, - 0x2B, - 0x7E, - 0, - 0x11C, - 0x11D, - 0x135, - 0x137, - 0x138, - 0, - 0x147, - 0x148, - 0x149, - 0x14B, - 0x14D, - 0x14F, - 0x150, - 0x151, - 0x152, - 0x153, - 0, - 0, /* Mute */ - 0, /* Volume Down */ - 0, /* Volume Up */ - 0, /* Power Off */ - 0, - 0, - 0, - 0, - 0, - 0x70, - 0x7B, - 0x73, - 0x15B, - 0x15C, - 0x15D -}; - -std::array x11_to_xt_vnc { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0x1D, - 0x11D, - 0x2A, - 0x36, - 0, - 0, - 0x38, - 0x138, - 0x39, - 0x0B, - 0x02, - 0x03, - 0x04, - 0x05, - 0x06, - 0x07, - 0x08, - 0x09, - 0x0A, - 0x0C, - 0x0D, - 0x1A, - 0x1B, - 0x27, - 0x28, - 0x29, - 0x33, - 0x34, - 0x35, - 0x2B, - 0x1E, - 0x30, - 0x2E, - 0x20, - 0x12, - 0x21, - 0x22, - 0x23, - 0x17, - 0x24, - 0x25, - 0x26, - 0x32, - 0x31, - 0x18, - 0x19, - 0x10, - 0x13, - 0x1F, - 0x14, - 0x16, - 0x2F, - 0x11, - 0x2D, - 0x15, - 0x2C, - 0x0E, - 0x1C, - 0x0F, - 0x01, - 0x153, - 0x147, - 0x14F, - 0x149, - 0x151, - 0x148, - 0x150, - 0x14B, - 0x14D, -}; -#endif - -#ifdef Q_OS_MACOS -std::array darwin_to_xt { - 0x1E, - 0x1F, - 0x20, - 0x21, - 0x23, - 0x22, - 0x2C, - 0x2D, - 0x2E, - 0x2F, - 0x2B, - 0x30, - 0x10, - 0x11, - 0x12, - 0x13, - 0x15, - 0x14, - 0x02, - 0x03, - 0x04, - 0x05, - 0x07, - 0x06, - 0x0D, - 0x0A, - 0x08, - 0x0C, - 0x09, - 0x0B, - 0x1B, - 0x18, - 0x16, - 0x1A, - 0x17, - 0x19, - 0x1C, - 0x26, - 0x24, - 0x28, - 0x25, - 0x27, - 0x2B, - 0x33, - 0x35, - 0x31, - 0x32, - 0x34, - 0x0F, - 0x39, - 0x29, - 0x0E, - 0x11C, - 0x01, - 0x15C, - 0x15B, - 0x2A, - 0x3A, - 0x38, - 0x1D, - 0x36, - 0x138, - 0x11D, - 0x15C, - 0, - 0x53, - 0, - 0x37, - 0, - 0x4E, - 0, - 0x45, - 0x130, - 0x12E, - 0x120, - 0x135, - 0x11C, - 0, - 0x4A, - 0, - 0, - 0, - 0x52, - 0x4F, - 0x50, - 0x51, - 0x4B, - 0x4C, - 0x4D, - 0x47, - 0, - 0x48, - 0x49, - 0, - 0, - 0, - 0x3F, - 0x40, - 0x41, - 0x3D, - 0x42, - 0x43, - 0, - 0x57, - 0, - 0x137, - 0, - 0x46, - 0, - 0x44, - 0x15D, - 0x58, - 0, - 0, // Pause/Break key. - 0x152, - 0x147, - 0x149, - 0x153, - 0x3E, - 0x14F, - 0x3C, - 0x151, - 0x3B, - 0x14B, - 0x14D, - 0x150, - 0x148, - 0, -}; -#endif - -#if defined(__unix__) && !defined(__HAIKU__) -static std::unordered_map evdev_to_xt = { - {96, 0x11C}, - { 97, 0x11D}, - { 98, 0x135}, - { 99, 0x71 }, - { 100, 0x138}, - { 101, 0x1C }, - { 102, 0x147}, - { 103, 0x148}, - { 104, 0x149}, - { 105, 0x14B}, - { 106, 0x14D}, - { 107, 0x14F}, - { 108, 0x150}, - { 109, 0x151}, - { 110, 0x152}, - { 111, 0x153} -}; -#endif - -#ifdef __HAIKU__ -static std::unordered_map be_to_xt = { - {0x01, 0x01 }, - { B_F1_KEY, 0x3B }, - { B_F2_KEY, 0x3C }, - { B_F3_KEY, 0x3D }, - { B_F4_KEY, 0x3E }, - { B_F5_KEY, 0x3F }, - { B_F6_KEY, 0x40 }, - { B_F7_KEY, 0x41 }, - { B_F8_KEY, 0x42 }, - { B_F9_KEY, 0x43 }, - { B_F10_KEY, 0x44 }, - { B_F11_KEY, 0x57 }, - { B_F12_KEY, 0x58 }, - { 0x11, 0x29 }, - { 0x12, 0x02 }, - { 0x13, 0x03 }, - { 0x14, 0x04 }, - { 0x15, 0x05 }, - { 0x16, 0x06 }, - { 0x17, 0x07 }, - { 0x18, 0x08 }, - { 0x19, 0x09 }, - { 0x1A, 0x0A }, - { 0x1B, 0x0B }, - { 0x1C, 0x0C }, - { 0x1D, 0x0D }, - { 0x1E, 0x0E }, - { 0x1F, 0x152}, - { 0x20, 0x147}, - { 0x21, 0x149}, - { 0x22, 0x45 }, - { 0x23, 0x135}, - { 0x24, 0x37 }, - { 0x25, 0x4A }, - { 0x26, 0x0F }, - { 0x27, 0x10 }, - { 0x28, 0x11 }, - { 0x29, 0x12 }, - { 0x2A, 0x13 }, - { 0x2B, 0x14 }, - { 0x2C, 0x15 }, - { 0x2D, 0x16 }, - { 0x2E, 0x17 }, - { 0x2F, 0x18 }, - { 0x30, 0x19 }, - { 0x31, 0x1A }, - { 0x32, 0x1B }, - { 0x33, 0x2B }, - { 0x34, 0x153}, - { 0x35, 0x14F}, - { 0x36, 0x151}, - { 0x37, 0x47 }, - { 0x38, 0x48 }, - { 0x39, 0x49 }, - { 0x3A, 0x4E }, - { 0x3B, 0x3A }, - { 0x3C, 0x1E }, - { 0x3D, 0x1F }, - { 0x3E, 0x20 }, - { 0x3F, 0x21 }, - { 0x40, 0x22 }, - { 0x41, 0x23 }, - { 0x42, 0x24 }, - { 0x43, 0x25 }, - { 0x44, 0x26 }, - { 0x45, 0x27 }, - { 0x46, 0x28 }, - { 0x47, 0x1C }, - { 0x48, 0x4B }, - { 0x49, 0x4C }, - { 0x4A, 0x4D }, - { 0x4B, 0x2A }, - { 0x4C, 0x2C }, - { 0x4D, 0x2D }, - { 0x4E, 0x2E }, - { 0x4F, 0x2F }, - { 0x50, 0x30 }, - { 0x51, 0x31 }, - { 0x52, 0x32 }, - { 0x53, 0x33 }, - { 0x54, 0x34 }, - { 0x55, 0x35 }, - { 0x56, 0x36 }, - { 0x57, 0x148}, - { 0x58, 0x51 }, - { 0x59, 0x50 }, - { 0x5A, 0x4F }, - { 0x5B, 0x11C}, - { 0x5C, 0x1D }, - { 0x5D, 0x38 }, - { 0x5E, 0x39 }, - { 0x5F, 0x138}, - { 0x60, 0x11D}, - { 0x61, 0x14B}, - { 0x62, 0x150}, - { 0x63, 0x14D}, - { 0x64, 0x52 }, - { 0x65, 0x53 }, - - { 0x0e, 0x137}, - { 0x0f, 0x46 }, - { 0x66, 0x15B}, - { 0x67, 0x15C}, - { 0x68, 0x15D}, - { 0x69, 0x56 } -}; -#endif - -#if defined(__unix__) && !defined(__HAIKU__) -static std::array &selected_keycode = x11_to_xt_base; -#endif - -uint16_t -x11_keycode_to_keysym(uint32_t keycode) +void +MainWindow::processKeyboardInput(bool down, uint32_t keycode) { - uint16_t finalkeycode = 0; -#if defined(Q_OS_WINDOWS) - finalkeycode = (keycode & 0xFFFF); +#if defined(Q_OS_WINDOWS) /* non-raw input */ + keycode &= 0xffff; #elif defined(Q_OS_MACOS) - finalkeycode = darwin_to_xt[keycode]; + keycode = (keycode < 127) ? cocoa_keycodes[keycode] : 0; #elif defined(__HAIKU__) - finalkeycode = be_to_xt[keycode]; + keycode = be_keycodes[keycode]; #else - static Display *x11display = nullptr; - if (QApplication::platformName().contains("wayland")) { - selected_keycode = x11_to_xt_2; - } else if (QApplication::platformName().contains("eglfs")) { - keycode -= 8; - if (keycode <= 88) - finalkeycode = keycode; - else - finalkeycode = evdev_to_xt[keycode]; - } else if (!x11display) { - x11display = XOpenDisplay(nullptr); - if (XKeysymToKeycode(x11display, XK_Home) == 110) { - selected_keycode = x11_to_xt_2; - } else if (XKeysymToKeycode(x11display, XK_Home) == 69) { - selected_keycode = x11_to_xt_vnc; - } - } - if (!QApplication::platformName().contains("eglfs")) - finalkeycode = selected_keycode[keycode]; +# ifdef XKBCOMMON + if (xkbcommon_keymap) + keycode = xkbcommon_translate(keycode); + else +# endif +# ifdef EVDEV_KEYBOARD_HPP + keycode = evdev_translate(keycode - 8); +# else + keycode = 0; +# endif #endif - if (rctrl_is_lalt && finalkeycode == 0x11D) { - finalkeycode = 0x38; + + /* Apply special cases. */ + switch (keycode) { + case 0x54: /* Alt + Print Screen (special case, i.e. evdev SELECTIVE_SCREENSHOT) */ + /* Send Alt as well. */ + if (down) { + keyboard_input(down, 0x38); + } else { + keyboard_input(down, keycode); + keycode = 0x38; + } + break; + + case 0x80 ... 0xff: /* regular break codes */ + case 0x10b: /* Microsoft scroll up normal */ + case 0x180 ... 0x1ff: /* E0 break codes (including Microsoft scroll down normal) */ + /* This key uses a break code as make. Send it manually, only on press. */ + if (down) { + if (keycode & 0x100) + keyboard_send(0xe0); + keyboard_send(keycode & 0xff); + } + return; + + case 0x11d: /* Right Ctrl */ + if (rctrl_is_lalt) + keycode = 0x38; /* map to Left Alt */ + break; + + case 0x137: /* Print Screen */ + if (keyboard_recv(0x38) || keyboard_recv(0x138)) { /* Alt+ */ + keycode = 0x54; + } else if (down) { + keyboard_input(down, 0x12a); + } else { + keyboard_input(down, keycode); + keycode = 0x12a; + } + break; + + case 0x145: /* Pause */ + if (keyboard_recv(0x1d) || keyboard_recv(0x11d)) { /* Ctrl+ */ + keycode = 0x146; + } else { + keyboard_input(down, 0xe11d); + keycode &= 0x00ff; + } + break; } - return finalkeycode; + + keyboard_input(down, keycode); } #ifdef Q_OS_MACOS @@ -1543,6 +1000,7 @@ static std::unordered_map mac_modifiers_to_xt = { { NX_DEVICE_ALPHASHIFT_STATELESS_MASK, 0x3A }, { NX_DEVICERCTLKEYMASK, 0x11D}, }; +static bool mac_iso_swap = false; void MainWindow::processMacKeyboardInput(bool down, const QKeyEvent *event) @@ -1583,11 +1041,67 @@ MainWindow::processMacKeyboardInput(bool down, const QKeyEvent *event) // It's possible that other lock keys get delivered in this way, but // standard Apple keyboards don't have them, so this is untested. if (event->key() == Qt::Key_CapsLock) { - keyboard_input(1, 0x3A); - keyboard_input(0, 0x3A); + keyboard_input(1, 0x3a); + keyboard_input(0, 0x3a); } } else { - keyboard_input(down, x11_keycode_to_keysym(event->nativeVirtualKey())); + /* Apple ISO keyboards are notorious for swapping ISO_Section and ANSI_Grave + on *some* layouts and/or models. While macOS can sort this mess out at + keymap level, it still provides applications with unfiltered, ambiguous + keycodes, so we have to disambiguate them by making some bold assumptions + about the user's keyboard layout based on the OS-provided key mappings. */ + auto nvk = event->nativeVirtualKey(); + if ((nvk == 0x0a) || (nvk == 0x32)) { + /* Flaws: + - Layouts with `~ on ISO_Section are partially detected due to a conflict with ANSI + - Czech and Slovak are not detected as they have <> ANSI_Grave and \| ISO_Section (differing from PC actually) + - Italian is partially detected due to \| conflicting with Brazilian + - Romanian third level ANSI_Grave is unknown + - Russian clusters <>, plusminus and paragraph into a four-level ANSI_Grave, with the aforementioned `~ on ISO_Section */ + auto key = event->key(); + if ((nvk == 0x32) && ( /* system reports ANSI_Grave for ISO_Section keys: */ + (key == Qt::Key_Less) || (key == Qt::Key_Greater) || /* Croatian, French, German, Icelandic, Italian, Norwegian, Portuguese, Spanish, Spanish Latin America, Turkish Q */ + (key == Qt::Key_Ugrave) || /* French Canadian */ + (key == Qt::Key_Icircumflex) || /* Romanian */ + (key == Qt::Key_Iacute) || /* Hungarian */ + (key == Qt::Key_BracketLeft) || (key == Qt::Key_BracketRight) || /* Russian upper two levels */ + (key == Qt::Key_W) /* Turkish F */ + )) + mac_iso_swap = true; + else if ((nvk == 0x0a) && ( /* system reports ISO_Section for ANSI_Grave keys: */ + (key == Qt::Key_paragraph) || (key == Qt::Key_plusminus) || /* Arabic, British, Bulgarian, Danish shifted, Dutch, Greek, Hebrew, Hungarian shifted, International English, Norwegian shifted, Portuguese, Russian lower two levels, Swiss unshifted, Swedish unshifted, Turkish F */ + (key == Qt::Key_At) || (key == Qt::Key_NumberSign) || /* Belgian, French */ + (key == Qt::Key_Apostrophe) || /* Brazilian unshifted */ + (key == Qt::Key_QuoteDbl) || /* Brazilian shifted, Turkish Q unshifted */ + (key == Qt::Key_QuoteLeft) || /* Croatian (right quote unknown) */ + (key == Qt::Key_Dollar) || /* Danish unshifted */ + (key == Qt::Key_AsciiCircum) || (key == 0x1ffffff) || /* German unshifted (0x1ffffff according to one tester), Polish unshifted */ + (key == Qt::Key_degree) || /* German shifted, Icelandic unshifted, Spanish Latin America shifted, Swiss shifted, Swedish shifted */ + (key == Qt::Key_0) || /* Hungarian unshifted */ + (key == Qt::Key_diaeresis) || /* Icelandic shifted */ + (key == Qt::Key_acute) || /* Norwegian unshifted */ + (key == Qt::Key_Asterisk) || /* Polish shifted */ + (key == Qt::Key_masculine) || (key == Qt::Key_ordfeminine) || /* Spanish (masculine unconfirmed) */ + (key == Qt::Key_Eacute) || /* Turkish Q shifted */ + (key == Qt::Key_Slash) /* French Canadian unshifted, Ukrainian shifted */ + )) + mac_iso_swap = true; +#if 0 + if (down) { + QMessageBox questionbox(QMessageBox::Icon::Information, QString("Mac key swap test"), QString("nativeVirtualKey 0x%1\nnativeScanCode 0x%2\nkey 0x%3\nmac_iso_swap %4").arg(nvk, 0, 16).arg(event->nativeScanCode(), 0, 16).arg(key, 0, 16).arg(mac_iso_swap ? "yes" : "no"), QMessageBox::Ok, this); + questionbox.exec(); + } +#endif + if (mac_iso_swap) + nvk = (nvk == 0x0a) ? 0x32 : 0x0a; + } + // Special case for command + forward delete to send insert. + if ((event->nativeModifiers() & NSEventModifierFlagCommand) && + ((event->nativeVirtualKey() == nvk_Delete) || event->key() == Qt::Key_Delete)) { + nvk = nvk_Insert; // Qt::Key_Help according to event->key() + } + + processKeyboardInput(down, nvk); } } #endif @@ -1731,33 +1245,17 @@ void MainWindow::keyPressEvent(QKeyEvent *event) { if (send_keyboard_input && !(kbd_req_capture && !mouse_capture)) { - // Windows keys in Qt have one-to-one mapping. - if (event->key() == Qt::Key_Pause && !keyboard_recv(0x38) && !keyboard_recv(0x138)) { - if ((keyboard_recv(0x1D) || keyboard_recv(0x11D))) { - keyboard_input(1, 0x46); - } else { - keyboard_input(0, 0xE1); - keyboard_input(0, 0x1D); - keyboard_input(0, 0x45); - keyboard_input(0, 0xE1); - keyboard_input(1, 0x1D); - keyboard_input(1, 0x45); - } - } else #ifdef Q_OS_MACOS - processMacKeyboardInput(true, event); + processMacKeyboardInput(true, event); #else - keyboard_input(1, x11_keycode_to_keysym(event->nativeScanCode())); + processKeyboardInput(true, event->nativeScanCode()); #endif } - if ((video_fullscreen > 0) && keyboard_isfsexit()) { - ui->actionFullscreen->trigger(); - } + checkFullscreenHotkey(); - if (keyboard_ismsexit()) { + if (keyboard_ismsexit()) plat_mouse_capture(0); - } if ((video_fullscreen > 0) && (keyboard_recv(0x1D) || keyboard_recv(0x11D))) { if (keyboard_recv(0x57)) @@ -1789,14 +1287,36 @@ MainWindow::keyReleaseEvent(QKeyEvent *event) plat_pause(dopause ^ 1); } } - if (!send_keyboard_input) - return; + if (send_keyboard_input && !event->isAutoRepeat()) { #ifdef Q_OS_MACOS - processMacKeyboardInput(false, event); + processMacKeyboardInput(false, event); #else - keyboard_input(0, x11_keycode_to_keysym(event->nativeScanCode())); + processKeyboardInput(false, event->nativeScanCode()); #endif + } + + checkFullscreenHotkey(); +} + +void +MainWindow::checkFullscreenHotkey() +{ + if (!fs_off_signal && video_fullscreen && keyboard_isfsexit()) { + /* Signal "exit fullscreen mode". */ + fs_off_signal = 1; + } else if (fs_off_signal && video_fullscreen && keyboard_isfsexit_up()) { + ui->actionFullscreen->trigger(); + fs_off_signal = 0; + } + + if (!fs_on_signal && !video_fullscreen && keyboard_isfsenter()) { + /* Signal "enter fullscreen mode". */ + fs_on_signal = 1; + } else if (fs_on_signal && !video_fullscreen && keyboard_isfsenter_up()) { + ui->actionFullscreen->trigger(); + fs_on_signal = 0; + } } QSize @@ -2189,18 +1709,20 @@ void MainWindow::on_actionRemember_size_and_position_triggered() { window_remember ^= 1; - window_w = ui->stackedWidget->width(); - window_h = ui->stackedWidget->height(); - if (!QApplication::platformName().contains("wayland")) { - window_x = geometry().x(); - window_y = geometry().y(); - } - for (int i = 1; i < MONITORS_NUM; i++) { - if (window_remember && renderers[i]) { - monitor_settings[i].mon_window_w = renderers[i]->geometry().width(); - monitor_settings[i].mon_window_h = renderers[i]->geometry().height(); - monitor_settings[i].mon_window_x = renderers[i]->geometry().x(); - monitor_settings[i].mon_window_y = renderers[i]->geometry().y(); + if (!video_fullscreen) { + window_w = ui->stackedWidget->width(); + window_h = ui->stackedWidget->height(); + if (!QApplication::platformName().contains("wayland")) { + window_x = geometry().x(); + window_y = geometry().y(); + } + for (int i = 1; i < MONITORS_NUM; i++) { + if (window_remember && renderers[i]) { + monitor_settings[i].mon_window_w = renderers[i]->geometry().width(); + monitor_settings[i].mon_window_h = renderers[i]->geometry().height(); + monitor_settings[i].mon_window_x = renderers[i]->geometry().x(); + monitor_settings[i].mon_window_y = renderers[i]->geometry().y(); + } } } ui->actionRemember_size_and_position->setChecked(window_remember); diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index bf4a30f1d..d5a6b1967 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -32,6 +32,7 @@ public: void blitToWidget(int x, int y, int w, int h, int monitor_index); QSize getRenderWidgetSize(); void setSendKeyboardInput(bool enabled); + void checkFullscreenHotkey(); std::array, 8> renderers; signals: @@ -155,6 +156,7 @@ private: std::unique_ptr status; std::shared_ptr mm; + void processKeyboardInput(bool down, uint32_t keycode); #ifdef Q_OS_MACOS uint32_t last_modifiers = 0; void processMacKeyboardInput(bool down, const QKeyEvent *event); @@ -166,6 +168,10 @@ private: bool resizableonce = false; bool vnc_enabled = false; + /* Full screen ON and OFF signals */ + bool fs_on_signal = false; + bool fs_off_signal = false; + friend class SpecifyDimensions; friend class ProgSettings; friend class RendererCommon; diff --git a/src/qt/qt_mainwindow.ui b/src/qt/qt_mainwindow.ui index 5cfaea14c..b61a974c6 100644 --- a/src/qt/qt_mainwindow.ui +++ b/src/qt/qt_mainwindow.ui @@ -362,12 +362,6 @@ &Fullscreen - - Ctrl+Alt+PgUp - - - false - diff --git a/src/qt/qt_mediahistorymanager.cpp b/src/qt/qt_mediahistorymanager.cpp index b895b46aa..9d003f464 100644 --- a/src/qt/qt_mediahistorymanager.cpp +++ b/src/qt/qt_mediahistorymanager.cpp @@ -66,8 +66,8 @@ MediaHistoryManager::getHistoryListForDeviceIndex(int index, ui::MediaType type) if ((index >= 0) && (index < master_list[type].size())) { return master_list[type][index]; } else { - qWarning("Media device index %i for device type %s was requested but index %i is out of range (valid range: >= 0 && < %i)", - index, mediaTypeToString(type).toUtf8().constData(), index, master_list[type].size()); + qWarning("Media device index %i for device type %s was requested but index %i is out of range (valid range: >= 0 && < %lli)", + index, mediaTypeToString(type).toUtf8().constData(), index, static_cast(master_list[type].size())); } } // Failure gets an empty list @@ -88,8 +88,8 @@ MediaHistoryManager::getImageForSlot(int index, int slot, ui::MediaType type) if ((slot >= 0) && (slot < device_history.size())) { image_name = device_history[slot]; } else { - qWarning("Media history slot %i, index %i for device type %s was requested but slot %i is out of range (valid range: >= 0 && < %i, device_history.size() is %i)", - slot, index, mediaTypeToString(type).toUtf8().constData(), slot, maxDevicesSupported(type), device_history.size()); + qWarning("Media history slot %i, index %i for device type %s was requested but slot %i is out of range (valid range: >= 0 && < %i, device_history.size() is %lli)", + slot, index, mediaTypeToString(type).toUtf8().constData(), slot, maxDevicesSupported(type), static_cast(device_history.size())); } return image_name; } @@ -241,7 +241,7 @@ MediaHistoryManager::addImageToHistory(int index, ui::MediaType type, const QStr } // Pop any extras - if ((device_history.size() > MAX_PREV_IMAGES)) { + if (device_history.size() > MAX_PREV_IMAGES) { device_history.pop_back(); } diff --git a/src/qt/qt_mediahistorymanager.hpp b/src/qt/qt_mediahistorymanager.hpp index f1942b81c..4eae46f9c 100644 --- a/src/qt/qt_mediahistorymanager.hpp +++ b/src/qt/qt_mediahistorymanager.hpp @@ -90,7 +90,8 @@ private: [[nodiscard]] const master_list_t &getMasterList() const; void setMasterList(const master_list_t &masterList); - device_index_list_t index_list, empty_device_index_list; + device_index_list_t index_list; + device_index_list_t empty_device_index_list; // Return a blank, initialized image history list master_list_t &blankImageHistory(master_list_t &initialized_master_list) const; diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index e898ea9d9..26169b0d0 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -572,7 +572,8 @@ MediaMenu::cdromUpdateMenu(int i) auto childs = menu->children(); auto *muteMenu = dynamic_cast(childs[cdromMutePos]); - muteMenu->setChecked(cdrom[i].sound_on == 0); + muteMenu->setIcon(QApplication::style()->standardIcon((cdrom[i].sound_on == 0) ? QStyle::SP_MediaVolume : QStyle::SP_MediaVolumeMuted)); + muteMenu->setText((cdrom[i].sound_on == 0) ? tr("&Unmute") : tr("&Mute")); auto *imageMenu = dynamic_cast(childs[cdromImagePos]); imageMenu->setEnabled(!name.isEmpty()); @@ -848,7 +849,7 @@ MediaMenu::nicUpdateMenu(int i) if (!netMenus.contains(i)) return; - QString netType = tr("None"); + QString netType = tr("Null Driver"); switch (net_cards_conf[i].net_type) { case NET_TYPE_SLIRP: netType = "SLiRP"; @@ -856,6 +857,9 @@ MediaMenu::nicUpdateMenu(int i) case NET_TYPE_PCAP: netType = "PCAP"; break; + case NET_TYPE_VDE: + netType = "VDE"; + break; } QString devName = DeviceConfig::DeviceName(network_card_getdevice(net_cards_conf[i].device_num), network_card_get_internal_name(net_cards_conf[i].device_num), 1); diff --git a/src/qt/qt_newfloppydialog.cpp b/src/qt/qt_newfloppydialog.cpp index 479b6711f..10c505e3b 100644 --- a/src/qt/qt_newfloppydialog.cpp +++ b/src/qt/qt_newfloppydialog.cpp @@ -61,10 +61,12 @@ struct disk_size_t { static const disk_size_t disk_sizes[14] = { // clang-format off -// { 1, 1, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 250k 8" */ -// { 1, 2, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 500k 8" */ -// { 1, 1, 2, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 616k 8" */ -// { 1, 2, 0, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 1232k 8" */ +#if 0 + { 1, 1, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 250k 8" */ + { 1, 2, 2, 1, 1, 77, 26, 0, 0, 4, 2, 6, 68 }, /* 500k 8" */ + { 1, 1, 2, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 616k 8" */ + { 1, 2, 0, 1, 1, 77, 8, 3, 0, 1, 2, 2, 192 }, /* 1232k 8" */ +#endif { 0, 1, 2, 1, 0, 40, 8, 2, 0xfe, 2, 2, 1, 64 }, /* 160k */ { 0, 1, 2, 1, 0, 40, 9, 2, 0xfc, 2, 2, 1, 64 }, /* 180k */ { 0, 2, 2, 1, 0, 40, 8, 2, 0xff, 2, 2, 1, 112 }, /* 320k */ @@ -79,8 +81,10 @@ static const disk_size_t disk_sizes[14] = { { 2, 2, 3, 1, 0, 80, 36, 2, 0xf0, 2, 2, 9, 240 }, /* 2.88M */ { 0, 64, 0, 0, 0, 96, 32, 2, 0, 0, 0, 0, 0 }, /* ZIP 100 */ { 0, 64, 0, 0, 0, 239, 32, 2, 0, 0, 0, 0, 0 }, /* ZIP 250 */ -// { 0, 8, 0, 0, 0, 963, 32, 2, 0, 0, 0, 0, 0 }, /* LS-120 */ -// { 0, 32, 0, 0, 0, 262, 56, 2, 0, 0, 0, 0, 0 } /* LS-240 */ +#if 0 + { 0, 8, 0, 0, 0, 963, 32, 2, 0, 0, 0, 0, 0 }, /* LS-120 */ + { 0, 32, 0, 0, 0, 262, 56, 2, 0, 0, 0, 0, 0 } /* LS-240 */ +#endif // clang-format on }; @@ -264,7 +268,8 @@ NewFloppyDialog::create86f(const QString &filename, const disk_size_t &disk_size uint32_t index_hole_pos = 0; uint32_t tarray[512]; uint32_t array_size; - uint32_t track_base, track_size; + uint32_t track_base; + uint32_t track_size; int i; uint32_t shift = 0; @@ -644,11 +649,13 @@ bool NewFloppyDialog::createMoSectorImage(const QString &filename, int8_t disk_size, FileType type, QProgressDialog &pbar) { const mo_type_t *dp = &mo_types[disk_size]; - uint32_t total_size = 0, total_size2; + uint32_t total_size = 0; + uint32_t total_size2; uint32_t total_sectors = 0; uint32_t sector_bytes = 0; uint16_t base = 0x1000; - uint32_t pbar_max = 0, blocks_num; + uint32_t pbar_max = 0; + uint32_t blocks_num; QFile file(filename); if (!file.open(QIODevice::WriteOnly)) { diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 1fa3b5637..0274bc44a 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -48,7 +48,9 @@ # include #endif -// static QByteArray buf; +#if 0 +static QByteArray buf; +#endif extern QElapsedTimer elapsed_timer; extern MainWindow *main_window; QElapsedTimer elapsed_timer; @@ -145,7 +147,9 @@ void do_stop(void) { cpu_thread_run = 0; - // main_window->close(); +#if 0 + main_window->close(); +#endif } void @@ -249,7 +253,7 @@ path_get_filename(char *s) c--; } - return (s); + return s; #else auto idx = QByteArray::fromRawData(s, strlen(s)).lastIndexOf(QDir::separator().toLatin1()); if (idx >= 0) { @@ -312,7 +316,7 @@ plat_tempfile(char *bufp, char *prefix, char *suffix) name.append(QString("%1-").arg(prefix)); } - name.append(QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss-zzzz")); + name.append(QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss-zzz")); if (suffix) name.append(suffix); strcpy(bufp, name.toUtf8().data()); @@ -353,7 +357,8 @@ void plat_pause(int p) { static wchar_t oldtitle[512]; - wchar_t title[1024], paused_msg[512]; + wchar_t title[1024]; + wchar_t paused_msg[512]; if (p == dopause) { #ifdef Q_OS_WINDOWS @@ -565,14 +570,10 @@ c16stombs(char dst[], const uint16_t src[], int len) #endif #ifdef _WIN32 -# define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" # define LIB_NAME_GS "gsdll32.dll" -# define LIB_NAME_FREETYPE "freetype.dll" # define MOUSE_CAPTURE_KEYSEQ "F8+F12" #else -# define LIB_NAME_FLUIDSYNTH "libfluidsynth" # define LIB_NAME_GS "libgs" -# define LIB_NAME_FREETYPE "libfreetype" # define MOUSE_CAPTURE_KEYSEQ "CTRL-END" #endif @@ -585,13 +586,11 @@ ProgSettings::reloadStrings() translatedstrings[IDS_2077] = QCoreApplication::translate("", "Click to capture mouse").toStdWString(); translatedstrings[IDS_2078] = QCoreApplication::translate("", "Press F8+F12 to release mouse").replace("F8+F12", MOUSE_CAPTURE_KEYSEQ).replace("CTRL-END", QLocale::system().name() == "de_DE" ? "Strg+Ende" : "CTRL-END").toStdWString(); translatedstrings[IDS_2079] = QCoreApplication::translate("", "Press F8+F12 or middle button to release mouse").replace("F8+F12", MOUSE_CAPTURE_KEYSEQ).replace("CTRL-END", QLocale::system().name() == "de_DE" ? "Strg+Ende" : "CTRL-END").toStdWString(); - translatedstrings[IDS_2080] = QCoreApplication::translate("", "Failed to initialize FluidSynth").toStdWString(); translatedstrings[IDS_2131] = QCoreApplication::translate("", "Invalid configuration").toStdWString(); translatedstrings[IDS_4099] = QCoreApplication::translate("", "MFM/RLL or ESDI CD-ROM drives never existed").toStdWString(); translatedstrings[IDS_2094] = QCoreApplication::translate("", "Failed to set up PCap").toStdWString(); translatedstrings[IDS_2095] = QCoreApplication::translate("", "No PCap devices found").toStdWString(); translatedstrings[IDS_2096] = QCoreApplication::translate("", "Invalid PCap device").toStdWString(); - translatedstrings[IDS_2111] = QCoreApplication::translate("", "Unable to initialize FreeType").toStdWString(); translatedstrings[IDS_2112] = QCoreApplication::translate("", "Unable to initialize SDL, libsdl2 is required").toStdWString(); translatedstrings[IDS_2130] = QCoreApplication::translate("", "Make sure libpcap is installed and that you are on a libpcap-compatible network connection.").toStdWString(); translatedstrings[IDS_2115] = QCoreApplication::translate("", "Unable to initialize Ghostscript").toStdWString(); @@ -602,25 +601,15 @@ ProgSettings::reloadStrings() translatedstrings[IDS_2143] = QCoreApplication::translate("", "Monitor in sleep mode").toStdWString(); translatedstrings[IDS_2121] = QCoreApplication::translate("", "No ROMs found").toStdWString(); translatedstrings[IDS_2056] = QCoreApplication::translate("", "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory.").toStdWString(); + translatedstrings[IDS_2167] = QCoreApplication::translate("", "Failed to initialize network driver").toStdWString(); + translatedstrings[IDS_2168] = QCoreApplication::translate("", "The network configuration will be switched to the null driver").toStdWString(); - auto flsynthstr = QCoreApplication::translate("", " is required for FluidSynth MIDI output."); - if (flsynthstr.contains("libfluidsynth")) { - flsynthstr.replace("libfluidsynth", LIB_NAME_FLUIDSYNTH); + auto gsstr = QCoreApplication::translate("", " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files."); + if (gsstr.contains("libgs")) { + gsstr.replace("libgs", LIB_NAME_GS); } else - flsynthstr.prepend(LIB_NAME_FLUIDSYNTH); - translatedstrings[IDS_2134] = flsynthstr.toStdWString(); - auto gssynthstr = QCoreApplication::translate("", " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files."); - if (gssynthstr.contains("libgs")) { - gssynthstr.replace("libgs", LIB_NAME_GS); - } else - gssynthstr.prepend(LIB_NAME_GS); - translatedstrings[IDS_2133] = gssynthstr.toStdWString(); - auto ftsynthstr = QCoreApplication::translate("", " is required for ESC/P printer emulation."); - if (ftsynthstr.contains("libfreetype")) { - ftsynthstr.replace("libfreetype", LIB_NAME_FREETYPE); - } else - ftsynthstr.prepend(LIB_NAME_FREETYPE); - translatedstrings[IDS_2132] = ftsynthstr.toStdWString(); + gsstr.prepend(LIB_NAME_GS); + translatedstrings[IDS_2133] = gsstr.toStdWString(); } wchar_t * diff --git a/src/qt/qt_renderercommon.cpp b/src/qt/qt_renderercommon.cpp index 47bc33d51..c2b38cd52 100644 --- a/src/qt/qt_renderercommon.cpp +++ b/src/qt/qt_renderercommon.cpp @@ -55,7 +55,11 @@ RendererCommon::onResize(int width, int height) destination.setRect(0, 0, width, height); return; } - double dx, dy, dw, dh, gsr; + double dx; + double dy; + double dw; + double dh; + double gsr; double hw = width; double hh = height; diff --git a/src/qt/qt_renderercommon.hpp b/src/qt/qt_renderercommon.hpp index 97370ea3f..34b28fb30 100644 --- a/src/qt/qt_renderercommon.hpp +++ b/src/qt/qt_renderercommon.hpp @@ -41,7 +41,8 @@ public: protected: bool eventDelegate(QEvent *event, bool &result); - QRect source { 0, 0, 0, 0 }, destination; + QRect source { 0, 0, 0, 0 }; + QRect destination; QWidget *parentWidget { nullptr }; std::vector buf_usage; diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 9ebd891c3..ee87dccb8 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -58,10 +58,13 @@ double mouse_x_error = 0.0, mouse_y_error = 0.0; } struct mouseinputdata { - atomic_int deltax, deltay, deltaz; + atomic_int deltax; + atomic_int deltay; + atomic_int deltaz; atomic_int mousebuttons; atomic_bool mouse_tablet_in_proximity; - std::atomic x_abs, y_abs; + std::atomic x_abs; + std::atomic y_abs; }; static mouseinputdata mousedata; @@ -127,7 +130,7 @@ qt_mouse_capture(int on) { if (!on) { mouse_capture = 0; - QApplication::setOverrideCursor(Qt::ArrowCursor); + if (QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); #ifdef __APPLE__ CGAssociateMouseAndMouseCursorPosition(true); #endif @@ -144,6 +147,20 @@ qt_mouse_capture(int on) void RendererStack::mousePoll() { + if (m_monitor_index >= 1) { + if (mouse_mode >= 1) { + mouse_x_abs = mousedata.x_abs; + mouse_y_abs = mousedata.y_abs; + if (!mouse_tablet_in_proximity) { + mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; + } + if (mousedata.mouse_tablet_in_proximity) { + mouse_buttons = mousedata.mousebuttons; + } + } + return; + } + #ifdef Q_OS_WINDOWS if (mouse_mode == 0) { mouse_x_abs = mousedata.x_abs; @@ -151,6 +168,7 @@ RendererStack::mousePoll() return; } #endif + #ifndef __APPLE__ mouse_x = mousedata.deltax; mouse_y = mousedata.deltay; @@ -180,7 +198,7 @@ int ignoreNextMouseEvent = 1; void RendererStack::mouseReleaseEvent(QMouseEvent *event) { - if (this->geometry().contains(event->pos()) && event->button() == Qt::LeftButton && !mouse_capture && (isMouseDown & 1) && (mouse_get_buttons() != 0) && mouse_mode == 0) { + if (this->geometry().contains(event->pos()) && (event->button() == Qt::LeftButton) && !mouse_capture && (isMouseDown & 1) && (kbd_req_capture || (mouse_get_buttons() != 0)) && (mouse_mode == 0)) { plat_mouse_capture(1); this->setCursor(Qt::BlankCursor); if (!ignoreNextMouseEvent) @@ -270,8 +288,9 @@ void RendererStack::leaveEvent(QEvent *event) { mousedata.mouse_tablet_in_proximity = 0; - if (mouse_mode == 1) - QApplication::setOverrideCursor(Qt::ArrowCursor); + + if (mouse_mode == 1 && QApplication::overrideCursor()) + QApplication::restoreOverrideCursor(); if (QApplication::platformName().contains("wayland")) { event->accept(); return; @@ -308,7 +327,7 @@ RendererStack::switchRenderer(Renderer renderer) createRenderer(renderer); disconnect(this, &RendererStack::blit, this, &RendererStack::blitDummy); blitDummied = false; - QTimer::singleShot(1000, this, [this]() { blitDummied = false; }); + QTimer::singleShot(1000, this, []() { blitDummied = false; }); }); rendererWindow->hasBlitFunc() ? current.reset() : current.release()->deleteLater(); @@ -419,7 +438,7 @@ RendererStack::createRenderer(Renderer renderer) QTimer::singleShot(0, this, [this]() { switchRenderer(Renderer::Software); }); current.reset(nullptr); break; - }; + } rendererWindow = hw; connect(this, &RendererStack::blitToRenderer, hw, &VulkanWindowRenderer::onBlit, Qt::QueuedConnection); connect(hw, &VulkanWindowRenderer::rendererInitialized, [=]() { diff --git a/src/qt/qt_rendererstack.hpp b/src/qt/qt_rendererstack.hpp index 27e07747c..df52a9542 100644 --- a/src/qt/qt_rendererstack.hpp +++ b/src/qt/qt_rendererstack.hpp @@ -103,7 +103,14 @@ private: Ui::RendererStack *ui; - int x, y, w, h, sx, sy, sw, sh; + int x; + int y; + int w; + int h; + int sx; + int sy; + int sw; + int sh; int currentBuf = 0; int isMouseDown = 0; diff --git a/src/qt/qt_sdl.c b/src/qt/qt_sdl.c index 857ccf381..6d04acd25 100644 --- a/src/qt/qt_sdl.c +++ b/src/qt/qt_sdl.c @@ -78,10 +78,14 @@ static SDL_Window *sdl_win = NULL; static SDL_Renderer *sdl_render = NULL; static SDL_Texture *sdl_tex = NULL; -static int sdl_w, sdl_h; -static int sdl_fs, sdl_flags = -1; -static int cur_w, cur_h; -static int cur_ww = 0, cur_wh = 0; +static int sdl_w; +static int sdl_h; +static int sdl_fs; +static int sdl_flags = -1; +static int cur_w; +static int cur_h; +static int cur_ww = 0; +static int cur_wh = 0; static volatile int sdl_enabled = 0; static SDL_mutex *sdl_mutex = NULL; @@ -236,7 +240,16 @@ sdl_integer_scale(double *d, double *g) static void sdl_stretch(int *w, int *h, int *x, int *y) { - double hw, gw, hh, gh, dx, dy, dw, dh, gsr, hsr; + double hw; + double gw; + double hh; + double gh; + double dx; + double dy; + double dw; + double dh; + double gsr; + double hsr; hw = (double) sdl_w; hh = (double) sdl_h; @@ -298,7 +311,8 @@ sdl_blit(int x, int y, int w, int h) { SDL_Rect r_src; void *pixeldata; - int ret, pitch; + int ret; + int pitch; if (!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) { video_blit_complete(); @@ -385,10 +399,9 @@ sdl_close(void) static void sdl_select_best_hw_driver(void) { - int i; SDL_RendererInfo renderInfo; - for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) { + for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i) { SDL_GetRenderDriverInfo(i, &renderInfo); if (renderInfo.flags & SDL_RENDERER_ACCELERATED) { SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name); @@ -408,7 +421,7 @@ sdl_init_texture(void) } sdl_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STREAMING, (2048), (2048)); + SDL_TEXTUREACCESS_STREAMING, 2048, 2048); if (sdl_render == NULL) { sdl_log("SDL: unable to SDL_CreateRenderer (%s)\n", SDL_GetError()); @@ -520,13 +533,14 @@ sdl_initho(void *win) int sdl_pause(void) { - return (0); + return 0; } void sdl_resize(int w, int h) { - int ww = 0, wh = 0; + int ww = 0; + int wh = 0; if (video_fullscreen & 2) return; diff --git a/src/qt/qt_settings_bus_tracking.cpp b/src/qt/qt_settings_bus_tracking.cpp index c6069e99e..4fe112627 100644 --- a/src/qt/qt_settings_bus_tracking.cpp +++ b/src/qt/qt_settings_bus_tracking.cpp @@ -1,261 +1,256 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Program settings UI module. - * - * - * - * Authors: Miran Grca - * Cacodemon345 - * - * Copyright 2022 Miran Grca - * Copyright 2022 Cacodemon345 - */ -#include -#include -#include -#include - -#include "86box/hdd.h" -#include "qt_settings_bus_tracking.hpp" - -SettingsBusTracking::SettingsBusTracking() -{ - int i; - - mfm_tracking = 0x0000000000000000ULL; - esdi_tracking = 0x0000000000000000ULL; - xta_tracking = 0x0000000000000000ULL; - - for (i = 0; i < 8; i++) { - if (i < 4) - ide_tracking[i] = 0x0000000000000000ULL; - - scsi_tracking[i] = 0x0000000000000000ULL; - } -} - -uint8_t -SettingsBusTracking::next_free_mfm_channel() -{ - if ((mfm_tracking & 0xff00ULL) && !(mfm_tracking & 0x00ffULL)) - return 1; - - if (!(mfm_tracking & 0xff00ULL) && (mfm_tracking & 0x00ffULL)) - return 0; - - return CHANNEL_NONE; -} - -uint8_t -SettingsBusTracking::next_free_esdi_channel() -{ - if ((esdi_tracking & 0xff00ULL) && !(esdi_tracking & 0x00ffULL)) - return 1; - - if (!(esdi_tracking & 0xff00ULL) && (esdi_tracking & 0x00ffULL)) - return 0; - - return CHANNEL_NONE; -} - -uint8_t -SettingsBusTracking::next_free_xta_channel() -{ - if ((xta_tracking & 0xff00ULL) && !(xta_tracking & 0x00ffULL)) - return 1; - - if (!(xta_tracking & 0xff00ULL) && (xta_tracking & 0x00ffULL)) - return 0; - - return CHANNEL_NONE; -} - -uint8_t -SettingsBusTracking::next_free_ide_channel() -{ - int i, element; - uint64_t mask; - uint8_t ret = CHANNEL_NONE; - - for (i = 0; i < 32; i++) { - element = ((i << 3) >> 6); - mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); - - if (!(ide_tracking[element] & mask)) { - ret = (uint8_t) i; - break; - } - } - - return ret; -} - -uint8_t -SettingsBusTracking::next_free_scsi_id() -{ - int i, element; - uint64_t mask; - uint8_t ret = CHANNEL_NONE; - - for (i = 0; i < 64; i++) { - element = ((i << 3) >> 6); - mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); - - if (!(scsi_tracking[element] & mask)) { - ret = (uint8_t) i; - break; - } - } - - return ret; -} - -int -SettingsBusTracking::mfm_bus_full() -{ - int i; - uint64_t mask; - uint8_t count = 0; - - for (i = 0; i < 2; i++) { - mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); - - if (mfm_tracking & mask) - count++; - } - - return (count == 2); -} - -int -SettingsBusTracking::esdi_bus_full() -{ - int i; - uint64_t mask; - uint8_t count = 0; - - for (i = 0; i < 2; i++) { - mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); - - if (esdi_tracking & mask) - count++; - } - - return (count == 2); -} - -int -SettingsBusTracking::xta_bus_full() -{ - int i; - uint64_t mask; - uint8_t count = 0; - - for (i = 0; i < 2; i++) { - mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); - - if (xta_tracking & mask) - count++; - } - - return (count == 2); -} - -int -SettingsBusTracking::ide_bus_full() -{ - int i, element; - uint64_t mask; - uint8_t count = 0; - - for (i = 0; i < 32; i++) { - element = ((i << 3) >> 6); - mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); - - if (ide_tracking[element] & mask) - count++; - } - - return (count == 32); -} - -int -SettingsBusTracking::scsi_bus_full() -{ - int i, element; - uint64_t mask; - uint8_t count = 0; - - for (i = 0; i < 64; i++) { - element = ((i << 3) >> 6); - mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); - - if (scsi_tracking[element] & mask) - count++; - } - - return (count == 64); -} - -void -SettingsBusTracking::device_track(int set, uint8_t dev_type, int bus, int channel) -{ - int element; - uint64_t mask; - - switch (bus) { - case HDD_BUS_MFM: - mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); - - if (set) - mfm_tracking |= mask; - else - mfm_tracking &= ~mask; - break; - - case HDD_BUS_ESDI: - mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); - - if (set) - esdi_tracking |= mask; - else - esdi_tracking &= ~mask; - break; - - case HDD_BUS_XTA: - mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); - - if (set) - xta_tracking |= mask; - else - xta_tracking &= ~mask; - break; - - case HDD_BUS_IDE: - case HDD_BUS_ATAPI: - element = ((channel << 3) >> 6); - mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); - - if (set) - ide_tracking[element] |= mask; - else - ide_tracking[element] &= ~mask; - break; - - case HDD_BUS_SCSI: - element = ((channel << 3) >> 6); - mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); - - if (set) - scsi_tracking[element] |= mask; - else - scsi_tracking[element] &= ~mask; - break; - } -} +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Program settings UI module. + * + * + * + * Authors: Miran Grca + * Cacodemon345 + * + * Copyright 2022 Miran Grca + * Copyright 2022 Cacodemon345 + */ +#include +#include +#include +#include + +#include "86box/hdd.h" +#include "qt_settings_bus_tracking.hpp" + +SettingsBusTracking::SettingsBusTracking() +{ + mfm_tracking = 0x0000000000000000ULL; + esdi_tracking = 0x0000000000000000ULL; + xta_tracking = 0x0000000000000000ULL; + + for (uint8_t i = 0; i < 8; i++) { + if (i < 4) + ide_tracking[i] = 0x0000000000000000ULL; + + scsi_tracking[i] = 0x0000000000000000ULL; + } +} + +uint8_t +SettingsBusTracking::next_free_mfm_channel() +{ + if ((mfm_tracking & 0xff00ULL) && !(mfm_tracking & 0x00ffULL)) + return 1; + + if (!(mfm_tracking & 0xff00ULL) && (mfm_tracking & 0x00ffULL)) + return 0; + + return CHANNEL_NONE; +} + +uint8_t +SettingsBusTracking::next_free_esdi_channel() +{ + if ((esdi_tracking & 0xff00ULL) && !(esdi_tracking & 0x00ffULL)) + return 1; + + if (!(esdi_tracking & 0xff00ULL) && (esdi_tracking & 0x00ffULL)) + return 0; + + return CHANNEL_NONE; +} + +uint8_t +SettingsBusTracking::next_free_xta_channel() +{ + if ((xta_tracking & 0xff00ULL) && !(xta_tracking & 0x00ffULL)) + return 1; + + if (!(xta_tracking & 0xff00ULL) && (xta_tracking & 0x00ffULL)) + return 0; + + return CHANNEL_NONE; +} + +uint8_t +SettingsBusTracking::next_free_ide_channel() +{ + int element; + uint64_t mask; + uint8_t ret = CHANNEL_NONE; + + for (uint8_t i = 0; i < 32; i++) { + element = ((i << 3) >> 6); + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + + if (!(ide_tracking[element] & mask)) { + ret = (uint8_t) i; + break; + } + } + + return ret; +} + +uint8_t +SettingsBusTracking::next_free_scsi_id() +{ + int element; + uint64_t mask; + uint8_t ret = CHANNEL_NONE; + + for (uint8_t i = 0; i < 64; i++) { + element = ((i << 3) >> 6); + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + + if (!(scsi_tracking[element] & mask)) { + ret = (uint8_t) i; + break; + } + } + + return ret; +} + +int +SettingsBusTracking::mfm_bus_full() +{ + uint64_t mask; + uint8_t count = 0; + + for (uint8_t i = 0; i < 2; i++) { + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + + if (mfm_tracking & mask) + count++; + } + + return (count == 2); +} + +int +SettingsBusTracking::esdi_bus_full() +{ + uint64_t mask; + uint8_t count = 0; + + for (uint8_t i = 0; i < 2; i++) { + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + + if (esdi_tracking & mask) + count++; + } + + return (count == 2); +} + +int +SettingsBusTracking::xta_bus_full() +{ + uint64_t mask; + uint8_t count = 0; + + for (uint8_t i = 0; i < 2; i++) { + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + + if (xta_tracking & mask) + count++; + } + + return (count == 2); +} + +int +SettingsBusTracking::ide_bus_full() +{ + int element; + uint64_t mask; + uint8_t count = 0; + + for (uint8_t i = 0; i < 32; i++) { + element = ((i << 3) >> 6); + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + + if (ide_tracking[element] & mask) + count++; + } + + return (count == 32); +} + +int +SettingsBusTracking::scsi_bus_full() +{ + int element; + uint64_t mask; + uint8_t count = 0; + + for (uint8_t i = 0; i < 64; i++) { + element = ((i << 3) >> 6); + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + + if (scsi_tracking[element] & mask) + count++; + } + + return (count == 64); +} + +void +SettingsBusTracking::device_track(int set, uint8_t dev_type, int bus, int channel) +{ + int element; + uint64_t mask; + + switch (bus) { + case HDD_BUS_MFM: + mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); + + if (set) + mfm_tracking |= mask; + else + mfm_tracking &= ~mask; + break; + + case HDD_BUS_ESDI: + mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); + + if (set) + esdi_tracking |= mask; + else + esdi_tracking &= ~mask; + break; + + case HDD_BUS_XTA: + mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); + + if (set) + xta_tracking |= mask; + else + xta_tracking &= ~mask; + break; + + case HDD_BUS_IDE: + case HDD_BUS_ATAPI: + element = ((channel << 3) >> 6); + mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); + + if (set) + ide_tracking[element] |= mask; + else + ide_tracking[element] &= ~mask; + break; + + case HDD_BUS_SCSI: + element = ((channel << 3) >> 6); + mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f)); + + if (set) + scsi_tracking[element] |= mask; + else + scsi_tracking[element] &= ~mask; + break; + } +} diff --git a/src/qt/qt_settingsdisplay.cpp b/src/qt/qt_settingsdisplay.cpp index e64dc74dd..5f2f81c58 100644 --- a/src/qt/qt_settingsdisplay.cpp +++ b/src/qt/qt_settingsdisplay.cpp @@ -36,7 +36,7 @@ SettingsDisplay::SettingsDisplay(QWidget *parent) { ui->setupUi(this); - videoCard[0] = gfxcard[0]; + videoCard[0] = gfxcard[0]; videoCard[1] = gfxcard[1]; onCurrentMachineChanged(machine); } @@ -102,6 +102,11 @@ SettingsDisplay::onCurrentMachineChanged(int machineId) ui->comboBoxVideoSecondary->setEnabled(true); ui->pushButtonConfigureSecondary->setEnabled(true); } + if (video_card_get_flags(gfxcard[0]) != VIDEO_FLAG_TYPE_8514) + ibm8514_has_vga = 0; + if (video_card_get_flags(gfxcard[0]) != VIDEO_FLAG_TYPE_XGA) + xga_has_vga = 0; + ui->comboBoxVideo->setCurrentIndex(selectedRow); if (gfxcard[1] == 0) ui->pushButtonConfigureSecondary->setEnabled(false); @@ -123,10 +128,12 @@ SettingsDisplay::on_pushButtonConfigureVoodoo_clicked() void SettingsDisplay::on_pushButtonConfigureXga_clicked() { - if (machine_has_bus(machineId, MACHINE_BUS_MCA) > 0) { - DeviceConfig::ConfigureDevice(&xga_device, 0, qobject_cast(Settings::settings)); - } else { - DeviceConfig::ConfigureDevice(&xga_isa_device, 0, qobject_cast(Settings::settings)); + if (!xga_has_vga) { + if (machine_has_bus(machineId, MACHINE_BUS_MCA) > 0) { + DeviceConfig::ConfigureDevice(&xga_device, 0, qobject_cast(Settings::settings)); + } else { + DeviceConfig::ConfigureDevice(&xga_isa_device, 0, qobject_cast(Settings::settings)); + } } } @@ -139,7 +146,6 @@ SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) auto curVideoCard_2 = videoCard[1]; videoCard[0] = ui->comboBoxVideo->currentData().toInt(); ui->pushButtonConfigure->setEnabled(video_card_has_config(videoCard[0]) > 0); - bool machineHasPci = machine_has_bus(machineId, MACHINE_BUS_PCI) > 0; ui->checkBoxVoodoo->setEnabled(machineHasPci); if (machineHasPci) { @@ -149,16 +155,16 @@ SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) bool hasIsa16 = machine_has_bus(machineId, MACHINE_BUS_ISA16) > 0; bool has_MCA = machine_has_bus(machineId, MACHINE_BUS_MCA) > 0; - ui->checkBox8514->setEnabled(hasIsa16 || has_MCA); + ui->checkBox8514->setEnabled((hasIsa16 || has_MCA) && !ibm8514_has_vga); if (hasIsa16 || has_MCA) { ui->checkBox8514->setChecked(ibm8514_enabled); } - ui->checkBoxXga->setEnabled(hasIsa16 || has_MCA); + ui->checkBoxXga->setEnabled((hasIsa16 || has_MCA) && !xga_has_vga); if (hasIsa16 || has_MCA) ui->checkBoxXga->setChecked(xga_enabled); - ui->pushButtonConfigureXga->setEnabled((hasIsa16 || has_MCA) && ui->checkBoxXga->isChecked()); + ui->pushButtonConfigureXga->setEnabled((hasIsa16 || has_MCA) && ui->checkBoxXga->isChecked() && !xga_has_vga); int c = 2; @@ -187,7 +193,7 @@ SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) c++; } - if (videoCard[1] == 0 || (machine_has_flags(machineId, MACHINE_VIDEO_ONLY) > 0)) { + if ((videoCard[1] == 0) || (machine_has_flags(machineId, MACHINE_VIDEO_ONLY) > 0)) { ui->comboBoxVideoSecondary->setCurrentIndex(0); ui->pushButtonConfigureSecondary->setEnabled(false); } @@ -202,7 +208,7 @@ SettingsDisplay::on_checkBoxVoodoo_stateChanged(int state) void SettingsDisplay::on_checkBoxXga_stateChanged(int state) { - ui->pushButtonConfigureXga->setEnabled(state == Qt::Checked); + ui->pushButtonConfigureXga->setEnabled((state == Qt::Checked) && !xga_has_vga); } void diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index 1b6964898..a66203406 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -44,17 +44,17 @@ const int DataBusChannel = Qt::UserRole + 1; const int DataBusPrevious = Qt::UserRole + 2; const int DataBusChannelPrevious = Qt::UserRole + 3; -/* +#if 0 static void normalize_hd_list() { hard_disk_t ihdd[HDD_NUM]; - int i, j; + int j; j = 0; memset(ihdd, 0x00, HDD_NUM * sizeof(hard_disk_t)); - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if (temp_hdd[i].bus != HDD_BUS_DISABLED) { memcpy(&(ihdd[j]), &(temp_hdd[i]), sizeof(hard_disk_t)); j++; @@ -63,7 +63,7 @@ normalize_hd_list() memcpy(temp_hdd, ihdd, HDD_NUM * sizeof(hard_disk_t)); } -*/ +#endif static QString busChannelName(const QModelIndex &idx) diff --git a/src/qt/qt_settingsmachine.cpp b/src/qt/qt_settingsmachine.cpp index e08b07997..569d1f6c3 100644 --- a/src/qt/qt_settingsmachine.cpp +++ b/src/qt/qt_settingsmachine.cpp @@ -90,6 +90,11 @@ SettingsMachine::SettingsMachine(QWidget *parent) ui->comboBoxMachineType->setCurrentIndex(-1); ui->comboBoxMachineType->setCurrentIndex(selectedMachineType); + +#ifndef USE_DYNAREC + ui->checkBoxDynamicRecompiler->setEnabled(false); + ui->checkBoxDynamicRecompiler->setVisible(false); +#endif } SettingsMachine::~SettingsMachine() @@ -105,6 +110,8 @@ SettingsMachine::save() cpu = ui->comboBoxSpeed->currentData().toInt(); fpu_type = ui->comboBoxFPU->currentData().toInt(); cpu_use_dynarec = ui->checkBoxDynamicRecompiler->isChecked() ? 1 : 0; + fpu_softfloat = ui->checkBoxFPUSoftfloat->isChecked() ? 1 : 0; + int64_t temp_mem_size; if (machine_get_ram_granularity(machine) < 1024) { temp_mem_size = ui->spinBoxRAM->value(); @@ -194,7 +201,7 @@ SettingsMachine::on_comboBoxMachine_currentIndexChanged(int index) ui->comboBoxCPU->setCurrentIndex(selectedCpuFamilyRow); int divisor; - if ((machine_get_ram_granularity(machineId) < 1024)) { + if (machine_get_ram_granularity(machineId) < 1024) { divisor = 1; ui->spinBoxRAM->setSuffix(QCoreApplication::translate("", "KB").prepend(' ')); } else { @@ -280,6 +287,7 @@ SettingsMachine::on_comboBoxSpeed_currentIndexChanged(int index) #endif // win_settings_machine_recalc_fpu + int machineId = ui->comboBoxMachine->currentData().toInt(); auto *modelFpu = ui->comboBoxFPU->model(); int removeRows = modelFpu->rowCount(); @@ -297,6 +305,10 @@ SettingsMachine::on_comboBoxSpeed_currentIndexChanged(int index) ui->comboBoxFPU->setEnabled(modelFpu->rowCount() > 1); ui->comboBoxFPU->setCurrentIndex(-1); ui->comboBoxFPU->setCurrentIndex(selectedFpuRow); + + ui->checkBoxFPUSoftfloat->setChecked(machine_has_flags(machineId, MACHINE_SOFTFLOAT_ONLY) ? true : fpu_softfloat); + ui->checkBoxFPUSoftfloat->setEnabled(machine_has_flags(machineId, MACHINE_SOFTFLOAT_ONLY) ? false : true); + } void diff --git a/src/qt/qt_settingsmachine.ui b/src/qt/qt_settingsmachine.ui index d5ff1ca59..ee8a048f4 100644 --- a/src/qt/qt_settingsmachine.ui +++ b/src/qt/qt_settingsmachine.ui @@ -200,6 +200,19 @@ + + + + + 3 + 3 + + + + Softfloat FPU + + + diff --git a/src/qt/qt_settingsnetwork.cpp b/src/qt/qt_settingsnetwork.cpp index 014e82ab3..5b5d1b1ee 100644 --- a/src/qt/qt_settingsnetwork.cpp +++ b/src/qt/qt_settingsnetwork.cpp @@ -37,13 +37,18 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) auto *net_type_cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); auto *intf_cbox = findChild(QString("comboBoxIntf%1").arg(i + 1)); auto *conf_btn = findChild(QString("pushButtonConf%1").arg(i + 1)); + auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); int netType = net_type_cbox->currentData().toInt(); - bool adaptersEnabled = netType == NET_TYPE_SLIRP || (netType == NET_TYPE_PCAP && intf_cbox->currentData().toInt() > 0); + bool adaptersEnabled = netType == NET_TYPE_NONE + || netType == NET_TYPE_SLIRP + || netType == NET_TYPE_VDE + || (netType == NET_TYPE_PCAP && intf_cbox->currentData().toInt() > 0); intf_cbox->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_PCAP); nic_cbox->setEnabled(adaptersEnabled); conf_btn->setEnabled(adaptersEnabled && network_card_has_config(nic_cbox->currentData().toInt())); + socket_line->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_VDE); } } @@ -75,12 +80,17 @@ SettingsNetwork::save() { for (int i = 0; i < NET_CARD_MAX; ++i) { auto *cbox = findChild(QString("comboBoxNIC%1").arg(i + 1)); + auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); net_cards_conf[i].device_num = cbox->currentData().toInt(); cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); net_cards_conf[i].net_type = cbox->currentData().toInt(); cbox = findChild(QString("comboBoxIntf%1").arg(i + 1)); memset(net_cards_conf[i].host_dev_name, '\0', sizeof(net_cards_conf[i].host_dev_name)); - strncpy(net_cards_conf[i].host_dev_name, network_devs[cbox->currentData().toInt()].device, sizeof(net_cards_conf[i].host_dev_name) - 1); + if (net_cards_conf[i].net_type == NET_TYPE_PCAP) { + strncpy(net_cards_conf[i].host_dev_name, network_devs[cbox->currentData().toInt()].device, sizeof(net_cards_conf[i].host_dev_name) - 1); + } else if (net_cards_conf[i].net_type == NET_TYPE_VDE) { + strncpy(net_cards_conf[i].host_dev_name, socket_line->text().toUtf8().constData(), sizeof(net_cards_conf[i].host_dev_name)); + } } } @@ -122,28 +132,40 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); model = cbox->model(); removeRows = model->rowCount(); - Models::AddEntry(model, tr("None"), NET_TYPE_NONE); + Models::AddEntry(model, tr("Null Driver"), NET_TYPE_NONE); Models::AddEntry(model, "SLiRP", NET_TYPE_SLIRP); + if (network_ndev > 1) { Models::AddEntry(model, "PCap", NET_TYPE_PCAP); } + if (network_devmap.has_vde) { + Models::AddEntry(model, "VDE", NET_TYPE_VDE); + } + model->removeRows(0, removeRows); cbox->setCurrentIndex(net_cards_conf[i].net_type); selectedRow = 0; - QString currentPcapDevice = net_cards_conf[i].host_dev_name; - cbox = findChild(QString("comboBoxIntf%1").arg(i + 1)); - model = cbox->model(); - removeRows = model->rowCount(); - for (int c = 0; c < network_ndev; c++) { - Models::AddEntry(model, tr(network_devs[c].description), c); - if (QString(network_devs[c].device) == currentPcapDevice) { - selectedRow = c; + if (network_ndev > 0) { + QString currentPcapDevice = net_cards_conf[i].host_dev_name; + cbox = findChild(QString("comboBoxIntf%1").arg(i + 1)); + model = cbox->model(); + removeRows = model->rowCount(); + for (int c = 0; c < network_ndev; c++) { + Models::AddEntry(model, tr(network_devs[c].description), c); + if (QString(network_devs[c].device) == currentPcapDevice) { + selectedRow = c; + } } + model->removeRows(0, removeRows); + cbox->setCurrentIndex(selectedRow); + } + if (net_cards_conf[i].net_type == NET_TYPE_VDE) { + QString currentVdeSocket = net_cards_conf[i].host_dev_name; + auto editline = findChild(QString("socketVDENIC%1").arg(i+1)); + editline->setText(currentVdeSocket); } - model->removeRows(0, removeRows); - cbox->setCurrentIndex(selectedRow); } } diff --git a/src/qt/qt_settingsnetwork.ui b/src/qt/qt_settingsnetwork.ui index d781a1beb..d6681a65e 100644 --- a/src/qt/qt_settingsnetwork.ui +++ b/src/qt/qt_settingsnetwork.ui @@ -36,21 +36,8 @@ Network Card #1 - - - - - 0 - 0 - - - - QComboBox::AdjustToContents - - - - - + + 0 @@ -58,7 +45,7 @@ - Adapter + Mode @@ -72,19 +59,6 @@ - - - - - 0 - 0 - - - - Configure - - - @@ -98,19 +72,6 @@ - - - - - 0 - 0 - - - - Mode - - - @@ -121,8 +82,61 @@ - - + + + + + 0 + 0 + + + + Adapter + + + + + + + + 0 + 0 + + + + QComboBox::AdjustToContents + + + + + + + + 0 + 0 + + + + Configure + + + + + + + VDE Socket + + + + + + + 127 + + + + + Qt::Vertical @@ -141,6 +155,29 @@ Network Card #2 + + + + + 0 + 0 + + + + Mode + + + + + + + + 0 + 0 + + + + @@ -154,17 +191,14 @@ - - + + - + 0 0 - - Mode - @@ -193,26 +227,6 @@ - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - @@ -220,8 +234,22 @@ - - + + + + VDE Socket + + + + + + + 127 + + + + + Qt::Vertical @@ -240,29 +268,6 @@ Network Card #3 - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Adapter - - - @@ -276,6 +281,16 @@ + + + + + 0 + 0 + + + + @@ -299,16 +314,16 @@ - - + + - + 0 0 - Configure + Adapter @@ -325,7 +340,34 @@ - + + + + + 0 + 0 + + + + Configure + + + + + + + VDE Socket + + + + + + + 127 + + + + Qt::Vertical @@ -345,29 +387,16 @@ Network Card #4 - - + + - - 0 - 0 - - - - QComboBox::AdjustToContents - - - - - - - + 0 0 - Configure + Mode @@ -394,6 +423,16 @@ + + + + + 0 + 0 + + + + @@ -407,30 +446,47 @@ - - + + 0 0 + + QComboBox::AdjustToContents + - - + + - + 0 0 - Mode + Configure - + + + + 127 + + + + + + + VDE Socket + + + + Qt::Vertical diff --git a/src/qt/qt_settingsotherperipherals.cpp b/src/qt/qt_settingsotherperipherals.cpp index e0edd7358..d168138a5 100644 --- a/src/qt/qt_settingsotherperipherals.cpp +++ b/src/qt/qt_settingsotherperipherals.cpp @@ -41,11 +41,12 @@ SettingsOtherPeripherals::onCurrentMachineChanged(int machineId) { this->machineId = machineId; - ui->checkBoxISABugger->setChecked(bugger_enabled > 0 ? true : false); + bool machineHasIsa = (machine_has_bus(machineId, MACHINE_BUS_ISA) > 0); + ui->checkBoxISABugger->setChecked((machineHasIsa && (bugger_enabled > 0)) ? true : false); ui->checkBoxPOSTCard->setChecked(postcard_enabled > 0 ? true : false); - ui->checkBoxISABugger->setEnabled(machine_has_bus(machineId, MACHINE_BUS_ISA)); - ui->comboBoxRTC->setEnabled(machine_has_bus(machineId, MACHINE_BUS_ISA)); - ui->pushButtonConfigureRTC->setEnabled(machine_has_bus(machineId, MACHINE_BUS_ISA)); + ui->checkBoxISABugger->setEnabled(machineHasIsa); + ui->comboBoxRTC->setEnabled(machineHasIsa); + ui->pushButtonConfigureRTC->setEnabled(machineHasIsa); ui->comboBoxCard1->clear(); ui->comboBoxCard2->clear(); @@ -97,8 +98,8 @@ SettingsOtherPeripherals::onCurrentMachineChanged(int machineId) } cbox->setCurrentIndex(-1); cbox->setCurrentIndex(selectedRow); - cbox->setEnabled(machine_has_bus(machineId, MACHINE_BUS_ISA)); - findChild(QString("pushButtonConfigureCard%1").arg(c + 1))->setEnabled(isamem_type[c] != 0 && machine_has_bus(machineId, MACHINE_BUS_ISA)); + cbox->setEnabled(machineHasIsa); + findChild(QString("pushButtonConfigureCard%1").arg(c + 1))->setEnabled(isamem_type[c] != 0 && machineHasIsa); } } diff --git a/src/qt/qt_settingsstoragecontrollers.cpp b/src/qt/qt_settingsstoragecontrollers.cpp index a732e9820..30949de3a 100644 --- a/src/qt/qt_settingsstoragecontrollers.cpp +++ b/src/qt/qt_settingsstoragecontrollers.cpp @@ -40,8 +40,6 @@ SettingsStorageControllers::SettingsStorageControllers(QWidget *parent) { ui->setupUi(this); - ui->checkBoxCassette->setChecked(cassette_enable > 0); - onCurrentMachineChanged(machine); } @@ -58,12 +56,12 @@ SettingsStorageControllers::save() auto *cbox = findChild(QString("comboBoxSCSI%1").arg(i + 1)); scsi_card_current[i] = cbox->currentData().toInt(); } - hdc_current = ui->comboBoxHD->currentData().toInt(); - fdc_type = ui->comboBoxFD->currentData().toInt(); - cdrom_interface_current = ui->comboBoxCDInterface->currentData().toInt(); - ide_ter_enabled = ui->checkBoxTertiaryIDE->isChecked() ? 1 : 0; - ide_qua_enabled = ui->checkBoxQuaternaryIDE->isChecked() ? 1 : 0; - cassette_enable = ui->checkBoxCassette->isChecked() ? 1 : 0; + hdc_current = ui->comboBoxHD->currentData().toInt(); + fdc_type = ui->comboBoxFD->currentData().toInt(); + cdrom_interface_current = ui->comboBoxCDInterface->currentData().toInt(); + ide_ter_enabled = ui->checkBoxTertiaryIDE->isChecked() ? 1 : 0; + ide_qua_enabled = ui->checkBoxQuaternaryIDE->isChecked() ? 1 : 0; + cassette_enable = ui->checkBoxCassette->isChecked() ? 1 : 0; } void @@ -134,9 +132,9 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) ui->comboBoxFD->setCurrentIndex(selectedRow); /*CD interface controller config*/ - model = ui->comboBoxCDInterface->model(); - removeRows = model->rowCount(); - c = 0; + model = ui->comboBoxCDInterface->model(); + removeRows = model->rowCount(); + c = 0; selectedRow = 0; while (true) { /* Skip "internal" if machine doesn't have it. */ @@ -198,6 +196,14 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) ui->checkBoxQuaternaryIDE->setEnabled(is_at > 0); ui->checkBoxTertiaryIDE->setChecked(ui->checkBoxTertiaryIDE->isEnabled() && ide_ter_enabled); ui->checkBoxQuaternaryIDE->setChecked(ui->checkBoxQuaternaryIDE->isEnabled() && ide_qua_enabled); + + if (machine_has_bus(machineId, MACHINE_BUS_CASSETTE)) { + ui->checkBoxCassette->setChecked(cassette_enable > 0); + ui->checkBoxCassette->setEnabled(true); + } else { + ui->checkBoxCassette->setChecked(false); + ui->checkBoxCassette->setEnabled(false); + } } void diff --git a/src/qt/qt_settingsstoragecontrollers.ui b/src/qt/qt_settingsstoragecontrollers.ui index 558d4c441..9fc0ea519 100644 --- a/src/qt/qt_settingsstoragecontrollers.ui +++ b/src/qt/qt_settingsstoragecontrollers.ui @@ -54,16 +54,26 @@ CD-ROM Controller: + + false + - + + + false + + Configure + + false + diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index 9d52e596a..22dad3fa1 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -29,7 +29,9 @@ MainWindow *main_window = nullptr; -static QString sb_text, sb_buguitext, sb_mt32lcdtext; +static QString sb_text; +static QString sb_buguitext; +static QString sb_mt32lcdtext; extern "C" { @@ -221,7 +223,6 @@ ui_sb_bugui(char *str) { sb_buguitext = str; ui_sb_update_text(); - ; } void diff --git a/src/qt/qt_vulkanrenderer.cpp b/src/qt/qt_vulkanrenderer.cpp index 41791a026..73594ea9e 100644 --- a/src/qt/qt_vulkanrenderer.cpp +++ b/src/qt/qt_vulkanrenderer.cpp @@ -1,1013 +1,1015 @@ -/**************************************************************************** -** -** Copyright (C) 2022 Cacodemon345 -** Copyright (C) 2017 The Qt Company Ltd. -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -****************************************************************************/ - -#include -#include -#include "qt_vulkanrenderer.hpp" -#if QT_CONFIG(vulkan) -# include - -extern "C" { -# include <86box/86box.h> -} - -// Use a triangle strip to get a quad. -// -// Note that the vertex data and the projection matrix assume OpenGL. With -// Vulkan Y is negated in clip space and the near/far plane is at 0/1 instead -// of -1/1. These will be corrected for by an extra transformation when -// calculating the modelview-projection matrix. -static float vertexData[] = { // Y up, front = CW - // x, y, z, u, v - -1, -1, 0, 0, 1, - -1, 1, 0, 0, 0, - 1, -1, 0, 1, 1, - 1, 1, 0, 1, 0 -}; - -static const int UNIFORM_DATA_SIZE = 16 * sizeof(float); - -static inline VkDeviceSize -aligned(VkDeviceSize v, VkDeviceSize byteAlign) -{ - return (v + byteAlign - 1) & ~(byteAlign - 1); -} - -VulkanRenderer2::VulkanRenderer2(QVulkanWindow *w) - : m_window(w) -{ -} - -VkShaderModule -VulkanRenderer2::createShader(const QString &name) -{ - QFile file(name); - if (!file.open(QIODevice::ReadOnly)) { - qWarning("Failed to read shader %s", qPrintable(name)); - return VK_NULL_HANDLE; - } - QByteArray blob = file.readAll(); - file.close(); - - VkShaderModuleCreateInfo shaderInfo; - memset(&shaderInfo, 0, sizeof(shaderInfo)); - shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - shaderInfo.codeSize = blob.size(); - shaderInfo.pCode = reinterpret_cast(blob.constData()); - VkShaderModule shaderModule; - VkResult err = m_devFuncs->vkCreateShaderModule(m_window->device(), &shaderInfo, nullptr, &shaderModule); - if (err != VK_SUCCESS) { - qWarning("Failed to create shader module: %d", err); - return VK_NULL_HANDLE; - } - - return shaderModule; -} - -bool -VulkanRenderer2::createTexture() -{ - QImage img(2048, 2048, QImage::Format_RGBA8888_Premultiplied); - img.fill(QColor(0, 0, 0)); - - QVulkanFunctions *f = m_window->vulkanInstance()->functions(); - VkDevice dev = m_window->device(); - - m_texFormat = VK_FORMAT_B8G8R8A8_UNORM; - - // Now we can either map and copy the image data directly, or have to go - // through a staging buffer to copy and convert into the internal optimal - // tiling format. - VkFormatProperties props; - f->vkGetPhysicalDeviceFormatProperties(m_window->physicalDevice(), m_texFormat, &props); - const bool canSampleLinear = (props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); - const bool canSampleOptimal = (props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); - if (!canSampleLinear && !canSampleOptimal) { - qWarning("Neither linear nor optimal image sampling is supported for RGBA8"); - return false; - } - - static bool alwaysStage = qEnvironmentVariableIntValue("QT_VK_FORCE_STAGE_TEX"); - - if (canSampleLinear && !alwaysStage) { - if (!createTextureImage(img.size(), &m_texImage, &m_texMem, - VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT, - m_window->hostVisibleMemoryIndex())) - return false; - - if (!writeLinearImage(img, m_texImage, m_texMem)) - return false; - - m_texLayoutPending = true; - } else { - if (!createTextureImage(img.size(), &m_texStaging, &m_texStagingMem, - VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, - m_window->hostVisibleMemoryIndex())) - return false; - - if (!createTextureImage(img.size(), &m_texImage, &m_texMem, - VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, - m_window->deviceLocalMemoryIndex())) - return false; - - if (!writeLinearImage(img, m_texStaging, m_texStagingMem)) - return false; - - m_texStagingPending = true; - } - - VkImageViewCreateInfo viewInfo; - memset(&viewInfo, 0, sizeof(viewInfo)); - viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - viewInfo.image = m_texImage; - viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; - viewInfo.format = m_texFormat; - viewInfo.components.r = VK_COMPONENT_SWIZZLE_R; - viewInfo.components.g = VK_COMPONENT_SWIZZLE_G; - viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; - viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; - viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - viewInfo.subresourceRange.levelCount = viewInfo.subresourceRange.layerCount = 1; - - VkResult err = m_devFuncs->vkCreateImageView(dev, &viewInfo, nullptr, &m_texView); - if (err != VK_SUCCESS) { - qWarning("Failed to create image view for texture: %d", err); - return false; - } - - m_texSize = img.size(); - - return true; -} - -bool -VulkanRenderer2::createTextureImage(const QSize &size, VkImage *image, VkDeviceMemory *mem, - VkImageTiling tiling, VkImageUsageFlags usage, uint32_t memIndex) -{ - VkDevice dev = m_window->device(); - - VkImageCreateInfo imageInfo; - memset(&imageInfo, 0, sizeof(imageInfo)); - imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - imageInfo.imageType = VK_IMAGE_TYPE_2D; - imageInfo.format = m_texFormat; - imageInfo.extent.width = size.width(); - imageInfo.extent.height = size.height(); - imageInfo.extent.depth = 1; - imageInfo.mipLevels = 1; - imageInfo.arrayLayers = 1; - imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; - imageInfo.tiling = tiling; - imageInfo.usage = usage; - imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; - - VkResult err = m_devFuncs->vkCreateImage(dev, &imageInfo, nullptr, image); - if (err != VK_SUCCESS) { - qWarning("Failed to create linear image for texture: %d", err); - return false; - } - - VkMemoryRequirements memReq; - m_devFuncs->vkGetImageMemoryRequirements(dev, *image, &memReq); - - if (!(memReq.memoryTypeBits & (1 << memIndex))) { - VkPhysicalDeviceMemoryProperties physDevMemProps; - m_window->vulkanInstance()->functions()->vkGetPhysicalDeviceMemoryProperties(m_window->physicalDevice(), &physDevMemProps); - for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) { - if (!(memReq.memoryTypeBits & (1 << i))) - continue; - memIndex = i; - } - } - - VkMemoryAllocateInfo allocInfo = { - VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, - nullptr, - memReq.size, - memIndex - }; - qDebug("allocating %u bytes for texture image", uint32_t(memReq.size)); - - err = m_devFuncs->vkAllocateMemory(dev, &allocInfo, nullptr, mem); - if (err != VK_SUCCESS) { - qWarning("Failed to allocate memory for linear image: %d", err); - return false; - } - - err = m_devFuncs->vkBindImageMemory(dev, *image, *mem, 0); - if (err != VK_SUCCESS) { - qWarning("Failed to bind linear image memory: %d", err); - return false; - } - - return true; -} - -bool -VulkanRenderer2::writeLinearImage(const QImage &img, VkImage image, VkDeviceMemory memory) -{ - VkDevice dev = m_window->device(); - - VkImageSubresource subres = { - VK_IMAGE_ASPECT_COLOR_BIT, - 0, // mip level - 0 - }; - VkSubresourceLayout layout; - m_devFuncs->vkGetImageSubresourceLayout(dev, image, &subres, &layout); - - uchar *p; - VkResult err = m_devFuncs->vkMapMemory(dev, memory, layout.offset, layout.size, 0, reinterpret_cast(&p)); - if (err != VK_SUCCESS) { - qWarning("Failed to map memory for linear image: %d", err); - return false; - } - - for (int y = 0; y < img.height(); ++y) { - const uchar *line = img.constScanLine(y); - memcpy(p, line, img.width() * 4); - p += layout.rowPitch; - } - - m_devFuncs->vkUnmapMemory(dev, memory); - return true; -} - -void -VulkanRenderer2::ensureTexture() -{ - if (!m_texLayoutPending && !m_texStagingPending) - return; - - Q_ASSERT(m_texLayoutPending != m_texStagingPending); - VkCommandBuffer cb = m_window->currentCommandBuffer(); - - VkImageMemoryBarrier barrier; - memset(&barrier, 0, sizeof(barrier)); - barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - barrier.subresourceRange.levelCount = barrier.subresourceRange.layerCount = 1; - - if (m_texLayoutPending) { - m_texLayoutPending = false; - - barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; - barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - barrier.image = m_texImage; - - m_devFuncs->vkCmdPipelineBarrier(cb, - VK_PIPELINE_STAGE_HOST_BIT, - VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, - 0, 0, nullptr, 0, nullptr, - 1, &barrier); - - VkDevice dev = m_window->device(); - - VkImageSubresource subres = { - VK_IMAGE_ASPECT_COLOR_BIT, - 0, // mip level - 0 - }; - VkSubresourceLayout layout; - m_devFuncs->vkGetImageSubresourceLayout(dev, m_texImage, &subres, &layout); - - VkResult err = m_devFuncs->vkMapMemory(dev, m_texMem, layout.offset, layout.size, 0, reinterpret_cast(&mappedPtr)); - if (err != VK_SUCCESS) { - qWarning("Failed to map memory for linear image: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - imagePitch = layout.rowPitch; - - if (qobject_cast(m_window)) { - emit qobject_cast(m_window)->rendererInitialized(); - } - } else { - m_texStagingPending = false; - - if (!m_texStagingTransferLayout) { - barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; - barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; - barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; - barrier.image = m_texStaging; - m_devFuncs->vkCmdPipelineBarrier(cb, - VK_PIPELINE_STAGE_HOST_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, - 0, 0, nullptr, 0, nullptr, - 1, &barrier); - - barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; - barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - barrier.srcAccessMask = 0; - barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - barrier.image = m_texImage; - m_devFuncs->vkCmdPipelineBarrier(cb, - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, - 0, 0, nullptr, 0, nullptr, - 1, &barrier); - - VkDevice dev = m_window->device(); - - VkImageSubresource subres = { - VK_IMAGE_ASPECT_COLOR_BIT, - 0, // mip level - 0 - }; - VkSubresourceLayout layout; - m_devFuncs->vkGetImageSubresourceLayout(dev, m_texStaging, &subres, &layout); - - VkResult err = m_devFuncs->vkMapMemory(dev, m_texStagingMem, layout.offset, layout.size, 0, reinterpret_cast(&mappedPtr)); - if (err != VK_SUCCESS) { - qWarning("Failed to map memory for linear image: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - imagePitch = layout.rowPitch; - - if (qobject_cast(m_window)) { - emit qobject_cast(m_window)->rendererInitialized(); - } - - m_texStagingTransferLayout = true; - } - - VkImageCopy copyInfo; - memset(©Info, 0, sizeof(copyInfo)); - copyInfo.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - copyInfo.srcSubresource.layerCount = 1; - copyInfo.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - copyInfo.dstSubresource.layerCount = 1; - copyInfo.extent.width = m_texSize.width(); - copyInfo.extent.height = m_texSize.height(); - copyInfo.extent.depth = 1; - m_devFuncs->vkCmdCopyImage(cb, m_texStaging, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - m_texImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©Info); - - barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - barrier.image = m_texImage; - m_devFuncs->vkCmdPipelineBarrier(cb, - VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, - 0, 0, nullptr, 0, nullptr, - 1, &barrier); - } -} - -void -VulkanRenderer2::updateSamplers() -{ - static int cur_video_filter_method = -1; - - if (cur_video_filter_method != video_filter_method) { - cur_video_filter_method = video_filter_method; - m_devFuncs->vkDeviceWaitIdle(m_window->device()); - - VkDescriptorImageInfo descImageInfo = { - cur_video_filter_method == 1 ? m_linearSampler : m_sampler, - m_texView, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL - }; - - for (int i = 0; i < m_window->concurrentFrameCount(); i++) { - VkWriteDescriptorSet descWrite[2]; - memset(descWrite, 0, sizeof(descWrite)); - descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - descWrite[0].dstSet = m_descSet[i]; - descWrite[0].dstBinding = 0; - descWrite[0].descriptorCount = 1; - descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - descWrite[0].pBufferInfo = &m_uniformBufInfo[i]; - - descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - descWrite[1].dstSet = m_descSet[i]; - descWrite[1].dstBinding = 1; - descWrite[1].descriptorCount = 1; - descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - descWrite[1].pImageInfo = &descImageInfo; - m_devFuncs->vkUpdateDescriptorSets(m_window->device(), 2, descWrite, 0, nullptr); - } - } -} - -void -VulkanRenderer2::initResources() -{ - qDebug("initResources"); - - VkDevice dev = m_window->device(); - m_devFuncs = m_window->vulkanInstance()->deviceFunctions(dev); - - // The setup is similar to hellovulkantriangle. The difference is the - // presence of a second vertex attribute (texcoord), a sampler, and that we - // need blending. - - const int concurrentFrameCount = m_window->concurrentFrameCount(); - const VkPhysicalDeviceLimits *pdevLimits = &m_window->physicalDeviceProperties()->limits; - const VkDeviceSize uniAlign = pdevLimits->minUniformBufferOffsetAlignment; - qDebug("uniform buffer offset alignment is %u", (uint) uniAlign); - VkBufferCreateInfo bufInfo; - memset(&bufInfo, 0, sizeof(bufInfo)); - bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - // Our internal layout is vertex, uniform, uniform, ... with each uniform buffer start offset aligned to uniAlign. - const VkDeviceSize vertexAllocSize = aligned(sizeof(vertexData), uniAlign); - const VkDeviceSize uniformAllocSize = aligned(UNIFORM_DATA_SIZE, uniAlign); - bufInfo.size = vertexAllocSize + concurrentFrameCount * uniformAllocSize; - bufInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; - - VkResult err = m_devFuncs->vkCreateBuffer(dev, &bufInfo, nullptr, &m_buf); - if (err != VK_SUCCESS) { - qWarning("Failed to create buffer: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - VkMemoryRequirements memReq; - m_devFuncs->vkGetBufferMemoryRequirements(dev, m_buf, &memReq); - - VkMemoryAllocateInfo memAllocInfo = { - VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, - nullptr, - memReq.size, - m_window->hostVisibleMemoryIndex() - }; - - err = m_devFuncs->vkAllocateMemory(dev, &memAllocInfo, nullptr, &m_bufMem); - if (err != VK_SUCCESS) { - qWarning("Failed to allocate memory: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - err = m_devFuncs->vkBindBufferMemory(dev, m_buf, m_bufMem, 0); - if (err != VK_SUCCESS) { - qWarning("Failed to bind buffer memory: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - quint8 *p; - err = m_devFuncs->vkMapMemory(dev, m_bufMem, 0, memReq.size, 0, reinterpret_cast(&p)); - if (err != VK_SUCCESS) { - qWarning("Failed to map memory: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - memcpy(p, vertexData, sizeof(vertexData)); - QMatrix4x4 ident; - memset(m_uniformBufInfo, 0, sizeof(m_uniformBufInfo)); - for (int i = 0; i < concurrentFrameCount; ++i) { - const VkDeviceSize offset = vertexAllocSize + i * uniformAllocSize; - memcpy(p + offset, ident.constData(), 16 * sizeof(float)); - m_uniformBufInfo[i].buffer = m_buf; - m_uniformBufInfo[i].offset = offset; - m_uniformBufInfo[i].range = uniformAllocSize; - } - m_devFuncs->vkUnmapMemory(dev, m_bufMem); - - VkVertexInputBindingDescription vertexBindingDesc = { - 0, // binding - 5 * sizeof(float), - VK_VERTEX_INPUT_RATE_VERTEX - }; - VkVertexInputAttributeDescription vertexAttrDesc[] = { - {// position - 0, // location - 0, // binding - VK_FORMAT_R32G32B32_SFLOAT, - 0 }, - { // texcoord - 1, - 0, - VK_FORMAT_R32G32_SFLOAT, - 3 * sizeof(float)} - }; - - VkPipelineVertexInputStateCreateInfo vertexInputInfo; - vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.pNext = nullptr; - vertexInputInfo.flags = 0; - vertexInputInfo.vertexBindingDescriptionCount = 1; - vertexInputInfo.pVertexBindingDescriptions = &vertexBindingDesc; - vertexInputInfo.vertexAttributeDescriptionCount = 2; - vertexInputInfo.pVertexAttributeDescriptions = vertexAttrDesc; - - // Sampler. - VkSamplerCreateInfo samplerInfo; - memset(&samplerInfo, 0, sizeof(samplerInfo)); - samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - samplerInfo.magFilter = VK_FILTER_NEAREST; - samplerInfo.minFilter = VK_FILTER_NEAREST; - samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - samplerInfo.maxAnisotropy = 1.0f; - samplerInfo.maxLod = 0.25; - err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_sampler); - if (err != VK_SUCCESS) { - qWarning("Failed to create sampler: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - samplerInfo.magFilter = VK_FILTER_LINEAR; - samplerInfo.minFilter = VK_FILTER_LINEAR; - err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_linearSampler); - if (err != VK_SUCCESS) { - qWarning("Failed to create sampler: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - // Texture. - if (!createTexture()) { - qWarning("Failed to create texture"); - return emit qobject_cast(m_window)->errorInitializing(); - } - - // Set up descriptor set and its layout. - VkDescriptorPoolSize descPoolSizes[2] = { - {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uint32_t(concurrentFrameCount)}, - { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, uint32_t(concurrentFrameCount)} - }; - VkDescriptorPoolCreateInfo descPoolInfo; - memset(&descPoolInfo, 0, sizeof(descPoolInfo)); - descPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; - descPoolInfo.maxSets = concurrentFrameCount; - descPoolInfo.poolSizeCount = 2; - descPoolInfo.pPoolSizes = descPoolSizes; - err = m_devFuncs->vkCreateDescriptorPool(dev, &descPoolInfo, nullptr, &m_descPool); - if (err != VK_SUCCESS) { - qWarning("Failed to create descriptor pool: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - VkDescriptorSetLayoutBinding layoutBinding[2] = { - {0, // binding - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 1, // descriptorCount - VK_SHADER_STAGE_VERTEX_BIT, - nullptr}, - { 1, // binding - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - 1, // descriptorCount - VK_SHADER_STAGE_FRAGMENT_BIT, - nullptr} - }; - VkDescriptorSetLayoutCreateInfo descLayoutInfo = { - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, - nullptr, - 0, - 2, // bindingCount - layoutBinding - }; - err = m_devFuncs->vkCreateDescriptorSetLayout(dev, &descLayoutInfo, nullptr, &m_descSetLayout); - if (err != VK_SUCCESS) { - qWarning("Failed to create descriptor set layout: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - for (int i = 0; i < concurrentFrameCount; ++i) { - VkDescriptorSetAllocateInfo descSetAllocInfo = { - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, - nullptr, - m_descPool, - 1, - &m_descSetLayout - }; - err = m_devFuncs->vkAllocateDescriptorSets(dev, &descSetAllocInfo, &m_descSet[i]); - if (err != VK_SUCCESS) { - qWarning("Failed to allocate descriptor set: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - VkWriteDescriptorSet descWrite[2]; - memset(descWrite, 0, sizeof(descWrite)); - descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - descWrite[0].dstSet = m_descSet[i]; - descWrite[0].dstBinding = 0; - descWrite[0].descriptorCount = 1; - descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - descWrite[0].pBufferInfo = &m_uniformBufInfo[i]; - - VkDescriptorImageInfo descImageInfo = { - video_filter_method == 1 ? m_linearSampler : m_sampler, - m_texView, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL - }; - - descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - descWrite[1].dstSet = m_descSet[i]; - descWrite[1].dstBinding = 1; - descWrite[1].descriptorCount = 1; - descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - descWrite[1].pImageInfo = &descImageInfo; - - m_devFuncs->vkUpdateDescriptorSets(dev, 2, descWrite, 0, nullptr); - } - - // Pipeline cache - VkPipelineCacheCreateInfo pipelineCacheInfo; - memset(&pipelineCacheInfo, 0, sizeof(pipelineCacheInfo)); - pipelineCacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; - err = m_devFuncs->vkCreatePipelineCache(dev, &pipelineCacheInfo, nullptr, &m_pipelineCache); - if (err != VK_SUCCESS) { - qWarning("Failed to create pipeline cache: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - // Pipeline layout - VkPipelineLayoutCreateInfo pipelineLayoutInfo; - memset(&pipelineLayoutInfo, 0, sizeof(pipelineLayoutInfo)); - pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - pipelineLayoutInfo.setLayoutCount = 1; - pipelineLayoutInfo.pSetLayouts = &m_descSetLayout; - err = m_devFuncs->vkCreatePipelineLayout(dev, &pipelineLayoutInfo, nullptr, &m_pipelineLayout); - if (err != VK_SUCCESS) { - qWarning("Failed to create pipeline layout: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - // Shaders - /* - #version 440 - - layout(location = 0) in vec4 position; - layout(location = 1) in vec2 texcoord; - - layout(location = 0) out vec2 v_texcoord; - - layout(std140, binding = 0) uniform buf { - mat4 mvp; - } ubuf; - - out gl_PerVertex { vec4 gl_Position; }; - - void main() - { - v_texcoord = texcoord; - gl_Position = ubuf.mvp * position; - } - */ - VkShaderModule vertShaderModule = createShader(QStringLiteral(":/texture_vert.spv")); - /* - #version 440 - - layout(location = 0) in vec2 v_texcoord; - - layout(location = 0) out vec4 fragColor; - - layout(binding = 1) uniform sampler2D tex; - - void main() - { - fragColor = texture(tex, v_texcoord); - } - */ - VkShaderModule fragShaderModule = createShader(QStringLiteral(":/texture_frag.spv")); - - // Graphics pipeline - VkGraphicsPipelineCreateInfo pipelineInfo; - memset(&pipelineInfo, 0, sizeof(pipelineInfo)); - pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - - VkPipelineShaderStageCreateInfo shaderStages[2] = { - { - VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, - nullptr, - 0, - VK_SHADER_STAGE_VERTEX_BIT, - vertShaderModule, - "main", - nullptr - }, - { - VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, - nullptr, - 0, - VK_SHADER_STAGE_FRAGMENT_BIT, - fragShaderModule, - "main", - nullptr - } - }; - pipelineInfo.stageCount = 2; - pipelineInfo.pStages = shaderStages; - - pipelineInfo.pVertexInputState = &vertexInputInfo; - - VkPipelineInputAssemblyStateCreateInfo ia; - memset(&ia, 0, sizeof(ia)); - ia.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; - pipelineInfo.pInputAssemblyState = &ia; - - // The viewport and scissor will be set dynamically via vkCmdSetViewport/Scissor. - // This way the pipeline does not need to be touched when resizing the window. - VkPipelineViewportStateCreateInfo vp; - memset(&vp, 0, sizeof(vp)); - vp.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - vp.viewportCount = 1; - vp.scissorCount = 1; - pipelineInfo.pViewportState = &vp; - - VkPipelineRasterizationStateCreateInfo rs; - memset(&rs, 0, sizeof(rs)); - rs.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rs.polygonMode = VK_POLYGON_MODE_FILL; - rs.cullMode = VK_CULL_MODE_BACK_BIT; - rs.frontFace = VK_FRONT_FACE_CLOCKWISE; - rs.lineWidth = 1.0f; - pipelineInfo.pRasterizationState = &rs; - - VkPipelineMultisampleStateCreateInfo ms; - memset(&ms, 0, sizeof(ms)); - ms.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - ms.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; - pipelineInfo.pMultisampleState = &ms; - - VkPipelineDepthStencilStateCreateInfo ds; - memset(&ds, 0, sizeof(ds)); - ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - ds.depthTestEnable = VK_TRUE; - ds.depthWriteEnable = VK_TRUE; - ds.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; - pipelineInfo.pDepthStencilState = &ds; - - VkPipelineColorBlendStateCreateInfo cb; - memset(&cb, 0, sizeof(cb)); - cb.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - // assume pre-multiplied alpha, blend, write out all of rgba - VkPipelineColorBlendAttachmentState att; - memset(&att, 0, sizeof(att)); - att.colorWriteMask = 0xF; - att.blendEnable = VK_TRUE; - att.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; - att.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - att.colorBlendOp = VK_BLEND_OP_ADD; - att.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - att.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - att.alphaBlendOp = VK_BLEND_OP_ADD; - cb.attachmentCount = 1; - cb.pAttachments = &att; - pipelineInfo.pColorBlendState = &cb; - - VkDynamicState dynEnable[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; - VkPipelineDynamicStateCreateInfo dyn; - memset(&dyn, 0, sizeof(dyn)); - dyn.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dyn.dynamicStateCount = sizeof(dynEnable) / sizeof(VkDynamicState); - dyn.pDynamicStates = dynEnable; - pipelineInfo.pDynamicState = &dyn; - - pipelineInfo.layout = m_pipelineLayout; - pipelineInfo.renderPass = m_window->defaultRenderPass(); - - err = m_devFuncs->vkCreateGraphicsPipelines(dev, m_pipelineCache, 1, &pipelineInfo, nullptr, &m_pipeline); - if (err != VK_SUCCESS) { - qWarning("Failed to create graphics pipeline: %d", err); - return emit qobject_cast(m_window)->errorInitializing(); - } - - if (vertShaderModule) - m_devFuncs->vkDestroyShaderModule(dev, vertShaderModule, nullptr); - if (fragShaderModule) - m_devFuncs->vkDestroyShaderModule(dev, fragShaderModule, nullptr); - - pclog("Vulkan device: %s\n", m_window->physicalDeviceProperties()->deviceName); - pclog("Vulkan API version: %d.%d.%d\n", VK_VERSION_MAJOR(m_window->physicalDeviceProperties()->apiVersion), VK_VERSION_MINOR(m_window->physicalDeviceProperties()->apiVersion), VK_VERSION_PATCH(m_window->physicalDeviceProperties()->apiVersion)); - pclog("Vulkan driver version: %d.%d.%d\n", VK_VERSION_MAJOR(m_window->physicalDeviceProperties()->driverVersion), VK_VERSION_MINOR(m_window->physicalDeviceProperties()->driverVersion), VK_VERSION_PATCH(m_window->physicalDeviceProperties()->driverVersion)); -} - -void -VulkanRenderer2::initSwapChainResources() -{ - qDebug("initSwapChainResources"); - - // Projection matrix - m_proj = m_window->clipCorrectionMatrix(); // adjust for Vulkan-OpenGL clip space differences -} - -void -VulkanRenderer2::releaseSwapChainResources() -{ - qDebug("releaseSwapChainResources"); -} - -void -VulkanRenderer2::releaseResources() -{ - qDebug("releaseResources"); - - VkDevice dev = m_window->device(); - - if (m_sampler) { - m_devFuncs->vkDestroySampler(dev, m_sampler, nullptr); - m_sampler = VK_NULL_HANDLE; - } - - if (m_linearSampler) { - m_devFuncs->vkDestroySampler(dev, m_linearSampler, nullptr); - m_linearSampler = VK_NULL_HANDLE; - } - - if (m_texStaging) { - m_devFuncs->vkDestroyImage(dev, m_texStaging, nullptr); - m_texStaging = VK_NULL_HANDLE; - } - - if (m_texStagingMem) { - m_devFuncs->vkFreeMemory(dev, m_texStagingMem, nullptr); - m_texStagingMem = VK_NULL_HANDLE; - } - - if (m_texView) { - m_devFuncs->vkDestroyImageView(dev, m_texView, nullptr); - m_texView = VK_NULL_HANDLE; - } - - if (m_texImage) { - m_devFuncs->vkDestroyImage(dev, m_texImage, nullptr); - m_texImage = VK_NULL_HANDLE; - } - - if (m_texMem) { - m_devFuncs->vkFreeMemory(dev, m_texMem, nullptr); - m_texMem = VK_NULL_HANDLE; - } - - if (m_pipeline) { - m_devFuncs->vkDestroyPipeline(dev, m_pipeline, nullptr); - m_pipeline = VK_NULL_HANDLE; - } - - if (m_pipelineLayout) { - m_devFuncs->vkDestroyPipelineLayout(dev, m_pipelineLayout, nullptr); - m_pipelineLayout = VK_NULL_HANDLE; - } - - if (m_pipelineCache) { - m_devFuncs->vkDestroyPipelineCache(dev, m_pipelineCache, nullptr); - m_pipelineCache = VK_NULL_HANDLE; - } - - if (m_descSetLayout) { - m_devFuncs->vkDestroyDescriptorSetLayout(dev, m_descSetLayout, nullptr); - m_descSetLayout = VK_NULL_HANDLE; - } - - if (m_descPool) { - m_devFuncs->vkDestroyDescriptorPool(dev, m_descPool, nullptr); - m_descPool = VK_NULL_HANDLE; - } - - if (m_buf) { - m_devFuncs->vkDestroyBuffer(dev, m_buf, nullptr); - m_buf = VK_NULL_HANDLE; - } - - if (m_bufMem) { - m_devFuncs->vkFreeMemory(dev, m_bufMem, nullptr); - m_bufMem = VK_NULL_HANDLE; - } -} - -void -VulkanRenderer2::startNextFrame() -{ - VkDevice dev = m_window->device(); - VkCommandBuffer cb = m_window->currentCommandBuffer(); - const QSize sz = m_window->swapChainImageSize(); - - updateSamplers(); - // Add the necessary barriers and do the host-linear -> device-optimal copy, if not yet done. - ensureTexture(); - - VkClearColorValue clearColor = { - {0, 0, 0, 1} - }; - VkClearDepthStencilValue clearDS = { 1, 0 }; - VkClearValue clearValues[2]; - memset(clearValues, 0, sizeof(clearValues)); - clearValues[0].color = clearColor; - clearValues[1].depthStencil = clearDS; - - VkRenderPassBeginInfo rpBeginInfo; - memset(&rpBeginInfo, 0, sizeof(rpBeginInfo)); - rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - rpBeginInfo.renderPass = m_window->defaultRenderPass(); - rpBeginInfo.framebuffer = m_window->currentFramebuffer(); - rpBeginInfo.renderArea.extent.width = sz.width(); - rpBeginInfo.renderArea.extent.height = sz.height(); - rpBeginInfo.clearValueCount = 2; - rpBeginInfo.pClearValues = clearValues; - VkCommandBuffer cmdBuf = m_window->currentCommandBuffer(); - m_devFuncs->vkCmdBeginRenderPass(cmdBuf, &rpBeginInfo, VK_SUBPASS_CONTENTS_INLINE); - - quint8 *p; - VkResult err = m_devFuncs->vkMapMemory(dev, m_bufMem, m_uniformBufInfo[m_window->currentFrame()].offset, - UNIFORM_DATA_SIZE, 0, reinterpret_cast(&p)); - if (err != VK_SUCCESS) - qFatal("Failed to map memory: %d", err); - QMatrix4x4 m = m_proj; - // m.rotate(m_rotation, 0, 0, 1); - memcpy(p, m.constData(), 16 * sizeof(float)); - m_devFuncs->vkUnmapMemory(dev, m_bufMem); - p = nullptr; - - // Second pass for texture coordinates. - err = m_devFuncs->vkMapMemory(dev, m_bufMem, 0, - sizeof(vertexData), 0, reinterpret_cast(&p)); - if (err != VK_SUCCESS) - qFatal("Failed to map memory: %d", err); - - float *floatData = (float *) p; - auto source = qobject_cast(m_window)->source; - auto destination = qobject_cast(m_window)->destination; - floatData[3] = (float) source.x() / 2048.f; - floatData[9] = (float) (source.y()) / 2048.f; - floatData[8] = (float) source.x() / 2048.f; - floatData[4] = (float) (source.y() + source.height()) / 2048.f; - floatData[13] = (float) (source.x() + source.width()) / 2048.f; - floatData[19] = (float) (source.y()) / 2048.f; - floatData[18] = (float) (source.x() + source.width()) / 2048.f; - floatData[14] = (float) (source.y() + source.height()) / 2048.f; - - m_devFuncs->vkUnmapMemory(dev, m_bufMem); - - m_devFuncs->vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline); - m_devFuncs->vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, - &m_descSet[m_window->currentFrame()], 0, nullptr); - VkDeviceSize vbOffset = 0; - m_devFuncs->vkCmdBindVertexBuffers(cb, 0, 1, &m_buf, &vbOffset); - - VkViewport viewport; - viewport.x = destination.x() * m_window->devicePixelRatio(); - viewport.y = destination.y() * m_window->devicePixelRatio(); - viewport.width = destination.width() * m_window->devicePixelRatio(); - viewport.height = destination.height() * m_window->devicePixelRatio(); - viewport.minDepth = 0; - viewport.maxDepth = 1; - m_devFuncs->vkCmdSetViewport(cb, 0, 1, &viewport); - - VkRect2D scissor; - scissor.offset.x = viewport.x; - scissor.offset.y = viewport.y; - scissor.extent.width = viewport.width; - scissor.extent.height = viewport.height; - m_devFuncs->vkCmdSetScissor(cb, 0, 1, &scissor); - - m_devFuncs->vkCmdDraw(cb, 4, 1, 0, 0); - - m_devFuncs->vkCmdEndRenderPass(cmdBuf); - - if (m_texStagingTransferLayout) { - VkImageMemoryBarrier barrier {}; - barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - barrier.subresourceRange.levelCount = barrier.subresourceRange.layerCount = 1; - barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - barrier.oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT; - barrier.image = m_texImage; - m_devFuncs->vkCmdPipelineBarrier(cb, - VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, - 0, 0, nullptr, 0, nullptr, - 1, &barrier); - m_texStagingPending = true; - } - - m_window->frameReady(); - m_window->requestUpdate(); // render continuously, throttled by the presentation rate -} -#endif +/**************************************************************************** +** +** Copyright (C) 2022 Cacodemon345 +** Copyright (C) 2017 The Qt Company Ltd. +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ + +#include +#include +#include "qt_vulkanrenderer.hpp" +#if QT_CONFIG(vulkan) +# include + +extern "C" { +# include <86box/86box.h> +} + +// Use a triangle strip to get a quad. +// +// Note that the vertex data and the projection matrix assume OpenGL. With +// Vulkan Y is negated in clip space and the near/far plane is at 0/1 instead +// of -1/1. These will be corrected for by an extra transformation when +// calculating the modelview-projection matrix. +static float vertexData[] = { // Y up, front = CW + // x, y, z, u, v + -1, -1, 0, 0, 1, + -1, 1, 0, 0, 0, + 1, -1, 0, 1, 1, + 1, 1, 0, 1, 0 +}; + +static const int UNIFORM_DATA_SIZE = 16 * sizeof(float); + +static inline VkDeviceSize +aligned(VkDeviceSize v, VkDeviceSize byteAlign) +{ + return (v + byteAlign - 1) & ~(byteAlign - 1); +} + +VulkanRenderer2::VulkanRenderer2(QVulkanWindow *w) + : m_window(w) +{ +} + +VkShaderModule +VulkanRenderer2::createShader(const QString &name) +{ + QFile file(name); + if (!file.open(QIODevice::ReadOnly)) { + qWarning("Failed to read shader %s", qPrintable(name)); + return VK_NULL_HANDLE; + } + QByteArray blob = file.readAll(); + file.close(); + + VkShaderModuleCreateInfo shaderInfo; + memset(&shaderInfo, 0, sizeof(shaderInfo)); + shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + shaderInfo.codeSize = blob.size(); + shaderInfo.pCode = reinterpret_cast(blob.constData()); + VkShaderModule shaderModule; + VkResult err = m_devFuncs->vkCreateShaderModule(m_window->device(), &shaderInfo, nullptr, &shaderModule); + if (err != VK_SUCCESS) { + qWarning("Failed to create shader module: %d", err); + return VK_NULL_HANDLE; + } + + return shaderModule; +} + +bool +VulkanRenderer2::createTexture() +{ + QImage img(2048, 2048, QImage::Format_RGBA8888_Premultiplied); + img.fill(QColor(0, 0, 0)); + + QVulkanFunctions *f = m_window->vulkanInstance()->functions(); + VkDevice dev = m_window->device(); + + m_texFormat = VK_FORMAT_B8G8R8A8_UNORM; + + // Now we can either map and copy the image data directly, or have to go + // through a staging buffer to copy and convert into the internal optimal + // tiling format. + VkFormatProperties props; + f->vkGetPhysicalDeviceFormatProperties(m_window->physicalDevice(), m_texFormat, &props); + const bool canSampleLinear = (props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); + const bool canSampleOptimal = (props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); + if (!canSampleLinear && !canSampleOptimal) { + qWarning("Neither linear nor optimal image sampling is supported for RGBA8"); + return false; + } + + static bool alwaysStage = qEnvironmentVariableIntValue("QT_VK_FORCE_STAGE_TEX"); + + if (canSampleLinear && !alwaysStage) { + if (!createTextureImage(img.size(), &m_texImage, &m_texMem, + VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT, + m_window->hostVisibleMemoryIndex())) + return false; + + if (!writeLinearImage(img, m_texImage, m_texMem)) + return false; + + m_texLayoutPending = true; + } else { + if (!createTextureImage(img.size(), &m_texStaging, &m_texStagingMem, + VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, + m_window->hostVisibleMemoryIndex())) + return false; + + if (!createTextureImage(img.size(), &m_texImage, &m_texMem, + VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, + m_window->deviceLocalMemoryIndex())) + return false; + + if (!writeLinearImage(img, m_texStaging, m_texStagingMem)) + return false; + + m_texStagingPending = true; + } + + VkImageViewCreateInfo viewInfo; + memset(&viewInfo, 0, sizeof(viewInfo)); + viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + viewInfo.image = m_texImage; + viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; + viewInfo.format = m_texFormat; + viewInfo.components.r = VK_COMPONENT_SWIZZLE_R; + viewInfo.components.g = VK_COMPONENT_SWIZZLE_G; + viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; + viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; + viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + viewInfo.subresourceRange.levelCount = viewInfo.subresourceRange.layerCount = 1; + + VkResult err = m_devFuncs->vkCreateImageView(dev, &viewInfo, nullptr, &m_texView); + if (err != VK_SUCCESS) { + qWarning("Failed to create image view for texture: %d", err); + return false; + } + + m_texSize = img.size(); + + return true; +} + +bool +VulkanRenderer2::createTextureImage(const QSize &size, VkImage *image, VkDeviceMemory *mem, + VkImageTiling tiling, VkImageUsageFlags usage, uint32_t memIndex) +{ + VkDevice dev = m_window->device(); + + VkImageCreateInfo imageInfo; + memset(&imageInfo, 0, sizeof(imageInfo)); + imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + imageInfo.imageType = VK_IMAGE_TYPE_2D; + imageInfo.format = m_texFormat; + imageInfo.extent.width = size.width(); + imageInfo.extent.height = size.height(); + imageInfo.extent.depth = 1; + imageInfo.mipLevels = 1; + imageInfo.arrayLayers = 1; + imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; + imageInfo.tiling = tiling; + imageInfo.usage = usage; + imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + + VkResult err = m_devFuncs->vkCreateImage(dev, &imageInfo, nullptr, image); + if (err != VK_SUCCESS) { + qWarning("Failed to create linear image for texture: %d", err); + return false; + } + + VkMemoryRequirements memReq; + m_devFuncs->vkGetImageMemoryRequirements(dev, *image, &memReq); + + if (!(memReq.memoryTypeBits & (1 << memIndex))) { + VkPhysicalDeviceMemoryProperties physDevMemProps; + m_window->vulkanInstance()->functions()->vkGetPhysicalDeviceMemoryProperties(m_window->physicalDevice(), &physDevMemProps); + for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) { + if (!(memReq.memoryTypeBits & (1 << i))) + continue; + memIndex = i; + } + } + + VkMemoryAllocateInfo allocInfo = { + VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + nullptr, + memReq.size, + memIndex + }; + qDebug("allocating %u bytes for texture image", uint32_t(memReq.size)); + + err = m_devFuncs->vkAllocateMemory(dev, &allocInfo, nullptr, mem); + if (err != VK_SUCCESS) { + qWarning("Failed to allocate memory for linear image: %d", err); + return false; + } + + err = m_devFuncs->vkBindImageMemory(dev, *image, *mem, 0); + if (err != VK_SUCCESS) { + qWarning("Failed to bind linear image memory: %d", err); + return false; + } + + return true; +} + +bool +VulkanRenderer2::writeLinearImage(const QImage &img, VkImage image, VkDeviceMemory memory) +{ + VkDevice dev = m_window->device(); + + VkImageSubresource subres = { + VK_IMAGE_ASPECT_COLOR_BIT, + 0, // mip level + 0 + }; + VkSubresourceLayout layout; + m_devFuncs->vkGetImageSubresourceLayout(dev, image, &subres, &layout); + + uchar *p; + VkResult err = m_devFuncs->vkMapMemory(dev, memory, layout.offset, layout.size, 0, reinterpret_cast(&p)); + if (err != VK_SUCCESS) { + qWarning("Failed to map memory for linear image: %d", err); + return false; + } + + for (int y = 0; y < img.height(); ++y) { + const uchar *line = img.constScanLine(y); + memcpy(p, line, img.width() * 4); + p += layout.rowPitch; + } + + m_devFuncs->vkUnmapMemory(dev, memory); + return true; +} + +void +VulkanRenderer2::ensureTexture() +{ + if (!m_texLayoutPending && !m_texStagingPending) + return; + + Q_ASSERT(m_texLayoutPending != m_texStagingPending); + VkCommandBuffer cb = m_window->currentCommandBuffer(); + + VkImageMemoryBarrier barrier; + memset(&barrier, 0, sizeof(barrier)); + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.levelCount = barrier.subresourceRange.layerCount = 1; + + if (m_texLayoutPending) { + m_texLayoutPending = false; + + barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; + barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barrier.image = m_texImage; + + m_devFuncs->vkCmdPipelineBarrier(cb, + VK_PIPELINE_STAGE_HOST_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, 0, nullptr, 0, nullptr, + 1, &barrier); + + VkDevice dev = m_window->device(); + + VkImageSubresource subres = { + VK_IMAGE_ASPECT_COLOR_BIT, + 0, // mip level + 0 + }; + VkSubresourceLayout layout; + m_devFuncs->vkGetImageSubresourceLayout(dev, m_texImage, &subres, &layout); + + VkResult err = m_devFuncs->vkMapMemory(dev, m_texMem, layout.offset, layout.size, 0, reinterpret_cast(&mappedPtr)); + if (err != VK_SUCCESS) { + qWarning("Failed to map memory for linear image: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + imagePitch = layout.rowPitch; + + if (qobject_cast(m_window)) { + emit qobject_cast(m_window)->rendererInitialized(); + } + } else { + m_texStagingPending = false; + + if (!m_texStagingTransferLayout) { + barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; + barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + barrier.image = m_texStaging; + m_devFuncs->vkCmdPipelineBarrier(cb, + VK_PIPELINE_STAGE_HOST_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, nullptr, 0, nullptr, + 1, &barrier); + + barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; + barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + barrier.srcAccessMask = 0; + barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barrier.image = m_texImage; + m_devFuncs->vkCmdPipelineBarrier(cb, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, nullptr, 0, nullptr, + 1, &barrier); + + VkDevice dev = m_window->device(); + + VkImageSubresource subres = { + VK_IMAGE_ASPECT_COLOR_BIT, + 0, // mip level + 0 + }; + VkSubresourceLayout layout; + m_devFuncs->vkGetImageSubresourceLayout(dev, m_texStaging, &subres, &layout); + + VkResult err = m_devFuncs->vkMapMemory(dev, m_texStagingMem, layout.offset, layout.size, 0, reinterpret_cast(&mappedPtr)); + if (err != VK_SUCCESS) { + qWarning("Failed to map memory for linear image: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + imagePitch = layout.rowPitch; + + if (qobject_cast(m_window)) { + emit qobject_cast(m_window)->rendererInitialized(); + } + + m_texStagingTransferLayout = true; + } + + VkImageCopy copyInfo; + memset(©Info, 0, sizeof(copyInfo)); + copyInfo.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + copyInfo.srcSubresource.layerCount = 1; + copyInfo.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + copyInfo.dstSubresource.layerCount = 1; + copyInfo.extent.width = m_texSize.width(); + copyInfo.extent.height = m_texSize.height(); + copyInfo.extent.depth = 1; + m_devFuncs->vkCmdCopyImage(cb, m_texStaging, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + m_texImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©Info); + + barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; + barrier.image = m_texImage; + m_devFuncs->vkCmdPipelineBarrier(cb, + VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, 0, nullptr, 0, nullptr, + 1, &barrier); + } +} + +void +VulkanRenderer2::updateSamplers() +{ + static int cur_video_filter_method = -1; + + if (cur_video_filter_method != video_filter_method) { + cur_video_filter_method = video_filter_method; + m_devFuncs->vkDeviceWaitIdle(m_window->device()); + + VkDescriptorImageInfo descImageInfo = { + cur_video_filter_method == 1 ? m_linearSampler : m_sampler, + m_texView, + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + }; + + for (int i = 0; i < m_window->concurrentFrameCount(); i++) { + VkWriteDescriptorSet descWrite[2]; + memset(descWrite, 0, sizeof(descWrite)); + descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + descWrite[0].dstSet = m_descSet[i]; + descWrite[0].dstBinding = 0; + descWrite[0].descriptorCount = 1; + descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + descWrite[0].pBufferInfo = &m_uniformBufInfo[i]; + + descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + descWrite[1].dstSet = m_descSet[i]; + descWrite[1].dstBinding = 1; + descWrite[1].descriptorCount = 1; + descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + descWrite[1].pImageInfo = &descImageInfo; + m_devFuncs->vkUpdateDescriptorSets(m_window->device(), 2, descWrite, 0, nullptr); + } + } +} + +void +VulkanRenderer2::initResources() +{ + qDebug("initResources"); + + VkDevice dev = m_window->device(); + m_devFuncs = m_window->vulkanInstance()->deviceFunctions(dev); + + // The setup is similar to hellovulkantriangle. The difference is the + // presence of a second vertex attribute (texcoord), a sampler, and that we + // need blending. + + const int concurrentFrameCount = m_window->concurrentFrameCount(); + const VkPhysicalDeviceLimits *pdevLimits = &m_window->physicalDeviceProperties()->limits; + const VkDeviceSize uniAlign = pdevLimits->minUniformBufferOffsetAlignment; + qDebug("uniform buffer offset alignment is %u", (uint) uniAlign); + VkBufferCreateInfo bufInfo; + memset(&bufInfo, 0, sizeof(bufInfo)); + bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + // Our internal layout is vertex, uniform, uniform, ... with each uniform buffer start offset aligned to uniAlign. + const VkDeviceSize vertexAllocSize = aligned(sizeof(vertexData), uniAlign); + const VkDeviceSize uniformAllocSize = aligned(UNIFORM_DATA_SIZE, uniAlign); + bufInfo.size = vertexAllocSize + concurrentFrameCount * uniformAllocSize; + bufInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + + VkResult err = m_devFuncs->vkCreateBuffer(dev, &bufInfo, nullptr, &m_buf); + if (err != VK_SUCCESS) { + qWarning("Failed to create buffer: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + VkMemoryRequirements memReq; + m_devFuncs->vkGetBufferMemoryRequirements(dev, m_buf, &memReq); + + VkMemoryAllocateInfo memAllocInfo = { + VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + nullptr, + memReq.size, + m_window->hostVisibleMemoryIndex() + }; + + err = m_devFuncs->vkAllocateMemory(dev, &memAllocInfo, nullptr, &m_bufMem); + if (err != VK_SUCCESS) { + qWarning("Failed to allocate memory: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + err = m_devFuncs->vkBindBufferMemory(dev, m_buf, m_bufMem, 0); + if (err != VK_SUCCESS) { + qWarning("Failed to bind buffer memory: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + quint8 *p; + err = m_devFuncs->vkMapMemory(dev, m_bufMem, 0, memReq.size, 0, reinterpret_cast(&p)); + if (err != VK_SUCCESS) { + qWarning("Failed to map memory: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + memcpy(p, vertexData, sizeof(vertexData)); + QMatrix4x4 ident; + memset(m_uniformBufInfo, 0, sizeof(m_uniformBufInfo)); + for (int i = 0; i < concurrentFrameCount; ++i) { + const VkDeviceSize offset = vertexAllocSize + i * uniformAllocSize; + memcpy(p + offset, ident.constData(), 16 * sizeof(float)); + m_uniformBufInfo[i].buffer = m_buf; + m_uniformBufInfo[i].offset = offset; + m_uniformBufInfo[i].range = uniformAllocSize; + } + m_devFuncs->vkUnmapMemory(dev, m_bufMem); + + VkVertexInputBindingDescription vertexBindingDesc = { + 0, // binding + 5 * sizeof(float), + VK_VERTEX_INPUT_RATE_VERTEX + }; + VkVertexInputAttributeDescription vertexAttrDesc[] = { + {// position + 0, // location + 0, // binding + VK_FORMAT_R32G32B32_SFLOAT, + 0 }, + { // texcoord + 1, + 0, + VK_FORMAT_R32G32_SFLOAT, + 3 * sizeof(float)} + }; + + VkPipelineVertexInputStateCreateInfo vertexInputInfo; + vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertexInputInfo.pNext = nullptr; + vertexInputInfo.flags = 0; + vertexInputInfo.vertexBindingDescriptionCount = 1; + vertexInputInfo.pVertexBindingDescriptions = &vertexBindingDesc; + vertexInputInfo.vertexAttributeDescriptionCount = 2; + vertexInputInfo.pVertexAttributeDescriptions = vertexAttrDesc; + + // Sampler. + VkSamplerCreateInfo samplerInfo; + memset(&samplerInfo, 0, sizeof(samplerInfo)); + samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + samplerInfo.magFilter = VK_FILTER_NEAREST; + samplerInfo.minFilter = VK_FILTER_NEAREST; + samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + samplerInfo.maxAnisotropy = 1.0f; + samplerInfo.maxLod = 0.25; + err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_sampler); + if (err != VK_SUCCESS) { + qWarning("Failed to create sampler: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + samplerInfo.magFilter = VK_FILTER_LINEAR; + samplerInfo.minFilter = VK_FILTER_LINEAR; + err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_linearSampler); + if (err != VK_SUCCESS) { + qWarning("Failed to create sampler: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + // Texture. + if (!createTexture()) { + qWarning("Failed to create texture"); + return emit qobject_cast(m_window)->errorInitializing(); + } + + // Set up descriptor set and its layout. + VkDescriptorPoolSize descPoolSizes[2] = { + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uint32_t(concurrentFrameCount)}, + { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, uint32_t(concurrentFrameCount)} + }; + VkDescriptorPoolCreateInfo descPoolInfo; + memset(&descPoolInfo, 0, sizeof(descPoolInfo)); + descPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + descPoolInfo.maxSets = concurrentFrameCount; + descPoolInfo.poolSizeCount = 2; + descPoolInfo.pPoolSizes = descPoolSizes; + err = m_devFuncs->vkCreateDescriptorPool(dev, &descPoolInfo, nullptr, &m_descPool); + if (err != VK_SUCCESS) { + qWarning("Failed to create descriptor pool: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + VkDescriptorSetLayoutBinding layoutBinding[2] = { + {0, // binding + VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + 1, // descriptorCount + VK_SHADER_STAGE_VERTEX_BIT, + nullptr}, + { 1, // binding + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + 1, // descriptorCount + VK_SHADER_STAGE_FRAGMENT_BIT, + nullptr} + }; + VkDescriptorSetLayoutCreateInfo descLayoutInfo = { + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, + nullptr, + 0, + 2, // bindingCount + layoutBinding + }; + err = m_devFuncs->vkCreateDescriptorSetLayout(dev, &descLayoutInfo, nullptr, &m_descSetLayout); + if (err != VK_SUCCESS) { + qWarning("Failed to create descriptor set layout: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + for (int i = 0; i < concurrentFrameCount; ++i) { + VkDescriptorSetAllocateInfo descSetAllocInfo = { + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, + nullptr, + m_descPool, + 1, + &m_descSetLayout + }; + err = m_devFuncs->vkAllocateDescriptorSets(dev, &descSetAllocInfo, &m_descSet[i]); + if (err != VK_SUCCESS) { + qWarning("Failed to allocate descriptor set: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + VkWriteDescriptorSet descWrite[2]; + memset(descWrite, 0, sizeof(descWrite)); + descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + descWrite[0].dstSet = m_descSet[i]; + descWrite[0].dstBinding = 0; + descWrite[0].descriptorCount = 1; + descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + descWrite[0].pBufferInfo = &m_uniformBufInfo[i]; + + VkDescriptorImageInfo descImageInfo = { + video_filter_method == 1 ? m_linearSampler : m_sampler, + m_texView, + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + }; + + descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + descWrite[1].dstSet = m_descSet[i]; + descWrite[1].dstBinding = 1; + descWrite[1].descriptorCount = 1; + descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + descWrite[1].pImageInfo = &descImageInfo; + + m_devFuncs->vkUpdateDescriptorSets(dev, 2, descWrite, 0, nullptr); + } + + // Pipeline cache + VkPipelineCacheCreateInfo pipelineCacheInfo; + memset(&pipelineCacheInfo, 0, sizeof(pipelineCacheInfo)); + pipelineCacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; + err = m_devFuncs->vkCreatePipelineCache(dev, &pipelineCacheInfo, nullptr, &m_pipelineCache); + if (err != VK_SUCCESS) { + qWarning("Failed to create pipeline cache: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + // Pipeline layout + VkPipelineLayoutCreateInfo pipelineLayoutInfo; + memset(&pipelineLayoutInfo, 0, sizeof(pipelineLayoutInfo)); + pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipelineLayoutInfo.setLayoutCount = 1; + pipelineLayoutInfo.pSetLayouts = &m_descSetLayout; + err = m_devFuncs->vkCreatePipelineLayout(dev, &pipelineLayoutInfo, nullptr, &m_pipelineLayout); + if (err != VK_SUCCESS) { + qWarning("Failed to create pipeline layout: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + // Shaders +#if 0 + #version 440 + + layout(location = 0) in vec4 position; + layout(location = 1) in vec2 texcoord; + + layout(location = 0) out vec2 v_texcoord; + + layout(std140, binding = 0) uniform buf { + mat4 mvp; + } ubuf; + + out gl_PerVertex { vec4 gl_Position; }; + + void main() + { + v_texcoord = texcoord; + gl_Position = ubuf.mvp * position; + } +#endif + VkShaderModule vertShaderModule = createShader(QStringLiteral(":/texture_vert.spv")); +#if 0 + #version 440 + + layout(location = 0) in vec2 v_texcoord; + + layout(location = 0) out vec4 fragColor; + + layout(binding = 1) uniform sampler2D tex; + + void main() + { + fragColor = texture(tex, v_texcoord); + } +#endif + VkShaderModule fragShaderModule = createShader(QStringLiteral(":/texture_frag.spv")); + + // Graphics pipeline + VkGraphicsPipelineCreateInfo pipelineInfo; + memset(&pipelineInfo, 0, sizeof(pipelineInfo)); + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + + VkPipelineShaderStageCreateInfo shaderStages[2] = { + { + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + nullptr, + 0, + VK_SHADER_STAGE_VERTEX_BIT, + vertShaderModule, + "main", + nullptr + }, + { + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + nullptr, + 0, + VK_SHADER_STAGE_FRAGMENT_BIT, + fragShaderModule, + "main", + nullptr + } + }; + pipelineInfo.stageCount = 2; + pipelineInfo.pStages = shaderStages; + + pipelineInfo.pVertexInputState = &vertexInputInfo; + + VkPipelineInputAssemblyStateCreateInfo ia; + memset(&ia, 0, sizeof(ia)); + ia.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + pipelineInfo.pInputAssemblyState = &ia; + + // The viewport and scissor will be set dynamically via vkCmdSetViewport/Scissor. + // This way the pipeline does not need to be touched when resizing the window. + VkPipelineViewportStateCreateInfo vp; + memset(&vp, 0, sizeof(vp)); + vp.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + vp.viewportCount = 1; + vp.scissorCount = 1; + pipelineInfo.pViewportState = &vp; + + VkPipelineRasterizationStateCreateInfo rs; + memset(&rs, 0, sizeof(rs)); + rs.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rs.polygonMode = VK_POLYGON_MODE_FILL; + rs.cullMode = VK_CULL_MODE_BACK_BIT; + rs.frontFace = VK_FRONT_FACE_CLOCKWISE; + rs.lineWidth = 1.0f; + pipelineInfo.pRasterizationState = &rs; + + VkPipelineMultisampleStateCreateInfo ms; + memset(&ms, 0, sizeof(ms)); + ms.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + ms.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + pipelineInfo.pMultisampleState = &ms; + + VkPipelineDepthStencilStateCreateInfo ds; + memset(&ds, 0, sizeof(ds)); + ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + ds.depthTestEnable = VK_TRUE; + ds.depthWriteEnable = VK_TRUE; + ds.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; + pipelineInfo.pDepthStencilState = &ds; + + VkPipelineColorBlendStateCreateInfo cb; + memset(&cb, 0, sizeof(cb)); + cb.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + // assume pre-multiplied alpha, blend, write out all of rgba + VkPipelineColorBlendAttachmentState att; + memset(&att, 0, sizeof(att)); + att.colorWriteMask = 0xF; + att.blendEnable = VK_TRUE; + att.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; + att.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + att.colorBlendOp = VK_BLEND_OP_ADD; + att.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + att.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + att.alphaBlendOp = VK_BLEND_OP_ADD; + cb.attachmentCount = 1; + cb.pAttachments = &att; + pipelineInfo.pColorBlendState = &cb; + + VkDynamicState dynEnable[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; + VkPipelineDynamicStateCreateInfo dyn; + memset(&dyn, 0, sizeof(dyn)); + dyn.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dyn.dynamicStateCount = sizeof(dynEnable) / sizeof(VkDynamicState); + dyn.pDynamicStates = dynEnable; + pipelineInfo.pDynamicState = &dyn; + + pipelineInfo.layout = m_pipelineLayout; + pipelineInfo.renderPass = m_window->defaultRenderPass(); + + err = m_devFuncs->vkCreateGraphicsPipelines(dev, m_pipelineCache, 1, &pipelineInfo, nullptr, &m_pipeline); + if (err != VK_SUCCESS) { + qWarning("Failed to create graphics pipeline: %d", err); + return emit qobject_cast(m_window)->errorInitializing(); + } + + if (vertShaderModule) + m_devFuncs->vkDestroyShaderModule(dev, vertShaderModule, nullptr); + if (fragShaderModule) + m_devFuncs->vkDestroyShaderModule(dev, fragShaderModule, nullptr); + + pclog("Vulkan device: %s\n", m_window->physicalDeviceProperties()->deviceName); + pclog("Vulkan API version: %d.%d.%d\n", VK_VERSION_MAJOR(m_window->physicalDeviceProperties()->apiVersion), VK_VERSION_MINOR(m_window->physicalDeviceProperties()->apiVersion), VK_VERSION_PATCH(m_window->physicalDeviceProperties()->apiVersion)); + pclog("Vulkan driver version: %d.%d.%d\n", VK_VERSION_MAJOR(m_window->physicalDeviceProperties()->driverVersion), VK_VERSION_MINOR(m_window->physicalDeviceProperties()->driverVersion), VK_VERSION_PATCH(m_window->physicalDeviceProperties()->driverVersion)); +} + +void +VulkanRenderer2::initSwapChainResources() +{ + qDebug("initSwapChainResources"); + + // Projection matrix + m_proj = m_window->clipCorrectionMatrix(); // adjust for Vulkan-OpenGL clip space differences +} + +void +VulkanRenderer2::releaseSwapChainResources() +{ + qDebug("releaseSwapChainResources"); +} + +void +VulkanRenderer2::releaseResources() +{ + qDebug("releaseResources"); + + VkDevice dev = m_window->device(); + + if (m_sampler) { + m_devFuncs->vkDestroySampler(dev, m_sampler, nullptr); + m_sampler = VK_NULL_HANDLE; + } + + if (m_linearSampler) { + m_devFuncs->vkDestroySampler(dev, m_linearSampler, nullptr); + m_linearSampler = VK_NULL_HANDLE; + } + + if (m_texStaging) { + m_devFuncs->vkDestroyImage(dev, m_texStaging, nullptr); + m_texStaging = VK_NULL_HANDLE; + } + + if (m_texStagingMem) { + m_devFuncs->vkFreeMemory(dev, m_texStagingMem, nullptr); + m_texStagingMem = VK_NULL_HANDLE; + } + + if (m_texView) { + m_devFuncs->vkDestroyImageView(dev, m_texView, nullptr); + m_texView = VK_NULL_HANDLE; + } + + if (m_texImage) { + m_devFuncs->vkDestroyImage(dev, m_texImage, nullptr); + m_texImage = VK_NULL_HANDLE; + } + + if (m_texMem) { + m_devFuncs->vkFreeMemory(dev, m_texMem, nullptr); + m_texMem = VK_NULL_HANDLE; + } + + if (m_pipeline) { + m_devFuncs->vkDestroyPipeline(dev, m_pipeline, nullptr); + m_pipeline = VK_NULL_HANDLE; + } + + if (m_pipelineLayout) { + m_devFuncs->vkDestroyPipelineLayout(dev, m_pipelineLayout, nullptr); + m_pipelineLayout = VK_NULL_HANDLE; + } + + if (m_pipelineCache) { + m_devFuncs->vkDestroyPipelineCache(dev, m_pipelineCache, nullptr); + m_pipelineCache = VK_NULL_HANDLE; + } + + if (m_descSetLayout) { + m_devFuncs->vkDestroyDescriptorSetLayout(dev, m_descSetLayout, nullptr); + m_descSetLayout = VK_NULL_HANDLE; + } + + if (m_descPool) { + m_devFuncs->vkDestroyDescriptorPool(dev, m_descPool, nullptr); + m_descPool = VK_NULL_HANDLE; + } + + if (m_buf) { + m_devFuncs->vkDestroyBuffer(dev, m_buf, nullptr); + m_buf = VK_NULL_HANDLE; + } + + if (m_bufMem) { + m_devFuncs->vkFreeMemory(dev, m_bufMem, nullptr); + m_bufMem = VK_NULL_HANDLE; + } +} + +void +VulkanRenderer2::startNextFrame() +{ + VkDevice dev = m_window->device(); + VkCommandBuffer cb = m_window->currentCommandBuffer(); + const QSize sz = m_window->swapChainImageSize(); + + updateSamplers(); + // Add the necessary barriers and do the host-linear -> device-optimal copy, if not yet done. + ensureTexture(); + + VkClearColorValue clearColor = { + {0, 0, 0, 1} + }; + VkClearDepthStencilValue clearDS = { 1, 0 }; + VkClearValue clearValues[2]; + memset(clearValues, 0, sizeof(clearValues)); + clearValues[0].color = clearColor; + clearValues[1].depthStencil = clearDS; + + VkRenderPassBeginInfo rpBeginInfo; + memset(&rpBeginInfo, 0, sizeof(rpBeginInfo)); + rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + rpBeginInfo.renderPass = m_window->defaultRenderPass(); + rpBeginInfo.framebuffer = m_window->currentFramebuffer(); + rpBeginInfo.renderArea.extent.width = sz.width(); + rpBeginInfo.renderArea.extent.height = sz.height(); + rpBeginInfo.clearValueCount = 2; + rpBeginInfo.pClearValues = clearValues; + VkCommandBuffer cmdBuf = m_window->currentCommandBuffer(); + m_devFuncs->vkCmdBeginRenderPass(cmdBuf, &rpBeginInfo, VK_SUBPASS_CONTENTS_INLINE); + + quint8 *p; + VkResult err = m_devFuncs->vkMapMemory(dev, m_bufMem, m_uniformBufInfo[m_window->currentFrame()].offset, + UNIFORM_DATA_SIZE, 0, reinterpret_cast(&p)); + if (err != VK_SUCCESS) + qFatal("Failed to map memory: %d", err); + QMatrix4x4 m = m_proj; +#if 0 + m.rotate(m_rotation, 0, 0, 1); +#endif + memcpy(p, m.constData(), 16 * sizeof(float)); + m_devFuncs->vkUnmapMemory(dev, m_bufMem); + p = nullptr; + + // Second pass for texture coordinates. + err = m_devFuncs->vkMapMemory(dev, m_bufMem, 0, + sizeof(vertexData), 0, reinterpret_cast(&p)); + if (err != VK_SUCCESS) + qFatal("Failed to map memory: %d", err); + + float *floatData = (float *) p; + auto source = qobject_cast(m_window)->source; + auto destination = qobject_cast(m_window)->destination; + floatData[3] = (float) source.x() / 2048.f; + floatData[9] = (float) (source.y()) / 2048.f; + floatData[8] = (float) source.x() / 2048.f; + floatData[4] = (float) (source.y() + source.height()) / 2048.f; + floatData[13] = (float) (source.x() + source.width()) / 2048.f; + floatData[19] = (float) (source.y()) / 2048.f; + floatData[18] = (float) (source.x() + source.width()) / 2048.f; + floatData[14] = (float) (source.y() + source.height()) / 2048.f; + + m_devFuncs->vkUnmapMemory(dev, m_bufMem); + + m_devFuncs->vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline); + m_devFuncs->vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, + &m_descSet[m_window->currentFrame()], 0, nullptr); + VkDeviceSize vbOffset = 0; + m_devFuncs->vkCmdBindVertexBuffers(cb, 0, 1, &m_buf, &vbOffset); + + VkViewport viewport; + viewport.x = destination.x() * m_window->devicePixelRatio(); + viewport.y = destination.y() * m_window->devicePixelRatio(); + viewport.width = destination.width() * m_window->devicePixelRatio(); + viewport.height = destination.height() * m_window->devicePixelRatio(); + viewport.minDepth = 0; + viewport.maxDepth = 1; + m_devFuncs->vkCmdSetViewport(cb, 0, 1, &viewport); + + VkRect2D scissor; + scissor.offset.x = viewport.x; + scissor.offset.y = viewport.y; + scissor.extent.width = viewport.width; + scissor.extent.height = viewport.height; + m_devFuncs->vkCmdSetScissor(cb, 0, 1, &scissor); + + m_devFuncs->vkCmdDraw(cb, 4, 1, 0, 0); + + m_devFuncs->vkCmdEndRenderPass(cmdBuf); + + if (m_texStagingTransferLayout) { + VkImageMemoryBarrier barrier {}; + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barrier.subresourceRange.levelCount = barrier.subresourceRange.layerCount = 1; + barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + barrier.oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT; + barrier.image = m_texImage; + m_devFuncs->vkCmdPipelineBarrier(cb, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, nullptr, 0, nullptr, + 1, &barrier); + m_texStagingPending = true; + } + + m_window->frameReady(); + m_window->requestUpdate(); // render continuously, throttled by the presentation rate +} +#endif diff --git a/src/qt/qt_winrawinputfilter.cpp b/src/qt/qt_winrawinputfilter.cpp index 522130432..73eea9ad8 100644 --- a/src/qt/qt_winrawinputfilter.cpp +++ b/src/qt/qt_winrawinputfilter.cpp @@ -45,9 +45,11 @@ #include #include +#include "qt_rendererstack.hpp" + extern "C" void win_joystick_handle(PRAWINPUT); std::unique_ptr -WindowsRawInputFilter::Register(QMainWindow *window) +WindowsRawInputFilter::Register(MainWindow *window) { HWND wnd = (HWND) window->winId(); @@ -70,7 +72,7 @@ WindowsRawInputFilter::Register(QMainWindow *window) return inputfilter; } -WindowsRawInputFilter::WindowsRawInputFilter(QMainWindow *window) +WindowsRawInputFilter::WindowsRawInputFilter(MainWindow *window) { this->window = window; @@ -108,8 +110,18 @@ WindowsRawInputFilter::nativeEventFilter(const QByteArray &eventType, void *mess MSG *msg = static_cast(message); if (msg->message == WM_INPUT) { + if (window->isActiveWindow() && menus_open == 0) handle_input((HRAWINPUT) msg->lParam); + else + { + for (auto &w : window->renderers) { + if (w && w->isActiveWindow()) { + handle_input((HRAWINPUT) msg->lParam); + break; + } + } + } return true; } @@ -160,7 +172,9 @@ void WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) { USHORT scancode; - static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0; + static int recv_lalt = 0; + static int recv_ralt = 0; + static int recv_tab = 0; RAWKEYBOARD rawKB = raw->data.keyboard; scancode = rawKB.MakeCode; @@ -186,13 +200,13 @@ WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) We use scan code 0xFFFF to mean a mapping that has a prefix other than E0 and that is not E1 1D, which is, for our purposes, invalid. */ - if ((scancode == 0x00F) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && !mouse_capture) { + if ((scancode == 0x00f) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { /* We received a TAB while ALT was pressed, while the mouse - is not captured, suppress the TAB and send an ALT key up. */ + is not captured, suppress the TAB and send an ALT key up. */ if (recv_lalt) { keyboard_input(0, 0x038); /* Extra key press and release so the guest is not stuck in the - menu bar. */ + menu bar. */ keyboard_input(1, 0x038); keyboard_input(0, 0x038); recv_lalt = 0; @@ -200,19 +214,19 @@ WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) if (recv_ralt) { keyboard_input(0, 0x138); /* Extra key press and release so the guest is not stuck in the - menu bar. */ + menu bar. */ keyboard_input(1, 0x138); keyboard_input(0, 0x138); recv_ralt = 0; } - } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && !mouse_capture) { + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && (!kbd_req_capture || mouse_capture)) { /* We received an ALT while TAB was pressed, while the mouse - is not captured, suppress the ALT and send a TAB key up. */ - keyboard_input(0, 0x00F); + is not captured, suppress the ALT and send a TAB key up. */ + keyboard_input(0, 0x00f); recv_tab = 0; } else { switch (scancode) { - case 0x00F: + case 0x00f: recv_tab = !(rawKB.Flags & RI_KEY_BREAK); break; case 0x038: @@ -225,13 +239,15 @@ WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) /* Translate right CTRL to left ALT if the user has so chosen. */ - if ((scancode == 0x11D) && rctrl_is_lalt) + if ((scancode == 0x11d) && rctrl_is_lalt) scancode = 0x038; /* Normal scan code pass through, pass it through as is if it's not an invalid scan code. */ if (scancode != 0xFFFF) keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode); + + window->checkFullscreenHotkey(); } } else { if (rawKB.MakeCode == 0x1D) { @@ -322,7 +338,8 @@ void WindowsRawInputFilter::mouse_handle(PRAWINPUT raw) { RAWMOUSE state = raw->data.mouse; - static int x, y; + static int x; + static int y; /* read mouse buttons and wheel */ if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) diff --git a/src/qt/qt_winrawinputfilter.hpp b/src/qt/qt_winrawinputfilter.hpp index b03f6783e..81b2c0d48 100644 --- a/src/qt/qt_winrawinputfilter.hpp +++ b/src/qt/qt_winrawinputfilter.hpp @@ -41,6 +41,8 @@ #include +#include "qt_mainwindow.hpp" + #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) # define result_t qintptr #else @@ -51,7 +53,7 @@ class WindowsRawInputFilter : public QObject, public QAbstractNativeEventFilter Q_OBJECT public: - static std::unique_ptr Register(QMainWindow *window); + static std::unique_ptr Register(MainWindow *window); bool nativeEventFilter(const QByteArray &eventType, void *message, result_t *result) override; @@ -61,7 +63,7 @@ public slots: void mousePoll(); private: - QMainWindow *window; + MainWindow *window; uint16_t scancode_map[768]; int buttons = 0; int dx = 0; @@ -69,7 +71,7 @@ private: int dwheel = 0; int menus_open = 0; - WindowsRawInputFilter(QMainWindow *window); + WindowsRawInputFilter(MainWindow *window); void handle_input(HRAWINPUT input); void keyboard_handle(PRAWINPUT raw); diff --git a/src/qt/sdl_joystick.cpp b/src/qt/sdl_joystick.cpp index 06f0a73b8..bc540fcf6 100644 --- a/src/qt/sdl_joystick.cpp +++ b/src/qt/sdl_joystick.cpp @@ -106,7 +106,8 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process() { - int c, d; + int c; + int d; if (!joystick_type) return; diff --git a/src/qt/win_joystick_rawinput.c b/src/qt/win_joystick_rawinput.c index 2976a54b9..e5d477296 100644 --- a/src/qt/win_joystick_rawinput.c +++ b/src/qt/win_joystick_rawinput.c @@ -98,6 +98,8 @@ joystick_add_button(raw_joystick_t *rawjoy, plat_joystick_t *joy, USAGE usage) void joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS prop) { + LONG center; + if (joy->nr_axes >= 8) return; @@ -141,7 +143,10 @@ joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS } rawjoy->axis[joy->nr_axes].min = prop->LogicalMin; - joy->nr_axes++; + center = (rawjoy->axis[joy->nr_axes].max - rawjoy->axis[joy->nr_axes].min + 1) / 2; + + if (center != 0x00) + joy->nr_axes++; } void @@ -443,12 +448,12 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process(void) { - int c, d; + int d; if (joystick_type == 7) return; - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { + for (int c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { if (joystick_state[c].plat_joystick_nr) { int joystick_nr = joystick_state[c].plat_joystick_nr - 1; @@ -458,8 +463,10 @@ joystick_process(void) joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]]; for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - int x, y; - double angle, magnitude; + int x; + int y; + double angle; + double magnitude; x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]); y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]); diff --git a/src/qt/wl_mouse.cpp b/src/qt/wl_mouse.cpp index 9b23792c8..789712de5 100644 --- a/src/qt/wl_mouse.cpp +++ b/src/qt/wl_mouse.cpp @@ -34,7 +34,8 @@ static zwp_relative_pointer_v1 *rel_pointer = nullptr; static zwp_pointer_constraints_v1 *conf_pointer_interface = nullptr; static zwp_locked_pointer_v1 *conf_pointer = nullptr; -static int rel_mouse_x = 0, rel_mouse_y = 0; +static int rel_mouse_x = 0; +static int rel_mouse_y = 0; static bool wl_init_ok = false; void diff --git a/src/qt/xinput2_mouse.cpp b/src/qt/xinput2_mouse.cpp index 0ce51c5ab..dafa4ffda 100644 --- a/src/qt/xinput2_mouse.cpp +++ b/src/qt/xinput2_mouse.cpp @@ -59,7 +59,8 @@ parse_valuators(const double *input_values, const unsigned char *mask, int mask_len, double *output_values, int output_values_len) { - int i = 0, z = 0; + int i = 0; + int z = 0; int top = mask_len * 8; if (top > 16) top = 16; @@ -92,6 +93,13 @@ xinput2_get_xtest_pointer() if ((dev->use == XISlavePointer) && !strcmp(dev->name, "TigerVNC pointer")) return dev->deviceid; } + /* Steam Input on SteamOS uses XTEST the intended way for trackpad movement. + Hope nobody is remoting into their Steam Deck with a non-TigerVNC server. */ + for (int i = 0; i < devs; i++) { + dev = &info[i]; + if ((dev->use == XISlavePointer) && !strncmp(dev->name, "Valve Software Steam Deck", 25)) + return -1; + } for (int i = 0; i < devs; i++) { dev = &info[i]; if ((dev->use == XISlavePointer) && !strcmp(dev->name, "Virtual core XTEST pointer")) @@ -253,7 +261,10 @@ xinput2_init() qWarning() << "Cannot open current X11 display"; return; } - auto event = 0, err = 0, minor = 1, major = 2; + auto event = 0; + auto err = 0; + auto minor = 1; + auto major = 2; if (XQueryExtension(disp, "XInputExtension", &xi2opcode, &event, &err)) { if (XIQueryVersion(disp, &major, &minor) == Success) { procThread = QThread::create(xinput2_proc); diff --git a/src/qt/xkbcommon_keyboard.cpp b/src/qt/xkbcommon_keyboard.cpp new file mode 100644 index 000000000..969552229 --- /dev/null +++ b/src/qt/xkbcommon_keyboard.cpp @@ -0,0 +1,240 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * xkbcommon keyboard input module. + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +extern "C" { +#include +}; + +#include +#include +#include "evdev_keyboard.hpp" + +#define IS_DEC_DIGIT(c) (((c) >= '0') && ((c) <= '9')) +#define IS_HEX_DIGIT(c) (IS_DEC_DIGIT(c) || (((c) >= 'A') && ((c) <= 'F')) || (((c) >= 'a') && ((c) <= 'f'))) + +static std::unordered_map xkb_keycodes = { + {"ESC", 0x01}, + {"AE01", 0x02}, + {"AE02", 0x03}, + {"AE03", 0x04}, + {"AE04", 0x05}, + {"AE05", 0x06}, + {"AE06", 0x07}, + {"AE07", 0x08}, + {"AE08", 0x09}, + {"AE09", 0x0a}, + {"AE10", 0x0b}, + {"AE11", 0x0c}, + {"AE12", 0x0d}, + {"BKSP", 0x0e}, + + {"TAB", 0x0f}, + {"AD01", 0x10}, + {"AD02", 0x11}, + {"AD03", 0x12}, + {"AD04", 0x13}, + {"AD05", 0x14}, + {"AD06", 0x15}, + {"AD07", 0x16}, + {"AD08", 0x17}, + {"AD09", 0x18}, + {"AD10", 0x19}, + {"AD11", 0x1a}, + {"AD12", 0x1b}, + {"RTRN", 0x1c}, + {"LNFD", 0x1c}, /* linefeed => Enter */ + + {"LCTL", 0x1d}, + {"CTRL", 0x1d}, + {"AC01", 0x1e}, + {"AC02", 0x1f}, + {"AC03", 0x20}, + {"AC04", 0x21}, + {"AC05", 0x22}, + {"AC06", 0x23}, + {"AC07", 0x24}, + {"AC08", 0x25}, + {"AC09", 0x26}, + {"AC10", 0x27}, + {"AC11", 0x28}, + + {"TLDE", 0x29}, + {"AE00", 0x29}, /* alias of TLDE on keycodes/xfree86 (i.e. X11 forwarding) */ + {"LFSH", 0x2a}, + {"BKSL", 0x2b}, + {"AC12", 0x2b}, + {"AB01", 0x2c}, + {"AB02", 0x2d}, + {"AB03", 0x2e}, + {"AB04", 0x2f}, + {"AB05", 0x30}, + {"AB06", 0x31}, + {"AB07", 0x32}, + {"AB08", 0x33}, + {"AB09", 0x34}, + {"AB10", 0x35}, + {"RTSH", 0x36}, + + {"KPMU", 0x37}, + {"LALT", 0x38}, + {"ALT", 0x38}, + {"SPCE", 0x39}, + {"CAPS", 0x3a}, + {"FK01", 0x3b}, + {"FK02", 0x3c}, + {"FK03", 0x3d}, + {"FK04", 0x3e}, + {"FK05", 0x3f}, + {"FK06", 0x40}, + {"FK07", 0x41}, + {"FK08", 0x42}, + {"FK09", 0x43}, + {"FK10", 0x44}, + + {"NMLK", 0x45}, + {"SCLK", 0x46}, + {"FK14", 0x46}, /* F14 => Scroll Lock (for Apple keyboards) */ + {"KP7", 0x47}, + {"KP8", 0x48}, + {"KP9", 0x49}, + {"KPSU", 0x4a}, + {"KP4", 0x4b}, + {"KP5", 0x4c}, + {"KP6", 0x4d}, + {"KPAD", 0x4e}, + {"KP1", 0x4f}, + {"KP2", 0x50}, + {"KP3", 0x51}, + {"KP0", 0x52}, + {"KPDL", 0x53}, + + {"LSGT", 0x56}, + {"FK11", 0x57}, + {"FK12", 0x58}, + {"FK16", 0x5d}, /* F16 => F13 */ + {"FK17", 0x5e}, /* F17 => F14 */ + {"FK18", 0x5f}, /* F18 => F15 */ + + /* Japanese keys. */ + {"JPCM", 0x5c}, /* Num, */ + {"KPDC", 0x5c}, + {"HKTG", 0x70}, /* hiragana-katakana toggle */ + {"AB11", 0x73}, /* \_ and Brazilian /? */ + {"HZTG", 0x76}, /* hankaku-zenkaku toggle */ + {"HIRA", 0x77}, + {"KATA", 0x78}, + {"HENK", 0x79}, + {"KANA", 0x79}, /* kana => henkan (for Apple keyboards) */ + {"MUHE", 0x7b}, + {"EISU", 0x7b}, /* eisu => muhenkan (for Apple keyboards) */ + {"AE13", 0x7d}, /* \| */ + {"KPPT", 0x7e}, /* Brazilian Num. */ + {"I06", 0x7e}, /* alias of KPPT on keycodes/xfree86 (i.e. X11 forwarding) */ + + /* Korean keys. */ + {"HJCV", 0xf1}, /* hancha toggle */ + {"HNGL", 0xf2}, /* latin toggle */ + + {"KPEN", 0x11c}, + {"RCTL", 0x11d}, + {"KPDV", 0x135}, + {"PRSC", 0x137}, + {"SYRQ", 0x137}, + {"FK13", 0x137}, /* F13 => SysRq (for Apple keyboards) */ + {"RALT", 0x138}, + {"ALGR", 0x138}, + {"LVL3", 0x138}, /* observed on TigerVNC with AltGr-enabled layout */ + {"PAUS", 0x145}, + {"FK15", 0x145}, /* F15 => Pause (for Apple keyboards) */ + {"BRK", 0x145}, + {"HOME", 0x147}, + {"UP", 0x148}, + {"PGUP", 0x149}, + {"LEFT", 0x14b}, + {"RGHT", 0x14d}, + {"END", 0x14f}, + {"DOWN", 0x150}, + {"PGDN", 0x151}, + {"INS", 0x152}, + {"DELE", 0x153}, + + {"LWIN", 0x15b}, + {"WIN", 0x15b}, + {"LMTA", 0x15b}, + {"META", 0x15b}, + {"RWIN", 0x15c}, + {"RMTA", 0x15c}, + {"MENU", 0x15d}, + {"COMP", 0x15d}, /* Compose as Menu */ + + /* Multimedia keys. Same notes as evdev_keyboard apply here. */ + {"KPEQ", 0x59}, /* Num= */ + {"FRNT", 0x101}, /* # Logitech Task Select */ + {"UNDO", 0x108}, /* # */ + {"PAST", 0x10a}, /* # Paste */ + {"FIND", 0x112}, /* # Logitech */ + {"CUT", 0x117}, /* # */ + {"COPY", 0x118}, /* # */ + {"MUTE", 0x120}, + {"VOL-", 0x12e}, + {"VOL+", 0x130}, + {"HELP", 0x13b}, + {"OPEN", 0x13f}, + {"POWR", 0x15e}, + {"STOP", 0x168}, +}; +struct xkb_keymap *xkbcommon_keymap = nullptr; + +void +xkbcommon_init(struct xkb_keymap *keymap) +{ + if (keymap) + xkbcommon_keymap = keymap; +} + +void +xkbcommon_close() +{ + xkbcommon_keymap = nullptr; +} + +uint16_t +xkbcommon_translate(uint32_t keycode) +{ + const char *key_name = xkb_keymap_key_get_name(xkbcommon_keymap, keycode); + + /* If XKB doesn't know the key name for this keycode, assume an unnamed Ixxx key. + This is useful for older XKB versions with an incomplete evdev keycode map. */ + auto key_name_s = key_name ? std::string(key_name) : QString("I%1").arg(keycode).toStdString(); + auto ret = xkb_keycodes[key_name_s]; + + /* Observed with multimedia keys on Windows VcXsrv. */ + if (!ret && (key_name_s.length() == 3) && (key_name_s[0] == 'I') && IS_HEX_DIGIT(key_name_s[1]) && IS_HEX_DIGIT(key_name_s[2])) + ret = 0x100 | stoi(key_name_s.substr(1), nullptr, 16); + + /* Translate unnamed evdev-specific keycodes. */ + if (!ret && (key_name_s.length() >= 2) && (key_name_s[0] == 'I') && IS_DEC_DIGIT(key_name_s[1])) + ret = evdev_translate(stoi(key_name_s.substr(1)) - 8); + + if (!ret) + qWarning() << "XKB Keyboard: Unknown key" << QString::number(keycode, 16) << QString::fromStdString(key_name_s); +#if 0 + else + qInfo() << "XKB Keyboard: Key" << QString::number(keycode, 16) << QString::fromStdString(key_name_s) << "scancode" << QString::number(ret, 16); +#endif + + return ret; +} diff --git a/src/qt/xkbcommon_keyboard.hpp b/src/qt/xkbcommon_keyboard.hpp new file mode 100644 index 000000000..c3b28eeec --- /dev/null +++ b/src/qt/xkbcommon_keyboard.hpp @@ -0,0 +1,20 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Definitions for xkbcommon keyboard input module. + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +extern void *xkbcommon_keymap; +void xkbcommon_init(struct xkb_keymap *keymap); +void xkbcommon_close(); +uint16_t xkbcommon_translate(uint32_t keycode); diff --git a/src/qt/xkbcommon_wl_keyboard.cpp b/src/qt/xkbcommon_wl_keyboard.cpp new file mode 100644 index 000000000..8b7e6399a --- /dev/null +++ b/src/qt/xkbcommon_wl_keyboard.cpp @@ -0,0 +1,243 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * xkbcommon Wayland keyboard input module. + * + * Heavily inspired by libxkbcommon interactive-wayland.c + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +extern "C" { +#include +#include +#include +#include <86box/86box.h> +}; +#include "xkbcommon_keyboard.hpp" +#include +#include + +#include +#include +#include + +typedef struct { + struct wl_seat *wl_seat; + struct wl_keyboard *wl_kbd; + uint32_t version; + + struct xkb_keymap *keymap; + + struct wl_list link; +} seat_t; + +static bool wl_init_ok = false; +static struct wl_list seats; +static struct xkb_context *ctx; + +static void +xkbcommon_wl_set_keymap() +{ + /* Grab keymap from the first seat with one. */ + seat_t *seat; + seat_t *tmp; + wl_list_for_each_safe(seat, tmp, &seats, link) { + if (seat->keymap) { + xkbcommon_init(seat->keymap); + return; + } + } + xkbcommon_close(); /* none found */ +} + +static void +kbd_keymap(void *data, struct wl_keyboard *wl_kbd, uint32_t format, + int fd, uint32_t size) +{ + seat_t *seat = (seat_t *) data; + + char *buf = (char *) mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); + if (!buf) { + qWarning() << "XKB Keyboard: Failed to mmap keymap with error" << errno; + return; + } + + if (seat->keymap) { + struct xkb_keymap *keymap = seat->keymap; + seat->keymap = NULL; + xkbcommon_wl_set_keymap(); + xkb_keymap_unref(keymap); + } + + seat->keymap = xkb_keymap_new_from_buffer(ctx, buf, size - 1, + XKB_KEYMAP_FORMAT_TEXT_V1, + XKB_KEYMAP_COMPILE_NO_FLAGS); + munmap(buf, size); + close(fd); + if (!seat->keymap) + qWarning() << "XKB Keyboard: Keymap compilation failed"; + + xkbcommon_wl_set_keymap(); +} + +static void +kbd_enter(void *data, struct wl_keyboard *wl_kbd, uint32_t serial, + struct wl_surface *surf, struct wl_array *keys) +{ +} + +static void +kbd_leave(void *data, struct wl_keyboard *wl_kbd, uint32_t serial, + struct wl_surface *surf) +{ +} + +static void +kbd_key(void *data, struct wl_keyboard *wl_kbd, uint32_t serial, uint32_t time, + uint32_t key, uint32_t state) +{ +} + +static void +kbd_modifiers(void *data, struct wl_keyboard *wl_kbd, uint32_t serial, + uint32_t mods_depressed, uint32_t mods_latched, + uint32_t mods_locked, uint32_t group) +{ +} + +static void +kbd_repeat_info(void *data, struct wl_keyboard *wl_kbd, int32_t rate, + int32_t delay) +{ +} + +static const struct wl_keyboard_listener kbd_listener = { + kbd_keymap, + kbd_enter, + kbd_leave, + kbd_key, + kbd_modifiers, + kbd_repeat_info +}; + +static void +seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t caps) +{ + seat_t *seat = (seat_t *) data; + + if (!seat->wl_kbd && (caps & WL_SEAT_CAPABILITY_KEYBOARD)) { + seat->wl_kbd = wl_seat_get_keyboard(seat->wl_seat); + wl_keyboard_add_listener(seat->wl_kbd, &kbd_listener, seat); + } else if (seat->wl_kbd && !(caps & WL_SEAT_CAPABILITY_KEYBOARD)) { + if (seat->version >= WL_SEAT_RELEASE_SINCE_VERSION) + wl_keyboard_release(seat->wl_kbd); + else + wl_keyboard_destroy(seat->wl_kbd); + + struct xkb_keymap *keymap = seat->keymap; + seat->keymap = NULL; + xkbcommon_wl_set_keymap(); + xkb_keymap_unref(keymap); + + seat->wl_kbd = NULL; + } +} + +static void +seat_name(void *data, struct wl_seat *wl_seat, const char *name) +{ +} + +static const struct wl_seat_listener seat_listener = { + seat_capabilities, + seat_name +}; + +static void +display_handle_global(void *data, struct wl_registry *wl_registry, uint32_t id, + const char *interface, uint32_t version) +{ + if (!strcmp(interface, "wl_seat")) { + seat_t *seat = (seat_t *) malloc(sizeof(seat_t)); + memset(seat, 0, sizeof(seat_t)); + + seat->wl_seat = (wl_seat *) wl_registry_bind(wl_registry, id, &wl_seat_interface, MIN(version, 5)); + wl_seat_add_listener(seat->wl_seat, &seat_listener, seat); + wl_list_insert(&seats, &seat->link); + } +} + +static void +display_global_remove(void *data, struct wl_registry *wl_registry, uint32_t id) +{ + xkbcommon_close(); + + seat_t *seat; + seat_t *tmp; + wl_list_for_each_safe(seat, tmp, &seats, link) { + if (seat->wl_kbd) { + if (seat->version >= WL_SEAT_RELEASE_SINCE_VERSION) + wl_keyboard_release(seat->wl_kbd); + else + wl_keyboard_destroy(seat->wl_kbd); + + xkb_keymap_unref(seat->keymap); + } + + if (seat->version >= WL_SEAT_RELEASE_SINCE_VERSION) + wl_seat_release(seat->wl_seat); + else + wl_seat_destroy(seat->wl_seat); + + wl_list_remove(&seat->link); + free(seat); + } +} + +static const struct wl_registry_listener registry_listener = { + display_handle_global, + display_global_remove +}; + +void +xkbcommon_wl_init() +{ + if (wl_init_ok) + return; + + wl_list_init(&seats); + + ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + if (!ctx) { + qWarning() << "XKB Keyboard: XKB context creation failed"; + return; + } + + wl_display *display = (wl_display *) QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_display"); + if (display) { + auto registry = wl_display_get_registry(display); + if (registry) { + wl_registry_add_listener(registry, ®istry_listener, nullptr); + wl_display_roundtrip(display); + wl_display_roundtrip(display); + } else { + goto err_ctx; + } + } else { + goto err_ctx; + } + wl_init_ok = true; + return; + +err_ctx: + xkb_context_unref(ctx); +} diff --git a/src/qt/xkbcommon_wl_keyboard.hpp b/src/qt/xkbcommon_wl_keyboard.hpp new file mode 100644 index 000000000..a70cb9e9b --- /dev/null +++ b/src/qt/xkbcommon_wl_keyboard.hpp @@ -0,0 +1,17 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Definitions for xkbcommon Wayland keyboard input module. + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +void xkbcommon_wl_init(); diff --git a/src/qt/xkbcommon_x11_keyboard.cpp b/src/qt/xkbcommon_x11_keyboard.cpp new file mode 100644 index 000000000..8e0167518 --- /dev/null +++ b/src/qt/xkbcommon_x11_keyboard.cpp @@ -0,0 +1,86 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * xkbcommon-x11 keyboard input module. + * + * Heavily inspired by libxkbcommon interactive-x11.c + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +extern "C" { +/* xkb.h has identifiers named "explicit", which is a C++ keyword now... */ +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wkeyword-macro" +#endif +#define explicit explicit_ +#ifdef __clang__ +#pragma clang diagnostic pop +#endif +#include +#undef explicit + +#include +}; +#include "xkbcommon_keyboard.hpp" + +#include +#include +#include + +void +xkbcommon_x11_init() +{ + xcb_connection_t *conn; + struct xkb_context *ctx; + int32_t core_kbd_device_id; + struct xkb_keymap *keymap; + + conn = (xcb_connection_t *) QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("connection"); + if (!conn) { + qWarning() << "XKB Keyboard: X server connection failed"; + return; + } + + int ret = xkb_x11_setup_xkb_extension(conn, + XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION, + XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, + NULL, NULL, NULL, NULL); + if (!ret) { + qWarning() << "XKB Keyboard: XKB extension setup failed"; + return; + } + + ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + if (!ctx) { + qWarning() << "XKB Keyboard: XKB context creation failed"; + return; + } + + core_kbd_device_id = xkb_x11_get_core_keyboard_device_id(conn); + if (core_kbd_device_id == -1) { + qWarning() << "XKB Keyboard: Core keyboard device not found"; + goto err_ctx; + } + + keymap = xkb_x11_keymap_new_from_device(ctx, conn, core_kbd_device_id, XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + qWarning() << "XKB Keyboard: Keymap loading failed"; + goto err_ctx; + } + + xkbcommon_init(keymap); + return; + +err_ctx: + xkb_context_unref(ctx); +} diff --git a/src/qt/xkbcommon_x11_keyboard.hpp b/src/qt/xkbcommon_x11_keyboard.hpp new file mode 100644 index 000000000..d8c063acb --- /dev/null +++ b/src/qt/xkbcommon_x11_keyboard.hpp @@ -0,0 +1,17 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Definitions for xkbcommon-x11 keyboard input module. + * + * + * + * Authors: RichardG, + * + * Copyright 2023 RichardG. + */ +void xkbcommon_x11_init(); diff --git a/src/random.c b/src/random.c index 18c52ef02..3f5fed1b9 100644 --- a/src/random.c +++ b/src/random.c @@ -51,7 +51,8 @@ static __inline unsigned long long rdtsc(void) { #if defined(__i386__) || defined(__x86_64__) - unsigned hi, lo; + unsigned int hi; + unsigned int lo; # ifdef _MSC_VER __asm { rdtsc diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index 4e82f67fa..1f1e6eafd 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -125,7 +125,7 @@ scsi_card_available(int card) if (scsi_cards[card].device) return (device_available(scsi_cards[card].device)); - return (1); + return 1; } const device_t * @@ -138,7 +138,7 @@ int scsi_card_has_config(int card) { if (!scsi_cards[card].device) - return (0); + return 0; return (device_has_config(scsi_cards[card].device) ? 1 : 0); } @@ -156,17 +156,17 @@ scsi_card_get_from_internal_name(char *s) while (scsi_cards[c].device != NULL) { if (!strcmp((char *) scsi_cards[c].device->internal_name, s)) - return (c); + return c; c++; } - return (0); + return 0; } void scsi_card_init(void) { - int i = 0, max = SCSI_BUS_MAX; + int max = SCSI_BUS_MAX; /* On-board SCSI controllers get the first bus, so if one is present, increase our instance number here. */ @@ -176,7 +176,7 @@ scsi_card_init(void) /* Do not initialize any controllers if we have do not have any SCSI bus left. */ if (max > 0) { - for (i = 0; i < max; i++) { + for (int i = 0; i < max; i++) { if (!scsi_cards[scsi_card_current[i]].device) continue; diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index aec89d588..2a1c23566 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -71,13 +71,13 @@ uint16_t aha_ports[] = { static uint8_t *aha1542cp_pnp_rom = NULL; #pragma pack(push, 1) -typedef struct { - uint8_t CustomerSignature[20]; - uint8_t uAutoRetry; - uint8_t uBoardSwitches; - uint8_t uChecksum; - uint8_t uUnknown; - addr24 BIOSMailboxAddress; +typedef struct aha_setup_t { + uint8_t CustomerSignature[20]; + uint8_t uAutoRetry; + uint8_t uBoardSwitches; + uint8_t uChecksum; + uint8_t uUnknown; + addr24_t BIOSMailboxAddress; } aha_setup_t; #pragma pack(pop) @@ -123,8 +123,8 @@ aha_mem_write(uint32_t addr, uint8_t val, void *priv) static uint8_t aha_mem_read(uint32_t addr, void *priv) { - x54x_t *dev = (x54x_t *) priv; - rom_t *rom = &dev->bios; + const x54x_t *dev = (x54x_t *) priv; + const rom_t *rom = &dev->bios; addr &= 0x3fff; @@ -139,14 +139,14 @@ aha154x_shram(x54x_t *dev, uint8_t cmd) { /* If not supported, give up. */ if (dev->rom_shram == 0x0000) - return (0x04); + return 0x04; /* Bit 0 = Shadow RAM write enable; Bit 1 = Shadow RAM read enable. */ dev->shram_mode = cmd; /* Firmware expects 04 status. */ - return (0x04); + return 0x04; } static void @@ -163,7 +163,7 @@ aha_eeprom_save(x54x_t *dev) } static uint8_t -aha154x_eeprom(x54x_t *dev, uint8_t cmd, uint8_t arg, uint8_t len, uint8_t off, uint8_t *bufp) +aha154x_eeprom(x54x_t *dev, uint8_t cmd, UNUSED(uint8_t arg), uint8_t len, uint8_t off, uint8_t *bufp) { uint8_t r = 0xff; int c; @@ -173,7 +173,7 @@ aha154x_eeprom(x54x_t *dev, uint8_t cmd, uint8_t arg, uint8_t len, uint8_t off, /* Only if we can handle it.. */ if (dev->nvr == NULL) - return (r); + return r; if (cmd == 0x22) { /* Write data to the EEPROM. */ @@ -198,7 +198,7 @@ aha154x_eeprom(x54x_t *dev, uint8_t cmd, uint8_t arg, uint8_t len, uint8_t off, r = len; } - return (r); + return r; } /* Map either the main or utility (Select) ROM into the memory space. */ @@ -217,39 +217,42 @@ aha154x_mmap(x54x_t *dev, uint8_t cmd) /* Enable the mapper, so, set ROM2 active. */ dev->bios.rom = dev->rom2; break; + + default: + break; } - return (0); + return 0; } static uint8_t -aha_get_host_id(void *p) +aha_get_host_id(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; return dev->nvr[0] & 0x07; } static uint8_t -aha_get_irq(void *p) +aha_get_irq(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; return (dev->nvr[1] & 0x07) + 9; } static uint8_t -aha_get_dma(void *p) +aha_get_dma(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; return (dev->nvr[1] >> 4) & 0x07; } static uint8_t -aha_cmd_is_fast(void *p) +aha_cmd_is_fast(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; if (dev->Command == CMD_BIOS_SCSI) return 1; @@ -258,9 +261,9 @@ aha_cmd_is_fast(void *p) } static uint8_t -aha_fast_cmds(void *p, uint8_t cmd) +aha_fast_cmds(void *priv, uint8_t cmd) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; if (cmd == CMD_BIOS_SCSI) { dev->BIOSMailboxReq++; @@ -271,9 +274,9 @@ aha_fast_cmds(void *p, uint8_t cmd) } static uint8_t -aha_param_len(void *p) +aha_param_len(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; switch (dev->Command) { case CMD_BIOS_MBINIT: @@ -307,10 +310,10 @@ aha_param_len(void *p) } static uint8_t -aha_cmds(void *p) +aha_cmds(void *priv) { - x54x_t *dev = (x54x_t *) p; - MailboxInit_t *mbi; + x54x_t *dev = (x54x_t *) priv; + const MailboxInit_t *mbi; if (!dev->CmdParamLeft) { aha_log("Running Operation Code 0x%02X\n", dev->Command); @@ -351,7 +354,9 @@ aha_cmds(void *p) * and expects a 0x04 back in the INTR * register. --FvK */ - /* dev->Interrupt = aha154x_shram(dev,val); */ +#if 0 + dev->Interrupt = aha154x_shram(dev,val); +#endif dev->Interrupt = aha154x_shram(dev, dev->CmdBuf[0]); break; @@ -451,9 +456,9 @@ aha_cmds(void *p) } static void -aha_setup_data(void *p) +aha_setup_data(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; ReplyInquireSetupInformation *ReplyISI; aha_setup_t *aha_setup; @@ -486,9 +491,9 @@ aha_do_bios_mail(x54x_t *dev) } static void -aha_callback(void *p) +aha_callback(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; if (dev->BIOSMailboxInit && dev->BIOSMailboxReq) aha_do_bios_mail(dev); @@ -497,7 +502,7 @@ aha_callback(void *p) static uint8_t aha_mca_read(int port, void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[port & 7]); } @@ -551,6 +556,9 @@ aha_mca_write(int port, uint8_t val, void *priv) case 0x10: /* [1]=xx01 0xxx */ dev->rom_addr = 0xC8000; break; + + default: + break; } else { /* Disabled. */ @@ -606,7 +614,7 @@ aha_mca_write(int port, uint8_t val, void *priv) static uint8_t aha_mca_feedb(void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[2] & 0x01); } @@ -696,6 +704,8 @@ aha_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) break; #endif + default: + break; } } @@ -997,6 +1007,9 @@ aha_init(const device_t *info) case 0x0334: dev->bios_path = "roms/scsi/adaptec/aha1540b320_334.bin"; break; + + default: + break; } dev->fw_rev = "A005"; /* The 3.2 microcode says A012. */ /* This is configurable from the configuration for the 154xB, the rest of the controllers read it from the EEPROM. */ @@ -1082,6 +1095,9 @@ aha_init(const device_t *info) mca_add(aha_mca_read, aha_mca_write, aha_mca_feedb, NULL, dev); dev->ha_bps = 5000000.0; /* normal SCSI */ break; + + default: + break; } /* Initialize ROM BIOS if needed. */ @@ -1106,7 +1122,7 @@ aha_init(const device_t *info) } } - return (dev); + return dev; } // clang-format off diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index 1e0f74d0f..d38a967bd 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -53,20 +53,20 @@ * configuration parameters. */ #pragma pack(push, 1) -typedef struct { - uint8_t aInternalSignature[2]; - uint8_t cbInformation; - uint8_t aHostAdaptertype[6]; - uint8_t uReserved1; - uint8_t fFloppyEnabled : 1, - fFloppySecondary : 1, - fLevelSensitiveInterrupt : 1, - uReserved2 : 2, - uSystemRAMAreForBIOS : 3; - uint8_t uDMAChannel : 7, - fDMAAutoConfiguration : 1, - uIrqChannel : 7, - fIrqAutoConfiguration : 1; +typedef struct AutoSCSIRam_t { + uint8_t aInternalSignature[2]; + uint8_t cbInformation; + uint8_t aHostAdaptertype[6]; + uint8_t uReserved1; + uint8_t fFloppyEnabled : 1; + uint8_t fFloppySecondary : 1; + uint8_t fLevelSensitiveInterrupt : 1; + uint8_t uReserved2 : 2; + uint8_t uSystemRAMAreForBIOS : 3; + uint8_t uDMAChannel : 7; + uint8_t fDMAAutoConfiguration : 1; + uint8_t uIrqChannel : 7; + uint8_t fIrqAutoConfiguration : 1; uint8_t uDMATransferRate; uint8_t uSCSIId; uint8_t uSCSIConfiguration; @@ -142,46 +142,45 @@ typedef struct { /* Structure for the INQUIRE_EXTENDED_SETUP_INFORMATION. */ #pragma pack(push, 1) -typedef struct { +typedef struct ReplyInquireExtendedSetupInformation_t { uint8_t uBusType; uint8_t uBiosAddress; uint16_t u16ScatterGatherLimit; uint8_t cMailbox; uint32_t uMailboxAddressBase; - uint8_t uReserved1 : 2, - fFastEISA : 1, - uReserved2 : 3, - fLevelSensitiveInterrupt : 1, - uReserved3 : 1; + uint8_t uReserved1 : 2; + uint8_t fFastEISA : 1; + uint8_t uReserved2 : 3; + uint8_t fLevelSensitiveInterrupt : 1; + uint8_t uReserved3 : 1; uint8_t aFirmwareRevision[3]; - uint8_t fHostWideSCSI : 1, - fHostDifferentialSCSI : 1, - fHostSupportsSCAM : 1, - fHostUltraSCSI : 1, - fHostSmartTermination : 1, - uReserved4 : 3; + uint8_t fHostWideSCSI : 1; + uint8_t fHostDifferentialSCSI : 1; + uint8_t fHostSupportsSCAM : 1; + uint8_t fHostUltraSCSI : 1; + uint8_t fHostSmartTermination : 1; + uint8_t uReserved4 : 3; } ReplyInquireExtendedSetupInformation; #pragma pack(pop) /* Structure for the INQUIRE_PCI_HOST_ADAPTER_INFORMATION reply. */ #pragma pack(push, 1) -typedef struct { +typedef struct BuslogicPCIInformation_t { uint8_t IsaIOPort; uint8_t IRQ; - uint8_t LowByteTerminated : 1, - HighByteTerminated : 1, - uReserved : 2, /* Reserved. */ - JP1 : 1, /* Whatever that means. */ - JP2 : 1, /* Whatever that means. */ - JP3 : 1, /* Whatever that means. */ - InformationIsValid : 1; - uint8_t uReserved2; /* Reserved. */ + uint8_t LowByteTerminated : 1; + uint8_t HighByteTerminated : 1; + uint8_t uReserved : 2; /* Reserved. */ + uint8_t JP1 : 1; /* Whatever that means. */ + uint8_t JP2 : 1; /* Whatever that means. */ + uint8_t JP3 : 1; /* Whatever that means. */ + uint8_t InformationIsValid : 1; + uint8_t uReserved2; /* Reserved. */ } BuslogicPCIInformation_t; #pragma pack(pop) #pragma pack(push, 1) -typedef struct -{ +typedef struct ESCMD_t { /** Data length. */ uint32_t DataLength; /** Data pointer. */ @@ -204,14 +203,14 @@ typedef struct #pragma pack(pop) #pragma pack(push, 1) -typedef struct { +typedef struct MailboxInitExtended_t { uint8_t Count; uint32_t Address; } MailboxInitExtended_t; #pragma pack(pop) #pragma pack(push, 1) -typedef struct { +typedef struct buslogic_data_t { rom_t bios; int ExtendedLUNCCBFormat; int fAggressiveRoundRobinMode; @@ -220,11 +219,11 @@ typedef struct { int MMIOBase; int chip; int has_bios; - uint32_t bios_addr, - bios_size, - bios_mask; - uint8_t AutoSCSIROM[32768]; - uint8_t SCAMData[65536]; + uint32_t bios_addr; + uint32_t bios_size; + uint32_t bios_mask; + uint8_t AutoSCSIROM[32768]; + uint8_t SCAMData[65536]; } buslogic_data_t; #pragma pack(pop) @@ -325,6 +324,9 @@ BuslogicAutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) case CHIP_BUSLOGIC_PCI_958D_1995_12_30: memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "958D", 4); break; + + default: + break; } HALR->structured.autoSCSIData.fLevelSensitiveInterrupt = (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30) ? 1 : 0; @@ -407,17 +409,17 @@ BuslogicAutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) static void BuslogicInitializeAutoSCSIRam(x54x_t *dev) { - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + const HALocalRAM *HALR = &bl->LocalRAM; - FILE *f; + FILE *fp; - f = nvr_fopen(BuslogicGetNVRFileName(bl), "rb"); - if (f) { - if (fread(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, f) != 64) + fp = nvr_fopen(BuslogicGetNVRFileName(bl), "rb"); + if (fp) { + if (fread(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, fp) != 64) fatal("BuslogicInitializeAutoSCSIRam(): Error reading data\n"); - fclose(f); - f = NULL; + fclose(fp); + fp = NULL; if (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30) { x54x_io_remove(dev, dev->Base, 4); switch (HALR->structured.autoSCSIData.uHostAdapterIoPortAddress) { @@ -439,9 +441,9 @@ BuslogicInitializeAutoSCSIRam(x54x_t *dev) } static void -buslogic_cmd_phase1(void *p) +buslogic_cmd_phase1(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; if ((dev->CmdParam == 2) && (dev->Command == 0x90)) { dev->CmdParamLeft = dev->CmdBuf[1]; @@ -463,12 +465,12 @@ buslogic_cmd_phase1(void *p) } static uint8_t -buslogic_get_host_id(void *p) +buslogic_get_host_id(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; if ((bl->chip == CHIP_BUSLOGIC_ISA_542B_1991_12_14) || (bl->chip == CHIP_BUSLOGIC_ISA_545S_1992_10_05) || (bl->chip == CHIP_BUSLOGIC_ISA_542BH_1993_05_23) || (bl->chip == CHIP_BUSLOGIC_VLB_445S_1993_11_16)) return dev->HostID; @@ -477,14 +479,14 @@ buslogic_get_host_id(void *p) } static uint8_t -buslogic_get_irq(void *p) +buslogic_get_irq(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; uint8_t bl_irq[7] = { 0, 9, 10, 11, 12, 14, 15 }; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; if ((bl->chip == CHIP_BUSLOGIC_ISA_542B_1991_12_14) || (bl->chip == CHIP_BUSLOGIC_ISA_545S_1992_10_05) || (bl->chip == CHIP_BUSLOGIC_ISA_542BH_1993_05_23) || (bl->chip == CHIP_BUSLOGIC_VLB_445S_1993_11_16) || (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30)) return dev->Irq; @@ -493,14 +495,14 @@ buslogic_get_irq(void *p) } static uint8_t -buslogic_get_dma(void *p) +buslogic_get_dma(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; uint8_t bl_dma[4] = { 0, 5, 6, 7 }; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; if (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30) return (dev->Base ? 7 : 0); @@ -511,10 +513,10 @@ buslogic_get_dma(void *p) } static uint8_t -buslogic_param_len(void *p) +buslogic_param_len(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; switch (dev->Command) { case 0x21: @@ -577,10 +579,10 @@ BuslogicSCSIBIOSDMATransfer(x54x_t *dev, ESCMD *ESCSICmd, uint8_t TargetID, int if (dir && ((ESCSICmd->DataDirection == CCB_DATA_XFER_OUT) || (ESCSICmd->DataDirection == 0x00))) { buslogic_log("BusLogic BIOS DMA: Reading %i bytes from %08X\n", TransferLength, Address); - dma_bm_read(Address, (uint8_t *) sd->sc->temp_buffer, TransferLength, transfer_size); + dma_bm_read(Address, sd->sc->temp_buffer, TransferLength, transfer_size); } else if (!dir && ((ESCSICmd->DataDirection == CCB_DATA_XFER_IN) || (ESCSICmd->DataDirection == 0x00))) { buslogic_log("BusLogic BIOS DMA: Writing %i bytes at %08X\n", TransferLength, Address); - dma_bm_write(Address, (uint8_t *) sd->sc->temp_buffer, TransferLength, transfer_size); + dma_bm_write(Address, sd->sc->temp_buffer, TransferLength, transfer_size); } } } @@ -589,7 +591,6 @@ static void BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, uint8_t DataReply) { ESCMD *ESCSICmd = (ESCMD *) CmdBuf; - uint32_t i; uint8_t temp_cdb[12]; int target_cdb_len = 12; #ifdef ENABLE_BUSLOGIC_LOG @@ -631,7 +632,7 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u buslogic_log("SCSI target command being executed on: SCSI ID %i, SCSI LUN %i, Target %i\n", ESCSICmd->TargetId, ESCSICmd->LogicalUnit, target_id); buslogic_log("SCSI Cdb[0]=0x%02X\n", ESCSICmd->CDB[0]); - for (i = 1; i < ESCSICmd->CDBLength; i++) { + for (uint8_t i = 1; i < ESCSICmd->CDBLength; i++) { buslogic_log("SCSI Cdb[%i]=%i\n", i, ESCSICmd->CDB[i]); } @@ -667,18 +668,18 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u } static uint8_t -buslogic_cmds(void *p) +buslogic_cmds(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; FILE *f; uint16_t TargetsPresentMask = 0; uint32_t Offset; int i = 0; - MailboxInitExtended_t *MailboxInitE; + const MailboxInitExtended_t *MailboxInitE; ReplyInquireExtendedSetupInformation *ReplyIESI; BuslogicPCIInformation_t *ReplyPI; int cCharsToTransfer; @@ -828,6 +829,9 @@ buslogic_cmds(void *p) case CHIP_BUSLOGIC_PCI_958D_1995_12_30: ReplyIESI->uBusType = 'E'; /* PCI style */ break; + + default: + break; } ReplyIESI->uBiosAddress = 0xd8; ReplyIESI->u16ScatterGatherLimit = 8192; @@ -1013,13 +1017,13 @@ buslogic_cmds(void *p) } static void -buslogic_setup_data(void *p) +buslogic_setup_data(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; ReplyInquireSetupInformation *ReplyISI; buslogic_setup_t *bl_setup; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + const HALocalRAM *HALR = &bl->LocalRAM; ReplyISI = (ReplyInquireSetupInformation *) dev->DataBuf; bl_setup = (buslogic_setup_t *) ReplyISI->VendorSpecificData; @@ -1049,14 +1053,17 @@ buslogic_setup_data(void *p) case CHIP_BUSLOGIC_PCI_958D_1995_12_30: bl_setup->uHostBusType = 'F'; break; + + default: + break; } } static uint8_t -buslogic_is_aggressive_mode(void *p) +buslogic_is_aggressive_mode(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; buslogic_log("Buslogic: Aggressive mode = %d\n", bl->fAggressiveRoundRobinMode); @@ -1064,10 +1071,10 @@ buslogic_is_aggressive_mode(void *p) } static uint8_t -buslogic_interrupt_type(void *p) +buslogic_interrupt_type(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; if ((bl->chip == CHIP_BUSLOGIC_ISA_542B_1991_12_14) || (bl->chip == CHIP_BUSLOGIC_ISA_545S_1992_10_05) || (bl->chip == CHIP_BUSLOGIC_ISA_542BH_1993_05_23) || (bl->chip == CHIP_BUSLOGIC_VLB_445S_1993_11_16) || (bl->chip == CHIP_BUSLOGIC_MCA_640A_1993_05_23)) return 0; @@ -1076,9 +1083,9 @@ buslogic_interrupt_type(void *p) } static void -buslogic_reset(void *p) +buslogic_reset(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; bl->ExtendedLUNCCBFormat = 0; @@ -1109,9 +1116,9 @@ BuslogicBIOSUpdate(buslogic_data_t *bl) } static uint8_t -BuslogicPCIRead(int func, int addr, void *p) +BuslogicPCIRead(UNUSED(int func), int addr, void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; #ifdef ENABLE_BUSLOGIC_LOG buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; #endif @@ -1152,7 +1159,9 @@ BuslogicPCIRead(int func, int addr, void *p) case 0x13: return buslogic_pci_bar[0].addr_regs[3]; case 0x14: - // return (buslogic_pci_bar[1].addr_regs[0] & 0xe0); /*Memory space*/ +#if 0 + return (buslogic_pci_bar[1].addr_regs[0] & 0xe0); /*Memory space*/ +#endif return 0x00; case 0x15: return buslogic_pci_bar[1].addr_regs[1] & 0xc0; @@ -1174,28 +1183,28 @@ BuslogicPCIRead(int func, int addr, void *p) case 0x31: /* PCI_ROMBAR 15:11 */ buslogic_log("BT-958D: BIOS BAR 01 = %02X\n", (buslogic_pci_bar[2].addr_regs[1] & bl->bios_mask)); return buslogic_pci_bar[2].addr_regs[1]; - break; case 0x32: /* PCI_ROMBAR 23:16 */ buslogic_log("BT-958D: BIOS BAR 02 = %02X\n", buslogic_pci_bar[2].addr_regs[2]); return buslogic_pci_bar[2].addr_regs[2]; - break; case 0x33: /* PCI_ROMBAR 31:24 */ buslogic_log("BT-958D: BIOS BAR 03 = %02X\n", buslogic_pci_bar[2].addr_regs[3]); return buslogic_pci_bar[2].addr_regs[3]; - break; case 0x3C: return dev->Irq; case 0x3D: return PCI_INTA; + + default: + break; } - return (0); + return 0; } static void -BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) +BuslogicPCIWrite(UNUSED(int func), int addr, uint8_t val, void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; uint8_t valxor; @@ -1223,7 +1232,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) case 0x10: val &= 0xe0; val |= 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: case 0x12: @@ -1247,7 +1258,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) case 0x14: val &= 0xe0; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x15: case 0x16: @@ -1258,7 +1271,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) /* Then let's set the PCI regs. */ buslogic_pci_bar[1].addr_regs[addr & 3] = val; /* Then let's calculate the new I/O base. */ - // bl->MMIOBase = buslogic_pci_bar[1].addr & 0xffffffe0; +#if 0 + bl->MMIOBase = buslogic_pci_bar[1].addr & 0xffffffe0; +#endif /* Give it a 4 kB alignment as that's this emulator's granularity. */ buslogic_pci_bar[1].addr &= 0xffffc000; bl->MMIOBase = buslogic_pci_bar[1].addr & 0xffffc000; @@ -1291,6 +1306,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) } else dev->Irq = 0; return; + + default: + break; } } @@ -1316,7 +1334,7 @@ BuslogicInitializeLocalRAM(buslogic_data_t *bl) static uint8_t buslogic_mca_read(int port, void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[port & 7]); } @@ -1385,6 +1403,9 @@ buslogic_mca_write(int port, uint8_t val, void *priv) case 0x20: /* [0]=001x xxxx */ bl->bios_addr = 0xC4000; break; + + default: + break; } else { /* Disabled. */ @@ -1490,15 +1511,15 @@ buslogic_mca_write(int port, uint8_t val, void *priv) static uint8_t buslogic_mca_feedb(void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[2] & 0x01); } void -BuslogicDeviceReset(void *p) +BuslogicDeviceReset(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; x54x_device_reset(dev); @@ -1512,14 +1533,14 @@ buslogic_init(const device_t *info) { x54x_t *dev; char *bios_rom_name; - uint16_t bios_rom_size; - uint16_t bios_rom_mask; + uint16_t bios_rom_size = 0; + uint16_t bios_rom_mask = 0; uint8_t has_autoscsi_rom; - char *autoscsi_rom_name; - uint16_t autoscsi_rom_size; + char *autoscsi_rom_name = NULL; + uint16_t autoscsi_rom_size = 0; uint8_t has_scam_rom; - char *scam_rom_name; - uint16_t scam_rom_size; + char *scam_rom_name = NULL; + uint16_t scam_rom_size = 0; FILE *f; buslogic_data_t *bl; uint32_t bios_rom_addr; @@ -1683,6 +1704,9 @@ buslogic_init(const device_t *info) dev->ha_bps = 20000000.0; /* ultra SCSI */ dev->max_id = 15; /* wide SCSI */ break; + + default: + break; } if ((dev->Base != 0) && !(dev->card_bus & DEVICE_MCA) && !(dev->card_bus & DEVICE_PCI)) { @@ -1753,7 +1777,7 @@ buslogic_init(const device_t *info) BuslogicInitializeAutoSCSIRam(dev); } - return (dev); + return dev; } // clang-format off diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index 98716692b..d192aec53 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -42,8 +42,7 @@ #include <86box/version.h> #pragma pack(push, 1) -typedef struct -{ +typedef struct gesn_cdb_t { uint8_t opcode; uint8_t polled; uint8_t reserved2[2]; @@ -53,8 +52,7 @@ typedef struct uint8_t control; } gesn_cdb_t; -typedef struct -{ +typedef struct gesn_event_header_t { uint16_t len; uint8_t notification_class; uint8_t supported_events; @@ -565,6 +563,9 @@ scsi_cdrom_atapi_phase_to_scsi(scsi_cdrom_t *dev) return 1; case 3: return 7; + + default: + break; } } else { if ((dev->phase & 3) == 3) @@ -577,9 +578,9 @@ scsi_cdrom_atapi_phase_to_scsi(scsi_cdrom_t *dev) } static uint32_t -scsi_cdrom_get_channel(void *p, int channel) +scsi_cdrom_get_channel(void *priv, int channel) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (!dev) return channel + 1; @@ -591,9 +592,9 @@ scsi_cdrom_get_channel(void *p, int channel) } static uint32_t -scsi_cdrom_get_volume(void *p, int channel) +scsi_cdrom_get_volume(void *priv, int channel) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (!dev) return 255; @@ -682,7 +683,7 @@ scsi_cdrom_drive_status_load(scsi_cdrom_t *dev) } static uint8_t -scsi_cdrom_drive_status_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +scsi_cdrom_drive_status_read(scsi_cdrom_t *dev, UNUSED(uint8_t page_control), uint8_t page, uint8_t pos) { return dev->ms_drive_status_pages_saved.pages[page][pos]; } @@ -691,13 +692,11 @@ static uint32_t scsi_cdrom_drive_status(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t page) { uint8_t page_control = (page >> 6) & 3; - int i = 0, j = 0; - uint16_t msplen; page &= 0x3f; - for (i = 0; i < 0x40; i++) { + for (uint8_t i = 0; i < 0x40; i++) { if (page == i) { if (scsi_cdrom_drive_status_page_flags & (1LL << ((uint64_t) (page & 0x3f)))) { buf[pos++] = scsi_cdrom_drive_status_read(dev, page_control, i, 0); @@ -706,7 +705,7 @@ scsi_cdrom_drive_status(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t p buf[pos++] = (msplen >> 8) & 0xff; buf[pos++] = msplen & 0xff; scsi_cdrom_log("CD-ROM %i: DRIVE STATUS: Page [%02X] length %i\n", dev->id, i, msplen); - for (j = 0; j < msplen; j++) { + for (uint16_t j = 0; j < msplen; j++) { if (i == 0x01) { buf[pos++] = scsi_cdrom_drive_status_read(dev, page_control, i, 3 + j); if (!(j & 1)) { /*MSB of Drive Status*/ @@ -737,12 +736,12 @@ scsi_cdrom_mode_sense_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page case 0: case 3: return dev->ms_pages_saved_sony.pages[page][pos]; - break; case 1: return scsi_cdrom_mode_sense_pages_changeable_sony.pages[page][pos]; - break; case 2: return scsi_cdrom_mode_sense_pages_default_sony_scsi.pages[page][pos]; + + default: break; } } else { @@ -750,16 +749,17 @@ scsi_cdrom_mode_sense_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page case 0: case 3: return dev->ms_pages_saved.pages[page][pos]; - break; case 1: return scsi_cdrom_mode_sense_pages_changeable.pages[page][pos]; - break; case 2: if (dev->drv->bus_type == CDROM_BUS_SCSI) return scsi_cdrom_mode_sense_pages_default_scsi.pages[page][pos]; else return scsi_cdrom_mode_sense_pages_default.pages[page][pos]; + + default: break; + } } @@ -770,8 +770,6 @@ static uint32_t scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) { uint8_t page_control = (page >> 6) & 3; - int i = 0, j = 0; - uint8_t msplen; page &= 0x3f; @@ -787,14 +785,14 @@ scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t pag buf[pos++] = 0; } - for (i = 0; i < 0x40; i++) { + for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { if (scsi_cdrom_mode_sense_page_flags & (1LL << ((uint64_t) (page & 0x3f)))) { buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 0); msplen = scsi_cdrom_mode_sense_read(dev, page_control, i, 1); buf[pos++] = msplen; scsi_cdrom_log("CD-ROM %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); - for (j = 0; j < msplen; j++) { + for (uint8_t j = 0; j < msplen; j++) { /* If we are returning changeable values, always return them from the page, so they are all correctly. */ if (page_control == 1) @@ -840,7 +838,8 @@ scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t pag static void scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, int block_len) { - int32_t bt, min_len = 0; + int32_t bt; + int32_t min_len = 0; double dlen; dev->max_transfer_len = dev->request_length; @@ -884,7 +883,9 @@ scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, int block_len) break; } } - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: dev->packet_len = len; @@ -928,7 +929,8 @@ scsi_cdrom_bus_speed(scsi_cdrom_t *dev) static void scsi_cdrom_command_common(scsi_cdrom_t *dev) { - double bytes_per_second = 0.0, period; + double bytes_per_second = 0.0; + double period; dev->status = BUSY_STAT; dev->phase = 1; @@ -959,7 +961,9 @@ scsi_cdrom_command_common(scsi_cdrom_t *dev) scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us\n", dev->id, (uint64_t) period); dev->callback += period; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x25: case 0x42: case 0x43: @@ -978,7 +982,9 @@ scsi_cdrom_command_common(scsi_cdrom_t *dev) break; case 0xc6: case 0xc7: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_DRIVEXM_3433"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_DRIVEXM_3433") || + !strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-3301TA_0272") || + !strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5701TA_3136")) { bytes_per_second = 176.0 * 1024.0; bytes_per_second *= (double) dev->drv->cur_speed; } @@ -1002,7 +1008,15 @@ scsi_cdrom_command_common(scsi_cdrom_t *dev) break; case 0xc3: if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU-541_1.0i") || - !strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU-76S_1.00")) { + !strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU-76S_1.00") || + !strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403")) { + bytes_per_second = 176.0 * 1024.0; + bytes_per_second *= (double) dev->drv->cur_speed; + } + break; + case 0xde: + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE74_1.00") || + !strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE464_1.05")) { bytes_per_second = 176.0 * 1024.0; bytes_per_second *= (double) dev->drv->cur_speed; } @@ -1108,7 +1122,7 @@ scsi_cdrom_data_command_finish(scsi_cdrom_t *dev, int len, int block_len, int al } static void -scsi_cdrom_sense_clear(scsi_cdrom_t *dev, int command) +scsi_cdrom_sense_clear(scsi_cdrom_t *dev, UNUSED(int command)) { scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = 0; } @@ -1273,9 +1287,10 @@ scsi_cdrom_data_phase_error(scsi_cdrom_t *dev) static int scsi_cdrom_read_data(scsi_cdrom_t *dev, int msf, int type, int flags, int32_t *len, int vendor_type) { - int ret = 0, data_pos = 0; - int i = 0, temp_len = 0; - uint32_t cdsize = 0; + int ret = 0; + int data_pos = 0; + int temp_len = 0; + uint32_t cdsize = 0; if (dev->drv->cd_status == CD_STATUS_EMPTY) { scsi_cdrom_not_ready(dev); @@ -1306,7 +1321,7 @@ scsi_cdrom_read_data(scsi_cdrom_t *dev, int msf, int type, int flags, int32_t *l dev->old_len = 0; *len = 0; - for (i = 0; i < dev->requested_blocks; i++) { + for (int i = 0; i < dev->requested_blocks; i++) { ret = cdrom_readsector_raw(dev->drv, dev->buffer + data_pos, dev->sector_pos + i, msf, type, flags, &temp_len, vendor_type); @@ -1327,8 +1342,10 @@ scsi_cdrom_read_data(scsi_cdrom_t *dev, int msf, int type, int flags, int32_t *l static int scsi_cdrom_read_blocks(scsi_cdrom_t *dev, int32_t *len, int first_batch, int vendor_type) { - int ret = 0, msf = 0; - int type = 0, flags = 0; + int ret = 0; + int msf = 0; + int type = 0; + int flags = 0; if (dev->current_cdb[0] == GPCMD_READ_CD_MSF) msf = 1; @@ -1484,9 +1501,9 @@ scsi_cdrom_read_dvd_structure(scsi_cdrom_t *dev, int format, const uint8_t *pack } static void -scsi_cdrom_insert(void *p) +scsi_cdrom_insert(void *priv) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (!dev) return; @@ -1695,16 +1712,26 @@ void scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int len, max_len, used_len, alloc_length, msf; - int pos = 0, i = 0, size_idx, idx = 0; + int len; + int max_len; + int used_len; + int alloc_length; + int msf; + int pos = 0; + int size_idx; + int idx = 0; uint32_t feature; unsigned preamble_len; - int toc_format, block_desc = 0; - int ret, format = 0; - int real_pos, track = 0; + int toc_format; + int block_desc = 0; + int ret; + int format = 0; + int real_pos; + int track = 0; char device_identify[9] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', 0 }; char device_identify_ex[15] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', ' ', 'v', '1', '.', '0', '0', 0 }; - int32_t blen = 0, *BufLen; + int32_t blen = 0; + int32_t *BufLen; uint8_t *b; uint32_t profiles[2] = { MMC_PROFILE_CD_ROM, MMC_PROFILE_DVD_ROM }; uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; @@ -1875,7 +1902,7 @@ begin: return; case 0xC7: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_PLAY_AUDIO_MSF_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_PLAY_AUDIO_MSF_MATSUSHITA*/ cdb[0] = GPCMD_PLAY_AUDIO_MSF; dev->current_cdb[0] = cdb[0]; goto begin; @@ -1913,7 +1940,9 @@ begin: /* IMPORTANT: Convert the command to new read CD for pass through purposes. */ dev->current_cdb[0] = GPCMD_READ_CD; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_READ_6: case GPCMD_READ_10: @@ -1991,6 +2020,9 @@ begin: return; } break; + + default: + break; } if (!dev->sector_len) { @@ -2218,7 +2250,7 @@ begin: alloc_length += 4; b += 4; - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { b[0] = (profiles[i] >> 8) & 0xff; b[1] = profiles[i] & 0xff; @@ -2407,7 +2439,7 @@ begin: break; } /*GPCMD_AUDIO_TRACK_SEARCH_TOSHIBA and GPCMD_EJECT_CHINON*/ case 0xD8: /*GPCMD_AUDIO_TRACK_SEARCH_NEC*/ - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42")) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_stop(sc); cdrom_eject(dev->id); @@ -2528,6 +2560,9 @@ begin: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; len = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; break; + + default: + break; } if ((dev->drv->host_drive < 1) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) { @@ -2603,13 +2638,13 @@ begin: dev->buffer[1] = 0x11; break; case CD_STATUS_PAUSED: - dev->buffer[1] = ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42"))) ? 0x15 : 0x12; + dev->buffer[1] = (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42")) ? 0x15 : 0x12; break; case CD_STATUS_DATA_ONLY: - dev->buffer[1] = ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42"))) ? 0x00 : 0x15; + dev->buffer[1] = (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42")) ? 0x00 : 0x15; break; default: - dev->buffer[1] = ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42"))) ? 0x00 : 0x13; + dev->buffer[1] = (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42")) ? 0x00 : 0x13; break; } @@ -2650,7 +2685,7 @@ begin: break; } /*GPCMD_READ_SUBCODEQ_PLAYING_STATUS_TOSHIBA and GPCMD_STOP_CHINON*/ case 0xDD: /*GPCMD_READ_SUBCODEQ_PLAYING_STATUS_NEC*/ - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42")) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_stop(sc); scsi_cdrom_command_complete(dev); @@ -2746,13 +2781,16 @@ begin: case 3: /* Load the disc (close tray). */ cdrom_reload(dev->id); break; + + default: + break; } scsi_cdrom_command_complete(dev); break; case 0xC4: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_READ_HEADER_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_READ_HEADER_MATSUSHITA*/ cdb[0] = GPCMD_READ_HEADER; dev->current_cdb[0] = cdb[0]; goto begin; @@ -2839,14 +2877,14 @@ begin: dev->buffer[idx++] = 0x00; dev->buffer[idx++] = 68; - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00"))) + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00")) ide_padstr8(dev->buffer + idx, 8, EMU_NAME); /* Vendor */ else ide_padstr8(dev->buffer + idx, 8, cdrom_drive_types[dev->drv->type].vendor); /* Vendor */ idx += 8; - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00"))) + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00")) ide_padstr8(dev->buffer + idx, 40, device_identify_ex); /* Product */ else ide_padstr8(dev->buffer + idx, 40, cdrom_drive_types[dev->drv->type].model); /* Product */ @@ -2872,15 +2910,15 @@ begin: if (dev->drv->bus_type == CDROM_BUS_SCSI) { dev->buffer[3] = 0x02; - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00")) { dev->buffer[2] = 0x05; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_DRIVEXM_3433"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_DRIVEXM_3433")) { dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-3301TA_0272"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-3301TA_0272")) { dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5701TA_3136"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5701TA_3136")) { dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "CHINON_CD-ROM_CDS-431_H42")) { dev->buffer[3] = 0x01; dev->buffer[2] = 0x02; } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU-541_1.0i")) { @@ -2889,17 +2927,17 @@ begin: } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU-76S_1.00")) { dev->buffer[3] = 0x01; dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { dev->buffer[3] = 0x01; dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE74_1.00"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE74_1.00")) { dev->buffer[3] = 0x01; dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "DEC_RRD45_0436"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "DEC_RRD45_0436")) { dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE464_1.05"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE464_1.05")) { dev->buffer[2] = 0x02; - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403")) { dev->buffer[2] = 0x02; } } else { @@ -2909,32 +2947,32 @@ begin: dev->buffer[4] = 31; if (dev->drv->bus_type == CDROM_BUS_SCSI) { - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00")) { dev->buffer[6] = 0x01; /* 16-bit transfers supported */ dev->buffer[7] = 0x20; /* Wide bus supported */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PLEXTOR_CD-ROM_PX-32TS_1.03"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PLEXTOR_CD-ROM_PX-32TS_1.03")) { dev->buffer[6] = 0x01; /* 16-bit transfers supported */ dev->buffer[7] = 0x20; /* Wide bus supported */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TEAC_CD-R55S_1.0R"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TEAC_CD-R55S_1.0R")) { dev->buffer[6] = 0x01; /* 16-bit transfers supported */ dev->buffer[7] = 0x20; /* Wide bus supported */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "DEC_RRD45_0436"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "DEC_RRD45_0436")) { dev->buffer[7] = 0x98; /* Linked Command and Relative Addressing supported */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_DRIVEXM_3433"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_DRIVEXM_3433")) { dev->buffer[4] = 91; /* Always 91 on Toshiba SCSI-2 CD-ROM drives from 1990*/ dev->buffer[7] = 0x88; /* Linked Command and Relative Addressing supported */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-3301TA_0272"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-3301TA_0272")) { dev->buffer[4] = 91; /* Always 91 on Toshiba SCSI-2 CD-ROM drives from 1990*/ dev->buffer[7] = 0x88; /* Linked Command and Relative Addressing supported */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5701TA_3136"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5701TA_3136")) { dev->buffer[4] = 91; /* Always 91 on Toshiba SCSI-2 CD-ROM drives from 1990*/ dev->buffer[7] = 0x88; /* Linked Command and Relative Addressing supported */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403")) { dev->buffer[4] = 42; } } - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00")) { ide_padstr8(dev->buffer + 8, 8, EMU_NAME); /* Vendor */ ide_padstr8(dev->buffer + 16, 16, device_identify); /* Product */ ide_padstr8(dev->buffer + 32, 4, EMU_VERSION_EX); /* Revision */ @@ -2942,7 +2980,7 @@ begin: ide_padstr8(dev->buffer + 8, 8, cdrom_drive_types[dev->drv->type].vendor); /* Vendor */ ide_padstr8(dev->buffer + 16, 16, cdrom_drive_types[dev->drv->type].model); /* Product */ ide_padstr8(dev->buffer + 32, 4, cdrom_drive_types[dev->drv->type].revision); /* Revision */ - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403")) { dev->buffer[36] = 0x20; ide_padstr8(dev->buffer + 37, 10, "1993/01/01"); /* Date */ } @@ -2993,7 +3031,7 @@ atapi_out: break; case 0xC3: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_READ_TOC_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_READ_TOC_MATSUSHITA*/ cdb[0] = GPCMD_READ_TOC_PMA_ATIP; dev->current_cdb[0] = cdb[0]; goto begin; @@ -3028,7 +3066,7 @@ atapi_out: break; case 0xC2: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_READ_SUBCHANNEL_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_READ_SUBCHANNEL_MATSUSHITA*/ cdb[0] = GPCMD_READ_SUBCHANNEL; dev->current_cdb[0] = cdb[0]; goto begin; @@ -3084,6 +3122,9 @@ atapi_out: case GPCMD_SEEK_10: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; break; + + default: + break; } dev->drv->seek_diff = ABS((int) (pos - dev->drv->seek_pos)); if (cdb[0] == GPCMD_SEEK_10) { @@ -3133,7 +3174,7 @@ atapi_out: break; case 0xC5: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_PLAY_AUDIO_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_PLAY_AUDIO_MATSUSHITA*/ cdb[0] = GPCMD_PLAY_AUDIO_10; dev->current_cdb[0] = cdb[0]; goto begin; @@ -3147,7 +3188,7 @@ atapi_out: break; } case 0xC8: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_PLAY_AUDIO_TRACK_INDEX_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_PLAY_AUDIO_TRACK_INDEX_MATSUSHITA*/ cdb[0] = GPCMD_PLAY_AUDIO_TRACK_INDEX; dev->current_cdb[0] = cdb[0]; goto begin; @@ -3161,7 +3202,7 @@ atapi_out: break; } case 0xC9: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10_MATSUSHITA*/ cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10; dev->current_cdb[0] = cdb[0]; goto begin; @@ -3179,21 +3220,21 @@ atapi_out: break; } case 0xCA: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403"))) { /*GPCMD_PAUSE_PIONEER*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403")) { /*GPCMD_PAUSE_PIONEER*/ scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); cdrom_audio_pause_resume(dev->drv, !(cdb[1] & 0x10)); scsi_cdrom_command_complete(dev); break; } case 0xCB: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_PAUSE_RESUME_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_PAUSE_RESUME_MATSUSHITA*/ cdb[0] = GPCMD_PAUSE_RESUME; dev->current_cdb[0] = cdb[0]; goto begin; break; } case 0xCC: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403")) { scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); max_len = cdb[7]; @@ -3221,7 +3262,7 @@ atapi_out: break; } case 0xE0: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403"))) { /*GPCMD_DRIVE_STATUS_PIONEER*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PIONEER_CD-ROM_DRM-604X_2403")) { /*GPCMD_DRIVE_STATUS_PIONEER*/ scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); len = (cdb[9] | (cdb[8] << 8)); @@ -3256,14 +3297,14 @@ atapi_out: return; } case 0xE5: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_PLAY_AUDIO_12_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_PLAY_AUDIO_12_MATSUSHITA*/ cdb[0] = GPCMD_PLAY_AUDIO_12; dev->current_cdb[0] = cdb[0]; goto begin; break; } case 0xE9: - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b"))) { /*GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12_MATSUSHITA*/ + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-501_1.0b")) { /*GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12_MATSUSHITA*/ cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12; dev->current_cdb[0] = cdb[0]; goto begin; @@ -3294,12 +3335,18 @@ static uint8_t scsi_cdrom_phase_data_out(scsi_common_t *sc) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - uint16_t block_desc_len, pos; + uint16_t block_desc_len; + uint16_t pos; uint16_t param_list_len; uint16_t i = 0; uint8_t error = 0; - uint8_t page, page_len, hdr_len, val, old_val, ch; + uint8_t page; + uint8_t page_len; + uint8_t hdr_len; + uint8_t val; + uint8_t old_val; + uint8_t ch; switch (dev->current_cdb[0]) { case GPCMD_MODE_SELECT_6: @@ -3412,6 +3459,9 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) } } break; + + default: + break; } scsi_cdrom_command_stop((scsi_common_t *) dev); @@ -3419,9 +3469,9 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) } static void -scsi_cdrom_close(void *p) +scsi_cdrom_close(void *priv) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (dev) free(dev); @@ -3482,7 +3532,7 @@ scsi_cdrom_get_timings(int ide_has_dma, int type) static void scsi_cdrom_identify(ide_t *ide, int ide_has_dma) { - scsi_cdrom_t *dev; + const scsi_cdrom_t *dev; char device_identify[9] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', 0 }; dev = (scsi_cdrom_t *) ide->sc; @@ -3496,68 +3546,68 @@ scsi_cdrom_identify(ide_t *ide, int ide_has_dma) ide->buffer[0] = 0x8000 | (5 << 8) | 0x80 | (2 << 5); /* ATAPI device, CD-ROM drive, removable media, accelerated DRQ */ ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "86BOX_CD-ROM_1.00")) { ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), device_identify, 40); /* Model */ } else { - if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE260_1.01"))) { + if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE260_1.01")) { ide_padstr((char *) (ide->buffer + 23), ".110 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "EN C DCR-MOD IREV2:06 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE260_1.00"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE260_1.00")) { ide_padstr((char *) (ide->buffer + 23), ".100 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "EN C DCR-MOD IREV2:06 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "AZT_CDA46802I_1.15"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "AZT_CDA46802I_1.15")) { ide_padstr((char *) (ide->buffer + 23), "1.15 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "AZT CDA46802I ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "HITACHI_CDR-8130_0020"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "HITACHI_CDR-8130_0020")) { ide_padstr((char *) (ide->buffer + 23), "0020 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "HITACHI CDR-8130 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU76_1.0i"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU76_1.0i")) { ide_padstr((char *) (ide->buffer + 23), "1.0i ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "SONY CD-ROM CDU76 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU311_3.0h"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "SONY_CD-ROM_CDU311_3.0h")) { ide_padstr((char *) (ide->buffer + 23), "3.0h ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "SONY CD-ROM CDU311 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE280_1.05"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE280_1.05")) { ide_padstr((char *) (ide->buffer + 23), "1.05 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:280 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE280_3.08"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE280_3.08")) { ide_padstr((char *) (ide->buffer + 23), "3.08 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:280 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE273_4.20"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "NEC_CD-ROM_DRIVE273_4.20")) { ide_padstr((char *) (ide->buffer + 23), "4.20 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:273 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5302TA_0305"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5302TA_0305")) { ide_padstr((char *) (ide->buffer + 23), "0305 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-5302TA ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5702B_TA70"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "TOSHIBA_CD-ROM_XM-5702B_TA70")) { ide_padstr((char *) (ide->buffer + 23), "TA70 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-5702B ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "GOLDSTAR_CRD-8160B_3.14"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "GOLDSTAR_CRD-8160B_3.14")) { ide_padstr((char *) (ide->buffer + 23), "3.14 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "GOLDSTAR CRD-8160B ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CR-571_1.0e"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CR-571_1.0e")) { ide_padstr((char *) (ide->buffer + 23), "1.0e ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "MATSHITA CR-571 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CR-572_1.0j"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CR-572_1.0j")) { ide_padstr((char *) (ide->buffer + 23), "1.0j ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "MATSHITA CR-572 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-587_7S13"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-587_7S13")) { ide_padstr((char *) (ide->buffer + 23), "7S13 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-587 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-588_LS15"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MATSHITA_CD-ROM_CR-588_LS15")) { ide_padstr((char *) (ide->buffer + 23), "LS15 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-588 ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MITSUMI_CRMC-FX4820T_D02A"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "MITSUMI_CRMC-FX4820T_D02A")) { ide_padstr((char *) (ide->buffer + 23), "D02A ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "MITSUMI CRMC-FX4820T ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PHILIPS_CD-ROM_PCA403CD_U31P"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "PHILIPS_CD-ROM_PCA403CD_U31P")) { ide_padstr((char *) (ide->buffer + 23), "U31P ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "PHILIPS CD-ROM PCA403CD ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "BTC_CD-ROM_BCD36XH_U1.0"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "BTC_CD-ROM_BCD36XH_U1.0")) { ide_padstr((char *) (ide->buffer + 23), "U1.0 ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "BTC CD-ROM BCD36XH ", 40); /* Model */ - } else if ((!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "KENWOOD_CD-ROM_UCR-421_208E"))) { + } else if (!strcmp(cdrom_drive_types[dev->drv->type].internal_name, "KENWOOD_CD-ROM_UCR-421_208E")) { ide_padstr((char *) (ide->buffer + 23), "208E ", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "KENWOOD CD-ROM UCR-421 ", 40); /* Model */ } diff --git a/src/scsi/scsi_device.c b/src/scsi/scsi_device.c index 721411bd8..4fce9f989 100644 --- a/src/scsi/scsi_device.c +++ b/src/scsi/scsi_device.c @@ -25,6 +25,7 @@ #include <86box/hdd.h> #include <86box/scsi.h> #include <86box/scsi_device.h> +#include <86box/plat_unused.h> scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; @@ -97,7 +98,7 @@ scsi_device_valid(scsi_device_t *dev) } int -scsi_device_cdb_length(scsi_device_t *dev) +scsi_device_cdb_length(UNUSED(scsi_device_t *dev)) { /* Right now, it's 12 for all devices. */ return 12; @@ -162,11 +163,10 @@ scsi_device_identify(scsi_device_t *dev, uint8_t lun) void scsi_device_close_all(void) { - int i, j; scsi_device_t *dev; - for (i = 0; i < SCSI_BUS_MAX; i++) { - for (j = 0; j < SCSI_ID_MAX; j++) { + for (uint8_t i = 0; i < SCSI_BUS_MAX; i++) { + for (uint8_t j = 0; j < SCSI_ID_MAX; j++) { dev = &(scsi_devices[i][j]); if (dev->command_stop && dev->sc) dev->command_stop(dev->sc); @@ -177,11 +177,10 @@ scsi_device_close_all(void) void scsi_device_init(void) { - int i, j; scsi_device_t *dev; - for (i = 0; i < SCSI_BUS_MAX; i++) { - for (j = 0; j < SCSI_ID_MAX; j++) { + for (uint8_t i = 0; i < SCSI_BUS_MAX; i++) { + for (uint8_t j = 0; j < SCSI_ID_MAX; j++) { dev = &(scsi_devices[i][j]); memset(dev, 0, sizeof(scsi_device_t)); diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index 5cc48b906..2bd61313b 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -182,9 +182,9 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 2: case 3: switch (pos) { + default: case 0: case 1: - default: return scsi_disk_mode_sense_pages_default.pages[page][pos]; case 2: case 6: @@ -201,6 +201,8 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 5: return dev->drv->hpc & 0xff; } + + default: break; } else if (page == GPMODE_FORMAT_DEVICE_PAGE) @@ -210,9 +212,9 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 2: case 3: switch (pos) { + default: case 0: case 1: - default: return scsi_disk_mode_sense_pages_default.pages[page][pos]; /* Actual sectors + the 1 "alternate sector" we report. */ case 10: @@ -220,6 +222,8 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 11: return (dev->drv->spt + 1) & 0xff; } + + default: break; } else @@ -229,6 +233,9 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, return dev->ms_pages_saved.pages[page][pos]; case 2: return scsi_disk_mode_sense_pages_default.pages[page][pos]; + + default: + break; } return 0; @@ -237,10 +244,9 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, uint32_t scsi_disk_mode_sense(scsi_disk_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) { - uint8_t msplen, page_control = (page >> 6) & 3; - - int i = 0, j = 0; - int size = 0; + uint8_t msplen; + uint8_t page_control = (page >> 6) & 3; + int size = 0; page &= 0x3f; @@ -257,14 +263,14 @@ scsi_disk_mode_sense(scsi_disk_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, buf[pos++] = 0; } - for (i = 0; i < 0x40; i++) { + for (uint8_t i = 0; i < 0x40; i++) { if ((page == GPMODE_ALL_PAGES) || (page == i)) { if (scsi_disk_mode_sense_page_flags & (1LL << (uint64_t) page)) { buf[pos++] = scsi_disk_mode_sense_read(dev, page_control, i, 0); msplen = scsi_disk_mode_sense_read(dev, page_control, i, 1); buf[pos++] = msplen; scsi_disk_log("SCSI HDD %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); - for (j = 0; j < msplen; j++) + for (uint8_t j = 0; j < msplen; j++) buf[pos++] = scsi_disk_mode_sense_read(dev, page_control, i, 2 + j); } } @@ -307,7 +313,7 @@ scsi_disk_command_write_dma(scsi_disk_t *dev) } static void -scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int alloc_len, int direction) +scsi_disk_data_command_finish(scsi_disk_t *dev, int len, UNUSED(int block_len), int alloc_len, int direction) { scsi_disk_log("SCSI HD %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, dev->request_length); @@ -326,7 +332,7 @@ scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int allo } static void -scsi_disk_sense_clear(scsi_disk_t *dev, int command) +scsi_disk_sense_clear(scsi_disk_t *dev, UNUSED(int command)) { scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = 0; } @@ -501,7 +507,7 @@ scsi_disk_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t all } static void -scsi_disk_set_buf_len(scsi_disk_t *dev, int32_t *BufLen, int32_t *src_len) +scsi_disk_set_buf_len(UNUSED(scsi_disk_t *dev), int32_t *BufLen, int32_t *src_len) { if (*BufLen == -1) *BufLen = *src_len; @@ -535,10 +541,13 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) { scsi_disk_t *dev = (scsi_disk_t *) sc; int32_t *BufLen; - int32_t len, max_len, alloc_length; + int32_t len; + int32_t max_len; + int32_t alloc_length; int pos = 0; int idx = 0; - unsigned size_idx, preamble_len; + unsigned size_idx; + unsigned preamble_len; uint32_t last_sector = 0; char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; char device_identify_ex[15] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', ' ', 'v', '1', '.', '0', '0', 0 }; @@ -588,7 +597,9 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) scsi_disk_invalid_field(dev); return; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_SCSI_RESERVE: case GPCMD_SCSI_RELEASE: case GPCMD_TEST_UNIT_READY: @@ -659,6 +670,9 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } if ((dev->sector_pos > last_sector) /* || ((dev->sector_pos + dev->sector_len - 1) > last_sector)*/) { @@ -735,6 +749,9 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } if ((dev->sector_pos > last_sector) /* || @@ -999,6 +1016,9 @@ atapi_out: case GPCMD_SEEK_10: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; break; + + default: + break; } scsi_disk_seek(dev, pos); @@ -1044,17 +1064,26 @@ scsi_disk_command_stop(scsi_common_t *sc) static uint8_t scsi_disk_phase_data_out(scsi_common_t *sc) { - scsi_disk_t *dev = (scsi_disk_t *) sc; - uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_id & 0x0f; - int i; - int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; - uint32_t last_sector = hdd_image_get_last_sector(dev->id); - uint32_t c, h, s, last_to_write = 0; - uint16_t block_desc_len, pos; - uint16_t param_list_len; - uint8_t hdr_len, val, old_val, ch, error = 0; - uint8_t page, page_len; + scsi_disk_t *dev = (scsi_disk_t *) sc; + uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + int i; + const int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; + uint32_t last_sector = hdd_image_get_last_sector(dev->id); + uint32_t c; + uint32_t h; + uint32_t s; + uint32_t last_to_write = 0; + uint16_t block_desc_len; + uint16_t pos; + uint16_t param_list_len; + uint8_t hdr_len; + uint8_t val; + uint8_t old_val; + uint8_t ch; + uint8_t error = 0; + uint8_t page; + uint8_t page_len; if (!*BufLen) { scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); @@ -1185,12 +1214,12 @@ scsi_disk_phase_data_out(scsi_common_t *sc) void scsi_disk_hard_reset(void) { - int c; scsi_disk_t *dev; scsi_device_t *sd; - uint8_t scsi_bus, scsi_id; + uint8_t scsi_bus; + uint8_t scsi_id; - for (c = 0; c < HDD_NUM; c++) { + for (uint8_t c = 0; c < HDD_NUM; c++) { if (hdd[c].bus == HDD_BUS_SCSI) { scsi_disk_log("SCSI disk hard_reset drive=%d\n", c); @@ -1247,10 +1276,10 @@ void scsi_disk_close(void) { scsi_disk_t *dev; - int c; - uint8_t scsi_bus, scsi_id; + uint8_t scsi_bus; + uint8_t scsi_id; - for (c = 0; c < HDD_NUM; c++) { + for (uint8_t c = 0; c < HDD_NUM; c++) { if (hdd[c].bus == HDD_BUS_SCSI) { scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; scsi_id = hdd[c].scsi_id & 0x0f; diff --git a/src/scsi/scsi_ncr5380.c b/src/scsi/scsi_ncr5380.c index faa91b093..8b0ae3c0c 100644 --- a/src/scsi/scsi_ncr5380.c +++ b/src/scsi/scsi_ncr5380.c @@ -93,9 +93,15 @@ #define STATUS_BUFFER_NOT_READY 0x04 #define STATUS_53C80_ACCESSIBLE 0x80 -typedef struct { - uint8_t icr, mode, tcr, data_wait; - uint8_t isr, output_data, target_id, tx_data; +typedef struct ncr_t { + uint8_t icr; + uint8_t mode; + uint8_t tcr; + uint8_t data_wait; + uint8_t isr; + uint8_t output_data; + uint8_t target_id; + uint8_t tx_data; uint8_t msglun; uint8_t command[20]; @@ -103,12 +109,19 @@ typedef struct { int msgout_pos; int is_msgout; - int dma_mode, cur_bus, bus_in, new_phase; - int state, clear_req, wait_data, wait_complete; - int command_pos, data_pos; + int dma_mode; + int cur_bus; + int bus_in; + int new_phase; + int state; + int clear_req; + int wait_data; + int wait_complete; + int command_pos; + int data_pos; } ncr_t; -typedef struct { +typedef struct t128_t { uint8_t ctrl; uint8_t status; uint8_t buffer[512]; @@ -121,14 +134,15 @@ typedef struct { int bios_enabled; } t128_t; -typedef struct { +typedef struct ncr5380_t { ncr_t ncr; t128_t t128; const char *name; uint8_t buffer[128]; - uint8_t int_ram[0x40], ext_ram[0x600]; + uint8_t int_ram[0x40]; + uint8_t ext_ram[0x600]; uint32_t rom_addr; uint16_t base; @@ -217,14 +231,12 @@ ncr_irq(ncr5380_t *ncr_dev, ncr_t *ncr, int set_irq) static int get_dev_id(uint8_t data) { - int c; - - for (c = 0; c < SCSI_ID_MAX; c++) { + for (uint8_t c = 0; c < SCSI_ID_MAX; c++) { if (data & (1 << c)) - return (c); + return c; } - return (-1); + return -1; } static int @@ -316,9 +328,9 @@ get_bus_host(ncr_t *ncr) static void ncr_bus_read(ncr5380_t *ncr_dev) { - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev; - int phase; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev; + int phase; /*Wait processes to handle bus requests*/ if (ncr->clear_req) { @@ -442,7 +454,9 @@ ncr_bus_update(void *priv, int bus) if (ncr->command_pos == cmd_len[(ncr->command[0] >> 5) & 7]) { if (ncr->is_msgout) { ncr->is_msgout = 0; - // ncr->command[1] = (ncr->command[1] & 0x1f) | (ncr->msglun << 5); +#if 0 + ncr->command[1] = (ncr->command[1] & 0x1f) | (ncr->msglun << 5); +#endif } /*Reset data position to default*/ @@ -567,6 +581,9 @@ ncr_bus_update(void *priv, int bus) SET_BUS_STATE(ncr, SCSI_PHASE_COMMAND); } break; + + default: + break; } ncr->bus_in = bus; @@ -575,10 +592,10 @@ ncr_bus_update(void *priv, int bus) static void ncr_write(uint16_t port, uint8_t val, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; - int bus_host = 0; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + int bus_host = 0; ncr_log("NCR5380 write(%04x,%02x)\n", port & 7, val); @@ -718,7 +735,8 @@ ncr_read(uint16_t port, void *priv) ncr5380_t *ncr_dev = (ncr5380_t *) priv; ncr_t *ncr = &ncr_dev->ncr; uint8_t ret = 0xff; - int bus, bus_state; + int bus; + int bus_state; switch (port & 7) { case 0: /* Current SCSI data */ @@ -824,17 +842,17 @@ ncr_read(uint16_t port, void *priv) ncr_log("NCR5380 read(%04x)=%02x\n", port & 7, ret); - return (ret); + return ret; } /* Memory-mapped I/O READ handler. */ static uint8_t memio_read(uint32_t addr, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; - uint8_t ret = 0xff; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + uint8_t ret = 0xff; addr &= 0x3fff; @@ -900,8 +918,14 @@ memio_read(uint32_t addr, void *priv) case 0x3983: ret = 0xff; break; + + default: + break; } break; + + default: + break; } #if ENABLE_NCR5380_LOG @@ -909,16 +933,16 @@ memio_read(uint32_t addr, void *priv) ncr_log("memio_read(%08x)=%02x\n", addr, ret); #endif - return (ret); + return ret; } /* Memory-mapped I/O WRITE handler. */ static void memio_write(uint32_t addr, uint8_t val, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; addr &= 0x3fff; @@ -977,8 +1001,14 @@ memio_write(uint32_t addr, uint8_t val, void *priv) ncr_dev->status_ctrl &= ~STATUS_BUFFER_NOT_READY; } break; + + default: + break; } break; + + default: + break; } } @@ -986,8 +1016,8 @@ memio_write(uint32_t addr, uint8_t val, void *priv) static uint8_t t130b_read(uint32_t addr, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - uint8_t ret = 0xff; + const ncr5380_t *ncr_dev = (ncr5380_t *) priv; + uint8_t ret = 0xff; addr &= 0x3fff; if (addr < 0x1800) @@ -996,7 +1026,7 @@ t130b_read(uint32_t addr, void *priv) ret = ncr_dev->ext_ram[addr & 0x7f]; ncr_log("MEM: Reading %02X from %08X\n", ret, addr); - return (ret); + return ret; } /* Memory-mapped I/O WRITE handler for the Trantor T130B. */ @@ -1040,10 +1070,13 @@ t130b_in(uint16_t port, void *priv) case 0x0f: ret = ncr_read(port, ncr_dev); break; + + default: + break; } ncr_log("I/O: Reading %02X from %04X\n", ret, port); - return (ret); + return ret; } static void @@ -1076,13 +1109,16 @@ t130b_out(uint16_t port, uint8_t val, void *priv) case 0x0f: ncr_write(port, val, ncr_dev); break; + + default: + break; } } static void ncr_dma_send(ncr5380_t *ncr_dev, ncr_t *ncr, scsi_device_t *dev) { - int bus, c = 0; + int bus; uint8_t data; if (scsi_device_get_callback(dev) > 0.0) @@ -1090,7 +1126,7 @@ ncr_dma_send(ncr5380_t *ncr_dev, ncr_t *ncr, scsi_device_t *dev) else ncr_timer_on(ncr_dev, ncr, 0); - for (c = 0; c < 10; c++) { + for (uint8_t c = 0; c < 10; c++) { ncr_bus_read(ncr_dev); if (ncr->cur_bus & BUS_REQ) break; @@ -1161,7 +1197,7 @@ ncr_dma_send(ncr5380_t *ncr_dev, ncr_t *ncr, scsi_device_t *dev) static void ncr_dma_initiator_receive(ncr5380_t *ncr_dev, ncr_t *ncr, scsi_device_t *dev) { - int bus, c = 0; + int bus; uint8_t temp; if (scsi_device_get_callback(dev) > 0.0) { @@ -1170,7 +1206,7 @@ ncr_dma_initiator_receive(ncr5380_t *ncr_dev, ncr_t *ncr, scsi_device_t *dev) ncr_timer_on(ncr_dev, ncr, 0); } - for (c = 0; c < 10; c++) { + for (uint8_t c = 0; c < 10; c++) { ncr_bus_read(ncr_dev); if (ncr->cur_bus & BUS_REQ) break; @@ -1326,6 +1362,9 @@ ncr_callback(void *priv) } ncr_dma_initiator_receive(ncr_dev, ncr, dev); break; + + default: + break; } ncr_bus_read(ncr_dev); @@ -1342,7 +1381,7 @@ static uint8_t t128_read(uint32_t addr, void *priv) { ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; + const ncr_t *ncr = &ncr_dev->ncr; scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; uint8_t ret = 0xff; @@ -1376,15 +1415,15 @@ t128_read(uint32_t addr, void *priv) } } - return (ret); + return ret; } static void t128_write(uint32_t addr, uint8_t val, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + const ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; addr &= 0x3fff; if (addr >= 0x1800 && addr < 0x1880) @@ -1418,7 +1457,7 @@ t128_write(uint32_t addr, uint8_t val, void *priv) static uint8_t rt1000b_mc_read(int port, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; + const ncr5380_t *ncr_dev = (ncr5380_t *) priv; return (ncr_dev->pos_regs[port & 7]); } @@ -1458,6 +1497,9 @@ rt1000b_mc_write(int port, uint8_t val, void *priv) case 0xe0: ncr_dev->rom_addr = 0xd8000; break; + + default: + break; } mem_mapping_set_addr(&ncr_dev->bios_rom.mapping, ncr_dev->rom_addr, 0x4000); @@ -1468,7 +1510,7 @@ rt1000b_mc_write(int port, uint8_t val, void *priv) static uint8_t rt1000b_mc_feedb(void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; + const ncr5380_t *ncr_dev = (ncr5380_t *) priv; return ncr_dev->pos_regs[2] & 1; } @@ -1476,9 +1518,9 @@ rt1000b_mc_feedb(void *priv) static void * ncr_init(const device_t *info) { - char *fn = NULL; - char temp[128]; - ncr5380_t *ncr_dev; + const char *fn = NULL; + char temp[128]; + ncr5380_t *ncr_dev; ncr_dev = malloc(sizeof(ncr5380_t)); memset(ncr_dev, 0x00, sizeof(ncr5380_t)); @@ -1578,6 +1620,9 @@ ncr_init(const device_t *info) memio_write, NULL, NULL, ncr_dev->bios_rom.rom, MEM_MAPPING_EXTERNAL, ncr_dev); break; + + default: + break; } sprintf(temp, "%s: BIOS=%05X", ncr_dev->name, ncr_dev->rom_addr); @@ -1600,7 +1645,7 @@ ncr_init(const device_t *info) } timer_add(&ncr_dev->timer, ncr_callback, ncr_dev, 0); - return (ncr_dev); + return ncr_dev; } static void diff --git a/src/scsi/scsi_ncr53c8xx.c b/src/scsi/scsi_ncr53c8xx.c index dfeae7569..897f37d1d 100644 --- a/src/scsi/scsi_ncr53c8xx.c +++ b/src/scsi/scsi_ncr53c8xx.c @@ -204,7 +204,7 @@ typedef enum { SCSI_STATE_WRITE_MESSAGE } scsi_state_t; -typedef struct { +typedef struct ncr53c8xx_t { char *nvr_path; uint8_t pci_slot; uint8_t chip, wide; @@ -291,9 +291,16 @@ typedef struct { uint32_t dbc; uint32_t dsp; uint32_t dsps; - uint32_t scratcha, scratchb, scratchc, scratchd; - uint32_t scratche, scratchf, scratchg, scratchh; - uint32_t scratchi, scratchj; + uint32_t scratcha; + uint32_t scratchb; + uint32_t scratchc; + uint32_t scratchd; + uint32_t scratche; + uint32_t scratchf; + uint32_t scratchg; + uint32_t scratchh; + uint32_t scratchi; + uint32_t scratchj; int last_level; void *hba_private; uint32_t buffer_pos; @@ -451,13 +458,11 @@ ncr53c8xx_soft_reset(ncr53c8xx_t *dev) static void ncr53c8xx_read(ncr53c8xx_t *dev, uint32_t addr, uint8_t *buf, uint32_t len) { - uint32_t i = 0; - ncr53c8xx_log("ncr53c8xx_read(): %08X-%08X, length %i\n", addr, (addr + len - 1), len); if (dev->dmode & NCR_DMODE_SIOM) { ncr53c8xx_log("NCR 810: Reading from I/O address %04X\n", (uint16_t) addr); - for (i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) buf[i] = inb((uint16_t) (addr + i)); } else { ncr53c8xx_log("NCR 810: Reading from memory address %08X\n", addr); @@ -468,13 +473,11 @@ ncr53c8xx_read(ncr53c8xx_t *dev, uint32_t addr, uint8_t *buf, uint32_t len) static void ncr53c8xx_write(ncr53c8xx_t *dev, uint32_t addr, uint8_t *buf, uint32_t len) { - uint32_t i = 0; - ncr53c8xx_log("ncr53c8xx_write(): %08X-%08X, length %i\n", addr, (addr + len - 1), len); if (dev->dmode & NCR_DMODE_DIOM) { ncr53c8xx_log("NCR 810: Writing to I/O address %04X\n", (uint16_t) addr); - for (i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) outb((uint16_t) (addr + i), buf[i]); } else { ncr53c8xx_log("NCR 810: Writing to memory address %08X\n", addr); @@ -483,7 +486,7 @@ ncr53c8xx_write(ncr53c8xx_t *dev, uint32_t addr, uint8_t *buf, uint32_t len) } static __inline uint32_t -read_dword(ncr53c8xx_t *dev, uint32_t addr) +read_dword(UNUSED(ncr53c8xx_t *dev), uint32_t addr) { uint32_t buf; ncr53c8xx_log("Reading the next DWORD from memory (%08X)...\n", addr); @@ -582,7 +585,7 @@ ncr53c8xx_set_phase(ncr53c8xx_t *dev, int phase) } static void -ncr53c8xx_bad_phase(ncr53c8xx_t *dev, int out, int new_phase) +ncr53c8xx_bad_phase(ncr53c8xx_t *dev, UNUSED(int out), int new_phase) { /* Trigger a phase mismatch. */ ncr53c8xx_log("Phase mismatch interrupt\n"); @@ -607,7 +610,7 @@ ncr53c8xx_disconnect(ncr53c8xx_t *dev) } static void -ncr53c8xx_bad_selection(ncr53c8xx_t *dev, uint32_t id) +ncr53c8xx_bad_selection(ncr53c8xx_t *dev, UNUSED(uint32_t id)) { ncr53c8xx_log("Selected absent target %d\n", id); ncr53c8xx_script_scsi_interrupt(dev, 0, NCR_SIST1_STO); @@ -637,12 +640,13 @@ ncr53c8xx_command_complete(void *priv, uint32_t status) static void ncr53c8xx_do_dma(ncr53c8xx_t *dev, int out, uint8_t id) { - uint32_t addr, tdbc; + uint32_t addr; + uint32_t tdbc; int count; scsi_device_t *sd = &scsi_devices[dev->bus][id]; - if ((!scsi_device_present(sd))) { + if (!scsi_device_present(sd)) { ncr53c8xx_log("(ID=%02i LUN=%02i) SCSI Command 0x%02x: Device not present when attempting to do DMA\n", id, dev->current_lun, dev->last_command); return; } @@ -866,7 +870,7 @@ ncr53c8xx_skip_msgbytes(ncr53c8xx_t *dev, unsigned int n) } static void -ncr53c8xx_bad_message(ncr53c8xx_t *dev, uint8_t msg) +ncr53c8xx_bad_message(ncr53c8xx_t *dev, UNUSED(uint8_t msg)) { ncr53c8xx_log("Unimplemented message 0x%02x\n", msg); ncr53c8xx_set_phase(dev, PHASE_MI); @@ -878,7 +882,8 @@ static void ncr53c8xx_do_msgout(ncr53c8xx_t *dev, uint8_t id) { uint8_t msg; - int len, arg; + int len; + int arg; scsi_device_t *sd; sd = &scsi_devices[dev->bus][id]; @@ -1000,10 +1005,26 @@ ncr53c8xx_memcpy(ncr53c8xx_t *dev, uint32_t dest, uint32_t src, int count) static void ncr53c8xx_process_script(ncr53c8xx_t *dev) { - uint32_t insn, addr, id, buf[2], dest; - int opcode, insn_processed = 0, reg, operator, cond, jmp, n, i, c; - int32_t offset; - uint8_t op0, op1, data8, mask, data[7]; + uint32_t insn; + uint32_t addr; + uint32_t id; + uint32_t buf[2]; + uint32_t dest; + int opcode; + int insn_processed = 0; + int reg; + int operator; + int cond; + int jmp; + int n; + int i; + int c; + int32_t offset; + uint8_t op0; + uint8_t op1; + uint8_t data8; + uint8_t mask; + uint8_t data[7]; dev->sstop = 0; again: @@ -1177,6 +1198,9 @@ again: if (insn & (1 << 10)) dev->carry = 0; break; + + default: + break; } } else { reg = ((insn >> 16) & 0x7f) | (insn & 0x80); @@ -1202,6 +1226,9 @@ again: else op1 = data8; break; + + default: + break; } switch (operator) { @@ -1238,6 +1265,9 @@ again: else dev->carry = op0 < op1; break; + + default: + break; } switch (opcode) { @@ -1248,6 +1278,9 @@ again: case 6: /* To SFBR */ dev->sfbr = op0; break; + + default: + break; } } break; @@ -1389,9 +1422,9 @@ ncr53c8xx_execute_script(ncr53c8xx_t *dev) } static void -ncr53c8xx_callback(void *p) +ncr53c8xx_callback(void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; if (!dev->sstop) { if (dev->waiting) @@ -1545,7 +1578,9 @@ ncr53c8xx_reg_writeb(ncr53c8xx_t *dev, uint32_t offset, uint8_t val) ncr53c8xx_log("Woken by SIGP\n"); dev->waiting = 0; dev->dsp = dev->dnad; - /* ncr53c8xx_execute_script(dev); */ +#if 0 + ncr53c8xx_execute_script(dev); +#endif } if ((val & NCR_ISTAT_SRST) && !(tmp & NCR_ISTAT_SRST)) { ncr53c8xx_soft_reset(dev); @@ -1964,6 +1999,9 @@ ncr53c8xx_reg_readb(ncr53c8xx_t *dev, uint32_t offset) CASE_GET_REG32_COND(scratchh, 0x74) CASE_GET_REG32_COND(scratchi, 0x78) CASE_GET_REG32_COND(scratchj, 0x7c) + + default: + break; } ncr53c8xx_log("readb 0x%x\n", offset); return 0; @@ -1973,16 +2011,17 @@ ncr53c8xx_reg_readb(ncr53c8xx_t *dev, uint32_t offset) } static uint8_t -ncr53c8xx_io_readb(uint16_t addr, void *p) +ncr53c8xx_io_readb(uint16_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + return ncr53c8xx_reg_readb(dev, addr & 0xff); } static uint16_t -ncr53c8xx_io_readw(uint16_t addr, void *p) +ncr53c8xx_io_readw(uint16_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint16_t val; addr &= 0xff; @@ -1992,9 +2031,9 @@ ncr53c8xx_io_readw(uint16_t addr, void *p) } static uint32_t -ncr53c8xx_io_readl(uint16_t addr, void *p) +ncr53c8xx_io_readl(uint16_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint32_t val; addr &= 0xff; @@ -2006,25 +2045,28 @@ ncr53c8xx_io_readl(uint16_t addr, void *p) } static void -ncr53c8xx_io_writeb(uint16_t addr, uint8_t val, void *p) +ncr53c8xx_io_writeb(uint16_t addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + ncr53c8xx_reg_writeb(dev, addr & 0xff, val); } static void -ncr53c8xx_io_writew(uint16_t addr, uint16_t val, void *p) +ncr53c8xx_io_writew(uint16_t addr, uint16_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); ncr53c8xx_reg_writeb(dev, addr + 1, (val >> 8) & 0xff); } static void -ncr53c8xx_io_writel(uint16_t addr, uint32_t val, void *p) +ncr53c8xx_io_writel(uint16_t addr, uint32_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); ncr53c8xx_reg_writeb(dev, addr + 1, (val >> 8) & 0xff); @@ -2033,17 +2075,17 @@ ncr53c8xx_io_writel(uint16_t addr, uint32_t val, void *p) } static void -ncr53c8xx_mmio_writeb(uint32_t addr, uint8_t val, void *p) +ncr53c8xx_mmio_writeb(uint32_t addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; ncr53c8xx_reg_writeb(dev, addr & 0xff, val); } static void -ncr53c8xx_mmio_writew(uint32_t addr, uint16_t val, void *p) +ncr53c8xx_mmio_writew(uint32_t addr, uint16_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); @@ -2051,9 +2093,9 @@ ncr53c8xx_mmio_writew(uint32_t addr, uint16_t val, void *p) } static void -ncr53c8xx_mmio_writel(uint32_t addr, uint32_t val, void *p) +ncr53c8xx_mmio_writel(uint32_t addr, uint32_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); @@ -2063,17 +2105,17 @@ ncr53c8xx_mmio_writel(uint32_t addr, uint32_t val, void *p) } static uint8_t -ncr53c8xx_mmio_readb(uint32_t addr, void *p) +ncr53c8xx_mmio_readb(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; return ncr53c8xx_reg_readb(dev, addr & 0xff); } static uint16_t -ncr53c8xx_mmio_readw(uint32_t addr, void *p) +ncr53c8xx_mmio_readw(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint16_t val; addr &= 0xff; @@ -2083,9 +2125,9 @@ ncr53c8xx_mmio_readw(uint32_t addr, void *p) } static uint32_t -ncr53c8xx_mmio_readl(uint32_t addr, void *p) +ncr53c8xx_mmio_readl(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint32_t val; addr &= 0xff; @@ -2098,57 +2140,57 @@ ncr53c8xx_mmio_readl(uint32_t addr, void *p) } static void -ncr53c8xx_ram_writeb(uint32_t addr, uint8_t val, void *p) +ncr53c8xx_ram_writeb(uint32_t addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; dev->ram[addr & 0x0fff] = val; } static void -ncr53c8xx_ram_writew(uint32_t addr, uint16_t val, void *p) +ncr53c8xx_ram_writew(uint32_t addr, uint16_t val, void *priv) { - ncr53c8xx_ram_writeb(addr, val & 0xff, p); - ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, p); + ncr53c8xx_ram_writeb(addr, val & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, priv); } static void -ncr53c8xx_ram_writel(uint32_t addr, uint32_t val, void *p) +ncr53c8xx_ram_writel(uint32_t addr, uint32_t val, void *priv) { - ncr53c8xx_ram_writeb(addr, val & 0xff, p); - ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, p); - ncr53c8xx_ram_writeb(addr + 2, (val >> 16) & 0xff, p); - ncr53c8xx_ram_writeb(addr + 3, (val >> 24) & 0xff, p); + ncr53c8xx_ram_writeb(addr, val & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 2, (val >> 16) & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 3, (val >> 24) & 0xff, priv); } static uint8_t -ncr53c8xx_ram_readb(uint32_t addr, void *p) +ncr53c8xx_ram_readb(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + const ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; return dev->ram[addr & 0x0fff]; } static uint16_t -ncr53c8xx_ram_readw(uint32_t addr, void *p) +ncr53c8xx_ram_readw(uint32_t addr, void *priv) { uint16_t val; - val = ncr53c8xx_ram_readb(addr, p); - val |= ncr53c8xx_ram_readb(addr + 1, p) << 8; + val = ncr53c8xx_ram_readb(addr, priv); + val |= ncr53c8xx_ram_readb(addr + 1, priv) << 8; return val; } static uint32_t -ncr53c8xx_ram_readl(uint32_t addr, void *p) +ncr53c8xx_ram_readl(uint32_t addr, void *priv) { uint32_t val; - val = ncr53c8xx_ram_readb(addr, p); - val |= ncr53c8xx_ram_readb(addr + 1, p) << 8; - val |= ncr53c8xx_ram_readb(addr + 2, p) << 16; - val |= ncr53c8xx_ram_readb(addr + 3, p) << 24; + val = ncr53c8xx_ram_readb(addr, priv); + val |= ncr53c8xx_ram_readb(addr + 1, priv) << 8; + val |= ncr53c8xx_ram_readb(addr + 2, priv) << 16; + val |= ncr53c8xx_ram_readb(addr + 3, priv) << 24; return val; } @@ -2232,9 +2274,9 @@ uint8_t ncr53c8xx_pci_regs[256]; bar_t ncr53c8xx_pci_bar[4]; static uint8_t -ncr53c8xx_pci_read(int func, int addr, void *p) +ncr53c8xx_pci_read(UNUSED(int func), int addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; ncr53c8xx_log("NCR53c8xx: Reading register %02X\n", addr & 0xff); @@ -2327,15 +2369,18 @@ ncr53c8xx_pci_read(int func, int addr, void *p) return 0x11; case 0x3F: return 0x40; + + default: + break; } - return (0); + return 0; } static void -ncr53c8xx_pci_write(int func, int addr, uint8_t val, void *p) +ncr53c8xx_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint8_t valxor; ncr53c8xx_log("NCR53c8xx: Write value %02X to register %02X\n", val, addr & 0xff); @@ -2465,6 +2510,9 @@ ncr53c8xx_pci_write(int func, int addr, uint8_t val, void *p) ncr53c8xx_pci_regs[addr] = val; dev->irq = val; return; + + default: + break; } } @@ -2570,7 +2618,7 @@ ncr53c8xx_init(const device_t *info) timer_add(&dev->timer, ncr53c8xx_callback, dev, 0); - return (dev); + return dev; } static void diff --git a/src/scsi/scsi_pcscsi.c b/src/scsi/scsi_pcscsi.c index c4f3143e8..7fa359396 100644 --- a/src/scsi/scsi_pcscsi.c +++ b/src/scsi/scsi_pcscsi.c @@ -149,7 +149,7 @@ #define SBAC_STATUS (1 << 24) #define SBAC_PABTEN (1 << 25) -typedef struct { +typedef struct esp_t { mem_mapping_t mmio_mapping; mem_mapping_t ram_mapping; char *nvr_path; @@ -188,10 +188,10 @@ typedef struct { int mca; uint16_t Base; - uint8_t HostID, DmaChannel; + uint8_t HostID; + uint8_t DmaChannel; - struct - { + struct { uint8_t mode; uint8_t status; int pos; @@ -360,7 +360,8 @@ static uint32_t esp_get_cmd(esp_t *dev, uint32_t maxlen) { uint8_t buf[ESP_CMDFIFO_SZ]; - uint32_t dmalen, n; + uint32_t dmalen; + uint32_t n; dev->id = dev->wregs[ESP_WBUSID] & BUSID_DID; if (dev->dma) { @@ -378,9 +379,9 @@ esp_get_cmd(esp_t *dev, uint32_t maxlen) dma_set_drq(dev->DmaChannel, 0); } else { esp_pci_dma_memory_rw(dev, buf, dmalen, WRITE_TO_DEVICE); - dmalen = MIN(fifo8_num_free(&dev->cmdfifo), dmalen); - fifo8_push_all(&dev->cmdfifo, buf, dmalen); } + dmalen = MIN(fifo8_num_free(&dev->cmdfifo), dmalen); + fifo8_push_all(&dev->cmdfifo, buf, dmalen); } else { dmalen = MIN(fifo8_num_used(&dev->fifo), maxlen); esp_log("ESP Get command, dmalen = %i\n", dmalen); @@ -544,6 +545,8 @@ esp_hard_reset(esp_t *dev) dev->do_cmd = 0; dev->rregs[ESP_CFG1] = dev->mca ? dev->HostID : 7; esp_log("ESP Reset\n"); + for (uint8_t i = 0; i < 16; i++) + scsi_device_reset(&scsi_devices[dev->bus][i]); timer_stop(&dev->timer); } @@ -568,7 +571,6 @@ esp_do_nodma(esp_t *dev, scsi_device_t *sd) esp_do_cmd(dev); } else { dev->cmdfifo_cdb_offset = fifo8_num_used(&dev->cmdfifo); - ; esp_log("CDB offset = %i used\n", dev->cmdfifo_cdb_offset); dev->rregs[ESP_RSTAT] = STAT_TC | STAT_CD; @@ -664,7 +666,7 @@ esp_do_dma(esp_t *dev, scsi_device_t *sd) count = tdbc = esp_get_tc(dev); - if (dev->mca) { /*See the comment in the esp_do_busid_cmd() function.*/ + if (dev->mca) { if (sd->buffer_length < 0) { if (dev->dma_enabled) goto done; @@ -712,7 +714,7 @@ esp_do_dma(esp_t *dev, scsi_device_t *sd) return; } - esp_log("ESP SCSI dmaleft = %d, async_len = %i, buffer length = %d\n", esp_get_tc(dev), sd->buffer_length); + esp_log("ESP SCSI dmaleft = %d, buffer length = %d\n", esp_get_tc(dev), sd->buffer_length); /* Make sure count is never bigger than buffer_length. */ if (count > dev->xfer_counter) @@ -950,9 +952,9 @@ esp_write_response(esp_t *dev) } static void -esp_callback(void *p) +esp_callback(void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; if (dev->dma_enabled || dev->do_cmd || ((dev->rregs[ESP_CMD] & CMD_CMD) == CMD_PAD)) { if ((dev->rregs[ESP_CMD] & CMD_CMD) == CMD_TI) { @@ -1027,7 +1029,9 @@ esp_reg_write(esp_t *dev, uint32_t saddr, uint32_t val) switch (saddr) { case ESP_TCHI: dev->tchi_written = 1; - /* fall through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case ESP_TCLO: case ESP_TCMID: esp_log("Transfer count regs %02x = %i\n", saddr, val); @@ -1081,6 +1085,9 @@ esp_reg_write(esp_t *dev, uint32_t saddr, uint32_t val) esp_pci_soft_reset(dev); break; case CMD_BUSRESET: + for (uint8_t i = 0; i < 16; i++) + scsi_device_reset(&scsi_devices[dev->bus][i]); + if (!(dev->wregs[ESP_CFG1] & CFG1_RESREPT)) { dev->rregs[ESP_RINTR] |= INTR_RST; esp_log("ESP Bus Reset with IRQ\n"); @@ -1129,6 +1136,9 @@ esp_reg_write(esp_t *dev, uint32_t saddr, uint32_t val) esp_log("ESP Disable Selection\n"); esp_raise_irq(dev); break; + + default: + break; } break; case ESP_WBUSID: @@ -1254,6 +1264,9 @@ esp_pci_dma_write(esp_t *dev, uint16_t saddr, uint32_t val) dev->dma_regs[DMA_STAT] &= ~(val & mask); } break; + + default: + break; } } @@ -1313,7 +1326,8 @@ esp_io_pci_read(esp_t *dev, uint32_t addr, unsigned int size) static void esp_io_pci_write(esp_t *dev, uint32_t addr, uint32_t val, unsigned int size) { - uint32_t current, mask; + uint32_t current; + uint32_t mask; int shift; addr &= 0x7f; @@ -1355,44 +1369,49 @@ esp_io_pci_write(esp_t *dev, uint32_t addr, uint32_t val, unsigned int size) } static void -esp_pci_io_writeb(uint16_t addr, uint8_t val, void *p) +esp_pci_io_writeb(uint16_t addr, uint8_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + esp_io_pci_write(dev, addr, val, 1); } static void -esp_pci_io_writew(uint16_t addr, uint16_t val, void *p) +esp_pci_io_writew(uint16_t addr, uint16_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + esp_io_pci_write(dev, addr, val, 2); } static void -esp_pci_io_writel(uint16_t addr, uint32_t val, void *p) +esp_pci_io_writel(uint16_t addr, uint32_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; esp_io_pci_write(dev, addr, val, 4); } static uint8_t -esp_pci_io_readb(uint16_t addr, void *p) +esp_pci_io_readb(uint16_t addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + return esp_io_pci_read(dev, addr, 1); } static uint16_t -esp_pci_io_readw(uint16_t addr, void *p) +esp_pci_io_readw(uint16_t addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + return esp_io_pci_read(dev, addr, 2); } static uint32_t -esp_pci_io_readl(uint16_t addr, void *p) +esp_pci_io_readl(uint16_t addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + return esp_io_pci_read(dev, addr, 4); } @@ -1543,6 +1562,9 @@ dc390_write_eeprom(esp_t *dev, int ena, int clk, int dat) esp_log("EEPROM Write enable command\n"); eeprom->wp = 0; break; + + default: + break; } } else { esp_log("EEPROM Read, write or erase word\n"); @@ -1616,9 +1638,9 @@ uint8_t esp_pci_regs[256]; bar_t esp_pci_bar[2]; static uint8_t -esp_pci_read(int func, int addr, void *p) +esp_pci_read(UNUSED(int func), int addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; // esp_log("ESP PCI: Reading register %02X\n", addr & 0xff); @@ -1689,15 +1711,18 @@ esp_pci_read(int func, int addr, void *p) case 0x40 ... 0x4f: return esp_pci_regs[addr]; + + default: + break; } - return (0); + return 0; } static void -esp_pci_write(int func, int addr, uint8_t val, void *p) +esp_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; uint8_t valxor; int eesk; int eedi; @@ -1793,11 +1818,14 @@ esp_pci_write(int func, int addr, uint8_t val, void *p) case 0x40 ... 0x4f: esp_pci_regs[addr] = val; return; + + default: + break; } } static void * -dc390_init(const device_t *info) +dc390_init(UNUSED(const device_t *info)) { esp_t *dev; @@ -1844,7 +1872,7 @@ dc390_init(const device_t *info) timer_add(&dev->timer, esp_callback, dev, 0); - return (dev); + return dev; } static uint16_t @@ -1866,6 +1894,9 @@ ncr53c90_in(uint16_t port, void *priv) case 0x0c: ret = dev->dma_86c01.status; break; + + default: + break; } } @@ -1920,7 +1951,7 @@ ncr53c90_outw(uint16_t port, uint16_t val, void *priv) static uint8_t ncr53c90_mca_read(int port, void *priv) { - esp_t *dev = (esp_t *) priv; + const esp_t *dev = (esp_t *) priv; return (dev->pos_regs[port & 7]); } @@ -1983,13 +2014,13 @@ ncr53c90_mca_write(int port, uint8_t val, void *priv) static uint8_t ncr53c90_mca_feedb(void *priv) { - esp_t *dev = (esp_t *) priv; + const esp_t *dev = (esp_t *) priv; return (dev->pos_regs[2] & 0x01); } static void * -ncr53c90_mca_init(const device_t *info) +ncr53c90_mca_init(UNUSED(const device_t *info)) { esp_t *dev; @@ -2011,7 +2042,7 @@ ncr53c90_mca_init(const device_t *info) timer_add(&dev->timer, esp_callback, dev, 0); - return (dev); + return dev; } static void diff --git a/src/scsi/scsi_spock.c b/src/scsi/scsi_spock.c index 19fba0fb7..3b9f5108c 100644 --- a/src/scsi/scsi_spock.c +++ b/src/scsi/scsi_spock.c @@ -228,10 +228,9 @@ static void spock_rethink_irqs(spock_t *scsi) { int irq_pending = 0; - int c; if (!scsi->irq_status) { - for (c = 0; c < SCSI_ID_MAX; c++) { + for (uint8_t c = 0; c < SCSI_ID_MAX; c++) { if (scsi->irq_requests[c] != IRQ_TYPE_NONE) { /* Found IRQ */ scsi->irq_status = c | (scsi->irq_requests[c] << 4); @@ -287,9 +286,9 @@ spock_add_to_period(spock_t *scsi, int TransferLength) } static void -spock_write(uint16_t port, uint8_t val, void *p) +spock_write(uint16_t port, uint8_t val, void *priv) { - spock_t *scsi = (spock_t *) p; + spock_t *scsi = (spock_t *) priv; spock_log("spock_write: port=%04x val=%02x %04x:%04x\n", port, val, CS, cpu_state.pc); @@ -321,13 +320,16 @@ spock_write(uint16_t port, uint8_t val, void *p) scsi->basic_ctrl = val; spock_rethink_irqs(scsi); break; + + default: + break; } } static void -spock_writew(uint16_t port, uint16_t val, void *p) +spock_writew(uint16_t port, uint16_t val, void *priv) { - spock_t *scsi = (spock_t *) p; + spock_t *scsi = (spock_t *) priv; switch (port & 7) { case 0: /*Command Interface Register*/ @@ -340,15 +342,18 @@ spock_writew(uint16_t port, uint16_t val, void *p) scsi->cir_pending[3] = val >> 8; scsi->cir_status |= 2; break; + + default: + break; } spock_log("spock_writew: port=%04x val=%04x\n", port, val); } static uint8_t -spock_read(uint16_t port, void *p) +spock_read(uint16_t port, void *priv) { - spock_t *scsi = (spock_t *) p; + const spock_t *scsi = (spock_t *) priv; uint8_t temp = 0xff; switch (port & 7) { @@ -379,6 +384,9 @@ spock_read(uint16_t port, void *p) temp |= STATUS_CMD_FULL; } break; + + default: + break; } spock_log("spock_read: port=%04x val=%02x %04x(%05x):%04x.\n", port, temp, CS, cs, cpu_state.pc); @@ -386,10 +394,10 @@ spock_read(uint16_t port, void *p) } static uint16_t -spock_readw(uint16_t port, void *p) +spock_readw(uint16_t port, void *priv) { - spock_t *scsi = (spock_t *) p; - uint16_t temp = 0xffff; + const spock_t *scsi = (spock_t *) priv; + uint16_t temp = 0xffff; switch (port & 7) { case 0: /*Command Interface Register*/ @@ -398,6 +406,9 @@ spock_readw(uint16_t port, void *p) case 2: /*Command Interface Register*/ temp = scsi->cir_pending[2] | (scsi->cir_pending[3] << 8); break; + + default: + break; } spock_log("spock_readw: port=%04x val=%04x\n", port, temp); @@ -414,21 +425,21 @@ spock_rd_sge(spock_t *scsi, uint32_t Address, SGE *SG) static int spock_get_len(spock_t *scsi, scb_t *scb) { - uint32_t DataToTransfer = 0, i = 0; + uint32_t DataToTransfer = 0; spock_log("Data Buffer write: length %d, pointer 0x%04X\n", scsi->data_len, scsi->data_ptr); if (!scsi->data_len) - return (0); + return 0; if (scb->enable & ENABLE_PT) { - for (i = 0; i < scsi->data_len; i += 8) { + for (uint32_t i = 0; i < scsi->data_len; i += 8) { spock_rd_sge(scsi, scsi->data_ptr + i, &scb->sge); DataToTransfer += scb->sge.sys_buf_byte_count; } - return (DataToTransfer); + return DataToTransfer; } else { return (scsi->data_len); } @@ -437,8 +448,11 @@ spock_get_len(spock_t *scsi, scb_t *scb) static void spock_process_imm_cmd(spock_t *scsi) { - int i, j = 0; - int adapter_id, phys_id, lun_id; + int i; + int j = 0; + int adapter_id; + int phys_id; + int lun_id; scsi->assign = 0; @@ -516,7 +530,8 @@ spock_process_imm_cmd(spock_t *scsi) static void spock_execute_cmd(spock_t *scsi, scb_t *scb) { - int c, j = 0; + int c; + int j = 0; int old_scb_state; if (scsi->in_reset) { @@ -794,6 +809,9 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) scsi->scsi_state = SCSI_STATE_SELECT; scsi->scb_state = 2; return; + + default: + break; } break; @@ -840,6 +858,9 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) spock_log("Complete SCB ID = %d.\n", scsi->attention & 0x0f); } break; + + default: + break; } } while (scsi->scb_state != old_scb_state); } @@ -847,7 +868,6 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) static void spock_process_scsi(spock_t *scsi, scb_t *scb) { - int c; double p; scsi_device_t *sd; @@ -910,7 +930,7 @@ spock_process_scsi(spock_t *scsi, scb_t *scb) uint32_t Address; if (scb->sge.sys_buf_byte_count > 0) { - for (c = 0; c < scsi->data_len; c += 8) { + for (uint32_t c = 0; c < scsi->data_len; c += 8) { spock_rd_sge(scsi, scsi->data_ptr + c, &scb->sge); Address = scb->sge.sys_buf_addr; @@ -998,6 +1018,9 @@ spock_callback(void *priv) case CMD_RESET: spock_process_imm_cmd(scsi); break; + + default: + break; } break; @@ -1022,6 +1045,9 @@ spock_callback(void *priv) scsi->irq_status = 0; spock_clear_irq(scsi, scsi->attention & 0x0f); break; + + default: + break; } } } @@ -1060,7 +1086,7 @@ spock_mca_write(int port, uint8_t val, void *priv) static uint8_t spock_mca_read(int port, void *priv) { - spock_t *scsi = (spock_t *) priv; + const spock_t *scsi = (spock_t *) priv; return scsi->pos_regs[port & 7]; } @@ -1068,7 +1094,7 @@ spock_mca_read(int port, void *priv) static uint8_t spock_mca_feedb(void *priv) { - spock_t *scsi = (spock_t *) priv; + const spock_t *scsi = (spock_t *) priv; return (scsi->pos_regs[2] & 0x01); } @@ -1077,7 +1103,6 @@ static void spock_mca_reset(void *priv) { spock_t *scsi = (spock_t *) priv; - int i; scsi->in_reset = 2; scsi->cmd_timer = SPOCK_TIME * 50; @@ -1089,16 +1114,15 @@ spock_mca_reset(void *priv) scsi->basic_ctrl = 0; /* Reset all devices on controller reset. */ - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { scsi_device_reset(&scsi_devices[scsi->bus][i]); scsi->present[i] = 0; } } static void * -spock_init(const device_t *info) +spock_init(UNUSED(const device_t *info)) { - int c; spock_t *scsi = malloc(sizeof(spock_t)); memset(scsi, 0x00, sizeof(spock_t)); @@ -1117,6 +1141,9 @@ spock_init(const device_t *info) rom_init_interleaved(&scsi->bios_rom, SPOCK_U68_1990_ROM, SPOCK_U69_1990_ROM, 0xc8000, 0x8000, 0x7fff, 0x4000, MEM_MAPPING_EXTERNAL); break; + + default: + break; } mem_mapping_disable(&scsi->bios_rom.mapping); @@ -1128,7 +1155,7 @@ spock_init(const device_t *info) scsi->cmd_timer = SPOCK_TIME * 50; scsi->status = STATUS_BUSY; - for (c = 0; c < (SCSI_ID_MAX - 1); c++) { + for (uint8_t c = 0; c < (SCSI_ID_MAX - 1); c++) { scsi->dev_id[c].phys_id = -1; } @@ -1142,9 +1169,9 @@ spock_init(const device_t *info) } static void -spock_close(void *p) +spock_close(void *priv) { - spock_t *scsi = (spock_t *) p; + spock_t *scsi = (spock_t *) priv; if (scsi) { free(scsi); diff --git a/src/scsi/scsi_x54x.c b/src/scsi/scsi_x54x.c index ae049d921..7a6923def 100644 --- a/src/scsi/scsi_x54x.c +++ b/src/scsi/scsi_x54x.c @@ -238,9 +238,12 @@ completion_code(uint8_t *sense) case ASC_MEDIUM_NOT_PRESENT: ret = 0xaa; break; - }; - return (ret); + default: + break; + } + + return ret; } static uint8_t @@ -256,7 +259,7 @@ x54x_bios_scsi_command(scsi_device_t *dev, uint8_t *cdb, uint8_t *buf, int len, if (len > 0) { if (dev->buffer_length == -1) { fatal("Buffer length -1 when doing SCSI DMA\n"); - return (0xff); + return 0xff; } if (dev->phase == SCSI_PHASE_DATA_IN) { @@ -292,7 +295,7 @@ x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf, int transfer_size) free(cdb); - return (ret); + return ret; } static uint8_t @@ -311,7 +314,7 @@ x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf, int transfer_size) free(cdb); - return (ret); + return ret; } static uint8_t @@ -327,7 +330,7 @@ x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer, int transfer_size) ret = x54x_bios_read_capacity(sd, rcbuf, transfer_size); if (ret) { free(rcbuf); - return (ret); + return ret; } memset(buffer, 0x00, 6); @@ -340,15 +343,15 @@ x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer, int transfer_size) free(rcbuf); - return (0); + return 0; } static int x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer, int transfer_size) { - uint8_t *inqbuf, *rcbuf; + uint8_t *inqbuf; + uint8_t *rcbuf; uint8_t ret; - int i; memset(buffer, 0x00, 6); @@ -356,7 +359,7 @@ x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer, int transfer_size) ret = x54x_bios_inquiry(sd, inqbuf, transfer_size); if (ret) { free(inqbuf); - return (ret); + return ret; } buffer[4] = inqbuf[0]; @@ -367,10 +370,10 @@ x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer, int transfer_size) if (ret) { free(rcbuf); free(inqbuf); - return (ret); + return ret; } - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) buffer[i] = rcbuf[i]; x54x_log("BIOS Command 0x15: %02X %02X %02X %02X %02X %02X\n", @@ -379,7 +382,7 @@ x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer, int transfer_size) free(rcbuf); free(inqbuf); - return (0); + return 0; } /* This returns the completion code. */ @@ -428,7 +431,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) if ((dev->type == SCSI_REMOVABLE_CDROM) && !(x54x->flags & X54X_CDROM_BOOT)) { x54x_log("BIOS Target ID %i is CD-ROM on unsupported BIOS\n", cmd->id); - return (0x80); + return 0x80; } else { dma_address = ADDR_TO_U32(cmd->dma_address); @@ -458,7 +461,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) dma_bm_write(dma_address, scsi_device_sense(dev), 14, x54x->transfer_size); } - return (0); + return 0; break; case 0x02: /* Read Desired Sectors to Memory */ @@ -483,6 +486,9 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) default: x54x_log("BIOS: Unimplemented command: %02X\n", cmd->command); +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x05: /* Format Track, invalid since SCSI has no tracks */ case 0x0a: /* ???? */ case 0x0b: /* ???? */ @@ -533,7 +539,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) } x54x_log("BIOS Request %02X complete: %02X\n", cmd->command, ret); - return (ret); + return ret; } static void @@ -583,8 +589,8 @@ x54x_mbi_setup(x54x_t *dev, uint32_t CCBPointer, CCBU *CmdBlock, static void x54x_ccb(x54x_t *dev) { - Req_t *req = &dev->Req; - uint8_t bytes[4] = { 0, 0, 0, 0 }; + const Req_t *req = &dev->Req; + uint8_t bytes[4] = { 0, 0, 0, 0 }; /* Rewrite the CCB up to the CDB. */ x54x_log("CCB completion code and statuses rewritten (pointer %08X)\n", req->CCBPointer); @@ -605,14 +611,16 @@ static void x54x_mbi(x54x_t *dev) { Req_t *req = &dev->Req; - // uint32_t CCBPointer = req->CCBPointer; - addr24 CCBPointer; - CCBU *CmdBlock = &(req->CmdBlock); - uint8_t HostStatus = req->HostStatus; - uint8_t TargetStatus = req->TargetStatus; - uint32_t MailboxCompletionCode = req->MailboxCompletionCode; - uint32_t Incoming; - uint8_t bytes[4] = { 0, 0, 0, 0 }; +#if 0 + uint32_t CCBPointer = req->CCBPointer; +#endif + addr24_t CCBPointer; + CCBU *CmdBlock = &(req->CmdBlock); + uint8_t HostStatus = req->HostStatus; + uint8_t TargetStatus = req->TargetStatus; + uint32_t MailboxCompletionCode = req->MailboxCompletionCode; + uint32_t Incoming; + uint8_t bytes[4] = { 0, 0, 0, 0 }; Incoming = dev->MailboxInAddr + (dev->MailboxInPosCur * ((dev->flags & X54X_MBX_24BIT) ? sizeof(Mailbox_t) : sizeof(Mailbox32_t))); @@ -675,7 +683,7 @@ x54x_rd_sge(x54x_t *dev, int Is24bit, uint32_t Address, SGE32 *SG) memcpy((uint8_t *) &SGE24, bytes, sizeof(SGE)); } else { /* 16-bit device, special handling not needed. */ - dma_bm_read(Address, (uint8_t *) &SGE24, 8, dev->transfer_size); + dma_bm_read(Address, (uint8_t *) &SGE24, 6, dev->transfer_size); } x54x_add_to_period(dev, sizeof(SGE)); @@ -692,10 +700,11 @@ x54x_rd_sge(x54x_t *dev, int Is24bit, uint32_t Address, SGE32 *SG) static int x54x_get_length(x54x_t *dev, Req_t *req, int Is24bit) { - uint32_t DataPointer, DataLength; + uint32_t DataPointer; + uint32_t DataLength; uint32_t SGEntryLength = (Is24bit ? sizeof(SGE) : sizeof(SGE32)); SGE32 SGBuffer; - uint32_t DataToTransfer = 0, i = 0; + uint32_t DataToTransfer = 0; if (Is24bit) { DataPointer = ADDR_TO_U32(req->CmdBlock.old.DataPointer); @@ -709,23 +718,23 @@ x54x_get_length(x54x_t *dev, Req_t *req, int Is24bit) DataLength, DataPointer); if (!DataLength) - return (0); + return 0; if (req->CmdBlock.common.ControlByte != 0x03) { if (req->CmdBlock.common.Opcode == SCATTER_GATHER_COMMAND || req->CmdBlock.common.Opcode == SCATTER_GATHER_COMMAND_RES) { - for (i = 0; i < DataLength; i += SGEntryLength) { + for (uint32_t i = 0; i < DataLength; i += SGEntryLength) { x54x_rd_sge(dev, Is24bit, DataPointer + i, &SGBuffer); DataToTransfer += SGBuffer.Segment; } - return (DataToTransfer); + return DataToTransfer; } else if (req->CmdBlock.common.Opcode == SCSI_INITIATOR_COMMAND || req->CmdBlock.common.Opcode == SCSI_INITIATOR_COMMAND_RES) { - return (DataLength); + return DataLength; } else { - return (0); + return 0; } } else { - return (0); + return 0; } } @@ -733,7 +742,7 @@ static void x54x_set_residue(x54x_t *dev, Req_t *req, int32_t TransferLength) { uint32_t Residue = 0; - addr24 Residue24; + addr24_t Residue24; int32_t BufLen = scsi_devices[dev->bus][req->TargetID].buffer_length; uint8_t bytes[4] = { 0, 0, 0, 0 }; @@ -763,9 +772,10 @@ x54x_set_residue(x54x_t *dev, Req_t *req, int32_t TransferLength) static void x54x_buf_dma_transfer(x54x_t *dev, Req_t *req, int Is24bit, int TransferLength, int dir) { - uint32_t DataPointer, DataLength; + uint32_t DataPointer; + uint32_t DataLength; uint32_t SGEntryLength = (Is24bit ? sizeof(SGE) : sizeof(SGE32)); - uint32_t Address, i; + uint32_t Address; int32_t BufLen = scsi_devices[dev->bus][req->TargetID].buffer_length; uint8_t read_from_host = (dir && ((req->CmdBlock.common.ControlByte == CCB_DATA_XFER_OUT) || (req->CmdBlock.common.ControlByte == 0x00))); uint8_t write_to_host = (!dir && ((req->CmdBlock.common.ControlByte == CCB_DATA_XFER_IN) || (req->CmdBlock.common.ControlByte == 0x00))); @@ -789,7 +799,7 @@ x54x_buf_dma_transfer(x54x_t *dev, Req_t *req, int Is24bit, int TransferLength, /* If the control byte is 0x00, it means that the transfer direction is set up by the SCSI command without checking its length, so do this procedure for both no read/write commands. */ if ((DataLength > 0) && (req->CmdBlock.common.ControlByte < 0x03)) { - for (i = 0; i < DataLength; i += SGEntryLength) { + for (uint32_t i = 0; i < DataLength; i += SGEntryLength) { x54x_rd_sge(dev, Is24bit, DataPointer + i, &SGBuffer); Address = SGBuffer.SegmentPointer; @@ -838,7 +848,7 @@ ConvertSenseLength(uint8_t RequestSenseLength) x54x_log("Request Sense length %i\n", RequestSenseLength); - return (RequestSenseLength); + return RequestSenseLength; } uint32_t @@ -852,7 +862,7 @@ SenseBufferPointer(Req_t *req) SenseBufferAddress = req->CmdBlock.new.SensePointer; } - return (SenseBufferAddress); + return SenseBufferAddress; } static void @@ -888,7 +898,7 @@ x54x_scsi_cmd(x54x_t *dev) { Req_t *req = &dev->Req; uint8_t bit24 = !!req->Is24bit; - uint32_t i, target_cdb_len = 12; + uint32_t target_cdb_len = 12; scsi_device_t *sd; sd = &scsi_devices[dev->bus][req->TargetID]; @@ -904,7 +914,7 @@ x54x_scsi_cmd(x54x_t *dev) x54x_log("SCSI command being executed on ID %i, LUN %i\n", req->TargetID, req->LUN); x54x_log("SCSI CDB[0]=0x%02X\n", req->CmdBlock.common.Cdb[0]); - for (i = 1; i < req->CmdBlock.common.CdbLength; i++) + for (uint8_t i = 1; i < req->CmdBlock.common.CdbLength; i++) x54x_log("SCSI CDB[%i]=%i\n", i, req->CmdBlock.common.Cdb[i]); memset(dev->temp_cdb, 0x00, target_cdb_len); @@ -1015,7 +1025,7 @@ x54x_mbo_free(x54x_t *dev) static void x54x_notify(x54x_t *dev) { - Req_t *req = &dev->Req; + const Req_t *req = &dev->Req; scsi_device_t *sd; sd = &scsi_devices[dev->bus][req->TargetID]; @@ -1033,10 +1043,11 @@ x54x_notify(x54x_t *dev) } static void -x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) +x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, UNUSED(Mailbox32_t *Mailbox32)) { Req_t *req = &dev->Req; - uint8_t id, lun; + uint8_t id; + uint8_t lun; scsi_device_t *sd; /* Fetch data from the Command Control Block. */ @@ -1141,7 +1152,7 @@ x54x_mbo(x54x_t *dev, Mailbox32_t *Mailbox32) x54x_add_to_period(dev, sizeof(Mailbox32_t)); } - return (Outgoing); + return Outgoing; } uint8_t @@ -1158,9 +1169,11 @@ x54x_mbo_process(x54x_t *dev) } else if (!dev->MailboxIsBIOS && (mb32.u.out.ActionCode == MBO_ABORT)) { x54x_log("Abort Mailbox Command\n"); x54x_req_abort(dev, mb32.CCBPointer); - } /* else { +#if 0 + } else { x54x_log("Invalid action code: %02X\n", mb32.u.out.ActionCode); - } */ +#endif + } if ((mb32.u.out.ActionCode == MBO_START) || (!dev->MailboxIsBIOS && (mb32.u.out.ActionCode == MBO_ABORT))) { /* We got the mailbox, decrease the number of pending requests. */ @@ -1169,10 +1182,10 @@ x54x_mbo_process(x54x_t *dev) else dev->MailboxReq--; - return (1); + return 1; } - return (0); + return 0; } static void @@ -1218,7 +1231,8 @@ x54x_cmd_callback(void *priv) double period; x54x_t *dev = (x54x_t *) priv; - int mailboxes_present, bios_mailboxes_present; + int mailboxes_present; + int bios_mailboxes_present; mailboxes_present = (!(dev->Status & STAT_INIT) && dev->MailboxInit && dev->MailboxReq); bios_mailboxes_present = (dev->ven_callback && dev->BIOSMailboxInit && dev->BIOSMailboxReq); @@ -1278,7 +1292,9 @@ x54x_cmd_callback(void *priv) period = (1000000.0 / dev->ha_bps) * ((double) dev->temp_period); timer_on(&dev->timer, dev->media_period + period + 10.0, 0); - // x54x_log("Temporary period: %lf us (%" PRIi64 " periods)\n", dev->timer.period, dev->temp_period); +#if 0 + x54x_log("Temporary period: %lf us (%" PRIi64 " periods)\n", dev->timer.period, dev->temp_period); +#endif } static uint8_t @@ -1288,8 +1304,8 @@ x54x_in(uint16_t port, void *priv) uint8_t ret; switch (port & 3) { - case 0: default: + case 0: ret = dev->Status; break; @@ -1325,8 +1341,8 @@ x54x_in(uint16_t port, void *priv) ret = dev->Geometry; else { switch (dev->Geometry) { - case 0: default: + case 0: ret = 'A'; break; case 1: @@ -1354,7 +1370,7 @@ x54x_in(uint16_t port, void *priv) x54x_log("x54x_in(): %04X, %02X\n", port, ret); #endif - return (ret); + return ret; } static uint16_t @@ -1398,8 +1414,6 @@ x54x_reset_poll(void *priv) static void x54x_reset(x54x_t *dev) { - int i; - clear_irq(dev); if (dev->flags & X54X_INT_GEOM_WRITABLE) dev->Geometry = 0x90; @@ -1421,7 +1435,7 @@ x54x_reset(x54x_t *dev) dev->MailboxOutPosCur = 0; /* Reset all devices on controller reset. */ - for (i = 0; i < 16; i++) + for (uint8_t i = 0; i < 16; i++) scsi_device_reset(&scsi_devices[dev->bus][i]); if (dev->ven_reset) @@ -1457,7 +1471,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) int suppress = 0; uint32_t FIFOBuf; uint8_t reset; - addr24 Address; + addr24_t Address; uint8_t host_id = dev->HostID; uint8_t irq = 0; @@ -1878,7 +1892,7 @@ x54x_init(const device_t *info) /* Allocate control block and set up basic stuff. */ dev = malloc(sizeof(x54x_t)); if (dev == NULL) - return (dev); + return dev; memset(dev, 0x00, sizeof(x54x_t)); dev->type = info->local; @@ -1895,7 +1909,7 @@ x54x_init(const device_t *info) else dev->transfer_size = 2; - return (dev); + return dev; } void diff --git a/src/sio/sio_82091aa.c b/src/sio/sio_82091aa.c index 52a8809e9..346d2d435 100644 --- a/src/sio/sio_82091aa.c +++ b/src/sio/sio_82091aa.c @@ -35,9 +35,10 @@ #include <86box/fdc.h> #include <86box/sio.h> -typedef struct { - uint8_t cur_reg, has_ide, - regs[81]; +typedef struct i82091aa_t { + uint8_t cur_reg; + uint8_t has_ide; + uint8_t regs[81]; uint16_t base_address; fdc_t *fdc; serial_t *uart[2]; @@ -71,6 +72,9 @@ lpt1_handler(i82091aa_t *dev) case 3: lpt_port = 0x000; break; + + default: + break; } if ((dev->regs[0x20] & 0x01) && lpt_port) @@ -112,6 +116,9 @@ serial_handler(i82091aa_t *dev, int uart) case 0x07: uart_port = COM3_ADDR; break; + + default: + break; } if (dev->regs[reg] & 0x01) @@ -134,7 +141,8 @@ static void i82091aa_write(uint16_t port, uint8_t val, void *priv) { i82091aa_t *dev = (i82091aa_t *) priv; - uint8_t index, valxor; + uint8_t index; + uint8_t valxor = 0; uint8_t uart = (dev->cur_reg >> 4) - 0x03; uint8_t *reg = &(dev->regs[dev->cur_reg]); @@ -192,6 +200,9 @@ i82091aa_write(uint16_t port, uint8_t val, void *priv) if (dev->has_ide && (valxor & 0x03)) ide_handler(dev); break; + + default: + break; } } @@ -199,7 +210,8 @@ uint8_t i82091aa_read(uint16_t port, void *priv) { i82091aa_t *dev = (i82091aa_t *) priv; - uint8_t ret = 0xff, index; + uint8_t ret = 0xff; + uint8_t index; index = (port & 1) ? 0 : 1; diff --git a/src/sio/sio_acc3221.c b/src/sio/sio_acc3221.c index f5c671c3a..10250d602 100644 --- a/src/sio/sio_acc3221.c +++ b/src/sio/sio_acc3221.c @@ -31,6 +31,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> typedef struct acc3221_t { int reg_idx; @@ -344,9 +345,9 @@ acc3221_serial2_handler(acc3221_t *dev) } static void -acc3221_write(uint16_t addr, uint8_t val, void *p) +acc3221_write(uint16_t addr, uint8_t val, void *priv) { - acc3221_t *dev = (acc3221_t *) p; + acc3221_t *dev = (acc3221_t *) priv; uint8_t old; if (!(addr & 1)) @@ -405,14 +406,17 @@ acc3221_write(uint16_t addr, uint8_t val, void *p) ide_pri_enable(); } break; + + default: + break; } } } static uint8_t -acc3221_read(uint16_t addr, void *p) +acc3221_read(uint16_t addr, void *priv) { - acc3221_t *dev = (acc3221_t *) p; + acc3221_t *dev = (acc3221_t *) priv; if (!(addr & 1)) return dev->reg_idx; @@ -448,7 +452,7 @@ acc3221_close(void *priv) } static void * -acc3221_init(const device_t *info) +acc3221_init(UNUSED(const device_t *info)) { acc3221_t *dev = (acc3221_t *) malloc(sizeof(acc3221_t)); memset(dev, 0, sizeof(acc3221_t)); diff --git a/src/sio/sio_ali5123.c b/src/sio/sio_ali5123.c index 33e4022c6..25fb1aa65 100644 --- a/src/sio/sio_ali5123.c +++ b/src/sio/sio_ali5123.c @@ -37,13 +37,14 @@ #define AB_RST 0x80 -typedef struct { - uint8_t chip_id, is_apm, - tries, - regs[48], - ld_regs[13][256]; - int locked, - cur_reg; +typedef struct ali5123_t { + uint8_t chip_id; + uint8_t is_apm; + uint8_t tries; + uint8_t regs[48]; + uint8_t ld_regs[13][256]; + int locked; + int cur_reg; fdc_t *fdc; serial_t *uart[3]; } ali5123_t; @@ -125,21 +126,22 @@ ali5123_serial_handler(ali5123_t *dev, int uart) case 0x05: serial_set_clock_src(dev->uart[uart], 2000000.0); break; + + default: + break; } } static void ali5123_reset(ali5123_t *dev) { - int i = 0; - memset(dev->regs, 0, 48); dev->regs[0x20] = 0x43; dev->regs[0x21] = 0x15; dev->regs[0x2d] = 0x20; - for (i = 0; i < 13; i++) + for (uint8_t i = 0; i < 13; i++) memset(dev->ld_regs[i], 0, 256); /* Logical device 0: FDD */ @@ -174,6 +176,7 @@ ali5123_reset(ali5123_t *dev) serial_setup(dev->uart[1], 0x03e8, dev->ld_regs[5][0x70]); /* Logical device 7: Keyboard */ + dev->ld_regs[7][0x30] = 1; dev->ld_regs[7][0x70] = 1; /* TODO: Register F0 bit 6: 0 = PS/2, 1 = AT */ @@ -208,7 +211,8 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) { ali5123_t *dev = (ali5123_t *) priv; uint8_t index = (port & 1) ? 0 : 1; - uint8_t valxor = 0x00, cur_ld = dev->regs[7]; + uint8_t valxor = 0x00; + uint8_t cur_ld = dev->regs[7]; if (index) { if (((val == 0x51) && (!dev->tries) && (!dev->locked)) || ((val == 0x23) && (dev->tries) && (!dev->locked))) { @@ -253,6 +257,13 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) case 0x06: case 0x08 ... 0x0a: return; + case 0x07: + if (dev->cur_reg == 0xf0) + val &= 0xbf; + break; + + default: + break; } dev->ld_regs[cur_ld][dev->cur_reg] = val; } @@ -285,6 +296,9 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) ali5123_serial_handler(dev, 2); } break; + + default: + break; } return; @@ -329,6 +343,9 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x08) fdc_update_drvrate(dev->fdc, 3, (val & 0x08) >> 3); break; + + default: + break; } break; case 3: @@ -343,6 +360,9 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) if (valxor) ali5123_lpt_handler(dev); break; + + default: + break; } break; case 4: @@ -358,6 +378,9 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) if (valxor) ali5123_serial_handler(dev, 0); break; + + default: + break; } break; case 5: @@ -373,6 +396,9 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) if (valxor) ali5123_serial_handler(dev, (dev->regs[0x2d] & 0x20) ? 2 : 1); break; + + default: + break; } break; case 0x0b: @@ -388,8 +414,14 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) if (valxor) ali5123_serial_handler(dev, (dev->regs[0x2d] & 0x20) ? 1 : 2); break; + + default: + break; } break; + + default: + break; } } @@ -398,7 +430,8 @@ ali5123_read(uint16_t port, void *priv) { ali5123_t *dev = (ali5123_t *) priv; uint8_t index = (port & 1) ? 0 : 1; - uint8_t ret = 0xff, cur_ld; + uint8_t ret = 0xff; + uint8_t cur_ld; if (dev->locked) { if (index) diff --git a/src/sio/sio_detect.c b/src/sio/sio_detect.c index 36c12cd54..01c41224a 100644 --- a/src/sio/sio_detect.c +++ b/src/sio/sio_detect.c @@ -26,8 +26,9 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct sio_detect_t { uint8_t regs[2]; } sio_detect_t; @@ -62,7 +63,7 @@ sio_detect_close(void *priv) } static void * -sio_detect_init(const device_t *info) +sio_detect_init(UNUSED(const device_t *info)) { sio_detect_t *dev = (sio_detect_t *) malloc(sizeof(sio_detect_t)); memset(dev, 0, sizeof(sio_detect_t)); diff --git a/src/sio/sio_f82c710.c b/src/sio/sio_f82c710.c index ad347fb03..fc0eb2aae 100644 --- a/src/sio/sio_f82c710.c +++ b/src/sio/sio_f82c710.c @@ -151,6 +151,9 @@ f82c606_update_ports(upc_t *dev, int set) case 0xc0: uart2_int = COM2_IRQ; break; + + default: + break; } switch (dev->regs[8] & 0x30) { @@ -163,6 +166,9 @@ f82c606_update_ports(upc_t *dev, int set) case 0x30: uart2_int = COM1_IRQ; break; + + default: + break; } switch (dev->regs[8] & 0x0c) { @@ -175,6 +181,9 @@ f82c606_update_ports(upc_t *dev, int set) case 0x0c: lpt1_int = LPT2_IRQ; break; + + default: + break; } switch (dev->regs[8] & 0x03) { @@ -187,6 +196,9 @@ f82c606_update_ports(upc_t *dev, int set) case 0x03: lpt1_int = LPT1_IRQ; break; + + default: + break; } if (dev->regs[0] & 1) { diff --git a/src/sio/sio_fdc37c669.c b/src/sio/sio_fdc37c669.c index 219213d69..3a1bcf5af 100644 --- a/src/sio/sio_fdc37c669.c +++ b/src/sio/sio_fdc37c669.c @@ -32,11 +32,13 @@ #include <86box/fdc.h> #include <86box/sio.h> -typedef struct { - uint8_t id, tries, - regs[42]; - int locked, rw_locked, - cur_reg; +typedef struct fdc37c669_t { + uint8_t id; + uint8_t tries; + uint8_t regs[42]; + int locked; + int rw_locked; + int cur_reg; fdc_t *fdc; serial_t *uart[2]; } fdc37c669_t; @@ -62,6 +64,9 @@ make_port(fdc37c669_t *dev, uint8_t reg) case 0x25: mask = 0xfe; break; + + default: + break; } p = ((uint16_t) (dev->regs[reg] & mask)) << 2; @@ -217,6 +222,9 @@ fdc37c669_write(uint16_t port, uint8_t val, void *priv) serial_setup(dev->uart[0], make_port(dev, 0x24), (dev->regs[0x28] & 0xf0) >> 4); } break; + + default: + break; } } diff --git a/src/sio/sio_fdc37c67x.c b/src/sio/sio_fdc37c67x.c index af8a89bf5..3cfa5a38d 100644 --- a/src/sio/sio_fdc37c67x.c +++ b/src/sio/sio_fdc37c67x.c @@ -33,19 +33,23 @@ #include <86box/fdc.h> #include "cpu.h" #include <86box/sio.h> +#include <86box/plat_unused.h> #define AB_RST 0x80 -typedef struct { - uint8_t chip_id, is_apm, - tries, - gpio_regs[2], auxio_reg, - regs[48], - ld_regs[11][256]; - uint16_t gpio_base, /* Set to EA */ - auxio_base, sio_base; - int locked, - cur_reg; +typedef struct fdc37c67x_t { + uint8_t chip_id; + uint8_t is_apm; + uint8_t tries; + uint8_t gpio_regs[2]; + uint8_t auxio_reg; + uint8_t regs[48]; + uint8_t ld_regs[11][256]; + uint16_t gpio_base; /* Set to EA */ + uint16_t auxio_base; + uint16_t sio_base; + int locked; + int cur_reg; fdc_t *fdc; serial_t *uart[2]; } fdc37c67x_t; @@ -65,7 +69,7 @@ make_port(fdc37c67x_t *dev, uint8_t ld) } static uint8_t -fdc37c67x_auxio_read(uint16_t port, void *priv) +fdc37c67x_auxio_read(UNUSED(uint16_t port), void *priv) { fdc37c67x_t *dev = (fdc37c67x_t *) priv; @@ -73,7 +77,7 @@ fdc37c67x_auxio_read(uint16_t port, void *priv) } static void -fdc37c67x_auxio_write(uint16_t port, uint8_t val, void *priv) +fdc37c67x_auxio_write(UNUSED(uint16_t port), uint8_t val, void *priv) { fdc37c67x_t *dev = (fdc37c67x_t *) priv; @@ -168,7 +172,7 @@ fdc37c67x_auxio_handler(fdc37c67x_t *dev) } static void -fdc37c67x_sio_handler(fdc37c67x_t *dev) +fdc37c67x_sio_handler(UNUSED(fdc37c67x_t *dev)) { #if 0 if (dev->sio_base) { @@ -207,6 +211,9 @@ fdc37c67x_gpio_handler(fdc37c67x_t *dev) case 3: ld_port = 0xea; /* Default */ break; + + default: + break; } dev->gpio_base = ld_port; if (ld_port > 0x0000) @@ -234,7 +241,8 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) { fdc37c67x_t *dev = (fdc37c67x_t *) priv; uint8_t index = (port & 1) ? 0 : 1; - uint8_t valxor = 0x00, keep = 0x00; + uint8_t valxor = 0x00; + uint8_t keep = 0x00; if (index) { if ((val == 0x55) && !dev->locked) { @@ -278,6 +286,9 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) case 0x02: case 0x07: return; + + default: + break; } dev->ld_regs[dev->regs[7]][dev->cur_reg] = val | keep; } @@ -305,6 +316,9 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) case 0x26: case 0x27: fdc37c67x_sio_handler(dev); + + default: + break; } return; @@ -358,6 +372,9 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x18) fdc_update_drvrate(dev->fdc, 3, (val & 0x18) >> 3); break; + + default: + break; } break; case 3: @@ -374,6 +391,9 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) if (dev->cur_reg == 0x70) fdc37c67x_smi_handler(dev); break; + + default: + break; } break; case 4: @@ -390,6 +410,9 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) if (dev->cur_reg == 0x70) fdc37c67x_smi_handler(dev); break; + + default: + break; } break; case 5: @@ -406,6 +429,9 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) if (dev->cur_reg == 0x70) fdc37c67x_smi_handler(dev); break; + + default: + break; } break; case 8: @@ -422,8 +448,14 @@ fdc37c67x_write(uint16_t port, uint8_t val, void *priv) case 0xb5: fdc37c67x_smi_handler(dev); break; + + default: + break; } break; + + default: + break; } } @@ -477,8 +509,6 @@ fdc37c67x_read(uint16_t port, void *priv) static void fdc37c67x_reset(fdc37c67x_t *dev) { - int i = 0; - memset(dev->regs, 0, 48); dev->regs[0x03] = 0x03; @@ -488,7 +518,7 @@ fdc37c67x_reset(fdc37c67x_t *dev) dev->regs[0x26] = 0xf0; dev->regs[0x27] = 0x03; - for (i = 0; i < 11; i++) + for (uint8_t i = 0; i < 11; i++) memset(dev->ld_regs[i], 0, 256); /* Logical device 0: FDD */ @@ -571,7 +601,9 @@ fdc37c67x_init(const device_t *info) dev->chip_id = info->local & 0xff; dev->gpio_regs[0] = 0xff; - // dev->gpio_regs[1] = (info->local == 0x0030) ? 0xff : 0xfd; +#if 0 + dev->gpio_regs[1] = (info->local == 0x0030) ? 0xff : 0xfd; +#endif dev->gpio_regs[1] = (dev->chip_id == 0x30) ? 0xff : 0xfd; fdc37c67x_reset(dev); diff --git a/src/sio/sio_fdc37c6xx.c b/src/sio/sio_fdc37c6xx.c index 8400ca1e0..10eccf97c 100644 --- a/src/sio/sio_fdc37c6xx.c +++ b/src/sio/sio_fdc37c6xx.c @@ -35,12 +35,15 @@ #include <86box/fdc.h> #include <86box/sio.h> -typedef struct { - uint8_t max_reg, chip_id, - tries, has_ide, - regs[16]; - int cur_reg, - com3_addr, com4_addr; +typedef struct fdc37c6xx_t { + uint8_t max_reg; + uint8_t chip_id; + uint8_t tries; + uint8_t has_ide; + uint8_t regs[16]; + int cur_reg; + int com3_addr; + int com4_addr; fdc_t *fdc; serial_t *uart[2]; } fdc37c6xx_t; @@ -65,6 +68,9 @@ set_com34_addr(fdc37c6xx_t *dev) dev->com3_addr = 0x220; dev->com4_addr = 0x228; break; + + default: + break; } } @@ -92,6 +98,9 @@ set_serial_addr(fdc37c6xx_t *dev, int port) case 3: serial_setup(dev->uart[port], dev->com4_addr, COM4_IRQ); break; + + default: + break; } } @@ -115,6 +124,9 @@ lpt1_handler(fdc37c6xx_t *dev) lpt1_init(LPT2_ADDR); lpt1_irq(7 /*5*/); break; + + default: + break; } } @@ -206,6 +218,9 @@ fdc37c6xx_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x20) fdc_set_swap(dev->fdc, (dev->regs[5] & 0x20) >> 5); break; + + default: + break; } } } else if ((port == FDC_PRIMARY_ADDR) && (val == 0x55)) diff --git a/src/sio/sio_fdc37c93x.c b/src/sio/sio_fdc37c93x.c index 110289f1f..0330297fb 100644 --- a/src/sio/sio_fdc37c93x.c +++ b/src/sio/sio_fdc37c93x.c @@ -35,10 +35,11 @@ #include <86box/apm.h> #include <86box/acpi.h> #include <86box/sio.h> +#include <86box/plat_unused.h> #define AB_RST 0x80 -typedef struct { +typedef struct access_bus_t { uint8_t control; uint8_t status; uint8_t own_addr; @@ -47,16 +48,19 @@ typedef struct { uint16_t base; } access_bus_t; -typedef struct { - uint8_t chip_id, is_apm, - tries, - gpio_regs[2], auxio_reg, - regs[48], - ld_regs[11][256]; - uint16_t gpio_base, /* Set to EA */ - auxio_base, nvr_sec_base; - int locked, - cur_reg; +typedef struct fdc37c93x_t { + uint8_t chip_id; + uint8_t is_apm; + uint8_t tries; + uint8_t gpio_regs[2]; + uint8_t auxio_reg; + uint8_t regs[48]; + uint8_t ld_regs[11][256]; + uint16_t gpio_base; /* Set to EA */ + uint16_t auxio_base; + uint16_t nvr_sec_base; + int locked; + int cur_reg; fdc_t *fdc; serial_t *uart[2]; access_bus_t *access_bus; @@ -87,7 +91,7 @@ make_port_sec(fdc37c93x_t *dev, uint8_t ld) } static uint8_t -fdc37c93x_auxio_read(uint16_t port, void *priv) +fdc37c93x_auxio_read(UNUSED(uint16_t port), void *priv) { fdc37c93x_t *dev = (fdc37c93x_t *) priv; @@ -95,7 +99,7 @@ fdc37c93x_auxio_read(uint16_t port, void *priv) } static void -fdc37c93x_auxio_write(uint16_t port, uint8_t val, void *priv) +fdc37c93x_auxio_write(UNUSED(uint16_t port), uint8_t val, void *priv) { fdc37c93x_t *dev = (fdc37c93x_t *) priv; @@ -239,6 +243,9 @@ fdc37c93x_gpio_handler(fdc37c93x_t *dev) case 3: ld_port = 0xea; /* Default */ break; + + default: + break; } dev->gpio_base = ld_port; if (ld_port > 0x0000) @@ -266,6 +273,9 @@ fdc37c93x_access_bus_read(uint16_t port, void *priv) case 3: ret = (dev->clock & 0x87); break; + + default: + break; } return ret; @@ -290,6 +300,9 @@ fdc37c93x_access_bus_write(uint16_t port, uint8_t val, void *priv) dev->clock &= 0x80; dev->clock |= (val & 0x07); break; + + default: + break; } } @@ -339,7 +352,8 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) { fdc37c93x_t *dev = (fdc37c93x_t *) priv; uint8_t index = (port & 1) ? 0 : 1; - uint8_t valxor = 0x00, keep = 0x00; + uint8_t valxor = 0x00; + uint8_t keep = 0x00; /* Compaq Presario 4500: Unlock at FB, Register at EA, Data at EB, Lock at F9. */ if ((port == 0xea) || (port == 0xf9) || (port == 0xfb)) @@ -409,6 +423,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (!dev->is_apm) return; break; + + default: + break; } dev->ld_regs[dev->regs[7]][dev->cur_reg] = val | keep; } @@ -435,6 +452,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if ((valxor & 0x40) && (dev->chip_id != 0x02)) fdc37c93x_access_bus_handler(dev); break; + + default: + break; } return; @@ -488,6 +508,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x18) fdc_update_drvrate(dev->fdc, 3, (val & 0x18) >> 3); break; + + default: + break; } break; case 3: @@ -502,6 +525,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (valxor) fdc37c93x_lpt_handler(dev); break; + + default: + break; } break; case 4: @@ -516,6 +542,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (valxor) fdc37c93x_serial_handler(dev, 0); break; + + default: + break; } break; case 5: @@ -530,6 +559,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (valxor) fdc37c93x_serial_handler(dev, 1); break; + + default: + break; } break; case 6: @@ -553,8 +585,8 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) nvr_lock_set(0xe0, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x08), dev->nvr); if (dev->ld_regs[6][dev->cur_reg] & 0x80) switch ((dev->ld_regs[6][dev->cur_reg] >> 4) & 0x07) { - case 0x00: default: + case 0x00: nvr_bank_set(0, 0xff, dev->nvr); nvr_bank_set(1, 1, dev->nvr); break; @@ -587,6 +619,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) } } break; + + default: + break; } break; case 8: @@ -599,6 +634,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (valxor) fdc37c93x_auxio_handler(dev); break; + + default: + break; } break; case 9: @@ -613,6 +651,9 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (valxor) fdc37c93x_access_bus_handler(dev); break; + + default: + break; } break; case 10: @@ -627,8 +668,14 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) if (valxor) fdc37c93x_acpi_handler(dev); break; + + default: + break; } break; + + default: + break; } } @@ -669,8 +716,6 @@ fdc37c93x_read(uint16_t port, void *priv) static void fdc37c93x_reset(fdc37c93x_t *dev) { - int i = 0; - memset(dev->regs, 0, 48); dev->regs[0x03] = 0x03; @@ -681,7 +726,7 @@ fdc37c93x_reset(fdc37c93x_t *dev) dev->regs[0x26] = 0xF0; dev->regs[0x27] = 0x03; - for (i = 0; i < 11; i++) + for (uint8_t i = 0; i < 11; i++) memset(dev->ld_regs[i], 0, 256); /* Logical device 0: FDD */ @@ -784,7 +829,7 @@ access_bus_close(void *priv) } static void * -access_bus_init(const device_t *info) +access_bus_init(UNUSED(const device_t *info)) { access_bus_t *dev = (access_bus_t *) malloc(sizeof(access_bus_t)); memset(dev, 0, sizeof(access_bus_t)); @@ -831,7 +876,9 @@ fdc37c93x_init(const device_t *info) is_compaq = (info->local >> 8) & 0x02; dev->gpio_regs[0] = 0xff; - // dev->gpio_regs[1] = (info->local == 0x0030) ? 0xff : 0xfd; +#if 0 + dev->gpio_regs[1] = (info->local == 0x0030) ? 0xff : 0xfd; +#endif dev->gpio_regs[1] = (dev->chip_id == 0x30) ? 0xff : 0xfd; if (dev->chip_id == 0x30) { diff --git a/src/sio/sio_fdc37m60x.c b/src/sio/sio_fdc37m60x.c index e29734c51..190e65453 100644 --- a/src/sio/sio_fdc37m60x.c +++ b/src/sio/sio_fdc37m60x.c @@ -68,9 +68,12 @@ fdc37m60x_log(const char *fmt, ...) # define fdc37m60x_log(fmt, ...) #endif -typedef struct -{ - uint8_t index, regs[256], device_regs[10][256], cfg_lock, ide_function; +typedef struct fdc37m60x_t { + uint8_t index; + uint8_t regs[256]; + uint8_t device_regs[10][256]; + uint8_t cfg_lock; + uint8_t ide_function; uint16_t sio_index_port; fdc_t *fdc; @@ -141,6 +144,9 @@ fdc37m60x_write(uint16_t addr, uint8_t val, void *priv) dev->device_regs[CURRENT_LOGICAL_DEVICE][INDEX] = (INDEX == 0x30) ? (val & 1) : val; fdc37m60x_logical_device_handler(dev); break; + + default: + break; } } } else { @@ -242,6 +248,9 @@ fdc37m60x_logical_device_handler(fdc37m60x_t *dev) case 0x05: fdc37m60x_uart_handler(1, dev); break; + + default: + break; } } @@ -249,10 +258,9 @@ static void fdc37m60x_reset(void *priv) { fdc37m60x_t *dev = (fdc37m60x_t *) priv; - uint8_t i; memset(dev->regs, 0, sizeof(dev->regs)); - for (i = 0; i < 10; i++) + for (uint8_t i = 0; i < 10; i++) memset(dev->device_regs[i], 0, sizeof(dev->device_regs[i])); dev->regs[0x20] = 0x47; diff --git a/src/sio/sio_it8661f.c b/src/sio/sio_it8661f.c index c7d4110be..5e5ccb655 100644 --- a/src/sio/sio_it8661f.c +++ b/src/sio/sio_it8661f.c @@ -32,16 +32,19 @@ #include <86box/fdc.h> #include <86box/fdd_common.h> #include <86box/sio.h> +#include <86box/plat_unused.h> #define LDN dev->regs[7] -typedef struct -{ +typedef struct it8661f_t { fdc_t *fdc_controller; serial_t *uart[2]; - uint8_t index, regs[256], device_regs[6][256]; - int unlocked, enumerator; + uint8_t index; + uint8_t regs[256]; + uint8_t device_regs[6][256]; + int unlocked; + int enumerator; } it8661f_t; static uint8_t mb_pnp_key[32] = { 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b, 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74, 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 }; @@ -99,6 +102,9 @@ it8661_fdc(uint16_t addr, uint8_t val, it8661f_t *dev) case 0xf0: dev->device_regs[0][addr] = val & 0x0f; break; + + default: + break; } fdc_set_base(dev->fdc_controller, (dev->device_regs[0][0x60] << 8) | (dev->device_regs[0][0x61])); @@ -140,6 +146,9 @@ it8661_serial(int uart, uint16_t addr, uint8_t val, it8661f_t *dev) case 0xf0: dev->device_regs[1 + uart][addr] = val & 3; break; + + default: + break; } serial_setup(dev->uart[uart], (dev->device_regs[1 + uart][0x60] << 8) | (dev->device_regs[1 + uart][0x61]), dev->device_regs[1 + uart][0x70] & 0x0f); @@ -177,6 +186,9 @@ it8661_lpt(uint16_t addr, uint8_t val, it8661f_t *dev) case 0xf0: dev->device_regs[3][addr] = val & 3; break; + + default: + break; } lpt1_init((dev->device_regs[3][0x60] << 8) | (dev->device_regs[3][0x61])); @@ -196,11 +208,14 @@ it8661_ldn(uint16_t addr, uint8_t val, it8661f_t *dev) break; case 1: case 2: - it8661_serial(LDN & 2, addr, val, dev); + it8661_serial((LDN & 2) - 1, addr, val, dev); break; case 3: it8661_lpt(addr, val, dev); break; + + default: + break; } } @@ -246,6 +261,9 @@ it8661f_write(uint16_t addr, uint8_t val, void *priv) } } break; + + default: + break; } return; @@ -300,7 +318,7 @@ it8661f_close(void *priv) } static void * -it8661f_init(const device_t *info) +it8661f_init(UNUSED(const device_t *info)) { it8661f_t *dev = (it8661f_t *) malloc(sizeof(it8661f_t)); memset(dev, 0, sizeof(it8661f_t)); diff --git a/src/sio/sio_pc87306.c b/src/sio/sio_pc87306.c index 8755775de..656b36d92 100644 --- a/src/sio/sio_pc87306.c +++ b/src/sio/sio_pc87306.c @@ -34,10 +34,12 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> -typedef struct { - uint8_t tries, - regs[29], gpio[2]; +typedef struct pc87306_t { + uint8_t tries; + uint8_t regs[29]; + uint8_t gpio[2]; int cur_reg; fdc_t *fdc; serial_t *uart[2]; @@ -85,7 +87,8 @@ static void lpt1_handler(pc87306_t *dev) { int temp; - uint16_t lptba, lpt_port = LPT1_ADDR; + uint16_t lptba; + uint16_t lpt_port = LPT1_ADDR; uint8_t lpt_irq = LPT2_IRQ; temp = dev->regs[0x01] & 3; @@ -111,6 +114,9 @@ lpt1_handler(pc87306_t *dev) lpt_port = 0x000; lpt_irq = 0xff; break; + + default: + break; } if (dev->regs[0x1b] & 0x10) @@ -126,8 +132,10 @@ static void serial_handler(pc87306_t *dev, int uart) { int temp; - uint8_t fer_irq, pnp1_irq; - uint8_t fer_shift, pnp_shift; + uint8_t fer_irq; + uint8_t pnp1_irq; + uint8_t fer_shift; + uint8_t pnp_shift; uint8_t irq; temp = (dev->regs[1] >> (2 << uart)) & 3; @@ -162,6 +170,9 @@ serial_handler(pc87306_t *dev, int uart) case 3: serial_setup(dev->uart[uart], 0x220, irq); break; + + default: + break; } break; case 3: @@ -178,8 +189,14 @@ serial_handler(pc87306_t *dev, int uart) case 3: serial_setup(dev->uart[uart], 0x228, irq); break; + + default: + break; } break; + + default: + break; } } @@ -187,7 +204,8 @@ static void pc87306_write(uint16_t port, uint8_t val, void *priv) { pc87306_t *dev = (pc87306_t *) priv; - uint8_t index, valxor; + uint8_t index; + uint8_t valxor; index = (port & 1) ? 0 : 1; @@ -320,6 +338,9 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) serial_handler(dev, 1); } break; + + default: + break; } } @@ -327,7 +348,8 @@ uint8_t pc87306_read(uint16_t port, void *priv) { pc87306_t *dev = (pc87306_t *) priv; - uint8_t ret = 0xff, index; + uint8_t ret = 0xff; + uint8_t index; index = (port & 1) ? 0 : 1; @@ -387,7 +409,7 @@ pc87306_close(void *priv) } static void * -pc87306_init(const device_t *info) +pc87306_init(UNUSED(const device_t *info)) { pc87306_t *dev = (pc87306_t *) malloc(sizeof(pc87306_t)); memset(dev, 0, sizeof(pc87306_t)); diff --git a/src/sio/sio_pc87307.c b/src/sio/sio_pc87307.c index 6f773a8e1..e66467d62 100644 --- a/src/sio/sio_pc87307.c +++ b/src/sio/sio_pc87307.c @@ -35,13 +35,17 @@ #include <86box/fdc.h> #include <86box/sio.h> -typedef struct { - uint8_t id, pm_idx, - regs[48], ld_regs[256][208], - pcregs[16], gpio[2][4], - pm[8]; - uint16_t gpio_base, gpio_base2, - pm_base; +typedef struct pc87307_t { + uint8_t id; + uint8_t pm_idx; + uint8_t regs[48]; + uint8_t ld_regs[256][208]; + uint8_t pcregs[16]; + uint8_t gpio[2][4]; + uint8_t pm[8]; + uint16_t gpio_base; + uint16_t gpio_base2; + uint16_t pm_base; int cur_reg; fdc_t *fdc; serial_t *uart[2]; @@ -64,14 +68,19 @@ uint8_t pc87307_gpio_read(uint16_t port, void *priv) { pc87307_t *dev = (pc87307_t *) priv; - uint8_t pins = 0xff, bank = ((port & 0xfffc) == dev->gpio_base2); - uint8_t mask, ret = dev->gpio[bank][port & 0x0003]; + uint8_t pins = 0xff; + uint8_t bank = ((port & 0xfffc) == dev->gpio_base2); + uint8_t mask; + uint8_t ret = dev->gpio[bank][port & 0x0003]; switch (port & 0x0003) { case 0x0000: mask = dev->gpio[bank][0x0001]; ret = (ret & mask) | (pins & ~mask); break; + + default: + break; } return ret; @@ -120,6 +129,9 @@ pc87307_pm_write(uint16_t port, uint8_t val, void *priv) serial_handler(dev, 1); serial_handler(dev, 0); break; + + default: + break; } } } @@ -157,7 +169,8 @@ pc87307_pm_init(pc87307_t *dev, uint16_t addr) static void fdc_handler(pc87307_t *dev) { - uint8_t irq, active; + uint8_t irq; + uint8_t active; uint16_t addr; fdc_remove(dev->fdc); @@ -175,7 +188,8 @@ fdc_handler(pc87307_t *dev) static void lpt1_handler(pc87307_t *dev) { - uint8_t irq, active; + uint8_t irq; + uint8_t active; uint16_t addr; lpt1_remove(); @@ -193,7 +207,8 @@ lpt1_handler(pc87307_t *dev) static void serial_handler(pc87307_t *dev, int uart) { - uint8_t irq, active; + uint8_t irq; + uint8_t active; uint16_t addr; serial_remove(dev->uart[uart]); @@ -302,6 +317,9 @@ pc87307_write(uint16_t port, uint8_t val, void *priv) case 0x08: pm_handler(dev); break; + + default: + break; } break; case 0x60: @@ -328,6 +346,9 @@ pc87307_write(uint16_t port, uint8_t val, void *priv) case 0x08: pm_handler(dev); break; + + default: + break; } break; case 0x61: @@ -359,6 +380,9 @@ pc87307_write(uint16_t port, uint8_t val, void *priv) dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xfe; pm_handler(dev); break; + + default: + break; } break; case 0x63: @@ -391,6 +415,9 @@ pc87307_write(uint16_t port, uint8_t val, void *priv) case 0x08: pm_handler(dev); break; + + default: + break; } break; case 0xf0: @@ -411,12 +438,18 @@ pc87307_write(uint16_t port, uint8_t val, void *priv) case 0x06: dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x87; break; + + default: + break; } break; case 0xf1: if (dev->regs[0x07] == 0x03) dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x0f; break; + + default: + break; } } @@ -424,7 +457,8 @@ uint8_t pc87307_read(uint16_t port, void *priv) { pc87307_t *dev = (pc87307_t *) priv; - uint8_t ret = 0xff, index; + uint8_t ret = 0xff; + uint8_t index; index = (port & 1) ? 0 : 1; @@ -445,10 +479,8 @@ pc87307_read(uint16_t port, void *priv) void pc87307_reset(pc87307_t *dev) { - int i; - memset(dev->regs, 0x00, 0x30); - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) memset(dev->ld_regs[i], 0x00, 0xd0); memset(dev->pcregs, 0x00, 0x10); memset(dev->gpio, 0xff, 0x08); @@ -515,8 +547,10 @@ pc87307_reset(pc87307_t *dev) dev->ld_regs[0x08][0x44] = 0x04; dev->ld_regs[0x08][0x45] = 0x04; - // dev->gpio[0] = 0xff; - // dev->gpio[1] = 0xfb; +#if 0 + dev->gpio[0] = 0xff; + dev->gpio[1] = 0xfb; +#endif dev->gpio[0][0] = 0xff; dev->gpio[0][1] = 0x00; dev->gpio[0][2] = 0x00; diff --git a/src/sio/sio_pc87309.c b/src/sio/sio_pc87309.c index 70ed57229..edd1fb0b8 100644 --- a/src/sio/sio_pc87309.c +++ b/src/sio/sio_pc87309.c @@ -35,10 +35,12 @@ #include <86box/fdc.h> #include <86box/sio.h> -typedef struct { - uint8_t id, pm_idx, - regs[48], ld_regs[256][208], - pm[8]; +typedef struct pc87309_t { + uint8_t id; + uint8_t pm_idx; + uint8_t regs[48]; + uint8_t ld_regs[256][208]; + uint8_t pm[8]; uint16_t pm_base; int cur_reg; fdc_t *fdc; @@ -64,6 +66,9 @@ pc87309_pm_write(uint16_t port, uint8_t val, void *priv) serial_handler(dev, 1); serial_handler(dev, 0); break; + + default: + break; } } else dev->pm_idx = val & 0x07; @@ -102,7 +107,8 @@ pc87309_pm_init(pc87309_t *dev, uint16_t addr) static void fdc_handler(pc87309_t *dev) { - uint8_t irq, active; + uint8_t irq; + uint8_t active; uint16_t addr; fdc_remove(dev->fdc); @@ -120,7 +126,8 @@ fdc_handler(pc87309_t *dev) static void lpt1_handler(pc87309_t *dev) { - uint8_t irq, active; + uint8_t irq; + uint8_t active; uint16_t addr; lpt1_remove(); @@ -138,7 +145,8 @@ lpt1_handler(pc87309_t *dev) static void serial_handler(pc87309_t *dev, int uart) { - uint8_t irq, active; + uint8_t irq; + uint8_t active; uint16_t addr; serial_remove(dev->uart[uart]); @@ -218,6 +226,9 @@ pc87309_write(uint16_t port, uint8_t val, void *priv) case 0x04: pm_handler(dev); break; + + default: + break; } break; case 0x60: @@ -241,6 +252,9 @@ pc87309_write(uint16_t port, uint8_t val, void *priv) case 0x04: pm_handler(dev); break; + + default: + break; } break; case 0x63: @@ -272,6 +286,9 @@ pc87309_write(uint16_t port, uint8_t val, void *priv) case 0x06: dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf8; break; + + default: + break; } break; case 0x70: @@ -293,6 +310,9 @@ pc87309_write(uint16_t port, uint8_t val, void *priv) case 0x04: pm_handler(dev); break; + + default: + break; } break; case 0xf0: @@ -313,12 +333,18 @@ pc87309_write(uint16_t port, uint8_t val, void *priv) case 0x06: dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xc1; break; + + default: + break; } break; case 0xf1: if (dev->regs[0x07] == 0x00) dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x0f; break; + + default: + break; } } @@ -326,7 +352,8 @@ uint8_t pc87309_read(uint16_t port, void *priv) { pc87309_t *dev = (pc87309_t *) priv; - uint8_t ret = 0xff, index; + uint8_t ret = 0xff; + uint8_t index; index = (port & 1) ? 0 : 1; @@ -345,10 +372,8 @@ pc87309_read(uint16_t port, void *priv) void pc87309_reset(pc87309_t *dev) { - int i; - memset(dev->regs, 0x00, 0x30); - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) memset(dev->ld_regs[i], 0x00, 0xd0); memset(dev->pm, 0x00, 0x08); diff --git a/src/sio/sio_pc87310.c b/src/sio/sio_pc87310.c index eacbadf89..d567bd4d5 100644 --- a/src/sio/sio_pc87310.c +++ b/src/sio/sio_pc87310.c @@ -40,6 +40,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> #define HAS_IDE_FUNCTIONALITY dev->ide_function @@ -61,9 +62,10 @@ pc87310_log(const char *fmt, ...) # define pc87310_log(fmt, ...) #endif -typedef struct { - uint8_t tries, ide_function, - reg; +typedef struct pc87310_t { + uint8_t tries; + uint8_t ide_function; + uint8_t reg; fdc_t *fdc; serial_t *uart[2]; } pc87310_t; @@ -97,6 +99,9 @@ lpt1_handler(pc87310_t *dev) lpt_port = 0x000; lpt_irq = 0xff; break; + + default: + break; } if (lpt_port) @@ -127,7 +132,7 @@ serial_handler(pc87310_t *dev, int uart) } static void -pc87310_write(uint16_t port, uint8_t val, void *priv) +pc87310_write(UNUSED(uint16_t port), uint8_t val, void *priv) { pc87310_t *dev = (pc87310_t *) priv; uint8_t valxor; @@ -189,7 +194,7 @@ pc87310_write(uint16_t port, uint8_t val, void *priv) } uint8_t -pc87310_read(uint16_t port, void *priv) +pc87310_read(UNUSED(uint16_t port), void *priv) { pc87310_t *dev = (pc87310_t *) priv; uint8_t ret = 0xff; @@ -219,7 +224,9 @@ pc87310_reset(pc87310_t *dev) serial_handler(dev, 0); serial_handler(dev, 1); fdc_reset(dev->fdc); - // ide_pri_enable(); +#if 0 + ide_pri_enable(); +#endif } static void diff --git a/src/sio/sio_pc87311.c b/src/sio/sio_pc87311.c index c795da8a9..143712692 100644 --- a/src/sio/sio_pc87311.c +++ b/src/sio/sio_pc87311.c @@ -32,6 +32,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> #define HAS_IDE_FUNCTIONALITY dev->ide_function @@ -64,10 +65,13 @@ pc87311_log(const char *fmt, ...) # define pc87311_log(fmt, ...) #endif -typedef struct -{ - uint8_t index, regs[256], cfg_lock, ide_function; - uint16_t base, irq; +typedef struct pc87311_t { + uint8_t index; + uint8_t regs[256]; + uint8_t cfg_lock; + uint8_t ide_function; + uint16_t base; + uint16_t irq; fdc_t *fdc_controller; serial_t *uart[2]; @@ -102,15 +106,21 @@ pc87311_write(uint16_t addr, uint8_t val, void *priv) case 0x02: POWER_TEST = val; break; + + default: + break; } break; + + default: + break; } pc87311_enable(dev); } static uint8_t -pc87311_read(uint16_t addr, void *priv) +pc87311_read(UNUSED(uint16_t addr), void *priv) { pc87311_t *dev = (pc87311_t *) priv; @@ -181,6 +191,9 @@ pc87311_uart_handler(uint8_t num, pc87311_t *dev) dev->base = com4(dev); dev->irq = COM4_IRQ; break; + + default: + break; } serial_setup(dev->uart[num & 1], dev->base, dev->irq); pc87311_log("PC87311-UART%01x: BASE %04x IRQ %01x\n", num & 1, dev->base, dev->irq); @@ -203,6 +216,9 @@ pc87311_lpt_handler(pc87311_t *dev) dev->base = LPT2_ADDR; dev->irq = LPT2_IRQ; break; + + default: + break; } lpt1_init(dev->base); lpt1_irq(dev->irq); diff --git a/src/sio/sio_pc87332.c b/src/sio/sio_pc87332.c index 64dd86665..5cbf9f694 100644 --- a/src/sio/sio_pc87332.c +++ b/src/sio/sio_pc87332.c @@ -35,9 +35,11 @@ #include <86box/fdc.h> #include <86box/sio.h> -typedef struct { - uint8_t tries, has_ide, - fdc_on, regs[15]; +typedef struct pc87332_t { + uint8_t tries; + uint8_t has_ide; + uint8_t fdc_on; + uint8_t regs[15]; int cur_reg; fdc_t *fdc; serial_t *uart[2]; @@ -69,6 +71,9 @@ lpt1_handler(pc87332_t *dev) lpt_port = 0x000; lpt_irq = 0xff; break; + + default: + break; } if (lpt_port) @@ -105,6 +110,9 @@ serial_handler(pc87332_t *dev, int uart) case 3: serial_setup(dev->uart[uart], 0x220, COM3_IRQ); break; + + default: + break; } break; case 3: @@ -121,8 +129,14 @@ serial_handler(pc87332_t *dev, int uart) case 3: serial_setup(dev->uart[uart], 0x228, COM4_IRQ); break; + + default: + break; } break; + + default: + break; } } @@ -149,7 +163,8 @@ static void pc87332_write(uint16_t port, uint8_t val, void *priv) { pc87332_t *dev = (pc87332_t *) priv; - uint8_t index, valxor; + uint8_t index; + uint8_t valxor; index = (port & 1) ? 0 : 1; @@ -237,6 +252,9 @@ pc87332_write(uint16_t port, uint8_t val, void *priv) lpt1_handler(dev); } break; + + default: + break; } } @@ -244,7 +262,8 @@ uint8_t pc87332_read(uint16_t port, void *priv) { pc87332_t *dev = (pc87332_t *) priv; - uint8_t ret = 0xff, index; + uint8_t ret = 0xff; + uint8_t index; index = (port & 1) ? 0 : 1; @@ -316,7 +335,7 @@ pc87332_init(const device_t *info) dev->fdc_on = (info->local >> 16) & 0xff; pc87332_reset(dev); - if ((info->local & 0xff) == (0x01)) { + if ((info->local & 0xff) == 0x01) { io_sethandler(0x398, 0x0002, pc87332_read, NULL, NULL, pc87332_write, NULL, NULL, dev); } else { diff --git a/src/sio/sio_prime3b.c b/src/sio/sio_prime3b.c index a204fde5b..32be854c7 100644 --- a/src/sio/sio_prime3b.c +++ b/src/sio/sio_prime3b.c @@ -32,6 +32,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> #define FSR dev->regs[0xa0] #define ASR dev->regs[0xa1] @@ -56,10 +57,13 @@ prime3b_log(const char *fmt, ...) # define prime3b_log(fmt, ...) #endif -typedef struct -{ - uint8_t index, regs[256], cfg_lock, ide_function; - uint16_t com3_addr, com4_addr; +typedef struct prime3b_t { + uint8_t index; + uint8_t regs[256]; + uint8_t cfg_lock; + uint8_t ide_function; + uint16_t com3_addr; + uint16_t com4_addr; fdc_t *fdc_controller; serial_t *uart[2]; @@ -121,17 +125,23 @@ prime3b_write(uint16_t addr, uint8_t val, void *priv) dev->com3_addr = 0x220; dev->com4_addr = 0x228; break; + + default: + break; } break; case 0xa5: /* ECP Register */ dev->regs[0xa5] = val; break; + + default: + break; } } } static uint8_t -prime3b_read(uint16_t addr, void *priv) +prime3b_read(UNUSED(uint16_t addr), void *priv) { prime3b_t *dev = (prime3b_t *) priv; diff --git a/src/sio/sio_prime3c.c b/src/sio/sio_prime3c.c index eae3fe1b2..160f23aab 100644 --- a/src/sio/sio_prime3c.c +++ b/src/sio/sio_prime3c.c @@ -32,6 +32,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> #ifdef ENABLE_PRIME3C_LOG int prime3c_do_log = ENABLE_PRIME3C_LOG; @@ -75,9 +76,11 @@ prime3c_log(const char *fmt, ...) /* IDE functionality(Note on Init) */ #define HAS_IDE_FUNCTIONALITY dev->ide_function -typedef struct -{ - uint8_t index, regs[256], cfg_lock, ide_function; +typedef struct prime3c_t { + uint8_t index; + uint8_t regs[256]; + uint8_t cfg_lock; + uint8_t ide_function; fdc_t *fdc_controller; serial_t *uart[2]; @@ -189,14 +192,20 @@ prime3c_write(uint16_t addr, uint8_t val, void *priv) case 0xd8: dev->regs[dev->index] = val; break; + + default: + break; } } break; + + default: + break; } } static uint8_t -prime3c_read(uint16_t addr, void *priv) +prime3c_read(UNUSED(uint16_t addr), void *priv) { prime3c_t *dev = (prime3c_t *) priv; diff --git a/src/sio/sio_um8669f.c b/src/sio/sio_um8669f.c index bd153a9e4..256c614ae 100644 --- a/src/sio/sio_um8669f.c +++ b/src/sio/sio_um8669f.c @@ -37,6 +37,7 @@ #include <86box/gameport.h> #include <86box/sio.h> #include <86box/isapnp.h> +#include <86box/plat_unused.h> /* This ROM was reconstructed out of many assumptions, some of which based on the IT8671F. */ static uint8_t um8669f_pnp_rom[] = { @@ -112,7 +113,8 @@ um8669f_log(const char *fmt, ...) #endif typedef struct um8669f_t { - int locked, cur_reg_108; + int locked; + int cur_reg_108; void *pnp_card; isapnp_device_config_t *pnp_config[5]; @@ -184,6 +186,9 @@ um8669f_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pri um8669f_log("UM8669F: Game port disabled\n"); gameport_remap(dev->gameport, 0); } + + default: + break; } } @@ -263,7 +268,7 @@ um8669f_close(void *priv) } static void * -um8669f_init(const device_t *info) +um8669f_init(UNUSED(const device_t *info)) { um8669f_log("UM8669F: init()\n"); diff --git a/src/sio/sio_vt82c686.c b/src/sio/sio_vt82c686.c index c7f9c28bc..f22af07df 100644 --- a/src/sio/sio_vt82c686.c +++ b/src/sio/sio_vt82c686.c @@ -31,10 +31,17 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/sio.h> +#include <86box/plat_unused.h> -typedef struct { - uint8_t cur_reg, last_val, regs[25], - fdc_dma, fdc_irq, uart_irq[2], lpt_dma, lpt_irq; +typedef struct vt82c686_t { + uint8_t cur_reg; + uint8_t last_val; + uint8_t regs[25]; + uint8_t fdc_dma; + uint8_t fdc_irq; + uint8_t uart_irq[2]; + uint8_t lpt_dma; + uint8_t lpt_irq; fdc_t *fdc; serial_t *uart[2]; } vt82c686_t; @@ -68,7 +75,8 @@ vt82c686_fdc_handler(vt82c686_t *dev) static void vt82c686_lpt_handler(vt82c686_t *dev) { - uint16_t io_mask, io_base = dev->regs[0x06] << 2; + uint16_t io_mask; + uint16_t io_base = dev->regs[0x06] << 2; int io_len = get_lpt_length(dev); io_base &= (0xff8 | io_len); io_mask = 0x3fc; /* non-EPP */ @@ -188,6 +196,9 @@ vt82c686_write(uint16_t port, uint8_t val, void *priv) dev->regs[reg] &= 0xf7; vt82c686_fdc_handler(dev); break; + + default: + break; } } @@ -241,6 +252,9 @@ vt82c686_sio_write(uint8_t addr, uint8_t val, void *priv) if (val & 0x02) io_sethandler(FDC_PRIMARY_ADDR, 2, vt82c686_read, NULL, NULL, vt82c686_write, NULL, NULL, dev); break; + + default: + break; } } @@ -271,7 +285,7 @@ vt82c686_close(void *priv) } static void * -vt82c686_init(const device_t *info) +vt82c686_init(UNUSED(const device_t *info)) { vt82c686_t *dev = (vt82c686_t *) malloc(sizeof(vt82c686_t)); memset(dev, 0, sizeof(vt82c686_t)); diff --git a/src/sio/sio_w83787f.c b/src/sio/sio_w83787f.c index 722f1eef8..1870741c7 100644 --- a/src/sio/sio_w83787f.c +++ b/src/sio/sio_w83787f.c @@ -74,13 +74,16 @@ w83787_log(const char *fmt, ...) #define HAS_IDE_FUNCTIONALITY dev->ide_function -typedef struct { - uint8_t tries, regs[42]; +typedef struct w83787f_t { + uint8_t tries; + uint8_t regs[42]; uint16_t reg_init; - int locked, rw_locked, - cur_reg, - key, ide_function, - ide_start; + int locked; + int rw_locked; + int cur_reg; + int key; + int ide_function; + int ide_start; fdc_t *fdc; serial_t *uart[2]; void *gameport; @@ -123,8 +126,10 @@ w83787f_serial_handler(w83787f_t *dev, int uart) int urs0 = !!(dev->regs[1] & (1 << uart)); int urs1 = !!(dev->regs[1] & (4 << uart)); int urs2 = !!(dev->regs[3] & (8 >> uart)); - int urs, irq = COM1_IRQ; - uint16_t addr = COM1_ADDR, enable = 1; + int urs; + int irq = COM1_IRQ; + uint16_t addr = COM1_ADDR; + uint16_t enable = 1; urs = (urs1 << 1) | urs0; @@ -165,7 +170,8 @@ w83787f_lpt_handler(w83787f_t *dev) { int ptras = (dev->regs[1] >> 4) & 0x03; int irq = LPT1_IRQ; - uint16_t addr = LPT1_ADDR, enable = 1; + uint16_t addr = LPT1_ADDR; + uint16_t enable = 1; switch (ptras) { case 0x00: @@ -339,6 +345,9 @@ w83787f_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x20) w83787f_remap(dev); break; + + default: + break; } } diff --git a/src/sio/sio_w83877f.c b/src/sio/sio_w83877f.c index 4f8b45118..8cbb82876 100644 --- a/src/sio/sio_w83877f.c +++ b/src/sio/sio_w83877f.c @@ -56,13 +56,16 @@ #define PRTIQS (dev->regs[0x27] & 0x0f) #define ECPIRQ ((dev->regs[0x27] >> 5) & 0x07) -typedef struct { - uint8_t tries, regs[42]; - uint16_t reg_init; - int locked, rw_locked, - cur_reg, - base_address, key, - key_times; +typedef struct w83877f_t { + uint8_t tries; + uint8_t regs[42]; + uint16_t reg_init; + int locked; + int rw_locked; + int cur_reg; + int base_address; + int key; + int key_times; fdc_t *fdc; serial_t *uart[2]; } w83877f_t; @@ -140,6 +143,9 @@ make_port(w83877f_t *dev, uint8_t reg) if ((p < 0x100) || (p > 0x3F8)) p = COM2_ADDR; break; + + default: + break; } return p; @@ -358,6 +364,9 @@ w83877f_write(uint16_t port, uint8_t val, void *priv) w83877f_serial_handler(dev, 0); } break; + + default: + break; } } diff --git a/src/sio/sio_w83977f.c b/src/sio/sio_w83977f.c index 1b6105840..063f0ca69 100644 --- a/src/sio/sio_w83977f.c +++ b/src/sio/sio_w83977f.c @@ -36,13 +36,17 @@ #define HEFRAS (dev->regs[0x26] & 0x40) -typedef struct { - uint8_t id, tries, - regs[48], - dev_regs[256][208]; - int locked, rw_locked, - cur_reg, base_address, - type, hefras; +typedef struct w83977f_t { + uint8_t id; + uint8_t tries; + uint8_t regs[48]; + uint8_t dev_regs[256][208]; + int locked; + int rw_locked; + int cur_reg; + int base_address; + int type; + int hefras; fdc_t *fdc; serial_t *uart[2]; } w83977f_t; @@ -96,7 +100,8 @@ w83977f_fdc_handler(w83977f_t *dev) static void w83977f_lpt_handler(w83977f_t *dev) { - uint16_t io_mask, io_base = (dev->dev_regs[1][0x30] << 8) | dev->dev_regs[1][0x31]; + uint16_t io_mask; + uint16_t io_base = (dev->dev_regs[1][0x30] << 8) | dev->dev_regs[1][0x31]; int io_len = get_lpt_length(dev); io_base &= (0xff8 | io_len); io_mask = 0xffc; @@ -144,6 +149,9 @@ w83977f_serial_handler(w83977f_t *dev, int uart) case 0x03: clock_src = 24000000.0 / 1.625; break; + + default: + break; } serial_set_clock_src(dev->uart[uart], clock_src); @@ -193,8 +201,10 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) switch (dev->cur_reg) { case 0x02: - /* if (valxor & 0x02) - softresetx86(); */ +#if 0 + if (valxor & 0x02) + softresetx86(); +#endif break; case 0x22: if (valxor & 0x20) @@ -225,6 +235,9 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) case 0x03: w83977f_serial_handler(dev, ld - 2); break; + + default: + break; } break; case 0x60: @@ -241,6 +254,9 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) case 0x03: w83977f_serial_handler(dev, ld - 2); break; + + default: + break; } break; case 0x70: @@ -256,6 +272,9 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) case 0x03: w83977f_serial_handler(dev, ld - 2); break; + + default: + break; } break; case 0xf0: @@ -280,6 +299,9 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x03) w83977f_serial_handler(dev, ld - 2); break; + + default: + break; } break; case 0xf1: @@ -297,6 +319,9 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) if (!dev->id && (valxor & 0x01)) fdc_set_swwp(dev->fdc, (val & 0x01) ? 1 : 0); break; + + default: + break; } break; case 0xf2: @@ -314,6 +339,9 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) if (!dev->id && (valxor & 0x03)) fdc_update_rwc(dev->fdc, 0, val & 0x03); break; + + default: + break; } break; case 0xf4: @@ -328,8 +356,14 @@ w83977f_write(uint16_t port, uint8_t val, void *priv) if (!dev->id && (valxor & 0x18)) fdc_update_drvrate(dev->fdc, dev->cur_reg & 0x03, (val & 0x18) >> 3); break; + + default: + break; } break; + + default: + break; } } @@ -362,10 +396,8 @@ w83977f_read(uint16_t port, void *priv) static void w83977f_reset(w83977f_t *dev) { - int i; - memset(dev->regs, 0, 48); - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) memset(dev->dev_regs[i], 0, 208); if (dev->type < 2) { diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index bcc335f33..d6672ac18 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -85,6 +85,13 @@ if(RTMIDI) endif() if(FLUIDSYNTH) + find_package(PkgConfig REQUIRED) + pkg_check_modules(FLUIDSYNTH REQUIRED IMPORTED_TARGET fluidsynth) + target_link_libraries(86Box PkgConfig::FLUIDSYNTH) + if(STATIC_BUILD) + target_link_libraries(86Box -static ${FLUIDSYNTH_STATIC_LIBRARIES} -fopenmp) + endif() + target_compile_definitions(snd PRIVATE USE_FLUIDSYNTH) target_sources(snd PRIVATE midi_fluidsynth.c) endif() diff --git a/src/sound/midi.c b/src/sound/midi.c index 2dd19f9fd..24eb8b97a 100644 --- a/src/sound/midi.c +++ b/src/sound/midi.c @@ -36,10 +36,12 @@ static int midi_output_device_last = 0; int midi_input_device_current = 0; static int midi_input_device_last = 0; -midi_t *midi_out = NULL, *midi_in = NULL; +midi_t *midi_out = NULL; +midi_t *midi_in = NULL; -midi_in_handler_t *mih_first = NULL, *mih_last = NULL, - *mih_cur = NULL; +midi_in_handler_t *mih_first = NULL; +midi_in_handler_t *mih_last = NULL; +midi_in_handler_t *mih_cur = NULL; uint8_t MIDI_InSysexBuf[SYSEX_SIZE]; @@ -307,7 +309,7 @@ midi_raw_out_rt_byte(uint8_t val) if (!midi_in->midi_realtime) return; - if ((!midi_in->midi_clockout && (val == 0xf8))) + if (!midi_in->midi_clockout && (val == 0xf8)) return; midi_in->midi_cmd_r = val << 24; @@ -330,7 +332,7 @@ midi_raw_out_byte(uint8_t val) if (!midi_out || !midi_out->m_out_device) return; - if ((midi_out->m_out_device->write && midi_out->m_out_device->write(val))) + if (midi_out->m_out_device->write && midi_out->m_out_device->write(val)) return; if (midi_out->midi_sysex_start) { @@ -407,9 +409,10 @@ midi_clear_buffer(void) } void -midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort), void *p) +midi_in_handler(int set, void (*msg)(void *priv, uint8_t *msg, uint32_t len), int (*sysex)(void *priv, uint8_t *buffer, uint32_t len, int abort), void *priv) { - midi_in_handler_t *temp = NULL, *next; + midi_in_handler_t *temp = NULL; + midi_in_handler_t *next; if (set) { /* Add MIDI IN handler. */ @@ -423,7 +426,7 @@ midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int ( memset(temp, 0, sizeof(midi_in_handler_t)); temp->msg = msg; temp->sysex = sysex; - temp->p = p; + temp->priv = priv; if (mih_last == NULL) mih_first = mih_last = temp; @@ -438,7 +441,7 @@ midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int ( if (temp == NULL) break; - if ((temp->msg == msg) && (temp->sysex == sysex) && (temp->p == p)) { + if ((temp->msg == msg) && (temp->sysex == sysex) && (temp->priv == priv)) { if (temp->prev != NULL) temp->prev->next = temp->next; @@ -469,7 +472,8 @@ midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int ( void midi_in_handlers_clear(void) { - midi_in_handler_t *temp = mih_first, *next; + midi_in_handler_t *temp = mih_first; + midi_in_handler_t *next; while (1) { if (temp == NULL) @@ -497,7 +501,7 @@ midi_in_msg(uint8_t *msg, uint32_t len) break; if (temp->msg) - temp->msg(temp->p, msg, len); + temp->msg(temp->priv, msg, len); temp = temp->next; @@ -533,7 +537,8 @@ static int midi_do_sysex(void) { midi_in_handler_t *temp = mih_first; - int ret, cnt_acc = 0; + int ret; + int cnt_acc = 0; while (1) { if (temp == NULL) @@ -544,9 +549,9 @@ midi_do_sysex(void) ret = 0; if (temp->sysex) { if (temp->cnt == 0) - ret = temp->sysex(temp->p, temp->buf, 0, 0); + ret = temp->sysex(temp->priv, temp->buf, 0, 0); else - ret = temp->sysex(temp->p, temp->buf, temp->len, 0); + ret = temp->sysex(temp->priv, temp->buf, temp->len, 0); } /* If count is 0 and length is 0, then this is just a finishing diff --git a/src/sound/midi_fluidsynth.c b/src/sound/midi_fluidsynth.c index 2372203d7..08aefe16c 100644 --- a/src/sound/midi_fluidsynth.c +++ b/src/sound/midi_fluidsynth.c @@ -8,104 +8,34 @@ # ifdef __unix__ # include # endif +# define FLUIDSYNTH_NOT_A_DLL +# include # include <86box/86box.h> # include <86box/config.h> # include <86box/device.h> # include <86box/midi.h> -# include <86box/plat.h> -# include <86box/plat_dynld.h> # include <86box/thread.h> # include <86box/sound.h> -# include <86box/ui.h> - -# define FLUID_CHORUS_DEFAULT_N 3 -# define FLUID_CHORUS_DEFAULT_LEVEL 2.0f -# define FLUID_CHORUS_DEFAULT_SPEED 0.3f -# define FLUID_CHORUS_DEFAULT_DEPTH 8.0f -# define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE +# include <86box/plat_unused.h> # define RENDER_RATE 100 # define BUFFER_SEGMENTS 10 -enum fluid_chorus_mod { - FLUID_CHORUS_MOD_SINE = 0, - FLUID_CHORUS_MOD_TRIANGLE = 1 -}; - -enum fluid_interp { - FLUID_INTERP_NONE = 0, - FLUID_INTERP_LINEAR = 1, - FLUID_INTERP_DEFAULT = 4, - FLUID_INTERP_4THORDER = 4, - FLUID_INTERP_7THORDER = 7, - FLUID_INTERP_HIGHEST = 7 -}; +/* Check the FluidSynth version to determine wheteher to use the older reverb/chorus + control functions that were deprecated in 2.2.0, or their newer replacements */ +# if (FLUIDSYNTH_VERSION_MAJOR < 2) || ((FLUIDSYNTH_VERSION_MAJOR == 2) && (FLUIDSYNTH_VERSION_MINOR < 2)) +# define USE_OLD_FLUIDSYNTH_API +# endif extern void givealbuffer_midi(void *buf, uint32_t size); extern void al_set_midi(int freq, int buf_size); -static void *fluidsynth_handle; /* handle to FluidSynth DLL */ - -/* Pointers to the real functions. */ -// clang-format off -static void *(*f_new_fluid_settings)(void); -static void (*f_delete_fluid_settings)(void *settings); -static int (*f_fluid_settings_setnum)(void *settings, const char *name, double val); -static int (*f_fluid_settings_getnum)(void *settings, const char *name, double *val); -static void *(*f_new_fluid_synth)(void *settings); -static int (*f_delete_fluid_synth)(void *synth); -static int (*f_fluid_synth_noteon)(void *synth, int chan, int key, int vel); -static int (*f_fluid_synth_noteoff)(void *synth, int chan, int key); -static int (*f_fluid_synth_cc)(void *synth, int chan, int ctrl, int val); -static int (*f_fluid_synth_channel_pressure)(void *synth, int chan, int val); -static int (*f_fluid_synth_sysex)(void *synth, const char *data, int len, char *response, int *response_len, int *handled, int dryrun); -static int (*f_fluid_synth_pitch_bend)(void *synth, int chan, int val); -static int (*f_fluid_synth_program_change)(void *synth, int chan, int program); -static int (*f_fluid_synth_sfload)(void *synth, const char *filename, int reset_presets); -static int (*f_fluid_synth_set_interp_method)(void *synth, int chan, int interp_method); -static void (*f_fluid_synth_set_reverb)(void *synth, double roomsize, double damping, double width, double level); -static void (*f_fluid_synth_set_reverb_on)(void *synth, int on); -static void (*f_fluid_synth_set_chorus)(void *synth, int nr, double level, double speed, double depth_ms, int type); -static void (*f_fluid_synth_set_chorus_on)(void *synth, int on); -static int (*f_fluid_synth_write_s16)(void *synth, int len, void *lout, int loff, int lincr, void *rout, int roff, int rincr); -static int (*f_fluid_synth_write_float)(void *synth, int len, void *lout, int loff, int lincr, void *rout, int roff, int rincr); -static char *(*f_fluid_version_str)(void); -// clang-format on - -static dllimp_t fluidsynth_imports[] = { - // clang-format off - { "new_fluid_settings", &f_new_fluid_settings }, - { "delete_fluid_settings", &f_delete_fluid_settings }, - { "fluid_settings_setnum", &f_fluid_settings_setnum }, - { "fluid_settings_getnum", &f_fluid_settings_getnum }, - { "new_fluid_synth", &f_new_fluid_synth }, - { "delete_fluid_synth", &f_delete_fluid_synth }, - { "fluid_synth_noteon", &f_fluid_synth_noteon }, - { "fluid_synth_noteoff", &f_fluid_synth_noteoff }, - { "fluid_synth_cc", &f_fluid_synth_cc }, - { "fluid_synth_channel_pressure", &f_fluid_synth_channel_pressure }, - { "fluid_synth_sysex", &f_fluid_synth_sysex }, - { "fluid_synth_pitch_bend", &f_fluid_synth_pitch_bend }, - { "fluid_synth_program_change", &f_fluid_synth_program_change }, - { "fluid_synth_sfload", &f_fluid_synth_sfload }, - { "fluid_synth_set_interp_method", &f_fluid_synth_set_interp_method }, - { "fluid_synth_set_reverb", &f_fluid_synth_set_reverb }, - { "fluid_synth_set_reverb_on", &f_fluid_synth_set_reverb_on }, - { "fluid_synth_set_chorus", &f_fluid_synth_set_chorus }, - { "fluid_synth_set_chorus_on", &f_fluid_synth_set_chorus_on }, - { "fluid_synth_write_s16", &f_fluid_synth_write_s16 }, - { "fluid_synth_write_float", &f_fluid_synth_write_float }, - { "fluid_version_str", &f_fluid_version_str }, - { NULL, NULL }, - // clang-format on -}; - typedef struct fluidsynth { - void *settings; - void *synth; - int samplerate; - int sound_font; + fluid_settings_t *settings; + fluid_synth_t *synth; + int samplerate; + int sound_font; thread_t *thread_h; event_t *event, *start_event; @@ -153,7 +83,7 @@ fluidsynth_thread(void *param) float *buf = (float *) ((uint8_t *) data->buffer + buf_pos); memset(buf, 0, buf_size); if (data->synth) - f_fluid_synth_write_float(data->synth, buf_size / (2 * sizeof(float)), buf, 0, 2, buf, 1, 2); + fluid_synth_write_float(data->synth, buf_size / (2 * sizeof(float)), buf, 0, 2, buf, 1, 2); buf_pos += buf_size; if (buf_pos >= data->buf_size) { givealbuffer_midi(data->buffer, data->buf_size / sizeof(float)); @@ -163,7 +93,7 @@ fluidsynth_thread(void *param) int16_t *buf = (int16_t *) ((uint8_t *) data->buffer_int16 + buf_pos); memset(buf, 0, buf_size); if (data->synth) - f_fluid_synth_write_s16(data->synth, buf_size / (2 * sizeof(int16_t)), buf, 0, 2, buf, 1, 2); + fluid_synth_write_s16(data->synth, buf_size / (2 * sizeof(int16_t)), buf, 0, 2, buf, 1, 2); buf_pos += buf_size; if (buf_pos >= data->buf_size) { givealbuffer_midi(data->buffer_int16, data->buf_size / sizeof(int16_t)); @@ -187,24 +117,24 @@ fluidsynth_msg(uint8_t *msg) switch (cmd) { case 0x80: /* Note Off */ - f_fluid_synth_noteoff(data->synth, chan, param1); + fluid_synth_noteoff(data->synth, chan, param1); break; case 0x90: /* Note On */ - f_fluid_synth_noteon(data->synth, chan, param1, param2); + fluid_synth_noteon(data->synth, chan, param1, param2); break; case 0xA0: /* Aftertouch */ break; case 0xB0: /* Control Change */ - f_fluid_synth_cc(data->synth, chan, param1, param2); + fluid_synth_cc(data->synth, chan, param1, param2); break; case 0xC0: /* Program Change */ - f_fluid_synth_program_change(data->synth, chan, param1); + fluid_synth_program_change(data->synth, chan, param1); break; case 0xD0: /* Channel Pressure */ - f_fluid_synth_channel_pressure(data->synth, chan, param1); + fluid_synth_channel_pressure(data->synth, chan, param1); break; case 0xE0: /* Pitch Bend */ - f_fluid_synth_pitch_bend(data->synth, chan, (param2 << 7) | param1); + fluid_synth_pitch_bend(data->synth, chan, (param2 << 7) | param1); break; case 0xF0: /* SysEx */ break; @@ -218,53 +148,38 @@ fluidsynth_sysex(uint8_t *data, unsigned int len) { fluidsynth_t *d = &fsdev; - f_fluid_synth_sysex(d->synth, (const char *) data, len, 0, 0, 0, 0); + fluid_synth_sysex(d->synth, (const char *) data, len, 0, 0, 0, 0); } void * -fluidsynth_init(const device_t *info) +fluidsynth_init(UNUSED(const device_t *info)) { fluidsynth_t *data = &fsdev; midi_device_t *dev; memset(data, 0, sizeof(fluidsynth_t)); - /* Try loading the DLL. */ -# ifdef _WIN32 -# if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) - fluidsynth_handle = dynld_module("libfluidsynth.dll", fluidsynth_imports); -# else - fluidsynth_handle = dynld_module("libfluidsynth64.dll", fluidsynth_imports); -# endif -# elif defined __APPLE__ - fluidsynth_handle = dynld_module("libfluidsynth.dylib", fluidsynth_imports); -# else - fluidsynth_handle = dynld_module("libfluidsynth.so.3", fluidsynth_imports); - if (fluidsynth_handle == NULL) - fluidsynth_handle = dynld_module("libfluidsynth.so.2", fluidsynth_imports); -# endif - if (fluidsynth_handle == NULL) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2080, (wchar_t *) IDS_2134); - return NULL; - } + data->settings = new_fluid_settings(); - data->settings = f_new_fluid_settings(); + fluid_settings_setnum(data->settings, "synth.sample-rate", 44100); + fluid_settings_setnum(data->settings, "synth.gain", device_get_config_int("output_gain") / 100.0f); - f_fluid_settings_setnum(data->settings, "synth.sample-rate", 44100); - f_fluid_settings_setnum(data->settings, "synth.gain", device_get_config_int("output_gain") / 100.0f); + data->synth = new_fluid_synth(data->settings); - data->synth = f_new_fluid_synth(data->settings); - - const char *sound_font = (char *) device_get_config_string("sound_font"); + const char *sound_font = device_get_config_string("sound_font"); # ifdef __unix__ if (!sound_font || sound_font[0] == 0) sound_font = (access("/usr/share/sounds/sf2/FluidR3_GM.sf2", F_OK) == 0 ? "/usr/share/sounds/sf2/FluidR3_GM.sf2" : (access("/usr/share/soundfonts/default.sf2", F_OK) == 0 ? "/usr/share/soundfonts/default.sf2" : "")); # endif - data->sound_font = f_fluid_synth_sfload(data->synth, sound_font, 1); + data->sound_font = fluid_synth_sfload(data->synth, sound_font, 1); if (device_get_config_int("chorus")) { - f_fluid_synth_set_chorus_on(data->synth, 1); +# ifndef USE_OLD_FLUIDSYNTH_API + fluid_synth_chorus_on(data->synth, -1, 1); +# else + fluid_synth_set_chorus_on(data->synth, 1); +# endif int chorus_voices = device_get_config_int("chorus_voices"); double chorus_level = device_get_config_int("chorus_level") / 100.0; @@ -277,21 +192,48 @@ fluidsynth_init(const device_t *info) else chorus_waveform = FLUID_CHORUS_MOD_TRIANGLE; - f_fluid_synth_set_chorus(data->synth, chorus_voices, chorus_level, chorus_speed, chorus_depth, chorus_waveform); +# ifndef USE_OLD_FLUIDSYNTH_API + fluid_synth_set_chorus_group_nr(data->synth, -1, chorus_voices); + fluid_synth_set_chorus_group_level(data->synth, -1, chorus_level); + fluid_synth_set_chorus_group_speed(data->synth, -1, chorus_speed); + fluid_synth_set_chorus_group_depth(data->synth, -1, chorus_depth); + fluid_synth_set_chorus_group_type(data->synth, -1, chorus_waveform); +# else + fluid_synth_set_chorus(data->synth, chorus_voices, chorus_level, chorus_speed, chorus_depth, chorus_waveform); +# endif } else - f_fluid_synth_set_chorus_on(data->synth, 0); +# ifndef USE_OLD_FLUIDSYNTH_API + fluid_synth_chorus_on(data->synth, -1, 0); +# else + fluid_synth_set_chorus_on(data->synth, 0); +# endif if (device_get_config_int("reverb")) { - f_fluid_synth_set_reverb_on(data->synth, 1); +# ifndef USE_OLD_FLUIDSYNTH_API + fluid_synth_reverb_on(data->synth, -1, 1); +# else + fluid_synth_set_reverb_on(data->synth, 1); +# endif double reverb_room_size = device_get_config_int("reverb_room_size") / 100.0; double reverb_damping = device_get_config_int("reverb_damping") / 100.0; - int reverb_width = device_get_config_int("reverb_width"); + double reverb_width = device_get_config_int("reverb_width") / 10.0; double reverb_level = device_get_config_int("reverb_level") / 100.0; - f_fluid_synth_set_reverb(data->synth, reverb_room_size, reverb_damping, reverb_width, reverb_level); +# ifndef USE_OLD_FLUIDSYNTH_API + fluid_synth_set_reverb_group_roomsize(data->synth, -1, reverb_room_size); + fluid_synth_set_reverb_group_damp(data->synth, -1, reverb_damping); + fluid_synth_set_reverb_group_width(data->synth, -1, reverb_width); + fluid_synth_set_reverb_group_level(data->synth, -1, reverb_level); +# else + fluid_synth_set_reverb(data->synth, reverb_room_size, reverb_damping, reverb_width, reverb_level); +# endif } else - f_fluid_synth_set_reverb_on(data->synth, 0); +# ifndef USE_OLD_FLUIDSYNTH_API + fluid_synth_reverb_on(data->synth, -1, 0); +# else + fluid_synth_set_reverb_on(data->synth, 0); +# endif int interpolation = device_get_config_int("interpolation"); int fs_interpolation = FLUID_INTERP_4THORDER; @@ -305,10 +247,10 @@ fluidsynth_init(const device_t *info) else if (interpolation == 3) fs_interpolation = FLUID_INTERP_7THORDER; - f_fluid_synth_set_interp_method(data->synth, -1, fs_interpolation); + fluid_synth_set_interp_method(data->synth, -1, fs_interpolation); double samplerate; - f_fluid_settings_getnum(data->settings, "synth.sample-rate", &samplerate); + fluid_settings_getnum(data->settings, "synth.sample-rate", &samplerate); data->samplerate = (int) samplerate; if (sound_is_float) { data->buf_size = (data->samplerate / RENDER_RATE) * 2 * sizeof(float) * BUFFER_SEGMENTS; @@ -345,9 +287,9 @@ fluidsynth_init(const device_t *info) } void -fluidsynth_close(void *p) +fluidsynth_close(void *priv) { - if (!p) + if (!priv) return; fluidsynth_t *data = &fsdev; @@ -357,12 +299,12 @@ fluidsynth_close(void *p) thread_wait(data->thread_h); if (data->synth) { - f_delete_fluid_synth(data->synth); + delete_fluid_synth(data->synth); data->synth = NULL; } if (data->settings) { - f_delete_fluid_settings(data->settings); + delete_fluid_settings(data->settings); data->settings = NULL; } @@ -375,12 +317,6 @@ fluidsynth_close(void *p) free(data->buffer_int16); data->buffer_int16 = NULL; } - - /* Unload the DLL if possible. */ - if (fluidsynth_handle != NULL) { - dynld_close(fluidsynth_handle); - fluidsynth_handle = NULL; - } } static const device_config_t fluidsynth_config[] = { @@ -407,7 +343,7 @@ static const device_config_t fluidsynth_config[] = { .name = "chorus", .description = "Chorus", .type = CONFIG_BINARY, - .default_int = 0 + .default_int = 1 }, { .name = "chorus_voices", @@ -429,7 +365,7 @@ static const device_config_t fluidsynth_config[] = { .min = 0, .max = 100 }, - .default_int = 100 + .default_int = 20 }, { .name = "chorus_speed", @@ -437,7 +373,7 @@ static const device_config_t fluidsynth_config[] = { .type = CONFIG_SPINNER, .spinner = { - .min = 30, + .min = 10, .max = 500 }, .default_int = 30 @@ -449,7 +385,7 @@ static const device_config_t fluidsynth_config[] = { .spinner = { .min = 0, - .max = 210 + .max = 2560 }, .default_int = 80 }, @@ -474,7 +410,7 @@ static const device_config_t fluidsynth_config[] = { .name = "reverb", .description = "Reverb", .type = CONFIG_BINARY, - .default_int = 0 + .default_int = 1 }, { .name = "reverb_room_size", @@ -483,7 +419,7 @@ static const device_config_t fluidsynth_config[] = { .spinner = { .min = 0, - .max = 120 + .max = 100 }, .default_int = 20 }, @@ -505,9 +441,9 @@ static const device_config_t fluidsynth_config[] = { .spinner = { .min = 0, - .max = 100 + .max = 1000 }, - .default_int = 1 + .default_int = 5 }, { .name = "reverb_level", diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index 230914d72..91d85e438 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -110,7 +110,7 @@ static mt32emu_context context = NULL; static int roms_present[2] = { -1, -1 }; mt32emu_return_code -mt32_check(const char *func, mt32emu_return_code ret, mt32emu_return_code expected) +mt32_check(UNUSED(const char *func), mt32emu_return_code ret, mt32emu_return_code expected) { if (ret != expected) { return 0; @@ -165,13 +165,13 @@ static int16_t *buffer_int16 = NULL; static int midi_pos = 0; static mt32emu_report_handler_version -get_mt32_report_handler_version(mt32emu_report_handler_i i) +get_mt32_report_handler_version(UNUSED(mt32emu_report_handler_i i)) { return MT32EMU_REPORT_HANDLER_VERSION_0; } static void -display_mt32_message(void *instance_data, const char *message) +display_mt32_message(UNUSED(void *instance_data), const char *message) { int sz = 0; char *ui_msg = NULL; @@ -209,7 +209,7 @@ mt32_poll(void) } static void -mt32_thread(void *param) +mt32_thread(UNUSED(void *param)) { int buf_pos = 0; int bsize = buf_size / BUFFER_SEGMENTS; @@ -321,33 +321,33 @@ mt32emu_init(char *control_rom, char *pcm_rom) } void * -mt32_old_init(const device_t *info) +mt32_old_init(UNUSED(const device_t *info)) { return mt32emu_init(MT32_OLD_CTRL_ROM, MT32_OLD_PCM_ROM); } void * -mt32_new_init(const device_t *info) +mt32_new_init(UNUSED(const device_t *info)) { return mt32emu_init(MT32_NEW_CTRL_ROM, MT32_NEW_PCM_ROM); } void * -cm32l_init(const device_t *info) +cm32l_init(UNUSED(const device_t *info)) { return mt32emu_init(CM32L_CTRL_ROM, CM32L_PCM_ROM); } void * -cm32ln_init(const device_t *info) +cm32ln_init(UNUSED(const device_t *info)) { return mt32emu_init(CM32LN_CTRL_ROM, CM32LN_PCM_ROM); } void -mt32_close(void *p) +mt32_close(void *priv) { - if (!p) + if (!priv) return; mt32_on = 0; diff --git a/src/sound/midi_rtmidi.cpp b/src/sound/midi_rtmidi.cpp index 354c7f61b..72df8fd32 100644 --- a/src/sound/midi_rtmidi.cpp +++ b/src/sound/midi_rtmidi.cpp @@ -35,6 +35,7 @@ extern "C" { #include <86box/midi_rtmidi.h> #include <86box/ini.h> #include <86box/config.h> +#include <86box/plat_unused.h> // Disable c99-designator to avoid the warnings in rtmidi_*_device #ifdef __clang__ @@ -50,7 +51,7 @@ static int midi_out_id = 0, midi_in_id = 0; static const int midi_lengths[8] = { 3, 3, 3, 3, 2, 2, 3, 1 }; int -rtmidi_write(uint8_t val) +rtmidi_write(UNUSED(uint8_t val)) { return 0; } @@ -70,7 +71,7 @@ rtmidi_play_sysex(uint8_t *sysex, unsigned int len) } void * -rtmidi_output_init(const device_t *info) +rtmidi_output_init(UNUSED(const device_t *info)) { midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t)); @@ -110,7 +111,7 @@ rtmidi_output_init(const device_t *info) } void -rtmidi_output_close(void *p) +rtmidi_output_close(UNUSED(void *priv)) { if (!midiout) return; @@ -144,7 +145,7 @@ rtmidi_out_get_dev_name(int num, char *s) } void -rtmidi_input_callback(double timeStamp, std::vector *message, void *userData) +rtmidi_input_callback(UNUSED(double timeStamp), std::vector *message, UNUSED(void *userData)) { if (message->front() == 0xF0) midi_in_sysex(message->data(), message->size()); @@ -153,7 +154,7 @@ rtmidi_input_callback(double timeStamp, std::vector *message, voi } void * -rtmidi_input_init(const device_t *info) +rtmidi_input_init(UNUSED(const device_t *info)) { midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t)); @@ -198,7 +199,7 @@ rtmidi_input_init(const device_t *info) } void -rtmidi_input_close(void *p) +rtmidi_input_close(UNUSED(void *priv)) { midiin->cancelCallback(); midiin->closePort(); diff --git a/src/sound/openal.c b/src/sound/openal.c index a1b870480..76656c66e 100644 --- a/src/sound/openal.c +++ b/src/sound/openal.c @@ -33,6 +33,7 @@ #include <86box/86box.h> #include <86box/midi.h> #include <86box/sound.h> +#include <86box/plat_unused.h> #define FREQ SOUND_FREQ #define BUFLEN SOUNDBUFLEN @@ -58,7 +59,7 @@ al_set_midi(int freq, int buf_size) void closeal(void); ALvoid -alutInit(ALint *argc, ALbyte **argv) +alutInit(UNUSED(ALint *argc), UNUSED(ALbyte **argv)) { /* Open device */ Device = alcOpenDevice((ALCchar *) ""); @@ -111,12 +112,15 @@ closeal(void) void inital(void) { - float *buf = NULL, *cd_buf = NULL, *midi_buf = NULL; - int16_t *buf_int16 = NULL, *cd_buf_int16 = NULL, *midi_buf_int16 = NULL; - int c; + float *buf = NULL; + float *cd_buf = NULL; + float *midi_buf = NULL; + int16_t *buf_int16 = NULL; + int16_t *cd_buf_int16 = NULL; + int16_t *midi_buf_int16 = NULL; - char *mdn; - int init_midi = 0; + const char *mdn; + int init_midi = 0; if (initialized) return; @@ -182,7 +186,7 @@ inital(void) memset(midi_buf_int16, 0, midi_buf_size * sizeof(int16_t)); } - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { if (sound_is_float) { alBufferData(buffers[c], AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN * 2 * sizeof(float), FREQ); alBufferData(buffers_cd[c], AL_FORMAT_STEREO_FLOAT32, cd_buf, CD_BUFLEN * 2 * sizeof(float), CD_FREQ); diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 58422a288..929574dce 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -25,83 +25,91 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/snd_ac97.h> +#include <86box/plat_fallthrough.h> static const struct { - const uint32_t vendor_id, min_rate, max_rate, misc_flags; /* definitions for misc_flags in snd_ac97.h */ - const uint16_t reset_flags, extid_flags, /* definitions in snd_ac97.h */ - powerdown_mask; /* bits [7:0] => register 26 bits [15:8]; bits [11:8] => register 2A bits [14:11] */ - const ac97_vendor_reg_t *vendor_regs; /* bits [11:8] of index are the page number if applicable (registers [60:6F]) */ - const device_t *device; + const device_t *device; + + /* Definitions for *_flags and vendor_regs in snd_ac97.h */ + uint32_t min_rate; + uint32_t max_rate; + uint32_t misc_flags; + uint16_t reset_flags; + uint16_t extid_flags; + uint8_t pcsr_mask; /* register 26 bits [15:8] */ + uint8_t eascr_mask; /* register 2A bits [14:11] */ + + const ac97_vendor_reg_t *vendor_regs; } ac97_codecs[] = { // clang-format off - [AC97_CODEC_AD1881] = { - .vendor_id = AC97_VENDOR_ID('A', 'D', 'S', 0x40), + { + .device = &ad1881_device, .min_rate = 7000, .max_rate = 48000, .misc_flags = AC97_MASTER_6B | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_POP | AC97_MS | AC97_LPBK, .reset_flags = (1 << AC97_3D_SHIFT), /* datasheet contradicts itself on AC97_HPOUT */ .extid_flags = AC97_VRA, - .powerdown_mask = 0x0bf, - .vendor_regs = (const ac97_vendor_reg_t[]) {{0x74, 0x0000, 0xff07}, {0x76, 0x0404, 0xdde5}, {0x78, 48000, 0x0000}, {0x7a, 48000, 0x0000}, {0}}, - .device = &ad1881_device + .pcsr_mask = 0xbf, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x74, 0x0000, 0xff07}, {0, 0x76, 0x0404, 0xdde5}, {0, 0x78, 48000, 0x0000}, {0, 0x7a, 48000, 0x0000}, {0}} }, - [AC97_CODEC_AK4540] = { - .vendor_id = AC97_VENDOR_ID('A', 'K', 'M', 0x00), + { + .device = &ak4540_device, .misc_flags = AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, - .powerdown_mask = 0x01f, - .device = &ak4540_device + .pcsr_mask = 0x1f }, - [AC97_CODEC_ALC100] = { - .vendor_id = AC97_VENDOR_ID('A', 'L', 'C', 0x20), + { + .device = &alc100_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_POP | AC97_MS | AC97_LPBK, .reset_flags = (22 << AC97_3D_SHIFT), .extid_flags = AC97_AMAP, - .powerdown_mask = 0x0bf, - .device = &alc100_device + .pcsr_mask = 0xbf }, - [AC97_CODEC_CS4297] = { - .vendor_id = AC97_VENDOR_ID('C', 'R', 'Y', 0x03), + { + .device = &cs4297_device, .misc_flags = AC97_MASTER_6B | AC97_AUXOUT | AC97_AUXOUT_6B | AC97_MONOOUT | AC97_MONOOUT_6B | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = AC97_HPOUT | AC97_DAC_18B | AC97_ADC_18B, .extid_flags = 0, - .powerdown_mask = 0x07f, - .vendor_regs = (const ac97_vendor_reg_t[]) {{0x5a, 0x0301, 0x0000}, {0}}, - .device = &cs4297_device + .pcsr_mask = 0x7f, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x5a, 0x0301, 0x0000}, {0}} }, - [AC97_CODEC_CS4297A] = { - .vendor_id = AC97_VENDOR_ID('C', 'R', 'Y', 0x11), + { + .device = &cs4297a_device, .misc_flags = AC97_MASTER_6B | AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = AC97_HPOUT | AC97_DAC_20B | AC97_ADC_18B | (6 << AC97_3D_SHIFT), .extid_flags = AC97_AMAP, - .powerdown_mask = 0x0ff, - .vendor_regs = (const ac97_vendor_reg_t[]) {{0x5e, 0x0000, 0x01b0}, {0x60, 0x0023, 0x0001}, {0x68, 0x0000, 0xdfff}, {0}}, - .device = &cs4297a_device + .pcsr_mask = 0xff, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x5e, 0x0000, 0x01b0}, {0, 0x60, 0x0023, 0x0001}, {0, 0x68, 0x0000, 0xdfff}, {0}} }, - [AC97_CODEC_STAC9708] = { - .vendor_id = AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x08), + { + .device = &stac9708_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = (26 << AC97_3D_SHIFT) | AC97_DAC_18B | AC97_ADC_18B, .extid_flags = AC97_SDAC, - .powerdown_mask = 0x2ff, - .vendor_regs = (const ac97_vendor_reg_t []) {{0x6c, 0x0000, 0x0003}, {0x74, 0x0000, 0x0003}, {0}}, - .device = &stac9708_device + .pcsr_mask = 0xff, + .eascr_mask = 0x02, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x6c, 0x0000, 0x0003}, {0, 0x74, 0x0000, 0x0003}, {0}} }, - [AC97_CODEC_STAC9721] = { - .vendor_id = AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x09), + { + .device = &stac9721_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = (26 << AC97_3D_SHIFT) | AC97_DAC_18B | AC97_ADC_18B, .extid_flags = AC97_AMAP, - .powerdown_mask = 0x0ff, - .vendor_regs = (const ac97_vendor_reg_t []) {{0x6c, 0x0000, 0x0000}, {0x6e, 0x0000, 0x0003}, {0x70, 0x0000, 0xffff}, {0x72, 0x0000, 0x0006}, {0x74, 0x0000, 0x0003}, {0x76, 0x0000, 0xffff}, {0x78, 0x0000, 0x3802}, {0}}, - .device = &stac9721_device + .pcsr_mask = 0xff, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x6c, 0x0000, 0x0000}, {0, 0x6e, 0x0000, 0x0003}, {0, 0x70, 0x0000, 0xffff}, {0, 0x72, 0x0000, 0x0006}, {0, 0x74, 0x0000, 0x0003}, {0, 0x76, 0x0000, 0xffff}, {0, 0x78, 0x0000, 0x3802}, {0}} }, - [AC97_CODEC_WM9701A] = { - .vendor_id = AC97_VENDOR_ID('W', 'M', 'L', 0x00), + { + .device = &tr28023_device, + .misc_flags = AC97_MASTER_6B | AC97_MONOOUT | AC97_MONOOUT_6B | AC97_PCBEEP | AC97_PHONE | AC97_POP | AC97_MS | AC97_LPBK, + .reset_flags = 0, + .extid_flags = 0, + .pcsr_mask = 0x3f + }, + { + .device = &wm9701a_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = AC97_DAC_18B | AC97_ADC_18B, .extid_flags = 0, - .powerdown_mask = 0x03f, - .device = &wm9701a_device + .pcsr_mask = 0x3f } // clang-format on }; @@ -134,9 +142,12 @@ static const int32_t codec_attn[] = { // clang-format on }; -ac97_codec_t **ac97_codec = NULL, **ac97_modem_codec = NULL; -int ac97_codec_count = 0, ac97_modem_codec_count = 0, - ac97_codec_id = 0, ac97_modem_codec_id = 0; +ac97_codec_t **ac97_codec = NULL; +ac97_codec_t **ac97_modem_codec = NULL; +int ac97_codec_count = 0; +int ac97_modem_codec_count = 0; +int ac97_codec_id = 0; +int ac97_modem_codec_id = 0; uint16_t ac97_codec_readw(ac97_codec_t *dev, uint8_t reg) @@ -160,7 +171,8 @@ ac97_codec_writew(ac97_codec_t *dev, uint8_t reg, uint16_t val) ac97_codec_log("AC97 Codec %d: writew(%02X, %04X)\n", dev->codec_id, reg, val); reg &= 0x7e; - uint16_t i = 0, prev = dev->regs[reg >> 1]; + uint16_t i = 0; + uint16_t prev = dev->regs[reg >> 1]; int j; switch (reg) { @@ -172,7 +184,7 @@ ac97_codec_writew(ac97_codec_t *dev, uint8_t reg, uint16_t val) val &= 0xbf3f; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_MASTER_6B)) { + if (!(ac97_codecs[dev->model].misc_flags & AC97_MASTER_6B)) { clamp_5b: if (val & 0x2000) val = (val & ~0x2000) | 0x1f00; @@ -183,41 +195,41 @@ clamp_5b_r: break; case 0x04: /* Aux Out Volume */ - if (!(dev->misc_flags & AC97_AUXOUT)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_AUXOUT)) return; val &= 0xbf3f; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_AUXOUT_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_AUXOUT_6B)) goto clamp_5b; break; case 0x06: /* Mono Out Volume */ - if (!(dev->misc_flags & AC97_MONOOUT)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_MONOOUT)) return; val &= 0x803f; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_MONOOUT_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_MONOOUT_6B)) goto clamp_5b_r; break; case 0x08: /* Master Tone Control */ - if (!(dev->reset_flags & AC97_TONECTL)) + if (!(ac97_codecs[dev->model].reset_flags & AC97_TONECTL)) return; val &= 0x0f0f; break; case 0x0a: /* PC Beep Volume */ - if (dev->misc_flags & AC97_PCBEEP) + if (ac97_codecs[dev->model].misc_flags & AC97_PCBEEP) i |= 0x801e; - if (dev->misc_flags & AC97_PCBEEP_GEN) + if (ac97_codecs[dev->model].misc_flags & AC97_PCBEEP_GEN) i |= 0x1fe0; val &= i; break; case 0x0c: /* Phone Volume */ - if (!(dev->misc_flags & AC97_PHONE)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_PHONE)) return; val &= 0x801f; break; @@ -234,12 +246,12 @@ line_gain: break; case 0x14: /* Video Volume */ - if (!(dev->misc_flags & AC97_VIDEO)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_VIDEO)) return; goto line_gain; case 0x16: /* Aux In Volume */ - if (!(dev->misc_flags & AC97_AUXIN)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_AUXIN)) return; goto line_gain; @@ -252,26 +264,26 @@ line_gain: break; case 0x1e: /* Record Gain Mic */ - if (!(dev->reset_flags & AC97_MICPCM)) + if (!(ac97_codecs[dev->model].reset_flags & AC97_MICPCM)) return; val &= 0x800f; break; case 0x20: /* General Purpose */ - i = AC97_MIX | (dev->misc_flags & (AC97_POP | AC97_MS | AC97_LPBK)); - if (dev->reset_flags >> AC97_3D_SHIFT) + i = AC97_MIX | (ac97_codecs[dev->model].misc_flags & (AC97_POP | AC97_MS | AC97_LPBK)); + if (ac97_codecs[dev->model].reset_flags >> AC97_3D_SHIFT) i |= AC97_3D; - if (dev->reset_flags & AC97_SIMSTEREO) + if (ac97_codecs[dev->model].reset_flags & AC97_SIMSTEREO) i |= AC97_ST; - if (dev->reset_flags & AC97_LOUDNESS) + if (ac97_codecs[dev->model].reset_flags & AC97_LOUDNESS) i |= AC97_LD; - if (dev->extid_flags & AC97_DRA) + if (ac97_codecs[dev->model].extid_flags & AC97_DRA) i |= AC97_DRSS_MASK; val &= i; break; - case 0x22: /* 3D Control */ - switch (dev->reset_flags >> AC97_3D_SHIFT) { + case 0x22: /* 3D Control */ + switch (ac97_codecs[dev->model].reset_flags >> AC97_3D_SHIFT) { case 1: /* Analog Devices */ case 6: /* Crystal */ val &= 0x000f; @@ -283,7 +295,7 @@ line_gain: case 26: /* SigmaTel */ i = 0x0003; - if (dev->extid_flags & AC97_SDAC) + if (ac97_codecs[dev->model].extid_flags & AC97_SDAC) i |= 0x000c; val &= i; break; @@ -294,13 +306,13 @@ line_gain: break; case 0x24: /* Audio Interrupt and Paging Mechanism */ - if ((dev->extid_flags & AC97_REV_MASK) < AC97_REV_2_3) + if ((ac97_codecs[dev->model].extid_flags & AC97_REV_MASK) < AC97_REV_2_3) return; val &= 0x000f; break; case 0x26: /* Powerdown Control/Status */ - i = dev->powerdown_mask << 8; + i = ac97_codecs[dev->model].pcsr_mask << 8; val = (val & i) | (prev & ~i); /* Update status bits to reflect powerdowns. */ @@ -310,16 +322,16 @@ line_gain: break; case 0x28: /* Extended Audio ID */ - if (dev->misc_flags & AC97_DSA) + if (ac97_codecs[dev->model].misc_flags & AC97_DSA) i |= 0x0030; val = (val & i) | (prev & ~i); break; case 0x2a: /* Extended Audio Status/Control */ - i = dev->extid_flags & (AC97_VRA | AC97_DRA | AC97_SPDIF | AC97_VRM); - if (dev->extid_flags & AC97_SPDIF) + i = ac97_codecs[dev->model].extid_flags & (AC97_VRA | AC97_DRA | AC97_SPDIF | AC97_VRM); + if (ac97_codecs[dev->model].extid_flags & AC97_SPDIF) i |= AC97_SPSA_MASK << AC97_SPSA_SHIFT; - i |= (dev->powerdown_mask << 3) & 0x7800; /* multichannel powerdowns */ + i |= (ac97_codecs[dev->model].eascr_mask << 11) & 0x7800; val = (val & i) | (prev & ~i); /* Reset DAC sample rates to 48 KHz (96 KHz with DRA) if VRA is being cleared. */ @@ -339,57 +351,57 @@ line_gain: case 0x32: /* PCM L/R ADC Rate */ rate: /* Writable only if VRA/VRM is set. */ i = (reg >= 0x32) ? AC97_VRM : AC97_VRA; - if (!(dev->extid_flags & i)) + if (!(ac97_codecs[dev->model].extid_flags & i)) return; /* Limit to supported sample rate range. */ - if (val < dev->min_rate) - val = dev->min_rate; - else if (val > dev->max_rate) - val = dev->max_rate; + if (val < ac97_codecs[dev->model].min_rate) + val = ac97_codecs[dev->model].min_rate; + else if (val > ac97_codecs[dev->model].max_rate) + val = ac97_codecs[dev->model].max_rate; break; case 0x2e: /* PCM Surround DAC Rate */ - if (!(dev->extid_flags & AC97_SDAC)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_SDAC)) return; goto rate; case 0x30: /* PCM LFE DAC Rate */ - if (!(dev->extid_flags & AC97_LDAC)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_LDAC)) return; goto rate; case 0x34: /* Mic ADC Rate */ - if (!(dev->reset_flags & AC97_MICPCM)) + if (!(ac97_codecs[dev->model].reset_flags & AC97_MICPCM)) return; goto rate; case 0x36: /* Center/LFE Volume */ - if (dev->extid_flags & AC97_LDAC) + if (ac97_codecs[dev->model].extid_flags & AC97_LDAC) i |= 0xbf00; - if (dev->extid_flags & AC97_CDAC) + if (ac97_codecs[dev->model].extid_flags & AC97_CDAC) i |= 0x00bf; val &= i; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_LFE_6B) && (val & 0x2000)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_LFE_6B) && (val & 0x2000)) val = (val & ~0x2000) | 0x1f00; - if (!(dev->misc_flags & AC97_CENTER_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_CENTER_6B)) goto clamp_5b_r; break; case 0x38: /* Surround Volume */ - if (!(dev->extid_flags & AC97_SDAC)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_SDAC)) return; val &= 0xbfbf; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_SURR_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_SURR_6B)) goto clamp_5b; break; case 0x3a: /* S/PDIF Control */ - if (!(dev->extid_flags & AC97_SPDIF)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_SPDIF)) return; break; @@ -406,32 +418,30 @@ rate: /* Writable only if VRA/VRM is set. */ /* Get actual previous value. */ prev = dev->vendor_reg_pages[(i << 3) | ((reg & 0x0e) >> 1)]; } - - i <<= 8; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x5a ... 0x5e: /* Vendor Reserved */ case 0x70 ... 0x7a: /* Stop if no vendor-specific registers are defined. */ - if (!dev->vendor_regs) + if (!ac97_codecs[dev->model].vendor_regs) return; /* Look for a matching vendor-specific register. */ - i |= reg; - for (j = 0; dev->vendor_regs[j].index; j++) { + for (j = 0; ac97_codecs[dev->model].vendor_regs[j].index; j++) { /* If a match was found, inject written bits. */ - if (dev->vendor_regs[j].index == i) { - val = (val & dev->vendor_regs[j].write_mask) | (prev & ~dev->vendor_regs[j].write_mask); + if ((ac97_codecs[dev->model].vendor_regs[j].page == i) && (ac97_codecs[dev->model].vendor_regs[j].index == reg)) { + val = (val & ac97_codecs[dev->model].vendor_regs[j].write_mask) | (prev & ~ac97_codecs[dev->model].vendor_regs[j].write_mask); break; } } /* No match found. */ - if (!dev->vendor_regs[j].index) + if (!ac97_codecs[dev->model].vendor_regs[j].index) return; /* Redirect a write to page 1+ to the right array, part 2. */ - i >>= 8; if (i > 0) { dev->vendor_reg_pages[(i << 3) | ((reg & 0x0e) >> 1)] = val; return; @@ -441,6 +451,9 @@ rate: /* Writable only if VRA/VRM is set. */ case 0x7c: /* Vendor ID1 */ case 0x7e: /* Vendor ID2 */ return; + + default: + break; } dev->regs[reg >> 1] = val; @@ -450,7 +463,7 @@ void ac97_codec_reset(void *priv) { ac97_codec_t *dev = (ac97_codec_t *) priv; - uint16_t i, j; + uint16_t i; ac97_codec_log("AC97 Codec %d: reset()\n", dev->codec_id); @@ -458,52 +471,51 @@ ac97_codec_reset(void *priv) /* Set default level and gain values. */ dev->regs[0x02 >> 1] = AC97_MUTE; - if (dev->misc_flags & AC97_AUXOUT) + if (ac97_codecs[dev->model].misc_flags & AC97_AUXOUT) dev->regs[0x04 >> 1] = AC97_MUTE; - if (dev->misc_flags & AC97_MONOOUT) + if (ac97_codecs[dev->model].misc_flags & AC97_MONOOUT) dev->regs[0x06 >> 1] = AC97_MUTE; - if (dev->misc_flags & AC97_PHONE) + if (ac97_codecs[dev->model].misc_flags & AC97_PHONE) dev->regs[0x0c >> 1] = AC97_MUTE | 0x0008; dev->regs[0x0e >> 1] = AC97_MUTE | 0x0008; /* mic */ dev->regs[0x10 >> 1] = dev->regs[0x12 >> 1] = dev->regs[0x18 >> 1] = AC97_MUTE | 0x0808; /* line in, CD, PCM out */ - if (dev->misc_flags & AC97_VIDEO) + if (ac97_codecs[dev->model].misc_flags & AC97_VIDEO) dev->regs[0x14 >> 1] = AC97_MUTE | 0x0808; - if (dev->misc_flags & AC97_AUXIN) + if (ac97_codecs[dev->model].misc_flags & AC97_AUXIN) dev->regs[0x14 >> 1] = AC97_MUTE | 0x0808; - dev->regs[0x1c >> 1] = AC97_MUTE; /* record gain */ - if (dev->reset_flags & AC97_MICPCM) + dev->regs[0x1c >> 1] = AC97_MUTE; /* record gain */ + if (ac97_codecs[dev->model].reset_flags & AC97_MICPCM) dev->regs[0x1e >> 1] = AC97_MUTE; /* mic record gain */ - if (dev->misc_flags & AC97_LDAC) + if (ac97_codecs[dev->model].misc_flags & AC97_LDAC) dev->regs[0x36 >> 1] = AC97_MUTE_L; - if (dev->misc_flags & AC97_CDAC) + if (ac97_codecs[dev->model].misc_flags & AC97_CDAC) dev->regs[0x36 >> 1] |= AC97_MUTE_R; - if (dev->misc_flags & AC97_SDAC) + if (ac97_codecs[dev->model].misc_flags & AC97_SDAC) dev->regs[0x38 >> 1] = AC97_MUTE_L | AC97_MUTE_R; /* Set flags. */ - dev->regs[0x00 >> 1] = dev->reset_flags; - dev->regs[0x26 >> 1] = 0x000f; /* codec ready */ - dev->regs[0x28 >> 1] = (dev->codec_id << 14) | dev->extid_flags; + dev->regs[0x00 >> 1] = ac97_codecs[dev->model].reset_flags; + dev->regs[0x26 >> 1] = 0x000f; /* codec ready */ + dev->regs[0x28 >> 1] = (dev->codec_id << 14) | ac97_codecs[dev->model].extid_flags; ac97_codec_writew(dev, 0x2a, 0x0000); /* reset variable DAC/ADC sample rates */ - i = dev->extid_flags & (AC97_CDAC | AC97_SDAC | AC97_LDAC); + i = ac97_codecs[dev->model].extid_flags & (AC97_CDAC | AC97_SDAC | AC97_LDAC); dev->regs[0x2a >> 1] |= i | (i << 5); /* any additional DACs are ready but powered down */ - if (dev->extid_flags & AC97_SPDIF) + if (ac97_codecs[dev->model].extid_flags & AC97_SPDIF) dev->regs[0x2a >> 1] |= AC97_SPCV; - if (dev->reset_flags & AC97_MICPCM) + if (ac97_codecs[dev->model].reset_flags & AC97_MICPCM) dev->regs[0x2a >> 1] |= AC97_MADC | AC97_PRL; /* Set vendor ID. */ - dev->regs[0x7c >> 1] = dev->vendor_id >> 16; - dev->regs[0x7e >> 1] = dev->vendor_id; + dev->regs[0x7c >> 1] = ac97_codecs[dev->model].device->local >> 16; + dev->regs[0x7e >> 1] = ac97_codecs[dev->model].device->local; /* Set vendor-specific registers. */ - if (dev->vendor_regs) { - for (j = 0; dev->vendor_regs[j].index; j++) { - i = (dev->vendor_regs[j].index >> 8) & 0x000f; - if (i > 0) - dev->vendor_reg_pages[(i << 3) | (dev->vendor_regs[j].index >> 1)] = dev->vendor_regs[j].value; + if (ac97_codecs[dev->model].vendor_regs) { + for (i = 0; ac97_codecs[dev->model].vendor_regs[i].index; i++) { + if (ac97_codecs[dev->model].vendor_regs[i].page > 0) + dev->vendor_reg_pages[(ac97_codecs[dev->model].vendor_regs[i].page << 3) | (ac97_codecs[dev->model].vendor_regs[i].index >> 1)] = ac97_codecs[dev->model].vendor_regs[i].value; else - dev->regs[dev->vendor_regs[j].index >> 1] = dev->vendor_regs[j].value; + dev->regs[ac97_codecs[dev->model].vendor_regs[i].index >> 1] = ac97_codecs[dev->model].vendor_regs[i].value; } } } @@ -511,8 +523,8 @@ ac97_codec_reset(void *priv) void ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) { - ac97_codec_t *dev = (ac97_codec_t *) priv; - uint16_t val = dev->regs[reg >> 1]; + const ac97_codec_t *dev = (ac97_codec_t *) priv; + uint16_t val = dev->regs[reg >> 1]; /* Apply full mute and powerdowns. */ int full_mute = (reg < 0x36); @@ -523,7 +535,8 @@ ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) *r = 0; } else { /* per-channel mute */ /* Determine attenuation value. */ - uint8_t l_val = val >> 8, r_val = val; + uint8_t l_val = val >> 8; + uint8_t r_val = val; if (reg <= 0x06) { /* 6-bit level */ *l = codec_attn[0x3f - (l_val & 0x3f)]; *r = codec_attn[0x3f - (r_val & 0x3f)]; @@ -549,7 +562,7 @@ ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) uint32_t ac97_codec_getrate(void *priv, uint8_t reg) { - ac97_codec_t *dev = (ac97_codec_t *) priv; + const ac97_codec_t *dev = (ac97_codec_t *) priv; /* Get configured sample rate, which is always 48000 if VRA/VRM is not set. */ uint32_t ret = dev->regs[reg >> 1]; @@ -569,19 +582,23 @@ ac97_codec_init(const device_t *info) ac97_codec_t *dev = malloc(sizeof(ac97_codec_t)); memset(dev, 0, sizeof(ac97_codec_t)); - dev->vendor_id = ac97_codecs[info->local].vendor_id; - dev->min_rate = ac97_codecs[info->local].min_rate; - dev->max_rate = ac97_codecs[info->local].max_rate; - dev->reset_flags = ac97_codecs[info->local].reset_flags; - dev->extid_flags = ac97_codecs[info->local].extid_flags; - dev->misc_flags = ac97_codecs[info->local].misc_flags; - dev->powerdown_mask = ac97_codecs[info->local].powerdown_mask; - dev->vendor_regs = ac97_codecs[info->local].vendor_regs; - ac97_codec_log("AC97 Codec %d: init(%c%c%c%02X)\n", ac97_codec_id, (dev->vendor_id >> 24) & 0xff, (dev->vendor_id >> 16) & 0xff, (dev->vendor_id >> 8) & 0xff, dev->vendor_id & 0xff); + for (; dev->model < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])); dev->model++) { + if (ac97_codecs[dev->model].device->local == info->local) + break; + } + if (dev->model >= (sizeof(ac97_codecs) / sizeof(ac97_codecs[0]))) { + fatal("AC97 Codec %d: Unknown ID %c%c%c%02X\n", ac97_codec_id, (info->local >> 24) & 0xff, (info->local >> 16) & 0xff, (info->local >> 8) & 0xff, info->local & 0xff); + free(dev); + return NULL; + } + ac97_codec_log("AC97 Codec %d: init(%c%c%c%02X)\n", ac97_codec_id, + (ac97_codecs[dev->model].device->local >> 24) & 0xff, (ac97_codecs[dev->model].device->local >> 16) & 0xff, + (ac97_codecs[dev->model].device->local >> 8) & 0xff, ac97_codecs[dev->model].device->local & 0xff); /* Associate this codec to the current controller. */ if (!ac97_codec || (ac97_codec_count <= 0)) { pclog("AC97 Codec %d: No controller to associate codec\n", ac97_codec_id); + free(dev); return NULL; } *ac97_codec = dev; @@ -592,20 +609,17 @@ ac97_codec_init(const device_t *info) dev->codec_id = ac97_codec_id++; /* Allocate vendor-specific register pages if required. */ - if (dev->vendor_regs) { + if (ac97_codecs[dev->model].vendor_regs) { /* Get the highest vendor-specific register page number. */ - int i, j; - dev->vendor_reg_page_max = 0; - for (j = 0; dev->vendor_regs[j].index; j++) { - i = (dev->vendor_regs[j].index >> 8) & 0x000f; - if (i > dev->vendor_reg_page_max) - dev->vendor_reg_page_max = i; + for (uint16_t i = 0; ac97_codecs[dev->model].vendor_regs[i].index; i++) { + if (ac97_codecs[dev->model].vendor_regs[i].page > dev->vendor_reg_page_max) + dev->vendor_reg_page_max = ac97_codecs[dev->model].vendor_regs[i].page; } /* Allocate pages 1+. */ if (dev->vendor_reg_page_max > 0) { ac97_codec_log("AC97 Codec %d: Allocating %d vendor-specific register pages\n", dev->codec_id, dev->vendor_reg_page_max); - i = 16 * dev->vendor_reg_page_max; + int i = 16 * dev->vendor_reg_page_max; dev->vendor_reg_pages = (uint16_t *) malloc(i); memset(dev->vendor_reg_pages, 0, i); } @@ -632,12 +646,13 @@ ac97_codec_close(void *priv) } const device_t * -ac97_codec_get(int model) +ac97_codec_get(uint32_t id) { - if ((model >= 0) && (model < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])))) - return ac97_codecs[model].device; - else - return &cs4297a_device; /* fallback */ + for (int i = 0; i < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])); i++) { + if (ac97_codecs[i].device->local == id) + return ac97_codecs[i].device; + } + return &tr28023_device; /* fallback */ } const device_t ad1881_device = { @@ -738,6 +753,20 @@ const device_t stac9721_device = { .config = NULL }; +const device_t tr28023_device = { + .name = "TriTech TR28023 / Creative CT1297", + .internal_name = "tr28023", + .flags = DEVICE_AC97, + .local = AC97_CODEC_TR28023, + .init = ac97_codec_init, + .close = ac97_codec_close, + .reset = ac97_codec_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + const device_t wm9701a_device = { .name = "Wolfson WM9701A", .internal_name = "wm9701a", diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 8e611ed44..e074d17e2 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -30,38 +30,59 @@ #include <86box/snd_ac97.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> -typedef struct { - uint8_t id, always_run; +typedef struct ac97_via_sgd_t { + uint8_t id; + uint8_t always_run; struct _ac97_via_ *dev; - uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; + uint32_t entry_ptr; + uint32_t sample_ptr; + uint32_t fifo_pos; + uint32_t fifo_end; int32_t sample_count; - uint8_t entry_flags, fifo[32], restart; + uint8_t entry_flags; + uint8_t fifo[32]; + uint8_t restart; - int16_t out_l, out_r; - int vol_l, vol_r, pos; + int16_t out_l; + int16_t out_r; + int vol_l; + int vol_r; + int pos; int32_t buffer[SOUNDBUFLEN * 2]; uint64_t timer_latch; - pc_timer_t dma_timer, poll_timer; + pc_timer_t dma_timer; + pc_timer_t poll_timer; } ac97_via_sgd_t; typedef struct _ac97_via_ { - uint16_t audio_sgd_base, audio_codec_base, modem_sgd_base, modem_codec_base; - uint8_t sgd_regs[256], pcm_enabled : 1, fm_enabled : 1, vsr_enabled : 1; + uint16_t audio_sgd_base; + uint16_t audio_codec_base; + uint16_t modem_sgd_base; + uint16_t modem_codec_base; + uint8_t sgd_regs[256]; + uint8_t pcm_enabled : 1; + uint8_t fm_enabled : 1; + uint8_t vsr_enabled : 1; struct { union { uint8_t regs_codec[2][128]; uint8_t regs_linear[256]; }; } codec_shadow[2]; - int slot, irq_pin; + int slot; + int irq_pin; ac97_codec_t *codec[2][2]; ac97_via_sgd_t sgd[6]; - int master_vol_l, master_vol_r, cd_vol_l, cd_vol_r; + int master_vol_l; + int master_vol_r; + int cd_vol_l; + int cd_vol_r; } ac97_via_t; #ifdef ENABLE_AC97_VIA_LOG @@ -101,8 +122,8 @@ ac97_via_set_slot(void *priv, int slot, int irq_pin) uint8_t ac97_via_read_status(void *priv, uint8_t modem) { - ac97_via_t *dev = (ac97_via_t *) priv; - uint8_t ret = 0x00; + const ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t ret = 0x00; /* Flag each codec as ready if present. */ for (uint8_t i = 0; i <= 1; i++) { @@ -178,6 +199,7 @@ ac97_via_update_codec(ac97_via_t *dev) /* Update volumes according to codec registers. */ ac97_codec_getattn(codec, 0x02, &dev->master_vol_l, &dev->master_vol_r); ac97_codec_getattn(codec, 0x18, &dev->sgd[0].vol_l, &dev->sgd[0].vol_r); + ac97_codec_getattn(codec, 0x18, &dev->sgd[2].vol_l, &dev->sgd[2].vol_r); /* VIAFMTSR sets Master, CD and PCM volumes to 0 dB */ ac97_codec_getattn(codec, 0x12, &dev->cd_vol_l, &dev->cd_vol_r); /* Update sample rate according to codec registers and the variable sample rate flag. */ @@ -187,7 +209,7 @@ ac97_via_update_codec(ac97_via_t *dev) uint8_t ac97_via_sgd_read(uint16_t addr, void *priv) { - ac97_via_t *dev = (ac97_via_t *) priv; + const ac97_via_t *dev = (ac97_via_t *) priv; #ifdef ENABLE_AC97_VIA_LOG uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base; #endif @@ -283,7 +305,8 @@ void ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; - uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base, i; + uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base; + uint8_t i; ac97_codec_t *codec; addr &= 0xff; @@ -315,13 +338,11 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) dev->sgd_regs[addr & 0xf0] |= 0x08; } else { /* Start SGD immediately. */ - dev->sgd_regs[addr & 0xf0] |= 0x80; - dev->sgd_regs[addr & 0xf0] &= ~0x44; + dev->sgd_regs[addr & 0xf0] = (dev->sgd_regs[addr & 0xf0] & ~0x47) | 0x80; /* Start at the specified entry pointer. */ - dev->sgd[addr >> 4].sample_ptr = 0; dev->sgd[addr >> 4].entry_ptr = *((uint32_t *) &dev->sgd_regs[(addr & 0xf0) | 0x4]) & 0xfffffffe; - dev->sgd[addr >> 4].restart = 1; + dev->sgd[addr >> 4].restart = 2; /* Start the actual SGD process. */ ac97_via_sgd_process(&dev->sgd[addr >> 4]); @@ -350,6 +371,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) case 0x8 ... 0xf: /* Read-only registers. */ return; + + default: + break; } } else { /* Process regular registers. */ @@ -404,6 +428,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) val = dev->sgd_regs[addr] | (val & 0xc0); #endif break; + + default: + break; } } @@ -441,10 +468,11 @@ ac97_via_remap_modem_sgd(void *priv, uint16_t new_io_base, uint8_t enable) uint8_t ac97_via_codec_read(uint16_t addr, void *priv) { - ac97_via_t *dev = (ac97_via_t *) priv; - uint8_t modem = (addr & 0xff00) == dev->modem_codec_base; + const ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t modem = (addr & 0xff00) == dev->modem_codec_base; + uint8_t ret = 0xff; + addr &= 0xff; - uint8_t ret = 0xff; ret = dev->codec_shadow[modem].regs_linear[addr]; @@ -497,8 +525,8 @@ ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable) static void ac97_via_update_stereo(ac97_via_t *dev, ac97_via_sgd_t *sgd) { - int32_t l = (((sgd->out_l * sgd->vol_l) >> 15) * dev->master_vol_l) >> 15, - r = (((sgd->out_r * sgd->vol_r) >> 15) * dev->master_vol_r) >> 15; + int32_t l = (((sgd->out_l * sgd->vol_l) >> 15) * dev->master_vol_l) >> 15; + int32_t r = (((sgd->out_r * sgd->vol_r) >> 15) * dev->master_vol_r) >> 15; if (l < -32768) l = -32768; @@ -530,15 +558,14 @@ ac97_via_sgd_process(void *priv) timer_on_auto(&sgd->dma_timer, 10.0); /* Process SGD if it's active, and the FIFO has room or is disabled. */ - if ((sgd_status == 0x80) && (sgd->always_run || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { + if (((sgd_status & 0xc7) == 0x80) && (sgd->always_run || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { /* Move on to the next block if no entry is present. */ if (sgd->restart) { + /* (Re)load entry pointer if required. */ + if (sgd->restart & 2) + sgd->entry_ptr = *((uint32_t *) &dev->sgd_regs[sgd->id | 0x4]) & 0xfffffffe; /* TODO: probe real hardware - does "even addr" actually mean dword aligned? */ sgd->restart = 0; - /* Start at first entry if no pointer is present. */ - if (!sgd->entry_ptr) - sgd->entry_ptr = *((uint32_t *) &dev->sgd_regs[sgd->id | 0x4]) & 0xfffffffe; - /* Read entry. */ sgd->sample_ptr = mem_readl_phys(sgd->entry_ptr); sgd->entry_ptr += 4; @@ -573,6 +600,9 @@ ac97_via_sgd_process(void *priv) if (sgd->sample_count <= 0) { ac97_via_log("AC97 VIA: Ending SGD %d block", sgd->id >> 4); + /* Move on to the next block on the next run, unless overridden below. */ + sgd->restart = 1; + if (sgd->entry_flags & 0x20) { ac97_via_log(" with STOP"); @@ -583,8 +613,8 @@ ac97_via_sgd_process(void *priv) if (sgd->entry_flags & 0x40) { ac97_via_log(" with FLAG"); - /* Raise FLAG and STOP. */ - dev->sgd_regs[sgd->id] |= 0x05; + /* Raise FLAG to pause SGD. */ + dev->sgd_regs[sgd->id] |= 0x01; #ifdef ENABLE_AC97_VIA_LOG if (dev->sgd_regs[sgd->id | 0x2] & 0x01) @@ -610,8 +640,8 @@ ac97_via_sgd_process(void *priv) /* Un-queue trigger. */ dev->sgd_regs[sgd->id] &= ~0x08; - /* Go back to the starting block. */ - sgd->entry_ptr = 0; /* ugly, but Windows XP plays too fast if the pointer is reloaded now */ + /* Go back to the starting block on the next run. */ + sgd->restart = 2; } else { ac97_via_log(" finish"); @@ -623,9 +653,6 @@ ac97_via_sgd_process(void *priv) /* Fire any requested status interrupts. */ ac97_via_update_irqs(dev); - - /* Move on to a new block on the next run. */ - sgd->restart = 1; } } } @@ -677,6 +704,9 @@ ac97_via_poll_stereo(void *priv) return; } break; + + default: + break; } /* Feed silence if the FIFO is empty. */ @@ -729,8 +759,9 @@ ac97_via_get_buffer(int32_t *buffer, int len, void *priv) static void ac97_via_filter_cd_audio(int channel, double *buffer, void *priv) { - ac97_via_t *dev = (ac97_via_t *) priv; - double c, volume = channel ? dev->cd_vol_r : dev->cd_vol_l; + const ac97_via_t *dev = (ac97_via_t *) priv; + double c; + double volume = channel ? dev->cd_vol_r : dev->cd_vol_l; c = ((*buffer) * volume) / 65536.0; *buffer = c; @@ -749,11 +780,11 @@ ac97_via_speed_changed(void *priv) freq = (double) SOUND_FREQ; dev->sgd[0].timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / freq)); - dev->sgd[2].timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 24000.0)); + dev->sgd[2].timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 24000.0)); /* FM operates at a fixed 24 KHz */ } static void * -ac97_via_init(const device_t *info) +ac97_via_init(UNUSED(const device_t *info)) { ac97_via_t *dev = malloc(sizeof(ac97_via_t)); memset(dev, 0, sizeof(ac97_via_t)); @@ -775,10 +806,6 @@ ac97_via_init(const device_t *info) if ((i != 0) && (i != 2)) dev->sgd[i].always_run = 1; - /* No volume control on FM SGD that I know of. */ - if (i == 2) - dev->sgd[i].vol_l = dev->sgd[i].vol_r = 32767; - timer_add(&dev->sgd[i].dma_timer, ac97_via_sgd_process, &dev->sgd[i], 0); } diff --git a/src/sound/snd_ad1848.c b/src/sound/snd_ad1848.c index f9bc337c1..acc143636 100644 --- a/src/sound/snd_ad1848.c +++ b/src/sound/snd_ad1848.c @@ -30,6 +30,7 @@ #include <86box/timer.h> #include <86box/sound.h> #include <86box/snd_ad1848.h> +#include <86box/plat_fallthrough.h> #define CS4231 0x80 #define CS4236 0x03 @@ -48,9 +49,9 @@ ad1848_setirq(ad1848_t *ad1848, int irq) } void -ad1848_setdma(ad1848_t *ad1848, int dma) +ad1848_setdma(ad1848_t *ad1848, int newdma) { - ad1848->dma = dma; + ad1848->dma = newdma; } void @@ -65,8 +66,8 @@ ad1848_updatevolmask(ad1848_t *ad1848) static void ad1848_updatefreq(ad1848_t *ad1848) { - double freq; - uint8_t set = 0; + double freq = 0.0; + uint8_t set = 0; if (ad1848->type >= AD1848_TYPE_CS4235) { if (ad1848->xregs[11] & 0x20) { @@ -111,6 +112,9 @@ ad1848_updatefreq(ad1848_t *ad1848) case 0x20: freq /= 256 * set; break; + + default: + break; } set = 1; } @@ -143,6 +147,9 @@ ad1848_updatefreq(ad1848_t *ad1848) case 7: freq /= 2560; break; + + default: + break; } } @@ -194,12 +201,18 @@ ad1848_read(uint16_t addr, void *priv) ret = ad1848->xregs[ad1848->xindex]; } break; + + default: + break; } break; case 2: ret = ad1848->status; break; + + default: + break; } return ret; @@ -209,7 +222,8 @@ void ad1848_write(uint16_t addr, uint8_t val, void *priv) { ad1848_t *ad1848 = (ad1848_t *) priv; - uint8_t temp = 0, updatefreq = 0; + uint8_t temp = 0; + uint8_t updatefreq = 0; switch (addr & 3) { case 0: /* Index */ @@ -228,7 +242,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) case 10: if (ad1848->type < AD1848_TYPE_CS4235) break; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 8: updatefreq = 1; @@ -358,6 +374,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) case 25: return; + + default: + break; } ad1848->xregs[ad1848->xindex] = val; @@ -382,6 +401,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) if (ad1848->type != AD1848_TYPE_DEFAULT) return; break; + + default: + break; } ad1848->regs[ad1848->index] = val; @@ -405,6 +427,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) ad1848->status &= 0xfe; ad1848->regs[24] &= 0x0f; break; + + default: + break; } } @@ -560,6 +585,9 @@ ad1848_poll(void *priv) break; /* 0xe0 and 0xf0 reserved */ + + default: + break; } if (ad1848->regs[6] & 0x80) @@ -594,9 +622,9 @@ ad1848_poll(void *priv) void ad1848_filter_cd_audio(int channel, double *buffer, void *priv) { - ad1848_t *ad1848 = (ad1848_t *) priv; - double c; - double volume = channel ? ad1848->cd_vol_r : ad1848->cd_vol_l; + const ad1848_t *ad1848 = (ad1848_t *) priv; + double c; + double volume = channel ? ad1848->cd_vol_r : ad1848->cd_vol_l; c = ((*buffer) * volume) / 65536.0; *buffer = c; @@ -605,7 +633,7 @@ ad1848_filter_cd_audio(int channel, double *buffer, void *priv) void ad1848_filter_aux2(void *priv, double *out_l, double *out_r) { - ad1848_t *ad1848 = (ad1848_t *) priv; + const ad1848_t *ad1848 = (ad1848_t *) priv; if (ad1848->regs[4] & 0x80) { *out_l = 0.0; diff --git a/src/sound/snd_adlib.c b/src/sound/snd_adlib.c index 2f69bbf9d..5d0d7c7aa 100644 --- a/src/sound/snd_adlib.c +++ b/src/sound/snd_adlib.c @@ -13,6 +13,7 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_opl.h> +#include <86box/plat_unused.h> #ifdef ENABLE_ADLIB_LOG int adlib_do_log = ENABLE_ADLIB_LOG; @@ -39,23 +40,22 @@ typedef struct adlib_t { } adlib_t; static void -adlib_get_buffer(int32_t *buffer, int len, void *p) +adlib_get_buffer(int32_t *buffer, int len, void *priv) { - adlib_t *adlib = (adlib_t *) p; - int c; + adlib_t *adlib = (adlib_t *) priv; - int32_t *opl_buf = adlib->opl.update(adlib->opl.priv); + const int32_t *opl_buf = adlib->opl.update(adlib->opl.priv); - for (c = 0; c < len * 2; c++) - buffer[c] += (int32_t) opl_buf[c]; + for (int c = 0; c < len * 2; c++) + buffer[c] += opl_buf[c]; adlib->opl.reset_buffer(adlib->opl.priv); } uint8_t -adlib_mca_read(int port, void *p) +adlib_mca_read(int port, void *priv) { - adlib_t *adlib = (adlib_t *) p; + const adlib_t *adlib = (adlib_t *) priv; adlib_log("adlib_mca_read: port=%04x\n", port); @@ -63,9 +63,9 @@ adlib_mca_read(int port, void *p) } void -adlib_mca_write(int port, uint8_t val, void *p) +adlib_mca_write(int port, uint8_t val, void *priv) { - adlib_t *adlib = (adlib_t *) p; + adlib_t *adlib = (adlib_t *) priv; if (port < 0x102) return; @@ -85,20 +85,23 @@ adlib_mca_write(int port, uint8_t val, void *p) adlib->opl.write, NULL, NULL, adlib->opl.priv); break; + + default: + break; } adlib->pos_regs[port & 7] = val; } uint8_t -adlib_mca_feedb(void *p) +adlib_mca_feedb(void *priv) { - adlib_t *adlib = (adlib_t *) p; + const adlib_t *adlib = (adlib_t *) priv; return (adlib->pos_regs[2] & 1); } void * -adlib_init(const device_t *info) +adlib_init(UNUSED(const device_t *info)) { adlib_t *adlib = malloc(sizeof(adlib_t)); memset(adlib, 0, sizeof(adlib_t)); @@ -134,9 +137,9 @@ adlib_mca_init(const device_t *info) } void -adlib_close(void *p) +adlib_close(void *priv) { - adlib_t *adlib = (adlib_t *) p; + adlib_t *adlib = (adlib_t *) priv; free(adlib); } diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index 0616e8fa6..984a06ea9 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -17,15 +17,18 @@ #include <86box/sound.h> #include <86box/snd_opl.h> #include <86box/snd_ym7128.h> +#include <86box/plat_unused.h> typedef struct adgold_t { int adgold_irq_status; - int irq, dma, hdma; + int irq; + int dma; uint8_t adgold_eeprom[0x1a]; uint8_t adgold_status; - int adgold_38x_state, adgold_38x_addr; + int adgold_38x_state; + int adgold_38x_addr; uint8_t adgold_38x_regs[0x1a]; int adgold_mma_addr; @@ -33,7 +36,8 @@ typedef struct adgold_t { int adgold_mma_enable[2]; uint8_t adgold_mma_fifo[2][256]; - int adgold_mma_fifo_start[2], adgold_mma_fifo_end[2]; + int adgold_mma_fifo_start[2]; + int adgold_mma_fifo_end[2]; uint8_t adgold_mma_status; int16_t adgold_mma_out[2]; @@ -41,28 +45,42 @@ typedef struct adgold_t { pc_timer_t adgold_mma_timer_count; - uint8_t adgold_midi_ctrl, midi_queue[16]; - int midi_r, midi_w; - int uart_in, uart_out, sysex; + uint8_t adgold_midi_ctrl; + uint8_t midi_queue[16]; + int midi_r; + int midi_w; + int uart_in; + int uart_out; + int sysex; - struct - { - int timer0_latch, timer0_count; - int timerbase_latch, timerbase_count; - int timer1_latch, timer1_count; - int timer2_latch, timer2_count, timer2_read; + struct { + int timer0_latch; + int timer0_count; + int timerbase_latch; + int timerbase_count; + int timer1_latch; + int timer1_count; + int timer2_latch; + int timer2_count; + int timer2_read; - int voice_count[2], voice_latch[2]; + int voice_count[2]; + int voice_latch[2]; } adgold_mma; fm_drv_t opl; ym7128_t ym7128; - int fm_vol_l, fm_vol_r; - int samp_vol_l, samp_vol_r; - int aux_vol_l, aux_vol_r; - int vol_l, vol_r; - int treble, bass; + int fm_vol_l; + int fm_vol_r; + int samp_vol_l; + int samp_vol_r; + int aux_vol_l; + int aux_vol_r; + int vol_l; + int vol_r; + int treble; + int bass; int16_t opl_buffer[SOUNDBUFLEN * 2]; int16_t mma_buffer[2][SOUNDBUFLEN]; @@ -131,7 +149,7 @@ static int treble_cut[6] = { (int) (0.354 * 16384) /*-3 dB - filter output is at +6 dB*/ }; -void adgold_timer_poll(void *p); +void adgold_timer_poll(void *priv); void adgold_update(adgold_t *adgold); void @@ -192,9 +210,9 @@ adgold_getsamp_dma(adgold_t *adgold, int channel) } void -adgold_write(uint16_t addr, uint8_t val, void *p) +adgold_write(uint16_t addr, uint8_t val, void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; switch (addr & 7) { case 0: case 1: @@ -337,6 +355,9 @@ adgold_write(uint16_t addr, uint8_t val, void *p) case 0x18: adgold->adgold_mma.voice_latch[0] = 72; break; /* 7350 Hz*/ + + default: + break; } if (val & 0x80) { adgold->adgold_mma_enable[0] = 0; @@ -345,7 +366,7 @@ adgold_write(uint16_t addr, uint8_t val, void *p) adgold_update_irq_status(adgold); dma_set_drq(adgold->dma, 0); } - if ((val & 0x01)) /*Start playback*/ + if (val & 0x01) /*Start playback*/ { if (!(adgold->adgold_mma_regs[0][0x9] & 1)) adgold->adgold_mma.voice_count[0] = adgold->adgold_mma.voice_latch[0]; @@ -438,6 +459,9 @@ adgold_write(uint16_t addr, uint8_t val, void *p) adgold_update_irq_status(adgold); } break; + + default: + break; } adgold->adgold_mma_regs[0][adgold->adgold_mma_addr] = val; break; @@ -460,6 +484,9 @@ adgold_write(uint16_t addr, uint8_t val, void *p) case 0x18: adgold->adgold_mma.voice_latch[1] = 72; break; /* 7350 Hz*/ + + default: + break; } if (val & 0x80) { adgold->adgold_mma_enable[1] = 0; @@ -468,7 +495,7 @@ adgold_write(uint16_t addr, uint8_t val, void *p) adgold_update_irq_status(adgold); dma_set_drq(adgold->dma, 0); } - if ((val & 0x01)) /*Start playback*/ + if (val & 0x01) /*Start playback*/ { if (!(adgold->adgold_mma_regs[1][0x9] & 1)) adgold->adgold_mma.voice_count[1] = adgold->adgold_mma.voice_latch[1]; @@ -497,16 +524,22 @@ adgold_write(uint16_t addr, uint8_t val, void *p) case 0xc: adgold->adgold_mma_intpos[1] = (7 - ((val >> 2) & 7)) * 8; break; + + default: + break; } adgold->adgold_mma_regs[1][adgold->adgold_mma_addr] = val; break; + + default: + break; } } uint8_t -adgold_read(uint16_t addr, void *p) +adgold_read(uint16_t addr, void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; uint8_t temp = 0; switch (addr & 7) { @@ -547,6 +580,7 @@ adgold_read(uint16_t addr, void *p) temp = adgold->adgold_mma_status; adgold->adgold_mma_status &= ~0xf3; /*JUKEGOLD expects timer status flags to auto-clear*/ adgold_update_irq_status(adgold); + picintc(1 << adgold->irq); break; case 5: if (adgold->adgold_mma_addr >= 0xf) @@ -585,6 +619,9 @@ adgold_read(uint16_t addr, void *p) else temp = adgold->adgold_mma_regs[1][adgold->adgold_mma_addr]; break; + + default: + break; } return temp; } @@ -632,6 +669,9 @@ adgold_mma_poll(adgold_t *adgold, int channel) adgold->adgold_mma_fifo_start[channel] = (adgold->adgold_mma_fifo_start[channel] + 1) & 255; adgold->adgold_mma_out[channel] = dat; break; + + default: + break; } if (adgold->adgold_mma_regs[channel][0xc] & 1) { @@ -648,11 +688,12 @@ adgold_mma_poll(adgold_t *adgold, int channel) } void -adgold_timer_poll(void *p) +adgold_timer_poll(void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; - timer_advance_u64(&adgold->adgold_mma_timer_count, (uint64_t) ((double) TIMER_USEC * 1.88964)); + /*A small timer period will result in hangs.*/ + timer_on_auto(&adgold->adgold_mma_timer_count, 4.88964); if (adgold->adgold_midi_ctrl & 0x3f) { if ((adgold->adgold_midi_ctrl & 0x3f) != 0x3f) { @@ -716,16 +757,16 @@ adgold_timer_poll(void *p) } static void -adgold_get_buffer(int32_t *buffer, int len, void *p) +adgold_get_buffer(int32_t *buffer, int len, void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; int16_t *adgold_buffer = malloc(sizeof(int16_t) * len * 2); if (adgold_buffer == NULL) fatal("adgold_buffer = NULL"); int c; - int32_t *opl_buf = adgold->opl.update(adgold->opl.priv); + const int32_t *opl_buf = adgold->opl.update(adgold->opl.priv); adgold_update(adgold); for (c = 0; c < len * 2; c += 2) { @@ -753,6 +794,9 @@ adgold_get_buffer(int32_t *buffer, int len, void *p) break; case 6: /*Left and right channels*/ break; + + default: + break; } switch (adgold->adgold_38x_regs[0x8] & 0x18) { @@ -779,10 +823,15 @@ adgold_get_buffer(int32_t *buffer, int len, void *p) adgold_buffer[c + 1] += (l / 3) + ((r * 2) / 3); } break; + + default: + break; } for (c = 0; c < len * 2; c += 2) { - int32_t temp, lowpass, highpass; + int32_t temp; + int32_t lowpass; + int32_t highpass; /*Output is deliberately halved to avoid clipping*/ temp = ((int32_t) adgold_buffer[c] * adgold->vol_l) >> 17; @@ -827,12 +876,12 @@ adgold_get_buffer(int32_t *buffer, int len, void *p) } static void -adgold_filter_cd_audio(int channel, double *buffer, void *p) +adgold_filter_cd_audio(int channel, double *buffer, void *priv) { - adgold_t *adgold = (adgold_t *) p; - double c; - int aux = channel ? adgold->aux_vol_r : adgold->aux_vol_l; - int vol = channel ? adgold->vol_r : adgold->vol_l; + const adgold_t *adgold = (adgold_t *) priv; + double c; + int aux = channel ? adgold->aux_vol_r : adgold->aux_vol_l; + int vol = channel ? adgold->vol_r : adgold->vol_l; c = ((((*buffer) * aux) / 4096.0) * vol) / 4096.0; *buffer = c; @@ -842,7 +891,6 @@ static void adgold_input_msg(void *p, uint8_t *msg, uint32_t len) { adgold_t *adgold = (adgold_t *) p; - uint8_t i; if (adgold->sysex) return; @@ -850,7 +898,7 @@ adgold_input_msg(void *p, uint8_t *msg, uint32_t len) if (adgold->uart_in) { adgold->adgold_mma_status |= 0x04; - for (i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { adgold->midi_queue[adgold->midi_w++] = msg[i]; adgold->midi_w &= 0x0f; } @@ -863,14 +911,13 @@ static int adgold_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) { adgold_t *adgold = (adgold_t *) p; - uint32_t i; if (abort) { adgold->sysex = 0; return 0; } adgold->sysex = 1; - for (i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { if (adgold->midi_r == adgold->midi_w) return (len - i); adgold->midi_queue[adgold->midi_w++] = buffer[i]; @@ -881,7 +928,7 @@ adgold_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) } void * -adgold_init(const device_t *info) +adgold_init(UNUSED(const device_t *info)) { FILE *f; int c; @@ -925,7 +972,7 @@ adgold_init(const device_t *info) adgold->adgold_eeprom[0x10] = 0xff; adgold->adgold_eeprom[0x11] = 0x20; adgold->adgold_eeprom[0x12] = 0x00; - adgold->adgold_eeprom[0x13] = 0xa0; + adgold->adgold_eeprom[0x13] = 0x00; adgold->adgold_eeprom[0x14] = 0x00; adgold->adgold_eeprom[0x15] = 0x388 / 8; /*Present at 388-38f*/ adgold->adgold_eeprom[0x16] = 0x00; @@ -955,8 +1002,12 @@ adgold_init(const device_t *info) case 7: adgold->adgold_eeprom[0x13] |= 0x03; break; + + default: + break; } adgold->adgold_eeprom[0x13] |= (adgold->dma << 3); + adgold->adgold_eeprom[0x14] |= (adgold->dma << 4); memcpy(adgold->adgold_38x_regs, adgold->adgold_eeprom, 0x19); adgold->vol_l = attenuation[adgold->adgold_eeprom[0x04] & 0x3f]; adgold->vol_r = attenuation[adgold->adgold_eeprom[0x05] & 0x3f]; @@ -990,15 +1041,15 @@ adgold_init(const device_t *info) } void -adgold_close(void *p) +adgold_close(void *priv) { - FILE *f; - adgold_t *adgold = (adgold_t *) p; + FILE *fp; + adgold_t *adgold = (adgold_t *) priv; - f = nvr_fopen("adgold.bin", "wb"); - if (f) { - fwrite(adgold->adgold_eeprom, 0x1a, 1, f); - fclose(f); + fp = nvr_fopen("adgold.bin", "wb"); + if (fp) { + fwrite(adgold->adgold_eeprom, 0x1a, 1, fp); + fclose(fp); } free(adgold); diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 105907ede..fb156a205 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -38,6 +38,7 @@ #include <86box/snd_ac97.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> #define N 16 @@ -45,8 +46,9 @@ static float low_fir_es1371_coef[ES1371_NCoef]; -typedef struct { - uint8_t pci_command, pci_serr; +typedef struct es1371_t { + uint8_t pci_command; + uint8_t pci_serr; uint32_t base_addr; @@ -54,9 +56,10 @@ typedef struct { uint16_t pmcsr; - uint32_t int_ctrl, int_status, - legacy_ctrl; - void *gameport; + uint32_t int_ctrl; + uint32_t int_status; + uint32_t legacy_ctrl; + void *gameport; int mem_page; @@ -65,17 +68,22 @@ typedef struct { uint32_t sr_cir; uint16_t sr_ram[128]; - uint8_t uart_data, uart_ctrl, - uart_status, uart_res; + uint8_t uart_data; + uint8_t uart_ctrl; + uint8_t uart_status; + uint8_t uart_res; uint32_t uart_fifo[8]; - uint8_t read_fifo_pos, write_fifo_pos; + uint8_t read_fifo_pos; + uint8_t write_fifo_pos; ac97_codec_t *codec; uint32_t codec_ctrl; struct { - uint32_t addr, addr_latch; - uint16_t count, size; + uint32_t addr; + uint32_t addr_latch; + uint16_t count; + uint16_t size; uint16_t samp_ct; int curr_samp_ct; @@ -83,24 +91,34 @@ typedef struct { pc_timer_t timer; uint64_t latch; - uint32_t vf, ac; + uint32_t vf; + uint32_t ac; - int16_t buffer_l[64], buffer_r[64]; - int buffer_pos, buffer_pos_end; + int16_t buffer_l[64]; + int16_t buffer_r[64]; + int buffer_pos; + int buffer_pos_end; - int filtered_l[32], filtered_r[32]; + int filtered_l[32]; + int filtered_r[32]; int f_pos; - int16_t out_l, out_r; + int16_t out_l; + int16_t out_r; - int32_t vol_l, vol_r; + int32_t vol_l; + int32_t vol_r; } dac[2], adc; - int64_t dac_latch, dac_time; + int64_t dac_latch; + int64_t dac_time; - int master_vol_l, master_vol_r, - pcm_vol_l, pcm_vol_r, - cd_vol_l, cd_vol_r; + int master_vol_l; + int master_vol_r; + int pcm_vol_l; + int pcm_vol_r; + int cd_vol_l; + int cd_vol_r; int card; @@ -290,9 +308,7 @@ es1371_write_fifo(es1371_t *dev, uint8_t val) static void es1371_reset_fifo(es1371_t *dev) { - int i; - - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) dev->uart_fifo[i] = 0x00000000; dev->read_fifo_pos = dev->write_fifo_pos = 0; @@ -301,16 +317,15 @@ es1371_reset_fifo(es1371_t *dev) } static void -es1371_reset(void *p) +es1371_reset(void *priv) { - es1371_t *dev = (es1371_t *) p; - int i; + es1371_t *dev = (es1371_t *) priv; nmi = 0; /* Interrupt/Chip Select Control Register, Address 00H Addressable as byte, word, longword */ - dev->int_ctrl = 0xfc0f0000; + dev->int_ctrl = 0xfcff0000; /* Interrupt/Chip Select Control Register, Address 00H Addressable as longword only */ @@ -318,7 +333,7 @@ es1371_reset(void *p) /* UART Status Register, Address 09H Addressable as byte only */ - dev->uart_status = 0x00; + dev->uart_status = 0xff; /* UART Control Register, Address 09H Addressable as byte only */ @@ -326,15 +341,15 @@ es1371_reset(void *p) /* UART Reserved Register, Address 0AH Addressable as byte only */ - dev->uart_res = 0x00; + dev->uart_res = 0xff; /* Memory Page Register, Address 0CH Addressable as byte, word, longword */ - dev->mem_page = 0x00; + dev->mem_page = 0xf0; /* FIXME: hardware reads 0xfffffff0 */ /* Sample Rate Converter Interface Register, Address 10H Addressable as longword only */ - dev->sr_cir = 0x00000000; + dev->sr_cir = 0x00470000; /* CODEC Write Register, Address 14H Addressable as longword only */ @@ -342,7 +357,7 @@ es1371_reset(void *p) /* Legacy Control/Status Register, Address 18H Addressable as byte, word, longword */ - dev->legacy_ctrl = 0x0000f800; + dev->legacy_ctrl = 0x0000f801; /* Serial Interface Control Register, Address 20H Addressable as byte, word, longword */ @@ -350,17 +365,17 @@ es1371_reset(void *p) /* DAC1 Channel Sample Count Register, Address 24H Addressable as word, longword */ - dev->dac[0].samp_ct = 0x00000000; + dev->dac[0].samp_ct = 0x00000000; /* FIXME: hardware reads 0x00010000 */ dev->dac[0].curr_samp_ct = 0x00000000; /* DAC2 Channel Sample Count Register, Address 28H Addressable as word, longword */ - dev->dac[1].samp_ct = 0x00000000; + dev->dac[1].samp_ct = 0x00000000; /* FIXME: hardware reads 0x00010000 */ dev->dac[1].curr_samp_ct = 0x00000000; /* ADC Channel Sample Count Register, Address 2CH Addressable as word, longword */ - dev->adc.samp_ct = 0x00000000; + dev->adc.samp_ct = 0x00000000; /* FIXME: hardware reads 0x00010000 */ dev->adc.curr_samp_ct = 0x00000000; /* DAC1 Frame Register 1, Address 30H, Memory Page 1100b @@ -392,7 +407,7 @@ es1371_reset(void *p) /* UART FIFO Register, Address 30H, 34H, 38H, 3CH, Memory Page 1110b, 1111b Addressable as longword only */ - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) dev->uart_fifo[i] = 0xffff0000; /* Reset the UART TX. */ @@ -432,6 +447,9 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; case 0x34: @@ -455,6 +473,9 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; case 0x38: @@ -473,6 +494,9 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; case 0x3c: @@ -491,8 +515,14 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; + + default: + break; } return ret; @@ -522,6 +552,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; case 0x34: @@ -546,6 +579,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; case 0x38: @@ -563,6 +599,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; case 0x3c: @@ -581,8 +620,14 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; + + default: + break; } if (page == 0x0e || page == 0x0f) { @@ -591,9 +636,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) } static uint8_t -es1371_inb(uint16_t port, void *p) +es1371_inb(uint16_t port, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint8_t ret = 0xff; switch (port & 0x3f) { @@ -624,11 +669,11 @@ es1371_inb(uint16_t port, void *p) audiopci_log("[R] STATUS 8-15 = %02X\n", ret); break; case 0x06: - ret = (dev->int_status >> 16) & 0x0f; + ret = (dev->int_status >> 16) & 0xff; audiopci_log("[R] STATUS 16-23 = %02X\n", ret); break; case 0x07: - ret = ((dev->int_status >> 24) & 0x03) | 0xfc; + ret = (dev->int_status >> 24) & 0xff; audiopci_log("[R] STATUS 24-31 = %02X\n", ret); break; @@ -702,9 +747,9 @@ es1371_inb(uint16_t port, void *p) } static uint16_t -es1371_inw(uint16_t port, void *p) +es1371_inw(uint16_t port, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint16_t ret = 0xffff; switch (port & 0x3e) { @@ -783,6 +828,9 @@ es1371_inw(uint16_t port, void *p) case 0x3e: ret = es1371_read_frame_reg(dev, port & 0x3c, dev->mem_page) >> 16; break; + + default: + break; } audiopci_log("es1371_inw: port=%04x ret=%04x\n", port, ret); @@ -791,9 +839,9 @@ es1371_inw(uint16_t port, void *p) } static uint32_t -es1371_inl(uint16_t port, void *p) +es1371_inl(uint16_t port, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t ret = 0xffffffff; switch (port & 0x3c) { @@ -865,6 +913,9 @@ es1371_inl(uint16_t port, void *p) case 0x3c: ret = es1371_read_frame_reg(dev, port & 0x3c, dev->mem_page); break; + + default: + break; } audiopci_log("es1371_inl: port=%04x ret=%08x\n", port, ret); @@ -872,9 +923,9 @@ es1371_inl(uint16_t port, void *p) } static void -es1371_outb(uint16_t port, uint8_t val, void *p) +es1371_outb(uint16_t port, uint8_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t old_legacy_ctrl; audiopci_log("es1371_outb: port=%04x val=%02x\n", port, val); @@ -992,9 +1043,9 @@ es1371_outb(uint16_t port, uint8_t val, void *p) } static void -es1371_outw(uint16_t port, uint16_t val, void *p) +es1371_outw(uint16_t port, uint16_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t old_legacy_ctrl; switch (port & 0x3f) { @@ -1071,13 +1122,16 @@ es1371_outw(uint16_t port, uint16_t val, void *p) case 0x2c: dev->adc.samp_ct = val; break; + + default: + break; } } static void -es1371_outl(uint16_t port, uint32_t val, void *p) +es1371_outl(uint16_t port, uint32_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t old_legacy_ctrl; audiopci_log("es1371_outl: port=%04x val=%08x\n", port, val); @@ -1157,6 +1211,9 @@ es1371_outl(uint16_t port, uint32_t val, void *p) case 0x7f: dev->dac[1].vol_r = (int32_t) (int16_t) (val & 0xffff); break; + + default: + break; } } break; @@ -1222,6 +1279,9 @@ es1371_outl(uint16_t port, uint32_t val, void *p) case 0x3c: es1371_write_frame_reg(dev, port & 0x3c, dev->mem_page, val); break; + + default: + break; } } @@ -1240,106 +1300,106 @@ capture_event(es1371_t *dev, int type, int rw, uint16_t port) } static void -capture_write_sscape(uint16_t port, uint8_t val, void *p) +capture_write_sscape(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SSCAPE, 1, port); + capture_event(priv, LEGACY_EVENT_SSCAPE, 1, port); } static void -capture_write_codec(uint16_t port, uint8_t val, void *p) +capture_write_codec(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_CODEC, 1, port); + capture_event(priv, LEGACY_EVENT_CODEC, 1, port); } static void -capture_write_sb(uint16_t port, uint8_t val, void *p) +capture_write_sb(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SB, 1, port); + capture_event(priv, LEGACY_EVENT_SB, 1, port); } static void -capture_write_adlib(uint16_t port, uint8_t val, void *p) +capture_write_adlib(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_ADLIB, 1, port); + capture_event(priv, LEGACY_EVENT_ADLIB, 1, port); } static void -capture_write_master_pic(uint16_t port, uint8_t val, void *p) +capture_write_master_pic(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_PIC, 1, port); + capture_event(priv, LEGACY_EVENT_MASTER_PIC, 1, port); } static void -capture_write_master_dma(uint16_t port, uint8_t val, void *p) +capture_write_master_dma(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_DMA, 1, port); + capture_event(priv, LEGACY_EVENT_MASTER_DMA, 1, port); } static void -capture_write_slave_pic(uint16_t port, uint8_t val, void *p) +capture_write_slave_pic(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_PIC, 1, port); + capture_event(priv, LEGACY_EVENT_SLAVE_PIC, 1, port); } static void -capture_write_slave_dma(uint16_t port, uint8_t val, void *p) +capture_write_slave_dma(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_DMA, 1, port); + capture_event(priv, LEGACY_EVENT_SLAVE_DMA, 1, port); } static uint8_t -capture_read_sscape(uint16_t port, void *p) +capture_read_sscape(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SSCAPE, 0, port); + capture_event(priv, LEGACY_EVENT_SSCAPE, 0, port); return 0xff; } static uint8_t -capture_read_codec(uint16_t port, void *p) +capture_read_codec(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_CODEC, 0, port); + capture_event(priv, LEGACY_EVENT_CODEC, 0, port); return 0xff; } static uint8_t -capture_read_sb(uint16_t port, void *p) +capture_read_sb(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SB, 0, port); + capture_event(priv, LEGACY_EVENT_SB, 0, port); return 0xff; } static uint8_t -capture_read_adlib(uint16_t port, void *p) +capture_read_adlib(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_ADLIB, 0, port); + capture_event(priv, LEGACY_EVENT_ADLIB, 0, port); return 0xff; } static uint8_t -capture_read_master_pic(uint16_t port, void *p) +capture_read_master_pic(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_PIC, 0, port); + capture_event(priv, LEGACY_EVENT_MASTER_PIC, 0, port); return 0xff; } static uint8_t -capture_read_master_dma(uint16_t port, void *p) +capture_read_master_dma(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_DMA, 0, port); + capture_event(priv, LEGACY_EVENT_MASTER_DMA, 0, port); return 0xff; } static uint8_t -capture_read_slave_pic(uint16_t port, void *p) +capture_read_slave_pic(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_PIC, 0, port); + capture_event(priv, LEGACY_EVENT_SLAVE_PIC, 0, port); return 0xff; } static uint8_t -capture_read_slave_dma(uint16_t port, void *p) +capture_read_slave_dma(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_DMA, 0, port); + capture_event(priv, LEGACY_EVENT_SLAVE_DMA, 0, port); return 0xff; } @@ -1368,6 +1428,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_sscape, NULL, NULL, capture_write_sscape, NULL, NULL, dev); break; + + default: + break; } } @@ -1388,6 +1451,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_codec, NULL, NULL, capture_write_codec, NULL, NULL, dev); break; + + default: + break; } } @@ -1455,6 +1521,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_sscape, NULL, NULL, capture_write_sscape, NULL, NULL, dev); break; + + default: + break; } } @@ -1475,6 +1544,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_codec, NULL, NULL, capture_write_codec, NULL, NULL, dev); break; + + default: + break; } } @@ -1522,9 +1594,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) } static uint8_t -es1371_pci_read(int func, int addr, void *p) +es1371_pci_read(int func, int addr, void *priv) { - es1371_t *dev = (es1371_t *) p; + const es1371_t *dev = (es1371_t *) priv; if (func > 0) return 0xff; @@ -1554,7 +1626,7 @@ es1371_pci_read(int func, int addr, void *p) return 0x00; case 0x08: - return 0x08; /* Revision ID - 0x02 (datasheet, VMware) has issues with the 2001 Creative WDM driver */ + return 0x02; /* Revision ID - 0x02 is actual Ensoniq-branded ES1371 */ case 0x09: return 0x00; /* Multimedia audio device */ case 0x0a: @@ -1606,6 +1678,9 @@ es1371_pci_read(int func, int addr, void *p) return dev->pmcsr & 0xff; case 0xe1: return dev->pmcsr >> 8; + + default: + break; } return 0x00; @@ -1622,9 +1697,9 @@ es1371_io_set(es1371_t *dev, int set) } static void -es1371_pci_write(int func, int addr, uint8_t val, void *p) +es1371_pci_write(int func, int addr, uint8_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; if (func) return; @@ -1666,6 +1741,9 @@ es1371_pci_write(int func, int addr, uint8_t val, void *p) case 0xe1: dev->pmcsr = (dev->pmcsr & 0x00ff) | ((val & 0x01) << 8); break; + + default: + break; } } @@ -1751,6 +1829,9 @@ es1371_fetch(es1371_t *dev, int dac_nr) } } break; + + default: + break; } } @@ -1760,7 +1841,8 @@ low_fir_es1371(int dac_nr, int i, float NewSample) static float x[2][2][128]; // input samples static int x_pos[2] = { 0, 0 }; float out = 0.0; - int read_pos, n_coef; + int read_pos; + int n_coef; int pos = x_pos[dac_nr]; x[dac_nr][i][pos] = NewSample; @@ -1788,8 +1870,8 @@ low_fir_es1371(int dac_nr, int i, float NewSample) static void es1371_next_sample_filtered(es1371_t *dev, int dac_nr, int out_idx) { - int out_l, out_r; - int c; + int out_l; + int out_r; if ((dev->dac[dac_nr].buffer_pos - dev->dac[dac_nr].buffer_pos_end) >= 0) es1371_fetch(dev, dac_nr); @@ -1800,7 +1882,7 @@ es1371_next_sample_filtered(es1371_t *dev, int dac_nr, int out_idx) dev->dac[dac_nr].filtered_l[out_idx] = (int) low_fir_es1371(dac_nr, 0, (float) out_l); dev->dac[dac_nr].filtered_r[out_idx] = (int) low_fir_es1371(dac_nr, 1, (float) out_r); - for (c = 1; c < 16; c++) { + for (uint8_t c = 1; c < 16; c++) { dev->dac[dac_nr].filtered_l[out_idx + c] = (int) low_fir_es1371(dac_nr, 0, 0); dev->dac[dac_nr].filtered_r[out_idx + c] = (int) low_fir_es1371(dac_nr, 1, 0); } @@ -1811,7 +1893,8 @@ es1371_next_sample_filtered(es1371_t *dev, int dac_nr, int out_idx) static void es1371_update(es1371_t *dev) { - int32_t l, r; + int32_t l; + int32_t r; l = (dev->dac[0].out_l * dev->dac[0].vol_l) >> 12; l += ((dev->dac[1].out_l * dev->dac[1].vol_l) >> 12); @@ -1840,10 +1923,15 @@ es1371_update(es1371_t *dev) } static void -es1371_poll(void *p) +es1371_poll(void *priv) { - es1371_t *dev = (es1371_t *) p; - int frac, idx, samp1_l, samp1_r, samp2_l, samp2_r; + es1371_t *dev = (es1371_t *) priv; + int frac; + int idx; + int samp1_l; + int samp1_r; + int samp2_l; + int samp2_r; timer_advance_u64(&dev->dac[1].timer, dev->dac[1].latch); @@ -1903,26 +1991,25 @@ es1371_poll(void *p) } static void -es1371_get_buffer(int32_t *buffer, int len, void *p) +es1371_get_buffer(int32_t *buffer, int len, void *priv) { - es1371_t *dev = (es1371_t *) p; - int c; + es1371_t *dev = (es1371_t *) priv; es1371_update(dev); - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += (dev->buffer[c] / 2); dev->pos = 0; } static void -es1371_filter_cd_audio(int channel, double *buffer, void *p) +es1371_filter_cd_audio(int channel, double *buffer, void *priv) { - es1371_t *dev = (es1371_t *) p; - double c; - int cd = channel ? dev->cd_vol_r : dev->cd_vol_l; - int master = channel ? dev->master_vol_r : dev->master_vol_l; + const es1371_t *dev = (es1371_t *) priv; + double c; + int cd = channel ? dev->cd_vol_r : dev->cd_vol_l; + int master = channel ? dev->master_vol_r : dev->master_vol_l; c = ((((*buffer) * cd) / 65536.0) * master) / 65536.0; *buffer = c; @@ -1969,9 +2056,8 @@ static void es1371_input_msg(void *p, uint8_t *msg, uint32_t len) { es1371_t *dev = (es1371_t *) p; - uint8_t i; - for (i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) es1371_write_fifo(dev, msg[i]); } @@ -2033,17 +2119,17 @@ es1371_init(const device_t *info) } static void -es1371_close(void *p) +es1371_close(void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; free(dev); } static void -es1371_speed_changed(void *p) +es1371_speed_changed(void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; dev->dac[1].latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / (double) SOUND_FREQ)); } @@ -2052,7 +2138,7 @@ static const device_config_t es1371_config[] = { // clang-format off { .name = "codec", - .description = "CODEC", + .description = "Codec", .type = CONFIG_SELECTION, .selection = { { @@ -2060,23 +2146,12 @@ static const device_config_t es1371_config[] = { .value = AC97_CODEC_AK4540 }, { - .description = "Crystal CS4297", - .value = AC97_CODEC_CS4297 + .description = "TriTech TR28023 / Creative CT1297", + .value = AC97_CODEC_TR28023 }, - { - .description = "Crystal CS4297A", - .value = AC97_CODEC_CS4297A - }, - { - .description = "SigmaTel STAC9708", - .value = AC97_CODEC_STAC9708 - }, - { - .description = "SigmaTel STAC9721", - .value = AC97_CODEC_STAC9721 - } + { .description = "" } }, - .default_int = AC97_CODEC_CS4297A + .default_int = AC97_CODEC_TR28023 }, { .name = "receive_input", diff --git a/src/sound/snd_azt2316a.c b/src/sound/snd_azt2316a.c index ee46ab01b..b4a4dd238 100644 --- a/src/sound/snd_azt2316a.c +++ b/src/sound/snd_azt2316a.c @@ -150,6 +150,7 @@ #include <86box/snd_ad1848.h> #include <86box/snd_azt2316a.h> #include <86box/snd_sb.h> +#include <86box/plat_unused.h> /*530, 11, 3 - 530=23*/ /*530, 11, 1 - 530=22*/ @@ -164,7 +165,9 @@ static int azt2316a_wss_dma[4] = { 0, 0, 1, 3 }; static int azt2316a_wss_irq[8] = { 5, 7, 9, 10, 11, 12, 14, 15 }; /* W95 only uses 7-10, others may be wrong */ -// static uint16_t azt2316a_wss_addr[4] = {0x530, 0x604, 0xe80, 0xf40}; +#if 0 +static uint16_t azt2316a_wss_addr[4] = {0x530, 0x604, 0xe80, 0xf40}; +#endif typedef struct azt2316a_t { int type; @@ -172,10 +175,14 @@ typedef struct azt2316a_t { uint8_t wss_config; - uint16_t cur_addr, cur_wss_addr, cur_mpu401_addr; + uint16_t cur_addr; + uint16_t cur_wss_addr; + uint16_t cur_mpu401_addr; int cur_irq, cur_dma; - int cur_wss_enabled, cur_wss_irq, cur_wss_dma; + int cur_wss_enabled; + int cur_wss_irq; + int cur_wss_dma; int cur_mpu401_irq; int cur_mpu401_enabled; @@ -191,10 +198,10 @@ typedef struct azt2316a_t { } azt2316a_t; static uint8_t -azt2316a_wss_read(uint16_t addr, void *p) +azt2316a_wss_read(uint16_t addr, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; - uint8_t temp; + const azt2316a_t *azt2316a = (azt2316a_t *) priv; + uint8_t temp; /* TODO: when windows is initializing, writing 0x48, 0x58 and 0x60 to 0x530 makes reading from 0x533 return 0x44, but writing 0x50 @@ -208,9 +215,9 @@ azt2316a_wss_read(uint16_t addr, void *p) } static void -azt2316a_wss_write(uint16_t addr, uint8_t val, void *p) +azt2316a_wss_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; int interrupt = 0; if (azt2316a->wss_interrupt_after_config) { @@ -231,9 +238,9 @@ azt2316a_wss_write(uint16_t addr, uint8_t val, void *p) /* generate a config word based on current settings */ static void -azt1605_create_config_word(void *p) +azt1605_create_config_word(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint32_t temp = 0; /* not implemented / hardcoded */ @@ -244,20 +251,24 @@ azt1605_create_config_word(void *p) switch (azt2316a->cur_addr) { case 0x220: - /* do nothing - temp += 0 << 0; */ + // do nothing +#if 0 + temp += 0 << 0; +#endif break; case 0x240: temp += 1 << 0; break; - /* - case 0x260: // TODO: INVALID? - temp += 2 << 0; - break; - case 0x280: // TODO: INVALID? - temp += 3 << 0; - break; - */ +#if 0 + case 0x260: // TODO: INVALID? + temp += 2 << 0; + break; + case 0x280: // TODO: INVALID? + temp += 3 << 0; + break; +#endif + default: + break; } switch (azt2316a->cur_irq) { @@ -273,12 +284,17 @@ azt1605_create_config_word(void *p) case 7: temp += 1 << 11; break; + + default: + break; } switch (azt2316a->cur_wss_addr) { case 0x530: - /* do nothing - temp += 0 << 16; */ + // do nothing +#if 0 + temp += 0 << 16; +#endif break; case 0x604: temp += 1 << 16; @@ -289,6 +305,9 @@ azt1605_create_config_word(void *p) case 0xF40: temp += 3 << 16; break; + + default: + break; } if (azt2316a->cur_wss_enabled) @@ -299,12 +318,17 @@ azt1605_create_config_word(void *p) switch (azt2316a->cur_mpu401_addr) { case 0x300: - /* do nothing - temp += 0 << 2; */ + // do nothing +#if 0 + temp += 0 << 2; +#endif break; case 0x330: temp += 1 << 2; break; + + default: + break; } if (azt2316a->cur_mpu401_enabled) @@ -336,6 +360,9 @@ azt1605_create_config_word(void *p) case 7: // unused temp += 7 << 5; break; + + default: + break; } switch (cd_dma8) { @@ -352,6 +379,9 @@ azt1605_create_config_word(void *p) case 3: temp += 3 << 22; break; + + default: + break; } switch (azt2316a->cur_mpu401_irq) { @@ -367,6 +397,9 @@ azt1605_create_config_word(void *p) case 7: temp += 1 << 15; break; + + default: + break; } switch (cd_irq) { @@ -382,15 +415,18 @@ azt1605_create_config_word(void *p) case 15: temp += 1 << 21; break; + + default: + break; } azt2316a->config_word = temp; } static void -azt2316a_create_config_word(void *p) +azt2316a_create_config_word(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint32_t temp = 0; /* not implemented / hardcoded */ @@ -402,26 +438,30 @@ azt2316a_create_config_word(void *p) uint8_t cd_irq = 15; if (azt2316a->type == SB_SUBTYPE_CLONE_AZT1605_0X0C) { - azt1605_create_config_word(p); + azt1605_create_config_word(priv); return; } switch (azt2316a->cur_addr) { case 0x220: - /* do nothing - temp += 0 << 0; */ + // do nothing +#if 0 + temp += 0 << 0; +#endif break; case 0x240: temp += 1 << 0; break; - /* - case 0x260: // TODO: INVALID? - temp += 2 << 0; - break; - case 0x280: // TODO: INVALID? - temp += 3 << 0; - break; - */ +#if 0 + case 0x260: // TODO: INVALID? + temp += 2 << 0; + break; + case 0x280: // TODO: INVALID? + temp += 3 << 0; + break; +#endif + default: + break; } switch (azt2316a->cur_irq) { @@ -437,16 +477,19 @@ azt2316a_create_config_word(void *p) case 10: temp += 1 << 5; break; + + default: + break; } switch (azt2316a->cur_dma) { - /* - // TODO: INVALID? - case 0xFF: // -1 - // do nothing - //temp += 0 << 6; - break; - */ +#if 0 + // TODO: INVALID? + case 0xFF: // -1 + // do nothing + //temp += 0 << 6; + break; +#endif case 0: temp += 1 << 6; break; @@ -456,12 +499,17 @@ azt2316a_create_config_word(void *p) case 3: temp += 3 << 6; break; + + default: + break; } switch (azt2316a->cur_wss_addr) { case 0x530: // do nothing - // temp += 0 << 8; +#if 0 + temp += 0 << 8; +#endif break; case 0x604: temp += 1 << 8; @@ -472,6 +520,9 @@ azt2316a_create_config_word(void *p) case 0xF40: temp += 3 << 8; break; + + default: + break; } if (azt2316a->cur_wss_enabled) temp += 1 << 10; @@ -480,11 +531,16 @@ azt2316a_create_config_word(void *p) switch (azt2316a->cur_mpu401_addr) { case 0x300: // do nothing - // temp += 0 << 12; +#if 0 + temp += 0 << 12; +#endif break; case 0x330: temp += 1 << 12; break; + + default: + break; } if (azt2316a->cur_mpu401_enabled) @@ -493,7 +549,9 @@ azt2316a_create_config_word(void *p) switch (cd_addr) { case 0x310: // do nothing - // temp += 0 << 14; +#if 0 + temp += 0 << 14; +#endif break; case 0x320: temp += 1 << 14; @@ -504,11 +562,16 @@ azt2316a_create_config_word(void *p) case 0x350: temp += 3 << 14; break; + + default: + break; } switch (cd_type) { - case 0: /* disabled - do nothing + case 0: /* disabled */ + // do nothing +#if 0 temp += 0 << 16; */ +#endif break; case 1: /* panasonic */ temp += 1 << 16; @@ -531,6 +594,9 @@ azt2316a_create_config_word(void *p) case 7: /* unused */ temp += 7 << 16; break; + + default: + break; } switch (cd_dma8) { @@ -541,14 +607,17 @@ azt2316a_create_config_word(void *p) case 0: temp += 1 << 20; break; - /* - case 1: // TODO: INVALID? - temp += 2 << 20; - break; - */ +#if 0 + case 1: // TODO: INVALID? + temp += 2 << 20; + break; +#endif case 3: temp += 3 << 20; break; + + default: + break; } switch (cd_dma16) { @@ -565,6 +634,9 @@ azt2316a_create_config_word(void *p) case 7: temp += 3 << 22; break; + + default: + break; } switch (azt2316a->cur_mpu401_irq) { @@ -580,6 +652,9 @@ azt2316a_create_config_word(void *p) case 10: temp += 1 << 27; break; + + default: + break; } switch (cd_irq) { @@ -595,16 +670,19 @@ azt2316a_create_config_word(void *p) case 15: temp += 1 << 31; break; + + default: + break; } azt2316a->config_word = temp; } static uint8_t -azt2316a_config_read(uint16_t addr, void *p) +azt2316a_config_read(uint16_t addr, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; - uint8_t temp = 0; + const azt2316a_t *azt2316a = (azt2316a_t *) priv; + uint8_t temp = 0; /* Some WSS config here + config change enable bit (setting bit 7 and writing back) */ @@ -635,6 +713,9 @@ azt2316a_config_read(uint16_t addr, void *p) case 3: temp = (azt2316a->config_word >> 24); break; + + default: + break; } } @@ -642,9 +723,9 @@ azt2316a_config_read(uint16_t addr, void *p) } static void -azt1605_config_write(uint16_t addr, uint8_t val, void *p) +azt1605_config_write(uint16_t addr, uint8_t val, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint8_t temp; if (addr == (azt2316a->cur_addr + 0x404)) { @@ -665,12 +746,12 @@ azt1605_config_write(uint16_t addr, uint8_t val, void *p) azt2316a->cur_addr = 0x220; else if (temp == 1) azt2316a->cur_addr = 0x240; - /* - else if (temp == 2) - azt2316a->cur_addr = 0x260; // TODO: INVALID - else if (temp == 3) - azt2316a->cur_addr = 0x280; // TODO: INVALID - */ +#if 0 + else if (temp == 2) + azt2316a->cur_addr = 0x260; // TODO: INVALID + else if (temp == 3) + azt2316a->cur_addr = 0x280; // TODO: INVALID +#endif if (val & 0x4) azt2316a->cur_mpu401_addr = 0x330; else @@ -731,6 +812,9 @@ azt1605_config_write(uint16_t addr, uint8_t val, void *p) break; case 3: break; + + default: + break; } /* update sbprov2 configs */ sb_dsp_setaddr(&azt2316a->sb->dsp, azt2316a->cur_addr); @@ -743,9 +827,9 @@ azt1605_config_write(uint16_t addr, uint8_t val, void *p) } static void -azt2316a_config_write(uint16_t addr, uint8_t val, void *p) +azt2316a_config_write(uint16_t addr, uint8_t val, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint8_t temp; if (azt2316a->type == SB_SUBTYPE_CLONE_AZT1605_0X0C) { @@ -839,6 +923,9 @@ azt2316a_config_write(uint16_t addr, uint8_t val, void *p) azt2316a->cur_mpu401_irq = 10; /* else undefined? */ break; + + default: + break; } /* update sbprov2 configs */ sb_dsp_setaddr(&azt2316a->sb->dsp, azt2316a->cur_addr); @@ -852,9 +939,9 @@ azt2316a_config_write(uint16_t addr, uint8_t val, void *p) /* How it behaves when one or another is activated may affect games auto-detecting (and will also use more of the limited system resources!) */ void -azt2316a_enable_wss(uint8_t enable, void *p) +azt2316a_enable_wss(uint8_t enable, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; if (enable) azt2316a->cur_mode = 1; @@ -863,14 +950,13 @@ azt2316a_enable_wss(uint8_t enable, void *p) } static void -azt2316a_get_buffer(int32_t *buffer, int len, void *p) +azt2316a_get_buffer(int32_t *buffer, int len, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; - int c; + azt2316a_t *azt2316a = (azt2316a_t *) priv; /* wss part */ ad1848_update(&azt2316a->ad1848); - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += (azt2316a->ad1848.buffer[c] / 2); azt2316a->ad1848.pos = 0; @@ -1183,13 +1269,12 @@ azt_init(const device_t *info) } static void -azt_close(void *p) +azt_close(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; char *fn = NULL; FILE *f; uint8_t checksum = 0x7f; - int i; if (azt2316a->type == SB_SUBTYPE_CLONE_AZT1605_0X0C) { fn = "azt1605.nvr"; @@ -1200,7 +1285,7 @@ azt_close(void *p) /* always save to eeprom (recover from bad values) */ f = nvr_fopen(fn, "wb"); if (f) { - for (i = 0; i < AZTECH_EEPROM_SIZE; i++) + for (uint8_t i = 0; i < AZTECH_EEPROM_SIZE; i++) checksum += azt2316a->sb->dsp.azt_eeprom[i]; fwrite(azt2316a->sb->dsp.azt_eeprom, AZTECH_EEPROM_SIZE, 1, f); @@ -1219,9 +1304,9 @@ azt_close(void *p) } static void -azt_speed_changed(void *p) +azt_speed_changed(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; ad1848_speed_changed(&azt2316a->ad1848); sb_speed_changed(azt2316a->sb); diff --git a/src/sound/snd_cmi8x38.c b/src/sound/snd_cmi8x38.c index d4a54880b..ea81230a9 100644 --- a/src/sound/snd_cmi8x38.c +++ b/src/sound/snd_cmi8x38.c @@ -34,6 +34,8 @@ #include <86box/gameport.h> #include <86box/nmi.h> #include <86box/ui.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> enum { /* [23:16] = reg 0F [7:0] (reg 0C [31:24]) @@ -53,37 +55,67 @@ enum { TRAP_MAX }; -typedef struct { - uint8_t id, reg, always_run, playback_enabled, channels; +typedef struct cmi8x38_dma_t { + uint8_t id; + uint8_t reg; + uint8_t always_run; + uint8_t playback_enabled; + uint8_t channels; struct _cmi8x38_ *dev; - uint32_t sample_ptr, fifo_pos, fifo_end; - int32_t frame_count_dma, frame_count_fragment, sample_count_out; - uint8_t fifo[256], restart; + uint32_t sample_ptr; + uint32_t fifo_pos; + uint32_t fifo_end; + int32_t frame_count_dma; + int32_t frame_count_fragment; + int32_t sample_count_out; + uint8_t fifo[256]; + uint8_t restart; - int16_t out_fl, out_fr, out_rl, out_rr, out_c, out_lfe; - int vol_l, vol_r, pos; + int16_t out_fl; + int16_t out_fr; + int16_t out_rl; + int16_t out_rr; + int16_t out_c; + int16_t out_lfe; + int vol_l; + int vol_r; + int pos; int32_t buffer[SOUNDBUFLEN * 2]; uint64_t timer_latch; double dma_latch; - pc_timer_t dma_timer, poll_timer; + pc_timer_t dma_timer; + pc_timer_t poll_timer; } cmi8x38_dma_t; typedef struct _cmi8x38_ { uint32_t type; - uint16_t io_base, sb_base, opl_base, mpu_base; - uint8_t pci_regs[256], io_regs[256]; + uint16_t io_base; + uint16_t sb_base; + uint16_t opl_base; + uint16_t mpu_base; + uint8_t pci_regs[256]; + uint8_t io_regs[256]; int slot; sb_t *sb; - void *gameport, *io_traps[TRAP_MAX]; + void *gameport; + void *io_traps[TRAP_MAX]; cmi8x38_dma_t dma[2]; - uint16_t tdma_base_addr, tdma_base_count; - int tdma_8, tdma_16, tdma_mask, prev_mask, tdma_irq_mask; + uint16_t tdma_base_addr; + uint16_t tdma_base_count; + int tdma_8; + int tdma_16; + int tdma_mask; + int prev_mask; + int tdma_irq_mask; - int master_vol_l, master_vol_r, cd_vol_l, cd_vol_r; + int master_vol_l; + int master_vol_r; + int cd_vol_l; + int cd_vol_r; } cmi8x38_t; #ifdef ENABLE_CMI8X38_LOG @@ -138,7 +170,8 @@ cmi8x38_mpu_irq_update(void *priv, int set) static int cmi8x38_mpu_irq_pending(void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; + const cmi8x38_t *dev = (cmi8x38_t *) priv; + return dev->io_regs[0x12] & 0x01; } @@ -181,8 +214,8 @@ cmi8x38_sb_dma_post(cmi8x38_t *dev, uint16_t *addr, uint16_t *count, int channel /* Check TDMA position update interrupt if enabled. */ if (dev->io_regs[0x0e] & 0x04) { /* Nothing uses this; I assume it goes by the SB DSP sample counter (forwards instead of backwards). */ - int origlength = (channel & 4) ? dev->sb->dsp.sb_16_origlength : dev->sb->dsp.sb_8_origlength, - length = (channel & 4) ? dev->sb->dsp.sb_16_length : dev->sb->dsp.sb_8_length; + int origlength = (channel & 4) ? dev->sb->dsp.sb_16_origlength : dev->sb->dsp.sb_8_origlength; + int length = (channel & 4) ? dev->sb->dsp.sb_16_length : dev->sb->dsp.sb_8_length; if ((origlength != length) && (((origlength - length) & dev->tdma_irq_mask) == 0)) { /* skip initial sample */ /* Fire the interrupt. */ dev->io_regs[0x11] |= (channel & 4) ? 0x40 : 0x80; @@ -225,8 +258,8 @@ cmi8x38_sb_dma_readb(void *priv) return DMA_NODATA; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], - *count = (uint16_t *) &dev->io_regs[0x1e]; + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c]; + uint16_t *count = (uint16_t *) &dev->io_regs[0x1e]; /* Read data. */ int ret = mem_readb_phys((dma[channel].ab & 0xffff0000) | *addr); @@ -248,8 +281,8 @@ cmi8x38_sb_dma_readw(void *priv) return DMA_NODATA; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], - *count = (uint16_t *) &dev->io_regs[0x1e]; + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c]; + uint16_t *count = (uint16_t *) &dev->io_regs[0x1e]; /* Read data. */ int ret = mem_readw_phys((dma[channel].ab & 0xfffe0000) | ((*addr) << 1)); @@ -271,8 +304,8 @@ cmi8x38_sb_dma_writeb(void *priv, uint8_t val) return 1; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], - *count = (uint16_t *) &dev->io_regs[0x1e]; + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c]; + uint16_t *count = (uint16_t *) &dev->io_regs[0x1e]; /* Write data. */ mem_writeb_phys((dma[channel].ab & 0xffff0000) | *addr, val); @@ -294,8 +327,8 @@ cmi8x38_sb_dma_writew(void *priv, uint16_t val) return 1; /* Get 16-bit address and count registers. */ - uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c], - *count = (uint16_t *) &dev->io_regs[0x1e]; + uint16_t *addr = (uint16_t *) &dev->io_regs[0x1c]; + uint16_t *count = (uint16_t *) &dev->io_regs[0x1e]; /* Write data. */ mem_writew_phys((dma[channel].ab & 0xfffe0000) | ((*addr) << 1), val); @@ -307,7 +340,7 @@ cmi8x38_sb_dma_writew(void *priv, uint16_t val) } static void -cmi8x38_dma_write(uint16_t addr, uint8_t val, void *priv) +cmi8x38_dma_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; @@ -333,8 +366,8 @@ cmi8x38_dma_write(uint16_t addr, uint8_t val, void *priv) } /* Write base address and count. */ - uint16_t *daddr = (uint16_t *) &dev->io_regs[0x1c], - *count = (uint16_t *) &dev->io_regs[0x1e]; + uint16_t *daddr = (uint16_t *) &dev->io_regs[0x1c]; + uint16_t *count = (uint16_t *) &dev->io_regs[0x1e]; *daddr = dev->tdma_base_addr = dma[channel].ab >> !!(channel & 4); *count = dev->tdma_base_count = dma[channel].cb; cmi8x38_log("CMI8x38: Starting TDMA on DMA %d with addr %08X count %04X\n", @@ -348,7 +381,7 @@ cmi8x38_dma_write(uint16_t addr, uint8_t val, void *priv) } static void -cmi8x38_dma_mask_write(uint16_t addr, uint8_t val, void *priv) +cmi8x38_dma_mask_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; @@ -365,7 +398,7 @@ cmi8x38_dma_mask_write(uint16_t addr, uint8_t val, void *priv) } static void -cmi8338_io_trap(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) +cmi8338_io_trap(UNUSED(int size), uint16_t addr, uint8_t write, uint8_t val, void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; @@ -390,9 +423,9 @@ cmi8338_io_trap(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) static uint8_t cmi8x38_sb_mixer_read(uint16_t addr, void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; - sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; - uint8_t ret = sb_ct1745_mixer_read(addr, dev->sb); + cmi8x38_t *dev = (cmi8x38_t *) priv; + const sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; + uint8_t ret = sb_ct1745_mixer_read(addr, dev->sb); if (addr & 1) { if ((mixer->index == 0x0e) || (mixer->index >= 0xf0)) @@ -435,10 +468,15 @@ cmi8x38_sb_mixer_write(uint16_t addr, uint8_t val, void *priv) case 0xf8 ... 0xff: if (dev->type == CMEDIA_CMI8338) mixer->regs[mixer->index] = val; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xf1 ... 0xf7: return; + + default: + break; } sb_ct1745_mixer_write(addr, val, dev->sb); @@ -446,8 +484,8 @@ cmi8x38_sb_mixer_write(uint16_t addr, uint8_t val, void *priv) /* No [3F:47] controls. */ mixer->input_gain_L = 0; mixer->input_gain_R = 0; - mixer->output_gain_L = (double) 1.0; - mixer->output_gain_R = (double) 1.0; + mixer->output_gain_L = 1.0; + mixer->output_gain_R = 1.0; mixer->bass_l = 8; mixer->bass_r = 8; mixer->treble_l = 8; @@ -556,7 +594,8 @@ cmi8x38_remap_traps(cmi8x38_t *dev) static void cmi8x38_start_playback(cmi8x38_t *dev) { - uint8_t i, val = dev->io_regs[0x00]; + uint8_t i; + uint8_t val = dev->io_regs[0x00]; i = !(val & 0x01); if (!dev->dma[0].playback_enabled && i) @@ -919,8 +958,8 @@ cmi8x38_remap(cmi8x38_t *dev) static uint8_t cmi8x38_pci_read(int func, int addr, void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; - uint8_t ret = 0xff; + const cmi8x38_t *dev = (cmi8x38_t *) priv; + uint8_t ret = 0xff; if (!func) { ret = dev->pci_regs[addr]; @@ -989,9 +1028,9 @@ cmi8x38_pci_write(int func, int addr, uint8_t val, void *priv) static void cmi8x38_update(cmi8x38_t *dev, cmi8x38_dma_t *dma) { - sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; - int32_t l = (dma->out_fl * mixer->voice_l) * mixer->master_l, - r = (dma->out_fr * mixer->voice_r) * mixer->master_r; + const sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; + int32_t l = (dma->out_fl * mixer->voice_l) * mixer->master_l; + int32_t r = (dma->out_fr * mixer->voice_r) * mixer->master_r; for (; dma->pos < sound_pos_global; dma->pos++) { dma->buffer[dma->pos * 2] = l; @@ -1083,7 +1122,10 @@ cmi8x38_poll(void *priv) { cmi8x38_dma_t *dma = (cmi8x38_dma_t *) priv; cmi8x38_t *dev = dma->dev; - int16_t *out_l, *out_r, *out_ol, *out_or; /* o = opposite */ + int16_t *out_l; + int16_t *out_r; + int16_t *out_ol; + int16_t *out_or; /* o = opposite */ /* Schedule next run if playback is enabled. */ if (dma->playback_enabled) @@ -1197,8 +1239,14 @@ cmi8x38_poll(void *priv) return; } break; + + default: + break; } break; + + default: + break; } /* Feed silence if the FIFO is empty. */ @@ -1245,8 +1293,10 @@ cmi8x38_speed_changed(void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; double freq; - uint8_t dsr = dev->io_regs[0x09], freqreg = dev->io_regs[0x05] >> 2, - chfmt45 = dev->io_regs[0x0b], chfmt6 = dev->io_regs[0x15]; + uint8_t dsr = dev->io_regs[0x09]; + uint8_t freqreg = dev->io_regs[0x05] >> 2; + uint8_t chfmt45 = dev->io_regs[0x0b]; + uint8_t chfmt6 = dev->io_regs[0x15]; #ifdef ENABLE_CMI8X38_LOG char buf[256]; diff --git a/src/sound/snd_cms.c b/src/sound/snd_cms.c index 1b55765fa..d33eba83a 100644 --- a/src/sound/snd_cms.c +++ b/src/sound/snd_cms.c @@ -10,15 +10,16 @@ #include <86box/io.h> #include <86box/snd_cms.h> #include <86box/sound.h> +#include <86box/plat_unused.h> void cms_update(cms_t *cms) { for (; cms->pos < sound_pos_global; cms->pos++) { - int c, d; - int16_t out_l = 0, out_r = 0; + int16_t out_l = 0; + int16_t out_r = 0; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { switch (cms->noisetype[c >> 1][c & 1]) { case 0: cms->noisefreq[c >> 1][c & 1] = MASTER_CLOCK / 256; @@ -32,11 +33,14 @@ cms_update(cms_t *cms) case 3: cms->noisefreq[c >> 1][c & 1] = cms->freq[c >> 1][(c & 1) * 3]; break; + + default: + break; } } - for (c = 0; c < 2; c++) { + for (uint8_t c = 0; c < 2; c++) { if (cms->regs[c][0x1C] & 1) { - for (d = 0; d < 6; d++) { + for (uint8_t d = 0; d < 6; d++) { if (cms->regs[c][0x14] & (1 << d)) { if (cms->stat[c][d]) out_l += (cms->vol[c][d][0] * 90); @@ -54,7 +58,7 @@ cms_update(cms_t *cms) out_r += (cms->vol[c][d][0] * 90); } } - for (d = 0; d < 2; d++) { + for (uint8_t d = 0; d < 2; d++) { cms->noisecount[c][d] += cms->noisefreq[c][d]; while (cms->noisecount[c][d] >= 24000) { cms->noisecount[c][d] -= 24000; @@ -65,30 +69,28 @@ cms_update(cms_t *cms) } } } - cms->buffer[(cms->pos << 1)] = out_l; + cms->buffer[cms->pos << 1] = out_l; cms->buffer[(cms->pos << 1) + 1] = out_r; } } void -cms_get_buffer(int32_t *buffer, int len, void *p) +cms_get_buffer(int32_t *buffer, int len, void *priv) { - cms_t *cms = (cms_t *) p; - - int c; + cms_t *cms = (cms_t *) priv; cms_update(cms); - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += cms->buffer[c]; cms->pos = 0; } void -cms_write(uint16_t addr, uint8_t val, void *p) +cms_write(uint16_t addr, uint8_t val, void *priv) { - cms_t *cms = (cms_t *) p; + cms_t *cms = (cms_t *) priv; int voice; int chip = (addr & 2) >> 1; @@ -138,19 +140,25 @@ cms_write(uint16_t addr, uint8_t val, void *p) cms->noisetype[chip][0] = val & 3; cms->noisetype[chip][1] = (val >> 4) & 3; break; + + default: + break; } break; case 0x6: case 0x7: cms->latched_data = val; break; + + default: + break; } } uint8_t -cms_read(uint16_t addr, void *p) +cms_read(uint16_t addr, void *priv) { - cms_t *cms = (cms_t *) p; + const cms_t *cms = (cms_t *) priv; switch (addr & 0xf) { case 0x1: @@ -162,12 +170,15 @@ cms_read(uint16_t addr, void *p) case 0xa: case 0xb: return cms->latched_data; + + default: + break; } return 0xff; } void * -cms_init(const device_t *info) +cms_init(UNUSED(const device_t *info)) { cms_t *cms = malloc(sizeof(cms_t)); memset(cms, 0, sizeof(cms_t)); @@ -179,9 +190,9 @@ cms_init(const device_t *info) } void -cms_close(void *p) +cms_close(void *priv) { - cms_t *cms = (cms_t *) p; + cms_t *cms = (cms_t *) priv; free(cms); } diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 0a98d9886..fff716e28 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -36,6 +36,8 @@ #include <86box/snd_ad1848.h> #include <86box/snd_opl.h> #include <86box/snd_sb.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #define CRYSTAL_NOEEPROM 0x100 @@ -133,14 +135,32 @@ typedef struct cs423x_t { ad1848_t ad1848; sb_t *sb; void *gameport; - void *i2c, *eeprom; + void *i2c; + void *eeprom; - uint16_t wss_base, opl_base, sb_base, ctrl_base, ram_addr, eeprom_size : 11, pnp_offset; - uint8_t type, ad1848_type, regs[8], indirect_regs[16], - eeprom_data[2048], ram_data[65536], ram_dl : 2, opl_wss : 1; - char *nvr_path; + uint16_t wss_base; + uint16_t opl_base; + uint16_t sb_base; + uint16_t ctrl_base; + uint16_t ram_addr; + uint16_t eeprom_size : 11; + uint16_t pnp_offset; + uint8_t type; + uint8_t ad1848_type; + uint8_t regs[8]; + uint8_t indirect_regs[16]; + uint8_t eeprom_data[2048]; + uint8_t ram_data[65536]; + uint8_t ram_dl : 2; + uint8_t opl_wss : 1; + char *nvr_path; - uint8_t pnp_enable : 1, key_pos : 5, slam_enable : 1, slam_state : 2, slam_ld, slam_reg; + uint8_t pnp_enable : 1; + uint8_t key_pos : 5; + uint8_t slam_enable : 1; + uint8_t slam_state : 2; + uint8_t slam_ld; + uint8_t slam_reg; isapnp_device_config_t *slam_config; } cs423x_t; @@ -198,6 +218,9 @@ cs423x_read(uint16_t addr, void *priv) ret |= 0x20; break; + + default: + break; } return ret; @@ -264,6 +287,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) dev->ad1848.wten = !!(val & 0x08); ad1848_updatevolmask(&dev->ad1848); break; + + default: + break; } dev->indirect_regs[dev->regs[3]] = val; break; @@ -274,7 +300,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) switch (val) { case 0x55: /* Disable PnP Key */ dev->pnp_enable = 0; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x5a: /* Update Hardware Configuration Data */ cs423x_pnp_enable(dev, 0, 1); @@ -290,6 +318,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 0xaa: /* Download RAM */ dev->ram_dl = 1; break; + + default: + break; } break; @@ -306,6 +337,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 3: /* data */ dev->ram_data[dev->ram_addr++] = val; break; + + default: + break; } break; @@ -321,13 +355,16 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 7: /* Global Status */ return; + + default: + break; } dev->regs[reg] = val; } static void -cs423x_slam_write(uint16_t addr, uint8_t val, void *priv) +cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { cs423x_t *dev = (cs423x_t *) priv; uint8_t idx; @@ -441,11 +478,17 @@ cs423x_slam_write(uint16_t addr, uint8_t val, void *priv) /* Activate or deactivate the device. */ dev->slam_config->activate = val & 0x01; break; + + default: + break; } /* Prepare for the next register, unless a two-byte read returns above. */ dev->slam_state = CRYSTAL_SLAM_INDEX; break; + + default: + break; } } @@ -467,11 +510,11 @@ cs423x_slam_enable(cs423x_t *dev, uint8_t enable) } static void -cs423x_ctxswitch_write(uint16_t addr, uint8_t val, void *priv) +cs423x_ctxswitch_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { - cs423x_t *dev = (cs423x_t *) priv; - uint8_t ctx = (dev->regs[7] & 0x80), - enable_opl = (dev->ad1848.xregs[4] & 0x10) && !(dev->indirect_regs[2] & 0x85); + cs423x_t *dev = (cs423x_t *) priv; + uint8_t ctx = (dev->regs[7] & 0x80); + uint8_t enable_opl = (dev->ad1848.xregs[4] & 0x10) && !(dev->indirect_regs[2] & 0x85); /* Check if a context switch (WSS=1 <-> SBPro=0) occurred through the address being written. */ if ((dev->regs[7] & 0x80) ? ((addr & 0xfff0) == dev->sb_base) : ((addr & 0xfffc) == dev->wss_base)) { @@ -503,9 +546,9 @@ cs423x_ctxswitch_write(uint16_t addr, uint8_t val, void *priv) static void cs423x_get_buffer(int32_t *buffer, int len, void *priv) { - cs423x_t *dev = (cs423x_t *) priv; - int c, opl_wss = dev->opl_wss; - int32_t *opl_buf = NULL; + cs423x_t *dev = (cs423x_t *) priv; + int opl_wss = dev->opl_wss; + const int32_t *opl_buf = NULL; /* Output audio from the WSS codec, and also the OPL if we're in charge of it. */ ad1848_update(&dev->ad1848); @@ -514,7 +557,7 @@ cs423x_get_buffer(int32_t *buffer, int len, void *priv) /* Don't output anything if the analog section is powered down. */ if (!(dev->indirect_regs[2] & 0xa4)) { - for (c = 0; c < len * 2; c += 2) { + for (int c = 0; c < len * 2; c += 2) { if (opl_wss) { buffer[c] += (opl_buf[c] * dev->ad1848.fm_vol_l) >> 16; buffer[c + 1] += (opl_buf[c + 1] * dev->ad1848.fm_vol_r) >> 16; @@ -542,7 +585,9 @@ cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) /* But wait! The TriGem Delhi-III BIOS sends command 0x55, and its behavior doesn't line up with real hardware (still listed in the POST summary and seen by software). Disable the PnP key disabling mechanism until someone figures something out. */ - // isapnp_enable_card(dev->pnp_card, ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) ? ISAPNP_CARD_NO_KEY : ISAPNP_CARD_ENABLE); +#if 0 + isapnp_enable_card(dev->pnp_card, ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) ? ISAPNP_CARD_NO_KEY : ISAPNP_CARD_ENABLE); +#endif if ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) pclog("CS423x: Attempted to disable PnP key\n"); } @@ -674,6 +719,9 @@ cs423x_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv } break; + + default: + break; } } @@ -764,6 +812,9 @@ cs423x_init(const device_t *info) dev->eeprom_data[26] = 0x38; dev->nvr_path = "cs4238b.nvr"; break; + + default: + break; } /* Load EEPROM contents from file if present. */ @@ -775,6 +826,9 @@ cs423x_init(const device_t *info) dev->gameport = gameport_add(((dev->type == CRYSTAL_CS4235) || (dev->type == CRYSTAL_CS4236B)) ? &gameport_pnp_device : &gameport_pnp_6io_device); break; + + default: + break; } /* Initialize I2C bus for the EEPROM. */ diff --git a/src/sound/snd_emu8k.c b/src/sound/snd_emu8k.c index b58def3a9..ad00461f1 100644 --- a/src/sound/snd_emu8k.c +++ b/src/sound/snd_emu8k.c @@ -17,81 +17,90 @@ #include <86box/sound.h> #include <86box/snd_emu8k.h> #include <86box/timer.h> +#include <86box/plat_unused.h> #if !defined FILTER_INITIAL && !defined FILTER_MOOG && !defined FILTER_CONSTANT -// #define FILTER_INITIAL +#if 0 +#define FILTER_INITIAL +#endif # define FILTER_MOOG -// #define FILTER_CONSTANT +#if 0 +#define FILTER_CONSTANT +#endif #endif #if !defined RESAMPLER_LINEAR && !defined RESAMPLER_CUBIC -// #define RESAMPLER_LINEAR +#if 0 +#define RESAMPLER_LINEAR +#endif # define RESAMPLER_CUBIC #endif -// #define EMU8K_DEBUG_REGISTERS +#if 0 +#define EMU8K_DEBUG_REGISTERS +#endif char *PORT_NAMES[][8] = { - /* Data 0 ( 0x620/0x622) */ + /* Data 0 ( 0x620/0x622) */ { - "AWE_CPF", - "AWE_PTRX", - "AWE_CVCF", - "AWE_VTFT", - "Unk-620-4", - "Unk-620-5", - "AWE_PSST", - "AWE_CSL", - }, - /* Data 1 0xA20 */ + "AWE_CPF", + "AWE_PTRX", + "AWE_CVCF", + "AWE_VTFT", + "Unk-620-4", + "Unk-620-5", + "AWE_PSST", + "AWE_CSL", + }, + /* Data 1 0xA20 */ { - "AWE_CCCA", - 0, - /* - "AWE_HWCF4" - "AWE_HWCF5" - "AWE_HWCF6" - "AWE_HWCF7" - "AWE_SMALR" - "AWE_SMARR" - "AWE_SMALW" - "AWE_SMARW" - "AWE_SMLD" - "AWE_SMRD" - "AWE_WC" - "AWE_HWCF1" - "AWE_HWCF2" - "AWE_HWCF3" - */ - 0, //"AWE_INIT1", - 0, //"AWE_INIT3", + "AWE_CCCA", + 0, + /* + "AWE_HWCF4" + "AWE_HWCF5" + "AWE_HWCF6" + "AWE_HWCF7" + "AWE_SMALR" + "AWE_SMARR" + "AWE_SMALW" + "AWE_SMARW" + "AWE_SMLD" + "AWE_SMRD" + "AWE_WC" + "AWE_HWCF1" + "AWE_HWCF2" + "AWE_HWCF3" + */ + 0, //"AWE_INIT1", + 0, //"AWE_INIT3", "AWE_ENVVOL", - "AWE_DCYSUSV", - "AWE_ENVVAL", - "AWE_DCYSUS", - }, - /* Data 2 0xA22 */ + "AWE_DCYSUSV", + "AWE_ENVVAL", + "AWE_DCYSUS", + }, + /* Data 2 0xA22 */ { - "AWE_CCCA", - 0, - 0, //"AWE_INIT2", - 0, //"AWE_INIT4", + "AWE_CCCA", + 0, + 0, //"AWE_INIT2", + 0, //"AWE_INIT4", "AWE_ATKHLDV", - "AWE_LFO1VAL", - "AWE_ATKHLD", - "AWE_LFO2VAL", - }, - /* Data 3 0xE20 */ + "AWE_LFO1VAL", + "AWE_ATKHLD", + "AWE_LFO2VAL", + }, + /* Data 3 0xE20 */ { - "AWE_IP", - "AWE_IFATN", - "AWE_PEFE", - "AWE_FMMOD", - "AWE_TREMFRQ", - "AWE_FM2FRQ2", - 0, - 0, - }, + "AWE_IP", + "AWE_IFATN", + "AWE_PEFE", + "AWE_FMMOD", + "AWE_TREMFRQ", + "AWE_FM2FRQ2", + 0, + 0, + }, }; enum { @@ -143,13 +152,13 @@ static int32_t env_attack_to_samples[128]; * In other words, the unit of the table is the 1/21845th of a dB per sample frame, to be added or * substracted to the accumulating value_db of the envelope. */ static int32_t env_decay_to_dbs_or_oct[128] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 32, - 33, 34, 36, 38, 39, 41, 43, 45, 49, 51, 53, 55, 58, 60, 63, 66, - 69, 72, 75, 78, 82, 85, 89, 93, 97, 102, 106, 111, 116, 121, 126, 132, - 138, 144, 150, 157, 164, 171, 179, 186, 195, 203, 212, 222, 232, 243, 253, 264, - 276, 288, 301, 315, 328, 342, 358, 374, 390, 406, 425, 444, 466, 485, 506, 528, - 553, 580, 602, 634, 660, 689, 721, 755, 780, 820, 849, 897, 932, 970, 1012, 1057, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 32, + 33, 34, 36, 38, 39, 41, 43, 45, 49, 51, 53, 55, 58, 60, 63, 66, + 69, 72, 75, 78, 82, 85, 89, 93, 97, 102, 106, 111, 116, 121, 126, 132, + 138, 144, 150, 157, 164, 171, 179, 186, 195, 203, 212, 222, 232, 243, 253, 264, + 276, 288, 301, 315, 328, 342, 358, 374, 390, 406, 425, 444, 466, 485, 506, 528, + 553, 580, 602, 634, 660, 689, 721, 755, 780, 820, 849, 897, 932, 970, 1012, 1057, 1106, 1160, 1219, 1285, 1321, 1399, 1441, 1534, 1585, 1640, 1698, 1829, 1902, 1981, 2068, 2162 }; @@ -158,17 +167,19 @@ static int32_t env_decay_to_dbs_or_oct[128] = { * I tried calculating it using the instructions in awe32p10 from Judge Dredd, but the formula there * is wrong. * + */ +#if 0 static int32_t env_decay_to_millis[128] = { -0, 45120, 22614, 15990, 11307, 9508, 7995, 6723, 5653, 5184, 4754, 4359, 3997, 3665, 3361, 3082, -2828, 2765, 2648, 2535, 2428, 2325, 2226, 2132, 2042, 1955, 1872, 1793, 1717, 1644, 1574, 1507, -1443, 1382, 1324, 1267, 1214, 1162, 1113, 1066, 978, 936, 897, 859, 822, 787, 754, 722, -691, 662, 634, 607, 581, 557, 533, 510, 489, 468, 448, 429, 411, 393, 377, 361, -345, 331, 317, 303, 290, 278, 266, 255, 244, 234, 224, 214, 205, 196, 188, 180, -172, 165, 158, 151, 145, 139, 133, 127, 122, 117, 112, 107, 102, 98, 94, 90, -86, 82, 79, 75, 72, 69, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, -43, 41, 39, 37, 36, 34, 33, 31, 30, 29, 28, 26, 25, 24, 23, 22, + 0, 45120, 22614, 15990, 11307, 9508, 7995, 6723, 5653, 5184, 4754, 4359, 3997, 3665, 3361, 3082, + 2828, 2765, 2648, 2535, 2428, 2325, 2226, 2132, 2042, 1955, 1872, 1793, 1717, 1644, 1574, 1507, + 1443, 1382, 1324, 1267, 1214, 1162, 1113, 1066, 978, 936, 897, 859, 822, 787, 754, 722, + 691, 662, 634, 607, 581, 557, 533, 510, 489, 468, 448, 429, 411, 393, 377, 361, + 345, 331, 317, 303, 290, 278, 266, 255, 244, 234, 224, 214, 205, 196, 188, 180, + 172, 165, 158, 151, 145, 139, 133, 127, 122, 117, 112, 107, 102, 98, 94, 90, + 86, 82, 79, 75, 72, 69, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, + 43, 41, 39, 37, 36, 34, 33, 31, 30, 29, 28, 26, 25, 24, 23, 22, }; -*/ +#endif /* Table represeting the LFO waveform (signed 16bits with 32768 max int. >> 15 to move back to +/-1 range). */ static int32_t lfotable[65536]; @@ -348,7 +359,9 @@ EMU8K_READ_INTERP_CUBIC(emu8k_t *emu8k, uint32_t int_addr, uint16_t fract) * the card could use two oscillators (usually 31 and 32) where it would * be writing the OPL3 output, and to which, chorus and reverb could be applied to get * those effects for OPL3 sounds.*/ - // if ((addr & EMU8K_FM_MEM_ADDRESS) == EMU8K_FM_MEM_ADDRESS) {} +#if 0 + if ((addr & EMU8K_FM_MEM_ADDRESS) == EMU8K_FM_MEM_ADDRESS) {} +#endif /* This is cubic interpolation. * Not the same than 3-point interpolation, but a better approximation than linear @@ -383,9 +396,9 @@ EMU8K_WRITE(emu8k_t *emu8k, uint32_t addr, uint16_t val) } uint16_t -emu8k_inw(uint16_t addr, void *p) +emu8k_inw(uint16_t addr, void *priv) { - emu8k_t *emu8k = (emu8k_t *) p; + emu8k_t *emu8k = (emu8k_t *) priv; uint16_t ret = 0xffff; #ifdef EMU8K_DEBUG_REGISTERS @@ -557,6 +570,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: READ16(addr, emu8k->voice[emu8k->cur_voice].csl); return ret; + + default: + break; } break; @@ -611,6 +627,9 @@ emu8k_inw(uint16_t addr, void *p) | ((emu8k->hwcf3 & 0x08) ? 0x20 : 0) | ((emu8k->hwcf3 & 0x10) ? 0x80 : 0); case 31: /*Configuration Word 3*/ return emu8k->hwcf2 & 0x1f; + + default: + break; } break; @@ -631,6 +650,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: return emu8k->voice[emu8k->cur_voice].dcysus; + + default: + break; } break; @@ -690,6 +712,9 @@ emu8k_inw(uint16_t addr, void *p) the amount of calls and wait time */ case 27: /*Sample Counter ( 44Khz clock) */ return emu8k->wc; + + default: + break; } break; @@ -710,6 +735,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: return emu8k->voice[emu8k->cur_voice].lfo2val; + + default: + break; } break; @@ -738,6 +766,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: /*ID?*/ return 0x1c | ((emu8k->id & 0x0002) ? 0xff02 : 0); + + default: + break; } break; @@ -749,15 +780,18 @@ emu8k_inw(uint16_t addr, void *p) * cubic player has a similar code, where it waits until value & 0x1000 is nonzero, and then waits again until it changes to zero.*/ random_helper = (random_helper + 1) & 0x1F; return ((0x80 | random_helper) << 8) | (emu8k->cur_reg << 5) | emu8k->cur_voice; + + default: + break; } emu8k_log("EMU8K READ : Unknown register read: %04X-%02X(%d/%d) \n", addr, (emu8k->cur_reg << 5) | emu8k->cur_voice, emu8k->cur_reg, emu8k->cur_voice); return 0xffff; } void -emu8k_outw(uint16_t addr, uint16_t val, void *p) +emu8k_outw(uint16_t addr, uint16_t val, void *priv) { - emu8k_t *emu8k = (emu8k_t *) p; + emu8k_t *emu8k = (emu8k_t *) priv; /*TODO: I would like to not call this here, but i found it was needed or else cubic player would not finish opening (take a looot more of time than usual). * Basically, being here means that the audio is generated in the emulation thread, instead of the audio thread.*/ @@ -879,6 +913,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) /* TODO: Should we update only on MSB update, or this could be used as some sort of hack by applications? */ emu8k->voice[emu8k->cur_voice].loop_end.int_address = emu8k->voice[emu8k->cur_voice].csl & EMU8K_MEM_ADDRESS_MASK; return; + + default: + break; } break; @@ -933,6 +970,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 31: emu8k->hwcf3 = val; return; + + default: + break; } break; @@ -946,8 +986,7 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) break; case 0x5: { - int c; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { emu8k->reverb_engine.allpass[c].feedback = (val & 0xFF) / ((float) 0xFF); } } @@ -967,17 +1006,29 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 0x9: emu8k->reverb_engine.reflections[0].feedback = (val & 0xF) / 15.0; break; - case 0xB: // emu8k->reverb_engine.reflections[0].feedback_r = (val&0xF)/15.0; + case 0xB: +#if 0 + emu8k->reverb_engine.reflections[0].feedback_r = (val&0xF)/15.0; +#endif break; case 0x11: emu8k->reverb_engine.reflections[1].feedback = (val & 0xF) / 15.0; break; - case 0x13: // emu8k->reverb_engine.reflections[1].feedback_r = (val&0xF)/15.0; + case 0x13: +#if 0 + emu8k->reverb_engine.reflections[1].feedback_r = (val&0xF)/15.0; +#endif break; case 0x19: emu8k->reverb_engine.reflections[2].feedback = (val & 0xF) / 15.0; break; - case 0x1B: // emu8k->reverb_engine.reflections[2].feedback_r = (val&0xF)/15.0; + case 0x1B: +#if 0 + emu8k->reverb_engine.reflections[2].feedback_r = (val&0xF)/15.0; +#endif + break; + + default: break; } } @@ -999,7 +1050,13 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 1: emu8k->reverb_engine.refl_in_amp = val & 0xFF; break; - case 3: // emu8k->reverb_engine.refl_in_amp_r = val&0xFF; + case 3: +#if 0 + emu8k->reverb_engine.refl_in_amp_r = val&0xFF; +#endif + break; + + default: break; } } @@ -1106,6 +1163,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) } } return; + + default: + break; } break; @@ -1181,6 +1241,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) EMU8K_WRITE(emu8k, emu8k->smarw, val); emu8k->smarw++; return; + + default: + break; } break; @@ -1216,8 +1279,7 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) break; case 0x1d: { - int c; - for (c = 0; c < 6; c++) { + for (uint8_t c = 0; c < 6; c++) { emu8k->reverb_engine.reflections[c].damp1 = (val & 0xFF) / 255.0; emu8k->reverb_engine.reflections[c].damp2 = (0xFF - (val & 0xFF)) / 255.0; emu8k->reverb_engine.reflections[c].filterstore = 0; @@ -1232,17 +1294,29 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 0x1: emu8k->reverb_engine.reflections[3].feedback = (val & 0xF) / 15.0; break; - case 0x3: // emu8k->reverb_engine.reflections[3].feedback_r = (val&0xF)/15.0; + case 0x3: +#if 0 + emu8k->reverb_engine.reflections[3].feedback_r = (val&0xF)/15.0; +#endif break; case 0x9: emu8k->reverb_engine.reflections[4].feedback = (val & 0xF) / 15.0; break; - case 0xb: // emu8k->reverb_engine.reflections[4].feedback_r = (val&0xF)/15.0; + case 0xb: +#if 0 + emu8k->reverb_engine.reflections[4].feedback_r = (val&0xF)/15.0; +#endif break; case 0x11: emu8k->reverb_engine.reflections[5].feedback = (val & 0xF) / 15.0; break; - case 0x13: // emu8k->reverb_engine.reflections[5].feedback_r = (val&0xF)/15.0; + case 0x13: +#if 0 + emu8k->reverb_engine.reflections[5].feedback_r = (val&0xF)/15.0; +#endif + break; + + default: break; } } @@ -1263,6 +1337,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 0x1F: emu8k->reverb_engine.link_return_amp = val & 0xFF; break; + + default: + break; } } return; @@ -1348,6 +1425,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) emu8k->voice[emu8k->cur_voice].lfo2_delay_samples = LFOxVAL_TO_EMU_SAMPLES(val); return; + + default: + break; } break; @@ -1431,6 +1511,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 7: /*ID? I believe that this allows applications to know if the emu is in use by another application */ emu8k->id = val; return; + + default: + break; } break; @@ -1438,40 +1521,44 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) emu8k->cur_voice = (val & 31); emu8k->cur_reg = ((val >> 5) & 7); return; + + default: + break; } emu8k_log("EMU8K WRITE: Unknown register write: %04X-%02X(%d/%d): %04X \n", addr, (emu8k->cur_reg) << 5 | emu8k->cur_voice, emu8k->cur_reg, emu8k->cur_voice, val); } uint8_t -emu8k_inb(uint16_t addr, void *p) +emu8k_inb(uint16_t addr, void *priv) { /* Reading a single byte is a feature that at least Impulse tracker uses, * but only on detection code and not for odd addresses.*/ if (addr & 1) - return emu8k_inw(addr & ~1, p) >> 1; - return emu8k_inw(addr, p) & 0xff; + return emu8k_inw(addr & ~1, priv) >> 1; + return emu8k_inw(addr, priv) & 0xff; } void -emu8k_outb(uint16_t addr, uint8_t val, void *p) +emu8k_outb(uint16_t addr, uint8_t val, void *priv) { /* TODO: AWE32 docs says that you cannot write in bytes, but if * an app were to use this implementation, the content of the LS Byte would be lost.*/ if (addr & 1) - emu8k_outw(addr & ~1, val << 8, p); + emu8k_outw(addr & ~1, val << 8, priv); else - emu8k_outw(addr, val, p); + emu8k_outw(addr, val, priv); } /* TODO: This is not a correct emulation, just a workalike implementation. */ void emu8k_work_chorus(int32_t *inbuf, int32_t *outbuf, emu8k_chorus_eng_t *engine, int count) { - int pos; - for (pos = 0; pos < count; pos++) { + for (int pos = 0; pos < count; pos++) { double lfo_inter1 = chortable[engine->lfo_pos.int_address]; - // double lfo_inter2 = chortable[(engine->lfo_pos.int_address+1)&0xFFFF]; +#if 0 + double lfo_inter2 = chortable[(engine->lfo_pos.int_address+1)&0xFFFF]; +#endif double offset_lfo = lfo_inter1; //= lfo_inter1 + ((lfo_inter2-lfo_inter1)*engine->lfo_pos.fract_address/65536.0); offset_lfo *= engine->lfodepth_multip; @@ -1570,10 +1657,14 @@ emu8k_reverb_tail_work(emu8k_reverb_combfilter_t *comb, emu8k_reverb_combfilter_ /* store new value in delayed buffer */ comb->reflection[comb->read_pos] = in; - // output = emu8k_reverb_allpass_work(&allpasses[0],output); +#if 0 + output = emu8k_reverb_allpass_work(&allpasses[0],output); +#endif output = emu8k_reverb_diffuser_work(&allpasses[1], output); output = emu8k_reverb_diffuser_work(&allpasses[2], output); - // output = emu8k_reverb_allpass_work(&allpasses[3],output); +#if 0 + output = emu8k_reverb_allpass_work(&allpasses[3],output); +#endif if (++comb->read_pos >= comb->bufsize) comb->read_pos = 0; @@ -1595,7 +1686,10 @@ emu8k_work_reverb(int32_t *inbuf, int32_t *outbuf, emu8k_reverb_eng_t *engine, i int pos; if (engine->link_return_type) { for (pos = 0; pos < count; pos++) { - int32_t dat1, dat2, in, in2; + int32_t dat1; + int32_t dat2; + int32_t in; + int32_t in2; in = emu8k_reverb_damper_work(&engine->damper, inbuf[pos]); in2 = (in * engine->refl_in_amp) >> 8; dat2 = emu8k_reverb_comb_work(&engine->reflections[0], in2); @@ -1613,7 +1707,10 @@ emu8k_work_reverb(int32_t *inbuf, int32_t *outbuf, emu8k_reverb_eng_t *engine, i } } else { for (pos = 0; pos < count; pos++) { - int32_t dat1, dat2, in, in2; + int32_t dat1; + int32_t dat2; + int32_t in; + int32_t in2; in = emu8k_reverb_damper_work(&engine->damper, inbuf[pos]); in2 = (in * engine->refl_in_amp) >> 8; dat1 = emu8k_reverb_comb_work(&engine->reflections[0], in2); @@ -1633,7 +1730,7 @@ emu8k_work_reverb(int32_t *inbuf, int32_t *outbuf, emu8k_reverb_eng_t *engine, i } } void -emu8k_work_eq(int32_t *inoutbuf, int count) +emu8k_work_eq(UNUSED(int32_t *inoutbuf), UNUSED(int count)) { // TODO: Work EQ over buf } @@ -1653,9 +1750,11 @@ emu8k_vol_slide(emu8k_slide_t *slide, int32_t target) return slide->last; } -// int32_t old_pitch[32]={0}; -// int32_t old_cut[32]={0}; -// int32_t old_vol[32]={0}; +#if 0 +int32_t old_pitch[32] = { 0 }; +int32_t old_cut[32] = { 0 }; +int32_t old_vol[32] = { 0 }; +#endif void emu8k_update(emu8k_t *emu8k) { @@ -1666,7 +1765,6 @@ emu8k_update(emu8k_t *emu8k) int32_t *buf; emu8k_voice_t *emu_voice; int pos; - int c; /* Clean the buffers since we will accumulate into them. */ buf = &emu8k->buffer[emu8k->pos * 2]; @@ -1675,7 +1773,7 @@ emu8k_update(emu8k_t *emu8k) memset(&emu8k->reverb_in_buffer[emu8k->pos], 0, (new_pos - emu8k->pos) * sizeof(emu8k->reverb_in_buffer[0])); /* Voices section */ - for (c = 0; c < 32; c++) { + for (uint8_t c = 0; c < 32; c++) { emu_voice = &emu8k->voice[c]; buf = &emu8k->buffer[emu8k->pos * 2]; @@ -1859,6 +1957,9 @@ emu8k_update(emu8k_t *emu8k) case ENV_STOPPED: attenuation = 0x1FFFFF; break; + + default: + break; } emu8k_envelope_t *modenv = &emu_voice->mod_envelope; @@ -1910,6 +2011,9 @@ emu8k_update(emu8k_t *emu8k) modenv->state = ENV_SUSTAIN; } break; + + default: + break; } /* run lfos */ @@ -2007,11 +2111,13 @@ emu8k_update(emu8k_t *emu8k) emu_voice->ccca = (((uint32_t) emu_voice->ccca_qcontrol) << 24) | emu_voice->addr.int_address; emu_voice->cpf_curr_frac_addr = emu_voice->addr.fract_address; - // if ( emu_voice->cvcf_curr_volume != old_vol[c]) { - // pclog("EMUVOL (%d):%d\n", c, emu_voice->cvcf_curr_volume); - // old_vol[c]=emu_voice->cvcf_curr_volume; - // } - // pclog("EMUFILT :%d\n", emu_voice->cvcf_curr_filt_ctoff); +#if 0 + if (emu_voice->cvcf_curr_volume != old_vol[c]) { + pclog("EMUVOL (%d):%d\n", c, emu_voice->cvcf_curr_volume); + old_vol[c]=emu_voice->cvcf_curr_volume; + } + pclog("EMUFILT :%d\n", emu_voice->cvcf_curr_filt_ctoff); +#endif } buf = &emu8k->buffer[emu8k->pos * 2]; @@ -2140,8 +2246,10 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) * Important: Using 65535 as max output value because this is intended to be used with the volume target register! */ out = 65535.0; for (c = 0; c < 0x10000; c++) { - // double db = -(c*6.0205999/65535.0)*16.0; - // out = powf(10.f,db/20.f) * 65536.0; +#if 0 + double db = -(c*6.0205999/65535.0)*16.0; + out = powf(10.f,db/20.f) * 65536.0; +#endif env_vol_db_to_vol_target[c] = (int32_t) out; /* calculated from the 65536th root of 65536 */ out /= 1.00016923970; @@ -2205,8 +2313,7 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) } /* Filter coefficients tables. Note: Values are multiplied by *16777216 to left shift 24 bits. (i.e. 8.24 fixed point) */ - int qidx; - for (qidx = 0; qidx < 16; qidx++) { + for (uint8_t qidx = 0; qidx < 16; qidx++) { out = 125.0; /* Start at 125Hz */ for (c = 0; c < 256; c++) { #ifdef FILTER_INITIAL diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index 2bef7edac..c7e6d39f9 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -17,6 +17,8 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_ad1848.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> enum { MIDI_INT_RECEIVE = 0x01, @@ -48,28 +50,42 @@ typedef struct gus_t { int reset; int global; - uint32_t addr, dmaaddr; + uint32_t addr; + uint32_t dmaaddr; int voice; - uint32_t start[32], end[32], cur[32]; - uint32_t startx[32], endx[32], curx[32]; - int rstart[32], rend[32]; + uint32_t start[32]; + uint32_t end[32]; + uint32_t cur[32]; + uint32_t startx[32]; + uint32_t endx[32]; + uint32_t curx[32]; + int rstart[32]; + int rend[32]; int rcur[32]; uint16_t freq[32]; uint16_t rfreq[32]; uint8_t ctrl[32]; uint8_t rctrl[32]; int curvol[32]; - int pan_l[32], pan_r[32]; - int t1on, t2on; + int pan_l[32]; + int pan_r[32]; + int t1on; + int t2on; uint8_t tctrl; - uint16_t t1, t2, t1l, t2l; - uint8_t irqstatus, irqstatus2; + uint16_t t1; + uint16_t t2; + uint16_t t1l; + uint16_t t2l; + uint8_t irqstatus; + uint8_t irqstatus2; uint8_t adcommand; - int waveirqs[32], rampirqs[32]; + int waveirqs[32]; + int rampirqs[32]; int voices; uint8_t dmactrl; - int32_t out_l, out_r; + int32_t out_l; + int32_t out_r; int16_t buffer[2][SOUNDBUFLEN]; int pos; @@ -82,27 +98,41 @@ typedef struct gus_t { int irqnext; - pc_timer_t timer_1, timer_2; + pc_timer_t timer_1; + pc_timer_t timer_2; - int irq, dma, irq_midi; + int irq; + int dma; + int irq_midi; uint16_t base; int latch_enable; - uint8_t sb_2xa, sb_2xc, sb_2xe; + uint8_t sb_2xa; + uint8_t sb_2xc; + uint8_t sb_2xe; uint8_t sb_ctrl; int sb_nmi; uint8_t reg_ctrl; - uint8_t ad_status, ad_data; + uint8_t ad_status; + uint8_t ad_data; uint8_t ad_timer_ctrl; - uint8_t midi_ctrl, midi_status, midi_queue[64], midi_data; - int midi_r, midi_w; - int uart_in, uart_out, sysex; + uint8_t midi_ctrl; + uint8_t midi_status; + uint8_t midi_queue[64]; + uint8_t midi_data; + int midi_r; + int midi_w; + int uart_in; + int uart_out; + int sysex; - uint8_t gp1, gp2; - uint16_t gp1_addr, gp2_addr; + uint8_t gp1; + uint8_t gp2; + uint16_t gp1_addr; + uint16_t gp2_addr; uint8_t usrr; @@ -127,13 +157,12 @@ double vol16bit[4096]; void gus_update_int_status(gus_t *gus) { - int c; int irq_pending = 0; int midi_irq_pending = 0; gus->irqstatus &= ~0x60; gus->irqstatus2 = 0xE0; - for (c = 0; c < 32; c++) { + for (uint8_t c = 0; c < 32; c++) { if (gus->waveirqs[c]) { gus->irqstatus2 = 0x60 | c; if (gus->rampirqs[c]) @@ -199,10 +228,11 @@ gus_midi_update_int_status(gus_t *gus) } void -writegus(uint16_t addr, uint8_t val, void *p) +writegus(uint16_t addr, uint8_t val, void *priv) { - gus_t *gus = (gus_t *) p; - int c, d; + gus_t *gus = (gus_t *) priv; + int c; + int d; int old; uint16_t port; #if defined(DEV_BRANCH) && defined(USE_GUSMAX) @@ -298,6 +328,9 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->tctrl = val; gus_update_int_status(gus); break; + + default: + break; } break; case 0x305: /*Global high*/ @@ -478,6 +511,9 @@ writegus(uint16_t addr, uint8_t val, void *p) case 0x4c: /*Reset*/ gus->reset = val; break; + + default: + break; } break; case 0x307: /*DRAM access*/ @@ -565,6 +601,9 @@ writegus(uint16_t addr, uint8_t val, void *p) break; case 6: break; + + default: + break; } break; @@ -588,7 +627,9 @@ writegus(uint16_t addr, uint8_t val, void *p) else if (gus->irq != -1) picint(1 << gus->irq); } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x20d: gus->sb_2xc = val; break; @@ -618,13 +659,16 @@ writegus(uint16_t addr, uint8_t val, void *p) } #endif break; + + default: + break; } } uint8_t -readgus(uint16_t addr, void *p) +readgus(uint16_t addr, void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; uint8_t val = 0xff; uint16_t port; @@ -716,6 +760,9 @@ readgus(uint16_t addr, void *p) case 0x0f: val = 0xff; break; + + default: + break; } break; case 0x305: /*Global high*/ @@ -776,6 +823,9 @@ readgus(uint16_t addr, void *p) case 0x0f: val = 0xff; break; + + default: + break; } break; case 0x306: @@ -786,7 +836,6 @@ readgus(uint16_t addr, void *p) val = 0xff; /*Pre 3.7 - no mixer*/ break; - break; case 0x307: /*DRAM access*/ val = gus->ram[gus->addr]; gus->addr &= 0xFFFFF; @@ -812,6 +861,9 @@ readgus(uint16_t addr, void *p) case 4: val = gus->gp2_addr; break; + + default: + break; } break; @@ -847,14 +899,17 @@ readgus(uint16_t addr, void *p) case 0x20A: val = gus->adcommand; break; + + default: + break; } return val; } void -gus_poll_timer_1(void *p) +gus_poll_timer_1(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; timer_advance_u64(&gus->timer_1, (uint64_t) (TIMER_USEC * 80)); if (gus->t1on) { @@ -878,9 +933,9 @@ gus_poll_timer_1(void *p) } void -gus_poll_timer_2(void *p) +gus_poll_timer_2(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; timer_advance_u64(&gus->timer_2, (uint64_t) (TIMER_USEC * 320)); if (gus->t2on) { @@ -921,11 +976,10 @@ gus_update(gus_t *gus) } void -gus_poll_wave(void *p) +gus_poll_wave(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; uint32_t addr; - int d; int16_t v; int32_t vl; int update_irqs = 0; @@ -938,7 +992,7 @@ gus_poll_wave(void *p) if ((gus->reset & 3) != 3) return; - for (d = 0; d < 32; d++) { + for (uint8_t d = 0; d < 32; d++) { if (!(gus->ctrl[d] & 3)) { if (gus->ctrl[d] & 4) { addr = gus->cur[d] >> 9; @@ -1055,10 +1109,9 @@ gus_poll_wave(void *p) } static void -gus_get_buffer(int32_t *buffer, int len, void *p) +gus_get_buffer(int32_t *buffer, int len, void *priv) { - gus_t *gus = (gus_t *) p; - int c; + gus_t *gus = (gus_t *) priv; #if defined(DEV_BRANCH) && defined(USE_GUSMAX) if (gus->max_ctrl) @@ -1066,7 +1119,7 @@ gus_get_buffer(int32_t *buffer, int len, void *p) #endif gus_update(gus); - for (c = 0; c < len * 2; c++) { + for (int c = 0; c < len * 2; c++) { #if defined(DEV_BRANCH) && defined(USE_GUSMAX) if (gus->max_ctrl) buffer[c] += (int32_t) (gus->ad1848.buffer[c] / 2); @@ -1085,7 +1138,6 @@ static void gus_input_msg(void *p, uint8_t *msg, uint32_t len) { gus_t *gus = (gus_t *) p; - uint8_t i; if (gus->sysex) return; @@ -1093,7 +1145,7 @@ gus_input_msg(void *p, uint8_t *msg, uint32_t len) if (gus->uart_in) { gus->midi_status |= MIDI_INT_RECEIVE; - for (i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { gus->midi_queue[gus->midi_w++] = msg[i]; gus->midi_w &= 63; } @@ -1106,14 +1158,13 @@ static int gus_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) { gus_t *gus = (gus_t *) p; - uint32_t i; if (abort) { gus->sysex = 0; return 0; } gus->sysex = 1; - for (i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { if (gus->midi_r == gus->midi_w) return (len - i); gus->midi_queue[gus->midi_w++] = buffer[i]; @@ -1124,7 +1175,7 @@ gus_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) } void * -gus_init(const device_t *info) +gus_init(UNUSED(const device_t *info)) { int c; double out = 1.0; @@ -1183,18 +1234,18 @@ gus_init(const device_t *info) } void -gus_close(void *p) +gus_close(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; free(gus->ram); free(gus); } void -gus_speed_changed(void *p) +gus_speed_changed(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; if (gus->voices < 14) gus->samp_latch = (uint64_t) (TIMER_USEC * (1000000.0 / 44100.0)); diff --git a/src/sound/snd_lpt_dac.c b/src/sound/snd_lpt_dac.c index f3e679a55..8fb526f14 100644 --- a/src/sound/snd_lpt_dac.c +++ b/src/sound/snd_lpt_dac.c @@ -11,11 +11,13 @@ #include <86box/machine.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> typedef struct lpt_dac_t { void *lpt; - uint8_t dac_val_l, dac_val_r; + uint8_t dac_val_l; + uint8_t dac_val_r; int is_stereo; int channel; @@ -34,9 +36,9 @@ dac_update(lpt_dac_t *lpt_dac) } static void -dac_write_data(uint8_t val, void *p) +dac_write_data(uint8_t val, void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; if (lpt_dac->is_stereo) { if (lpt_dac->channel) @@ -49,29 +51,28 @@ dac_write_data(uint8_t val, void *p) } static void -dac_write_ctrl(uint8_t val, void *p) +dac_write_ctrl(uint8_t val, void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; if (lpt_dac->is_stereo) lpt_dac->channel = val & 0x01; } static uint8_t -dac_read_status(void *p) +dac_read_status(UNUSED(void *priv)) { return 0x0f; } static void -dac_get_buffer(int32_t *buffer, int len, void *p) +dac_get_buffer(int32_t *buffer, int len, void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; - int c; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; dac_update(lpt_dac); - for (c = 0; c < len; c++) { + for (int c = 0; c < len; c++) { buffer[c * 2] += dac_iir(0, lpt_dac->buffer[0][c]); buffer[c * 2 + 1] += dac_iir(1, lpt_dac->buffer[1][c]); } @@ -101,9 +102,9 @@ dac_stereo_init(void *lpt) return lpt_dac; } static void -dac_close(void *p) +dac_close(void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; free(lpt_dac); } diff --git a/src/sound/snd_lpt_dss.c b/src/sound/snd_lpt_dss.c index 7990a2a23..bd794fffb 100644 --- a/src/sound/snd_lpt_dss.c +++ b/src/sound/snd_lpt_dss.c @@ -11,15 +11,17 @@ #include <86box/machine.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> typedef struct dss_t { void *lpt; uint8_t fifo[16]; - int read_idx, write_idx; + int read_idx; + int write_idx; - uint8_t dac_val, - status; + uint8_t dac_val; + uint8_t status; pc_timer_t timer; @@ -49,9 +51,9 @@ dss_update_status(dss_t *dss) } static void -dss_write_data(uint8_t val, void *p) +dss_write_data(uint8_t val, void *priv) { - dss_t *dss = (dss_t *) p; + dss_t *dss = (dss_t *) priv; if ((dss->write_idx - dss->read_idx) < 16) { dss->fifo[dss->write_idx & 15] = val; @@ -61,31 +63,31 @@ dss_write_data(uint8_t val, void *p) } static void -dss_write_ctrl(uint8_t val, void *p) +dss_write_ctrl(UNUSED(uint8_t val), UNUSED(void *priv)) { + // } static uint8_t -dss_read_status(void *p) +dss_read_status(void *priv) { - dss_t *dss = (dss_t *) p; + const dss_t *dss = (dss_t *) priv; return dss->status | 0x0f; } static void -dss_get_buffer(int32_t *buffer, int len, void *p) +dss_get_buffer(int32_t *buffer, int len, void *priv) { - dss_t *dss = (dss_t *) p; - int c; + dss_t *dss = (dss_t *) priv; int16_t val; float fval; dss_update(dss); - for (c = 0; c < len * 2; c += 2) { + for (int c = 0; c < len * 2; c += 2) { fval = dss_iir((float) dss->buffer[c >> 1]); - val = (float) fval; + val = fval; buffer[c] += val; buffer[c + 1] += val; @@ -95,9 +97,9 @@ dss_get_buffer(int32_t *buffer, int len, void *p) } static void -dss_callback(void *p) +dss_callback(void *priv) { - dss_t *dss = (dss_t *) p; + dss_t *dss = (dss_t *) priv; dss_update(dss); @@ -124,9 +126,9 @@ dss_init(void *lpt) return dss; } static void -dss_close(void *p) +dss_close(void *priv) { - dss_t *dss = (dss_t *) p; + dss_t *dss = (dss_t *) priv; free(dss); } diff --git a/src/sound/snd_mpu401.c b/src/sound/snd_mpu401.c index 328c3c688..d9e51df29 100644 --- a/src/sound/snd_mpu401.c +++ b/src/sound/snd_mpu401.c @@ -38,6 +38,7 @@ #include <86box/timer.h> #include <86box/snd_mpu401.h> #include <86box/sound.h> +#include <86box/plat_unused.h> static uint32_t MPUClockBase[8] = { 48, 72, 96, 120, 144, 168, 192 }; static uint8_t cth_data[16] = { 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 }; @@ -52,7 +53,7 @@ int mpu401_standalone_enable = 0; static void MPU401_WriteCommand(mpu_t *mpu, uint8_t val); static void MPU401_IntelligentOut(mpu_t *mpu, uint8_t track); static void MPU401_EOIHandler(void *priv); -static void MPU401_EOIHandlerDispatch(void *p); +static void MPU401_EOIHandlerDispatch(void *priv); static void MPU401_NotesOff(mpu_t *mpu, int i); #ifdef ENABLE_MPU401_LOG @@ -76,7 +77,8 @@ mpu401_log(const char *fmt, ...) static void MPU401_ReCalcClock(mpu_t *mpu) { - int32_t maxtempo = 240, mintempo = 16; + int32_t mintempo = 16; + int32_t maxtempo = 240; int32_t freq; if (mpu->clock.timebase < 72) { @@ -136,7 +138,7 @@ MPU401_RunClock(mpu_t *mpu) } static void -MPU401_QueueByteEx(mpu_t *mpu, uint8_t data, int irq) +MPU401_QueueByteEx(mpu_t *mpu, uint8_t data, UNUSED(int irq)) { if (mpu->state.block_ack) { mpu->state.block_ack = 0; @@ -185,7 +187,7 @@ MPU401_IRQPending(mpu_t *mpu) } static void -MPU401_RecQueueBuffer(mpu_t *mpu, uint8_t *buf, uint32_t len, int block) +MPU401_RecQueueBuffer(mpu_t *mpu, uint8_t *buf, uint32_t len, UNUSED(int block)) { uint32_t cnt = 0; int pos; @@ -360,7 +362,10 @@ MPU401_ResetDone(void *priv) static void MPU401_WriteCommand(mpu_t *mpu, uint8_t val) { - uint8_t i, j, was_uart, recmsg[3]; + uint8_t i; + uint8_t j; + uint8_t was_uart; + uint8_t recmsg[3]; if (mpu->state.reset) mpu->state.cmd_pending = val + 1; @@ -401,6 +406,9 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) mpu->clock.measure_counter = mpu->clock.meas_old; mpu->clock.cth_counter = mpu->clock.cth_old; break; + + default: + break; } switch (val & 0xc) { /* Playing */ case 0x4: /* Stop */ @@ -414,6 +422,9 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) mpu->state.playing = 1; MPU401_StartClock(mpu); break; + + default: + break; } switch (val & 0x30) { /* Recording */ case 0: /* check if it waited for MIDI RT command */ @@ -446,6 +457,9 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) MPU401_StartClock(mpu); } break; + + default: + break; } } MPU401_QueueByte(mpu, MSG_MPU_ACK); @@ -675,8 +689,11 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) return; break; - /* default: - mpu401_log("MPU-401:Unhandled command %X",val); */ + default: +#if 0 + mpu401_log("MPU-401:Unhandled command %X",val); +#endif + break; } MPU401_QueueByte(mpu, MSG_MPU_ACK); @@ -685,8 +702,8 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) static void MPU401_WriteData(mpu_t *mpu, uint8_t val) { - static int length, cnt; - uint8_t i; + static int length; + static int cnt; #ifdef DOSBOX_CODE if (mpu->mode == M_UART) { @@ -740,7 +757,7 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) mpu->state.command_byte = 0; if (!val) val = 64; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) mpu->clock.cth_rate[i] = (val >> 2) + cth_data[(val & 3) * 4 + i]; mpu->clock.cth_mode = 0; return; @@ -789,7 +806,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) break; case 0xf0: - /* mpu401_log("MPU-401:Illegal WSD byte\n"); */ +#if 0 + mpu401_log("MPU-401:Illegal WSD byte\n"); +#endif mpu->state.wsd = 0; mpu->state.track = mpu->state.old_track; return; @@ -896,6 +915,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) mpu->state.data_onoff = -1; mpu->state.cond_req = 0; break; + + default: + break; } return; } @@ -940,7 +962,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) if (val == 0xf9) mpu->clock.measure_counter = 0; } else { - /* mpu401_log("MPU-401:Illegal message"); */ +#if 0 + mpu401_log("MPU-401:Illegal message"); +#endif mpu->playbuf[mpu->state.track].type = T_OVERFLOW; } mpu->state.data_onoff = -1; @@ -965,6 +989,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) MPU401_EOIHandler(mpu); } break; + + default: + break; } return; @@ -973,9 +1000,12 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) static void MPU401_IntelligentOut(mpu_t *mpu, uint8_t track) { - uint8_t chan, chrefnum, key, msg; - int send, retrigger; - uint8_t i; + uint8_t chan; + uint8_t chrefnum; + uint8_t key; + uint8_t msg; + int send; + int retrigger; switch (mpu->playbuf[track].type) { case T_OVERFLOW: @@ -1015,6 +1045,9 @@ MPU401_IntelligentOut(mpu_t *mpu, uint8_t track) return; } break; + + default: + break; } if (retrigger) { midi_raw_out_byte(0x80 | chan); @@ -1022,7 +1055,7 @@ MPU401_IntelligentOut(mpu_t *mpu, uint8_t track) midi_raw_out_byte(0); } if (send) { - for (i = 0; i < mpu->playbuf[track].length; i++) + for (uint8_t i = 0; i < mpu->playbuf[track].length; i++) midi_raw_out_byte(mpu->playbuf[track].value[i]); } break; @@ -1123,7 +1156,7 @@ MPU401_EOIHandlerDispatch(void *priv) } static void -imf_write(uint16_t addr, uint8_t val, void *priv) +imf_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), UNUSED(void *priv)) { mpu401_log("IMF:Wr %4X,%X\n", addr, val); } @@ -1238,6 +1271,9 @@ mpu401_write(uint16_t addr, uint8_t val, void *priv) MPU401_WriteCommand(mpu, val); mpu401_log("Write Command (0x331) %x\n", val); break; + + default: + break; } } @@ -1262,17 +1298,19 @@ mpu401_read(uint16_t addr, void *priv) mpu401_log("Read Status (0x331) %x\n", ret); break; + + default: + break; } /* mpu401_log("MPU401 Read Port %04X, ret %x\n", addr, ret); */ - return (ret); + return ret; } static void MPU401_Event(void *priv) { mpu_t *mpu = (mpu_t *) priv; - uint8_t i; int max_meascnt; mpu401_log("MPU-401 event callback\n"); @@ -1293,7 +1331,7 @@ MPU401_Event(void *priv) goto next_event; if (mpu->state.playing) { - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { /* Decrease counters. */ if (mpu->state.amask & (1 << i)) { mpu->playbuf[i].counter--; @@ -1356,17 +1394,14 @@ next_event: static void MPU401_NotesOff(mpu_t *mpu, int i) { - int j; - uint8_t key; - if (mpu->filter.allnotesoff_out && !(mpu->inputref[i].on && (mpu->inputref[i].key[0] | mpu->inputref[i].key[1] | mpu->inputref[i].key[2] | mpu->inputref[i].key[3]))) { - for (j = 0; j < 4; j++) + for (uint8_t j = 0; j < 4; j++) mpu->chanref[mpu->ch_toref[i]].key[j] = 0; midi_raw_out_byte(0xb0 | i); midi_raw_out_byte(123); midi_raw_out_byte(0); } else if (mpu->chanref[mpu->ch_toref[i]].on) { - for (key = 0; key < 128; key++) { + for (uint8_t key = 0; key < 128; key++) { if ((mpu->chanref[mpu->ch_toref[i]].M_GETKEY) && !(mpu->inputref[i].on && (mpu->inputref[i].M_GETKEY))) { midi_raw_out_byte(0x80 | i); midi_raw_out_byte(key); @@ -1437,12 +1472,17 @@ void MPU401_InputMsg(void *p, uint8_t *msg, uint32_t len) { mpu_t *mpu = (mpu_t *) p; - int i, tick; + int i; + int tick; static uint8_t old_msg = 0; uint8_t key; - uint8_t recdata[2], recmsg[4]; - int send = 1, send_thru = 0; - int retrigger_thru = 0, chan, chrefnum; + uint8_t recdata[2]; + uint8_t recmsg[4]; + int send = 1; + int send_thru = 0; + int retrigger_thru = 0; + int chan; + int chrefnum; /* Abort if sysex transfer is in progress. */ if (!mpu->state.sysex_in_finished) { @@ -1512,8 +1552,11 @@ MPU401_InputMsg(void *p, uint8_t *msg, uint32_t len) } } } - break; } + break; + + default: + break; } } if ((msg[0] >= 0xf0) || (mpu->state.midi_mask & (1 << chan))) { @@ -1609,9 +1652,16 @@ MPU401_InputMsg(void *p, uint8_t *msg, uint32_t len) if (mpu->filter.rt_out) midi_raw_out_rt_byte(msg[0]); break; + + default: + break; } return; } + break; + + default: + break; } } if (send_thru && mpu->midi_thru) { @@ -1720,17 +1770,17 @@ mpu401_device_add(void) } static uint8_t -mpu401_mca_read(int port, void *p) +mpu401_mca_read(int port, void *priv) { - mpu_t *mpu = (mpu_t *) p; + const mpu_t *mpu = (mpu_t *) priv; return mpu->pos_regs[port & 7]; } static void -mpu401_mca_write(int port, uint8_t val, void *p) +mpu401_mca_write(int port, uint8_t val, void *priv) { - mpu_t *mpu = (mpu_t *) p; + mpu_t *mpu = (mpu_t *) priv; uint16_t addr; if (port < 0x102) @@ -1754,7 +1804,7 @@ mpu401_mca_write(int port, uint8_t val, void *p) } static uint8_t -mpu401_mca_feedb(void *p) +mpu401_mca_feedb(UNUSED(void *priv)) { return 1; } @@ -1794,7 +1844,7 @@ mpu401_standalone_init(const device_t *info) mpu401_init(mpu, base, irq, M_INTELLIGENT, device_get_config_int("receive_input")); - return (mpu); + return mpu; } static void diff --git a/src/sound/snd_opl_nuked.c b/src/sound/snd_opl_nuked.c index c4d15c1c0..e4131f1fe 100644 --- a/src/sound/snd_opl_nuked.c +++ b/src/sound/snd_opl_nuked.c @@ -125,9 +125,9 @@ typedef struct chan { uint8_t con; uint8_t alg; uint8_t ksv; - uint16_t cha, - chb; - uint8_t ch_num; + uint16_t cha; + uint16_t chb; + uint8_t ch_num; } chan_t; typedef struct wrbuf { @@ -177,12 +177,14 @@ typedef struct chip { typedef struct { nuked_t opl; - int8_t flags, pad; + int8_t flags; + int8_t pad; uint16_t port; - uint8_t status, timer_ctrl; - uint16_t timer_count[2], - timer_cur_count[2]; + uint8_t status; + uint8_t timer_ctrl; + uint16_t timer_count[2]; + uint16_t timer_cur_count[2]; pc_timer_t timers[2]; @@ -514,7 +516,8 @@ env_calc(slot_t *slot) uint8_t rate_lo; uint8_t reg_rate = 0; uint8_t ks; - uint8_t eg_shift, shift; + uint8_t eg_shift; + uint8_t shift; uint16_t eg_rout; int16_t eg_inc; uint8_t eg_off; @@ -542,6 +545,9 @@ env_calc(slot_t *slot) case envelope_gen_num_release: reg_rate = slot->reg_rr; break; + + default: + break; } slot->pg_reset = reset; @@ -618,6 +624,9 @@ env_calc(slot_t *slot) if (!eg_off && !reset && shift > 0) eg_inc = 1 << (shift - 1); break; + + default: + break; } slot->eg_rout = (eg_rout + eg_inc) & 0x1ff; @@ -646,7 +655,8 @@ phase_generate(slot_t *slot) { uint16_t f_num; uint32_t basefreq; - uint8_t rm_xor, n_bit; + uint8_t rm_xor; + uint8_t n_bit; uint32_t noise; uint16_t phase; int8_t range; @@ -808,6 +818,9 @@ channel_setup_alg(chan_t *ch) ch->slots[0]->mod = &ch->slots[0]->fbmod; ch->slots[1]->mod = &ch->dev->zeromod; break; + + default: + break; } return; } @@ -865,6 +878,9 @@ channel_setup_alg(chan_t *ch) ch->out[2] = &ch->slots[1]->out; ch->out[3] = &ch->dev->zeromod; break; + + default: + break; } } else switch (ch->alg & 0x01) { @@ -885,13 +901,18 @@ channel_setup_alg(chan_t *ch) ch->out[2] = &ch->dev->zeromod; ch->out[3] = &ch->dev->zeromod; break; + + default: + break; } } static void channel_update_rhythm(nuked_t *dev, uint8_t data) { - chan_t *ch6, *ch7, *ch8; + chan_t *ch6; + chan_t *ch7; + chan_t *ch8; uint8_t chnum; dev->rhy = data & 0x3f; @@ -1076,9 +1097,8 @@ static void channel_set_4op(nuked_t *dev, uint8_t data) { uint8_t chnum; - uint8_t bit; - for (bit = 0; bit < 6; bit++) { + for (uint8_t bit = 0; bit < 6; bit++) { chnum = bit; if (bit >= 3) @@ -1097,14 +1117,14 @@ channel_set_4op(nuked_t *dev, uint8_t data) uint16_t nuked_write_addr(void *priv, uint16_t port, uint8_t val) { - nuked_t *dev = (nuked_t *) priv; + const nuked_t *dev = (nuked_t *) priv; uint16_t addr; addr = val; if ((port & 0x0002) && ((addr == 0x0005) || dev->newm)) addr |= 0x0100; - return (addr); + return addr; } void @@ -1125,12 +1145,18 @@ nuked_write_reg(void *priv, uint16_t reg, uint8_t val) case 0x05: dev->newm = val & 0x01; break; + + default: + break; } else switch (regm & 0x0f) { case 0x08: dev->nts = (val >> 6) & 0x01; break; + + default: + break; } break; @@ -1188,6 +1214,9 @@ nuked_write_reg(void *priv, uint16_t reg, uint8_t val) if (ad_slot[regm & 0x1f] >= 0) slot_write_e0(&dev->slot[18 * high + ad_slot[regm & 0x1f]], val); break; + + default: + break; } } @@ -1195,7 +1224,8 @@ void nuked_write_reg_buffered(void *priv, uint16_t reg, uint8_t val) { nuked_t *dev = (nuked_t *) priv; - uint64_t time1, time2; + uint64_t time1; + uint64_t time2; if (dev->wrbuf[dev->wrbuf_last].reg & 0x0200) { nuked_write_reg(dev, dev->wrbuf[dev->wrbuf_last].reg & 0x01ff, @@ -1222,8 +1252,10 @@ void nuked_generate(void *priv, int32_t *bufp) { nuked_t *dev = (nuked_t *) priv; - int16_t accm, shift = 0; - uint8_t i, j; + int16_t accm; + int16_t shift = 0; + uint8_t i; + uint8_t j; bufp[1] = dev->mixbuff[1]; @@ -1352,9 +1384,7 @@ nuked_generate_resampled(nuked_t *dev, int32_t *bufp) void nuked_generate_stream(nuked_t *dev, int32_t *sndptr, uint32_t num) { - uint32_t i; - - for (i = 0; i < num; i++) { + for (uint32_t i = 0; i < num; i++) { nuked_generate_resampled(dev, sndptr); sndptr += 2; } @@ -1572,6 +1602,9 @@ nuked_drv_write(uint16_t port, uint8_t val, void *priv) nuked_log("Status mask now %02X (val = %02X)\n", (val & ~CTRL_TMR_MASK) & CTRL_TMR_MASK, val); } break; + + default: + break; } } else { dev->port = nuked_write_addr(&dev->opl, port, val) & 0x01ff; diff --git a/src/sound/snd_opl_ymfm.cpp b/src/sound/snd_opl_ymfm.cpp index 6788a8ab4..642c6dceb 100644 --- a/src/sound/snd_opl_ymfm.cpp +++ b/src/sound/snd_opl_ymfm.cpp @@ -29,6 +29,7 @@ extern "C" { #include <86box/snd_opl.h> #include <86box/mem.h> #include <86box/rom.h> +#include <86box/plat_unused.h> // Disable c99-designator to avoid the warnings in *_ymfm_device #ifdef __clang__ @@ -50,7 +51,7 @@ enum { class YMFMChipBase { public: - YMFMChipBase(uint32_t clock, fm_type type, uint32_t samplerate) + YMFMChipBase(uint32_t clock, fm_type type, UNUSED(uint32_t samplerate)) : m_buf_pos(0) , m_flags(0) , m_type(type) @@ -240,7 +241,8 @@ public: private: ChipType m_chip; uint32_t m_clock; - double m_clock_us, m_subtract[2]; + double m_clock_us; + double m_subtract[2]; typename ChipType::output_data m_output; pc_timer_t m_timers[2]; int32_t m_duration_in_clocks[2]; // Needed for clock switches. @@ -294,8 +296,8 @@ ymfm_drv_init(const device_t *info) YMFMChipBase *fm; switch (info->local) { - case FM_YM3812: default: + case FM_YM3812: fm = (YMFMChipBase *) new YMFMChip(3579545, FM_YM3812, OPL_FREQ); break; @@ -323,7 +325,7 @@ ymfm_drv_close(void *priv) YMFMChipBase *drv = (YMFMChipBase *) priv; if (drv != NULL) - delete (drv); + delete drv; } static uint8_t diff --git a/src/sound/snd_optimc.c b/src/sound/snd_optimc.c index 5f0de7673..d7afca382 100644 --- a/src/sound/snd_optimc.c +++ b/src/sound/snd_optimc.c @@ -38,6 +38,7 @@ #include <86box/snd_sb.h> #include <86box/mem.h> #include <86box/rom.h> +#include <86box/plat_unused.h> static int optimc_wss_dma[4] = { 0, 0, 1, 3 }; static int optimc_wss_irq[8] = { 5, 7, 9, 10, 11, 12, 14, 15 }; @@ -48,14 +49,21 @@ enum optimc_local_flags { }; typedef struct optimc_t { - uint8_t type, fm_type; + uint8_t type; + uint8_t fm_type; - uint8_t wss_config, reg_enabled; + uint8_t wss_config; + uint8_t reg_enabled; - uint16_t cur_addr, cur_wss_addr, cur_mpu401_addr; + uint16_t cur_addr; + uint16_t cur_wss_addr; + uint16_t cur_mpu401_addr; - int cur_irq, cur_dma; - int cur_wss_enabled, cur_wss_irq, cur_wss_dma; + int cur_irq; + int cur_dma; + int cur_wss_enabled; + int cur_wss_irq; + int cur_wss_dma; int cur_mpu401_irq; int cur_mpu401_enabled; void *gameport; @@ -82,9 +90,9 @@ optimc_filter_opl(void *priv, double *out_l, double *out_r) } static uint8_t -optimc_wss_read(uint16_t addr, void *priv) +optimc_wss_read(UNUSED(uint16_t addr), void *priv) { - optimc_t *optimc = (optimc_t *) priv; + const optimc_t *optimc = (optimc_t *) priv; if (!(optimc->regs[4] & 0x10) && optimc->cur_mode == 0) return 0xFF; @@ -93,7 +101,7 @@ optimc_wss_read(uint16_t addr, void *priv) } static void -optimc_wss_write(uint16_t addr, uint8_t val, void *priv) +optimc_wss_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { optimc_t *optimc = (optimc_t *) priv; @@ -105,17 +113,16 @@ optimc_wss_write(uint16_t addr, uint8_t val, void *priv) } static void -optimc_get_buffer(int32_t *buffer, int len, void *p) +optimc_get_buffer(int32_t *buffer, int len, void *priv) { - optimc_t *optimc = (optimc_t *) p; - int c; + optimc_t *optimc = (optimc_t *) priv; if (optimc->regs[3] & 0x4) return; /* wss part */ ad1848_update(&optimc->ad1848); - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += (optimc->ad1848.buffer[c] / 2); optimc->ad1848.pos = 0; @@ -142,9 +149,9 @@ optimc_add_opl(optimc_t *optimc) } static void -optimc_reg_write(uint16_t addr, uint8_t val, void *p) +optimc_reg_write(uint16_t addr, uint8_t val, void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; uint16_t idx = addr - 0xF8D; uint8_t old = optimc->regs[idx]; static uint8_t reg_enable_phase = 0; @@ -177,6 +184,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) case 3: /* WSBase = 0x604 */ optimc->cur_wss_addr = 0x604; break; + + default: + break; } io_sethandler(optimc->cur_wss_addr, 0x0004, optimc_wss_read, NULL, NULL, optimc_wss_write, NULL, NULL, optimc); io_sethandler(optimc->cur_wss_addr + 0x0004, 0x0004, ad1848_read, NULL, NULL, ad1848_write, NULL, NULL, &optimc->ad1848); @@ -248,6 +258,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) case 3: optimc->cur_mpu401_irq = 7; break; + + default: + break; } switch ((val >> 5) & 0x3) { case 0: @@ -262,11 +275,17 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) case 3: optimc->cur_mpu401_addr = 0x300; break; + + default: + break; } mpu401_change_addr(optimc->mpu, optimc->cur_mpu401_addr); mpu401_setirq(optimc->mpu, optimc->cur_mpu401_irq); } break; + + default: + break; } } if (optimc->reg_enabled) @@ -292,6 +311,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) reg_enable_phase = 1; } break; + + default: + break; } } else reg_enable_phase = 1; @@ -300,9 +322,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) } static uint8_t -optimc_reg_read(uint16_t addr, void *p) +optimc_reg_read(uint16_t addr, void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; uint8_t temp = 0xFF; if (optimc->reg_enabled) { @@ -317,6 +339,9 @@ optimc_reg_read(uint16_t addr, void *p) case 2: /* MC3 */ temp = (optimc->regs[2] & ~0x3) | 0x2; break; + + default: + break; } optimc->reg_enabled = 0; } @@ -399,19 +424,19 @@ optimc_init(const device_t *info) } static void -optimc_close(void *p) +optimc_close(void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; sb_close(optimc->sb); free(optimc->mpu); - free(p); + free(priv); } static void -optimc_speed_changed(void *p) +optimc_speed_changed(void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; ad1848_speed_changed(&optimc->ad1848); sb_speed_changed(optimc->sb); diff --git a/src/sound/snd_pas16.c b/src/sound/snd_pas16.c index 856b29e93..674acfcbb 100644 --- a/src/sound/snd_pas16.c +++ b/src/sound/snd_pas16.c @@ -20,6 +20,7 @@ #include <86box/snd_opl.h> #include <86box/snd_sb.h> #include <86box/snd_sb_dsp.h> +#include <86box/plat_unused.h> /* Original PAS uses 2 x OPL2 @@ -97,39 +98,51 @@ typedef struct pas16_t { uint16_t base; - int irq, dma; + int irq; + int dma; uint8_t audiofilt; uint8_t audio_mixer; - uint8_t compat, compat_base; + uint8_t compat; + uint8_t compat_base; uint8_t enhancedscsi; - uint8_t io_conf_1, io_conf_2, io_conf_3, io_conf_4; + uint8_t io_conf_1; + uint8_t io_conf_2; + uint8_t io_conf_3; + uint8_t io_conf_4; - uint8_t irq_stat, irq_ena; + uint8_t irq_stat; + uint8_t irq_ena; uint8_t pcm_ctrl; uint16_t pcm_dat; - uint16_t pcm_dat_l, pcm_dat_r; + uint16_t pcm_dat_l; + uint16_t pcm_dat_r; uint8_t sb_irqdma; int stereo_lr; - uint8_t sys_conf_1, sys_conf_2, sys_conf_3, sys_conf_4; + uint8_t sys_conf_1; + uint8_t sys_conf_2; + uint8_t sys_conf_3; + uint8_t sys_conf_4; - struct - { + struct { uint32_t l[3]; int64_t c[3]; pc_timer_t timer[3]; uint8_t m[3]; - uint8_t ctrl, ctrls[2]; - int wp, rm[3], wm[3]; + uint8_t ctrl; + uint8_t ctrls[2]; + int wp; + int rm[3]; + int wm[3]; uint16_t rl[3]; int thit[3]; int delay[3]; @@ -192,9 +205,9 @@ pas16_log(const char *fmt, ...) #endif static uint8_t -pas16_in(uint16_t port, void *p) +pas16_in(uint16_t port, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; uint8_t temp = 0xff; switch ((port - pas16->base) + 0x388) { case 0x388: @@ -286,15 +299,18 @@ pas16_in(uint16_t port, void *p) case 0xff8b: /*Master mode read*/ temp = 0x20 | 0x10 | 0x01; /*AT bus, XT/AT timing*/ break; + + default: + break; } pas16_log("pas16_in : port %04X return %02X %04X:%04X\n", port, temp, CS, cpu_state.pc); return temp; } static void -pas16_out(uint16_t port, uint8_t val, void *p) +pas16_out(uint16_t port, uint8_t val, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; pas16_log("pas16_out : port %04X val %02X %04X:%04X\n", port, val, CS, cpu_state.pc); switch ((port - pas16->base) + 0x388) { case 0x388: @@ -409,9 +425,9 @@ pas16_out(uint16_t port, uint8_t val, void *p) } static void -pas16_pit_out(uint16_t port, uint8_t val, void *p) +pas16_pit_out(uint16_t port, uint8_t val, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; int t; switch (port & 3) { case 3: /*CTRL*/ @@ -419,7 +435,6 @@ pas16_pit_out(uint16_t port, uint8_t val, void *p) if (!(val & 0x20)) { if (val & 2) pas16->pit.rl[0] = timer_get_remaining_u64(&pas16->pit.timer[0]) / PITCONST; - ; if (val & 4) pas16->pit.rl[1] = pas16->pit.c[1]; if (val & 8) @@ -497,6 +512,9 @@ pas16_pit_out(uint16_t port, uint8_t val, void *p) pas16->pit.l[t] |= val; pas16->pit.wm[t] = 0; break; + + default: + break; } if (!pas16->pit.l[t]) { pas16->pit.l[t] |= 0x10000; @@ -505,13 +523,16 @@ pas16_pit_out(uint16_t port, uint8_t val, void *p) timer_set_delay_u64(&pas16->pit.timer[t], pas16->pit.c[t] * PITCONST); } break; + + default: + break; } } static uint8_t -pas16_pit_in(uint16_t port, void *p) +pas16_pit_in(uint16_t port, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; uint8_t temp = 0xff; int t = port & 3; switch (port & 3) { @@ -551,11 +572,17 @@ pas16_pit_in(uint16_t port, void *p) else pas16->pit.rm[t] = 0; break; + + default: + break; } break; case 3: /*Control*/ temp = pas16->pit.ctrl; break; + + default: + break; } return temp; } @@ -567,9 +594,9 @@ pas16_readdma(pas16_t *pas16) } static void -pas16_pcm_poll(void *p) +pas16_pcm_poll(void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; pas16_update(pas16); if (pas16->pit.m[0] & 2) { @@ -634,9 +661,9 @@ pas16_pcm_poll(void *p) } static void -pas16_out_base(uint16_t port, uint8_t val, void *p) +pas16_out_base(UNUSED(uint16_t port), uint8_t val, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; io_removehandler((pas16->base - 0x388) + 0x0388, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); io_removehandler((pas16->base - 0x388) + 0x0788, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); @@ -697,15 +724,14 @@ pas16_update(pas16_t *pas16) } void -pas16_get_buffer(int32_t *buffer, int len, void *p) +pas16_get_buffer(int32_t *buffer, int len, void *priv) { - pas16_t *pas16 = (pas16_t *) p; - int c; + pas16_t *pas16 = (pas16_t *) priv; - int32_t *opl_buf = pas16->opl.update(pas16->opl.priv); + const int32_t *opl_buf = pas16->opl.update(pas16->opl.priv); sb_dsp_update(&pas16->dsp); pas16_update(pas16); - for (c = 0; c < len * 2; c++) { + for (int c = 0; c < len * 2; c++) { buffer[c] += opl_buf[c]; buffer[c] += (int16_t) (sb_iir(0, c & 1, (double) pas16->dsp.buffer[c]) / 1.3) / 2; buffer[c] += (pas16->pcm_buffer[c & 1][c >> 1] / 2); @@ -717,7 +743,7 @@ pas16_get_buffer(int32_t *buffer, int len, void *p) } static void * -pas16_init(const device_t *info) +pas16_init(UNUSED(const device_t *info)) { pas16_t *pas16 = malloc(sizeof(pas16_t)); memset(pas16, 0, sizeof(pas16_t)); @@ -735,9 +761,9 @@ pas16_init(const device_t *info) } static void -pas16_close(void *p) +pas16_close(void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; free(pas16); } diff --git a/src/sound/snd_ps1.c b/src/sound/snd_ps1.c index 471874d4d..60b4515f8 100644 --- a/src/sound/snd_ps1.c +++ b/src/sound/snd_ps1.c @@ -13,15 +13,18 @@ #include <86box/sound.h> #include <86box/snd_sn76489.h> #include <86box/timer.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct ps1snd_t { sn76489_t sn76489; - uint8_t status, ctrl; + uint8_t status; + uint8_t ctrl; uint64_t timer_latch; pc_timer_t timer_count; int timer_enable; uint8_t fifo[2048]; - int fifo_read_idx, fifo_write_idx; + int fifo_read_idx; + int fifo_write_idx; int fifo_threshold; uint8_t dac_val; int16_t buffer[SOUNDBUFLEN]; @@ -73,9 +76,13 @@ ps1snd_read(uint16_t port, void *priv) case 6: case 7: ret = 0; + break; + + default: + break; } - return (ret); + return ret; } static void @@ -109,6 +116,9 @@ ps1snd_write(uint16_t port, uint8_t val, void *priv) case 4: /* almost empty */ ps1snd->fifo_threshold = val * 4; break; + + default: + break; } } @@ -144,18 +154,17 @@ static void ps1snd_get_buffer(int32_t *buffer, int len, void *priv) { ps1snd_t *ps1snd = (ps1snd_t *) priv; - int c; ps1snd_update(ps1snd); - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += ps1snd->buffer[c >> 1]; ps1snd->pos = 0; } static void * -ps1snd_init(const device_t *info) +ps1snd_init(UNUSED(const device_t *info)) { ps1snd_t *ps1snd = malloc(sizeof(ps1snd_t)); memset(ps1snd, 0x00, sizeof(ps1snd_t)); @@ -175,7 +184,7 @@ ps1snd_init(const device_t *info) sound_add_handler(ps1snd_get_buffer, ps1snd); - return (ps1snd); + return ps1snd; } static void diff --git a/src/sound/snd_pssj.c b/src/sound/snd_pssj.c index 8b493e030..1e6f48ae3 100644 --- a/src/sound/snd_pssj.c +++ b/src/sound/snd_pssj.c @@ -12,6 +12,7 @@ #include <86box/sound.h> #include <86box/snd_sn76489.h> #include <86box/timer.h> +#include <86box/plat_unused.h> typedef struct pssj_t { sn76489_t sn76489; @@ -41,9 +42,9 @@ pssj_update_irq(pssj_t *pssj) } static void -pssj_write(uint16_t port, uint8_t val, void *p) +pssj_write(uint16_t port, uint8_t val, void *priv) { - pssj_t *pssj = (pssj_t *) p; + pssj_t *pssj = (pssj_t *) priv; switch (port & 3) { case 0: @@ -67,6 +68,9 @@ pssj_write(uint16_t port, uint8_t val, void *p) case 3: /*Direct DAC*/ pssj->dac_val = val; break; + + default: + break; } break; case 2: @@ -76,12 +80,15 @@ pssj_write(uint16_t port, uint8_t val, void *p) pssj->freq = (pssj->freq & 0x0ff) | ((val & 0xf) << 8); pssj->amplitude = val >> 4; break; + + default: + break; } } static uint8_t -pssj_read(uint16_t port, void *p) +pssj_read(uint16_t port, void *priv) { - pssj_t *pssj = (pssj_t *) p; + const pssj_t *pssj = (pssj_t *) priv; switch (port & 3) { case 0: @@ -96,6 +103,9 @@ pssj_read(uint16_t port, void *p) return 0x80; case 3: /*Direct DAC*/ return pssj->dac_val; + + default: + break; } break; case 2: @@ -117,9 +127,9 @@ pssj_update(pssj_t *pssj) } static void -pssj_callback(void *p) +pssj_callback(void *priv) { - pssj_t *pssj = (pssj_t *) p; + pssj_t *pssj = (pssj_t *) priv; int data; pssj_update(pssj); @@ -157,6 +167,9 @@ pssj_callback(void *p) case 0xc0: pssj->dac_val = 0x80; break; + + default: + break; } pssj->wave_pos = (pssj->wave_pos + 1) & 31; } @@ -165,21 +178,20 @@ pssj_callback(void *p) } static void -pssj_get_buffer(int32_t *buffer, int len, void *p) +pssj_get_buffer(int32_t *buffer, int len, void *priv) { - pssj_t *pssj = (pssj_t *) p; - int c; + pssj_t *pssj = (pssj_t *) priv; pssj_update(pssj); - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += pssj->buffer[c >> 1]; pssj->pos = 0; } void * -pssj_init(const device_t *info) +pssj_init(UNUSED(const device_t *info)) { pssj_t *pssj = malloc(sizeof(pssj_t)); memset(pssj, 0, sizeof(pssj_t)); @@ -194,7 +206,7 @@ pssj_init(const device_t *info) } void * -pssj_1e0_init(const device_t *info) +pssj_1e0_init(UNUSED(const device_t *info)) { pssj_t *pssj = malloc(sizeof(pssj_t)); memset(pssj, 0, sizeof(pssj_t)); @@ -209,7 +221,7 @@ pssj_1e0_init(const device_t *info) } void * -pssj_isa_init(const device_t *info) +pssj_isa_init(UNUSED(const device_t *info)) { pssj_t *pssj = malloc(sizeof(pssj_t)); memset(pssj, 0, sizeof(pssj_t)); @@ -226,9 +238,9 @@ pssj_isa_init(const device_t *info) } void -pssj_close(void *p) +pssj_close(void *priv) { - pssj_t *pssj = (pssj_t *) p; + pssj_t *pssj = (pssj_t *) priv; free(pssj); } diff --git a/src/sound/snd_resid.cc b/src/sound/snd_resid.cc index da46b7634..94bbcd591 100644 --- a/src/sound/snd_resid.cc +++ b/src/sound/snd_resid.cc @@ -20,13 +20,16 @@ psid_t *psid; void * sid_init(void) { - // psid_t *psid; - int c; +#if 0 + psid_t *psid; +#endif sampling_method method = SAMPLE_INTERPOLATE; float cycles_per_sec = 14318180.0 / 16.0; psid = new psid_t; - // psid = (psid_t *)malloc(sizeof(sound_t)); +#if 0 + psid = (psid_t *)malloc(sizeof(sound_t)); +#endif psid->sid = new SIDFP; psid->sid->set_chip_model(MOS8580FP); @@ -40,12 +43,14 @@ sid_init(void) psid->sid->reset(); - for (c = 0; c < 32; c++) + for (uint8_t c = 0; c < 32; c++) psid->sid->write(c, 0); - if (!psid->sid->set_sampling_parameters((float) cycles_per_sec, method, + if (!psid->sid->set_sampling_parameters(cycles_per_sec, method, (float) RESID_FREQ, 0.9 * (float) RESID_FREQ / 2.0)) { - // printf("reSID failed!\n"); +#if 0 + printf("reSID failed!\n"); +#endif } psid->sid->set_chip_model(MOS6581FP); @@ -59,38 +64,49 @@ sid_init(void) } void -sid_close(UNUSED(void *p)) +sid_close(UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif delete psid->sid; - // free(psid); +#if 0 + free(psid); +#endif } void -sid_reset(UNUSED(void *p)) +sid_reset(UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; - int c; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif psid->sid->reset(); - for (c = 0; c < 32; c++) + for (uint8_t c = 0; c < 32; c++) psid->sid->write(c, 0); } uint8_t -sid_read(uint16_t addr, UNUSED(void *p)) +sid_read(uint16_t addr, UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif return psid->sid->read(addr & 0x1f); - // return 0xFF; +#if 0 + return 0xFF; +#endif } void -sid_write(uint16_t addr, uint8_t val, UNUSED(void *p)) +sid_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif psid->sid->write(addr & 0x1f, val); } @@ -107,9 +123,11 @@ fillbuf2(int &count, int16_t *buf, int len) psid->last_sample = *buf; } void -sid_fillbuf(int16_t *buf, int len, UNUSED(void *p)) +sid_fillbuf(int16_t *buf, int len, UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif int x = CLOCK_DELTA(len); fillbuf2(x, buf, len); diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 086b954bb..ae0cebabf 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -41,6 +41,7 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_sb.h> +#include <86box/plat_unused.h> /* 0 to 7 -> -14dB to 0dB i 2dB steps. 8 to 15 -> 0 to +14dB in 2dB steps. Note that for positive dB values, this is not amplitude, it is amplitude - 1. */ @@ -177,13 +178,14 @@ sb_log(const char *fmt, ...) /* SB 1, 1.5, MCV, and 2 do not have a mixer, so signal is hardwired. */ static void -sb_get_buffer_sb2(int32_t *buffer, int len, void *p) +sb_get_buffer_sb2(int32_t *buffer, int len, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; - int c; - double out_mono = 0.0, out_l = 0.0, out_r = 0.0; - int32_t *opl_buf = NULL; + sb_t *sb = (sb_t *) priv; + const sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; + double out_mono = 0.0; + double out_l = 0.0; + double out_r = 0.0; + const int32_t *opl_buf = NULL; if (sb->opl_enabled) opl_buf = sb->opl.update(sb->opl.priv); @@ -193,7 +195,7 @@ sb_get_buffer_sb2(int32_t *buffer, int len, void *p) if (sb->cms_enabled) cms_update(&sb->cms); - for (c = 0; c < len * 2; c += 2) { + for (int c = 0; c < len * 2; c += 2) { out_mono = 0.0; out_l = 0.0; out_r = 0.0; @@ -244,29 +246,30 @@ sb_get_buffer_sb2(int32_t *buffer, int len, void *p) } static void -sb2_filter_cd_audio(int channel, double *buffer, void *p) +sb2_filter_cd_audio(UNUSED(int channel), double *buffer, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; - double c; + const sb_t *sb = (sb_t *) priv; + const sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; + double c; if (sb->mixer_enabled) { c = ((sb_iir(1, 0, *buffer) / 1.3) * mixer->cd) / 3.0; *buffer = c * mixer->master; } else { - c = (((sb_iir(1, 0, ((double) *buffer)) / 1.3) * 65536) / 3.0) / 65536.0; + c = (((sb_iir(1, 0, (*buffer)) / 1.3) * 65536) / 3.0) / 65536.0; *buffer = c; } } void -sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) +sb_get_buffer_sbpro(int32_t *buffer, int len, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; - int c; - double out_l = 0.0, out_r = 0.0; - int32_t *opl_buf = NULL, *opl2_buf = NULL; + sb_t *sb = (sb_t *) priv; + const sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; + double out_l = 0.0; + double out_r = 0.0; + const int32_t *opl_buf = NULL; + const int32_t *opl2_buf = NULL; if (sb->opl_enabled) { if (sb->dsp.sb_type == SBPRO) { @@ -278,8 +281,9 @@ sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) sb_dsp_update(&sb->dsp); - for (c = 0; c < len * 2; c += 2) { - out_l = 0.0, out_r = 0.0; + for (int c = 0; c < len * 2; c += 2) { + out_l = 0.0; + out_r = 0.0; if (sb->opl_enabled) { if (sb->dsp.sb_type == SBPRO) { @@ -325,13 +329,13 @@ sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) } void -sbpro_filter_cd_audio(int channel, double *buffer, void *p) +sbpro_filter_cd_audio(int channel, double *buffer, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; - double c; - double cd = channel ? mixer->cd_r : mixer->cd_l; - double master = channel ? mixer->master_r : mixer->master_l; + const sb_t *sb = (sb_t *) priv; + const sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; + double c; + double cd = channel ? mixer->cd_r : mixer->cd_l; + double master = channel ? mixer->master_r : mixer->master_l; if (mixer->output_filter) c = (sb_iir(1, channel, *buffer) * cd) / 3.9; @@ -341,16 +345,19 @@ sbpro_filter_cd_audio(int channel, double *buffer, void *p) } static void -sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) +sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; - int c, dsp_rec_pos = sb->dsp.record_pos_write; - int c_emu8k, c_record; - int32_t in_l, in_r; - double out_l = 0.0, out_r = 0.0; - double bass_treble; - int32_t *opl_buf = NULL; + sb_t *sb = (sb_t *) priv; + const sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; + int dsp_rec_pos = sb->dsp.record_pos_write; + int c_emu8k = 0; + int c_record; + int32_t in_l; + int32_t in_r; + double out_l = 0.0; + double out_r = 0.0; + double bass_treble; + const int32_t *opl_buf = NULL; if (sb->opl_enabled) opl_buf = sb->opl.update(sb->opl.priv); @@ -360,8 +367,9 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) sb_dsp_update(&sb->dsp); - for (c = 0; c < len * 2; c += 2) { - out_l = 0.0, out_r = 0.0; + for (int c = 0; c < len * 2; c += 2) { + out_l = 0.0; + out_r = 0.0; if (sb->dsp.sb_type > SB16) c_emu8k = ((((c / 2) * FREQ_44100) / SOUND_FREQ) * 2); @@ -402,7 +410,7 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) if (mixer->bass_l > 8) out_l += (low_iir(0, 0, out_l) * bass_treble); else if (mixer->bass_l < 8) - out_l = ((out_l) *bass_treble + low_cut_iir(0, 0, out_l) * (1.0 - bass_treble)); + out_l = (out_l *bass_treble + low_cut_iir(0, 0, out_l) * (1.0 - bass_treble)); } if (mixer->bass_r != 8) { @@ -411,7 +419,7 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) if (mixer->bass_r > 8) out_r += (low_iir(0, 1, out_r) * bass_treble); else if (mixer->bass_r < 8) - out_r = ((out_r) *bass_treble + low_cut_iir(0, 1, out_r) * (1.0 - bass_treble)); + out_r = (out_r *bass_treble + low_cut_iir(0, 1, out_r) * (1.0 - bass_treble)); } if (mixer->treble_l != 8) { @@ -420,7 +428,7 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) if (mixer->treble_l > 8) out_l += (high_iir(0, 0, out_l) * bass_treble); else if (mixer->treble_l < 8) - out_l = ((out_l) *bass_treble + high_cut_iir(0, 0, out_l) * (1.0 - bass_treble)); + out_l = (out_l *bass_treble + high_cut_iir(0, 0, out_l) * (1.0 - bass_treble)); } if (mixer->treble_r != 8) { @@ -429,7 +437,7 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) if (mixer->treble_r > 8) out_r += (high_iir(0, 1, out_r) * bass_treble); else if (mixer->treble_r < 8) - out_r = ((out_l) *bass_treble + high_cut_iir(0, 1, out_r) * (1.0 - bass_treble)); + out_r = (out_l *bass_treble + high_cut_iir(0, 1, out_r) * (1.0 - bass_treble)); } if (sb->dsp.sb_enable_i) { @@ -471,17 +479,17 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) } void -sb16_awe32_filter_cd_audio(int channel, double *buffer, void *p) +sb16_awe32_filter_cd_audio(int channel, double *buffer, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; - double c; - double cd = channel ? mixer->cd_r : mixer->cd_l /* / 3.0 */; - double master = channel ? mixer->master_r : mixer->master_l; - int32_t bass = channel ? mixer->bass_r : mixer->bass_l; - int32_t treble = channel ? mixer->treble_r : mixer->treble_l; - double bass_treble; - double output_gain = (channel ? mixer->output_gain_R : mixer->output_gain_L); + const sb_t *sb = (sb_t *) priv; + const sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; + double c; + double cd = channel ? mixer->cd_r : mixer->cd_l /* / 3.0 */; + double master = channel ? mixer->master_r : mixer->master_l; + int32_t bass = channel ? mixer->bass_r : mixer->bass_l; + int32_t treble = channel ? mixer->treble_r : mixer->treble_l; + double bass_treble; + double output_gain = (channel ? mixer->output_gain_R : mixer->output_gain_L); if (mixer->output_filter) c = (low_fir_sb16(1, channel, *buffer) * cd) / 3.0; @@ -513,9 +521,9 @@ sb16_awe32_filter_cd_audio(int channel, double *buffer, void *p) } void -sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *p) +sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; if (!(addr & 1)) { @@ -552,10 +560,10 @@ sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *p) } uint8_t -sb_ct1335_mixer_read(uint16_t addr, void *p) +sb_ct1335_mixer_read(uint16_t addr, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; + const sb_t *sb = (sb_t *) priv; + const sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; if (!(addr & 1)) return mixer->index; @@ -583,9 +591,9 @@ sb_ct1335_mixer_reset(sb_t *sb) } void -sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *p) +sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; if (!(addr & 1)) { @@ -662,7 +670,7 @@ sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *p) if (mixer->index == 0xe) sb_dsp_set_stereo(&sb->dsp, val & 2); - switch ((mixer->regs[0xc] & 6)) { + switch (mixer->regs[0xc] & 6) { case 2: mixer->input_selector = INPUT_CD_L | INPUT_CD_R; break; @@ -679,10 +687,10 @@ sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *p) } uint8_t -sb_ct1345_mixer_read(uint16_t addr, void *p) +sb_ct1345_mixer_read(uint16_t addr, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; + const sb_t *sb = (sb_t *) priv; + const sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; if (!(addr & 1)) return mixer->index; @@ -721,9 +729,9 @@ sb_ct1345_mixer_reset(sb_t *sb) } void -sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) +sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; if (!(addr & 1)) @@ -855,6 +863,9 @@ sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) mpu401_change_addr(sb->mpu, 0); } break; + + default: + break; } mixer->output_selector = mixer->regs[0x3c]; @@ -891,11 +902,12 @@ sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) } uint8_t -sb_ct1745_mixer_read(uint16_t addr, void *p) +sb_ct1745_mixer_read(uint16_t addr, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; - uint8_t temp, ret = 0xff; + const sb_t *sb = (sb_t *) priv; + const sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; + uint8_t temp; + uint8_t ret = 0xff; if (!(addr & 1)) ret = mixer->index; @@ -967,6 +979,9 @@ sb_ct1745_mixer_read(uint16_t addr, void *p) case 10: ret = 8; break; + + default: + break; } break; @@ -989,6 +1004,9 @@ sb_ct1745_mixer_read(uint16_t addr, void *p) case 3: ret |= 8; break; + + default: + break; } switch (sb->dsp.sb_16_dmanum) { case 5: @@ -1000,6 +1018,9 @@ sb_ct1745_mixer_read(uint16_t addr, void *p) case 7: ret |= 0x80; break; + + default: + break; } break; @@ -1071,9 +1092,9 @@ sb_ct1745_mixer_reset(sb_t *sb) } uint8_t -sb_mcv_read(int port, void *p) +sb_mcv_read(int port, void *priv) { - sb_t *sb = (sb_t *) p; + const sb_t *sb = (sb_t *) priv; sb_log("sb_mcv_read: port=%04x\n", port); @@ -1081,10 +1102,10 @@ sb_mcv_read(int port, void *p) } void -sb_mcv_write(int port, uint8_t val, void *p) +sb_mcv_write(int port, uint8_t val, void *priv) { uint16_t addr; - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; if (port < 0x102) return; @@ -1126,18 +1147,18 @@ sb_mcv_write(int port, uint8_t val, void *p) } uint8_t -sb_mcv_feedb(void *p) +sb_mcv_feedb(void *priv) { - sb_t *sb = (sb_t *) p; + const sb_t *sb = (sb_t *) priv; return (sb->pos_regs[2] & 1); } static uint8_t -sb_pro_mcv_read(int port, void *p) +sb_pro_mcv_read(int port, void *priv) { - sb_t *sb = (sb_t *) p; - uint8_t ret = sb->pos_regs[port & 7]; + const sb_t *sb = (sb_t *) priv; + uint8_t ret = sb->pos_regs[port & 7]; sb_log("sb_pro_mcv_read: port=%04x ret=%02x\n", port, ret); @@ -1145,10 +1166,10 @@ sb_pro_mcv_read(int port, void *p) } static void -sb_pro_mcv_write(int port, uint8_t val, void *p) +sb_pro_mcv_write(int port, uint8_t val, void *priv) { uint16_t addr; - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; if (port < 0x102) return; @@ -1205,10 +1226,10 @@ sb_pro_mcv_write(int port, uint8_t val, void *p) } static uint8_t -sb_16_reply_mca_read(int port, void *p) +sb_16_reply_mca_read(int port, void *priv) { - sb_t *sb = (sb_t *) p; - uint8_t ret = sb->pos_regs[port & 7]; + const sb_t *sb = (sb_t *) priv; + uint8_t ret = sb->pos_regs[port & 7]; sb_log("sb_16_reply_mca_read: port=%04x ret=%02x\n", port, ret); @@ -1216,11 +1237,13 @@ sb_16_reply_mca_read(int port, void *p) } static void -sb_16_reply_mca_write(int port, uint8_t val, void *p) +sb_16_reply_mca_write(int port, uint8_t val, void *priv) { - uint16_t addr, mpu401_addr; - int low_dma, high_dma; - sb_t *sb = (sb_t *) p; + uint16_t addr; + uint16_t mpu401_addr; + int low_dma; + int high_dma; + sb_t *sb = (sb_t *) priv; if (port < 0x102) return; @@ -1338,6 +1361,9 @@ sb_16_reply_mca_write(int port, uint8_t val, void *p) case 0x60: sb_dsp_setirq(&sb->dsp, 10); break; + + default: + break; } low_dma = sb->pos_regs[3] & 3; @@ -1449,6 +1475,9 @@ sb_16_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) case 4: /* StereoEnhance (32) */ break; + + default: + break; } } @@ -1467,6 +1496,9 @@ sb_awe32_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pr case 3: /* WaveTable */ sb_16_pnp_config_changed(ld ^ 1, config, sb); break; + + default: + break; } } @@ -1484,11 +1516,14 @@ sb_awe64_gold_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, voi case 1: /* Game */ sb_16_pnp_config_changed(3, config, sb); break; + + default: + break; } } void * -sb_1_init(const device_t *info) +sb_1_init(UNUSED(const device_t *info)) { /* SB1/2 port mappings, 210h to 260h in 10h steps 2x0 to 2x3 -> CMS chip @@ -1536,7 +1571,7 @@ sb_1_init(const device_t *info) } void * -sb_15_init(const device_t *info) +sb_15_init(UNUSED(const device_t *info)) { /* SB1/2 port mappings, 210h to 260h in 10h steps 2x0 to 2x3 -> CMS chip @@ -1586,7 +1621,7 @@ sb_15_init(const device_t *info) } void * -sb_mcv_init(const device_t *info) +sb_mcv_init(UNUSED(const device_t *info)) { /* SB1/2 port mappings, 210h to 260h in 10h steps 2x6, 2xA, 2xC, 2xE -> DSP chip @@ -1619,7 +1654,7 @@ sb_mcv_init(const device_t *info) } void * -sb_2_init(const device_t *info) +sb_2_init(UNUSED(const device_t *info)) { /* SB2 port mappings, 220h or 240h. 2x0 to 2x3 -> CMS chip @@ -1715,7 +1750,7 @@ sb_pro_v1_opl_write(uint16_t port, uint8_t val, void *priv) } static void * -sb_pro_v1_init(const device_t *info) +sb_pro_v1_init(UNUSED(const device_t *info)) { /* SB Pro port mappings, 220h or 240h. 2x0 to 2x3 -> FM chip, Left and Right (9*2 voices) @@ -1775,7 +1810,7 @@ sb_pro_v1_init(const device_t *info) } static void * -sb_pro_v2_init(const device_t *info) +sb_pro_v2_init(UNUSED(const device_t *info)) { /* SB Pro 2 port mappings, 220h or 240h. 2x0 to 2x3 -> FM chip (18 voices) @@ -1827,7 +1862,7 @@ sb_pro_v2_init(const device_t *info) } static void * -sb_pro_mcv_init(const device_t *info) +sb_pro_mcv_init(UNUSED(const device_t *info)) { /* SB Pro MCV port mappings, 220h or 240h. 2x0 to 2x3 -> FM chip, Left and Right (18 voices) @@ -1859,7 +1894,7 @@ sb_pro_mcv_init(const device_t *info) } static void * -sb_pro_compat_init(const device_t *info) +sb_pro_compat_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0, sizeof(sb_t)); @@ -1881,7 +1916,7 @@ sb_pro_compat_init(const device_t *info) } static void * -sb_16_init(const device_t *info) +sb_16_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -1937,7 +1972,7 @@ sb_16_init(const device_t *info) } static void * -sb_16_reply_mca_init(const device_t *info) +sb_16_reply_mca_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0x00, sizeof(sb_t)); @@ -1972,7 +2007,7 @@ sb_16_reply_mca_init(const device_t *info) } static void * -sb_16_pnp_init(const device_t *info) +sb_16_pnp_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0x00, sizeof(sb_t)); @@ -2074,7 +2109,7 @@ sb_awe64_gold_available(void) } static void * -sb_awe32_init(const device_t *info) +sb_awe32_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -2167,7 +2202,7 @@ sb_awe32_pnp_init(const device_t *info) if ((info->local != 2) && (info->local != 3) && (info->local != 4)) device_add(&ide_ter_pnp_device); - char *pnp_rom_file = NULL; + const char *pnp_rom_file = NULL; switch (info->local) { case 0: pnp_rom_file = "roms/sound/CT3600 PnP.BIN"; @@ -2185,6 +2220,9 @@ sb_awe32_pnp_init(const device_t *info) case 4: pnp_rom_file = "roms/sound/CT4540 PnP.BIN"; break; + + default: + break; } uint8_t *pnp_rom = NULL; @@ -2211,6 +2249,9 @@ sb_awe32_pnp_init(const device_t *info) case 4: isapnp_add_card(pnp_rom, sizeof(sb->pnp_rom), sb_awe64_gold_pnp_config_changed, NULL, NULL, NULL, sb); break; + + default: + break; } sb_dsp_setaddr(&sb->dsp, 0); @@ -2229,18 +2270,18 @@ sb_awe32_pnp_init(const device_t *info) } void -sb_close(void *p) +sb_close(void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_dsp_close(&sb->dsp); free(sb); } static void -sb_awe32_close(void *p) +sb_awe32_close(void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; emu8k_close(&sb->emu8k); @@ -2248,9 +2289,9 @@ sb_awe32_close(void *p) } void -sb_speed_changed(void *p) +sb_speed_changed(void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_dsp_speed_changed(&sb->dsp); } diff --git a/src/sound/snd_sb_dsp.c b/src/sound/snd_sb_dsp.c index e6a7b8312..d4dcd5a79 100644 --- a/src/sound/snd_sb_dsp.c +++ b/src/sound/snd_sb_dsp.c @@ -25,6 +25,8 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_sb.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #define ADPCM_4 1 #define ADPCM_26 2 @@ -33,8 +35,8 @@ /*The recording safety margin is intended for uneven "len" calls to the get_buffer mixer calls on sound_sb*/ #define SB_DSP_REC_SAFEFTY_MARGIN 4096 -void pollsb(void *p); -void sb_poll_i(void *p); +void pollsb(void *priv); +void sb_poll_i(void *priv); static int sbe2dat[4][9] = { {0x01, -0x02, -0x04, 0x08, -0x10, 0x20, 0x40, -0x80, -106}, @@ -144,7 +146,8 @@ recalc_sb16_filter(int c, int playback_freq) { /* Cutoff frequency = playback / 2 */ int n; - double w, h; + double w; + double h; double fC = ((double) playback_freq) / (double) FREQ_96000; double gain; @@ -172,7 +175,7 @@ recalc_sb16_filter(int c, int playback_freq) static void sb_irq_update_pic(void *priv, int set) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; if (set) picint(1 << dsp->sb_irqnum); else @@ -204,8 +207,8 @@ sb_update_status(sb_dsp_t *dsp, int bit, int set) int masked = 0; switch (bit) { - case 0: default: + case 0: dsp->sb_irq8 = set; masked = dsp->sb_irqm8; break; @@ -248,7 +251,7 @@ sb_dsp_irq_update(void *priv, int set) static int sb_dsp_irq_pending(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; return dsp->sb_irq401; } @@ -299,8 +302,6 @@ sb_dsp_reset(sb_dsp_t *dsp) void sb_doreset(sb_dsp_t *dsp) { - int c; - sb_dsp_reset(dsp); if (IS_AZTECH(dsp)) { @@ -315,7 +316,7 @@ sb_doreset(sb_dsp_t *dsp) dsp->sb_asp_mode = 0; dsp->sb_asp_ram_index = 0; - for (c = 0; c < 256; c++) + for (uint16_t c = 0; c < 256; c++) dsp->sb_asp_regs[c] = 0; dsp->sb_asp_regs[5] = 0x01; @@ -409,28 +410,32 @@ sb_start_dma_i(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len) int sb_8_read_dma(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_read(dsp->sb_8_dmanum); } int sb_8_write_dma(void *priv, uint8_t val) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_write(dsp->sb_8_dmanum, val) == DMA_NODATA; } int sb_16_read_dma(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_read(dsp->sb_16_dmanum); } int sb_16_write_dma(void *priv, uint16_t val) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_write(dsp->sb_16_dmanum, val) == DMA_NODATA; } @@ -455,7 +460,8 @@ sb_dsp_setdma16(sb_dsp_t *dsp, int dma) void sb_exec_command(sb_dsp_t *dsp) { - int temp, c; + int temp; + int c; sb_dsp_log("sb_exec_command : SB command %02X\n", dsp->sb_command); @@ -595,7 +601,9 @@ sb_exec_command(sb_dsp_t *dsp) case 0x75: /* 4-bit ADPCM output with reference */ dsp->sbref = dsp->dma_readb(dsp->dma_priv); dsp->sbstep = 0; - /* Fall through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x74: /* 4-bit ADPCM output */ sb_start_dma(dsp, 1, 0, ADPCM_4, dsp->sb_data[0] + (dsp->sb_data[1] << 8)); dsp->sbdat2 = dsp->dma_readb(dsp->dma_priv); @@ -917,6 +925,9 @@ sb_exec_command(sb_dsp_t *dsp) * 0FCh DSP Auxiliary Status SB16 * 0FDh DSP Command Status SB16 */ + + default: + break; } /* Update 8051 ram with the last DSP command. @@ -1046,6 +1057,9 @@ sb_read(uint16_t a, void *priv) sb_dsp_log("SB 16-bit ACK read 0xFF\n"); ret = 0xff; break; + + default: + break; } return ret; @@ -1055,7 +1069,6 @@ void sb_dsp_input_msg(void *p, uint8_t *msg, uint32_t len) { sb_dsp_t *dsp = (sb_dsp_t *) p; - uint8_t i = 0; sb_dsp_log("MIDI in sysex = %d, uart irq = %d, msg = %d\n", dsp->midi_in_sysex, dsp->uart_irq, len); @@ -1068,11 +1081,11 @@ sb_dsp_input_msg(void *p, uint8_t *msg, uint32_t len) return; if (dsp->uart_irq) { - for (i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) sb_add_data(dsp, msg[i]); sb_irq(dsp, 1); } else if (dsp->midi_in_poll) { - for (i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) sb_add_data(dsp, msg[i]); } } @@ -1081,7 +1094,6 @@ int sb_dsp_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) { sb_dsp_t *dsp = (sb_dsp_t *) p; - uint32_t i; if (!dsp->uart_irq && !dsp->midi_in_poll && (dsp->mpu != NULL)) return MPU401_InputSysex(dsp->mpu, buffer, len, abort); @@ -1093,7 +1105,7 @@ sb_dsp_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) dsp->midi_in_sysex = 1; - for (i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { if (dsp->sb_read_rp == dsp->sb_read_wp) { sb_dsp_log("Length sysex SB = %d\n", len - i); return (len - i); @@ -1194,10 +1206,11 @@ sb_dsp_dma_attach(sb_dsp_t *dsp, } void -pollsb(void *p) +pollsb(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) p; - int tempi, ref; + sb_dsp_t *dsp = (sb_dsp_t *) priv; + int tempi; + int ref; int data[2]; timer_advance_u64(&dsp->output_timer, dsp->sblatcho); @@ -1379,6 +1392,9 @@ pollsb(void *p) } else dsp->sbdatl = dsp->sbdatr = dsp->sbdat; break; + + default: + break; } if (dsp->sb_8_length < 0) { @@ -1427,6 +1443,9 @@ pollsb(void *p) dsp->sbdatr = data[1]; dsp->sb_16_length -= 2; break; + + default: + break; } if (dsp->sb_16_length < 0) { @@ -1452,9 +1471,9 @@ pollsb(void *p) } void -sb_poll_i(void *p) +sb_poll_i(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) p; + sb_dsp_t *dsp = (sb_dsp_t *) priv; int processed = 0; timer_advance_u64(&dsp->input_timer, dsp->sblatchi); @@ -1487,6 +1506,9 @@ sb_poll_i(void *p) dsp->record_pos_read += 2; dsp->record_pos_read &= 0xFFFF; break; + + default: + break; } if (dsp->sb_8_length < 0) { @@ -1532,6 +1554,9 @@ sb_poll_i(void *p) dsp->record_pos_read += 2; dsp->record_pos_read &= 0xFFFF; break; + + default: + break; } if (dsp->sb_16_length < 0) { @@ -1566,6 +1591,7 @@ sb_dsp_update(sb_dsp_t *dsp) } void -sb_dsp_close(sb_dsp_t *dsp) +sb_dsp_close(UNUSED(sb_dsp_t *dsp)) { + // } diff --git a/src/sound/snd_sn76489.c b/src/sound/snd_sn76489.c index a28e5b848..519219934 100644 --- a/src/sound/snd_sn76489.c +++ b/src/sound/snd_sn76489.c @@ -10,6 +10,7 @@ #include <86box/io.h> #include <86box/sound.h> #include <86box/snd_sn76489.h> +#include <86box/plat_unused.h> int sn76489_mute; @@ -24,17 +25,16 @@ void sn76489_update(sn76489_t *sn76489) { for (; sn76489->pos < sound_pos_global; sn76489->pos++) { - int c; int16_t result = 0; - for (c = 1; c < 4; c++) { + for (uint8_t c = 1; c < 4; c++) { if (sn76489->latch[c] > 256) result += (int16_t) (volslog[sn76489->vol[c]] * sn76489->stat[c]); else result += (int16_t) (volslog[sn76489->vol[c]] * 127); sn76489->count[c] -= (256 * sn76489->psgconst); - while ((int) sn76489->count[c] < 0) { + while (sn76489->count[c] < 0) { sn76489->count[c] += sn76489->latch[c]; sn76489->stat[c] = -sn76489->stat[c]; } @@ -42,7 +42,7 @@ sn76489_update(sn76489_t *sn76489) result += (((sn76489->shift & 1) ^ 1) * 127 * volslog[sn76489->vol[0]] * 2); sn76489->count[0] -= (512 * sn76489->psgconst); - while ((int) sn76489->count[0] < 0 && sn76489->latch[0]) { + while (sn76489->count[0] < 0 && sn76489->latch[0]) { sn76489->count[0] += (sn76489->latch[0] * 4); if (!(sn76489->noise & 4)) { if (sn76489->shift & 1) @@ -60,16 +60,14 @@ sn76489_update(sn76489_t *sn76489) } void -sn76489_get_buffer(int32_t *buffer, int len, void *p) +sn76489_get_buffer(int32_t *buffer, int len, void *priv) { - sn76489_t *sn76489 = (sn76489_t *) p; - - int c; + sn76489_t *sn76489 = (sn76489_t *) priv; sn76489_update(sn76489); if (!sn76489_mute) { - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += sn76489->buffer[c >> 1]; } @@ -77,9 +75,9 @@ sn76489_get_buffer(int32_t *buffer, int len, void *p) } void -sn76489_write(uint16_t addr, uint8_t data, void *p) +sn76489_write(UNUSED(uint16_t addr), uint8_t data, void *priv) { - sn76489_t *sn76489 = (sn76489_t *) p; + sn76489_t *sn76489 = (sn76489_t *) priv; int freq; sn76489_update(sn76489); @@ -143,6 +141,9 @@ sn76489_write(uint16_t addr, uint8_t data, void *p) data &= 0xf; sn76489->vol[0] = 0xf - data; break; + + default: + break; } } else { if ((sn76489->firstdat & 0x70) == 0x60 && (sn76489->type == SN76496)) { @@ -200,7 +201,7 @@ sn76489_init(sn76489_t *sn76489, uint16_t base, uint16_t size, int type, int fre } void * -sn76489_device_init(const device_t *info) +sn76489_device_init(UNUSED(const device_t *info)) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -211,7 +212,7 @@ sn76489_device_init(const device_t *info) } void * -ncr8496_device_init(const device_t *info) +ncr8496_device_init(UNUSED(const device_t *info)) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -222,7 +223,7 @@ ncr8496_device_init(const device_t *info) } void * -tndy_device_init(const device_t *info) +tndy_device_init(UNUSED(const device_t *info)) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -235,9 +236,9 @@ tndy_device_init(const device_t *info) } void -sn76489_device_close(void *p) +sn76489_device_close(void *priv) { - sn76489_t *sn76489 = (sn76489_t *) p; + sn76489_t *sn76489 = (sn76489_t *) priv; free(sn76489); } diff --git a/src/sound/snd_speaker.c b/src/sound/snd_speaker.c index 774e4d650..693c3afc3 100644 --- a/src/sound/snd_speaker.c +++ b/src/sound/snd_speaker.c @@ -26,11 +26,16 @@ #include <86box/pit.h> #include <86box/snd_speaker.h> #include <86box/sound.h> +#include <86box/plat_unused.h> -int speaker_mute = 0, speaker_gated = 0; -int speaker_enable = 0, was_speaker_enable = 0; +int speaker_mute = 0; +int speaker_gated = 0; +int speaker_enable = 0; +int was_speaker_enable = 0; -int gated, speakval, speakon; +int gated; +int speakval; +int speakon; static int32_t speaker_buffer[SOUNDBUFLEN]; static int speaker_pos = 0; @@ -81,14 +86,14 @@ speaker_update(void) } void -speaker_get_buffer(int32_t *buffer, int len, void *p) +speaker_get_buffer(int32_t *buffer, int len, UNUSED(void *priv)) { - int32_t c, val; + int32_t val; speaker_update(); if (!speaker_mute) { - for (c = 0; c < len * 2; c += 2) { + for (int c = 0; c < len * 2; c += 2) { val = speaker_buffer[c >> 1]; buffer[c] += val; buffer[c + 1] += val; diff --git a/src/sound/snd_ssi2001.c b/src/sound/snd_ssi2001.c index 4ce948305..1f3c294ce 100644 --- a/src/sound/snd_ssi2001.c +++ b/src/sound/snd_ssi2001.c @@ -12,6 +12,7 @@ #include <86box/io.h> #include <86box/snd_resid.h> #include <86box/sound.h> +#include <86box/plat_unused.h> typedef struct ssi2001_t { void *psid; @@ -31,40 +32,39 @@ ssi2001_update(ssi2001_t *ssi2001) } static void -ssi2001_get_buffer(int32_t *buffer, int len, void *p) +ssi2001_get_buffer(int32_t *buffer, int len, void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; - int c; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; ssi2001_update(ssi2001); - for (c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) buffer[c] += ssi2001->buffer[c >> 1] / 2; ssi2001->pos = 0; } static uint8_t -ssi2001_read(uint16_t addr, void *p) +ssi2001_read(uint16_t addr, void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; ssi2001_update(ssi2001); - return sid_read(addr, p); + return sid_read(addr, priv); } static void -ssi2001_write(uint16_t addr, uint8_t val, void *p) +ssi2001_write(uint16_t addr, uint8_t val, void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; ssi2001_update(ssi2001); - sid_write(addr, val, p); + sid_write(addr, val, priv); } void * -ssi2001_init(const device_t *info) +ssi2001_init(UNUSED(const device_t *info)) { ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t)); memset(ssi2001, 0, sizeof(ssi2001_t)); @@ -81,9 +81,9 @@ ssi2001_init(const device_t *info) } void -ssi2001_close(void *p) +ssi2001_close(void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; sid_close(ssi2001->psid); diff --git a/src/sound/snd_wss.c b/src/sound/snd_wss.c index 9e37dd745..a69d746da 100644 --- a/src/sound/snd_wss.c +++ b/src/sound/snd_wss.c @@ -33,6 +33,7 @@ #include <86box/timer.h> #include <86box/snd_ad1848.h> #include <86box/snd_opl.h> +#include <86box/plat_unused.h> /* 530, 11, 3 - 530=23 * 530, 11, 1 - 530=22 @@ -59,14 +60,14 @@ typedef struct wss_t { } wss_t; uint8_t -wss_read(uint16_t addr, void *priv) +wss_read(UNUSED(uint16_t addr), void *priv) { - wss_t *wss = (wss_t *) priv; + const wss_t *wss = (wss_t *) priv; return 4 | (wss->config & 0x40); } void -wss_write(uint16_t addr, uint8_t val, void *priv) +wss_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { wss_t *wss = (wss_t *) priv; @@ -79,21 +80,25 @@ static void wss_get_buffer(int32_t *buffer, int len, void *priv) { wss_t *wss = (wss_t *) priv; - int c; + const int32_t *opl_buf = NULL; + + if (wss->opl_enabled) + opl_buf = wss->opl.update(wss->opl.priv); - int32_t *opl_buf = wss->opl.update(wss->opl.priv); ad1848_update(&wss->ad1848); - for (c = 0; c < len * 2; c++) { - buffer[c] += opl_buf[c]; + for (int c = 0; c < len * 2; c++) { + if (opl_buf) + buffer[c] += opl_buf[c]; buffer[c] += wss->ad1848.buffer[c] / 2; } - wss->opl.reset_buffer(wss->opl.priv); + if (wss->opl_enabled) + wss->opl.reset_buffer(wss->opl.priv); wss->ad1848.pos = 0; } void * -wss_init(const device_t *info) +wss_init(UNUSED(const device_t *info)) { wss_t *wss = malloc(sizeof(wss_t)); memset(wss, 0, sizeof(wss_t)); @@ -132,7 +137,7 @@ wss_init(const device_t *info) static uint8_t ncr_audio_mca_read(int port, void *priv) { - wss_t *wss = (wss_t *) priv; + const wss_t *wss = (wss_t *) priv; return wss->pos_regs[port & 7]; } @@ -187,12 +192,12 @@ ncr_audio_mca_write(int port, uint8_t val, void *priv) static uint8_t ncr_audio_mca_feedb(void *priv) { - wss_t *wss = (wss_t *) priv; + const wss_t *wss = (wss_t *) priv; return (wss->pos_regs[2] & 1); } void * -ncr_audio_init(const device_t *info) +ncr_audio_init(UNUSED(const device_t *info)) { wss_t *wss = malloc(sizeof(wss_t)); memset(wss, 0, sizeof(wss_t)); diff --git a/src/sound/snd_ym7128.c b/src/sound/snd_ym7128.c index a6398628a..59e5691e9 100644 --- a/src/sound/snd_ym7128.c +++ b/src/sound/snd_ym7128.c @@ -5,12 +5,13 @@ #include <86box/86box.h> #include <86box/snd_ym7128.h> +#include <86box/plat_unused.h> static int attenuation[32]; static int tap_position[32]; void -ym7128_init(ym7128_t *ym7128) +ym7128_init(UNUSED(ym7128_t *ym7128)) { int c; double out = 65536.0; @@ -97,6 +98,9 @@ ym7128_write(ym7128_t *ym7128, uint8_t val) case 0x1e: ym7128->t[ym7128->reg_sel - 0x16] = tap_position[ym7128->dat & 0x1f]; break; + + default: + break; } ym7128->regs[ym7128->reg_sel] = ym7128->dat; } @@ -112,13 +116,13 @@ ym7128_write(ym7128_t *ym7128, uint8_t val) void ym7128_apply(ym7128_t *ym7128, int16_t *buffer, int len) { - int c, d; - - for (c = 0; c < len * 2; c += 4) { + for (int c = 0; c < len * 2; c += 4) { /*YM7128 samples a mono stream at ~24 kHz, so downsample*/ int32_t samp = ((int32_t) buffer[c] + (int32_t) buffer[c + 1] + (int32_t) buffer[c + 2] + (int32_t) buffer[c + 3]) / 4; - int32_t filter_temp, filter_out; - int32_t samp_l = 0, samp_r = 0; + int32_t filter_temp; + int32_t filter_out; + int32_t samp_l = 0; + int32_t samp_r = 0; filter_temp = GET_DELAY_SAMPLE(ym7128, ym7128->t[0]); filter_out = ((filter_temp * ym7128->c0) >> 11) + ((ym7128->filter_dat * ym7128->c1) >> 11); @@ -129,7 +133,7 @@ ym7128_apply(ym7128_t *ym7128, int16_t *buffer, int len) ym7128->delay_buffer[ym7128->delay_pos] = samp; - for (d = 0; d < 8; d++) { + for (uint8_t d = 0; d < 8; d++) { samp_l += (GET_DELAY_SAMPLE(ym7128, ym7128->t[d + 1]) * ym7128->gl[d]) >> 16; samp_r += (GET_DELAY_SAMPLE(ym7128, ym7128->t[d + 1]) * ym7128->gr[d]) >> 16; } @@ -137,8 +141,8 @@ ym7128_apply(ym7128_t *ym7128, int16_t *buffer, int len) samp_l = (samp_l * ym7128->vl * 2) >> 16; samp_r = (samp_r * ym7128->vr * 2) >> 16; - buffer[c] += ((int32_t) samp_l + (int32_t) ym7128->prev_l) / 2; - buffer[c + 1] += ((int32_t) samp_r + (int32_t) ym7128->prev_r) / 2; + buffer[c] += (samp_l + (int32_t) ym7128->prev_l) / 2; + buffer[c + 1] += (samp_r + (int32_t) ym7128->prev_r) / 2; buffer[c + 2] += samp_l; buffer[c + 3] += samp_r; diff --git a/src/sound/sound.c b/src/sound/sound.c index dbfaf0fdb..542528ccb 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -47,7 +47,7 @@ typedef struct { } SOUND_CARD; typedef struct { - void (*get_buffer)(int32_t *buffer, int len, void *p); + void (*get_buffer)(int32_t *buffer, int len, void *priv); void *priv; } sound_handler_t; @@ -70,12 +70,13 @@ static uint64_t sound_poll_latch; static int16_t cd_buffer[CDROM_NUM][CD_BUFLEN * 2]; static float cd_out_buffer[CD_BUFLEN * 2]; static int16_t cd_out_buffer_int16[CD_BUFLEN * 2]; -static unsigned int cd_vol_l, cd_vol_r; +static unsigned int cd_vol_l; +static unsigned int cd_vol_r; static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN; static volatile int cdaudioon = 0; static int cd_thread_enable = 0; -static void (*filter_cd_audio)(int channel, double *buffer, void *p) = NULL; +static void (*filter_cd_audio)(int channel, double *buffer, void *priv) = NULL; static void *filter_cd_audio_p = NULL; static const device_t sound_none_device = { @@ -202,12 +203,12 @@ sound_card_get_internal_name(int card) } int -sound_card_get_from_internal_name(char *s) +sound_card_get_from_internal_name(const char *s) { int c = 0; while (sound_cards[c].device != NULL) { - if (!strcmp((char *) sound_cards[c].device->internal_name, s)) + if (!strcmp(sound_cards[c].device->internal_name, s)) return c; c++; } @@ -245,11 +246,14 @@ sound_cd_clean_buffers(void) } static void -sound_cd_thread(void *param) +sound_cd_thread(UNUSED(void *param)) { uint32_t lba; - int c, r, i, pre, channel_select[2]; - double audio_vol_l, audio_vol_r; + int r; + int pre; + int channel_select[2]; + double audio_vol_l; + double audio_vol_r; double cd_buffer_temp[2] = { 0.0, 0.0 }; thread_set_event(sound_cd_start_event); @@ -263,7 +267,7 @@ sound_cd_thread(void *param) sound_cd_clean_buffers(); - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { if ((cdrom[i].bus_type == CDROM_BUS_DISABLED) || (cdrom[i].cd_status == CD_STATUS_EMPTY)) continue; lba = cdrom[i].seek_pos; @@ -303,7 +307,7 @@ sound_cd_thread(void *param) channel_select[1] = 2; } - for (c = 0; c < CD_BUFLEN * 2; c += 2) { + for (uint16_t c = 0; c < CD_BUFLEN * 2; c += 2) { /*Apply ATAPI channel select*/ cd_buffer_temp[0] = cd_buffer_temp[1] = 0.0; @@ -388,7 +392,6 @@ sound_realloc_buffers(void) void sound_init(void) { - int i = 0; int available_cdrom_drives = 0; outbuffer_ex = NULL; @@ -398,7 +401,7 @@ sound_init(void) outbuffer = calloc(SOUNDBUFLEN * 2, sizeof(int32_t)); memset(outbuffer, 0x00, SOUNDBUFLEN * 2 * sizeof(int32_t)); - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { if (cdrom[i].bus_type != CDROM_BUS_DISABLED) available_cdrom_drives++; } @@ -422,24 +425,24 @@ sound_init(void) } void -sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p) +sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *priv), void *priv) { sound_handlers[sound_handlers_num].get_buffer = get_buffer; - sound_handlers[sound_handlers_num].priv = p; + sound_handlers[sound_handlers_num].priv = priv; sound_handlers_num++; } void -sound_set_cd_audio_filter(void (*filter)(int channel, double *buffer, void *p), void *p) +sound_set_cd_audio_filter(void (*filter)(int channel, double *buffer, void *priv), void *priv) { if ((filter_cd_audio == NULL) || (filter == NULL)) { filter_cd_audio = filter; - filter_cd_audio_p = p; + filter_cd_audio_p = priv; } } void -sound_poll(void *priv) +sound_poll(UNUSED(void *priv)) { timer_advance_u64(&sound_poll_timer, sound_poll_latch); @@ -456,7 +459,7 @@ sound_poll(void *priv) for (c = 0; c < SOUNDBUFLEN * 2; c++) { if (sound_is_float) - outbuffer_ex[c] = ((float) outbuffer[c]) / 32768.0; + outbuffer_ex[c] = ((float) outbuffer[c]) / (float) 32768.0; else { if (outbuffer[c] > 32767) outbuffer[c] = 32767; @@ -551,10 +554,9 @@ sound_cd_thread_end(void) void sound_cd_thread_reset(void) { - int i = 0; int available_cdrom_drives = 0; - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { cdrom_stop(&(cdrom[i])); if (cdrom[i].bus_type != CDROM_BUS_DISABLED) diff --git a/src/sound/xaudio2.c b/src/sound/xaudio2.c index 0045135fc..0d9e7d909 100644 --- a/src/sound/xaudio2.c +++ b/src/sound/xaudio2.c @@ -33,6 +33,7 @@ #include <86box/midi.h> #include <86box/plat_dynld.h> #include <86box/sound.h> +#include <86box/plat_unused.h> #if defined(_WIN32) && !defined(USE_FAUDIO) static void *xaudio2_handle = NULL; @@ -57,32 +58,38 @@ static IXAudio2SourceVoice *srcvoicecd = NULL; #define BUFLEN SOUNDBUFLEN static void WINAPI -OnVoiceProcessingPassStart(IXAudio2VoiceCallback *callback, uint32_t bytesRequired) +OnVoiceProcessingPassStart(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(uint32_t bytesRequired)) { + // } static void WINAPI -OnVoiceProcessingPassEnd(IXAudio2VoiceCallback *callback) +OnVoiceProcessingPassEnd(UNUSED(IXAudio2VoiceCallback *callback)) { + // } static void WINAPI -OnStreamEnd(IXAudio2VoiceCallback *callback) +OnStreamEnd(UNUSED(IXAudio2VoiceCallback *callback)) { + // } static void WINAPI -OnBufferStart(IXAudio2VoiceCallback *callback, void *pBufferContext) +OnBufferStart(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext)) { + // } static void WINAPI -OnLoopEnd(IXAudio2VoiceCallback *callback, void *pBufferContext) +OnLoopEnd(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext)) { + // } static void WINAPI -OnVoiceError(IXAudio2VoiceCallback *callback, void *pBufferContext, HRESULT error) +OnVoiceError(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext), UNUSED(HRESULT error)) { + // } static void WINAPI -OnBufferEnd(IXAudio2VoiceCallback *callback, void *pBufferContext) +OnBufferEnd(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext)) { free(pBufferContext); } @@ -167,7 +174,7 @@ inital(void) IXAudio2SourceVoice_Start(srcvoice, 0, XAUDIO2_COMMIT_NOW); IXAudio2SourceVoice_Start(srcvoicecd, 0, XAUDIO2_COMMIT_NOW); - char *mdn = midi_out_device_get_internal_name(midi_output_device_current); + const char *mdn = midi_out_device_get_internal_name(midi_output_device_current); if (strcmp(mdn, "none") && strcmp(mdn, SYSTEM_MIDI_INTERNAL_NAME)) { fmt.nSamplesPerSec = midi_freq; @@ -221,10 +228,10 @@ givealbuffer_common(void *buf, IXAudio2SourceVoice *sourcevoice, size_t buflen) buffer.Flags = 0; if (sound_is_float) { buffer.pAudioData = calloc(buflen, sizeof(float)); - buffer.AudioBytes = (buflen) * sizeof(float); + buffer.AudioBytes = buflen * sizeof(float); } else { buffer.pAudioData = calloc(buflen, sizeof(int16_t)); - buffer.AudioBytes = (buflen) * sizeof(int16_t); + buffer.AudioBytes = buflen * sizeof(int16_t); } if (buffer.pAudioData == NULL) { fatal("xaudio2: Out Of Memory!"); diff --git a/src/sound/ymfm/ymfm.h b/src/sound/ymfm/ymfm.h index ae13faedd..bc0cf8b6c 100644 --- a/src/sound/ymfm/ymfm.h +++ b/src/sound/ymfm/ymfm.h @@ -40,11 +40,11 @@ #include #include #include +#include #include #include #include #include -#include namespace ymfm { @@ -329,7 +329,7 @@ struct ymfm_output // ======================> ymfm_wavfile // this class is a debugging helper that accumulates data and writes it to wav files -template +template class ymfm_wavfile { public: @@ -361,10 +361,10 @@ public: memcpy(&header[12], "fmt ", 4); *(uint32_t *)&header[16] = 16; *(uint16_t *)&header[20] = 1; - *(uint16_t *)&header[22] = _Channels; + *(uint16_t *)&header[22] = Channels; *(uint32_t *)&header[24] = m_samplerate; - *(uint32_t *)&header[28] = m_samplerate * 2 * _Channels; - *(uint16_t *)&header[32] = 2 * _Channels; + *(uint32_t *)&header[28] = m_samplerate * 2 * Channels; + *(uint16_t *)&header[32] = 2 * Channels; *(uint16_t *)&header[34] = 16; memcpy(&header[36], "data", 4); *(uint32_t *)&header[40] = m_buffer.size() * 2 + 44 - 44; @@ -377,24 +377,24 @@ public: } // add data to the file - template - void add(ymfm_output<_Outputs> output) + template + void add(ymfm_output output) { - int16_t sum[_Channels] = { 0 }; - for (int index = 0; index < _Outputs; index++) - sum[index % _Channels] += output.data[index]; - for (int index = 0; index < _Channels; index++) + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index]; + for (int index = 0; index < Channels; index++) m_buffer.push_back(sum[index]); } // add data to the file, using a reference - template - void add(ymfm_output<_Outputs> output, ymfm_output<_Outputs> const &ref) + template + void add(ymfm_output output, ymfm_output const &ref) { - int16_t sum[_Channels] = { 0 }; - for (int index = 0; index < _Outputs; index++) - sum[index % _Channels] += output.data[index] - ref.data[index]; - for (int index = 0; index < _Channels; index++) + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index] - ref.data[index]; + for (int index = 0; index < Channels; index++) m_buffer.push_back(sum[index]); } diff --git a/src/sound/ymfm/ymfm_fm.h b/src/sound/ymfm/ymfm_fm.h index 7c92c0f82..81795f8fe 100644 --- a/src/sound/ymfm/ymfm_fm.h +++ b/src/sound/ymfm/ymfm_fm.h @@ -33,7 +33,7 @@ #pragma once -#define DEBUG_LOG_WAVFILES (0) +#define YMFM_DEBUG_LOG_WAVFILES (0) namespace ymfm { @@ -401,7 +401,7 @@ public: // compute sample rate uint32_t sample_rate(uint32_t baseclock) const { -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) m_wavfile[chnum].set_samplerate(baseclock / (m_clock_prescale * OPERATORS)); #endif @@ -453,7 +453,7 @@ protected: RegisterType m_regs; // register accessor std::unique_ptr> m_channel[CHANNELS]; // channel pointers std::unique_ptr> m_operator[OPERATORS]; // operator pointers -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) mutable ymfm_wavfile<1> m_wavfile[CHANNELS]; // for debugging #endif }; diff --git a/src/sound/ymfm/ymfm_fm.ipp b/src/sound/ymfm/ymfm_fm.ipp index 7e5109d59..14c1aa965 100644 --- a/src/sound/ymfm/ymfm_fm.ipp +++ b/src/sound/ymfm/ymfm_fm.ipp @@ -1185,6 +1185,7 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : m_irq_mask(STATUS_TIMERA | STATUS_TIMERB), m_irq_state(0), m_timer_running{0,0}, + m_total_clocks(0), m_active_channels(ALL_CHANNELS), m_modified_channels(ALL_CHANNELS), m_prepare_count(0) @@ -1200,7 +1201,7 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : for (uint32_t opnum = 0; opnum < OPERATORS; opnum++) m_operator[opnum] = std::make_unique>(*this, RegisterType::operator_offset(opnum)); -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) m_wavfile[chnum].set_index(chnum); #endif @@ -1332,7 +1333,7 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, chanmask &= debug::GLOBAL_FM_CHANNEL_MASK; // mask out inactive channels - if (!DEBUG_LOG_WAVFILES) + if (!YMFM_DEBUG_LOG_WAVFILES) chanmask &= m_active_channels; // handle the rhythm case, where some of the operators are dedicated @@ -1351,7 +1352,7 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) auto reference = output; #endif if (chnum == 6) @@ -1364,7 +1365,7 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) m_wavfile[chnum].add(output, reference); #endif } @@ -1375,14 +1376,14 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) auto reference = output; #endif if (m_channel[chnum]->is4op()) m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) m_wavfile[chnum].add(output, reference); #endif } diff --git a/src/sound/ymfm/ymfm_opl.cpp b/src/sound/ymfm/ymfm_opl.cpp index 86215c5b2..499bfceef 100644 --- a/src/sound/ymfm/ymfm_opl.cpp +++ b/src/sound/ymfm/ymfm_opl.cpp @@ -100,6 +100,11 @@ opl_registers_base::opl_registers_base() : } } } + + // OPL3/OPL4 have dynamic operators, so initialize the fourop_enable value here + // since operator_map() is called right away, prior to reset() + if (Revision > 2) + m_regdata[0x104 % REGISTERS] = 0; } @@ -1710,9 +1715,15 @@ uint8_t ymf278b::read_status() uint8_t ymf278b::read_data_pcm() { - // write to FM + // read from PCM if (bitfield(m_address, 9) != 0) - return m_pcm.read(m_address & 0xff); + { + uint8_t result = m_pcm.read(m_address & 0xff); + if ((m_address & 0xff) == 0x02) + result |= 0x20; + + return result; + } return 0; } diff --git a/src/sound/ymfm/ymfm_pcm.cpp b/src/sound/ymfm/ymfm_pcm.cpp index 50595133b..34417490c 100644 --- a/src/sound/ymfm/ymfm_pcm.cpp +++ b/src/sound/ymfm/ymfm_pcm.cpp @@ -46,7 +46,6 @@ namespace ymfm void pcm_registers::reset() { std::fill_n(&m_regdata[0], REGISTERS, 0); - m_regdata[0x02] = 0x20; m_regdata[0xf8] = 0x1b; } diff --git a/src/timer.c b/src/timer.c index 7a6600fc3..e863c2f21 100644 --- a/src/timer.c +++ b/src/timer.c @@ -123,7 +123,7 @@ timer_process(void) if (timer->flags & TIMER_SPLIT) timer_advance_ex(timer, 0); /* We're splitting a > 1 s period into multiple <= 1 s periods. */ else if (timer->callback != NULL) /* Make sure it's no NULL, so that we can have a NULL callback when no operation is needed. */ - timer->callback(timer->p); + timer->callback(timer->priv); } timer_target = timer_head->ts.ts32.integer; @@ -132,7 +132,8 @@ timer_process(void) void timer_close(void) { - pc_timer_t *t = timer_head, *r; + pc_timer_t *t = timer_head; + pc_timer_t *r; /* Set all timers' prev and next to NULL so it is assured that timers that are not in malloc'd structs don't keep pointing @@ -158,12 +159,12 @@ timer_init(void) } void -timer_add(pc_timer_t *timer, void (*callback)(void *p), void *p, int start_timer) +timer_add(pc_timer_t *timer, void (*callback)(void *priv), void *priv, int start_timer) { memset(timer, 0, sizeof(pc_timer_t)); timer->callback = callback; - timer->p = p; + timer->priv = priv; timer->flags = 0; timer->prev = timer->next = NULL; if (start_timer) diff --git a/src/unix/assets/86Box.spec b/src/unix/assets/86Box.spec index e994ca4a7..ede0d5bb6 100644 --- a/src/unix/assets/86Box.spec +++ b/src/unix/assets/86Box.spec @@ -12,7 +12,7 @@ # After a successful build, you can install the RPMs as follows: # sudo dnf install RPMS/$(uname -m)/86Box-3* RPMS/noarch/86Box-roms* -%global romver v3.11 +%global romver 3.11 Name: 86Box Version: 4.0 @@ -21,8 +21,8 @@ Summary: Classic PC emulator License: GPLv2+ URL: https://86box.net -Source0: https://github.com/86Box/86Box/archive/refs/tags/v%%{version}.tar.gz -Source1: https://github.com/86Box/roms/archive/refs/tags/%{romver}.zip +Source0: https://github.com/86Box/86Box/archive/refs/tags/v%{version}.tar.gz +Source1: https://github.com/86Box/roms/archive/refs/tags/v%{romver}.zip BuildRequires: cmake BuildRequires: desktop-file-utils @@ -32,6 +32,7 @@ BuildRequires: gcc-c++ BuildRequires: libFAudio-devel BuildRequires: libappstream-glib BuildRequires: libevdev-devel +BuildRequires: libxkbcommon-x11-devel BuildRequires: libXi-devel BuildRequires: ninja-build BuildRequires: openal-soft-devel @@ -98,7 +99,7 @@ cp src/unix/assets/net.86box.86Box.metainfo.xml %{buildroot}%{_metainfodir} appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/net.86box.86Box.metainfo.xml # install roms -pushd roms-%{version} +pushd roms-%{romver} mkdir -p %{buildroot}%{_datadir}/%{name}/roms cp -a * %{buildroot}%{_datadir}/%{name}/roms/ popd diff --git a/src/unix/unix.c b/src/unix/unix.c index 478b5309f..b56022474 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -36,6 +36,7 @@ #include <86box/unix_sdl.h> #include <86box/timer.h> #include <86box/nvr.h> +#include <86box/version.h> #include <86box/video.h> #include <86box/ui.h> #include <86box/gdbstub.h> @@ -63,7 +64,8 @@ SDL_mutex *blitmtx; SDL_threadID eventthread; static int exit_event = 0; static int fullscreen_pending = 0; -uint32_t lang_id = 0x0409, lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US +uint32_t lang_id = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US +uint32_t lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US char icon_set[256] = ""; /* name of the iconset to be used */ static const uint16_t sdl_to_xt[0x200] = { @@ -175,7 +177,10 @@ static const uint16_t sdl_to_xt[0x200] = { }; typedef struct sdl_blit_params { - int x, y, w, h; + int x; + int y; + int w; + int h; } sdl_blit_params; sdl_blit_params params = { 0, 0, 0, 0 }; @@ -242,8 +247,6 @@ plat_get_string(int i) return L"Press CTRL-END to release mouse"; case IDS_2079: return L"Press CTRL-END or middle button to release mouse"; - case IDS_2080: - return L"Failed to initialize FluidSynth"; case IDS_2131: return L"Invalid configuration"; case IDS_4099: @@ -254,16 +257,10 @@ plat_get_string(int i) return L"No PCap devices found"; case IDS_2096: return L"Invalid PCap device"; - case IDS_2111: - return L"Unable to initialize FreeType"; case IDS_2112: return L"Unable to initialize SDL, libsdl2 is required"; - case IDS_2132: - return L"libfreetype is required for ESC/P printer emulation."; case IDS_2133: return L"libgs is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files."; - case IDS_2134: - return L"libfluidsynth is required for FluidSynth MIDI output."; case IDS_2130: return L"Make sure libpcap is installed and that you are on a libpcap-compatible network connection."; case IDS_2115: @@ -307,7 +304,7 @@ path_normalize(char *path) void path_slash(char *path) { - if ((path[strlen(path) - 1] != '/')) { + if (path[strlen(path) - 1] != '/') { strcat(path, "/"); } path_normalize(path); @@ -347,7 +344,7 @@ path_get_filename(char *s) c--; } - return (s); + return s; } char * @@ -356,7 +353,7 @@ path_get_extension(char *s) int c = strlen(s) - 1; if (c <= 0) - return (s); + return s; while (c && s[c] != '.') c--; @@ -417,7 +414,8 @@ plat_timer_read(void) static uint64_t plat_get_ticks_common(void) { - uint64_t EndingTime, ElapsedMicroseconds; + uint64_t EndingTime; + uint64_t ElapsedMicroseconds; if (first_use) { Frequency = SDL_GetPerformanceFrequency(); StartingTime = SDL_GetPerformanceCounter(); @@ -519,8 +517,10 @@ strnicmp(const char *s1, const char *s2, size_t n) void main_thread(void *param) { - uint32_t old_time, new_time; - int drawits, frames; + uint32_t old_time; + uint32_t new_time; + int drawits; + int frames; SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); framecountx = 0; @@ -693,7 +693,9 @@ ui_sb_bugui(char *str) extern void sdl_blit(int x, int y, int w, int h); typedef struct mouseinputdata { - int deltax, deltay, deltaz; + int deltax; + int deltay; + int deltaz; int mousebuttons; } mouseinputdata; SDL_mutex *mousemutex; @@ -710,7 +712,8 @@ mouse_poll(void) SDL_UnlockMutex(mousemutex); } -int real_sdl_w, real_sdl_h; +int real_sdl_w; +int real_sdl_h; void ui_sb_set_ready(int ready) { @@ -721,7 +724,8 @@ char *xargv[512]; char * local_strsep(char **str, const char *sep) { - char *s = *str, *end; + char *s = *str; + char *end; if (!s) return NULL; end = s + strcspn(s, sep); @@ -814,7 +818,7 @@ void plat_get_global_config_dir(char *strptr) { #ifdef __APPLE__ - char *prefPath = SDL_GetPrefPath(NULL, "net.86Box.86Box") + char *prefPath = SDL_GetPrefPath(NULL, "net.86Box.86Box"); #else char *prefPath = SDL_GetPrefPath(NULL, "86Box"); #endif @@ -828,8 +832,7 @@ process_media_commands_3(uint8_t *id, char *fn, uint8_t *wp, int cmdargc) bool err = false; *id = atoi(xargv[1]); if (xargv[2][0] == '\'' || xargv[2][0] == '"') { - int curarg = 2; - for (curarg = 2; curarg < cmdargc; curarg++) { + for (int curarg = 2; curarg < cmdargc; curarg++) { if (strlen(fn) + strlen(xargv[curarg]) >= PATH_MAX) { err = true; fprintf(stderr, "Path name too long.\n"); @@ -925,9 +928,43 @@ monitor_thread(void *param) "hardreset - hard reset the emulated system.\n" "pause - pause the the emulated system.\n" "fullscreen - toggle fullscreen.\n" + "version - print version and license information.\n" "exit - exit 86Box.\n"); } else if (strncasecmp(xargv[0], "exit", 4) == 0) { exit_event = 1; + } else if (strncasecmp(xargv[0], "version", 7) == 0) { +# ifndef EMU_GIT_HASH +# define EMU_GIT_HASH "0000000" +# endif + +# if defined(__arm__) || defined(__TARGET_ARCH_ARM) +# define ARCH_STR "arm" +# elif defined(__aarch64__) || defined(_M_ARM64) +# define ARCH_STR "arm64" +# elif defined(__i386) || defined(__i386__) || defined(_M_IX86) +# define ARCH_STR "i386" +# elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) +# define ARCH_STR "x86_64" +# else +# define ARCH_STR "unknown arch" +# endif + +# ifdef USE_DYNAREC +# ifdef USE_NEW_DYNAREC +# define DYNAREC_STR "new dynarec" +# else +# define DYNAREC_STR "old dynarec" +# endif +# else +# define DYNAREC_STR "no dynarec" +# endif + + printf( + "%s v%s [%s] [%s, %s]\n\n" + "An emulator of old computers\n" + "Authors: Sarah Walker, Miran Grca, Fred N. van Kempen (waltje), SA1988, Tiseno100, reenigne, leilei, JohnElliott, greatpsycho, and others.\n\n" + "Released under the GNU General Public License version 2 or later. See LICENSE for more information.\n", + EMU_NAME, EMU_VERSION_FULL, EMU_GIT_HASH, ARCH_STR, DYNAREC_STR); } else if (strncasecmp(xargv[0], "fullscreen", 10) == 0) { video_fullscreen = video_fullscreen ? 0 : 1; fullscreen_pending = 1; @@ -989,7 +1026,8 @@ monitor_thread(void *param) } else if (strncasecmp(xargv[0], "zipeject", 8) == 0 && cmdargc >= 2) { zip_eject(atoi(xargv[1])); } else if (strncasecmp(xargv[0], "fddload", 7) == 0 && cmdargc >= 4) { - uint8_t id, wp; + uint8_t id; + uint8_t wp; bool err = false; char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); @@ -1008,7 +1046,8 @@ monitor_thread(void *param) floppy_mount(id, fn, wp); } } else if (strncasecmp(xargv[0], "moload", 7) == 0 && cmdargc >= 4) { - uint8_t id, wp; + uint8_t id; + uint8_t wp; bool err = false; char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); @@ -1027,7 +1066,8 @@ monitor_thread(void *param) mo_mount(id, fn, wp); } } else if (strncasecmp(xargv[0], "cartload", 7) == 0 && cmdargc >= 4) { - uint8_t id, wp; + uint8_t id; + uint8_t wp; bool err = false; char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); @@ -1046,7 +1086,8 @@ monitor_thread(void *param) cartridge_mount(id, fn, wp); } } else if (strncasecmp(xargv[0], "zipload", 7) == 0 && cmdargc >= 4) { - uint8_t id, wp; + uint8_t id; + uint8_t wp; bool err = false; char fn[PATH_MAX]; memset(fn, 0, sizeof(fn)); diff --git a/src/unix/unix_cdrom.c b/src/unix/unix_cdrom.c index 79a649eb5..7ba247108 100644 --- a/src/unix/unix_cdrom.c +++ b/src/unix/unix_cdrom.c @@ -49,7 +49,9 @@ cassette_mount(char *fn, uint8_t wp) if (fn != NULL) memcpy(cassette_fname, fn, MIN(511, strlen(fn))); ui_sb_update_icon_state(SB_CASSETTE, (fn == NULL) ? 1 : 0); - // media_menu_update_cassette(); +#if 0 + media_menu_update_cassette(); +#endif ui_sb_update_tip(SB_CASSETTE); config_save(); } @@ -60,7 +62,9 @@ cassette_eject(void) pc_cas_set_fname(cassette, NULL); memset(cassette_fname, 0x00, sizeof(cassette_fname)); ui_sb_update_icon_state(SB_CASSETTE, 1); - // media_menu_update_cassette(); +#if 0 + media_menu_update_cassette(); +#endif ui_sb_update_tip(SB_CASSETTE); config_save(); } @@ -71,7 +75,9 @@ cartridge_mount(uint8_t id, char *fn, uint8_t wp) cart_close(id); cart_load(id, fn); ui_sb_update_icon_state(SB_CARTRIDGE | id, strlen(cart_fns[id]) ? 0 : 1); - // media_menu_update_cartridge(id); +#if 0 + media_menu_update_cartridge(id); +#endif ui_sb_update_tip(SB_CARTRIDGE | id); config_save(); } @@ -81,7 +87,9 @@ cartridge_eject(uint8_t id) { cart_close(id); ui_sb_update_icon_state(SB_CARTRIDGE | id, 1); - // media_menu_update_cartridge(id); +#if 0 + media_menu_update_cartridge(id); +#endif ui_sb_update_tip(SB_CARTRIDGE | id); config_save(); } @@ -93,7 +101,9 @@ floppy_mount(uint8_t id, char *fn, uint8_t wp) ui_writeprot[id] = wp; fdd_load(id, fn); ui_sb_update_icon_state(SB_FLOPPY | id, strlen(floppyfns[id]) ? 0 : 1); - // media_menu_update_floppy(id); +#if 0 + media_menu_update_floppy(id); +#endif ui_sb_update_tip(SB_FLOPPY | id); config_save(); } @@ -103,7 +113,9 @@ floppy_eject(uint8_t id) { fdd_close(id); ui_sb_update_icon_state(SB_FLOPPY | id, 1); - // media_menu_update_floppy(id); +#if 0 + media_menu_update_floppy(id); +#endif ui_sb_update_tip(SB_FLOPPY | id); config_save(); } @@ -119,7 +131,9 @@ plat_cdrom_ui_update(uint8_t id, uint8_t reload) ui_sb_update_icon_state(SB_CDROM | id, 0); } - // media_menu_update_cdrom(id); +#if 0 + media_menu_update_cdrom(id); +#endif ui_sb_update_tip(SB_CDROM | id); } @@ -142,7 +156,9 @@ cdrom_mount(uint8_t id, char *fn) } else { ui_sb_update_icon_state(SB_CDROM | id, 1); } - // media_menu_update_cdrom(id); +#if 0 + media_menu_update_cdrom(id); +#endif ui_sb_update_tip(SB_CDROM | id); config_save(); } @@ -159,7 +175,9 @@ mo_eject(uint8_t id) } ui_sb_update_icon_state(SB_MO | id, 1); - // media_menu_update_mo(id); +#if 0 + media_menu_update_mo(id); +#endif ui_sb_update_tip(SB_MO | id); config_save(); } @@ -175,7 +193,9 @@ mo_mount(uint8_t id, char *fn, uint8_t wp) mo_insert(dev); ui_sb_update_icon_state(SB_MO | id, strlen(mo_drives[id].image_path) ? 0 : 1); - // media_menu_update_mo(id); +#if 0 + media_menu_update_mo(id); +#endif ui_sb_update_tip(SB_MO | id); config_save(); @@ -193,7 +213,9 @@ mo_reload(uint8_t id) ui_sb_update_icon_state(SB_MO | id, 0); } - // media_menu_update_mo(id); +#if 0 + media_menu_update_mo(id); +#endif ui_sb_update_tip(SB_MO | id); config_save(); @@ -211,7 +233,9 @@ zip_eject(uint8_t id) } ui_sb_update_icon_state(SB_ZIP | id, 1); - // media_menu_update_zip(id); +#if 0 + media_menu_update_zip(id); +#endif ui_sb_update_tip(SB_ZIP | id); config_save(); } @@ -227,7 +251,9 @@ zip_mount(uint8_t id, char *fn, uint8_t wp) zip_insert(dev); ui_sb_update_icon_state(SB_ZIP | id, strlen(zip_drives[id].image_path) ? 0 : 1); - // media_menu_update_zip(id); +#if 0 + media_menu_update_zip(id); +#endif ui_sb_update_tip(SB_ZIP | id); config_save(); @@ -245,7 +271,9 @@ zip_reload(uint8_t id) ui_sb_update_icon_state(SB_ZIP | id, 0); } - // media_menu_update_zip(id); +#if 0 + media_menu_update_zip(id); +#endif ui_sb_update_tip(SB_ZIP | id); config_save(); diff --git a/src/unix/unix_sdl.c b/src/unix/unix_sdl.c index bc89c9290..4cf723b00 100644 --- a/src/unix/unix_sdl.c +++ b/src/unix/unix_sdl.c @@ -23,18 +23,27 @@ #define RENDERER_OPENGL 4 typedef struct sdl_blit_params { - int x, y, w, h; + int x; + int y; + int w; + int h; } sdl_blit_params; extern sdl_blit_params params; extern int blitreq; -SDL_Window *sdl_win = NULL; -SDL_Renderer *sdl_render = NULL; -static SDL_Texture *sdl_tex = NULL; -int sdl_w = SCREEN_RES_X, sdl_h = SCREEN_RES_Y; -static int sdl_fs, sdl_flags = -1; -static int cur_w, cur_h; -static int cur_wx = 0, cur_wy = 0, cur_ww = 0, cur_wh = 0; +SDL_Window *sdl_win = NULL; +SDL_Renderer *sdl_render = NULL; +static SDL_Texture *sdl_tex = NULL; +int sdl_w = SCREEN_RES_X; +int sdl_h = SCREEN_RES_Y; +static int sdl_fs; +static int sdl_flags = -1; +static int cur_w; +static int cur_h; +static int cur_wx = 0; +static int cur_wy = 0; +static int cur_ww = 0; +static int cur_wh = 0; static volatile int sdl_enabled = 1; static SDL_mutex *sdl_mutex = NULL; int mouse_capture; @@ -43,7 +52,8 @@ int resize_pending = 0; int resize_w = 0; int resize_h = 0; double mouse_sensitivity = 1.0; /* Unused. */ -double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */ +double mouse_x_error = 0.0; /* Unused. */ +double mouse_y_error = 0.0; /* Unused. */ static uint8_t interpixels[17842176]; extern void RenderImGui(void); @@ -66,8 +76,18 @@ void sdl_reinit_texture(void); static void sdl_stretch(int *w, int *h, int *x, int *y) { - double hw, gw, hh, gh, dx, dy, dw, dh, gsr, hsr; - int real_sdl_w, real_sdl_h; + double hw; + double gw; + double hh; + double gh; + double dx; + double dy; + double dw; + double dh; + double gsr; + double hsr; + int real_sdl_w; + int real_sdl_h; SDL_GL_GetDrawableSize(sdl_win, &real_sdl_w, &real_sdl_h); @@ -147,7 +167,9 @@ void sdl_real_blit(SDL_Rect *r_src) { SDL_Rect r_dst; - int ret, winx, winy; + int ret; + int winx; + int winy; SDL_GL_GetDrawableSize(sdl_win, &winx, &winy); SDL_RenderClear(sdl_render); @@ -273,10 +295,9 @@ sdl_enable(int enable) static void sdl_select_best_hw_driver(void) { - int i; SDL_RendererInfo renderInfo; - for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) { + for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i) { SDL_GetRenderDriverInfo(i, &renderInfo); if (renderInfo.flags & SDL_RENDERER_ACCELERATED) { SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name); @@ -321,7 +342,10 @@ sdl_set_fs(int fs) void sdl_resize(int x, int y) { - int ww = 0, wh = 0, wx = 0, wy = 0; + int ww = 0; + int wh = 0; + int wx = 0; + int wy = 0; if (video_fullscreen & 2) return; @@ -436,7 +460,7 @@ sdl_initho(void) int sdl_pause(void) { - return (0); + return 0; } void diff --git a/src/unix/unix_serial_passthrough.c b/src/unix/unix_serial_passthrough.c index 13c695e83..61f23c345 100644 --- a/src/unix/unix_serial_passthrough.c +++ b/src/unix/unix_serial_passthrough.c @@ -21,6 +21,9 @@ # define _DEFAULT_SOURCE 1 # define _BSD_SOURCE 1 #endif +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +# define __BSD_VISIBLE 1 +#endif #include #include #include @@ -87,20 +90,22 @@ plat_serpt_close(void *p) static void plat_serpt_write_vcon(serial_passthrough_t *dev, uint8_t data) { - /* fd_set wrfds; - * int res; - */ +#if 0 + fd_set wrfds; + int res; +#endif /* We cannot use select here, this would block the hypervisor! */ - /* FD_ZERO(&wrfds); - FD_SET(ctx->master_fd, &wrfds); +#if 0 + FD_ZERO(&wrfds); + FD_SET(ctx->master_fd, &wrfds); - res = select(ctx->master_fd + 1, NULL, &wrfds, NULL, NULL); + res = select(ctx->master_fd + 1, NULL, &wrfds, NULL, NULL); - if (res <= 0) { - return; - } - */ + if (res <= 0) { + return; + } +#endif /* just write it out */ if (dev->mode == SERPT_MODE_HOSTSER) { @@ -163,7 +168,7 @@ plat_serpt_set_params(void *p) term_attr.c_cflag &= CSTOPB; if (dev->serial->lcr & 0x04) term_attr.c_cflag |= CSTOPB; -#ifdef __APPLE__ +#if !defined(__linux__) term_attr.c_cflag &= PARENB | PARODD; #else term_attr.c_cflag &= PARENB | PARODD | CMSPAR; @@ -172,7 +177,7 @@ plat_serpt_set_params(void *p) term_attr.c_cflag |= PARENB; if (!(dev->serial->lcr & 0x10)) term_attr.c_cflag |= PARODD; -#ifndef __APPLE__ +#if defined(__linux__) if ((dev->serial->lcr & 0x20)) term_attr.c_cflag |= CMSPAR; #endif diff --git a/src/unix/unix_thread.c b/src/unix/unix_thread.c index 268545719..0c2e9bf6b 100644 --- a/src/unix/unix_thread.c +++ b/src/unix/unix_thread.c @@ -133,7 +133,7 @@ int thread_wait_mutex(mutex_t *_mutex) { if (_mutex == NULL) - return (0); + return 0; pt_mutex_t *mutex = (pt_mutex_t *) _mutex; return pthread_mutex_lock(&mutex->mutex) != 0; @@ -143,7 +143,7 @@ int thread_test_mutex(mutex_t *_mutex) { if (_mutex == NULL) - return (0); + return 0; pt_mutex_t *mutex = (pt_mutex_t *) _mutex; return pthread_mutex_trylock(&mutex->mutex) != 0; @@ -153,7 +153,7 @@ int thread_release_mutex(mutex_t *_mutex) { if (_mutex == NULL) - return (0); + return 0; pt_mutex_t *mutex = (pt_mutex_t *) _mutex; return pthread_mutex_unlock(&mutex->mutex) != 0; diff --git a/src/upi42.c b/src/upi42.c index 6937644ad..8348b32e4 100644 --- a/src/upi42.c +++ b/src/upi42.c @@ -18,6 +18,7 @@ #include #include #include +#include <86box/plat_unused.h> #ifdef UPI42_STANDALONE # define fatal(...) \ @@ -160,7 +161,7 @@ upi42_op_MOV_A_imm(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_MOV_A_PSW(upi42_t *upi42, uint32_t fetchdat) +upi42_op_MOV_A_PSW(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = upi42->psw; upi42_mirror_f0(upi42); @@ -168,7 +169,7 @@ upi42_op_MOV_A_PSW(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_MOV_PSW_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_MOV_PSW_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->psw = upi42->a; upi42_mirror_f0(upi42); @@ -176,28 +177,28 @@ upi42_op_MOV_PSW_A(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_MOV_A_T(upi42_t *upi42, uint32_t fetchdat) +upi42_op_MOV_A_T(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = upi42->t; return 1; } static int -upi42_op_MOV_T_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_MOV_T_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->t = upi42->a; return 1; } static int -upi42_op_MOV_STS_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_MOV_STS_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->sts = (upi42->a & 0xf0) | (upi42->sts & 0x0f); return 1; } static int -upi42_op_MOVP_A_indA(upi42_t *upi42, uint32_t fetchdat) +upi42_op_MOVP_A_indA(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = upi42->rom[(upi42->pc & 0xff00) | upi42->a]; upi42->cycs--; @@ -205,7 +206,7 @@ upi42_op_MOVP_A_indA(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_MOVP3_A_indA(upi42_t *upi42, uint32_t fetchdat) +upi42_op_MOVP3_A_indA(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = upi42->rom[0x300 | upi42->a]; upi42->cycs--; @@ -224,7 +225,8 @@ upi42_op_XCH_A_Rr(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_XCH_A_indRr(upi42_t *upi42, uint32_t fetchdat) { - uint8_t temp = upi42->a, addr = upi42->ram[fetchdat & 1] & upi42->rammask; + uint8_t temp = upi42->a; + uint8_t addr = upi42->ram[fetchdat & 1] & upi42->rammask; upi42->a = upi42->ram[addr]; upi42->ram[addr] = temp; return 1; @@ -233,14 +235,15 @@ upi42_op_XCH_A_indRr(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_XCHD_A_indRr(upi42_t *upi42, uint32_t fetchdat) { - uint8_t temp = upi42->a, addr = upi42->ram[fetchdat & 1] & upi42->rammask; + uint8_t temp = upi42->a; + uint8_t addr = upi42->ram[fetchdat & 1] & upi42->rammask; upi42->a = (upi42->a & 0xf0) | (upi42->ram[addr] & 0x0f); upi42->ram[addr] = (upi42->ram[addr] & 0xf0) | (temp & 0x0f); return 1; } static int -upi42_op_SWAP_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_SWAP_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = (upi42->a << 4) | (upi42->a >> 4); return 1; @@ -256,7 +259,7 @@ upi42_op_IN_A_Pp(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_IN_A_DBB(upi42_t *upi42, uint32_t fetchdat) +upi42_op_IN_A_DBB(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = upi42->dbb_in; upi42->sts &= ~0x02; /* clear IBF */ @@ -264,7 +267,7 @@ upi42_op_IN_A_DBB(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_OUTL_Pp_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_OUTL_Pp_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->ports_out[fetchdat & 3] = upi42->a; upi42->cycs--; @@ -272,7 +275,7 @@ upi42_op_OUTL_Pp_A(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_OUT_DBB_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_OUT_DBB_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->dbb_out = upi42->a; upi42->sts |= 0x01; /* set OBF */ @@ -395,21 +398,21 @@ upi42_op_ORLD_Pp_A(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_RR_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_RR_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = (upi42->a << 7) | (upi42->a >> 1); return 1; } static int -upi42_op_RL_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_RL_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = (upi42->a >> 7) | (upi42->a << 1); return 1; } static int -upi42_op_RRC_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_RRC_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { uint8_t temp = upi42->a; upi42->a = (upi42->psw & 0x80) | (temp >> 1); @@ -418,7 +421,7 @@ upi42_op_RRC_A(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_RLC_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_RLC_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { uint8_t temp = upi42->a; upi42->a = (temp << 1) | (upi42->psw >> 7); @@ -427,7 +430,7 @@ upi42_op_RLC_A(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_INC_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_INC_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a++; return 1; @@ -448,7 +451,7 @@ upi42_op_INC_indRr(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_DEC_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_DEC_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a--; return 1; @@ -531,21 +534,21 @@ upi42_op_ADDC_A_imm(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_CLR_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CLR_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = 0; return 1; } static int -upi42_op_CPL_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CPL_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->a = ~upi42->a; return 1; } static int -upi42_op_DA_A(upi42_t *upi42, uint32_t fetchdat) +upi42_op_DA_A(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { if (((upi42->a & 0x0f) > 9) || (upi42->psw & 0x40)) upi42->a += 6; @@ -558,21 +561,21 @@ upi42_op_DA_A(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_CLR_C(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CLR_C(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->psw &= ~0x80; return 1; } static int -upi42_op_CPL_C(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CPL_C(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->psw ^= 0x80; return 1; } static int -upi42_op_CLR_F0(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CLR_F0(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->psw &= ~0x20; upi42_mirror_f0(upi42); @@ -580,7 +583,7 @@ upi42_op_CLR_F0(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_CPL_F0(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CPL_F0(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->psw ^= 0x20; upi42_mirror_f0(upi42); @@ -588,21 +591,21 @@ upi42_op_CPL_F0(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_CLR_F1(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CLR_F1(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->sts &= ~0x08; return 1; } static int -upi42_op_CPL_F1(upi42_t *upi42, uint32_t fetchdat) +upi42_op_CPL_F1(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->sts ^= 0x08; return 1; } static int -upi42_op_EN_I(upi42_t *upi42, uint32_t fetchdat) +upi42_op_EN_I(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->i = 1; upi42->skip_timer_inc = 1; @@ -610,7 +613,7 @@ upi42_op_EN_I(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_DIS_I(upi42_t *upi42, uint32_t fetchdat) +upi42_op_DIS_I(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->i = 0; upi42->skip_timer_inc = 1; @@ -618,21 +621,21 @@ upi42_op_DIS_I(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_EN_TCNTI(upi42_t *upi42, uint32_t fetchdat) +upi42_op_EN_TCNTI(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->tcnti = 1; return 1; } static int -upi42_op_DIS_TCNTI(upi42_t *upi42, uint32_t fetchdat) +upi42_op_DIS_TCNTI(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->tcnti = upi42->tcnti_raise = 0; return 1; } static int -upi42_op_STRT_T(upi42_t *upi42, uint32_t fetchdat) +upi42_op_STRT_T(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->run_timer = 1; upi42->prescaler = 0; @@ -641,7 +644,7 @@ upi42_op_STRT_T(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_STRT_CNT(upi42_t *upi42, uint32_t fetchdat) +upi42_op_STRT_CNT(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->run_counter = 1; upi42->skip_timer_inc = 1; @@ -649,7 +652,7 @@ upi42_op_STRT_CNT(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_STOP_TCNT(upi42_t *upi42, uint32_t fetchdat) +upi42_op_STOP_TCNT(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->run_timer = upi42->run_counter = 0; upi42->skip_timer_inc = 1; @@ -657,35 +660,35 @@ upi42_op_STOP_TCNT(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_SEL_PMB0(upi42_t *upi42, uint32_t fetchdat) +upi42_op_SEL_PMB0(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->dbf = 0; return 1; } static int -upi42_op_SEL_PMB1(upi42_t *upi42, uint32_t fetchdat) +upi42_op_SEL_PMB1(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->dbf = 1; return 1; } static int -upi42_op_SEL_RB0(upi42_t *upi42, uint32_t fetchdat) +upi42_op_SEL_RB0(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->psw &= ~0x10; return 1; } static int -upi42_op_SEL_RB1(upi42_t *upi42, uint32_t fetchdat) +upi42_op_SEL_RB1(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->psw |= 0x10; return 1; } static int -upi42_op_NOP(upi42_t *upi42, uint32_t fetchdat) +upi42_op_NOP(UNUSED(upi42_t *upi42), UNUSED(uint32_t fetchdat)) { return 1; } @@ -739,7 +742,7 @@ upi42_op_JMP_imm(upi42_t *upi42, uint32_t fetchdat) } static int -upi42_op_JMPP_indA(upi42_t *upi42, uint32_t fetchdat) +upi42_op_JMPP_indA(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->pc = (upi42->pc & 0xff00) | upi42->a; upi42->cycs--; @@ -772,27 +775,27 @@ UPI42_COND_JMP_IMM(JNIBF, !(upi42->sts & 0x02), ) UPI42_COND_JMP_IMM(JOBF, upi42->sts & 0x01, ) static int -upi42_op_EN_A20(upi42_t *upi42, uint32_t fetchdat) +upi42_op_EN_A20(UNUSED(upi42_t *upi42), UNUSED(uint32_t fetchdat)) { /* Enable fast A20 until reset. */ return 1; } static int -upi42_op_EN_DMA(upi42_t *upi42, uint32_t fetchdat) +upi42_op_EN_DMA(UNUSED(upi42_t *upi42), UNUSED(uint32_t fetchdat)) { return 1; } static int -upi42_op_EN_FLAGS(upi42_t *upi42, uint32_t fetchdat) +upi42_op_EN_FLAGS(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { upi42->flags = 1; return 1; } static int -upi42_op_SUSPEND(upi42_t *upi42, uint32_t fetchdatr) +upi42_op_SUSPEND(upi42_t *upi42, UNUSED(uint32_t fetchdat)) { /* Inhibit execution until reset. */ upi42->suspend = 1; @@ -921,6 +924,8 @@ upi42_port_read(void *priv, int port) /* Apply special meanings. */ switch (port) { + default: + break; } upi42_log("UPI42: port_read(%d) = %02X\n", port, ret); @@ -942,7 +947,7 @@ upi42_port_write(void *priv, int port, uint8_t val) /* NOTE: The dbb/sts/cmd functions use I/O handler signatures; port is ignored. */ uint8_t -upi42_dbb_read(uint16_t port, void *priv) +upi42_dbb_read(UNUSED(uint16_t port), void *priv) { upi42_t *upi42 = (upi42_t *) priv; @@ -953,7 +958,7 @@ upi42_dbb_read(uint16_t port, void *priv) } void -upi42_dbb_write(uint16_t port, uint8_t val, void *priv) +upi42_dbb_write(UNUSED(uint16_t port), uint8_t val, void *priv) { upi42_t *upi42 = (upi42_t *) priv; @@ -965,9 +970,9 @@ upi42_dbb_write(uint16_t port, uint8_t val, void *priv) } uint8_t -upi42_sts_read(uint16_t port, void *priv) +upi42_sts_read(UNUSED(uint16_t port), void *priv) { - upi42_t *upi42 = (upi42_t *) priv; + const upi42_t *upi42 = (upi42_t *) priv; uint8_t ret = upi42->sts; upi42_log("UPI42: sts_read(%04X) = %02X\n", port, ret); @@ -975,7 +980,7 @@ upi42_sts_read(uint16_t port, void *priv) } void -upi42_cmd_write(uint16_t port, uint8_t val, void *priv) +upi42_cmd_write(UNUSED(uint16_t port), uint8_t val, void *priv) { upi42_t *upi42 = (upi42_t *) priv; @@ -1003,7 +1008,7 @@ upi42_reset(upi42_t *upi42) void upi42_do_init(upi32_t type, uint8_t *rom) { - memset(upi42, 0, sizeof(upi42_t)); + memset(upi42, 0x00, sizeof(upi42_t)); upi42->rom = rom; /* Set chip type. */ @@ -1022,7 +1027,7 @@ upi42_do_init(upi32_t type, uint8_t *rom) upi42->ops[0xe2] = NULL; /* SUSPEND */ } - memset(upi42_t->ports_in, 0xff, 0x08); + memset(upi42_t->ports_in, 0xff, sizeof(upi42_t->ports_in)); upi42_t->t0 = 1; upi42_t->t1 = 1; } @@ -1172,7 +1177,8 @@ static void upi42_write(uint16_t port, uint8_t val, void *priv) { upi42_t *upi42 = (upi42_t *) priv; - uint32_t temp_type, uint8_t *temp_rom; + uint32_t temp_type; + uint8_t *temp_rom; int i; switch (port) { diff --git a/src/usb.c b/src/usb.c index 75e60d438..0ed98fc12 100644 --- a/src/usb.c +++ b/src/usb.c @@ -20,14 +20,18 @@ #include #include #include +#include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> #include <86box/mem.h> +#include <86box/timer.h> #include <86box/usb.h> -#include "cpu.h" +#include <86box/dma.h> +#include <86box/plat_unused.h> #ifdef ENABLE_USB_LOG int usb_do_log = ENABLE_USB_LOG; @@ -47,11 +51,104 @@ usb_log(const char *fmt, ...) # define usb_log(fmt, ...) #endif -static uint8_t -uhci_reg_read(uint16_t addr, void *p) +/* OHCI registers */ +enum { + OHCI_HcRevision = 0x00 /* 0x00 */, + OHCI_HcControl = 0x01 /* 0x04 */, + OHCI_HcCommandStatus = 0x02 /* 0x08 */, + OHCI_HcInterruptStatus = 0x03 /* 0x0c */, + OHCI_HcInterruptEnable = 0x04 /* 0x10 */, + OHCI_HcInterruptDisable = 0x05 /* 0x14 */, + OHCI_HcHCCA = 0x06 /* 0x18 */, + OHCI_HcPeriodCurrentED = 0x07 /* 0x1c */, + OHCI_HcControlHeadED = 0x08 /* 0x20 */, + OHCI_HcControlCurrentED = 0x09 /* 0x24 */, + OHCI_HcBulkHeadED = 0x0a /* 0x28 */, + OHCI_HcBulkCurrentED = 0x0b /* 0x2c */, + OHCI_HcDoneHead = 0x0c /* 0x30 */, + OHCI_HcFmInterval = 0x0d /* 0x34 */, + OHCI_HcFmRemaining = 0x0e /* 0x38 */, + OHCI_HcFmNumber = 0x0f /* 0x3c */, + OHCI_HcPeriodicStart = 0x10 /* 0x40 */, + OHCI_HcLSThreshold = 0x11 /* 0x44 */, + OHCI_HcRhDescriptorA = 0x12 /* 0x48 */, + OHCI_HcRhDescriptorB = 0x13 /* 0x4c */, + OHCI_HcRhStatus = 0x14 /* 0x50 */, + OHCI_HcRhPortStatus1 = 0x15 /* 0x54 */, + OHCI_HcRhPortStatus2 = 0x16 /* 0x58 */, + OHCI_HcRhPortStatus3 = 0x17 /* 0x5c */ +}; + +enum { + OHCI_aHcRevision = 0x00, + OHCI_aHcControl = 0x04, + OHCI_aHcCommandStatus = 0x08, + OHCI_aHcInterruptStatus = 0x0c, + OHCI_aHcInterruptEnable = 0x10, + OHCI_aHcInterruptDisable = 0x14, + OHCI_aHcHCCA = 0x18, + OHCI_aHcPeriodCurrentED = 0x1c, + OHCI_aHcControlHeadED = 0x20, + OHCI_aHcControlCurrentED = 0x24, + OHCI_aHcBulkHeadED = 0x28, + OHCI_aHcBulkCurrentED = 0x2c, + OHCI_aHcDoneHead = 0x30, + OHCI_aHcFmInterval = 0x34, + OHCI_aHcFmRemaining = 0x38, + OHCI_aHcFmNumber = 0x3c, + OHCI_aHcPeriodicStart = 0x40, + OHCI_aHcLSThreshold = 0x44, + OHCI_aHcRhDescriptorA = 0x48, + OHCI_aHcRhDescriptorB = 0x4c, + OHCI_aHcRhStatus = 0x50, + OHCI_aHcRhPortStatus1 = 0x54, + OHCI_aHcRhPortStatus2 = 0x58, + OHCI_aHcRhPortStatus3 = 0x5c +}; + +/* OHCI HcInterruptEnable/Disable bits */ +enum { + OHCI_HcInterruptEnable_SO = 1 << 0, + OHCI_HcInterruptEnable_WDH = 1 << 1, + OHCI_HcInterruptEnable_SF = 1 << 2, + OHCI_HcInterruptEnable_RD = 1 << 3, + OHCI_HcInterruptEnable_UE = 1 << 4, + OHCI_HcInterruptEnable_HNO = 1 << 5, + OHCI_HcInterruptEnable_RHSC = 1 << 6, +}; + +/* OHCI HcControl bits */ +enum { + OHCI_HcControl_ControlBulkServiceRatio = 1 << 0, + OHCI_HcControl_PeriodicListEnable = 1 << 1, + OHCI_HcControl_IsochronousEnable = 1 << 2, + OHCI_HcControl_ControlListEnable = 1 << 3, + OHCI_HcControl_BulkListEnable = 1 << 4 +}; + +usb_t* usb_device_inst = NULL; + +static void +usb_interrupt_ohci(usb_t *dev, uint32_t level) { - usb_t *dev = (usb_t *) p; - uint8_t ret, *regs = dev->uhci_io; + if (dev->ohci_mmio[OHCI_HcControl].b[1] & 1) { + if (dev->usb_params && dev->usb_params->smi_handle && !dev->usb_params->smi_handle(dev, dev->usb_params->parent_priv)) + return; + + if (level) + smi_raise(); + } else if (dev->usb_params != NULL) { + if ((dev->usb_params->parent_priv != NULL) && (dev->usb_params->update_interrupt != NULL)) + dev->usb_params->update_interrupt(dev, dev->usb_params->parent_priv); + } +} + +static uint8_t +uhci_reg_read(uint16_t addr, void *priv) +{ + const usb_t *dev = (usb_t *) priv; + uint8_t ret; + const uint8_t *regs = dev->uhci_io; addr &= 0x0000001f; @@ -61,9 +158,9 @@ uhci_reg_read(uint16_t addr, void *p) } static void -uhci_reg_write(uint16_t addr, uint8_t val, void *p) +uhci_reg_write(uint16_t addr, uint8_t val, void *priv) { - usb_t *dev = (usb_t *) p; + usb_t *dev = (usb_t *) priv; uint8_t *regs = dev->uhci_io; addr &= 0x0000001f; @@ -85,13 +182,16 @@ uhci_reg_write(uint16_t addr, uint8_t val, void *p) case 0x0c: regs[0x0c] = (val & 0x7f); break; + + default: + break; } } static void -uhci_reg_writew(uint16_t addr, uint16_t val, void *p) +uhci_reg_writew(uint16_t addr, uint16_t val, void *priv) { - usb_t *dev = (usb_t *) p; + usb_t *dev = (usb_t *) priv; uint16_t *regs = (uint16_t *) dev->uhci_io; addr &= 0x0000001f; @@ -112,8 +212,8 @@ uhci_reg_writew(uint16_t addr, uint16_t val, void *p) regs[addr >> 1] = ((regs[addr >> 1] & 0xedbb) | (val & 0x1244)) & ~(val & 0x080a); break; default: - uhci_reg_write(addr, val & 0xff, p); - uhci_reg_write(addr + 1, (val >> 8) & 0xff, p); + uhci_reg_write(addr, val & 0xff, priv); + uhci_reg_write(addr + 1, (val >> 8) & 0xff, priv); break; } } @@ -131,218 +231,724 @@ uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable) io_sethandler(dev->uhci_io_base, 0x20, uhci_reg_read, NULL, NULL, uhci_reg_write, uhci_reg_writew, NULL, dev); } -static uint8_t -ohci_mmio_read(uint32_t addr, void *p) +typedef struct { - usb_t *dev = (usb_t *) p; - uint8_t ret = 0x00; + uint32_t HccaInterrruptTable[32]; + uint16_t HccaFrameNumber; + uint16_t HccaPad1; + uint32_t HccaDoneHead; +} usb_hcca_t; + +/* Transfer descriptors */ +typedef struct +{ + uint32_t Control; + uint32_t CBP; + uint32_t NextTD; + uint32_t BE; +} usb_td_t; + +/* Endpoint descriptors */ +typedef struct +{ + uint32_t Control; + uint32_t TailP; + uint32_t HeadP; + uint32_t NextED; +} usb_ed_t; + +#define ENDPOINT_DESC_LIMIT 32 + +static uint8_t +ohci_mmio_read(uint32_t addr, void *priv) +{ + const usb_t *dev = (usb_t *) priv; + uint8_t ret = 0x00; +#ifdef ENABLE_USB_LOG + uint32_t old_addr = addr; +#endif addr &= 0x00000fff; - ret = dev->ohci_mmio[addr]; + ret = dev->ohci_mmio[addr >> 2].b[addr & 3]; + + switch (addr) { + case 0x101: + ret = (ret & 0xfe) | (!!mem_a20_key); + break; + case OHCI_aHcRhPortStatus1 + 1: + case OHCI_aHcRhPortStatus2 + 1: + case OHCI_aHcRhPortStatus3 + 1: + ret |= 0x1; + break; + case OHCI_aHcInterruptDisable: + case OHCI_aHcInterruptDisable + 1: + case OHCI_aHcInterruptDisable + 2: + case OHCI_aHcInterruptDisable + 3: + ret = dev->ohci_mmio[OHCI_HcInterruptEnable].b[addr & 3]; + default: + break; + } if (addr == 0x101) ret = (ret & 0xfe) | (!!mem_a20_key); +#ifdef ENABLE_USB_LOG + usb_log("[R] %08X = %04X\n", old_addr, ret); +#endif + return ret; } -static void -ohci_mmio_write(uint32_t addr, uint8_t val, void *p) +static uint16_t +ohci_mmio_readw(uint32_t addr, void *priv) { - usb_t *dev = (usb_t *) p; + return ohci_mmio_read(addr, priv) | (ohci_mmio_read(addr + 1, priv) << 8); +} + +static uint32_t +ohci_mmio_readl(uint32_t addr, void *priv) +{ + return ohci_mmio_readw(addr, priv) | (ohci_mmio_readw(addr + 2, priv) << 16); +} + +static void +ohci_update_irq(usb_t *dev) +{ + uint32_t level = !!(dev->ohci_mmio[OHCI_HcInterruptStatus].l & dev->ohci_mmio[OHCI_HcInterruptEnable].l); + + if (level != dev->irq_level) { + dev->irq_level = level; + usb_interrupt_ohci(dev, level); + } +} + +void +ohci_set_interrupt(usb_t *dev, uint8_t bit) +{ + if (!(dev->ohci_mmio[OHCI_HcInterruptEnable].b[3] & 0x80)) + return; + + if (!(dev->ohci_mmio[OHCI_HcInterruptEnable].b[0] & bit)) + return; + + if (dev->ohci_mmio[OHCI_HcInterruptDisable].b[0] & bit) + return; + + dev->ohci_mmio[OHCI_HcInterruptStatus].b[0] |= bit; + + /* TODO: Does setting UnrecoverableError also assert PERR# on any emulated USB chipsets? */ + + ohci_update_irq(dev); +} + +/* TODO: Actually use this function somewhere. */ +#if 0 +/* Next two functions ported over from QEMU. */ +static int ohci_copy_td_input(usb_t* dev, usb_td_t *td, + uint8_t *buf, int len) +{ + uint32_t ptr; + uint32_t n; + + ptr = td->CBP; + n = 0x1000 - (ptr & 0xfff); + if (n > len) { + n = len; + } + dma_bm_write(ptr, buf, n, 1); + if (n == len) { + return 0; + } + ptr = td->BE & ~0xfffu; + buf += n; + dma_bm_write(ptr, buf, len - n, 1); + return 0; +} +#endif + +static int ohci_copy_td_output(UNUSED(usb_t* dev), usb_td_t *td, + uint8_t *buf, int len) +{ + uint32_t ptr; + uint32_t n; + + ptr = td->CBP; + n = 0x1000 - (ptr & 0xfff); + if (n > len) { + n = len; + } + dma_bm_read(ptr, buf, n, 1); + if (n == len) { + return 0; + } + ptr = td->BE & ~0xfffu; + buf += n; + dma_bm_read(ptr, buf, len - n, 1); + return 0; +} + +#define OHCI_TD_DIR(val) ((val >> 19) & 3) +#define OHCI_ED_DIR(val) ((val >> 11) & 3) + +uint8_t +ohci_service_transfer_desc(usb_t* dev, usb_ed_t* endpoint_desc) +{ + uint32_t td_addr = endpoint_desc->HeadP & ~0xf; + usb_td_t td; + uint8_t dir; + uint8_t pid_token = 255; + uint32_t len = 0; + uint32_t pktlen = 0; + uint32_t actual_length = 0; + uint32_t i = 0; + uint8_t device_result = 0; + usb_device_t* target = NULL; + + dma_bm_read(td_addr, (uint8_t*)&td, sizeof(usb_td_t), 4); + + switch (dir = OHCI_ED_DIR(endpoint_desc->Control)) { + case 1: + case 2: + break; + default: + dir = OHCI_TD_DIR(td.Control); + break; + } + + switch (dir) { + case 0: /* Setup */ + pid_token = USB_PID_SETUP; + break; + case 1: /* OUT */ + pid_token = USB_PID_OUT; + break; + case 2: /* IN */ + pid_token = USB_PID_IN; + break; + default: + return 1; + } + + if (td.CBP && td.BE) { + if ((td.CBP & 0xfffff000) != (td.BE & 0xfffff000)) { + len = (td.BE & 0xfff) + 0x1001 - (td.CBP & 0xfff); + } else { + if (td.CBP > td.BE) { + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_UE); + return 1; + } + + len = (td.BE - td.CBP) + 1; + } + if (len > sizeof(dev->ohci_usb_buf)) { + len = sizeof(dev->ohci_usb_buf); + } + + pktlen = len; + if (len && pid_token != USB_PID_IN) { + pktlen = (endpoint_desc->Control >> 16) & 0xFFF; + if (pktlen > len) { + pktlen = len; + } + ohci_copy_td_output(dev, &td, dev->ohci_usb_buf, pktlen); + } + } + + for (i = 0; i < 2; i++) { + if (!dev->ohci_devices[i]) + continue; + + assert(dev->ohci_devices[i]->device_get_address != NULL); + + if (dev->ohci_devices[i]->device_get_address(dev->ohci_devices[i]->priv) != (endpoint_desc->Control & 0x7f)) + continue; + + target = dev->ohci_devices[i]; + break; + } + + if (!target) + return 1; + + device_result = target->device_process(target->priv, dev->ohci_usb_buf, &actual_length, pid_token, (endpoint_desc->Control & 0x780) >> 7, !(endpoint_desc->Control & (1 << 18))); + + if ((actual_length == pktlen) || (pid_token == USB_PID_IN && (endpoint_desc->Control & (1 << 18)) && device_result == USB_ERROR_NO_ERROR)) { + if (len == actual_length) { + td.CBP = 0; + } else { + if ((td.CBP & 0xfff) + actual_length > 0xfff) { + td.CBP = (td.BE & ~0xfff) + ((td.CBP + actual_length) & 0xfff); + } else { + td.CBP += actual_length; + } + } + + td.Control |= (1 << 25); /* dataToggle[1] */ + td.Control ^= (1 << 24); /* dataToggle[0] */ + td.Control &= ~0xFC000000; /* Set both ErrorCount and ConditionCode to 0. */ + + if (pid_token != USB_PID_IN && len != actual_length) { + goto exit_no_retire; + } + + endpoint_desc->HeadP &= ~0x2; + if (td.Control & (1 << 24)) { + endpoint_desc->HeadP |= 0x2; + } + } else { + if (actual_length != 0xFFFFFFFF && actual_length >= 0) { + td.Control &= ~0xF0000000; + td.Control |= 0x90000000; + } else { + switch (device_result) { + case USB_ERROR_NAK: + return 1; + + default: + break; + } + dev->ohci_interrupt_counter = 0; + } + + endpoint_desc->HeadP |= 0x1; + } + + endpoint_desc->HeadP &= 0xf; + endpoint_desc->HeadP |= td.NextTD & ~0xf; + td.NextTD = dev->ohci_mmio[OHCI_HcDoneHead].l; + dev->ohci_mmio[OHCI_HcDoneHead].l = td_addr; + i = (td.Control >> 21) & 7; + if (i < dev->ohci_interrupt_counter) { + dev->ohci_interrupt_counter = i; + } +exit_no_retire: + dma_bm_write(td_addr, (uint8_t*)&td, sizeof(usb_td_t), 4); + return !(td.Control & 0xF0000000); +} + +uint8_t +ohci_service_endpoint_desc(usb_t* dev, uint32_t head) +{ + usb_ed_t endpoint_desc; + uint8_t active = 0; + uint32_t next = 0; + uint32_t limit_counter = 0; + + if (head == 0) + return 0; + + for (uint32_t cur = head; cur && limit_counter++ < ENDPOINT_DESC_LIMIT; cur = next) { + dma_bm_read(cur, (uint8_t*)&endpoint_desc, sizeof(usb_ed_t), 4); + + next = endpoint_desc.NextED & ~0xFu; + + if ((endpoint_desc.Control & (1 << 13)) || (endpoint_desc.HeadP & (1 << 0))) + continue; + + if (endpoint_desc.Control & 0x8000) { + fatal("OHCI: Isochronous transfers not implemented!\n"); + } + + active = 1; + + while ((endpoint_desc.HeadP & ~0xFu) != endpoint_desc.TailP) { + ohci_service_transfer_desc(dev, &endpoint_desc); + } + + dma_bm_write(cur, (uint8_t*)&endpoint_desc, sizeof(usb_ed_t), 4); + } + + return active; +} + +void +ohci_end_of_frame(usb_t* dev) +{ + usb_hcca_t hcca; + if (dev->ohci_initial_start) + return; + dma_bm_read(dev->ohci_mmio[OHCI_HcHCCA].l, (uint8_t*)&hcca, sizeof(usb_hcca_t), 4); + + if (dev->ohci_mmio[OHCI_HcControl].l & OHCI_HcControl_PeriodicListEnable) { + ohci_service_endpoint_desc(dev, hcca.HccaInterrruptTable[dev->ohci_mmio[OHCI_HcFmNumber].l & 0x1f]); + } + + if ((dev->ohci_mmio[OHCI_HcControl].l & OHCI_HcControl_ControlListEnable) + && (dev->ohci_mmio[OHCI_HcCommandStatus].l & 0x2)) { + uint8_t result = ohci_service_endpoint_desc(dev, dev->ohci_mmio[OHCI_HcControlHeadED].l); + if (!result) { + dev->ohci_mmio[OHCI_HcControlHeadED].l = 0; + dev->ohci_mmio[OHCI_HcCommandStatus].l &= ~0x2; + } + } + + if ((dev->ohci_mmio[OHCI_HcControl].l & OHCI_HcControl_BulkListEnable) + && (dev->ohci_mmio[OHCI_HcCommandStatus].l & 0x4)) { + uint8_t result = ohci_service_endpoint_desc(dev, dev->ohci_mmio[OHCI_HcBulkHeadED].l); + if (!result) { + dev->ohci_mmio[OHCI_HcBulkHeadED].l = 0; + dev->ohci_mmio[OHCI_HcCommandStatus].l &= ~0x4; + } + } + + if (dev->ohci_interrupt_counter == 0 && !(dev->ohci_mmio[OHCI_HcInterruptStatus].l & OHCI_HcInterruptEnable_WDH)) { + if (dev->ohci_mmio[OHCI_HcDoneHead].l == 0) { + fatal("OHCI: HcDoneHead is still NULL!"); + } + + if (dev->ohci_mmio[OHCI_HcInterruptStatus].l & dev->ohci_mmio[OHCI_HcInterruptEnable].l) { + dev->ohci_mmio[OHCI_HcDoneHead].l |= 1; + } + + hcca.HccaDoneHead = dev->ohci_mmio[OHCI_HcDoneHead].l; + dev->ohci_mmio[OHCI_HcDoneHead].l = 0; + dev->ohci_interrupt_counter = 7; + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_WDH); + } + + if (dev->ohci_interrupt_counter != 0 && dev->ohci_interrupt_counter != 7) { + dev->ohci_interrupt_counter--; + } + + dev->ohci_mmio[OHCI_HcFmNumber].w[0]++; + hcca.HccaFrameNumber = dev->ohci_mmio[OHCI_HcFmNumber].w[0]; + + dma_bm_write(dev->ohci_mmio[OHCI_HcHCCA].l, (uint8_t*)&hcca, sizeof(usb_hcca_t), 4); +} + +void +ohci_start_of_frame(usb_t* dev) +{ + dev->ohci_initial_start = 0; + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_SO); +} + +void +ohci_update_frame_counter(void* priv) +{ + usb_t *dev = (usb_t *) priv; + + dev->ohci_mmio[OHCI_HcFmRemaining].w[0] &= 0x3fff; + if (dev->ohci_mmio[OHCI_HcFmRemaining].w[0] == 0) { + ohci_end_of_frame(dev); + dev->ohci_mmio[OHCI_HcFmRemaining].w[0] = dev->ohci_mmio[OHCI_HcFmInterval].w[0] & 0x3fff; + dev->ohci_mmio[OHCI_HcFmRemaining].l &= ~(1 << 31); + dev->ohci_mmio[OHCI_HcFmRemaining].l |= dev->ohci_mmio[OHCI_HcFmInterval].l & (1 << 31); + ohci_start_of_frame(dev); + timer_on_auto(&dev->ohci_frame_timer, 1. / 12.); + return; + } + dev->ohci_mmio[OHCI_HcFmRemaining].w[0]--; + timer_on_auto(&dev->ohci_frame_timer, 1. / 12.); +} + +void +ohci_port_reset_callback(void* priv) +{ + usb_t *dev = (usb_t *) priv; + + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[0] &= ~0x10; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] |= 0x10; +} + +void +ohci_port_reset_callback_2(void* priv) +{ + usb_t *dev = (usb_t *) priv; + + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[0] &= ~0x10; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] |= 0x10; +} + +static void +ohci_soft_reset(usb_t* dev) +{ + uint32_t old_HcControl = (dev->ohci_mmio[OHCI_HcControl].l & 0x100) | 0xc0; + memset(dev->ohci_mmio, 0x00, 4096); + dev->ohci_mmio[OHCI_HcRevision].b[0] = 0x10; + dev->ohci_mmio[OHCI_HcRevision].b[1] = 0x01; + dev->ohci_mmio[OHCI_HcRhDescriptorA].b[0] = 0x02; + dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] = 0x02; + dev->ohci_mmio[OHCI_HcFmInterval].l = 0x27782edf; /* FrameInterval = 11999, FSLargestDataPacket = 10104 */ + dev->ohci_mmio[OHCI_HcLSThreshold].l = 0x628; + dev->ohci_mmio[OHCI_HcInterruptEnable].l |= (1 << 31); + dev->ohci_mmio[OHCI_HcControl].l = old_HcControl; + dev->ohci_interrupt_counter = 7; + ohci_update_irq(dev); +} + +static void +ohci_mmio_write(uint32_t addr, uint8_t val, void *priv) +{ + usb_t *dev = (usb_t *) priv; uint8_t old; +#ifdef ENABLE_USB_LOG + usb_log("[W] %08X = %04X\n", addr, val); +#endif + addr &= 0x00000fff; switch (addr) { - case 0x04: + case OHCI_aHcControl: + old = dev->ohci_mmio[OHCI_HcControl].b[0]; +#ifdef ENABLE_USB_LOG + usb_log("OHCI: OHCI state 0x%X\n", (val & 0xc0)); +#endif if ((val & 0xc0) == 0x00) { /* UsbReset */ - dev->ohci_mmio[0x56] = dev->ohci_mmio[0x5a] = 0x16; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] = dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] = 0x16; + for (int i = 0; i < 2; i++) { + if (dev->ohci_devices[i]) { + dev->ohci_devices[i]->device_reset(dev->ohci_devices[i]->priv); + } + } + } else if ((val & 0xc0) == 0x80 && (old & 0xc0) != (val & 0xc0)) { + dev->ohci_mmio[OHCI_HcFmRemaining].l = 0; + dev->ohci_initial_start = 1; + timer_on_auto(&dev->ohci_frame_timer, 1000.); } break; - case 0x08: /* HCCOMMANDSTATUS */ + case OHCI_aHcCommandStatus: /* bit OwnershipChangeRequest triggers an ownership change (SMM <-> OS) */ if (val & 0x08) { - dev->ohci_mmio[0x0f] = 0x40; - if ((dev->ohci_mmio[0x13] & 0xc0) == 0xc0) + dev->ohci_mmio[OHCI_HcInterruptStatus].b[3] = 0x40; + if ((dev->ohci_mmio[OHCI_HcInterruptEnable].b[3] & 0x40) == 0x40) { smi_raise(); + } } /* bit HostControllerReset must be cleared for the controller to be seen as initialized */ if (val & 0x01) { - memset(dev->ohci_mmio, 0x00, 4096); - dev->ohci_mmio[0x00] = 0x10; - dev->ohci_mmio[0x01] = 0x01; - dev->ohci_mmio[0x48] = 0x02; + ohci_soft_reset(dev); + val &= ~0x01; } break; - case 0x0c: - dev->ohci_mmio[addr] &= ~(val & 0x7f); + case OHCI_aHcHCCA: return; - case 0x0d: - case 0x0e: + case OHCI_aHcInterruptEnable: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x7f); + dev->ohci_mmio[OHCI_HcInterruptDisable].b[0] &= ~(val & 0x7f); + ohci_update_irq(dev); return; - case 0x0f: - dev->ohci_mmio[addr] &= ~(val & 0x40); + case OHCI_aHcInterruptEnable + 1: + case OHCI_aHcInterruptEnable + 2: return; - case 0x3b: - dev->ohci_mmio[addr] = (val & 0x80); + case OHCI_aHcInterruptEnable + 3: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0xc0); + dev->ohci_mmio[OHCI_HcInterruptDisable].b[3] &= ~(val & 0xc0); + ohci_update_irq(dev); return; - case 0x39: - case 0x41: - dev->ohci_mmio[addr] = (val & 0x3f); + case OHCI_aHcInterruptDisable: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x7f); + dev->ohci_mmio[OHCI_HcInterruptEnable].b[0] &= ~(val & 0x7f); + ohci_update_irq(dev); return; - case 0x45: - dev->ohci_mmio[addr] = (val & 0x0f); + case OHCI_aHcInterruptDisable + 1: + case OHCI_aHcInterruptDisable + 2: return; - case 0x3a: - case 0x3e: - case 0x3f: - case 0x42: - case 0x43: - case 0x46: - case 0x47: - case 0x48: - case 0x4a: + case OHCI_aHcInterruptDisable + 3: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0xc0); + dev->ohci_mmio[OHCI_HcInterruptEnable].b[3] &= ~(val & 0xc0); + ohci_update_irq(dev); return; - case 0x49: - dev->ohci_mmio[addr] = (val & 0x1b); + case OHCI_aHcInterruptStatus: + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~(val & 0x7f); + return; + case OHCI_aHcInterruptStatus + 1: + case OHCI_aHcInterruptStatus + 2: + return; + case OHCI_aHcInterruptStatus + 3: + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~(val & 0x40); + return; + case OHCI_aHcFmRemaining + 3: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x80); + return; + case OHCI_aHcFmRemaining + 1: + case OHCI_aHcPeriodicStart + 1: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x3f); + return; + case OHCI_aHcLSThreshold + 1: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x0f); + return; + case OHCI_aHcFmRemaining + 2: + case OHCI_aHcFmNumber + 2: + case OHCI_aHcFmNumber + 3: + case OHCI_aHcPeriodicStart + 2: + case OHCI_aHcPeriodicStart + 3: + case OHCI_aHcLSThreshold + 2: + case OHCI_aHcLSThreshold + 3: + case OHCI_aHcRhDescriptorA: + case OHCI_aHcRhDescriptorA + 2: + return; + case OHCI_aHcRhDescriptorA + 1: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x1b); if (val & 0x02) { - dev->ohci_mmio[0x55] |= 0x01; - dev->ohci_mmio[0x59] |= 0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[1] |= 0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[1] |= 0x01; } return; - case 0x4b: - dev->ohci_mmio[addr] = (val & 0x03); + case OHCI_aHcRhDescriptorA + 3: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x03); return; - case 0x4c: - case 0x4e: - dev->ohci_mmio[addr] = (val & 0x06); - if ((addr == 0x4c) && !(val & 0x04)) { - if (!(dev->ohci_mmio[0x58] & 0x01)) - dev->ohci_mmio[0x5a] |= 0x01; - dev->ohci_mmio[0x58] |= 0x01; + case OHCI_aHcRhDescriptorB: + case OHCI_aHcRhDescriptorB + 2: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0x06); + if ((addr == OHCI_HcRhDescriptorB) && !(val & 0x04)) { + if (!(dev->ohci_mmio[OHCI_HcRhPortStatus2].b[0] & 0x01)) + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] |= 0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[0] |= 0x01; } - if ((addr == 0x4c) && !(val & 0x02)) { - if (!(dev->ohci_mmio[0x54] & 0x01)) - dev->ohci_mmio[0x56] |= 0x01; - dev->ohci_mmio[0x54] |= 0x01; + if ((addr == OHCI_HcRhDescriptorB) && !(val & 0x02)) { + if (!(dev->ohci_mmio[OHCI_HcRhPortStatus1].b[0] & 0x01)) + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] |= 0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[0] |= 0x01; } return; - case 0x4d: - case 0x4f: + case OHCI_aHcRhDescriptorB + 1: + case OHCI_aHcRhDescriptorB + 3: return; - case 0x50: + case OHCI_aHcRhStatus: if (val & 0x01) { - if ((dev->ohci_mmio[0x49] & 0x03) == 0x00) { - dev->ohci_mmio[0x55] &= ~0x01; - dev->ohci_mmio[0x54] &= ~0x17; - dev->ohci_mmio[0x56] &= ~0x17; - dev->ohci_mmio[0x59] &= ~0x01; - dev->ohci_mmio[0x58] &= ~0x17; - dev->ohci_mmio[0x5a] &= ~0x17; - } else if ((dev->ohci_mmio[0x49] & 0x03) == 0x01) { - if (!(dev->ohci_mmio[0x4e] & 0x02)) { - dev->ohci_mmio[0x55] &= ~0x01; - dev->ohci_mmio[0x54] &= ~0x17; - dev->ohci_mmio[0x56] &= ~0x17; + if ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x00) { + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[1] &= ~0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[0] &= ~0x17; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] &= ~0x17; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[1] &= ~0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[0] &= ~0x17; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] &= ~0x17; + } else if ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x01) { + if (!(dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x02)) { + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[1] &= ~0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[0] &= ~0x17; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] &= ~0x17; } - if (!(dev->ohci_mmio[0x4e] & 0x04)) { - dev->ohci_mmio[0x59] &= ~0x01; - dev->ohci_mmio[0x58] &= ~0x17; - dev->ohci_mmio[0x5a] &= ~0x17; + if (!(dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x04)) { + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[1] &= ~0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[0] &= ~0x17; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] &= ~0x17; } } } return; - case 0x51: + case OHCI_aHcRhStatus + 1: if (val & 0x80) - dev->ohci_mmio[addr] |= 0x80; + dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x80; return; - case 0x52: - dev->ohci_mmio[addr] &= ~(val & 0x02); + case OHCI_aHcRhStatus + 2: + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~(val & 0x02); if (val & 0x01) { - if ((dev->ohci_mmio[0x49] & 0x03) == 0x00) { - dev->ohci_mmio[0x55] |= 0x01; - dev->ohci_mmio[0x59] |= 0x01; - } else if ((dev->ohci_mmio[0x49] & 0x03) == 0x01) { - if (!(dev->ohci_mmio[0x4e] & 0x02)) - dev->ohci_mmio[0x55] |= 0x01; - if (!(dev->ohci_mmio[0x4e] & 0x04)) - dev->ohci_mmio[0x59] |= 0x01; + if ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x00) { + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[1] |= 0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[1] |= 0x01; + } else if ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x01) { + if (!(dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x02)) + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[1] |= 0x01; + if (!(dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x04)) + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[1] |= 0x01; } } return; - case 0x53: + case OHCI_aHcRhStatus + 3: if (val & 0x80) - dev->ohci_mmio[0x51] &= ~0x80; + dev->ohci_mmio[OHCI_HcRhStatus].b[1] &= ~0x80; return; - case 0x54: - case 0x58: - old = dev->ohci_mmio[addr]; + case OHCI_aHcRhPortStatus1: + case OHCI_aHcRhPortStatus2: + old = dev->ohci_mmio[addr >> 2].b[addr & 3]; if (val & 0x10) { if (old & 0x01) { - dev->ohci_mmio[addr] |= 0x10; - /* TODO: The clear should be on a 10 ms timer. */ - dev->ohci_mmio[addr] &= ~0x10; - dev->ohci_mmio[addr + 2] |= 0x10; + dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x10; + timer_on_auto(&dev->ohci_port_reset_timer[(addr - OHCI_aHcRhPortStatus1) / 4], 10000.); + if (dev->ohci_devices[(addr - OHCI_aHcRhPortStatus1) >> 2]) + dev->ohci_devices[(addr - OHCI_aHcRhPortStatus1) >> 2]->device_reset(dev->ohci_devices[(addr - OHCI_aHcRhPortStatus1) >> 2]->priv); } else - dev->ohci_mmio[addr + 2] |= 0x01; + dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x01; } if (val & 0x08) - dev->ohci_mmio[addr] &= ~0x04; - if (val & 0x04) - dev->ohci_mmio[addr] |= 0x04; + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~0x04; + if (val & 0x04) { + if (old & 0x01) + dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x04; + else + dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x01; + } if (val & 0x02) { if (old & 0x01) - dev->ohci_mmio[addr] |= 0x02; + dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x02; else - dev->ohci_mmio[addr + 2] |= 0x01; + dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x01; } if (val & 0x01) { if (old & 0x01) - dev->ohci_mmio[addr] &= ~0x02; + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~0x02; else - dev->ohci_mmio[addr + 2] |= 0x01; + dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x01; } - if (!(dev->ohci_mmio[addr] & 0x04) && (old & 0x04)) - dev->ohci_mmio[addr + 2] |= 0x04; - /* if (!(dev->ohci_mmio[addr] & 0x02)) - dev->ohci_mmio[addr + 2] |= 0x02; */ + if (!(dev->ohci_mmio[addr >> 2].b[addr & 3] & 0x04) && (old & 0x04)) + dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x04; +#if 0 + if (!(dev->ohci_mmio[addr >> 2].b[addr & 3] & 0x02)) + dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x02; +#endif return; - case 0x55: - if ((val & 0x02) && ((dev->ohci_mmio[0x49] & 0x03) == 0x00) && (dev->ohci_mmio[0x4e] & 0x02)) { - dev->ohci_mmio[addr] &= ~0x01; - dev->ohci_mmio[0x54] &= ~0x17; - dev->ohci_mmio[0x56] &= ~0x17; + case OHCI_aHcRhPortStatus1 + 1: + if ((val & 0x02) && ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x00) && (dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x02)) { + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[0] &= ~0x17; + dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] &= ~0x17; } - if ((val & 0x01) && ((dev->ohci_mmio[0x49] & 0x03) == 0x00) && (dev->ohci_mmio[0x4e] & 0x02)) { - dev->ohci_mmio[addr] |= 0x01; - dev->ohci_mmio[0x58] &= ~0x17; - dev->ohci_mmio[0x5a] &= ~0x17; + if ((val & 0x01) && ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x00) && (dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x02)) { + dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x01; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[0] &= ~0x17; + dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] &= ~0x17; } return; - case 0x59: - if ((val & 0x02) && ((dev->ohci_mmio[0x49] & 0x03) == 0x00) && (dev->ohci_mmio[0x4e] & 0x04)) - dev->ohci_mmio[addr] &= ~0x01; - if ((val & 0x01) && ((dev->ohci_mmio[0x49] & 0x03) == 0x00) && (dev->ohci_mmio[0x4e] & 0x04)) - dev->ohci_mmio[addr] |= 0x01; + case OHCI_aHcRhPortStatus2 + 1: + if ((val & 0x02) && ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x00) && (dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x04)) + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~0x01; + if ((val & 0x01) && ((dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] & 0x03) == 0x00) && (dev->ohci_mmio[OHCI_HcRhDescriptorB].b[2] & 0x04)) + dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x01; return; - case 0x56: - case 0x5a: - dev->ohci_mmio[addr] &= ~(val & 0x1f); + case OHCI_aHcRhPortStatus1 + 2: + case OHCI_aHcRhPortStatus2 + 2: + dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~(val & 0x1f); return; - case 0x57: - case 0x5b: + case OHCI_aHcRhPortStatus1 + 3: + case OHCI_aHcRhPortStatus2 + 3: return; + case OHCI_aHcDoneHead: + case OHCI_aHcBulkCurrentED: + case OHCI_aHcBulkHeadED: + case OHCI_aHcControlCurrentED: + case OHCI_aHcControlHeadED: + case OHCI_aHcPeriodCurrentED: + dev->ohci_mmio[addr >> 2].b[addr & 3] = (val & 0xf0); + return; + + default: + break; } - dev->ohci_mmio[addr] = val; + dev->ohci_mmio[addr >> 2].b[addr & 3] = val; +} + +static void +ohci_mmio_writew(uint32_t addr, uint16_t val, void *priv) +{ + ohci_mmio_write(addr, val & 0xff, priv); + ohci_mmio_write(addr + 1, val >> 8, priv); +} + +static void +ohci_mmio_writel(uint32_t addr, uint32_t val, void *priv) +{ + ohci_mmio_writew(addr, val & 0xffff, priv); + ohci_mmio_writew(addr + 2, val >> 16, priv); } void @@ -356,6 +962,71 @@ ohci_update_mem_mapping(usb_t *dev, uint8_t base1, uint8_t base2, uint8_t base3, if (dev->ohci_enable && (dev->ohci_mem_base != 0x00000000)) mem_mapping_set_addr(&dev->ohci_mmio_mapping, dev->ohci_mem_base, 0x1000); + + usb_log("ohci_update_mem_mapping(): OHCI %sabled at %08X\n", dev->ohci_enable ? "en" : "dis", dev->ohci_mem_base); +} + +uint8_t +usb_attach_device(usb_t *dev, usb_device_t* device, uint8_t bus_type) +{ + switch (bus_type) { + case USB_BUS_OHCI: + { + for (uint8_t i = 0; i < 2; i++) { + if (!dev->ohci_devices[i]) { + uint32_t old = dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l; + dev->ohci_devices[i] = device; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] |= 0x1; + if ((dev->ohci_mmio[OHCI_HcControl].b[0] & 0xc0) == 0xc0) { + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RD); + } + if (old != dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x1; + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); + } + return i; + } + } + } + break; + + default: + break; + } + return 0xff; +} + +void +usb_detach_device(usb_t *dev, uint8_t port, uint8_t bus_type) +{ + switch (bus_type) { + case USB_BUS_OHCI: + { + if (port > 2) + return; + if (dev->ohci_devices[port]) { + uint32_t old = dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].l; + dev->ohci_devices[port] = NULL; + if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] & 0x1) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] &= ~0x1; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[2] |= 0x1; + } + if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] & 0x2) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] &= ~0x2; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[2] |= 0x2; + } + if (old != dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].l) + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); + return; + } + + } + break; + + default: + break; + } + return; } static void @@ -363,20 +1034,21 @@ usb_reset(void *priv) { usb_t *dev = (usb_t *) priv; - memset(dev->uhci_io, 0x00, 128); + memset(dev->uhci_io, 0x00, sizeof(dev->uhci_io)); dev->uhci_io[0x0c] = 0x40; dev->uhci_io[0x10] = dev->uhci_io[0x12] = 0x80; - memset(dev->ohci_mmio, 0x00, 4096); - dev->ohci_mmio[0x00] = 0x10; - dev->ohci_mmio[0x01] = 0x01; - dev->ohci_mmio[0x48] = 0x02; + ohci_soft_reset(dev); + dev->ohci_mmio[OHCI_HcControl].l = 0x00; io_removehandler(dev->uhci_io_base, 0x20, uhci_reg_read, NULL, NULL, uhci_reg_write, uhci_reg_writew, NULL, dev); dev->uhci_enable = 0; mem_mapping_disable(&dev->ohci_mmio_mapping); dev->ohci_enable = 0; + + usb_log("usb_reset(): OHCI %sabled at %08X\n", dev->ohci_enable ? "en" : "dis", dev->ohci_mem_base); + usb_log("usb_reset(): map = %08X\n", &dev->ohci_mmio_mapping); } static void @@ -388,39 +1060,40 @@ usb_close(void *priv) } static void * -usb_init(const device_t *info) +usb_init_ext(UNUSED(const device_t *info), void *params) { usb_t *dev; - dev = (usb_t *) malloc(sizeof(usb_t)); + dev = (usb_t *) calloc(1, sizeof(usb_t)); if (dev == NULL) return (NULL); - memset(dev, 0x00, sizeof(usb_t)); - memset(dev->uhci_io, 0x00, 128); - dev->uhci_io[0x0c] = 0x40; - dev->uhci_io[0x10] = dev->uhci_io[0x12] = 0x80; + dev->usb_params = (usb_params_t *) params; - memset(dev->ohci_mmio, 0x00, 4096); - dev->ohci_mmio[0x00] = 0x10; - dev->ohci_mmio[0x01] = 0x01; - dev->ohci_mmio[0x48] = 0x02; - - mem_mapping_add(&dev->ohci_mmio_mapping, 0, 0, - ohci_mmio_read, NULL, NULL, - ohci_mmio_write, NULL, NULL, + mem_mapping_add(&dev->ohci_mmio_mapping, 0, 0x1000, + ohci_mmio_read, ohci_mmio_readw, ohci_mmio_readl, + ohci_mmio_write, ohci_mmio_writew, ohci_mmio_writel, NULL, MEM_MAPPING_EXTERNAL, dev); + + mem_mapping_disable(&dev->ohci_mmio_mapping); + + timer_add(&dev->ohci_frame_timer, ohci_update_frame_counter, dev, 0); /* Unused for now, to be used for frame counting. */ + timer_add(&dev->ohci_port_reset_timer[0], ohci_port_reset_callback, dev, 0); + timer_add(&dev->ohci_port_reset_timer[1], ohci_port_reset_callback_2, dev, 0); + usb_reset(dev); + usb_device_inst = dev; + return dev; } const device_t usb_device = { .name = "Universal Serial Bus", .internal_name = "usb", - .flags = DEVICE_PCI, + .flags = DEVICE_PCI | DEVICE_EXTPARAMS, .local = 0, - .init = usb_init, + .init_ext = usb_init_ext, .close = usb_close, .reset = usb_reset, { .available = NULL }, diff --git a/src/video/CMakeLists.txt b/src/video/CMakeLists.txt index b37e81134..3d3d2d466 100644 --- a/src/video/CMakeLists.txt +++ b/src/video/CMakeLists.txt @@ -18,7 +18,7 @@ add_library(vid OBJECT agpgart.c video.c vid_table.c vid_cga.c vid_cga_comp.c vid_incolor.c vid_colorplus.c vid_genius.c vid_pgc.c vid_im1024.c vid_sigma.c vid_wy700.c vid_ega.c vid_ega_render.c vid_svga.c vid_8514a.c vid_svga_render.c vid_ddc.c vid_vga.c vid_ati_eeprom.c vid_ati18800.c - vid_ati28800.c vid_ati_mach64.c vid_ati68860_ramdac.c vid_bt48x_ramdac.c + vid_ati28800.c vid_ati_mach8.c vid_ati_mach64.c vid_ati68860_ramdac.c vid_bt48x_ramdac.c vid_av9194.c vid_icd2061.c vid_ics2494.c vid_ics2595.c vid_cl54xx.c vid_et3000.c vid_et4000.c vid_sc1148x_ramdac.c vid_sc1502x_ramdac.c vid_et4000w32.c vid_stg_ramdac.c vid_ht216.c vid_oak_oti.c vid_paradise.c diff --git a/src/video/agpgart.c b/src/video/agpgart.c index 523fcc996..b8ae2bdc8 100644 --- a/src/video/agpgart.c +++ b/src/video/agpgart.c @@ -24,6 +24,7 @@ #include <86box/device.h> #include <86box/mem.h> #include <86box/agpgart.h> +#include <86box/plat_unused.h> #ifdef ENABLE_AGPGART_LOG int agpgart_do_log = ENABLE_AGPGART_LOG; @@ -129,7 +130,7 @@ agpgart_aperture_writel(uint32_t addr, uint32_t val, void *priv) } static void * -agpgart_init(const device_t *info) +agpgart_init(UNUSED(const device_t *info)) { agpgart_t *dev = malloc(sizeof(agpgart_t)); memset(dev, 0, sizeof(agpgart_t)); diff --git a/src/video/vid_8514a.c b/src/video/vid_8514a.c index f7f3ce607..b4719a539 100644 --- a/src/video/vid_8514a.c +++ b/src/video/vid_8514a.c @@ -7,13 +7,13 @@ * This file is part of the 86Box distribution. * * Emulation of the 8514/A card from IBM for the MCA bus and - * generic ISA bus clones without vendor extensions. + * ISA bus clones. * * * * Authors: TheCollector1995. * - * Copyright 2022 TheCollector1995. + * Copyright 2022-2023 TheCollector1995. */ #include #include @@ -21,6 +21,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> @@ -37,26 +38,58 @@ #include <86box/vid_svga_render.h> #include "cpu.h" -static void ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len); -static void ibm8514_accel_outb(uint16_t port, uint8_t val, void *p); -static void ibm8514_accel_outw(uint16_t port, uint16_t val, void *p); -static uint8_t ibm8514_accel_inb(uint16_t port, void *p); -static uint16_t ibm8514_accel_inw(uint16_t port, void *p); +static void ibm8514_accel_outb(uint16_t port, uint8_t val, void *priv); +static void ibm8514_accel_outw(uint16_t port, uint16_t val, void *priv); +static uint8_t ibm8514_accel_inb(uint16_t port, void *priv); +static uint16_t ibm8514_accel_inw(uint16_t port, void *priv); -static void ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, ibm8514_t *dev, uint8_t ssv, int len); -static void ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, ibm8514_t *dev, int len); +#ifdef ENABLE_IBM8514_LOG +int ibm8514_do_log = ENABLE_IBM8514_LOG; + +static void +ibm8514_log(const char *fmt, ...) +{ + va_list ap; + + if (ibm8514_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define ibm8514_log(fmt, ...) +#endif #define READ_PIXTRANS_WORD(cx, n) \ - if (cmd <= 1 || (cmd == 5)) { \ - temp = dev->vram[((dev->accel.cy * dev->h_disp) + (cx) + (n)) & dev->vram_mask]; \ - temp |= (dev->vram[((dev->accel.cy * dev->h_disp) + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + if ((cmd <= 1) || (cmd == 5)) { \ + if (dev->local) { \ + temp = svga->vram[((dev->accel.cy * dev->pitch) + (cx) + (n)) & svga->vram_mask]; \ + temp |= (svga->vram[((dev->accel.cy * dev->pitch) + (cx) + (n + 1)) & svga->vram_mask] << 8); \ + } else { \ + temp = dev->vram[((dev->accel.cy * dev->pitch) + (cx) + (n)) & dev->vram_mask]; \ + temp |= (dev->vram[((dev->accel.cy * dev->pitch) + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + } \ } else { \ - temp = dev->vram[(dev->accel.dest + (cx) + (n)) & dev->vram_mask]; \ - temp |= (dev->vram[(dev->accel.dest + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + if (dev->local) { \ + temp = svga->vram[(dev->accel.dest + (cx) + (n)) & svga->vram_mask]; \ + temp |= (svga->vram[(dev->accel.dest + (cx) + (n + 1)) & svga->vram_mask] << 8); \ + } else { \ + temp = dev->vram[(dev->accel.dest + (cx) + (n)) & dev->vram_mask]; \ + temp |= (dev->vram[(dev->accel.dest + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + } \ } #define READ(addr, dat) \ - dat = dev->vram[(addr) & (dev->vram_mask)]; + if (dev->local) { \ + if ((svga->bpp == 15) || (svga->bpp == 16)) { \ + dat = vram_w[(addr) & (svga->vram_mask >> 1)]; \ + } else { \ + dat = (svga->vram[(addr) & (svga->vram_mask)]); \ + } \ + } else { \ + dat = (dev->vram[(addr) & (dev->vram_mask)]); \ + } #define MIX(mixmode, dest_dat, src_dat) \ { \ @@ -161,12 +194,26 @@ static void ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint } #define WRITE(addr, dat) \ - dev->vram[((addr)) & (dev->vram_mask)] = dat; \ - dev->changedvram[(((addr)) & (dev->vram_mask)) >> 12] = changeframecount; + if (dev->local) { \ + if ((svga->bpp == 15) || (svga->bpp == 16)) { \ + vram_w[((addr)) & (svga->vram_mask >> 1)] = dat; \ + svga->changedvram[(((addr)) & (svga->vram_mask >> 1)) >> 11] = changeframecount; \ + } else { \ + svga->vram[((addr)) & (svga->vram_mask)] = dat; \ + svga->changedvram[(((addr)) & (svga->vram_mask)) >> 12] = changeframecount; \ + } \ + } else { \ + dev->vram[((addr)) & (dev->vram_mask)] = dat; \ + dev->changedvram[(((addr)) & (dev->vram_mask)) >> 12] = changeframecount; \ + } -static int -ibm8514_cpu_src(ibm8514_t *dev) +int ibm8514_has_vga = 0; + +int +ibm8514_cpu_src(svga_t *svga) { + const ibm8514_t *dev = &svga->dev8514; + if (!(dev->accel.cmd & 0x100)) return 0; @@ -176,9 +223,11 @@ ibm8514_cpu_src(ibm8514_t *dev) return 0; } -static int -ibm8514_cpu_dest(ibm8514_t *dev) +int +ibm8514_cpu_dest(svga_t *svga) { + const ibm8514_t *dev = &svga->dev8514; + if (!(dev->accel.cmd & 0x100)) return 0; @@ -188,17 +237,19 @@ ibm8514_cpu_dest(ibm8514_t *dev) return 1; } -static void -ibm8514_accel_out_pixtrans(ibm8514_t *dev, uint16_t port, uint16_t val, int len) +void +ibm8514_accel_out_pixtrans(svga_t *svga, UNUSED(uint16_t port), uint16_t val, int len) { - uint8_t nibble = 0; - uint32_t pixelxfer = 0, monoxfer = 0xffffffff; - int pixcnt = 0; - int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; - int frgd_mix = (dev->accel.frgd_mix >> 5) & 3; - int bkgd_mix = (dev->accel.bkgd_mix >> 5) & 3; - int cmd = dev->accel.cmd >> 13; - int and3 = dev->accel.cur_x & 3; + ibm8514_t *dev = &svga->dev8514; + uint8_t nibble = 0; + uint32_t pixelxfer = 0; + uint32_t monoxfer = 0xffffffff; + int pixcnt = 0; + int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; + int frgd_mix = (dev->accel.frgd_mix >> 5) & 3; + int bkgd_mix = (dev->accel.bkgd_mix >> 5) & 3; + int cmd = dev->accel.cmd >> 13; + int and3 = dev->accel.cur_x & 3; if (dev->accel.cmd & 0x100) { if (len != 1) { @@ -295,12 +346,12 @@ regular_nibble: nibble |= 0x01; } - if ((and3 == 0) || (dev->accel.cmd & 0x1000) || ((dev->accel.cmd & 8) && ibm8514_cpu_src(dev))) { - if ((dev->accel.cmd & 8) && ibm8514_cpu_src(dev)) { + if ((and3 == 0) || (dev->accel.cmd & 0x1000) || ((dev->accel.cmd & 8) && ibm8514_cpu_src(svga))) { + if ((dev->accel.cmd & 8) && ibm8514_cpu_src(svga)) { monoxfer = val; } else monoxfer = nibble; - ibm8514_accel_start(pixcnt, 1, monoxfer, pixelxfer, dev, len); + ibm8514_accel_start(pixcnt, 1, monoxfer, pixelxfer, svga, len); if (dev->accel.nibbleset != NULL) { free(dev->accel.nibbleset); dev->accel.nibbleset = NULL; @@ -383,7 +434,7 @@ regular_nibble: for (int i = 0; i < dev->accel.x_count; i++) { dev->accel.writemono[i] &= ~dev->accel.nibbleset[i]; dev->accel.writemono[i] |= dev->accel.nibbleset[i + 1]; - ibm8514_accel_start(pixcnt, 1, dev->accel.writemono[i], pixelxfer, dev, len); + ibm8514_accel_start(pixcnt, 1, dev->accel.writemono[i], pixelxfer, svga, len); } dev->accel.x_count = 0; @@ -403,14 +454,16 @@ regular_nibble: } else { pixelxfer = val; } - ibm8514_accel_start(pixcnt, 1, monoxfer, pixelxfer, dev, len); + ibm8514_accel_start(pixcnt, 1, monoxfer, pixelxfer, svga, len); } } } static void -ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) +ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) { + ibm8514_t *dev = &svga->dev8514; + switch (port) { case 0x82e8: case 0xc2e8: @@ -483,6 +536,9 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) case 0x92e8: if (len != 1) dev->test = val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xd2e8: if (len == 1) dev->accel.err_term = (dev->accel.err_term & 0x3f00) | val; @@ -527,7 +583,7 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) dev->accel.cmd = val; if (dev->accel.cmd & 0x100) dev->accel.cmd_back = 0; - ibm8514_accel_start(-1, 0, -1, 0, dev, len); + ibm8514_accel_start(-1, 0, -1, 0, svga, len); } break; case 0x9ae9: @@ -540,7 +596,7 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) if (dev->accel.cmd & 0x100) dev->accel.cmd_back = 0; } - ibm8514_accel_start(-1, 0, -1, 0, dev, len); + ibm8514_accel_start(-1, 0, -1, 0, svga, len); } break; @@ -553,36 +609,39 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) dev->accel.short_stroke = val; dev->accel.cx = dev->accel.cur_x; dev->accel.cy = dev->accel.cur_y; - if (dev->accel.cur_x & 0x400) - dev->accel.cx |= ~0x3ff; - if (dev->accel.cur_y & 0x400) - dev->accel.cy |= ~0x3ff; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; + + if (dev->accel.cur_y >= 0x600) + dev->accel.cy |= ~0x5ff; + if (dev->accel.cmd & 0x1000) { - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke & 0xff, len); - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke >> 8, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); } else { - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke >> 8, len); - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke & 0xff, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); } } break; case 0x9ee9: case 0xdee9: + dev->accel.ssv_state = 1; if (len == 1) { dev->accel.short_stroke = (dev->accel.short_stroke & 0xff) | (val << 8); dev->accel.cx = dev->accel.cur_x; dev->accel.cy = dev->accel.cur_y; - if (dev->accel.cur_x & 0x400) - dev->accel.cx |= ~0x3ff; - if (dev->accel.cur_y & 0x400) - dev->accel.cy |= ~0x3ff; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; + if (dev->accel.cur_y >= 0x600) + dev->accel.cy |= ~0x5ff; if (dev->accel.cmd & 0x1000) { - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke & 0xff, len); - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke >> 8, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); } else { - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke >> 8, len); - ibm8514_short_stroke_start(-1, 0, -1, 0, dev, dev->accel.short_stroke & 0xff, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); } } break; @@ -596,9 +655,9 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) else dev->accel.bkgd_color = val; } else { - if (ibm8514_cpu_dest(dev)) + if (ibm8514_cpu_dest(svga)) break; - ibm8514_accel_out_pixtrans(dev, port, val, len); + ibm8514_accel_out_pixtrans(svga, port, val, len); } } else { if (len == 1) @@ -622,9 +681,9 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) else dev->accel.frgd_color = val; } else { - if (ibm8514_cpu_dest(dev)) + if (ibm8514_cpu_dest(svga)) break; - ibm8514_accel_out_pixtrans(dev, port, val, len); + ibm8514_accel_out_pixtrans(svga, port, val, len); } } else { if (len == 1) @@ -696,10 +755,14 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) dev->accel.multifunc_cntl = val; dev->accel.multifunc[dev->accel.multifunc_cntl >> 12] = dev->accel.multifunc_cntl & 0xfff; if ((dev->accel.multifunc_cntl >> 12) == 1) { - dev->accel.clip_top = val & 0x3ff; + dev->accel.clip_top = val & 0x7ff; + if (val & 0x400) + dev->accel.clip_top |= ~0x3ff; } if ((dev->accel.multifunc_cntl >> 12) == 2) { - dev->accel.clip_left = val & 0x3ff; + dev->accel.clip_left = val & 0x7ff; + if (val & 0x400) + dev->accel.clip_left |= ~0x3ff; } if (port == 0xfee8) dev->accel.cmd_back = 1; @@ -718,50 +781,27 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) dev->accel.cmd_back = 0; } break; - } -} -static void -ibm8514_ramdac_out(uint16_t port, uint8_t val, void *p) -{ - svga_t *svga = (svga_t *) p; - - switch (port) { - case 0x2ea: - svga_out(0x3c6, val, svga); - break; - case 0x2eb: - svga_out(0x3c7, val, svga); - break; - case 0x2ec: - svga_out(0x3c8, val, svga); - break; - case 0x2ed: - svga_out(0x3c9, val, svga); + default: break; } } -static uint8_t -ibm8514_ramdac_in(uint16_t port, void *p) +void +ibm8514_ramdac_out(uint16_t port, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; - uint8_t ret = 0xff; + svga_t *svga = (svga_t *) priv; - switch (port) { - case 0x2ea: - ret = svga_in(0x3c6, svga); - break; - case 0x2eb: - ret = svga_in(0x3c7, svga); - break; - case 0x2ec: - ret = svga_in(0x3c8, svga); - break; - case 0x2ed: - ret = svga_in(0x3c9, svga); - break; - } + svga_out(port, val, svga); +} + +uint8_t +ibm8514_ramdac_in(uint16_t port, void *priv) +{ + svga_t *svga = (svga_t *) priv; + uint8_t ret; + + ret = svga_in(port, svga); return ret; } @@ -827,7 +867,7 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) ibm8514_t *dev = &svga->dev8514; if (port & 0x8000) { - ibm8514_accel_out_fifo(dev, port, val, len); + ibm8514_accel_out_fifo(svga, port, val, len); } else { switch (port) { case 0x2e8: @@ -841,24 +881,24 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) case 0x2e9: if (len != 1) { dev->htotal = (dev->htotal & 0xff) | (val << 8); - // pclog("IBM 8514/A: H_TOTAL write 02E8 = %d\n", dev->htotal + 1); + ibm8514_log("IBM 8514/A: H_TOTAL write 02E8 = %d\n", dev->htotal + 1); svga_recalctimings(svga); } break; case 0x6e8: dev->hdisp = val; - // pclog("IBM 8514/A: H_DISP write 06E8 = %d\n", dev->hdisp + 1); + ibm8514_log("IBM 8514/A: H_DISP write 06E8 = %d\n", dev->hdisp + 1); svga_recalctimings(svga); break; case 0xae8: - // pclog("IBM 8514/A: H_SYNC_STRT write 0AE8 = %d\n", val + 1); + ibm8514_log("IBM 8514/A: H_SYNC_STRT write 0AE8 = %d\n", val + 1); svga_recalctimings(svga); break; case 0xee8: - // pclog("IBM 8514/A: H_SYNC_WID write 0EE8 = %d\n", val + 1); + ibm8514_log("IBM 8514/A: H_SYNC_WID write 0EE8 = %d\n", val + 1); svga_recalctimings(svga); break; @@ -873,7 +913,7 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) case 0x12e9: if (len == 1) { dev->vtotal = (dev->vtotal & 0xff) | ((val & 0x1f) << 8); - // pclog("IBM 8514/A: V_TOTAL write 12E8 = %d\n", dev->vtotal); + ibm8514_log("IBM 8514/A: V_TOTAL write 12E8 = %d\n", dev->vtotal); svga_recalctimings(svga); } break; @@ -889,7 +929,7 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) case 0x16e9: if (len == 1) { dev->vdisp = (dev->vdisp & 0xff) | ((val & 0x1f) << 8); - // pclog("IBM 8514/A: V_DISP write 16E8 = %d\n", dev->vdisp); + ibm8514_log("IBM 8514/A: V_DISP write 16E8 = %d\n", dev->vdisp); svga_recalctimings(svga); } break; @@ -905,21 +945,21 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) case 0x1ae9: if (len == 1) { dev->vsyncstart = (dev->vsyncstart & 0xff) | ((val & 0x1f) << 8); - // pclog("IBM 8514/A: V_SYNC_STRT write 1AE8 = %d\n", dev->vsyncstart); + ibm8514_log("IBM 8514/A: V_SYNC_STRT write 1AE8 = %d\n", dev->vsyncstart); svga_recalctimings(svga); } break; case 0x1ee8: dev->vsyncwidth = val; - // pclog("IBM 8514/A: V_SYNC_WID write 1EE8 = %02x\n", val); + ibm8514_log("IBM 8514/A: V_SYNC_WID write 1EE8 = %02x\n", val); svga_recalctimings(svga); break; case 0x22e8: dev->disp_cntl = val & 0x7e; dev->interlace = !!(val & 0x10); - // pclog("IBM 8514/A: DISP_CNTL write 22E8 = %02x, SCANMODULOS = %d\n", dev->disp_cntl, dev->scanmodulos); + ibm8514_log("IBM 8514/A: DISP_CNTL write 22E8 = %02x, SCANMODULOS = %d\n", dev->disp_cntl, dev->scanmodulos); svga_recalctimings(svga); break; @@ -938,27 +978,32 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) break; case 0x4ae8: + if (!val) + break; dev->accel.advfunc_cntl = val & 7; - vga_on = ((dev->accel.advfunc_cntl & 1) == 0) ? 1 : 0; - ibm8514_on = !vga_on; - // pclog("IBM 8514/A: VGA ON = %i, val = %02x\n", vga_on, val); + ibm8514_on = (dev->accel.advfunc_cntl & 1); + vga_on = !ibm8514_on; + ibm8514_log("IBM 8514/A: VGA ON = %i, val = %02x\n", vga_on, val); svga_recalctimings(svga); break; + + default: + break; } } } static void -ibm8514_accel_outb(uint16_t port, uint8_t val, void *p) +ibm8514_accel_outb(uint16_t port, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; ibm8514_accel_out(port, val, svga, 1); } static void -ibm8514_accel_outw(uint16_t port, uint16_t val, void *p) +ibm8514_accel_outw(uint16_t port, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; ibm8514_accel_out(port, val, svga, 2); } @@ -968,8 +1013,22 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) ibm8514_t *dev = &svga->dev8514; uint32_t temp = 0; int cmd; + int vpos = dev->displine + svga->y_add; + int vblankend = svga->vblankstart + svga->crtc[0x16]; switch (port) { + case 0x2e8: + vpos = dev->displine + svga->y_add; + if (vblankend > dev->vtotal) { + vblankend -= dev->vtotal; + if (vpos >= svga->vblankstart || vpos <= vblankend) + temp |= 2; + } else { + if (vpos >= svga->vblankstart && vpos <= vblankend) + temp |= 2; + } + break; + case 0x6e8: temp = dev->hdisp; break; @@ -994,6 +1053,15 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) break; case 0x42e8: + vpos = dev->displine + svga->y_add; + if (vblankend > dev->vtotal) { + vblankend -= dev->vtotal; + if (vpos >= svga->vblankstart || vpos <= vblankend) + dev->subsys_stat |= 1; + } else { + if (vpos >= svga->vblankstart && vpos <= vblankend) + dev->subsys_stat |= 1; + } if (len != 1) { temp = dev->subsys_stat | 0xa0 | 0x8000; } else @@ -1013,7 +1081,6 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) case 0x9ae8: case 0xdae8: - temp = 0; if (len != 1) { if (dev->force_busy) temp |= 0x200; /*Hardware busy*/ @@ -1026,7 +1093,6 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) break; case 0x9ae9: case 0xdae9: - temp = 0; if (len == 1) { if (dev->force_busy2) temp |= 2; /*Hardware busy*/ @@ -1040,7 +1106,7 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) case 0xe2e8: case 0xe6e8: - if (ibm8514_cpu_dest(dev)) { + if (ibm8514_cpu_dest(svga)) { if (len == 1) { ; // READ_PIXTRANS_BYTE_IO(0) } else { @@ -1051,72 +1117,93 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) temp |= (dev->vram[(dev->accel.newdest_in + dev->accel.cur_x) & dev->vram_mask] << 8); } } - ibm8514_accel_out_pixtrans(dev, port, temp, len); + ibm8514_accel_out_pixtrans(svga, port, temp, len); } break; case 0xe2e9: case 0xe6e9: - if (ibm8514_cpu_dest(dev)) { + if (ibm8514_cpu_dest(svga)) { if (len == 1) { ; // READ_PIXTRANS_BYTE_IO(1) - ibm8514_accel_out_pixtrans(dev, port, temp, len); + ibm8514_accel_out_pixtrans(svga, port, temp, len); } } break; + + default: + break; } return temp; } static uint8_t -ibm8514_accel_inb(uint16_t port, void *p) +ibm8514_accel_inb(uint16_t port, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; + return ibm8514_accel_in(port, svga, 1); } static uint16_t -ibm8514_accel_inw(uint16_t port, void *p) +ibm8514_accel_inw(uint16_t port, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; + return ibm8514_accel_in(port, svga, 2); } -static void -ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, ibm8514_t *dev, uint8_t ssv, int len) +void +ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, uint8_t ssv, int len) { + ibm8514_t *dev = &svga->dev8514; + if (!cpu_input) { dev->accel.ssv_len = ssv & 0x0f; dev->accel.ssv_dir = ssv & 0xe0; dev->accel.ssv_draw = ssv & 0x10; - if (ibm8514_cpu_src(dev)) { + if (ibm8514_cpu_src(svga)) { return; /*Wait for data from CPU*/ } } - ibm8514_accel_start(count, cpu_input, mix_dat, cpu_dat, dev, len); + ibm8514_accel_start(count, cpu_input, mix_dat, cpu_dat, svga, len); } -static void -ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, ibm8514_t *dev, int len) +void +ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, UNUSED(int len)) { - uint8_t src_dat = 0, dest_dat, old_dest_dat; - int frgd_mix, bkgd_mix; - uint16_t clip_b = dev->accel.multifunc[3] & 0x7ff; - uint16_t clip_r = dev->accel.multifunc[4] & 0x7ff; - int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; - uint8_t mix_mask = 0x80; - uint8_t compare = dev->accel.color_cmp & 0xff; - int compare_mode = dev->accel.multifunc[0x0a] & 0x38; - int cmd = dev->accel.cmd >> 13; - uint8_t wrt_mask = dev->accel.wrt_mask & 0xff; - uint8_t rd_mask = ((dev->accel.rd_mask & 0x01) << 7) | ((dev->accel.rd_mask & 0xfe) >> 1); - uint8_t rd_mask_polygon = dev->accel.rd_mask & 0xff; - uint8_t frgd_color = dev->accel.frgd_color; - uint8_t bkgd_color = dev->accel.bkgd_color; - uint32_t old_mix_dat; - int and3 = dev->accel.cur_x & 3; - uint8_t poly_src = 0; + ibm8514_t *dev = &svga->dev8514; + uint16_t *vram_w = (uint16_t *) svga->vram; + uint16_t src_dat = 0; + uint16_t dest_dat; + uint16_t old_dest_dat; + int frgd_mix; + int bkgd_mix; + uint16_t clip_b = dev->accel.multifunc[3]; + uint16_t clip_r = dev->accel.multifunc[4]; + int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; + uint16_t mix_mask = ((svga->bpp == 8) || (svga->bpp == 24)) ? 0x80 : 0x8000; + uint16_t compare = dev->accel.color_cmp; + int compare_mode = dev->accel.multifunc[0x0a] & 0x38; + int cmd = dev->accel.cmd >> 13; + uint16_t wrt_mask = dev->accel.wrt_mask; + uint16_t rd_mask = dev->accel.rd_mask; + uint16_t rd_mask_polygon = dev->accel.rd_mask; + uint16_t frgd_color = dev->accel.frgd_color; + uint16_t bkgd_color = dev->accel.bkgd_color; + uint32_t old_mix_dat; + int and3 = dev->accel.cur_x & 3; + uint16_t poly_src = 0; + + if ((svga->bpp == 8) || (svga->bpp == 24)) { + compare &= 0xff; + frgd_color &= 0xff; + bkgd_color &= 0xff; + rd_mask = ((dev->accel.rd_mask & 0x01) << 7) | ((dev->accel.rd_mask & 0xfe) >> 1); + rd_mask &= 0xff; + rd_mask_polygon &= 0xff; + } if (dev->accel.cmd & 0x100) { dev->force_busy = 1; @@ -1139,81 +1226,86 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat } else { count >>= 3; } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + if ((dev->accel.cmd & 0x200) && (count == 2)) + count >>= 1; + } } if (pixcntl == 1) { mix_dat = 0; if (and3 == 3) { if (dev->accel.multifunc[8] & 0x02) - mix_dat |= 0x10; - if (dev->accel.multifunc[8] & 0x04) mix_dat |= 0x08; + if (dev->accel.multifunc[8] & 0x04) + mix_dat |= 0x10; if (dev->accel.multifunc[8] & 0x08) - mix_dat |= 0x04; - if (dev->accel.multifunc[8] & 0x10) - mix_dat |= 0x02; - if (dev->accel.multifunc[9] & 0x02) - mix_dat |= 0x01; - if (dev->accel.multifunc[9] & 0x04) - mix_dat |= 0x80; - if (dev->accel.multifunc[9] & 0x08) - mix_dat |= 0x40; - if (dev->accel.multifunc[9] & 0x10) mix_dat |= 0x20; + if (dev->accel.multifunc[8] & 0x10) + mix_dat |= 0x40; + if (dev->accel.multifunc[9] & 0x02) + mix_dat |= 0x80; + if (dev->accel.multifunc[9] & 0x04) + mix_dat |= 0x01; + if (dev->accel.multifunc[9] & 0x08) + mix_dat |= 0x02; + if (dev->accel.multifunc[9] & 0x10) + mix_dat |= 0x04; } if (and3 == 2) { if (dev->accel.multifunc[8] & 0x02) - mix_dat |= 0x20; - if (dev->accel.multifunc[8] & 0x04) - mix_dat |= 0x10; - if (dev->accel.multifunc[8] & 0x08) - mix_dat |= 0x08; - if (dev->accel.multifunc[8] & 0x10) mix_dat |= 0x04; + if (dev->accel.multifunc[8] & 0x04) + mix_dat |= 0x08; + if (dev->accel.multifunc[8] & 0x08) + mix_dat |= 0x10; + if (dev->accel.multifunc[8] & 0x10) + mix_dat |= 0x20; if (dev->accel.multifunc[9] & 0x02) - mix_dat |= 0x02; - if (dev->accel.multifunc[9] & 0x04) - mix_dat |= 0x01; - if (dev->accel.multifunc[9] & 0x08) - mix_dat |= 0x80; - if (dev->accel.multifunc[9] & 0x10) mix_dat |= 0x40; + if (dev->accel.multifunc[9] & 0x04) + mix_dat |= 0x80; + if (dev->accel.multifunc[9] & 0x08) + mix_dat |= 0x01; + if (dev->accel.multifunc[9] & 0x10) + mix_dat |= 0x02; } if (and3 == 1) { if (dev->accel.multifunc[8] & 0x02) - mix_dat |= 0x40; - if (dev->accel.multifunc[8] & 0x04) - mix_dat |= 0x20; - if (dev->accel.multifunc[8] & 0x08) - mix_dat |= 0x10; - if (dev->accel.multifunc[8] & 0x10) - mix_dat |= 0x08; - if (dev->accel.multifunc[9] & 0x02) - mix_dat |= 0x04; - if (dev->accel.multifunc[9] & 0x04) mix_dat |= 0x02; + if (dev->accel.multifunc[8] & 0x04) + mix_dat |= 0x04; + if (dev->accel.multifunc[8] & 0x08) + mix_dat |= 0x08; + if (dev->accel.multifunc[8] & 0x10) + mix_dat |= 0x10; + if (dev->accel.multifunc[9] & 0x02) + mix_dat |= 0x20; + if (dev->accel.multifunc[9] & 0x04) + mix_dat |= 0x40; if (dev->accel.multifunc[9] & 0x08) - mix_dat |= 0x01; - if (dev->accel.multifunc[9] & 0x10) mix_dat |= 0x80; + if (dev->accel.multifunc[9] & 0x10) + mix_dat |= 0x01; } if (and3 == 0) { if (dev->accel.multifunc[8] & 0x02) - mix_dat |= 0x80; - if (dev->accel.multifunc[8] & 0x04) - mix_dat |= 0x40; - if (dev->accel.multifunc[8] & 0x08) - mix_dat |= 0x20; - if (dev->accel.multifunc[8] & 0x10) - mix_dat |= 0x10; - if (dev->accel.multifunc[9] & 0x02) - mix_dat |= 0x08; - if (dev->accel.multifunc[9] & 0x04) - mix_dat |= 0x04; - if (dev->accel.multifunc[9] & 0x08) - mix_dat |= 0x02; - if (dev->accel.multifunc[9] & 0x10) mix_dat |= 0x01; + if (dev->accel.multifunc[8] & 0x04) + mix_dat |= 0x02; + if (dev->accel.multifunc[8] & 0x08) + mix_dat |= 0x04; + if (dev->accel.multifunc[8] & 0x10) + mix_dat |= 0x08; + if (dev->accel.multifunc[9] & 0x02) + mix_dat |= 0x10; + if (dev->accel.multifunc[9] & 0x04) + mix_dat |= 0x20; + if (dev->accel.multifunc[9] & 0x08) + mix_dat |= 0x40; + if (dev->accel.multifunc[9] & 0x10) + mix_dat |= 0x80; } } @@ -1238,26 +1330,38 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { + old_dest_dat = dest_dat; MIX(mix_dat & mix_mask, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); if (dev->accel.ssv_draw) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + if ((dev->accel.cmd & 4) && dev->accel.ssv_len) { + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); + } else if (!(dev->accel.cmd & 4)) { + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); + } } } } mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (!dev->accel.ssv_len) break; @@ -1291,14 +1395,133 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.cx++; dev->accel.cy++; break; + + default: + break; } dev->accel.ssv_len--; } + } else { + while (count-- && (dev->accel.ssv_len >= 0)) { + if ((dev->accel.cx >= dev->accel.clip_left) && (dev->accel.cx <= clip_r) && + (dev->accel.cy >= dev->accel.clip_top) && (dev->accel.cy <= clip_b)) { + switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { + case 0: + src_dat = bkgd_color; + break; + case 1: + src_dat = frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + src_dat = 0; + break; - dev->accel.cur_x = dev->accel.cx; - dev->accel.cur_y = dev->accel.cy; + default: + break; + } + + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); + + if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { + old_dest_dat = dest_dat; + MIX(mix_dat & mix_mask, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + + if (dev->accel.ssv_draw) { + if ((dev->accel.cmd & 4) && dev->accel.ssv_len) { + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); + } else if (!(dev->accel.cmd & 4)) { + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); + } + } + } + } + + mix_dat <<= 1; + mix_dat |= 1; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; + + if (!dev->accel.ssv_len) + break; + + if (dev->accel.err_term >= dev->accel.maj_axis_pcnt) { + dev->accel.err_term += dev->accel.destx_distp; + /*Step minor axis*/ + switch (dev->accel.cmd & 0xe0) { + case 0x00: + dev->accel.cy--; + break; + case 0x20: + dev->accel.cy--; + break; + case 0x40: + dev->accel.cx--; + break; + case 0x60: + dev->accel.cx++; + break; + case 0x80: + dev->accel.cy++; + break; + case 0xa0: + dev->accel.cy++; + break; + case 0xc0: + dev->accel.cx--; + break; + case 0xe0: + dev->accel.cx++; + break; + + default: + break; + } + } else + dev->accel.err_term += dev->accel.desty_axstp; + + /*Step major axis*/ + switch (dev->accel.cmd & 0xe0) { + case 0x00: + dev->accel.cx--; + break; + case 0x20: + dev->accel.cx++; + break; + case 0x40: + dev->accel.cy--; + break; + case 0x60: + dev->accel.cy--; + break; + case 0x80: + dev->accel.cx--; + break; + case 0xa0: + dev->accel.cx++; + break; + case 0xc0: + dev->accel.cy++; + break; + case 0xe0: + dev->accel.cy++; + break; + + default: + break; + } + + dev->accel.ssv_len--; + } } + dev->accel.cur_x = dev->accel.cx; + dev->accel.cur_y = dev->accel.cy; break; case 1: /*Draw line*/ @@ -1307,16 +1530,16 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.cx = dev->accel.cur_x; dev->accel.cy = dev->accel.cur_y; - if (dev->accel.cur_x & 0x400) { - dev->accel.cx |= ~0x3ff; + if (dev->accel.cur_x >= 0x600) { + dev->accel.cx |= ~0x5ff; } - if (dev->accel.cur_y & 0x400) { - dev->accel.cy |= ~0x3ff; + if (dev->accel.cur_y >= 0x600) { + dev->accel.cy |= ~0x5ff; } dev->accel.sy = dev->accel.maj_axis_pcnt; - if (ibm8514_cpu_src(dev)) { + if (ibm8514_cpu_src(svga)) { if (dev->accel.cmd & 2) { if (dev->accel.cmd & 8) { if (and3 == 1) { @@ -1349,7 +1572,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ - } else if (ibm8514_cpu_dest(dev)) { + } else if (ibm8514_cpu_dest(svga)) { dev->data_available = 1; dev->data_available2 = 1; return; @@ -1357,22 +1580,22 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat } if (dev->accel.cmd & 8) { /*Vector Line*/ - if (ibm8514_cpu_dest(dev) && cpu_input && (dev->accel.cmd & 2)) + if (ibm8514_cpu_dest(svga) && cpu_input && (dev->accel.cmd & 2)) count >>= 1; dev->accel.xx_count++; while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { - if (ibm8514_cpu_dest(dev) && (pixcntl == 0)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { + if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ - } else if (ibm8514_cpu_dest(dev) && (pixcntl == 3)) { + } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { /* Mix data = current video memory value. */ - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, mix_dat); + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, mix_dat); mix_dat = ((mix_dat & rd_mask) == rd_mask); mix_dat = mix_dat ? mix_mask : 0; } - if (ibm8514_cpu_dest(dev)) { - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, src_dat); + if (ibm8514_cpu_dest(svga)) { + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, src_dat); if (pixcntl == 3) src_dat = ((src_dat & rd_mask) == rd_mask); } else @@ -1384,83 +1607,86 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { old_dest_dat = dest_dat; MIX(mix_dat & mix_mask, dest_dat, src_dat); dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); - if ((dev->accel.cmd & 2) && ibm8514_cpu_src(dev)) { + if ((dev->accel.cmd & 2) && ibm8514_cpu_src(svga)) { if (and3 == 1) { if (dev->accel.xx_count >= 2) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } else if (and3 == 2) { if (dev->accel.xx_count == 2) { if (count <= 2) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } else if (dev->accel.xx_count >= 3) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } else if (and3 == 3) { if (dev->accel.xx_count == 2) { if (count <= 1) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } else if (dev->accel.xx_count >= 3) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } else { if (dev->accel.xx_count == 1) { if (!count) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } else if (dev->accel.xx_count >= 2) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } } else { - if (ibm8514_cpu_src(dev) || !cpu_input) { + if (ibm8514_cpu_src(svga) || !cpu_input) { if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } @@ -1469,7 +1695,10 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.sy == 0) { break; @@ -1504,6 +1733,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.cx++; dev->accel.cy++; break; + + default: + break; } dev->accel.sy--; @@ -1518,9 +1750,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.temp_cnt = 8; mix_dat = old_mix_dat; } - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { - if (ibm8514_cpu_dest(dev)) { - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, src_dat); + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { + if (ibm8514_cpu_dest(svga)) { + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, src_dat); } else switch ((mix_dat & 1) ? frgd_mix : bkgd_mix) { case 0: @@ -1530,30 +1762,36 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { old_dest_dat = dest_dat; MIX(mix_dat & 1, dest_dat, src_dat); dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } dev->accel.temp_cnt--; mix_dat >>= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.sy == 0) { break; @@ -1587,6 +1825,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cx++; break; + + default: + break; } } else dev->accel.err_term += dev->accel.desty_axstp; @@ -1617,24 +1858,27 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cy++; break; + + default: + break; } dev->accel.sy--; } } else { while (count-- && (dev->accel.sy >= 0)) { - if (((dev->accel.cx) >= dev->accel.clip_left && (dev->accel.cx) <= clip_r && (dev->accel.cy) >= dev->accel.clip_top && (dev->accel.cy) <= clip_b)) { - if (ibm8514_cpu_dest(dev) && (pixcntl == 0)) { + if ((dev->accel.cx) >= dev->accel.clip_left && (dev->accel.cx) <= clip_r && (dev->accel.cy) >= dev->accel.clip_top && (dev->accel.cy) <= clip_b) { + if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ - } else if (ibm8514_cpu_dest(dev) && (pixcntl == 3)) { + } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { /* Mix data = current video memory value. */ - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, mix_dat); + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, mix_dat); mix_dat = ((mix_dat & rd_mask) == rd_mask); mix_dat = mix_dat ? mix_mask : 0; } - if (ibm8514_cpu_dest(dev)) { - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, src_dat); + if (ibm8514_cpu_dest(svga)) { + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, src_dat); if (pixcntl == 3) src_dat = ((src_dat & rd_mask) == rd_mask); } else @@ -1646,30 +1890,36 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { old_dest_dat = dest_dat; MIX(mix_dat & mix_mask, dest_dat, src_dat); dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); if ((dev->accel.cmd & 4) && dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } else if (!(dev->accel.cmd & 4)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); } } } mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.sy == 0) { break; @@ -1703,6 +1953,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cx++; break; + + default: + break; } } else dev->accel.err_term += dev->accel.desty_axstp; @@ -1733,6 +1986,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cy++; break; + + default: + break; } dev->accel.sy--; @@ -1759,14 +2015,18 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.sx = dev->accel.maj_axis_pcnt & 0x7ff; dev->accel.sy = dev->accel.multifunc[0] & 0x7ff; - dev->accel.cx = dev->accel.cur_x & 0x3ff; - if (dev->accel.cur_x & 0x400) - dev->accel.cx |= ~0x3ff; - dev->accel.cy = dev->accel.cur_y & 0x3ff; - if (dev->accel.cur_y & 0x400) - dev->accel.cy |= ~0x3ff; + dev->accel.cx = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; + dev->accel.cy = dev->accel.cur_y; + if (dev->accel.cur_y >= 0x600) + dev->accel.cy |= ~0x5ff; + + if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) + dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + else + dev->accel.dest = dev->accel.cy * dev->pitch; - dev->accel.dest = dev->accel.cy * dev->h_disp; dev->accel.fill_state = 0; if (cmd == 4) @@ -1774,7 +2034,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat else if (cmd == 3) dev->accel.cmd &= ~2; - if (ibm8514_cpu_src(dev)) { + if (ibm8514_cpu_src(svga)) { if (dev->accel.cmd & 2) { if (!(dev->accel.cmd & 0x1000)) { if (!(dev->accel.cmd & 8)) { @@ -1813,19 +2073,22 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat } else { if (!(dev->accel.cmd & 0x40) && (frgd_mix == 2) && (bkgd_mix == 2) && (pixcntl == 0) && (cmd == 2)) { if (!(dev->accel.sx & 1)) { - dev->accel.output = 1; - dev->accel.newdest_out = (dev->accel.cy + 1) * dev->h_disp; + dev->accel.output = 1; + if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) + dev->accel.newdest_out = (dev->accel.ge_offset << 2) + ((dev->accel.cy + 1) * dev->pitch); + else + dev->accel.newdest_out = (dev->accel.cy + 1) * dev->pitch; } } } dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ - } else if (ibm8514_cpu_dest(dev)) { + } else if (ibm8514_cpu_dest(svga)) { if (!(dev->accel.cmd & 2) && (frgd_mix == 2) && (pixcntl == 0) && (cmd == 2)) { if (!(dev->accel.sx & 1)) { dev->accel.input = 1; - dev->accel.newdest_in = (dev->accel.cy + 1) * dev->h_disp; + dev->accel.newdest_in = (dev->accel.cy + 1) * dev->pitch; } } else if (dev->accel.cmd & 2) { if (dev->accel.cmd & 8) { @@ -1844,10 +2107,10 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat if (dev->accel.cmd & 2) { if (cpu_input) { rect_fill_pix: - if ((dev->accel.cmd & 8) && ibm8514_cpu_src(dev)) { + if ((dev->accel.cmd & 8) && ibm8514_cpu_src(svga)) { dev->accel.xx_count++; while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -1856,11 +2119,14 @@ rect_fill_pix: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -1931,7 +2197,10 @@ rect_fill_pix: mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; switch (dev->accel.cmd & 0xe0) { case 0x00: @@ -1952,6 +2221,9 @@ rect_fill_pix: case 0xe0: dev->accel.cx++; break; + + default: + break; } dev->accel.sx--; @@ -1991,9 +2263,12 @@ rect_fill_pix: case 0xe0: dev->accel.cy++; break; + + default: + break; } - dev->accel.dest = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; return; } @@ -2002,17 +2277,17 @@ rect_fill_pix: } if (count < 8) { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { - if (ibm8514_cpu_dest(dev) && (pixcntl == 0)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { + if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ - } else if (ibm8514_cpu_dest(dev) && (pixcntl == 3)) { + } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { /* Mix data = current video memory value. */ READ(dev->accel.dest + dev->accel.cx, mix_dat); mix_dat = ((mix_dat & rd_mask) == rd_mask); mix_dat = mix_dat ? mix_mask : 0; } - if (ibm8514_cpu_dest(dev)) { + if (ibm8514_cpu_dest(svga)) { READ(dev->accel.dest + dev->accel.cx, src_dat); if (pixcntl == 3) src_dat = ((src_dat & rd_mask) == rd_mask); @@ -2025,11 +2300,14 @@ rect_fill_pix: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2044,7 +2322,10 @@ rect_fill_pix: mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.cmd & 0x20) dev->accel.cx++; @@ -2069,24 +2350,28 @@ rect_fill_pix: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; + if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) + dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + else + dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.sy--; return; } } } else { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { - if (ibm8514_cpu_dest(dev) && (pixcntl == 0)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { + if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = 1; /* Mix data = forced to foreground register. */ - } else if (ibm8514_cpu_dest(dev) && (pixcntl == 3)) { + } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { /* Mix data = current video memory value. */ READ(dev->accel.dest + dev->accel.cx, mix_dat); mix_dat = ((mix_dat & rd_mask) == rd_mask); mix_dat = mix_dat ? 1 : 0; } - if (ibm8514_cpu_dest(dev)) { + if (ibm8514_cpu_dest(svga)) { READ(dev->accel.dest + dev->accel.cx, src_dat); if (pixcntl == 3) src_dat = ((src_dat & rd_mask) == rd_mask); @@ -2099,11 +2384,14 @@ rect_fill_pix: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } } @@ -2117,7 +2405,10 @@ rect_fill_pix: } } mix_dat >>= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.cmd & 0x20) dev->accel.cx++; @@ -2140,9 +2431,9 @@ rect_fill_pix: if (dev->accel.cmd & 2) { if (dev->accel.cmd & 0x1000) { - dev->accel.cx = dev->accel.cur_x & 0x3ff; - if (dev->accel.cur_x & 0x400) - dev->accel.cx |= ~0x3ff; + dev->accel.cx = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; } } @@ -2151,7 +2442,11 @@ rect_fill_pix: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; + if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) + dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + else + dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.sy--; return; } @@ -2167,7 +2462,7 @@ rect_fill_pix: } else { if (dev->accel.input && !dev->accel.output) { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ if (!dev->accel.odd_in && !dev->accel.sx) { READ(dev->accel.newdest_in + dev->accel.cur_x, src_dat); @@ -2205,8 +2500,8 @@ rect_fill_pix: dev->accel.cy++; else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; - dev->accel.newdest_in = (dev->accel.cy + 1) * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.newdest_in = (dev->accel.cy + 1) * dev->pitch; dev->accel.sy--; return; } @@ -2224,8 +2519,8 @@ rect_fill_pix: dev->accel.cy++; else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; - dev->accel.newdest_in = (dev->accel.cy + 1) * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.newdest_in = (dev->accel.cy + 1) * dev->pitch; dev->accel.sy--; return; } @@ -2233,7 +2528,7 @@ rect_fill_pix: } } else if (dev->accel.output && !dev->accel.input) { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { src_dat = cpu_dat; if (!dev->accel.odd_out && !dev->accel.sx) { READ(dev->accel.newdest_out + dev->accel.cur_x, dest_dat); @@ -2254,7 +2549,10 @@ rect_fill_pix: } mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.cmd & 0x20) dev->accel.cx++; @@ -2272,8 +2570,8 @@ rect_fill_pix: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; - dev->accel.newdest_out = (dev->accel.cy + 1) * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.newdest_out = (dev->accel.cy + 1) * dev->pitch; dev->accel.sy--; return; } @@ -2292,8 +2590,8 @@ rect_fill_pix: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; - dev->accel.newdest_out = (dev->accel.cy + 1) * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.newdest_out = (dev->accel.cy + 1) * dev->pitch; dev->accel.sy--; return; } @@ -2301,17 +2599,17 @@ rect_fill_pix: } } else { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { - if (ibm8514_cpu_dest(dev) && (pixcntl == 0)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { + if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ - } else if (ibm8514_cpu_dest(dev) && (pixcntl == 3)) { + } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { /* Mix data = current video memory value. */ READ(dev->accel.dest + dev->accel.cx, mix_dat); mix_dat = ((mix_dat & rd_mask) == rd_mask); mix_dat = mix_dat ? mix_mask : 0; } - if (ibm8514_cpu_dest(dev)) { + if (ibm8514_cpu_dest(svga)) { READ(dev->accel.dest + dev->accel.cx, src_dat); if (pixcntl == 3) { src_dat = ((src_dat & rd_mask) == rd_mask); @@ -2325,18 +2623,21 @@ rect_fill_pix: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { old_dest_dat = dest_dat; - if (ibm8514_cpu_dest(dev)) { + if (ibm8514_cpu_dest(svga)) { if (pixcntl == 3) { MIX(mix_dat & mix_mask, dest_dat, src_dat); } @@ -2350,7 +2651,10 @@ rect_fill_pix: mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.cmd & 0x20) dev->accel.cx++; @@ -2371,7 +2675,7 @@ rect_fill_pix: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; return; } @@ -2389,7 +2693,7 @@ rect_fill: mix_dat >>= 8; dev->accel.temp_cnt = 8; } - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2403,6 +2707,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2441,7 +2748,7 @@ rect_fill: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; dev->accel.cur_x = dev->accel.cx; @@ -2456,7 +2763,7 @@ rect_fill: dev->accel.temp_cnt = 8; mix_dat = old_mix_dat; } - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { switch ((mix_dat & 1) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2470,6 +2777,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2505,7 +2815,7 @@ rect_fill: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; if (dev->accel.sy < 0) { @@ -2519,7 +2829,7 @@ rect_fill: } else { if (dev->accel.multifunc[0x0a] & 6) { while (count-- && dev->accel.sy >= 0) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2533,6 +2843,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, poly_src); @@ -2583,7 +2896,7 @@ rect_fill: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; if (dev->accel.sy < 0) { @@ -2595,7 +2908,7 @@ rect_fill: } } else { while (count-- && dev->accel.sy >= 0) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if (dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2609,6 +2922,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2643,7 +2959,7 @@ rect_fill: else dev->accel.cy--; - dev->accel.dest = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; if (dev->accel.sy < 0) { @@ -2661,20 +2977,21 @@ rect_fill: case 5: /*Draw Polygon Boundary Line*/ if (!cpu_input) { - dev->accel.cx = dev->accel.cur_x; - dev->accel.cy = dev->accel.cur_y; + dev->accel.cx = dev->accel.cur_x; + dev->accel.cy = dev->accel.cur_y; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; + + if (dev->accel.cur_y >= 0x600) + dev->accel.cy |= ~0x5ff; dev->accel.oldcy = dev->accel.cy; + dev->accel.sy = 0; - dev->accel.xdir = (dev->accel.cmd & 0x20) ? 1 : -1; - dev->accel.ydir = (dev->accel.cmd & 0x80) ? 1 : -1; - - dev->accel.sy = 0; - - if (ibm8514_cpu_src(dev)) { + if (ibm8514_cpu_src(svga)) { dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ - } else if (ibm8514_cpu_dest(dev)) { + } else if (ibm8514_cpu_dest(svga)) { dev->data_available = 1; dev->data_available2 = 1; return; @@ -2682,7 +2999,7 @@ rect_fill: } while (count-- && (dev->accel.sy >= 0)) { - if (((dev->accel.cx) >= dev->accel.clip_left && (dev->accel.cx <= clip_r) && (dev->accel.cy) >= dev->accel.clip_top && (dev->accel.cy) <= clip_b)) { + if ((dev->accel.cx) >= dev->accel.clip_left && ((dev->accel.cx) <= clip_r) && (dev->accel.cy) >= dev->accel.clip_top && (dev->accel.cy) <= clip_b) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2691,14 +3008,17 @@ rect_fill: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: src_dat = 0; break; + + default: + break; } - READ((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { old_dest_dat = dest_dat; @@ -2706,11 +3026,11 @@ rect_fill: dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); if ((dev->accel.cmd & 4) && (dev->accel.sy < dev->accel.maj_axis_pcnt)) { if (!dev->accel.sy) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); - } else if ((dev->accel.cmd & 0x40) && dev->accel.sy && (dev->accel.cy == dev->accel.oldcy + 1)) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + (dev->accel.cx), dest_dat); + } else if ((dev->accel.cmd & 0x40) && dev->accel.sy && (dev->accel.cy == (dev->accel.oldcy + 1))) { + WRITE((dev->accel.cy * dev->pitch) + (dev->accel.cx), dest_dat); } else if (!(dev->accel.cmd & 0x40) && dev->accel.sy && (dev->accel.err_term >= 0) && (dev->accel.cy == (dev->accel.oldcy + 1))) { - WRITE((dev->accel.cy * dev->h_disp) + dev->accel.cx, dest_dat); + WRITE((dev->accel.cy * dev->pitch) + (dev->accel.cx), dest_dat); } } } @@ -2718,30 +3038,87 @@ rect_fill: mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.sy == dev->accel.maj_axis_pcnt) { - return; + break; } - if (dev->accel.cmd & 0x40) { - dev->accel.oldcy = dev->accel.cy; - dev->accel.cy += dev->accel.ydir; - if (dev->accel.err_term >= 0) { - dev->accel.err_term += dev->accel.destx_distp; - dev->accel.cx += dev->accel.xdir; - } else { - dev->accel.err_term += dev->accel.desty_axstp; + if (dev->accel.err_term >= dev->accel.maj_axis_pcnt) { + dev->accel.err_term += dev->accel.destx_distp; + /*Step minor axis*/ + switch (dev->accel.cmd & 0xe0) { + case 0x00: + dev->accel.oldcy = dev->accel.cy; + dev->accel.cy--; + break; + case 0x20: + dev->accel.oldcy = dev->accel.cy; + dev->accel.cy--; + break; + case 0x40: + dev->accel.cx--; + break; + case 0x60: + dev->accel.cx++; + break; + case 0x80: + dev->accel.oldcy = dev->accel.cy; + dev->accel.cy++; + break; + case 0xa0: + dev->accel.oldcy = dev->accel.cy; + dev->accel.cy++; + break; + case 0xc0: + dev->accel.cx--; + break; + case 0xe0: + dev->accel.cx++; + break; + + default: + break; } - } else { - dev->accel.cx += dev->accel.xdir; - if (dev->accel.err_term >= 0) { - dev->accel.err_term += dev->accel.destx_distp; + } else + dev->accel.err_term += dev->accel.desty_axstp; + + /*Step major axis*/ + switch (dev->accel.cmd & 0xe0) { + case 0x00: + dev->accel.cx--; + break; + case 0x20: + dev->accel.cx++; + break; + case 0x40: dev->accel.oldcy = dev->accel.cy; - dev->accel.cy += dev->accel.ydir; - } else { - dev->accel.err_term += dev->accel.desty_axstp; - } + dev->accel.cy--; + break; + case 0x60: + dev->accel.oldcy = dev->accel.cy; + dev->accel.cy--; + break; + case 0x80: + dev->accel.cx--; + break; + case 0xa0: + dev->accel.cx++; + break; + case 0xc0: + dev->accel.oldcy = dev->accel.cy; + dev->accel.cy++; + break; + case 0xe0: + dev->accel.oldcy = dev->accel.cy; + dev->accel.cy++; + break; + + default: + break; } dev->accel.sy++; @@ -2757,26 +3134,26 @@ rect_fill: dev->accel.sx = dev->accel.maj_axis_pcnt & 0x7ff; dev->accel.sy = dev->accel.multifunc[0] & 0x7ff; - dev->accel.dx = dev->accel.destx_distp & 0x3ff; - dev->accel.dy = dev->accel.desty_axstp & 0x3ff; + dev->accel.dx = dev->accel.destx_distp; + dev->accel.dy = dev->accel.desty_axstp; - if (dev->accel.destx_distp & 0x400) - dev->accel.dx |= ~0x3ff; - if (dev->accel.desty_axstp & 0x400) - dev->accel.dy |= ~0x3ff; + if (dev->accel.destx_distp >= 0x600) + dev->accel.dx |= ~0x5ff; + if (dev->accel.desty_axstp >= 0x600) + dev->accel.dy |= ~0x5ff; - dev->accel.cx = dev->accel.cur_x & 0x3ff; - dev->accel.cy = dev->accel.cur_y & 0x3ff; + dev->accel.cx = dev->accel.cur_x; + dev->accel.cy = dev->accel.cur_y; - if (dev->accel.cur_x & 0x400) - dev->accel.cx |= ~0x3ff; - if (dev->accel.cur_y & 0x400) - dev->accel.cy |= ~0x3ff; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; + if (dev->accel.cur_y >= 0x600) + dev->accel.cy |= ~0x5ff; - dev->accel.src = dev->accel.cy * dev->h_disp; - dev->accel.dest = dev->accel.dy * dev->h_disp; + dev->accel.src = dev->accel.cy * dev->pitch; + dev->accel.dest = dev->accel.dy * dev->pitch; - if (ibm8514_cpu_src(dev)) { + if (ibm8514_cpu_src(svga)) { if (dev->accel.cmd & 2) { if (!(dev->accel.cmd & 0x1000)) { dev->accel.sx += (dev->accel.cur_x & 3); @@ -2788,7 +3165,7 @@ rect_fill: dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ - } else if (ibm8514_cpu_dest(dev)) { + } else if (ibm8514_cpu_dest(svga)) { dev->data_available = 1; dev->data_available2 = 1; return; /*Wait for data from CPU*/ @@ -2800,7 +3177,7 @@ rect_fill: bitblt_pix: if (count < 8) { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b)) { + if (dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b) { if (pixcntl == 3) { if (!(dev->accel.cmd & 0x10) && ((frgd_mix != 3) || (bkgd_mix != 3))) { READ(dev->accel.src + dev->accel.cx, mix_dat); @@ -2820,7 +3197,7 @@ bitblt_pix: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: READ(dev->accel.src + dev->accel.cx, src_dat); @@ -2830,6 +3207,9 @@ bitblt_pix: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -2844,12 +3224,18 @@ bitblt_pix: mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; - - if (dev->accel.cmd & 0x20) - dev->accel.cx++; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; else + cpu_dat >>= 8; + + if (dev->accel.cmd & 0x20) { + dev->accel.dx++; + dev->accel.cx++; + } else { + dev->accel.dx--; dev->accel.cx--; + } dev->accel.sx--; if (dev->accel.sx < 0) { @@ -2860,23 +3246,30 @@ bitblt_pix: } if (dev->accel.cmd & 0x20) { + dev->accel.dx -= (dev->accel.sx) + 1; dev->accel.cx -= (dev->accel.sx) + 1; - } else + } else { + dev->accel.dx += (dev->accel.sx) + 1; dev->accel.cx += (dev->accel.sx) + 1; + } - if (dev->accel.cmd & 0x80) + if (dev->accel.cmd & 0x80) { + dev->accel.dy++; dev->accel.cy++; - else + } else { + dev->accel.dy--; dev->accel.cy--; + } - dev->accel.dest = dev->accel.cy * dev->h_disp; + dev->accel.src = dev->accel.cy * dev->pitch; + dev->accel.dest = dev->accel.dy * dev->pitch; dev->accel.sy--; return; } } } else { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b)) { + if (dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b) { if (pixcntl == 3) { if (!(dev->accel.cmd & 0x10) && ((frgd_mix != 3) || (bkgd_mix != 3))) { READ(dev->accel.src + dev->accel.cx, mix_dat); @@ -2896,7 +3289,7 @@ bitblt_pix: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: READ(dev->accel.src + dev->accel.cx, src_dat); @@ -2906,6 +3299,9 @@ bitblt_pix: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -2918,7 +3314,10 @@ bitblt_pix: } } mix_dat >>= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.cmd & 0x20) { dev->accel.dx++; @@ -2947,12 +3346,12 @@ bitblt_pix: if (dev->accel.cmd & 2) { if (dev->accel.cmd & 0x1000) { - dev->accel.cx = dev->accel.cur_x & 0x3ff; - if (dev->accel.cur_x & 0x400) - dev->accel.cx |= ~0x3ff; - dev->accel.dx = dev->accel.destx_distp & 0x3ff; - if (dev->accel.destx_distp & 0x400) - dev->accel.dx |= ~0x3ff; + dev->accel.cx = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + dev->accel.cx |= ~0x5ff; + dev->accel.dx = dev->accel.destx_distp; + if (dev->accel.destx_distp >= 0x600) + dev->accel.dx |= ~0x5ff; } } @@ -2964,8 +3363,8 @@ bitblt_pix: dev->accel.cy--; } - dev->accel.dest = dev->accel.dy * dev->h_disp; - dev->accel.src = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.dy * dev->pitch; + dev->accel.src = dev->accel.cy * dev->pitch; dev->accel.sy--; return; } @@ -2980,7 +3379,7 @@ bitblt_pix: goto bitblt_pix; } else { while (count-- && (dev->accel.sy >= 0)) { - if ((dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b)) { + if (dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b) { if (pixcntl == 3) { if (!(dev->accel.cmd & 0x10) && ((frgd_mix != 3) || (bkgd_mix != 3))) { READ(dev->accel.src + dev->accel.cx, mix_dat); @@ -3000,7 +3399,7 @@ bitblt_pix: src_dat = frgd_color; break; case 2: - src_dat = cpu_dat & 0xff; + src_dat = cpu_dat; break; case 3: READ(dev->accel.src + dev->accel.cx, src_dat); @@ -3010,6 +3409,9 @@ bitblt_pix: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3023,7 +3425,10 @@ bitblt_pix: } mix_dat <<= 1; mix_dat |= 1; - cpu_dat >>= 8; + if ((svga->bpp == 15) || (svga->bpp == 16)) + cpu_dat >>= 16; + else + cpu_dat >>= 8; if (dev->accel.cmd & 0x20) { dev->accel.dx++; @@ -3053,8 +3458,8 @@ bitblt_pix: dev->accel.cy--; } - dev->accel.dest = dev->accel.dy * dev->h_disp; - dev->accel.src = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.dy * dev->pitch; + dev->accel.src = dev->accel.cy * dev->pitch; dev->accel.sy--; return; } @@ -3067,11 +3472,11 @@ bitblt: count = dev->accel.maj_axis_pcnt + 1; dev->accel.temp_cnt = 8; while (count-- && dev->accel.sy >= 0) { - if (dev->accel.temp_cnt == 0) { + if (!dev->accel.temp_cnt) { mix_dat >>= 8; dev->accel.temp_cnt = 8; } - if ((dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b)) { + if (dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -3085,6 +3490,9 @@ bitblt: case 3: READ(dev->accel.src + dev->accel.cx, src_dat); break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3132,8 +3540,8 @@ bitblt: dev->accel.cy--; } - dev->accel.dest = dev->accel.dy * dev->h_disp; - dev->accel.src = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.dy * dev->pitch; + dev->accel.src = dev->accel.cy * dev->pitch; dev->accel.sy--; return; } @@ -3141,11 +3549,11 @@ bitblt: } else { dev->accel.temp_cnt = 8; while (count-- && dev->accel.sy >= 0) { - if (dev->accel.temp_cnt == 0) { + if (!dev->accel.temp_cnt) { dev->accel.temp_cnt = 8; mix_dat = old_mix_dat; } - if ((dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b)) { + if (dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b) { switch ((mix_dat & 1) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -3159,6 +3567,9 @@ bitblt: case 3: READ(dev->accel.src + dev->accel.cx, src_dat); break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3202,8 +3613,8 @@ bitblt: dev->accel.cy--; } - dev->accel.dest = dev->accel.dy * dev->h_disp; - dev->accel.src = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.dy * dev->pitch; + dev->accel.src = dev->accel.cy * dev->pitch; dev->accel.sy--; if (dev->accel.sy < 0) { @@ -3213,8 +3624,37 @@ bitblt: } } } else { + if ((svga->bpp == 24) && dev->local && (dev->accel.cmd == 0xc2b5)) { + int64_t cx; + int64_t dx; + + cx = (int64_t) dev->accel.cx; + dx = (int64_t) dev->accel.dx; + + while (1) { + if ((dx >= (((int64_t)dev->accel.clip_left) * 3)) && (dx <= (((uint64_t)clip_r) * 3)) && + (dev->accel.dy >= (dev->accel.clip_top << 1)) && (dev->accel.dy <= (clip_b << 1))) { + READ(dev->accel.src + (dev->accel.ge_offset << 2) + cx, src_dat); + READ(dev->accel.dest + (dev->accel.ge_offset << 2) + dx, dest_dat); + + dest_dat = (src_dat & wrt_mask) | (dest_dat & ~wrt_mask); + + WRITE(dev->accel.dest + (dev->accel.ge_offset << 2) + dx, dest_dat); + } + + cx++; + dx++; + + dev->accel.sx--; + if (dev->accel.sx < 0) + return; + } + return; + } + while (count-- && dev->accel.sy >= 0) { - if ((dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b)) { + if ((dev->accel.dx >= dev->accel.clip_left) && (dev->accel.dx <= clip_r) && + (dev->accel.dy >= dev->accel.clip_top) && (dev->accel.dy <= clip_b)) { if (pixcntl == 3) { if (!(dev->accel.cmd & 0x10) && ((frgd_mix != 3) || (bkgd_mix != 3))) { READ(dev->accel.src + dev->accel.cx, mix_dat); @@ -3244,6 +3684,9 @@ bitblt: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3253,7 +3696,13 @@ bitblt: MIX(mix_dat & mix_mask, dest_dat, src_dat); dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); - WRITE(dev->accel.dest + dev->accel.dx, dest_dat); + if (dev->accel.cmd & 4) { + if (dev->accel.sx > 0) { + WRITE(dev->accel.dest + dev->accel.dx, dest_dat); + } + } else { + WRITE(dev->accel.dest + dev->accel.dx, dest_dat); + } } } mix_dat <<= 1; @@ -3287,8 +3736,8 @@ bitblt: dev->accel.cy--; } - dev->accel.dest = dev->accel.dy * dev->h_disp; - dev->accel.src = dev->accel.cy * dev->h_disp; + dev->accel.dest = dev->accel.dy * dev->pitch; + dev->accel.src = dev->accel.cy * dev->pitch; dev->accel.sy--; if (dev->accel.sy < 0) { @@ -3300,6 +3749,9 @@ bitblt: } } break; + + default: + break; } } @@ -3307,7 +3759,6 @@ static void ibm8514_render_8bpp(svga_t *svga) { ibm8514_t *dev = &svga->dev8514; - int x; uint32_t *p; uint32_t dat; @@ -3322,7 +3773,7 @@ ibm8514_render_8bpp(svga_t *svga) dev->firstline_draw = dev->displine; dev->lastline_draw = dev->displine; - for (x = 0; x <= dev->h_disp; x += 8) { + for (int x = 0; x <= dev->h_disp; x += 8) { dat = *(uint32_t *) (&dev->vram[dev->ma & dev->vram_mask]); p[0] = dev->map8[dat & 0xff]; p[1] = dev->map8[(dat >> 8) & 0xff]; @@ -3345,22 +3796,20 @@ ibm8514_render_8bpp(svga_t *svga) static void ibm8514_render_overscan_left(ibm8514_t *dev, svga_t *svga) { - int i; - if ((dev->displine + svga->y_add) < 0) return; if (svga->scrblank || (dev->h_disp == 0)) return; - for (i = 0; i < svga->x_add; i++) + for (int i = 0; i < svga->x_add; i++) buffer32->line[dev->displine + svga->y_add][i] = svga->overscan_color; } static void ibm8514_render_overscan_right(ibm8514_t *dev, svga_t *svga) { - int i, right; + int right; if ((dev->displine + svga->y_add) < 0) return; @@ -3369,7 +3818,7 @@ ibm8514_render_overscan_right(ibm8514_t *dev, svga_t *svga) return; right = (overscan_x >> 1); - for (i = 0; i < right; i++) + for (int i = 0; i < right; i++) buffer32->line[dev->displine + svga->y_add][svga->x_add + dev->h_disp + i] = svga->overscan_color; } @@ -3377,7 +3826,8 @@ void ibm8514_poll(ibm8514_t *dev, svga_t *svga) { uint32_t x; - int wx, wy; + int wx; + int wy; if (!dev->linepos) { timer_advance_u64(&svga->timer, svga->dispofftime); @@ -3393,7 +3843,7 @@ ibm8514_poll(ibm8514_t *dev, svga_t *svga) video_wait_for_buffer(); } - ibm8514_render_8bpp(svga); + svga->render(svga); svga->x_add = (overscan_x >> 1); ibm8514_render_overscan_left(dev, svga); @@ -3416,16 +3866,13 @@ ibm8514_poll(ibm8514_t *dev, svga_t *svga) dev->linepos = 0; if (dev->dispon) { if (dev->sc == dev->rowcount) { - dev->linecountff = 0; - dev->sc = 0; - + dev->sc = 0; dev->maback += (dev->rowoffset << 3); if (dev->interlace) dev->maback += (dev->rowoffset << 3); dev->maback &= dev->vram_mask; dev->ma = dev->maback; } else { - dev->linecountff = 0; dev->sc++; dev->sc &= 31; dev->ma = dev->maback; @@ -3471,7 +3918,7 @@ ibm8514_poll(ibm8514_t *dev, svga_t *svga) changeframecount = dev->interlace ? 3 : 2; if (dev->interlace && dev->oddeven) - dev->ma = dev->maback = 0 + (dev->rowoffset << 1); + dev->ma = dev->maback = (dev->rowoffset << 1); else dev->ma = dev->maback = 0; @@ -3485,8 +3932,6 @@ ibm8514_poll(ibm8514_t *dev, svga_t *svga) dev->displine = (dev->interlace && dev->oddeven) ? 1 : 0; svga->x_add = (overscan_x >> 1); - - dev->linecountff = 0; } } } @@ -3496,51 +3941,86 @@ ibm8514_recalctimings(svga_t *svga) { ibm8514_t *dev = &svga->dev8514; - dev->h_disp_time = dev->h_disp = (dev->hdisp + 1) << 3; - dev->rowoffset = (dev->hdisp + 1); - dev->h_total = (dev->htotal + 1); - dev->v_total = (dev->vtotal + 1); - dev->v_syncstart = (dev->vsyncstart + 1); - dev->rowcount = !!(dev->disp_cntl & 0x08); - - if (dev->accel.advfunc_cntl & 4) { - if (dev->hdisp == 0) { - dev->rowoffset = 128; - dev->h_disp = 1024; - } - - if (dev->vtotal == 0) - dev->v_total = 1632; - - if (dev->vsyncstart == 0) - dev->v_syncstart = 1536; - - if (dev->interlace) { - dev->dispend = 384; /*Interlaced*/ - dev->v_total >>= 2; - dev->v_syncstart >>= 2; - } else { + if (ibm8514_on) { + dev->h_disp = (dev->hdisp + 1) << 3; + dev->pitch = (dev->accel.advfunc_cntl & 4) ? 1024 : 640; + dev->h_total = (dev->htotal + 1); + dev->v_total = (dev->vtotal + 1); + dev->v_syncstart = (dev->vsyncstart + 1); + dev->rowcount = !!(dev->disp_cntl & 0x08); + dev->dispend = ((dev->vdisp >> 1) + 1); + if (dev->dispend == 766) dev->dispend = 768; - dev->v_total >>= 1; - dev->v_syncstart >>= 1; + + if (dev->dispend == 598) + dev->dispend = 600; + + if (dev->accel.advfunc_cntl & 4) { + if (!vga_on && dev->ibm_mode) { + if (dev->h_disp == 8) { + dev->h_disp = 1024; + dev->dispend = 768; + dev->v_total = 1536; + dev->v_syncstart = 1536; + } + } + + if (dev->dispend == 598) + dev->dispend = 600; + + if (dev->interlace) { + dev->dispend >>= 1; + dev->v_syncstart >>= 2; + dev->v_total >>= 2; + } else { + dev->v_syncstart >>= 1; + dev->v_total >>= 1; + } + + if (ibm8514_has_vga) { + dev->pitch = dev->ext_pitch; + dev->rowoffset = dev->ext_crt_pitch; + } else + dev->rowoffset = 128; + + ibm8514_log("1024x768 clock mode, hdisp = %d, htotal = %d, vtotal = %d, vsyncstart = %d, interlace = %02x\n", dev->h_disp, dev->h_total, dev->v_total, dev->v_syncstart, dev->interlace); + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + } else { + if (!vga_on && dev->ibm_mode) { + if (dev->h_disp == 1024) { + dev->h_disp = 640; + dev->dispend = 480; + } + } + + if (dev->interlace) { + dev->dispend >>= 1; + dev->v_syncstart >>= 2; + dev->v_total >>= 2; + } else { + dev->v_syncstart >>= 1; + dev->v_total >>= 1; + } + + if (ibm8514_has_vga) { + dev->pitch = dev->ext_pitch; + dev->rowoffset = dev->ext_crt_pitch; + } else + dev->rowoffset = 128; + + svga->clock = (cpuclock * (double) (1ULL << 32)) / 25175000.0; } - // pclog("1024x768 clock mode, hdisp = %d, htotal = %d, vtotal = %d, vsyncstart = %d, interlace = %02x\n", dev->h_disp, dev->h_total, dev->v_total, dev->v_syncstart, dev->interlace); - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; - } else { - // pclog("640x480 clock mode\n"); - dev->dispend = 480; - dev->v_total >>= 1; - dev->v_syncstart >>= 1; - svga->clock = (cpuclock * (double) (1ull << 32)) / 25175000.0; + svga->render = ibm8514_render_8bpp; + ibm8514_log("BPP=%d, Pitch = %d, rowoffset = %d, crtc13 = %02x, mode = %d, highres bit = %02x, has_vga? = %d.\n", dev->bpp, dev->pitch, dev->rowoffset, svga->crtc[0x13], dev->ibm_mode, dev->accel.advfunc_cntl & 4, ibm8514_has_vga); } - // pclog("8514 enabled, hdisp=%d, vtotal=%d, htotal=%d, dispend=%d, rowoffset=%d, split=%d, vsyncstart=%d, split=%08x\n", dev->hdisp, dev->vtotal, dev->htotal, dev->dispend, dev->rowoffset, dev->split, dev->vsyncstart, dev->split); + ibm8514_log("8514 enabled, hdisp=%d, vtotal=%d, htotal=%d, dispend=%d, rowoffset=%d, split=%d, vsyncstart=%d, split=%08x\n", dev->hdisp, dev->vtotal, dev->htotal, dev->dispend, dev->rowoffset, dev->split, dev->vsyncstart, dev->split); } static uint8_t ibm8514_mca_read(int port, void *priv) { - svga_t *svga = (svga_t *) priv; - ibm8514_t *dev = &svga->dev8514; + const svga_t *svga = (svga_t *) priv; + const ibm8514_t *dev = &svga->dev8514; return (dev->pos_regs[port & 7]); } @@ -3562,16 +4042,18 @@ ibm8514_mca_write(int port, uint8_t val, void *priv) static uint8_t ibm8514_mca_feedb(void *priv) { - svga_t *svga = (svga_t *) priv; - ibm8514_t *dev = &svga->dev8514; + const svga_t *svga = (svga_t *) priv; + const ibm8514_t *dev = &svga->dev8514; return dev->pos_regs[2] & 1; } -static void - * - ibm8514_init(const device_t *info) +static void * +ibm8514_init(const device_t *info) { + if (svga_get_pri() == NULL) + return NULL; + svga_t *svga = svga_get_pri(); ibm8514_t *dev = &svga->dev8514; @@ -3581,7 +4063,9 @@ static void dev->vram_mask = dev->vram_size - 1; dev->map8 = svga->pallook; - dev->type = info->flags; + dev->type = info->flags; + dev->ibm_mode = 1; + dev->bpp = 8; ibm8514_io_set(svga); @@ -3595,9 +4079,9 @@ static void } static void -ibm8514_close(void *p) +ibm8514_close(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; ibm8514_t *dev = &svga->dev8514; if (dev) { @@ -3607,17 +4091,17 @@ ibm8514_close(void *p) } static void -ibm8514_speed_changed(void *p) +ibm8514_speed_changed(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; svga_recalctimings(svga); } static void -ibm8514_force_redraw(void *p) +ibm8514_force_redraw(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; svga->fullchange = changeframecount; } @@ -3655,7 +4139,7 @@ const device_t ibm8514_mca_device = { void ibm8514_device_add(void) { - if (!ibm8514_enabled) + if (!ibm8514_enabled || (ibm8514_enabled && ibm8514_has_vga)) return; if (machine_has_bus(machine, MACHINE_BUS_MCA)) diff --git a/src/video/vid_ati18800.c b/src/video/vid_ati18800.c index 3781ef567..5847faa39 100644 --- a/src/video/vid_ati18800.c +++ b/src/video/vid_ati18800.c @@ -62,9 +62,9 @@ typedef struct ati18800_t { static video_timings_t timing_ati18800 = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; static void -ati18800_out(uint16_t addr, uint8_t val, void *p) +ati18800_out(uint16_t addr, uint8_t val, void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_t *svga = &ati18800->svga; uint8_t old; @@ -93,6 +93,9 @@ ati18800_out(uint16_t addr, uint8_t val, void *p) case 0xb3: ati_eeprom_write(&ati18800->eeprom, val & 8, val & 2, val & 1); break; + + default: + break; } break; @@ -118,14 +121,17 @@ ati18800_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } static uint8_t -ati18800_in(uint16_t addr, void *p) +ati18800_in(uint16_t addr, void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_t *svga = &ati18800->svga; uint8_t temp = 0xff; @@ -165,7 +171,7 @@ ati18800_in(uint16_t addr, void *p) static void ati18800_recalctimings(svga_t *svga) { - ati18800_t *ati18800 = (ati18800_t *) svga->p; + const ati18800_t *ati18800 = (ati18800_t *) svga->priv; if (svga->crtc[0x17] & 4) { svga->vtotal <<= 1; @@ -193,11 +199,9 @@ ati18800_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_ati18800); switch (info->local) { -#if defined(DEV_BRANCH) && defined(USE_VGAWONDER) - case ATI18800_WONDER: -#endif default: #if defined(DEV_BRANCH) && defined(USE_VGAWONDER) + case ATI18800_WONDER: rom_init(&ati18800->bios_rom, BIOS_ROM_PATH_WONDER, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); break; #endif @@ -207,7 +211,7 @@ ati18800_init(const device_t *info) case ATI18800_EDGE16: rom_init(&ati18800->bios_rom, BIOS_ROM_PATH_EDGE16, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); break; - }; + } if (info->local == ATI18800_EDGE16) { svga_init(info, &ati18800->svga, ati18800, 1 << 18, /*256kb*/ @@ -254,9 +258,9 @@ ati18800_available(void) } static void -ati18800_close(void *p) +ati18800_close(void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_close(&ati18800->svga); @@ -264,17 +268,17 @@ ati18800_close(void *p) } static void -ati18800_speed_changed(void *p) +ati18800_speed_changed(void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_recalctimings(&ati18800->svga); } static void -ati18800_force_redraw(void *p) +ati18800_force_redraw(void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; ati18800->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ati28800.c b/src/video/vid_ati28800.c index 352ce2f7d..aa5800d1c 100644 --- a/src/video/vid_ati28800.c +++ b/src/video/vid_ati28800.c @@ -108,9 +108,9 @@ ati28800_log(const char *fmt, ...) static void ati28800_recalctimings(svga_t *svga); static void -ati28800_out(uint16_t addr, uint8_t val, void *p) +ati28800_out(uint16_t addr, uint8_t val, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_t *svga = &ati28800->svga; uint8_t old; @@ -169,6 +169,9 @@ ati28800_out(uint16_t addr, uint8_t val, void *p) if ((old ^ val) & 2) svga_recalctimings(svga); break; + + default: + break; } break; @@ -205,14 +208,17 @@ ati28800_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } static void -ati28800k_out(uint16_t addr, uint8_t val, void *p) +ati28800k_out(uint16_t addr, uint8_t val, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_t *svga = &ati28800->svga; uint16_t oldaddr = addr; @@ -225,7 +231,7 @@ ati28800k_out(uint16_t addr, uint8_t val, void *p) ati28800->ksc5601_mode_enabled = val & 0x20; svga_recalctimings(svga); } - ati28800_out(oldaddr, val, p); + ati28800_out(oldaddr, val, priv); break; case 0x3DD: ati28800->port_03dd_val = val; @@ -259,20 +265,23 @@ ati28800k_out(uint16_t addr, uint8_t val, void *p) if (val & 2) ati28800->in_get_korean_font_kind_set = 1; break; + + default: + break; } break; } break; default: - ati28800_out(oldaddr, val, p); + ati28800_out(oldaddr, val, priv); break; } } static uint8_t -ati28800_in(uint16_t addr, void *p) +ati28800_in(uint16_t addr, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_t *svga = &ati28800->svga; uint8_t temp; @@ -346,12 +355,12 @@ ati28800_in(uint16_t addr, void *p) } static uint8_t -ati28800k_in(uint16_t addr, void *p) +ati28800k_in(uint16_t addr, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; - svga_t *svga = &ati28800->svga; - uint16_t oldaddr = addr; - uint8_t temp = 0xFF; + ati28800_t *ati28800 = (ati28800_t *) priv; + const svga_t *svga = &ati28800->svga; + uint16_t oldaddr = addr; + uint8_t temp = 0xFF; if (addr != 0x3da) ati28800_log("ati28800k_in : %04X ", addr); @@ -380,7 +389,7 @@ ati28800k_in(uint16_t addr, void *p) } break; default: - temp = ati28800_in(oldaddr, p); + temp = ati28800_in(oldaddr, priv); break; } if (addr != 0x3da) @@ -391,7 +400,7 @@ ati28800k_in(uint16_t addr, void *p) static void ati28800_recalctimings(svga_t *svga) { - ati28800_t *ati28800 = (ati28800_t *) svga->p; + const ati28800_t *ati28800 = (ati28800_t *) svga->priv; if (ati28800->regs[0xa3] & 0x10) svga->ma_latch |= 0x10000; @@ -401,52 +410,52 @@ ati28800_recalctimings(svga_t *svga) switch (((ati28800->regs[0xbe] & 0x10) >> 1) | ((ati28800->regs[0xb9] & 2) << 1) | ((svga->miscout & 0x0C) >> 2)) { case 0x00: - svga->clock = (cpuclock * (double) (1ull << 32)) / 42954000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 42954000.0; break; case 0x01: - svga->clock = (cpuclock * (double) (1ull << 32)) / 48771000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 48771000.0; break; case 0x02: ati28800_log("clock 2\n"); break; case 0x03: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; case 0x04: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50350000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; break; case 0x05: - svga->clock = (cpuclock * (double) (1ull << 32)) / 56640000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 56640000.0; break; case 0x06: ati28800_log("clock 2\n"); break; case 0x07: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; break; case 0x08: - svga->clock = (cpuclock * (double) (1ull << 32)) / 30240000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 30240000.0; break; case 0x09: - svga->clock = (cpuclock * (double) (1ull << 32)) / 32000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 32000000.0; break; case 0x0A: - svga->clock = (cpuclock * (double) (1ull << 32)) / 37500000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 37500000.0; break; case 0x0B: - svga->clock = (cpuclock * (double) (1ull << 32)) / 39000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 39000000.0; break; case 0x0C: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50350000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; break; case 0x0D: - svga->clock = (cpuclock * (double) (1ull << 32)) / 56644000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 56644000.0; break; case 0x0E: - svga->clock = (cpuclock * (double) (1ull << 32)) / 75000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 75000000.0; break; case 0x0F: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; break; default: break; @@ -507,8 +516,14 @@ ati28800_recalctimings(svga_t *svga) svga->ma_latch <<= 1; } break; + + default: + break; } break; + + default: + break; } } } @@ -517,7 +532,7 @@ ati28800_recalctimings(svga_t *svga) static void ati28800k_recalctimings(svga_t *svga) { - ati28800_t *ati28800 = (ati28800_t *) svga->p; + const ati28800_t *ati28800 = (ati28800_t *) svga->priv; ati28800_recalctimings(svga); @@ -550,8 +565,8 @@ ati28800k_init(const device_t *info) ati28800->ksc5601_mode_enabled = 0; switch (ati28800->type_korean) { - case 0: default: + case 0: rom_init(&ati28800->bios_rom, BIOS_ATIKOR_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); loadfont(FONT_ATIKOR_PATH, 6); break; @@ -665,7 +680,7 @@ ati28800_init(const device_t *info) break; } - return (ati28800); + return ati28800; } static int @@ -677,20 +692,20 @@ ati28800_available(void) static int ati28800k_available(void) { - return ((rom_present(BIOS_ATIKOR_PATH) && rom_present(FONT_ATIKOR_PATH))); + return (rom_present(BIOS_ATIKOR_PATH) && rom_present(FONT_ATIKOR_PATH)); } static int compaq_ati28800_available(void) { - return ((rom_present(BIOS_VGAXL_ROM_PATH))); + return (rom_present(BIOS_VGAXL_ROM_PATH)); } #if defined(DEV_BRANCH) && defined(USE_XL24) static int ati28800_wonderxl24_available(void) { - return ((rom_present(BIOS_XL24_EVEN_PATH) && rom_present(BIOS_XL24_ODD_PATH))); + return (rom_present(BIOS_XL24_EVEN_PATH) && rom_present(BIOS_XL24_ODD_PATH)); } #endif @@ -705,9 +720,9 @@ ati28800_close(void *priv) } static void -ati28800_speed_changed(void *p) +ati28800_speed_changed(void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_recalctimings(&ati28800->svga); } diff --git a/src/video/vid_ati68860_ramdac.c b/src/video/vid_ati68860_ramdac.c index 49fad5815..5a8de5455 100644 --- a/src/video/vid_ati68860_ramdac.c +++ b/src/video/vid_ati68860_ramdac.c @@ -48,13 +48,16 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_unused.h> typedef struct ati68860_ramdac_t { uint8_t regs[16]; void (*render)(struct svga_t *svga); - int dac_addr, dac_pos; - int dac_r, dac_g; + int dac_addr; + int dac_pos; + int dac_r; + int dac_g; PALETTE pal; uint32_t pallook[2]; @@ -113,6 +116,9 @@ ati68860_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga) ramdac->dac_pos = 0; ramdac->dac_addr = (ramdac->dac_addr + 1) & 255; break; + + default: + break; } break; case 0xb: @@ -153,6 +159,9 @@ ati68860_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga) case 0xc: svga_set_ramdac_type(svga, (val & 1) ? RAMDAC_6BIT : RAMDAC_8BIT); break; + + default: + break; } break; } @@ -201,12 +210,11 @@ void ati68860_set_ramdac_type(void *p, int type) { ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) p; - int c; if (ramdac->ramdac_type != type) { ramdac->ramdac_type = type; - for (c = 0; c < 2; c++) { + for (uint8_t c = 0; c < 2; c++) { if (ramdac->ramdac_type == RAMDAC_8BIT) ramdac->pallook[c] = makecol32(ramdac->pal[c].r, ramdac->pal[c].g, ramdac->pal[c].b); @@ -218,7 +226,7 @@ ati68860_set_ramdac_type(void *p, int type) } static void * -ati68860_ramdac_init(const device_t *info) +ati68860_ramdac_init(UNUSED(const device_t *info)) { ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) malloc(sizeof(ati68860_ramdac_t)); memset(ramdac, 0, sizeof(ati68860_ramdac_t)); @@ -248,13 +256,13 @@ void ati68860_hwcursor_draw(svga_t *svga, int displine) { ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) svga->ramdac; - int x, offset; + int offset; uint8_t dat; uint32_t col0 = ramdac->pallook[0]; uint32_t col1 = ramdac->pallook[1]; offset = svga->dac_hwcursor_latch.xoff; - for (x = 0; x < 64 - svga->dac_hwcursor_latch.xoff; x += 4) { + for (uint32_t x = 0; x < 64 - svga->dac_hwcursor_latch.xoff; x += 4) { dat = svga->vram[svga->dac_hwcursor_latch.addr + (offset >> 2)]; if (!(dat & 2)) buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add] = (dat & 1) ? col1 : col0; diff --git a/src/video/vid_ati_eeprom.c b/src/video/vid_ati_eeprom.c index f1840a698..2f4746e86 100644 --- a/src/video/vid_ati_eeprom.c +++ b/src/video/vid_ati_eeprom.c @@ -26,39 +26,59 @@ #include <86box/timer.h> #include <86box/nvr.h> #include <86box/vid_ati_eeprom.h> +#include <86box/plat_fallthrough.h> void ati_eeprom_load(ati_eeprom_t *eeprom, char *fn, int type) { - FILE *f; + FILE *fp; int size; eeprom->type = type; strncpy(eeprom->fn, fn, sizeof(eeprom->fn) - 1); - f = nvr_fopen(eeprom->fn, "rb"); + fp = nvr_fopen(eeprom->fn, "rb"); size = eeprom->type ? 512 : 128; - if (!f) { + if (!fp) { memset(eeprom->data, 0xff, size); return; } - if (fread(eeprom->data, 1, size, f) != size) + if (fread(eeprom->data, 1, size, fp) != size) memset(eeprom->data, 0, size); - fclose(f); + fclose(fp); +} + +void +ati_eeprom_load_mach8(ati_eeprom_t *eeprom, char *fn) +{ + FILE *fp; + int size; + eeprom->type = 0; + strncpy(eeprom->fn, fn, sizeof(eeprom->fn) - 1); + fp = nvr_fopen(eeprom->fn, "rb"); + size = 128; + if (!fp) { /*The ATI Graphics Ultra bios expects an immediate write to nvram if none is present at boot time otherwise + it would hang the machine.*/ + memset(eeprom->data, 0, size); + fp = nvr_fopen(eeprom->fn, "wb"); + fwrite(eeprom->data, 1, size, fp); + } + if (fread(eeprom->data, 1, size, fp) != size) + memset(eeprom->data, 0, size); + fclose(fp); } void ati_eeprom_save(ati_eeprom_t *eeprom) { - FILE *f = nvr_fopen(eeprom->fn, "wb"); - if (!f) + FILE *fp = nvr_fopen(eeprom->fn, "wb"); + if (!fp) return; - fwrite(eeprom->data, 1, eeprom->type ? 512 : 128, f); - fclose(f); + fwrite(eeprom->data, 1, eeprom->type ? 512 : 128, fp); + fclose(fp); } void ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) { - int c; if (!ena) { eeprom->out = 1; } @@ -74,7 +94,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) if (!dat) break; eeprom->state = EEPROM_OPCODE; - /* fall through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case EEPROM_OPCODE: eeprom->opcode = (eeprom->opcode << 1) | (dat ? 1 : 0); eeprom->count--; @@ -100,6 +122,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) eeprom->state = EEPROM_INPUT; eeprom->dat = 0; break; + + default: + break; } } break; @@ -141,6 +166,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) case EEPROM_OP_EWEN: eeprom->wp = 0; break; + + default: + break; } eeprom->state = EEPROM_IDLE; eeprom->out = 1; @@ -157,16 +185,22 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) case EEPROM_OP_WRALMAIN: if (!eeprom->wp) { - for (c = 0; c < 256; c++) + for (uint16_t c = 0; c < 256; c++) eeprom->data[c] = eeprom->dat; ati_eeprom_save(eeprom); } eeprom->state = EEPROM_IDLE; eeprom->out = 1; break; + + default: + break; } } break; + + default: + break; } } eeprom->oldena = ena; @@ -181,6 +215,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) eeprom->state = EEPROM_IDLE; } break; + + default: + break; } } } diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index d67ff876b..c28d4c0aa 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -67,8 +67,7 @@ enum { FIFO_WRITE_DWORD = (0x03 << 24) }; -typedef struct -{ +typedef struct fifo_entry_t { uint32_t addr_type; uint32_t val; } fifo_entry_t; @@ -92,7 +91,8 @@ typedef struct mach64_t { uint8_t regs[256]; int index; - int type, pci; + int type; + int pci; uint8_t pci_regs[256]; uint8_t int_line; @@ -157,50 +157,76 @@ typedef struct mach64_t { uint32_t ovr_wid_top_bottom; uint32_t pat_cntl; - uint32_t pat_reg0, pat_reg1; + uint32_t pat_reg0; + uint32_t pat_reg1; - uint32_t sc_left_right, sc_top_bottom; + uint32_t sc_left_right; + uint32_t sc_top_bottom; - uint32_t scratch_reg0, scratch_reg1; + uint32_t scratch_reg0; + uint32_t scratch_reg1; uint32_t src_cntl; uint32_t src_off_pitch; uint32_t src_y_x; uint32_t src_y_x_start; - uint32_t src_height1_width1, src_height2_width2; + uint32_t src_height1_width1; + uint32_t src_height2_width2; uint32_t write_mask; uint32_t chain_mask; - uint32_t linear_base, old_linear_base; + uint32_t linear_base; uint32_t io_base; - struct - { + struct { int op; - int dst_x, dst_y; - int dst_x_start, dst_y_start; - int src_x, src_y; - int src_x_start, src_y_start; - int xinc, yinc; - int x_count, y_count; - int src_x_count, src_y_count; - int src_width1, src_height1; - int src_width2, src_height2; - uint32_t src_offset, src_pitch; - uint32_t dst_offset, dst_pitch; - int mix_bg, mix_fg; - int source_bg, source_fg, source_mix; + int dst_x; + int dst_y; + int dst_x_start; + int dst_y_start; + int src_x; + int src_y; + int src_x_start; + int src_y_start; + int xinc; + int yinc; + int x_count; + int y_count; + int xx_count; + int src_x_count; + int src_y_count; + int src_width1; + int src_height1; + int src_width2; + int src_height2; + uint32_t src_offset; + uint32_t src_pitch; + uint32_t dst_offset; + uint32_t dst_pitch; + int mix_bg; + int mix_fg; + int source_bg; + int source_fg; + int source_mix; int source_host; - int dst_width, dst_height; + int dst_width; + int dst_height; int busy; int pattern[8][8]; uint8_t pattern_clr4x2[2][4]; uint8_t pattern_clr8x1[8]; - int sc_left, sc_right, sc_top, sc_bottom; - int dst_pix_width, src_pix_width, host_pix_width; - int dst_size, src_size, host_size; + int sc_left; + int sc_right; + int sc_top; + int sc_bottom; + int dst_pix_width; + int src_pix_width; + int host_pix_width; + int dst_size; + int src_size; + int host_size; uint32_t dp_bkgd_clr; uint32_t dp_frgd_clr; @@ -216,7 +242,8 @@ typedef struct mach64_t { } accel; fifo_entry_t fifo[FIFO_SIZE]; - atomic_int fifo_read_idx, fifo_write_idx; + atomic_int fifo_read_idx; + atomic_int fifo_write_idx; thread_t *fifo_thread; event_t *wake_fifo_thread; @@ -237,26 +264,32 @@ typedef struct mach64_t { uint32_t config_stat0; - uint32_t cur_clr0, cur_clr1; + uint32_t cur_clr0; + uint32_t cur_clr1; uint32_t overlay_dat[1024]; - uint32_t overlay_graphics_key_clr, overlay_graphics_key_msk; - uint32_t overlay_video_key_clr, overlay_video_key_msk; + uint32_t overlay_graphics_key_clr; + uint32_t overlay_graphics_key_msk; + uint32_t overlay_video_key_clr; + uint32_t overlay_video_key_msk; uint32_t overlay_key_cntl; uint32_t overlay_scale_inc; uint32_t overlay_scale_cntl; - uint32_t overlay_y_x_start, overlay_y_x_end; + uint32_t overlay_y_x_start; + uint32_t overlay_y_x_end; uint32_t scaler_height_width; int scaler_format; int scaler_update; - uint32_t buf_offset[2], buf_pitch[2]; + uint32_t buf_offset[2]; + uint32_t buf_pitch[2]; int overlay_v_acc; uint8_t thread_run; - void *i2c, *ddc; + void *i2c; + void *ddc; } mach64_t; static video_timings_t timing_mach64_isa = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; @@ -361,9 +394,9 @@ mach64_log(const char *fmt, ...) #endif void -mach64_out(uint16_t addr, uint8_t val, void *p) +mach64_out(uint16_t addr, uint8_t val, void *priv) { - mach64_t *mach64 = p; + mach64_t *mach64 = priv; svga_t *svga = &mach64->svga; uint8_t old; @@ -425,14 +458,17 @@ mach64_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } uint8_t -mach64_in(uint16_t addr, void *p) +mach64_in(uint16_t addr, void *priv) { - mach64_t *mach64 = p; + mach64_t *mach64 = priv; svga_t *svga = &mach64->svga; if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) @@ -458,6 +494,9 @@ mach64_in(uint16_t addr, void *p) if (svga->crtcreg > 0x18) return 0xff; return svga->crtc[svga->crtcreg]; + + default: + break; } return svga_in(addr, svga); } @@ -465,7 +504,7 @@ mach64_in(uint16_t addr, void *p) void mach64_recalctimings(svga_t *svga) { - mach64_t *mach64 = (mach64_t *) svga->p; + const mach64_t *mach64 = (mach64_t *) svga->priv; if (((mach64->crtc_gen_cntl >> 24) & 3) == 3) { svga->vtotal = (mach64->crtc_v_total_disp & 2047) + 1; @@ -474,7 +513,7 @@ mach64_recalctimings(svga_t *svga) svga->hdisp_time = svga->hdisp = ((mach64->crtc_h_total_disp >> 16) & 255) + 1; svga->vsyncstart = (mach64->crtc_v_sync_strt_wid & 2047) + 1; svga->rowoffset = (mach64->crtc_off_pitch >> 22); - svga->clock = (cpuclock * (double) (1ull << 32)) / ics2595_getclock(svga->clock_gen); + svga->clock = (cpuclock * (double) (1ULL << 32)) / ics2595_getclock(svga->clock_gen); svga->ma_latch = (mach64->crtc_off_pitch & 0x1fffff) * 2; svga->linedbl = svga->rowcount = 0; svga->split = 0xffffff; @@ -487,35 +526,38 @@ mach64_recalctimings(svga_t *svga) case BPP_4: if (mach64->type != MACH64_GX) svga->render = svga_render_4bpp_highres; - svga->hdisp *= 8; + svga->hdisp <<= 3; break; case BPP_8: if (mach64->type != MACH64_GX) svga->render = svga_render_8bpp_highres; - svga->hdisp *= 8; - svga->rowoffset /= 2; + svga->hdisp <<= 3; + svga->rowoffset >>= 1; break; case BPP_15: if (mach64->type != MACH64_GX) svga->render = svga_render_15bpp_highres; - svga->hdisp *= 8; + svga->hdisp <<= 3; break; case BPP_16: if (mach64->type != MACH64_GX) svga->render = svga_render_16bpp_highres; - svga->hdisp *= 8; + svga->hdisp <<= 3; break; case BPP_24: if (mach64->type != MACH64_GX) svga->render = svga_render_24bpp_highres; - svga->hdisp *= 8; + svga->hdisp <<= 3; svga->rowoffset = (svga->rowoffset * 3) / 2; break; case BPP_32: if (mach64->type != MACH64_GX) svga->render = svga_render_32bpp_highres; - svga->hdisp *= 8; - svga->rowoffset *= 2; + svga->hdisp <<= 3; + svga->rowoffset <<= 1; + break; + + default: break; } @@ -530,7 +572,7 @@ mach64_updatemapping(mach64_t *mach64) { svga_t *svga = &mach64->svga; - if (!(mach64->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM)) { + if (mach64->pci && !(mach64->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM)) { mach64_log("Update mapping - PCI disabled\n"); mem_mapping_disable(&svga->mapping); mem_mapping_disable(&mach64->linear_mapping); @@ -543,31 +585,36 @@ mach64_updatemapping(mach64_t *mach64) mem_mapping_disable(&mach64->mmio_mapping); switch (svga->gdcreg[6] & 0xc) { case 0x0: /*128k at A0000*/ - mem_mapping_set_handler(&mach64->svga.mapping, mach64_read, mach64_readw, mach64_readl, mach64_write, mach64_writew, mach64_writel); - mem_mapping_set_p(&mach64->svga.mapping, mach64); + mem_mapping_set_handler(&svga->mapping, mach64_read, mach64_readw, mach64_readl, mach64_write, mach64_writew, mach64_writel); + mem_mapping_set_p(&svga->mapping, mach64); mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x20000); mem_mapping_enable(&mach64->mmio_mapping); svga->banked_mask = 0xffff; break; case 0x4: /*64k at A0000*/ - mem_mapping_set_handler(&mach64->svga.mapping, mach64_read, mach64_readw, mach64_readl, mach64_write, mach64_writew, mach64_writel); - mem_mapping_set_p(&mach64->svga.mapping, mach64); + mem_mapping_set_handler(&svga->mapping, mach64_read, mach64_readw, mach64_readl, mach64_write, mach64_writew, mach64_writel); + mem_mapping_set_p(&svga->mapping, mach64); mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x10000); svga->banked_mask = 0xffff; break; case 0x8: /*32k at B0000*/ - mem_mapping_set_handler(&mach64->svga.mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); - mem_mapping_set_p(&mach64->svga.mapping, svga); + mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); + mem_mapping_set_p(&svga->mapping, svga); mem_mapping_set_addr(&svga->mapping, 0xb0000, 0x08000); svga->banked_mask = 0x7fff; break; case 0xC: /*32k at B8000*/ - mem_mapping_set_handler(&mach64->svga.mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); - mem_mapping_set_p(&mach64->svga.mapping, svga); + mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); + mem_mapping_set_p(&svga->mapping, svga); mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); svga->banked_mask = 0x7fff; break; + + default: + break; } + + mach64_log("Mach64 linear aperture = %08x.\n", mach64->linear_base); if (mach64->linear_base) { if (mach64->type == MACH64_GX) { if ((mach64->config_cntl & 3) == 2) { @@ -691,7 +738,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) case 0x11e: case 0x11f: WRITE8(addr, mach64->dst_height_width, val); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x113: if (((addr & 0x3ff) == 0x11b || (addr & 0x3ff) == 0x11f || (addr & 0x3ff) == 0x113) && !(val & 0x80)) { mach64_start_fill(mach64); @@ -914,7 +963,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) case 0x2a4: case 0x2a5: addr += 2; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x2aa: case 0x2ab: WRITE8(addr, mach64->sc_left_right, val); @@ -929,7 +980,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) case 0x2b0: case 0x2b1: addr += 2; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x2b6: case 0x2b7: WRITE8(addr, mach64->sc_top_bottom, val); @@ -1019,6 +1072,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) else mach64->host_cntl &= ~HOST_BYTE_ALIGN; break; + + default: + break; } } static void @@ -1179,12 +1235,15 @@ mach64_queue(mach64_t *mach64, uint32_t addr, uint32_t val, uint32_t type) void mach64_start_fill(mach64_t *mach64) { - int x, y; + mach64->accel.dst_x = 0; + mach64->accel.dst_y = 0; - mach64->accel.dst_x = 0; - mach64->accel.dst_y = 0; mach64->accel.dst_x_start = (mach64->dst_y_x >> 16) & 0xfff; - mach64->accel.dst_y_start = mach64->dst_y_x & 0xfff; + if ((mach64->dst_y_x >> 16) & 0x1000) + mach64->accel.dst_x_start |= ~0xfff; + mach64->accel.dst_y_start = mach64->dst_y_x & 0x3fff; + if (mach64->dst_y_x & 0x4000) + mach64->accel.dst_y_start |= ~0x3fff; mach64->accel.dst_width = (mach64->dst_height_width >> 16) & 0x1fff; mach64->accel.dst_height = mach64->dst_height_width & 0x1fff; @@ -1194,12 +1253,19 @@ mach64_start_fill(mach64_t *mach64) mach64->accel.dst_width = (mach64->accel.dst_width & ~7) + 8; } - mach64->accel.x_count = mach64->accel.dst_width; + mach64->accel.x_count = mach64->accel.dst_width; + mach64->accel.xx_count = 0; + + mach64->accel.src_x = 0; + mach64->accel.src_y = 0; - mach64->accel.src_x = 0; - mach64->accel.src_y = 0; mach64->accel.src_x_start = (mach64->src_y_x >> 16) & 0xfff; - mach64->accel.src_y_start = mach64->src_y_x & 0xfff; + if ((mach64->src_y_x >> 16) & 0x1000) + mach64->accel.src_x_start |= ~0xfff; + mach64->accel.src_y_start = mach64->src_y_x & 0x3fff; + if (mach64->src_y_x & 0x4000) + mach64->accel.src_y_start |= ~0x3fff; + if (mach64->src_cntl & SRC_LINEAR_EN) mach64->accel.src_x_count = 0x7ffffff; /*Essentially infinite*/ else @@ -1221,11 +1287,11 @@ mach64_start_fill(mach64_t *mach64) mach64->src_height1_width1, mach64->src_height2_width2); - mach64->accel.src_pitch = (mach64->src_off_pitch >> 22) * 8; - mach64->accel.src_offset = (mach64->src_off_pitch & 0xfffff) * 8; + mach64->accel.src_pitch = (mach64->src_off_pitch >> 22) << 3; + mach64->accel.src_offset = (mach64->src_off_pitch & 0xfffff) << 3; - mach64->accel.dst_pitch = (mach64->dst_off_pitch >> 22) * 8; - mach64->accel.dst_offset = (mach64->dst_off_pitch & 0xfffff) * 8; + mach64->accel.dst_pitch = (mach64->dst_off_pitch >> 22) << 3; + mach64->accel.dst_offset = (mach64->dst_off_pitch & 0xfffff) << 3; mach64->accel.mix_fg = (mach64->dp_mix >> 16) & 0x1f; mach64->accel.mix_bg = mach64->dp_mix & 0x1f; @@ -1257,8 +1323,8 @@ mach64_start_fill(mach64_t *mach64) mach64->accel.source_host = ((mach64->dp_src & 7) == SRC_HOST) || (((mach64->dp_src >> 8) & 7) == SRC_HOST); - for (y = 0; y < 8; y++) { - for (x = 0; x < 8; x++) { + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t x = 0; x < 8; x++) { uint32_t temp = (y & 4) ? mach64->pat_reg1 : mach64->pat_reg0; mach64->accel.pattern[y][7 - x] = (temp >> (x + ((y & 3) * 8))) & 1; } @@ -1309,19 +1375,25 @@ mach64_start_fill(mach64_t *mach64) void mach64_start_line(mach64_t *mach64) { - int x, y; - mach64->accel.dst_x = (mach64->dst_y_x >> 16) & 0xfff; - mach64->accel.dst_y = mach64->dst_y_x & 0xfff; + if ((mach64->dst_y_x >> 16) & 0x1000) + mach64->accel.dst_x |= ~0xfff; + mach64->accel.dst_y = mach64->dst_y_x & 0x3fff; + if (mach64->dst_y_x & 0x4000) + mach64->accel.dst_y |= ~0x3fff; mach64->accel.src_x = (mach64->src_y_x >> 16) & 0xfff; - mach64->accel.src_y = mach64->src_y_x & 0xfff; + if ((mach64->src_y_x >> 16) & 0x1000) + mach64->accel.src_x |= ~0xfff; + mach64->accel.src_y = mach64->src_y_x & 0x3fff; + if (mach64->src_y_x & 0x4000) + mach64->accel.src_y |= ~0x3fff; - mach64->accel.src_pitch = (mach64->src_off_pitch >> 22) * 8; - mach64->accel.src_offset = (mach64->src_off_pitch & 0xfffff) * 8; + mach64->accel.src_pitch = (mach64->src_off_pitch >> 22) << 3; + mach64->accel.src_offset = (mach64->src_off_pitch & 0xfffff) << 3; - mach64->accel.dst_pitch = (mach64->dst_off_pitch >> 22) * 8; - mach64->accel.dst_offset = (mach64->dst_off_pitch & 0xfffff) * 8; + mach64->accel.dst_pitch = (mach64->dst_off_pitch >> 22) << 3; + mach64->accel.dst_offset = (mach64->dst_off_pitch & 0xfffff) << 3; mach64->accel.mix_fg = (mach64->dp_mix >> 16) & 0x1f; mach64->accel.mix_bg = mach64->dp_mix & 0x1f; @@ -1348,13 +1420,10 @@ mach64_start_line(mach64_t *mach64) else mach64->accel.dst_offset >>= mach64->accel.dst_size; - /* mach64->accel.src_pitch *= mach64_inc[mach64->accel.src_pix_width]; - mach64->accel.dst_pitch *= mach64_inc[mach64->accel.dst_pix_width];*/ - mach64->accel.source_host = ((mach64->dp_src & 7) == SRC_HOST) || (((mach64->dp_src >> 8) & 7) == SRC_HOST); - for (y = 0; y < 8; y++) { - for (x = 0; x < 8; x++) { + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t x = 0; x < 8; x++) { uint32_t temp = (y & 4) ? mach64->pat_reg1 : mach64->pat_reg0; mach64->accel.pattern[y][7 - x] = (temp >> (x + ((y & 3) * 8))) & 1; } @@ -1450,6 +1519,7 @@ mach64_start_line(mach64_t *mach64) break; \ case 0x17: \ dest_dat = (dest_dat + src_dat) >> 1; \ + break; \ } #define WRITE(addr, width) \ @@ -1487,23 +1557,31 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mach64_log("mach64_blit : return as not busy\n"); return; } + switch (mach64->accel.op) { case OP_RECT: while (count) { - uint32_t src_dat = 0, dest_dat; + uint8_t write_mask = 0; + uint32_t src_dat = 0; + uint32_t dest_dat; uint32_t host_dat = 0; uint32_t old_dest_dat; - int mix = 0; - int dst_x = (mach64->accel.dst_x + mach64->accel.dst_x_start) & 0xfff; - int dst_y = (mach64->accel.dst_y + mach64->accel.dst_y_start) & 0xfff; + int mix = 0; + int dst_x; + int dst_y; int src_x; - int src_y = (mach64->accel.src_y + mach64->accel.src_y_start) & 0xfff; + int src_y; + + dst_x = (mach64->accel.dst_x + mach64->accel.dst_x_start) & 0xfff; + dst_y = (mach64->accel.dst_y + mach64->accel.dst_y_start) & 0x3fff; if (mach64->src_cntl & SRC_LINEAR_EN) src_x = mach64->accel.src_x; else src_x = (mach64->accel.src_x + mach64->accel.src_x_start) & 0xfff; + src_y = (mach64->accel.src_y + mach64->accel.src_y_start) & 0x3fff; + if (mach64->accel.source_host) { host_dat = cpu_dat; switch (mach64->accel.host_size) { @@ -1518,6 +1596,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 2: count -= 32; break; + + default: + break; } } else count--; @@ -1528,7 +1609,7 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mix = cpu_dat & 1; cpu_dat >>= 1; } else { - mix = cpu_dat >> 31; + mix = cpu_dat >> 0x1f; cpu_dat <<= 1; } break; @@ -1545,6 +1626,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) READ(mach64->accel.src_offset + (src_y * mach64->accel.src_pitch) + src_x, mix, WIDTH_1BIT); } break; + + default: + break; } if (dst_x >= mach64->accel.sc_left && dst_x <= mach64->accel.sc_right && dst_y >= mach64->accel.sc_top && dst_y <= mach64->accel.sc_bottom) { @@ -1556,24 +1640,42 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) READ(mach64->accel.src_offset + (src_y * mach64->accel.src_pitch) + src_x, src_dat, mach64->accel.src_size); break; case SRC_FG: - if ((mach64->dst_cntl & (DST_LAST_PEL | DST_X_DIR | DST_Y_DIR | DST_24_ROT_EN)) == (DST_LAST_PEL | DST_X_DIR | DST_Y_DIR | DST_24_ROT_EN)) { - if ((mach64->accel.x_count % 3) == 2) - src_dat = mach64->accel.dp_frgd_clr & 0xff; - else if ((mach64->accel.x_count % 3) == 1) - src_dat = (mach64->accel.dp_frgd_clr >> 8) & 0xff; - else if ((mach64->accel.x_count % 3) == 0) - src_dat = (mach64->accel.dp_frgd_clr >> 16) & 0xff; + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) { + if (mach64->accel.xinc == -1) { + if ((mach64->accel.xx_count % 3) == 2) + src_dat = mach64->accel.dp_frgd_clr & 0xff; + else if ((mach64->accel.xx_count % 3) == 1) + src_dat = (mach64->accel.dp_frgd_clr >> 8) & 0xff; + else + src_dat = (mach64->accel.dp_frgd_clr >> 16) & 0xff; + } else { + if ((mach64->accel.xx_count % 3) == 2) + src_dat = (mach64->accel.dp_frgd_clr >> 16) & 0xff; + else if ((mach64->accel.xx_count % 3) == 1) + src_dat = (mach64->accel.dp_frgd_clr >> 8) & 0xff; + else + src_dat = mach64->accel.dp_frgd_clr & 0xff; + } } else src_dat = mach64->accel.dp_frgd_clr; break; case SRC_BG: - if ((mach64->dst_cntl & (DST_LAST_PEL | DST_X_DIR | DST_Y_DIR | DST_24_ROT_EN)) == (DST_LAST_PEL | DST_X_DIR | DST_Y_DIR | DST_24_ROT_EN)) { - if ((mach64->accel.x_count % 3) == 2) - src_dat = mach64->accel.dp_bkgd_clr & 0xff; - else if ((mach64->accel.x_count % 3) == 1) - src_dat = (mach64->accel.dp_bkgd_clr >> 8) & 0xff; - else if ((mach64->accel.x_count % 3) == 0) - src_dat = (mach64->accel.dp_bkgd_clr >> 16) & 0xff; + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) { + if (mach64->accel.xinc == -1) { + if ((mach64->accel.xx_count % 3) == 2) + src_dat = mach64->accel.dp_bkgd_clr & 0xff; + else if ((mach64->accel.xx_count % 3) == 1) + src_dat = (mach64->accel.dp_bkgd_clr >> 8) & 0xff; + else + src_dat = (mach64->accel.dp_bkgd_clr >> 16) & 0xff; + } else { + if ((mach64->accel.xx_count % 3) == 2) + src_dat = (mach64->accel.dp_bkgd_clr >> 16) & 0xff; + else if ((mach64->accel.xx_count % 3) == 1) + src_dat = (mach64->accel.dp_bkgd_clr >> 8) & 0xff; + else + src_dat = mach64->accel.dp_bkgd_clr & 0xff; + } } else src_dat = mach64->accel.dp_bkgd_clr; break; @@ -1598,7 +1700,7 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) } if (!(mach64->dst_cntl & DST_POLYGON_EN) || mach64->accel.poly_draw) { - READ(mach64->accel.dst_offset + (dst_y * mach64->accel.dst_pitch) + dst_x, dest_dat, mach64->accel.dst_size); + READ(mach64->accel.dst_offset + ((dst_y) *mach64->accel.dst_pitch) + (dst_x), dest_dat, mach64->accel.dst_size); switch (mach64->accel.clr_cmp_fn) { case 1: /*TRUE*/ @@ -1610,24 +1712,38 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 5: /*DST_CLR == CLR_CMP_CLR*/ cmp_clr = (((mach64->accel.clr_cmp_src) ? src_dat : dest_dat) & mach64->accel.clr_cmp_mask) == mach64->accel.clr_cmp_clr; break; + + default: + break; } if (!cmp_clr) { old_dest_dat = dest_dat; MIX - dest_dat - = (dest_dat & mach64->accel.write_mask) | (old_dest_dat & ~mach64->accel.write_mask); + + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) { + if (mach64->accel.xinc == -1) { + if ((mach64->accel.xx_count % 3) == 2) + write_mask = mach64->accel.write_mask & 0xff; + else if ((mach64->accel.xx_count % 3) == 1) + write_mask = (mach64->accel.write_mask >> 8) & 0xff; + else + write_mask = (mach64->accel.write_mask >> 16) & 0xff; + } else { + if ((mach64->accel.xx_count % 3) == 2) + write_mask = (mach64->accel.write_mask >> 16) & 0xff; + else if ((mach64->accel.xx_count % 3) == 1) + write_mask = (mach64->accel.write_mask >> 8) & 0xff; + else + write_mask = mach64->accel.write_mask & 0xff; + } + dest_dat = (dest_dat & write_mask) | (old_dest_dat & ~write_mask); + } else { + dest_dat = (dest_dat & mach64->accel.write_mask) | (old_dest_dat & ~mach64->accel.write_mask); + } } - WRITE(mach64->accel.dst_offset + (dst_y * mach64->accel.dst_pitch) + dst_x, mach64->accel.dst_size); - } - } - - if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) { - if ((mach64->dst_cntl & (DST_LAST_PEL | DST_X_DIR | DST_Y_DIR | DST_24_ROT_EN)) != (DST_LAST_PEL | DST_X_DIR | DST_Y_DIR | DST_24_ROT_EN)) { - mach64->accel.dp_frgd_clr = ((mach64->accel.dp_frgd_clr >> 8) & 0xffff) | (mach64->accel.dp_frgd_clr << 16); - mach64->accel.dp_bkgd_clr = ((mach64->accel.dp_bkgd_clr >> 8) & 0xffff) | (mach64->accel.dp_bkgd_clr << 16); - mach64->accel.write_mask = ((mach64->accel.write_mask >> 8) & 0xffff) | (mach64->accel.write_mask << 16); + WRITE(mach64->accel.dst_offset + ((dst_y) * mach64->accel.dst_pitch) + (dst_x), mach64->accel.dst_size); } } @@ -1639,16 +1755,20 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mach64->accel.src_x = 0; if ((mach64->src_cntl & (SRC_PATT_ROT_EN | SRC_PATT_EN)) == (SRC_PATT_ROT_EN | SRC_PATT_EN)) { mach64->accel.src_x_start = (mach64->src_y_x_start >> 16) & 0xfff; + if ((mach64->src_y_x_start >> 16) & 0x1000) + mach64->accel.src_x_start |= ~0xfff; mach64->accel.src_x_count = mach64->accel.src_width2; } else mach64->accel.src_x_count = mach64->accel.src_width1; } } + mach64->accel.xx_count++; mach64->accel.x_count--; if (mach64->accel.x_count <= 0) { - mach64->accel.x_count = mach64->accel.dst_width; - mach64->accel.dst_x = 0; + mach64->accel.xx_count = 0; + mach64->accel.x_count = mach64->accel.dst_width; + mach64->accel.dst_x = 0; mach64->accel.dst_y += mach64->accel.yinc; mach64->accel.src_x_start = (mach64->src_y_x >> 16) & 0xfff; mach64->accel.src_x_count = mach64->accel.src_width1; @@ -1660,7 +1780,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) if (mach64->accel.src_y_count <= 0) { mach64->accel.src_y = 0; if ((mach64->src_cntl & (SRC_PATT_ROT_EN | SRC_PATT_EN)) == (SRC_PATT_ROT_EN | SRC_PATT_EN)) { - mach64->accel.src_y_start = mach64->src_y_x_start & 0xfff; + mach64->accel.src_y_start = mach64->src_y_x_start & 0x3fff; + if (mach64->src_y_x_start & 0x4000) + mach64->accel.src_y_start |= ~0x3fff; mach64->accel.src_y_count = mach64->accel.src_height2; } else mach64->accel.src_y_count = mach64->accel.src_height1; @@ -1698,13 +1820,14 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) { int x = 0; while (count) { - uint32_t src_dat = 0, dest_dat; + uint32_t src_dat = 0; + uint32_t dest_dat; uint32_t host_dat = 0; int mix = 0; if (mach64->accel.source_host) { host_dat = cpu_dat; - switch (mach64->accel.src_size) { + switch (mach64->accel.host_size) { case 0: cpu_dat >>= 8; count -= 8; @@ -1716,6 +1839,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 2: count -= 32; break; + + default: + break; } } else count--; @@ -1739,6 +1865,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case MONO_SRC_BLITSRC: READ(mach64->accel.src_offset + (mach64->accel.src_y * mach64->accel.src_pitch) + mach64->accel.src_x, mix, WIDTH_1BIT); break; + + default: + break; } if ((mach64->accel.dst_x >= mach64->accel.sc_left) && (mach64->accel.dst_x <= mach64->accel.sc_right) && (mach64->accel.dst_y >= mach64->accel.sc_top) && (mach64->accel.dst_y <= mach64->accel.sc_bottom)) { @@ -1780,17 +1909,18 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 5: /*DST_CLR == CLR_CMP_CLR*/ cmp_clr = (((mach64->accel.clr_cmp_src) ? src_dat : dest_dat) & mach64->accel.clr_cmp_mask) == mach64->accel.clr_cmp_clr; break; + + default: + break; } if (!cmp_clr) MIX - if (!(mach64->dst_cntl & DST_Y_MAJOR)) - { - if (x == 0) - dest_dat &= ~1; - } - else { + if (!(mach64->dst_cntl & DST_Y_MAJOR)) { + if (!x) + dest_dat &= ~1; + } else { if (x == (mach64->accel.x_count - 1)) dest_dat &= ~1; } @@ -1825,14 +1955,15 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) } } else { while (count) { - uint32_t src_dat = 0, dest_dat; + uint32_t src_dat = 0; + uint32_t dest_dat; uint32_t host_dat = 0; int mix = 0; int draw_pixel = !(mach64->dst_cntl & DST_POLYGON_EN); if (mach64->accel.source_host) { host_dat = cpu_dat; - switch (mach64->accel.src_size) { + switch (mach64->accel.host_size) { case 0: cpu_dat >>= 8; count -= 8; @@ -1844,6 +1975,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 2: count -= 32; break; + + default: + break; } } else count--; @@ -1905,12 +2039,15 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 5: /*DST_CLR == CLR_CMP_CLR*/ cmp_clr = (((mach64->accel.clr_cmp_src) ? src_dat : dest_dat) & mach64->accel.clr_cmp_mask) == mach64->accel.clr_cmp_clr; break; + + default: + break; } if (!cmp_clr) MIX - WRITE(mach64->accel.dst_offset + (mach64->accel.dst_y * mach64->accel.dst_pitch) + mach64->accel.dst_x, mach64->accel.dst_size); + WRITE(mach64->accel.dst_offset + (mach64->accel.dst_y * mach64->accel.dst_pitch) + mach64->accel.dst_x, mach64->accel.dst_size); } mach64->accel.x_count--; @@ -1942,6 +2079,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mach64->accel.src_y++; mach64->accel.dst_y++; break; + + default: + break; } mach64_log("x %i y %i err %i inc %i dec %i\n", mach64->accel.dst_x, mach64->accel.dst_y, mach64->accel.err, mach64->dst_bres_inc, mach64->dst_bres_dec); if (mach64->accel.err >= 0) { @@ -1968,12 +2108,18 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mach64->accel.src_x++; mach64->accel.dst_x++; break; + + default: + break; } } else mach64->accel.err += mach64->dst_bres_inc; } } break; + + default: + break; } } @@ -2052,8 +2198,6 @@ mach64_load_context(mach64_t *mach64) static void pll_write(mach64_t *mach64, uint32_t addr, uint8_t val) { - int c; - switch (addr & 3) { case 0: /*Clock sel*/ break; @@ -2064,7 +2208,7 @@ pll_write(mach64_t *mach64, uint32_t addr, uint8_t val) mach64->pll_regs[mach64->pll_addr] = val; mach64_log("pll_write %02x,%02x\n", mach64->pll_addr, val); - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { double m = (double) mach64->pll_regs[PLL_REF_DIV]; double n = (double) mach64->pll_regs[VCLK0_FB_DIV + c]; double r = 14318184.0; @@ -2075,6 +2219,9 @@ pll_write(mach64_t *mach64, uint32_t addr, uint8_t val) mach64_log(" %g\n", mach64->pll_freq[c]); } break; + + default: + break; } } @@ -2082,7 +2229,7 @@ pll_write(mach64_t *mach64, uint32_t addr, uint8_t val) static void mach64_vblank_start(svga_t *svga) { - mach64_t *mach64 = (mach64_t *) svga->p; + mach64_t *mach64 = (mach64_t *) svga->priv; int overlay_cmp_mix = (mach64->overlay_key_cntl >> 8) & 0xf; mach64->crtc_int_cntl |= 4; @@ -2104,9 +2251,9 @@ mach64_vblank_start(svga_t *svga) } uint8_t -mach64_ext_readb(uint32_t addr, void *p) +mach64_ext_readb(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint8_t ret = 0xff; if (!(addr & 0x400)) { @@ -2350,6 +2497,7 @@ mach64_ext_readb(uint32_t addr, void *p) mach64->config_cntl = (mach64->config_cntl & ~0x3ff0) | ((mach64->linear_base >> 22) << 4); else mach64->config_cntl = (mach64->config_cntl & ~0x3ff0) | ((mach64->linear_base >> 24) << 4); + READ8(addr, mach64->config_cntl); break; case 0xe0: @@ -2670,11 +2818,15 @@ mach64_ext_readb(uint32_t addr, void *p) case 0x310: case 0x311: - if (!FIFO_EMPTY) - wake_fifo_thread(mach64); - ret = 0; - if (FIFO_FULL) - ret = 0xff; + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) { + ret = 0; + } else { + if (!FIFO_EMPTY) + wake_fifo_thread(mach64); + ret = 0; + if (FIFO_FULL) + ret = 0xff; + } break; case 0x320: @@ -2700,7 +2852,10 @@ mach64_ext_readb(uint32_t addr, void *p) break; case 0x338: - ret = FIFO_EMPTY ? 0 : 1; + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) + ret = 0; + else + ret = FIFO_EMPTY ? 0 : 1; break; default: @@ -2712,10 +2867,11 @@ mach64_ext_readb(uint32_t addr, void *p) return ret; } uint16_t -mach64_ext_readw(uint32_t addr, void *p) +mach64_ext_readw(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + const mach64_t *mach64 = (mach64_t *) priv; uint16_t ret; + if (!(addr & 0x400)) { mach64_log("nmach64_ext_readw: addr=%04x\n", addr); ret = 0xffff; @@ -2731,8 +2887,8 @@ mach64_ext_readw(uint32_t addr, void *p) break; default: - ret = mach64_ext_readb(addr, p); - ret |= mach64_ext_readb(addr + 1, p) << 8; + ret = mach64_ext_readb(addr, priv); + ret |= mach64_ext_readb(addr + 1, priv) << 8; break; } if ((addr & 0x3fc) != 0x018) @@ -2740,10 +2896,11 @@ mach64_ext_readw(uint32_t addr, void *p) return ret; } uint32_t -mach64_ext_readl(uint32_t addr, void *p) +mach64_ext_readl(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; - uint32_t ret; + const mach64_t *mach64 = (mach64_t *) priv; + uint32_t ret; + if (!(addr & 0x400)) { mach64_log("nmach64_ext_readl: addr=%04x\n", addr); ret = 0xffffffff; @@ -2763,8 +2920,8 @@ mach64_ext_readl(uint32_t addr, void *p) break; default: - ret = mach64_ext_readw(addr, p); - ret |= mach64_ext_readw(addr + 2, p) << 16; + ret = mach64_ext_readw(addr, priv); + ret |= mach64_ext_readw(addr + 2, priv) << 16; break; } if ((addr & 0x3fc) != 0x018) @@ -2773,9 +2930,9 @@ mach64_ext_readl(uint32_t addr, void *p) } void -mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) +mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; mach64_log("mach64_ext_writeb : addr %08X val %02X\n", addr, val); @@ -2875,11 +3032,17 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) case 0xa7: WRITE8(addr, mach64->buf_pitch[1], val); break; + + default: + break; } mach64_log("nmach64_ext_writeb: addr=%04x val=%02x\n", addr, val); } else if (addr & 0x300) { - mach64_queue(mach64, addr & 0x3ff, val, FIFO_WRITE_BYTE); + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) + mach64_accel_write_fifo(mach64, addr & 0x3ff, val); + else + mach64_queue(mach64, addr & 0x3ff, val, FIFO_WRITE_BYTE); } else switch (addr & 0x3ff) { case 0x00: @@ -3089,55 +3252,64 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) if (mach64->type != MACH64_GX) WRITE8(addr, mach64->config_stat0, val); break; - } -} -void -mach64_ext_writew(uint32_t addr, uint16_t val, void *p) -{ - mach64_t *mach64 = (mach64_t *) p; - mach64_log("mach64_ext_writew : addr %08X val %04X\n", addr, val); - if (!(addr & 0x400)) { - mach64_log("mach64_ext_writew: addr=%04x val=%04x\n", addr, val); - mach64_ext_writeb(addr, val, p); - mach64_ext_writeb(addr + 1, val >> 8, p); - } else if (addr & 0x300) { - mach64_queue(mach64, addr & 0x3fe, val, FIFO_WRITE_WORD); - } else - switch (addr & 0x3fe) { default: - mach64_ext_writeb(addr, val, p); - mach64_ext_writeb(addr + 1, val >> 8, p); break; } } void -mach64_ext_writel(uint32_t addr, uint32_t val, void *p) +mach64_ext_writew(uint32_t addr, uint16_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; + mach64_log("mach64_ext_writew : addr %08X val %04X\n", addr, val); + if (!(addr & 0x400)) { + mach64_log("mach64_ext_writew: addr=%04x val=%04x\n", addr, val); + + mach64_ext_writeb(addr, val, priv); + mach64_ext_writeb(addr + 1, val >> 8, priv); + } else if (addr & 0x300) { + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) + mach64_accel_write_fifo_w(mach64, addr & 0x3fe, val); + else + mach64_queue(mach64, addr & 0x3fe, val, FIFO_WRITE_WORD); + } else + switch (addr & 0x3fe) { + default: + mach64_ext_writeb(addr, val, priv); + mach64_ext_writeb(addr + 1, val >> 8, priv); + break; + } +} +void +mach64_ext_writel(uint32_t addr, uint32_t val, void *priv) +{ + mach64_t *mach64 = (mach64_t *) priv; if ((addr & 0x3c0) != 0x200) mach64_log("mach64_ext_writel : addr %08X val %08X\n", addr, val); if (!(addr & 0x400)) { mach64_log("mach64_ext_writel: addr=%04x val=%08x\n", addr, val); - mach64_ext_writew(addr, val, p); - mach64_ext_writew(addr + 2, val >> 16, p); + mach64_ext_writew(addr, val, priv); + mach64_ext_writew(addr + 2, val >> 16, priv); } else if (addr & 0x300) { - mach64_queue(mach64, addr & 0x3fc, val, FIFO_WRITE_DWORD); + if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) + mach64_accel_write_fifo_l(mach64, addr & 0x3fc, val); + else + mach64_queue(mach64, addr & 0x3fc, val, FIFO_WRITE_DWORD); } else switch (addr & 0x3fc) { default: - mach64_ext_writew(addr, val, p); - mach64_ext_writew(addr + 2, val >> 16, p); + mach64_ext_writew(addr, val, priv); + mach64_ext_writew(addr + 2, val >> 16, priv); break; } } uint8_t -mach64_ext_inb(uint16_t port, void *p) +mach64_ext_inb(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; - uint8_t ret; + mach64_t *mach64 = (mach64_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x02ec: @@ -3148,135 +3320,135 @@ mach64_ext_inb(uint16_t port, void *p) case 0x7eed: case 0x7eee: case 0x7eef: - ret = mach64_ext_readb(0x400 | 0x00 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x00 | (port & 3), priv); break; case 0x0aec: case 0x0aed: case 0x0aee: case 0x0aef: - ret = mach64_ext_readb(0x400 | 0x08 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x08 | (port & 3), priv); break; case 0x0eec: case 0x0eed: case 0x0eee: case 0x0eef: - ret = mach64_ext_readb(0x400 | 0x0c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x0c | (port & 3), priv); break; case 0x12ec: case 0x12ed: case 0x12ee: case 0x12ef: - ret = mach64_ext_readb(0x400 | 0x10 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x10 | (port & 3), priv); break; case 0x16ec: case 0x16ed: case 0x16ee: case 0x16ef: - ret = mach64_ext_readb(0x400 | 0x14 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x14 | (port & 3), priv); break; case 0x1aec: - ret = mach64_ext_readb(0x400 | 0x18, p); + ret = mach64_ext_readb(0x400 | 0x18, priv); break; case 0x1eec: case 0x1eed: case 0x1eee: case 0x1eef: - ret = mach64_ext_readb(0x400 | 0x1c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x1c | (port & 3), priv); break; case 0x22ec: case 0x22ed: case 0x22ee: case 0x22ef: - ret = mach64_ext_readb(0x400 | 0x40 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x40 | (port & 3), priv); break; case 0x26ec: case 0x26ed: case 0x26ee: case 0x26ef: - ret = mach64_ext_readb(0x400 | 0x44 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x44 | (port & 3), priv); break; case 0x2aec: case 0x2aed: case 0x2aee: case 0x2aef: - ret = mach64_ext_readb(0x400 | 0x48 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x48 | (port & 3), priv); break; case 0x2eec: case 0x2eed: case 0x2eee: case 0x2eef: - ret = mach64_ext_readb(0x400 | 0x60 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x60 | (port & 3), priv); break; case 0x32ec: case 0x32ed: case 0x32ee: case 0x32ef: - ret = mach64_ext_readb(0x400 | 0x64 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x64 | (port & 3), priv); break; case 0x36ec: case 0x36ed: case 0x36ee: case 0x36ef: - ret = mach64_ext_readb(0x400 | 0x68 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x68 | (port & 3), priv); break; case 0x3aec: case 0x3aed: case 0x3aee: case 0x3aef: - ret = mach64_ext_readb(0x400 | 0x6c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x6c | (port & 3), priv); break; case 0x3eec: case 0x3eed: case 0x3eee: case 0x3eef: - ret = mach64_ext_readb(0x400 | 0x70 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x70 | (port & 3), priv); break; case 0x42ec: case 0x42ed: case 0x42ee: case 0x42ef: - ret = mach64_ext_readb(0x400 | 0x80 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x80 | (port & 3), priv); break; case 0x46ec: case 0x46ed: case 0x46ee: case 0x46ef: - ret = mach64_ext_readb(0x400 | 0x84 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x84 | (port & 3), priv); break; case 0x4aec: case 0x4aed: case 0x4aee: case 0x4aef: - ret = mach64_ext_readb(0x400 | 0x90 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x90 | (port & 3), priv); break; case 0x52ec: case 0x52ed: case 0x52ee: case 0x52ef: - ret = mach64_ext_readb(0x400 | 0xb0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xb0 | (port & 3), priv); break; case 0x56ec: - ret = mach64_ext_readb(0x400 | 0xb4, p); + ret = mach64_ext_readb(0x400 | 0xb4, priv); break; case 0x56ed: case 0x56ee: - ret = mach64_ext_readb(0x400 | 0xb5, p); + ret = mach64_ext_readb(0x400 | 0xb5, priv); break; case 0x5aec: - ret = mach64_ext_readb(0x400 | 0xb8, p); + ret = mach64_ext_readb(0x400 | 0xb8, priv); break; case 0x5aed: case 0x5aee: - ret = mach64_ext_readb(0x400 | 0xb9, p); + ret = mach64_ext_readb(0x400 | 0xb9, priv); break; case 0x5eec: @@ -3293,14 +3465,14 @@ mach64_ext_inb(uint16_t port, void *p) case 0x62ed: case 0x62ee: case 0x62ef: - ret = mach64_ext_readb(0x400 | 0xc4 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xc4 | (port & 3), priv); break; case 0x66ec: case 0x66ed: case 0x66ee: case 0x66ef: - ret = mach64_ext_readb(0x400 | 0xd0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xd0 | (port & 3), priv); break; case 0x6aec: @@ -3315,14 +3487,14 @@ mach64_ext_inb(uint16_t port, void *p) case 0x6eed: case 0x6eee: case 0x6eef: - ret = mach64_ext_readb(0x400 | 0xe0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xe0 | (port & 3), priv); break; case 0x72ec: case 0x72ed: case 0x72ee: case 0x72ef: - ret = mach64_ext_readb(0x400 | 0xe4 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xe4 | (port & 3), priv); break; default: @@ -3333,33 +3505,33 @@ mach64_ext_inb(uint16_t port, void *p) return ret; } uint16_t -mach64_ext_inw(uint16_t port, void *p) +mach64_ext_inw(uint16_t port, void *priv) { uint16_t ret; switch (port) { default: - ret = mach64_ext_inb(port, p); - ret |= (mach64_ext_inb(port + 1, p) << 8); + ret = mach64_ext_inb(port, priv); + ret |= (mach64_ext_inb(port + 1, priv) << 8); break; } mach64_log("mach64_ext_inw : port %04X ret %04X\n", port, ret); return ret; } uint32_t -mach64_ext_inl(uint16_t port, void *p) +mach64_ext_inl(uint16_t port, void *priv) { uint32_t ret; switch (port) { case 0x56ec: - ret = mach64_ext_readl(0x400 | 0xb4, p); + ret = mach64_ext_readl(0x400 | 0xb4, priv); break; case 0x5aec: - ret = mach64_ext_readl(0x400 | 0xb8, p); + ret = mach64_ext_readl(0x400 | 0xb8, priv); break; default: - ret = mach64_ext_inw(port, p); - ret |= (mach64_ext_inw(port + 2, p) << 16); + ret = mach64_ext_inw(port, priv); + ret |= (mach64_ext_inw(port + 2, priv) << 16); break; } mach64_log("mach64_ext_inl : port %04X ret %08X\n", port, ret); @@ -3367,9 +3539,9 @@ mach64_ext_inl(uint16_t port, void *p) } void -mach64_ext_outb(uint16_t port, uint8_t val, void *p) +mach64_ext_outb(uint16_t port, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_ext_outb : port %04X val %02X\n", port, val); switch (port) { @@ -3381,128 +3553,128 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *p) case 0x7eed: case 0x7eee: case 0x7eef: - mach64_ext_writeb(0x400 | 0x00 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x00 | (port & 3), val, priv); break; case 0x0aec: case 0x0aed: case 0x0aee: case 0x0aef: - mach64_ext_writeb(0x400 | 0x08 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x08 | (port & 3), val, priv); break; case 0x0eec: case 0x0eed: case 0x0eee: case 0x0eef: - mach64_ext_writeb(0x400 | 0x0c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x0c | (port & 3), val, priv); break; case 0x16ec: case 0x16ed: case 0x16ee: case 0x16ef: - mach64_ext_writeb(0x400 | 0x14 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x14 | (port & 3), val, priv); break; case 0x1aec: - mach64_ext_writeb(0x400 | 0x18, val, p); + mach64_ext_writeb(0x400 | 0x18, val, priv); break; case 0x1eec: case 0x1eed: case 0x1eee: case 0x1eef: - mach64_ext_writeb(0x400 | 0x1c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x1c | (port & 3), val, priv); break; case 0x22ec: case 0x22ed: case 0x22ee: case 0x22ef: - mach64_ext_writeb(0x400 | 0x40 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x40 | (port & 3), val, priv); break; case 0x26ec: case 0x26ed: case 0x26ee: case 0x26ef: - mach64_ext_writeb(0x400 | 0x44 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x44 | (port & 3), val, priv); break; case 0x2aec: case 0x2aed: case 0x2aee: case 0x2aef: - mach64_ext_writeb(0x400 | 0x48 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x48 | (port & 3), val, priv); break; case 0x2eec: case 0x2eed: case 0x2eee: case 0x2eef: - mach64_ext_writeb(0x400 | 0x60 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x60 | (port & 3), val, priv); break; case 0x32ec: case 0x32ed: case 0x32ee: case 0x32ef: - mach64_ext_writeb(0x400 | 0x64 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x64 | (port & 3), val, priv); break; case 0x36ec: case 0x36ed: case 0x36ee: case 0x36ef: - mach64_ext_writeb(0x400 | 0x68 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x68 | (port & 3), val, priv); break; case 0x3aec: case 0x3aed: case 0x3aee: case 0x3aef: - mach64_ext_writeb(0x400 | 0x6c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x6c | (port & 3), val, priv); break; case 0x3eec: case 0x3eed: case 0x3eee: case 0x3eef: - mach64_ext_writeb(0x400 | 0x70 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x70 | (port & 3), val, priv); break; case 0x42ec: case 0x42ed: case 0x42ee: case 0x42ef: - mach64_ext_writeb(0x400 | 0x80 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x80 | (port & 3), val, priv); break; case 0x46ec: case 0x46ed: case 0x46ee: case 0x46ef: - mach64_ext_writeb(0x400 | 0x84 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x84 | (port & 3), val, priv); break; case 0x4aec: case 0x4aed: case 0x4aee: case 0x4aef: - mach64_ext_writeb(0x400 | 0x90 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x90 | (port & 3), val, priv); break; case 0x52ec: case 0x52ed: case 0x52ee: case 0x52ef: - mach64_ext_writeb(0x400 | 0xb0 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xb0 | (port & 3), val, priv); break; case 0x56ec: - mach64_ext_writeb(0x400 | 0xb4, val, p); + mach64_ext_writeb(0x400 | 0xb4, val, priv); break; case 0x56ed: case 0x56ee: - mach64_ext_writeb(0x400 | 0xb5, val, p); + mach64_ext_writeb(0x400 | 0xb5, val, priv); break; case 0x5aec: - mach64_ext_writeb(0x400 | 0xb8, val, p); + mach64_ext_writeb(0x400 | 0xb8, val, priv); break; case 0x5aed: case 0x5aee: - mach64_ext_writeb(0x400 | 0xb9, val, p); + mach64_ext_writeb(0x400 | 0xb9, val, priv); break; case 0x5eec: @@ -3519,14 +3691,14 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *p) case 0x62ed: case 0x62ee: case 0x62ef: - mach64_ext_writeb(0x400 | 0xc4 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xc4 | (port & 3), val, priv); break; case 0x66ec: case 0x66ed: case 0x66ee: case 0x66ef: - mach64_ext_writeb(0x400 | 0xd0 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xd0 | (port & 3), val, priv); break; case 0x6aec: @@ -3539,32 +3711,32 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *p) } } void -mach64_ext_outw(uint16_t port, uint16_t val, void *p) +mach64_ext_outw(uint16_t port, uint16_t val, void *priv) { mach64_log("mach64_ext_outw : port %04X val %04X\n", port, val); switch (port) { default: - mach64_ext_outb(port, val, p); - mach64_ext_outb(port + 1, val >> 8, p); + mach64_ext_outb(port, val, priv); + mach64_ext_outb(port + 1, val >> 8, priv); break; } } void -mach64_ext_outl(uint16_t port, uint32_t val, void *p) +mach64_ext_outl(uint16_t port, uint32_t val, void *priv) { mach64_log("mach64_ext_outl : port %04X val %08X\n", port, val); switch (port) { default: - mach64_ext_outw(port, val, p); - mach64_ext_outw(port + 2, val >> 16, p); + mach64_ext_outw(port, val, priv); + mach64_ext_outw(port + 2, val >> 16, priv); break; } } static uint8_t -mach64_block_inb(uint16_t port, void *p) +mach64_block_inb(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint8_t ret; ret = mach64_ext_readb(0x400 | (port & 0x3ff), mach64); @@ -3572,9 +3744,9 @@ mach64_block_inb(uint16_t port, void *p) return ret; } static uint16_t -mach64_block_inw(uint16_t port, void *p) +mach64_block_inw(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint16_t ret; ret = mach64_ext_readw(0x400 | (port & 0x3ff), mach64); @@ -3582,9 +3754,9 @@ mach64_block_inw(uint16_t port, void *p) return ret; } static uint32_t -mach64_block_inl(uint16_t port, void *p) +mach64_block_inl(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint32_t ret; ret = mach64_ext_readl(0x400 | (port & 0x3ff), mach64); @@ -3593,51 +3765,51 @@ mach64_block_inl(uint16_t port, void *p) } static void -mach64_block_outb(uint16_t port, uint8_t val, void *p) +mach64_block_outb(uint16_t port, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_block_outb : port %04X val %02X\n ", port, val); mach64_ext_writeb(0x400 | (port & 0x3ff), val, mach64); } static void -mach64_block_outw(uint16_t port, uint16_t val, void *p) +mach64_block_outw(uint16_t port, uint16_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_block_outw : port %04X val %04X\n ", port, val); mach64_ext_writew(0x400 | (port & 0x3ff), val, mach64); } static void -mach64_block_outl(uint16_t port, uint32_t val, void *p) +mach64_block_outl(uint16_t port, uint32_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_block_outl : port %04X val %08X\n ", port, val); mach64_ext_writel(0x400 | (port & 0x3ff), val, mach64); } void -mach64_write(uint32_t addr, uint8_t val, void *p) +mach64_write(uint32_t addr, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; svga_write_linear(addr, val, svga); } void -mach64_writew(uint32_t addr, uint16_t val, void *p) +mach64_writew(uint32_t addr, uint16_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; svga_writew_linear(addr, val, svga); } void -mach64_writel(uint32_t addr, uint32_t val, void *p) +mach64_writel(uint32_t addr, uint32_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; @@ -3645,9 +3817,9 @@ mach64_writel(uint32_t addr, uint32_t val, void *p) } uint8_t -mach64_read(uint32_t addr, void *p) +mach64_read(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; uint8_t ret; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; @@ -3655,18 +3827,18 @@ mach64_read(uint32_t addr, void *p) return ret; } uint16_t -mach64_readw(uint32_t addr, void *p) +mach64_readw(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; return svga_readw_linear(addr, svga); } uint32_t -mach64_readl(uint32_t addr, void *p) +mach64_readl(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; @@ -3800,7 +3972,7 @@ mach64_readl(uint32_t addr, void *p) void mach64_overlay_draw(svga_t *svga, int displine) { - mach64_t *mach64 = (mach64_t *) svga->p; + mach64_t *mach64 = (mach64_t *) svga->priv; int x; int h_acc = 0; int h_max = (mach64->scaler_height_width >> 16) & 0x3ff; @@ -3856,8 +4028,9 @@ mach64_overlay_draw(svga_t *svga, int displine) } } else { for (x = 0; x < mach64->svga.overlay_latch.cur_xsize; x++) { - int h = h_acc >> 12; - int gr_cmp = 0, vid_cmp = 0; + int h = h_acc >> 12; + int gr_cmp = 0; + int vid_cmp = 0; int use_video = 0; switch (video_key_fn) { @@ -3873,6 +4046,9 @@ mach64_overlay_draw(svga_t *svga, int displine) case 5: vid_cmp = !((mach64->overlay_dat[h] ^ mach64->overlay_video_key_clr) & mach64->overlay_video_key_msk); break; + + default: + break; } switch (graphics_key_fn) { case 0: @@ -3887,6 +4063,9 @@ mach64_overlay_draw(svga_t *svga, int displine) case 5: gr_cmp = !(((p[x]) ^ mach64->overlay_graphics_key_clr) & mach64->overlay_graphics_key_msk & 0xffffff); break; + + default: + break; } vid_cmp = vid_cmp ? -1 : 0; gr_cmp = gr_cmp ? -1 : 0; @@ -3940,6 +4119,9 @@ mach64_overlay_draw(svga_t *svga, int displine) case 0xf: use_video = ~gr_cmp & ~vid_cmp; break; + + default: + break; } if (use_video) @@ -3968,12 +4150,11 @@ mach64_overlay_draw(svga_t *svga, int displine) static void mach64_io_remove(mach64_t *mach64) { - int c; uint16_t io_base = 0x02ec; switch (mach64->io_base) { - case 0: default: + case 0: io_base = 0x02ec; break; case 1: @@ -3989,7 +4170,7 @@ mach64_io_remove(mach64_t *mach64) io_removehandler(0x03c0, 0x0020, mach64_in, NULL, NULL, mach64_out, NULL, NULL, mach64); - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { io_removehandler((c * 0x1000) + 0x0000 + io_base, 0x0004, mach64_ext_inb, mach64_ext_inw, mach64_ext_inl, mach64_ext_outb, mach64_ext_outw, mach64_ext_outl, mach64); io_removehandler((c * 0x1000) + 0x0400 + io_base, 0x0004, mach64_ext_inb, mach64_ext_inw, mach64_ext_inl, mach64_ext_outb, mach64_ext_outw, mach64_ext_outl, mach64); io_removehandler((c * 0x1000) + 0x0800 + io_base, 0x0004, mach64_ext_inb, mach64_ext_inw, mach64_ext_inl, mach64_ext_outb, mach64_ext_outw, mach64_ext_outl, mach64); @@ -4005,14 +4186,12 @@ mach64_io_remove(mach64_t *mach64) static void mach64_io_set(mach64_t *mach64) { - int c; - mach64_io_remove(mach64); io_sethandler(0x03c0, 0x0020, mach64_in, NULL, NULL, mach64_out, NULL, NULL, mach64); if (!mach64->use_block_decoded_io) { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { io_sethandler((c * 0x1000) + 0x2ec, 0x0004, mach64_ext_inb, mach64_ext_inw, mach64_ext_inl, mach64_ext_outb, mach64_ext_outw, mach64_ext_outl, mach64); io_sethandler((c * 0x1000) + 0x6ec, 0x0004, mach64_ext_inb, mach64_ext_inw, mach64_ext_inl, mach64_ext_outb, mach64_ext_outw, mach64_ext_outl, mach64); io_sethandler((c * 0x1000) + 0xaec, 0x0004, mach64_ext_inb, mach64_ext_inw, mach64_ext_inl, mach64_ext_outb, mach64_ext_outw, mach64_ext_outl, mach64); @@ -4027,9 +4206,9 @@ mach64_io_set(mach64_t *mach64) } uint8_t -mach64_pci_read(int func, int addr, void *p) +mach64_pci_read(UNUSED(int func), int addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + const mach64_t *mach64 = (mach64_t *) priv; switch (addr) { case 0x00: @@ -4103,14 +4282,17 @@ mach64_pci_read(int func, int addr, void *p) case 0x40: return mach64->use_block_decoded_io | mach64->io_base; + + default: + break; } return 0; } void -mach64_pci_write(int func, int addr, uint8_t val, void *p) +mach64_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; switch (addr) { case PCI_REG_COMMAND: @@ -4188,6 +4370,9 @@ mach64_pci_write(int func, int addr, uint8_t val, void *p) if (mach64->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_IO) mach64_io_set(mach64); break; + + default: + break; } } @@ -4215,9 +4400,8 @@ mach64_common_init(const device_t *info) mach64_io_set(mach64); - if (info->flags & DEVICE_PCI) { + if (info->flags & DEVICE_PCI) mach64->card = pci_add_card(PCI_ADD_VIDEO, mach64_pci_read, mach64_pci_write, mach64); - } mach64->pci_regs[PCI_REG_COMMAND] = 3; mach64->pci_regs[0x30] = 0x00; @@ -4256,8 +4440,8 @@ mach64gx_init(const device_t *info) mach64->type = MACH64_GX; mach64->pci = !!(info->flags & DEVICE_PCI); - mach64->pci_id = (int) 'X' | ((int) 'G' << 8); - mach64->config_chip_id = 0x020000d7; + mach64->pci_id = 'X' | ('G' << 8); + mach64->config_chip_id = 0x000000d7; mach64->dac_cntl = 5 << 16; /*ATI 68860 RAMDAC*/ mach64->config_stat0 = (5 << 9) | (3 << 3); /*ATI-68860, 256Kx16 DRAM*/ if (info->flags & DEVICE_PCI) @@ -4287,10 +4471,7 @@ mach64vt2_init(const device_t *info) mach64_t *mach64 = mach64_common_init(info); svga_t *svga = &mach64->svga; - if (info->flags & DEVICE_PCI) - video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_pci); - else - video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_vlb); + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_pci); mach64->type = MACH64_VT2; mach64->pci = 1; @@ -4304,8 +4485,7 @@ mach64vt2_init(const device_t *info) rom_init(&mach64->bios_rom, BIOS_ROMVT2_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - if (info->flags & DEVICE_PCI) - mem_mapping_disable(&mach64->bios_rom.mapping); + mem_mapping_disable(&mach64->bios_rom.mapping); svga->vblank_start = mach64_vblank_start; @@ -4334,9 +4514,9 @@ mach64vt2_available(void) } void -mach64_close(void *p) +mach64_close(void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64->thread_run = 0; thread_set_event(mach64->wake_fifo_thread); @@ -4353,17 +4533,17 @@ mach64_close(void *p) } void -mach64_speed_changed(void *p) +mach64_speed_changed(void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_recalctimings(&mach64->svga); } void -mach64_force_redraw(void *p) +mach64_force_redraw(void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ati_mach8.c b/src/video/vid_ati_mach8.c new file mode 100644 index 000000000..1aa55bd6b --- /dev/null +++ b/src/video/vid_ati_mach8.c @@ -0,0 +1,5734 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Emulation of the 8514/A-compatible Mach8 and Mach32 graphics + * chips from ATI for the ISA/VLB/MCA/PCI buses. + * + * + * + * Authors: TheCollector1995. + * + * Copyright 2022-2023 TheCollector1995. + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/mem.h> +#include <86box/timer.h> +#include <86box/mca.h> +#include <86box/pci.h> +#include <86box/rom.h> +#include <86box/plat.h> +#include <86box/thread.h> +#include <86box/video.h> +#include <86box/i2c.h> +#include <86box/vid_ddc.h> +#include <86box/vid_svga.h> +#include <86box/vid_svga_render.h> +#include <86box/vid_ati_eeprom.h> + +#define BIOS_MACH8_ROM_PATH "roms/video/mach8/BIOS.BIN" +#define BIOS_MACH32_ISA_ROM_PATH "roms/video/mach32/MACH32ISA.VBI" +#define BIOS_MACH32_VLB_ROM_PATH "roms/video/mach32/MACH32VLB.VBI" +#define BIOS_MACH32_PCI_ROM_PATH "roms/video/mach32/MACH32PCI.BIN" + +typedef struct mach_t { + ati_eeprom_t eeprom; + svga_t svga; + + rom_t bios_rom; + mem_mapping_t mmio_linear_mapping; + + int mca_bus; + int pci_bus; + int vlb_bus; + uint8_t regs[256]; + uint8_t pci_regs[256]; + uint8_t int_line; + int card; + int index; + + uint32_t memory; + + uint16_t config1; + uint16_t config2; + + uint8_t pos_regs[8]; + uint8_t cursor_col_0; + uint8_t cursor_col_1; + uint8_t ext_cur_col_0_r; + uint8_t ext_cur_col_1_r; + uint8_t ext_cur_col_0_g; + uint8_t ext_cur_col_1_g; + uint16_t cursor_offset_lo; + uint16_t cursor_offset_hi; + uint16_t cursor_x; + uint16_t cursor_y; + uint16_t misc; + uint16_t memory_aperture; + uint16_t local_cntl; + uint32_t linear_base; + uint8_t ap_size; + uint8_t bank_w; + uint8_t bank_r; + + struct { + uint8_t line_idx; + int16_t line_array[6]; + uint8_t patt_idx; + uint8_t patt_len; + uint8_t pix_trans[2]; + uint8_t eeprom_control; + uint16_t dest_x_end; + uint16_t dest_x_start; + uint16_t dest_y_end; + uint16_t src_x_end; + uint16_t src_x_start; + uint16_t src_x; + uint16_t src_y; + int16_t bres_count; + uint16_t clock_sel; + uint16_t crt_offset_lo; + uint16_t crt_offset_hi; + uint16_t dest_cmp_fn; + uint16_t dp_config; + uint16_t ext_ge_config; + uint16_t ge_offset_lo; + uint16_t ge_offset_hi; + uint16_t linedraw_opt; + uint16_t max_waitstates; + uint8_t patt_data_idx; + uint8_t patt_data[0x18]; + uint16_t scan_to_x; + uint16_t scratch0; + uint16_t scratch1; + uint16_t test; + uint16_t pattern; + uint8_t test2[2]; + uint8_t test3[2]; + int src_y_dir; + int cmd_type; + int block_write_mono_pattern_enable; + int mono_pattern_enable; + int16_t cx_end_line; + int16_t cy_end_line; + int16_t cx; + int16_t cx_end; + int16_t cy_end; + int16_t dx; + int16_t dx_end; + int16_t dy_end; + int16_t dx_start; + int16_t dy_start; + int16_t cy; + int16_t sx_start; + int16_t sx_end; + int16_t sx; + int16_t x_count; + int16_t xx_count; + int16_t xxx_count; + int16_t sy; + int16_t y_count; + int16_t err; + int16_t width; + int16_t src_width; + int16_t height; + int poly_src; + int temp_cnt; + int stepx; + int stepy; + int src_stepx; + uint8_t color_pattern[16]; + uint8_t color_pattern_full[32]; + uint16_t color_pattern_word[8]; + int mono_pattern[8][8]; + uint32_t ge_offset; + uint32_t crt_offset; + uint32_t patt_len_reg; + int poly_fill; + uint16_t dst_clr_cmp_mask; + int clip_overrun; + int color_pattern_idx; + } accel; + + atomic_int force_busy; + atomic_int force_busy2; +} mach_t; + +static video_timings_t timing_gfxultra_isa = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; +static video_timings_t timing_mach32_vlb = { .type = VIDEO_BUS, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 20, .read_w = 20, .read_l = 21 }; +static video_timings_t timing_mach32_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 20, .read_w = 20, .read_l = 21 }; + +static void mach_accel_outb(uint16_t port, uint8_t val, void *priv); +static void mach_accel_outw(uint16_t port, uint16_t val, void *priv); +static uint8_t mach_accel_inb(uint16_t port, void *priv); +static uint16_t mach_accel_inw(uint16_t port, void *priv); + +static void mach32_updatemapping(mach_t *mach); + +#ifdef ENABLE_MACH_LOG +int mach_do_log = ENABLE_MACH_LOG; + +static void +mach_log(const char *fmt, ...) +{ + va_list ap; + + if (mach_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define mach_log(fmt, ...) +#endif + +#define READ_PIXTRANS_BYTE_IO(cx, n, vgacore) \ + if ((mach->accel.cmd_type == 2) || (mach->accel.cmd_type == 5)) { \ + if (vgacore) { \ + if ((svga->bpp == 15) || (svga->bpp == 16)) \ + if (n == 0) \ + mach->accel.pix_trans[(n)] = vram_w[(dev->accel.dest + (cx) + (n)) & (svga->vram_mask >> 1)] & 0xff; \ + else \ + mach->accel.pix_trans[(n)] = vram_w[(dev->accel.dest + (cx) + (n)) & (svga->vram_mask >> 1)] >> 8; \ + else \ + mach->accel.pix_trans[(n)] = svga->vram[(dev->accel.dest + (cx) + (n)) & svga->vram_mask]; \ + } else \ + mach->accel.pix_trans[(n)] = dev->vram[(dev->accel.dest + (cx) + (n)) & dev->vram_mask]; \ + } + +#define READ_PIXTRANS_WORD(cx, n, vgacore) \ + if ((cmd == 0) || (cmd == 1) || (cmd == 5) || (mach->accel.cmd_type == -1)) { \ + if (vgacore) { \ + if ((svga->bpp == 15) || (svga->bpp == 16)) { \ + temp = vram_w[((dev->accel.cy * dev->pitch) + (cx) + (n)) & (svga->vram_mask >> 1)]; \ + } else { \ + temp = svga->vram[((dev->accel.cy * dev->pitch) + (cx) + (n)) & svga->vram_mask]; \ + temp |= (svga->vram[((dev->accel.cy * dev->pitch) + (cx) + (n + 1)) & svga->vram_mask] << 8); \ + } \ + } else { \ + temp = dev->vram[((dev->accel.cy * dev->pitch) + (cx) + (n)) & dev->vram_mask]; \ + temp |= (dev->vram[((dev->accel.cy * dev->pitch) + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + } \ + } else if ((mach->accel.cmd_type == 2) || (mach->accel.cmd_type == 5)) { \ + if ((svga->bpp == 8) || (svga->bpp == 24)) { \ + if (vgacore) { \ + temp = svga->vram[((dev->accel.dest) + (cx) + (n)) & svga->vram_mask]; \ + temp |= (svga->vram[((dev->accel.dest) + (cx) + (n + 1)) & svga->vram_mask] << 8); \ + } else { \ + temp = dev->vram[((dev->accel.dest) + (cx) + (n)) & dev->vram_mask]; \ + temp |= (dev->vram[((dev->accel.dest) + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + } \ + } else if ((svga->bpp == 15) || (svga->bpp == 16)) { \ + temp = vram_w[((dev->accel.dest) + (cx) + (n)) & (svga->vram_mask >> 1)]; \ + } \ + } else if ((mach->accel.cmd_type == 3) || (mach->accel.cmd_type == 4)) { \ + if ((svga->bpp == 8) || (svga->bpp == 24)) { \ + if (vgacore) { \ + temp = svga->vram[((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (cx) + (n)) & svga->vram_mask]; \ + temp |= (svga->vram[((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (cx) + (n + 1)) & svga->vram_mask] << 8); \ + } else { \ + temp = dev->vram[((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (cx) + (n)) & dev->vram_mask]; \ + temp |= (dev->vram[((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + } \ + } else if ((svga->bpp == 15) || (svga->bpp == 16)) { \ + temp = vram_w[((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (cx) + (n)) & (svga->vram_mask >> 1)]; \ + } \ + } + +#define READ(addr, dat, vgacore) \ + if ((svga->bpp == 8) || (svga->bpp == 24)) \ + dat = vgacore ? (svga->vram[(addr) & (svga->vram_mask)]) : (dev->vram[(addr) & (dev->vram_mask)]); \ + else if ((svga->bpp == 15) || (svga->bpp == 16)) \ + dat = vram_w[(addr) & (svga->vram_mask >> 1)]; + +#define MIX(mixmode, dest_dat, src_dat) \ + { \ + switch ((mixmode) ? (dev->accel.frgd_mix & 0x1f) : (dev->accel.bkgd_mix & 0x1f)) { \ + case 0x00: \ + dest_dat = ~dest_dat; \ + break; \ + case 0x01: \ + dest_dat = 0; \ + break; \ + case 0x02: \ + dest_dat = ~0; \ + break; \ + case 0x03: \ + dest_dat = dest_dat; \ + break; \ + case 0x04: \ + dest_dat = ~src_dat; \ + break; \ + case 0x05: \ + dest_dat = src_dat ^ dest_dat; \ + break; \ + case 0x06: \ + dest_dat = ~(src_dat ^ dest_dat); \ + break; \ + case 0x07: \ + dest_dat = src_dat; \ + break; \ + case 0x08: \ + dest_dat = ~(src_dat & dest_dat); \ + break; \ + case 0x09: \ + dest_dat = ~src_dat | dest_dat; \ + break; \ + case 0x0a: \ + dest_dat = src_dat | ~dest_dat; \ + break; \ + case 0x0b: \ + dest_dat = src_dat | dest_dat; \ + break; \ + case 0x0c: \ + dest_dat = src_dat & dest_dat; \ + break; \ + case 0x0d: \ + dest_dat = src_dat & ~dest_dat; \ + break; \ + case 0x0e: \ + dest_dat = ~src_dat & dest_dat; \ + break; \ + case 0x0f: \ + dest_dat = ~(src_dat | dest_dat); \ + break; \ + case 0x10: \ + dest_dat = MIN(src_dat, dest_dat); \ + break; \ + case 0x11: \ + dest_dat = dest_dat - src_dat; \ + break; \ + case 0x12: \ + dest_dat = src_dat - dest_dat; \ + break; \ + case 0x13: \ + dest_dat = src_dat + dest_dat; \ + break; \ + case 0x14: \ + dest_dat = MAX(src_dat, dest_dat); \ + break; \ + case 0x15: \ + dest_dat = (dest_dat - src_dat) / 2; \ + break; \ + case 0x16: \ + dest_dat = (src_dat - dest_dat) / 2; \ + break; \ + case 0x17: \ + dest_dat = (dest_dat + src_dat) / 2; \ + break; \ + case 0x18: \ + dest_dat = MAX(0, (dest_dat - src_dat)); \ + break; \ + case 0x19: \ + dest_dat = MAX(0, (dest_dat - src_dat)); \ + break; \ + case 0x1a: \ + dest_dat = MAX(0, (src_dat - dest_dat)); \ + break; \ + case 0x1b: \ + dest_dat = MIN(0xff, (dest_dat + src_dat)); \ + break; \ + case 0x1c: \ + dest_dat = MAX(0, (dest_dat - src_dat)) / 2; \ + break; \ + case 0x1d: \ + dest_dat = MAX(0, (dest_dat - src_dat)) / 2; \ + break; \ + case 0x1e: \ + dest_dat = MAX(0, (src_dat - dest_dat)) / 2; \ + break; \ + case 0x1f: \ + dest_dat = (0xff < (src_dat + dest_dat)) ? 0xff : ((src_dat + dest_dat) / 2); \ + break; \ + } \ + } + + +#define WRITE(addr, dat, vgacore) \ + if ((svga->bpp == 8) || (svga->bpp == 24)) { \ + if (vgacore) { \ + svga->vram[((addr)) & (svga->vram_mask)] = dat; \ + svga->changedvram[(((addr)) & (svga->vram_mask)) >> 12] = changeframecount; \ + } else { \ + dev->vram[((addr)) & (dev->vram_mask)] = dat; \ + dev->changedvram[(((addr)) & (dev->vram_mask)) >> 12] = changeframecount; \ + } \ + } else if ((svga->bpp == 15) || (svga->bpp == 16)) { \ + vram_w[((addr)) & (svga->vram_mask >> 1)] = dat; \ + svga->changedvram[(((addr)) & (svga->vram_mask >> 1)) >> 11] = changeframecount; \ + } + +static int +mach_pixel_write(mach_t *mach) +{ + if (mach->accel.dp_config & 1) + return 1; + + return 0; +} + +static int +mach_pixel_read(mach_t *mach) +{ + if (mach->accel.dp_config & 1) + return 0; + + return 1; +} + +static void +mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint32_t cpu_dat, mach_t *mach, ibm8514_t *dev, UNUSED(int len)) +{ + svga_t *svga = &mach->svga; + int compare_mode; + int poly_src = 0; + uint16_t rd_mask = dev->accel.rd_mask; + uint16_t wrt_mask = dev->accel.wrt_mask; + uint16_t dest_cmp_clr = dev->accel.color_cmp; + int frgd_sel; + int bkgd_sel; + int mono_src; + int compare = 0; + uint16_t src_dat = 0; + uint16_t dest_dat = 0; + uint16_t old_dest_dat; + uint16_t *vram_w = (uint16_t *) svga->vram; + uint16_t mix = 0; + int16_t clip_l = dev->accel.clip_left & 0x7ff; + int16_t clip_t = dev->accel.clip_top & 0x7ff; + int16_t clip_r = dev->accel.multifunc[4] & 0x7ff; + int16_t clip_b = dev->accel.multifunc[3] & 0x7ff; + uint32_t mono_dat0 = 0; + uint32_t mono_dat1 = 0; + + if ((svga->bpp == 8) || (svga->bpp == 24)) { + rd_mask &= 0xff; + dest_cmp_clr &= 0xff; + } + + compare_mode = (mach->accel.dest_cmp_fn >> 3) & 7; + frgd_sel = (mach->accel.dp_config >> 13) & 7; + bkgd_sel = (mach->accel.dp_config >> 7) & 3; + mono_src = (mach->accel.dp_config >> 5) & 3; + + mach->accel.ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); + + if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + mach->force_busy = 1; + mach->force_busy2 = 1; + dev->force_busy = 1; + dev->force_busy2 = 1; + } + + if (cpu_input) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + if ((mach->accel.dp_config & 0x200) && (count == 2)) { + count >>= 1; + } + } + } + + if ((svga->bpp == 8) || (svga->bpp == 15) || (svga->bpp == 16) || (svga->bpp == 24)) { + if (svga->bpp == 24) + mach_log("24BPP: CMDType=%d, cwh(%d,%d,%d,%d), dpconfig=%04x\n", cmd_type, clip_l, clip_r, clip_t, clip_b, mach->accel.dp_config); + else + mach_log("BPP=%d, CMDType = %d, offs=%08x, DPCONFIG = %04x, cnt = %d, input = %d, mono_src = %d, frgdsel = %d, dstx = %d, dstxend = %d, pitch = %d, extcrt = %d, rw = %x, monpattern = %x.\n", svga->bpp, cmd_type, mach->accel.ge_offset, mach->accel.dp_config, count, cpu_input, mono_src, frgd_sel, dev->accel.cur_x, mach->accel.dest_x_end, dev->ext_pitch, dev->ext_crt_pitch, mach->accel.dp_config & 1, mach->accel.mono_pattern_enable); + } + + switch (cmd_type) { + case 1: /*Extended Raw Linedraw from bres_count register (0x96ee)*/ + if (!cpu_input) { + dev->accel.dx = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + dev->accel.dx |= ~0x5ff; + dev->accel.dy = dev->accel.cur_y; + if (dev->accel.cur_y >= 0x600) + dev->accel.dy |= ~0x5ff; + + dev->accel.cx = dev->accel.destx_distp; + if (dev->accel.destx_distp >= 0x600) + dev->accel.cx |= ~0x5ff; + dev->accel.cy = dev->accel.desty_axstp; + if (dev->accel.desty_axstp >= 0x600) + dev->accel.cy |= ~0x5ff; + + mach->accel.width = mach->accel.bres_count; + dev->accel.sx = 0; + mach->accel.poly_fill = 0; + + mach->accel.color_pattern_idx = ((dev->accel.cx + (dev->accel.cy << 3)) & mach->accel.patt_len); + + mach->accel.stepx = (mach->accel.linedraw_opt & 0x20) ? 1 : -1; + mach->accel.stepy = (mach->accel.linedraw_opt & 0x80) ? 1 : -1; + + mach_log("Extended bresenham, CUR(%d,%d), DEST(%d,%d), width = %d, options = %04x, dpconfig = %04x, opt_ena = %03x.\n", dev->accel.dx, dev->accel.dy, dev->accel.cx, dev->accel.cy, mach->accel.width, mach->accel.linedraw_opt, mach->accel.dp_config, mach->accel.max_waitstates & 0x100); + + if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + if (mach_pixel_write(mach)) { + dev->data_available = 0; + dev->data_available2 = 0; + return; + } else if (mach_pixel_read(mach)) { + dev->data_available = 1; + dev->data_available2 = 1; + return; + } + } + } + + if (frgd_sel == 5) { + for (int x = 0; x <= mach->accel.patt_len; x++) { + mach->accel.color_pattern[x] = mach->accel.patt_data[x & mach->accel.patt_len]; + } + + /*The destination coordinates should match the pattern index.*/ + if (mach->accel.color_pattern_idx != mach->accel.patt_idx) + mach->accel.color_pattern_idx = mach->accel.patt_idx; + } + + if (mono_src == 1) { + count = mach->accel.width; + mix_dat = mach->accel.patt_data[0x10]; + dev->accel.temp_cnt = 8; + } + + if (mach->accel.linedraw_opt & 0x08) { /*Vector Line*/ + while (count--) { + switch (mono_src) { + case 0: + mix = 1; + break; + case 1: + if (dev->accel.temp_cnt == 0) { + dev->accel.temp_cnt = 8; + mix_dat >>= 8; + } + mix = (mix_dat & 0x80); + dev->accel.temp_cnt--; + mix_dat <<= 1; + mix_dat |= 1; + break; + case 2: + if (mach->accel.dp_config & 0x1000) { + mix = mix_dat >> 0x1f; + mix_dat <<= 1; + } else { + if (mach->accel.dp_config & 0x200) { + mix = mix_dat & 1; + mix_dat >>= 1; + } else { + mix = mix_dat & 0x80; + mix_dat <<= 1; + mix_dat |= 1; + } + } + break; + case 3: + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } + mix = (mix & rd_mask) == rd_mask; + break; + + default: + break; + } + + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { + if (mach->accel.linedraw_opt & 0x02) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src, dev->local); + } + poly_src = ((poly_src & rd_mask) == rd_mask); + if (poly_src) + mach->accel.poly_fill = !mach->accel.poly_fill; + } + + if (!mach->accel.poly_fill || !(mach->accel.linedraw_opt & 0x02)) { + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } + if (mono_src == 3) { + src_dat = (src_dat & rd_mask) == rd_mask; + } + } + break; + case 5: + if (mix) { + src_dat = mach->accel.color_pattern[((dev->accel.dx) + ((dev->accel.dy) << 3)) & mach->accel.patt_len]; + } else + src_dat = 0; + break; + + default: + break; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } + } + + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + + if (mach->accel.dp_config & 0x10) { + if (mach->accel.linedraw_opt & 0x04) { + if (dev->accel.sx < mach->accel.width) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } + } + } else { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } + } + } + } + + if ((mono_src == 1) && !count) + break; + else if ((mono_src != 1) && (dev->accel.sx >= mach->accel.width)) + break; + + if (svga->bpp == 8) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + switch (mach->accel.linedraw_opt & 0xe0) { + case 0x00: + dev->accel.cx++; + dev->accel.dx++; + break; + case 0x20: + dev->accel.cx++; + dev->accel.dx++; + dev->accel.cy--; + dev->accel.dy--; + break; + case 0x40: + dev->accel.cy--; + dev->accel.dy--; + break; + case 0x60: + dev->accel.cx--; + dev->accel.dx--; + dev->accel.cy--; + dev->accel.dy--; + break; + case 0x80: + dev->accel.cx--; + dev->accel.dx--; + break; + case 0xa0: + dev->accel.cx--; + dev->accel.dx--; + dev->accel.cy++; + dev->accel.dy++; + break; + case 0xc0: + dev->accel.cy++; + dev->accel.dy++; + break; + case 0xe0: + dev->accel.cx++; + dev->accel.dx++; + dev->accel.cy++; + dev->accel.dy++; + break; + + default: + break; + } + + dev->accel.sx++; + } + } else { /*Bresenham*/ + while (count--) { + switch (mono_src) { + case 0: + mix = 1; + break; + case 1: + if (dev->accel.temp_cnt == 0) { + dev->accel.temp_cnt = 8; + mix_dat >>= 8; + } + mix = (mix_dat & 0x80); + dev->accel.temp_cnt--; + mix_dat <<= 1; + mix_dat |= 1; + break; + case 2: + if (mach->accel.dp_config & 0x1000) { + mix = mix_dat >> 0x1f; + mix_dat <<= 1; + } else { + if (mach->accel.dp_config & 0x200) { + mix = mix_dat & 1; + mix_dat >>= 1; + } else { + mix = mix_dat & 0x80; + mix_dat <<= 1; + mix_dat |= 1; + } + } + break; + case 3: + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } + mix = (mix & rd_mask) == rd_mask; + break; + + default: + break; + } + + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { + if (mach->accel.linedraw_opt & 0x02) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src, dev->local); + } + poly_src = ((poly_src & rd_mask) == rd_mask); + if (poly_src) + mach->accel.poly_fill = !mach->accel.poly_fill; + } + + if (!mach->accel.poly_fill || !(mach->accel.linedraw_opt & 0x02)) { + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix, dev->local); + } + if (mono_src == 3) { + src_dat = (src_dat & rd_mask) == rd_mask; + } + } + break; + case 5: + if (mix) { + src_dat = mach->accel.color_pattern[((dev->accel.dx) + ((dev->accel.dy) << 3)) & mach->accel.patt_len]; + } else + src_dat = 0; + break; + + default: + break; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } + } + + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + + if (mach->accel.dp_config & 0x10) { + if (mach->accel.linedraw_opt & 0x04) { + if (dev->accel.sx < mach->accel.width) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } + } + } else { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat, dev->local); + } + } + } + } + + if ((mono_src == 1) && !count) + break; + else if ((mono_src != 1) && (dev->accel.sx >= mach->accel.width)) + break; + + if (svga->bpp == 8) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + if (mach->accel.linedraw_opt & 0x40) { + dev->accel.dy += mach->accel.stepy; + if ((frgd_sel == 3) || (bkgd_sel == 3)) + dev->accel.cy += mach->accel.stepy; + + if (dev->accel.err_term >= 0) { + dev->accel.err_term += dev->accel.destx_distp; + dev->accel.dx += mach->accel.stepx; + if ((frgd_sel == 3) || (bkgd_sel == 3)) + dev->accel.cx += mach->accel.stepx; + } else { + dev->accel.err_term += dev->accel.desty_axstp; + } + } else { + dev->accel.dx += mach->accel.stepx; + if ((frgd_sel == 3) || (bkgd_sel == 3)) + dev->accel.cx += mach->accel.stepx; + + if (dev->accel.err_term >= 0) { + dev->accel.err_term += dev->accel.destx_distp; + dev->accel.dy += mach->accel.stepy; + if ((frgd_sel == 3) || (bkgd_sel == 3)) + dev->accel.cy += mach->accel.stepy; + } else { + dev->accel.err_term += dev->accel.desty_axstp; + } + } + + dev->accel.sx++; + } + } + dev->accel.cur_x = dev->accel.dx; + dev->accel.cur_y = dev->accel.dy; + break; + + case 2: /*Non-conforming BitBLT from dest_y_end register (0xaeee)*/ + if (!cpu_input) { + mach->accel.stepx = 0; + mach->accel.stepy = 0; + + dev->accel.dx = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + dev->accel.dx |= ~0x5ff; + + dev->accel.dy = dev->accel.cur_y; + if (dev->accel.cur_y >= 0x600) + dev->accel.dy |= ~0x5ff; + + /*Destination Width*/ + if (mach->accel.dest_x_start != dev->accel.dx) + mach->accel.dest_x_start = dev->accel.dx; + + mach->accel.dx_start = mach->accel.dest_x_start; + if (mach->accel.dest_x_start >= 0x600) + mach->accel.dx_start |= ~0x5ff; + + mach->accel.dx_end = mach->accel.dest_x_end; + if (mach->accel.dest_x_end >= 0x600) + mach->accel.dx_end |= ~0x5ff; + + if (mach->accel.dx_end > mach->accel.dx_start) { + mach->accel.width = (mach->accel.dx_end - mach->accel.dx_start); + mach->accel.stepx = 1; + } else if (mach->accel.dx_end < mach->accel.dx_start) { + mach->accel.width = (mach->accel.dx_start - mach->accel.dx_end); + mach->accel.stepx = -1; + if (dev->accel.dx > 0) + dev->accel.dx--; + mach_log("BitBLT: Dst Negative X, dxstart = %d, end = %d, width = %d, dx = %d, dpconfig = %04x.\n", mach->accel.dest_x_start, mach->accel.dest_x_end, mach->accel.width, dev->accel.dx, mach->accel.dp_config); + } else { + mach->accel.stepx = 1; + mach->accel.width = 0; + mach_log("BitBLT: Dst Indeterminate X, dpconfig = %04x, destxend = %d, destxstart = %d.\n", mach->accel.dp_config, mach->accel.dest_x_end, mach->accel.dest_x_start); + } + + dev->accel.sx = 0; + mach->accel.poly_fill = 0; + mach->accel.color_pattern_idx = ((dev->accel.dx + (dev->accel.dy << 3)) & mach->accel.patt_len); + if ((svga->bpp == 24) && (mono_src != 1)) { + if (mach->accel.color_pattern_idx == mach->accel.patt_len) + mach->accel.color_pattern_idx = mach->accel.patt_data_idx; + } else if ((svga->bpp == 24) && (frgd_sel == 5) && (mono_src == 1) && (mach->accel.patt_len_reg & 0x4000)) + mach->accel.color_pattern_idx = 0; + + /*Height*/ + mach->accel.dy_start = dev->accel.cur_y; + if (dev->accel.cur_y >= 0x600) + mach->accel.dy_start |= ~0x5ff; + mach->accel.dy_end = mach->accel.dest_y_end; + if (mach->accel.dest_y_end >= 0x600) + mach->accel.dy_end |= ~0x5ff; + + if (mach->accel.dy_end > mach->accel.dy_start) { + mach->accel.height = (mach->accel.dy_end - mach->accel.dy_start); + mach->accel.stepy = 1; + } else if (mach->accel.dy_end < mach->accel.dy_start) { + mach->accel.height = (mach->accel.dy_start - mach->accel.dy_end); + mach->accel.stepy = -1; + } else { + mach->accel.height = 0; + mach->accel.stepy = 1; + } + + dev->accel.sy = 0; + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.dest = (mach->accel.ge_offset << 1) + (dev->accel.dy * (dev->pitch)); + else + dev->accel.dest = (mach->accel.ge_offset << 2) + (dev->accel.dy * (dev->pitch)); + + mach->accel.src_stepx = 0; + + /*Source Width*/ + dev->accel.cx = mach->accel.src_x; + if (mach->accel.src_x >= 0x600) + dev->accel.cx |= ~0x5ff; + + dev->accel.cy = mach->accel.src_y; + if (mach->accel.src_y >= 0x600) + dev->accel.cy |= ~0x5ff; + + mach->accel.sx_start = mach->accel.src_x_start; + if (mach->accel.src_x_start >= 0x600) + mach->accel.sx_start |= ~0x5ff; + + mach->accel.sx_end = mach->accel.src_x_end; + if (mach->accel.src_x_end >= 0x600) + mach->accel.sx_end |= ~0x5ff; + + if (mach->accel.sx_end > mach->accel.sx_start) { + mach->accel.src_width = (mach->accel.sx_end - mach->accel.sx_start); + mach->accel.src_stepx = 1; + mach_log("BitBLT: Src Positive X: wh(%d,%d), srcwidth = %d, coordinates: %d,%d px, start: %d, end: %d px, stepx = %d, dpconfig = %04x, oddwidth = %d.\n", mach->accel.width, mach->accel.height, mach->accel.src_width, dev->accel.cx, dev->accel.cy, mach->accel.src_x_start, mach->accel.src_x_end, mach->accel.src_stepx, mach->accel.dp_config, mach->accel.src_width & 1); + } else if (mach->accel.sx_end < mach->accel.sx_start) { + mach->accel.src_width = (mach->accel.sx_start - mach->accel.sx_end); + mach->accel.src_stepx = -1; + if (dev->accel.cx > 0) + dev->accel.cx--; + mach_log("BitBLT: Src Negative X: width = %d, coordinates: %d,%d px, end: %d px, stepx = %d, dpconfig = %04x, oddwidth = %d.\n", mach->accel.src_width, dev->accel.cx, dev->accel.cy, mach->accel.src_x_end, mach->accel.src_stepx, mach->accel.dp_config, mach->accel.src_width & 1); + } else { + mach->accel.src_stepx = 1; + mach->accel.src_width = 0; + mach_log("BitBLT: Src Indeterminate X: width = %d, coordinates: %d,%d px, end: %d px, stepx = %d, dpconfig = %04x, oddwidth = %d.\n", mach->accel.src_width, dev->accel.cx, dev->accel.cy, mach->accel.src_x_end, mach->accel.src_stepx, mach->accel.dp_config, mach->accel.src_width & 1); + } + mach->accel.sx = 0; + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.src = (mach->accel.ge_offset << 1) + (dev->accel.cy * (dev->pitch)); + else + dev->accel.src = (mach->accel.ge_offset << 2) + (dev->accel.cy * (dev->pitch)); + + if ((svga->bpp == 24) && (frgd_sel == 5)) { + mach_log("BitBLT=%04x, WH(%d,%d), SRCWidth=%d, c(%d,%d), s(%d,%d).\n", mach->accel.dp_config, mach->accel.width, mach->accel.height, mach->accel.src_width, dev->accel.dx, dev->accel.dy, dev->accel.cx, dev->accel.cy); + } else + mach_log("BitBLT=%04x, Pitch=%d, C(%d,%d), SRCWidth=%d, WH(%d,%d), geoffset=%08x.\n", mach->accel.dp_config, dev->ext_pitch, dev->accel.cx, dev->accel.cy, mach->accel.src_width, mach->accel.width, mach->accel.height, (mach->accel.ge_offset << 2)); + + if (mono_src == 1) { + if ((mach->accel.mono_pattern_enable) && !(mach->accel.patt_len_reg & 0x4000)) { + mono_dat0 = mach->accel.patt_data[0x10]; + mono_dat0 |= (mach->accel.patt_data[0x11] << 8); + mono_dat0 |= (mach->accel.patt_data[0x12] << 16); + mono_dat0 |= (mach->accel.patt_data[0x13] << 24); + mono_dat1 = mach->accel.patt_data[0x14]; + mono_dat1 |= (mach->accel.patt_data[0x15] << 8); + mono_dat1 |= (mach->accel.patt_data[0x16] << 16); + mono_dat1 |= (mach->accel.patt_data[0x17] << 24); + + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t x = 0; x < 8; x++) { + uint32_t temp = (y & 4) ? mono_dat1 : mono_dat0; + mach->accel.mono_pattern[y][7 - x] = (temp >> (x + ((y & 3) << 3))) & 1; + } + } + } + } + + if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + if (mach_pixel_write(mach)) { + dev->data_available = 0; + dev->data_available2 = 0; + return; + } else if (mach_pixel_read(mach)) { + dev->data_available = 1; + dev->data_available2 = 1; + return; + } + } + } + + if (mono_src == 1) { + if (!mach->accel.mono_pattern_enable && !(mach->accel.patt_len_reg & 0x4000)) { + count = mach->accel.width; + mix_dat = mach->accel.patt_data[0x10] ^ ((mach->accel.patt_idx & 1) ? 0xff : 0); + dev->accel.temp_cnt = 8; + } + } + + if (frgd_sel == 5) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + for (int x = 0; x <= mach->accel.patt_len; x += 2) { + mach->accel.color_pattern_word[x + (mach->accel.color_pattern_idx & 1)] = (mach->accel.patt_data[x & mach->accel.patt_len] & 0xff); + mach->accel.color_pattern_word[x + (mach->accel.color_pattern_idx & 1)] |= (mach->accel.patt_data[(x + 1) & mach->accel.patt_len] << 8); + } + } else { + if ((svga->bpp == 24) && (mach->accel.patt_len < 3)) { + for (int x = 0; x <= mach->accel.patt_len; x++) { + mach->accel.color_pattern[x] = mach->accel.patt_data[x]; + mach_log("BITBLT: Color Pattern 24bpp[%d]=%02x, dataidx=%d, pattlen=%d.\n", x, mach->accel.color_pattern[x], mach->accel.patt_data_idx, mach->accel.patt_len); + } + } else { + for (int x = 0; x <= mach->accel.patt_len; x++) { + mach->accel.color_pattern[x] = mach->accel.patt_data[x & mach->accel.patt_len]; + } + } + } + + /*The destination coordinates should match the pattern index.*/ + if (mach->accel.color_pattern_idx != mach->accel.patt_idx) + mach->accel.color_pattern_idx = mach->accel.patt_idx; + } + + if (mach->accel.dy_end == mach->accel.dy_start) { + mach_log("No DEST.\n"); + return; + } + + if ((mono_src == 3) || (bkgd_sel == 3) || (frgd_sel == 3)) { + if (mach->accel.sx_end == mach->accel.sx_start) { + mach_log("No SRC.\n"); + return; + } + } + + if (cpu_input) { + if (mach->accel.dp_config == 0x3251) { + if (dev->accel.sy == mach->accel.height) + return; + } + } + + while (count--) { + switch (mono_src) { + case 0: + mix = 1; + break; + case 1: + if (mach->accel.mono_pattern_enable) { + mix = mach->accel.mono_pattern[dev->accel.dy & 7][dev->accel.dx & 7]; + } else { + if ((svga->bpp == 24) && (frgd_sel == 5) && (mach->accel.patt_len_reg & 0x4000)) + mix = 1; + else { + if (!dev->accel.temp_cnt) { + dev->accel.temp_cnt = 8; + mix_dat >>= 8; + } + mix = (mix_dat & 0x80); + dev->accel.temp_cnt--; + mix_dat <<= 1; + mix_dat |= 1; + } + } + break; + case 2: + if (mach->accel.dp_config & 0x1000) { + mix = mix_dat >> 0x1f; + mix_dat <<= 1; + } else { + if (mach->accel.dp_config & 0x200) { + mix = mix_dat & 1; + mix_dat >>= 1; + } else { + mix = mix_dat & 0x80; + mix_dat <<= 1; + mix_dat |= 1; + } + } + break; + case 3: + READ(dev->accel.src + ((dev->accel.cx)), mix, dev->local); + mix = (mix & rd_mask) == rd_mask; + break; + + default: + break; + } + + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { + if (mach->accel.dp_config & 0x02) { + READ(dev->accel.src + (dev->accel.cx), poly_src, dev->local); + poly_src = ((poly_src & rd_mask) == rd_mask); + if (poly_src) + mach->accel.poly_fill = !mach->accel.poly_fill; + } + + if (!mach->accel.poly_fill || !(mach->accel.dp_config & 0x02)) { + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + READ(dev->accel.src + (dev->accel.cx), src_dat, dev->local); + if (mono_src == 3) { + src_dat = (src_dat & rd_mask) == rd_mask; + } + } + break; + case 5: + if (mix) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + src_dat = mach->accel.color_pattern_word[mach->accel.color_pattern_idx]; + } else { + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; + } + } else + src_dat = 0; + break; + + default: + break; + } + } + + if ((svga->bpp == 24) && (mono_src == 1) && (frgd_sel == 5) && (mach->accel.patt_len_reg & 0x4000)) { + if (dev->accel.sy & 1) { + READ(dev->accel.dest + dev->accel.dx - dev->ext_pitch, dest_dat, dev->local); + } else { + READ(dev->accel.dest + dev->accel.dx, dest_dat, dev->local); + } + } else { + READ(dev->accel.dest + dev->accel.dx, dest_dat, dev->local); + } + + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + + if (mach->accel.dp_config & 0x10) { + if ((svga->bpp == 24) && (mono_src == 1) && (frgd_sel == 5) && (mach->accel.patt_len_reg & 0x4000)) { + if (dev->accel.sy & 1) { + WRITE(dev->accel.dest + dev->accel.dx - dev->ext_pitch, dest_dat, dev->local); + } else { + WRITE(dev->accel.dest + dev->accel.dx, dest_dat, dev->local); + } + } else { + WRITE(dev->accel.dest + dev->accel.dx, dest_dat, dev->local); + } + } + } + + if ((svga->bpp == 8) || (svga->bpp == 24)) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + if ((mono_src == 3) || (frgd_sel == 3) || (bkgd_sel == 3)) { + dev->accel.cx += mach->accel.src_stepx; + mach->accel.sx++; + if (mach->accel.sx >= mach->accel.src_width) { + mach->accel.sx = 0; + if (mach->accel.src_stepx == -1) + dev->accel.cx += mach->accel.src_width; + else + dev->accel.cx -= mach->accel.src_width; + dev->accel.cy += (mach->accel.src_y_dir ? 1 : -1); + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.src = (mach->accel.ge_offset << 1) + (dev->accel.cy * (dev->pitch)); + else + dev->accel.src = (mach->accel.ge_offset << 2) + (dev->accel.cy * (dev->pitch)); + } + } + + dev->accel.dx += mach->accel.stepx; + + if ((svga->bpp == 8) || ((svga->bpp == 24) && (mach->accel.patt_len >= 3) && (mono_src != 1))) + mach->accel.color_pattern_idx = (mach->accel.color_pattern_idx + mach->accel.stepx) & mach->accel.patt_len; + + if ((svga->bpp == 24) && (mach->accel.color_pattern_idx == mach->accel.patt_len) && (mach->accel.patt_len >= 3) && (mono_src != 1)) { + mach->accel.color_pattern_idx = mach->accel.patt_data_idx; + } else if ((svga->bpp == 24) && (mach->accel.patt_len < 3)) { + if (mach->accel.patt_len == 2) { + mach->accel.color_pattern_idx++; + if (mach->accel.color_pattern_idx == 3) + mach->accel.color_pattern_idx = 0; + } else { + mach->accel.color_pattern_idx = (mach->accel.color_pattern_idx + mach->accel.stepx) & mach->accel.patt_len; + } + } else if ((svga->bpp == 24) && (mach->accel.patt_len_reg & 0x4000) && (frgd_sel == 5)) { + mach->accel.color_pattern_idx++; + if (mach->accel.color_pattern_idx == 3) + mach->accel.color_pattern_idx = 0; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + mach->accel.color_pattern_idx = (mach->accel.color_pattern_idx + mach->accel.stepx) & mach->accel.patt_len; + mach->accel.color_pattern_idx = (mach->accel.color_pattern_idx + mach->accel.stepx) & mach->accel.patt_len; + } + + dev->accel.sx++; + if (dev->accel.sx >= mach->accel.width) { + mach->accel.poly_fill = 0; + dev->accel.sx = 0; + if (mach->accel.stepx == -1) + dev->accel.dx += mach->accel.width; + else + dev->accel.dx -= mach->accel.width; + + dev->accel.dy += mach->accel.stepy; + dev->accel.sy++; + + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.dest = (mach->accel.ge_offset << 1) + (dev->accel.dy * (dev->pitch)); + else { + dev->accel.dest = (mach->accel.ge_offset << 2) + (dev->accel.dy * (dev->pitch)); + } + if ((mono_src == 1) && (svga->bpp == 24) && (frgd_sel == 5)) + mach->accel.color_pattern_idx = 0; + else + mach->accel.color_pattern_idx = ((dev->accel.dx + (dev->accel.dy << 3)) & mach->accel.patt_len); + + if ((svga->bpp == 24) && (mach->accel.color_pattern_idx == mach->accel.patt_len) && (mono_src != 1)) + mach->accel.color_pattern_idx = 0; + if ((mono_src == 1) && !mach->accel.mono_pattern_enable && !(mach->accel.patt_len_reg & 0x4000)) { + dev->accel.cur_x = dev->accel.dx; + dev->accel.cur_y = dev->accel.dy; + return; + } + if (dev->accel.sy >= mach->accel.height) { + if ((mono_src == 2) || (mono_src == 3) || (frgd_sel == 2) || (frgd_sel == 3) || (bkgd_sel == 2) || (bkgd_sel == 3)) + return; + if ((mono_src == 1) && (frgd_sel == 5) && (svga->bpp == 24) && (mach->accel.patt_len_reg & 0x4000)) + return; + dev->accel.cur_x = dev->accel.dx; + dev->accel.cur_y = dev->accel.dy; + return; + } + } + } + break; + + case 3: /*Direct Linedraw (Polyline) from linedraw indexes (0xfeee)*/ + case 4: + if (!cpu_input) { + dev->accel.cx = dev->accel.cur_x; + dev->accel.cy = dev->accel.cur_y; + + if (dev->accel.cur_x >= 0x600) { + mach_log("Linedraw XOver = %d.\n", dev->accel.cur_x); + dev->accel.cx |= ~0x5ff; + } + if (dev->accel.cur_y >= 0x600) { + mach_log("Linedraw YOver = %d.\n", dev->accel.cur_y); + dev->accel.cy |= ~0x5ff; + } + + dev->accel.dx = ABS(mach->accel.cx_end_line - dev->accel.cx) << 1; + dev->accel.dy = ABS(mach->accel.cy_end_line - dev->accel.cy) << 1; + + mach->accel.stepx = (mach->accel.cx_end_line < dev->accel.cx) ? -1 : 1; + mach->accel.stepy = (mach->accel.cy_end_line < dev->accel.cy) ? -1 : 1; + + dev->accel.sx = 0; + + mach_log("Linedraw: c(%d,%d), d(%d,%d), cend(%d,%d).\n", dev->accel.cur_x, dev->accel.cur_y, dev->accel.dx, dev->accel.dy, mach->accel.cx_end_line, mach->accel.cy_end_line); + + if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + if (mach_pixel_write(mach)) { + dev->data_available = 0; + dev->data_available2 = 0; + return; + } else if (mach_pixel_read(mach)) { + dev->data_available = 1; + dev->data_available2 = 1; + return; + } + } + } + + if (frgd_sel == 5) { + for (int x = 0; x <= mach->accel.patt_len; x++) { + mach->accel.color_pattern[x] = mach->accel.patt_data[x & mach->accel.patt_len]; + } + } + + if (mono_src == 1) { + mix_dat = mach->accel.patt_data[0x10]; + dev->accel.temp_cnt = 8; + } + + count = (dev->accel.dx > dev->accel.dy) ? (dev->accel.dx >> 1) : (dev->accel.dy >> 1); + mach->accel.width = count; + + if (dev->accel.dx > dev->accel.dy) { + mach->accel.err = (dev->accel.dy - dev->accel.dx) >> 1; + if (mono_src == 1) { + while (count--) { + if (!dev->accel.temp_cnt) { + dev->accel.temp_cnt = 8; + mix_dat >>= 8; + } + mix = (mix_dat & 0x80); + dev->accel.temp_cnt--; + mix_dat <<= 1; + mix_dat |= 1; + + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { + mach->accel.clip_overrun = 0; + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + src_dat = 0; + } + break; + case 5: + if (mix) { + src_dat = mach->accel.color_pattern[((dev->accel.cx) + ((dev->accel.cy) << 3)) & mach->accel.patt_len]; + } else + src_dat = 0; + break; + + default: + break; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + } + } else + mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); + + if (!count) + break; + + if (svga->bpp == 8) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + if (mach->accel.err >= 0) { + dev->accel.cy += mach->accel.stepy; + mach->accel.err -= dev->accel.dx; + } + dev->accel.cx += mach->accel.stepx; + mach->accel.err += dev->accel.dy; + } + } else { + while (count--) { + switch (mono_src) { + case 0: + case 3: + mix = 1; + break; + case 2: + if (mach->accel.dp_config & 0x1000) { + mix = mix_dat >> 0x1f; + mix_dat <<= 1; + } else { + if (mach->accel.dp_config & 0x200) { + mix = mix_dat & 1; + mix_dat >>= 1; + } else { + mix = mix_dat & 0x80; + mix_dat <<= 1; + mix_dat |= 1; + } + } + break; + + default: + break; + } + + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { + mach->accel.clip_overrun = 0; + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + src_dat = 0; + } + break; + case 5: + if (mix) { + src_dat = mach->accel.color_pattern[((dev->accel.cx) + ((dev->accel.cy) << 3)) & mach->accel.patt_len]; + } else + src_dat = 0; + break; + + default: + break; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + + if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { + if (mach->accel.linedraw_opt & 0x04) { + if (dev->accel.sx < mach->accel.width) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + } + } else { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + } + } + } else + mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); + + if (dev->accel.sx >= mach->accel.width) + break; + + if (svga->bpp == 8) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + if (mach->accel.err >= 0) { + dev->accel.cy += mach->accel.stepy; + mach->accel.err -= dev->accel.dx; + } + dev->accel.cx += mach->accel.stepx; + mach->accel.err += dev->accel.dy; + + dev->accel.sx++; + } + } + } else { + mach->accel.err = (dev->accel.dx - dev->accel.dy) >> 1; + if (mono_src == 1) { + while (count--) { + if (dev->accel.temp_cnt == 0) { + dev->accel.temp_cnt = 8; + mix_dat >>= 8; + } + mix = (mix_dat & 0x80); + dev->accel.temp_cnt--; + mix_dat <<= 1; + mix_dat |= 1; + + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { + mach->accel.clip_overrun = 0; + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + src_dat = 0; + } + break; + case 5: + if (mix) { + src_dat = mach->accel.color_pattern[((dev->accel.cx) + ((dev->accel.cy) << 3)) & mach->accel.patt_len]; + } else + src_dat = 0; + break; + + default: + break; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + + if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + } + } else + mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); + + if (!count) + break; + + if (svga->bpp == 8) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + if (mach->accel.err >= 0) { + dev->accel.cx += mach->accel.stepx; + mach->accel.err -= dev->accel.dy; + } + dev->accel.cy += mach->accel.stepy; + mach->accel.err += dev->accel.dx; + } + } else { + while (count--) { + switch (mono_src) { + case 0: + case 3: + mix = 1; + break; + case 2: + if (mach->accel.dp_config & 0x1000) { + mix = mix_dat >> 0x1f; + mix_dat <<= 1; + } else { + if (mach->accel.dp_config & 0x200) { + mix = mix_dat & 1; + mix_dat >>= 1; + } else { + mix = mix_dat & 0x80; + mix_dat <<= 1; + mix_dat |= 1; + } + } + break; + + default: + break; + } + + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { + mach->accel.clip_overrun = 0; + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + src_dat = 0; + } + break; + case 5: + if (mix) { + src_dat = mach->accel.color_pattern[((dev->accel.cx) + ((dev->accel.cy) << 3)) & mach->accel.patt_len]; + } else + src_dat = 0; + break; + + default: + break; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) { + READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + + if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { + if (mach->accel.linedraw_opt & 0x04) { + if (dev->accel.sx < mach->accel.width) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + } + } else { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } else { + WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat, dev->local); + } + } + } + } else + mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); + + if (dev->accel.sx >= mach->accel.width) + break; + + if (svga->bpp == 8) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + if (mach->accel.err >= 0) { + dev->accel.cx += mach->accel.stepx; + mach->accel.err -= dev->accel.dy; + } + dev->accel.cy += mach->accel.stepy; + mach->accel.err += dev->accel.dx; + + dev->accel.sx++; + } + } + } + mach->accel.line_array[(cmd_type == 4) ? 4 : 0] = dev->accel.cx; + mach->accel.line_array[(cmd_type == 4) ? 5 : 1] = dev->accel.cy; + dev->accel.cur_x = mach->accel.line_array[(cmd_type == 4) ? 4 : 0]; + dev->accel.cur_y = mach->accel.line_array[(cmd_type == 4) ? 5 : 1]; + break; + + case 5: /*Horizontal Raster Draw from scan_to_x register (0xcaee)*/ + if (!cpu_input) { + mach->accel.stepx = 0; + mach->accel.stepy = 0; + + dev->accel.dx = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + dev->accel.dx |= ~0x5ff; + dev->accel.dy = dev->accel.cur_y; + if (dev->accel.cur_y >= 0x600) + dev->accel.dy |= ~0x5ff; + + /*Destination Width*/ + mach->accel.dx_start = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + mach->accel.dx_start |= ~0x5ff; + mach->accel.dx_end = mach->accel.scan_to_x; + if (mach->accel.scan_to_x >= 0x600) + mach->accel.dx_end |= ~0x5ff; + + if (mach->accel.dx_end > mach->accel.dx_start) { + mach->accel.width = (mach->accel.dx_end - mach->accel.dx_start); + mach->accel.stepx = 1; + } else if (mach->accel.dx_end < mach->accel.dx_start) { + mach->accel.width = (mach->accel.dx_start - mach->accel.dx_end); + mach->accel.stepx = -1; + if (dev->accel.dx > 0) + dev->accel.dx--; + } else { + mach->accel.stepx = 1; + mach->accel.width = 0; + } + + dev->accel.sx = 0; + if ((svga->bpp == 24) && (mach->accel.patt_len < 0x17)) + mach->accel.color_pattern_idx = 0; + + /*Step Y*/ + mach->accel.dy_start = dev->accel.cur_y; + if (dev->accel.cur_y >= 0x600) + mach->accel.dy_start |= ~0x5ff; + mach->accel.dy_end = mach->accel.dest_y_end; + if (mach->accel.dest_y_end >= 0x600) + mach->accel.dy_end |= ~0x5ff; + + if (mach->accel.dy_end > mach->accel.dy_start) { + mach->accel.stepy = 1; + } else if (mach->accel.dy_end < mach->accel.dy_start) { + mach->accel.stepy = -1; + } else { + mach->accel.stepy = 0; + } + + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.dest = (mach->accel.ge_offset << 1) + (dev->accel.dy * (dev->pitch)); + else + dev->accel.dest = (mach->accel.ge_offset << 2) + (dev->accel.dy * (dev->pitch)); + + mach->accel.src_stepx = 0; + + /*Source Width*/ + dev->accel.cx = mach->accel.src_x; + if (mach->accel.src_x >= 0x600) + dev->accel.cx |= ~0x5ff; + dev->accel.cy = mach->accel.src_y; + if (mach->accel.src_y >= 0x600) + dev->accel.cy |= ~0x5ff; + + mach->accel.sx_start = mach->accel.src_x_start; + if (mach->accel.src_x_start >= 0x600) + mach->accel.sx_start |= ~0x5ff; + + mach->accel.sx_end = mach->accel.src_x_end; + if (mach->accel.src_x_end >= 0x600) + mach->accel.sx_end |= ~0x5ff; + + if (mach->accel.sx_end > mach->accel.sx_start) { + mach->accel.src_width = (mach->accel.sx_end - mach->accel.sx_start); + mach->accel.src_stepx = 1; + } else if (mach->accel.sx_end < mach->accel.sx_start) { + mach->accel.src_width = (mach->accel.sx_start - mach->accel.sx_end); + mach->accel.src_stepx = -1; + if (dev->accel.cx > 0) + dev->accel.cx--; + } else { + mach->accel.src_stepx = 1; + mach->accel.src_width = 0; + } + + mach->accel.sx = 0; + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.src = (mach->accel.ge_offset << 1) + (dev->accel.cy * (dev->pitch)); + else + dev->accel.src = (mach->accel.ge_offset << 2) + (dev->accel.cy * (dev->pitch)); + + if ((svga->bpp == 24) && (frgd_sel == 5)) { + if (mach->accel.patt_len == 0x17) + mach->accel.color_pattern_idx = 0; + dev->accel.x1 = dev->accel.dx + mach->accel.width; + if (dev->accel.x1 == dev->pitch) { + dev->accel.x2 = mach->accel.width & 1; + } else if ((dev->accel.x1 == mach->accel.width) && (dev->accel.dy & 1) && !dev->accel.y1 && dev->accel.x2) { + if (mach->accel.patt_len == 0x17) + mach->accel.color_pattern_idx = 3; + dev->accel.x3 = 1; + } else + dev->accel.x3 = 0; + } else + mach_log("ScanToX=%04x, Pitch=%d, C(%d,%d), SRCWidth=%d, WH(%d,%d), geoffset=%08x.\n", mach->accel.dp_config, dev->ext_pitch, dev->accel.cx, dev->accel.cy, mach->accel.src_width, mach->accel.width, mach->accel.height, (mach->accel.ge_offset << 1)); + + dev->accel.y1 = 0; + + if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + if (mach_pixel_write(mach)) { + dev->data_available = 0; + dev->data_available2 = 0; + return; + } else if (mach_pixel_read(mach)) { + dev->data_available = 1; + dev->data_available2 = 1; + return; + } + } + } + + if (mono_src == 1) { + count = mach->accel.width; + mix_dat = mach->accel.patt_data[0x10]; + dev->accel.temp_cnt = 8; + } + + if (frgd_sel == 5) { + if (svga->bpp != 24) { + for (int x = 0; x <= mach->accel.patt_len; x++) { + mach->accel.color_pattern[x] = mach->accel.patt_data[x & mach->accel.patt_len]; + } + } else { + if (mach->accel.patt_len == 0x17) { + for (int x = 0; x <= mach->accel.patt_len; x++) { + mach->accel.color_pattern_full[x] = mach->accel.patt_data[x]; + mach_log("ScanToX: Color Pattern 24bpp[%d]=%02x, dataidx=%d, pattlen=%d.\n", x, mach->accel.color_pattern_full[x], mach->accel.patt_data_idx, mach->accel.patt_len); + } + } else { + for (int x = 0; x <= mach->accel.patt_len; x++) { + mach->accel.color_pattern[x] = mach->accel.patt_data[x]; + mach_log("ScanToX: Color Pattern 24bpp[%d]=%02x, dataidx=%d, pattlen=%d.\n", x, mach->accel.color_pattern[x], mach->accel.patt_data_idx, mach->accel.patt_len); + } + } + } + } + + while (count--) { + switch (mono_src) { + case 0: + mix = 1; + break; + case 1: + if (dev->accel.temp_cnt == 0) { + dev->accel.temp_cnt = 8; + mix_dat >>= 8; + } + mix = (mix_dat & 0x80); + dev->accel.temp_cnt--; + mix_dat <<= 1; + mix_dat |= 1; + break; + case 2: + if (mach->accel.dp_config & 0x1000) { + mix = mix_dat >> 0x1f; + mix_dat <<= 1; + } else { + if (mach->accel.dp_config & 0x200) { + mix = mix_dat & 1; + mix_dat >>= 1; + } else { + mix = mix_dat & 0x80; + mix_dat <<= 1; + mix_dat |= 1; + } + } + break; + case 3: + READ(dev->accel.src + (dev->accel.cx), mix, dev->local); + mix = (mix & rd_mask) == rd_mask; + break; + + default: + break; + } + + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { + switch (mix ? frgd_sel : bkgd_sel) { + case 0: + src_dat = dev->accel.bkgd_color; + break; + case 1: + src_dat = dev->accel.frgd_color; + break; + case 2: + src_dat = cpu_dat; + break; + case 3: + if (mach_pixel_read(mach)) + src_dat = cpu_dat; + else { + READ(dev->accel.src + (dev->accel.cx), src_dat, dev->local); + if (mono_src == 3) { + src_dat = (src_dat & rd_mask) == rd_mask; + } + } + break; + case 5: + if (mix) { + if (svga->bpp == 24) { + if (mach->accel.patt_len == 0x17) + src_dat = mach->accel.color_pattern_full[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; + } else + src_dat = mach->accel.color_pattern[(dev->accel.dx + (dev->accel.dy << 3)) & mach->accel.patt_len]; + } else + src_dat = 0; + break; + + default: + break; + } + + READ(dev->accel.dest + (dev->accel.dx), dest_dat, dev->local); + + switch (compare_mode) { + case 1: + compare = 1; + break; + case 2: + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; + break; + case 3: + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; + break; + case 4: + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; + break; + case 5: + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; + break; + case 6: + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; + break; + case 7: + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: + break; + } + + if (!compare) { + if (mach_pixel_write(mach)) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + } + + if (mach->accel.dp_config & 0x10) { + WRITE(dev->accel.dest + (dev->accel.dx), dest_dat, dev->local); + } + } + + if ((svga->bpp == 8) || (svga->bpp == 24)) + cpu_dat >>= 8; + else + cpu_dat >>= 16; + + dev->accel.cx += mach->accel.src_stepx; + mach->accel.sx++; + if (mach->accel.sx >= mach->accel.src_width) { + mach->accel.sx = 0; + if (mach->accel.src_stepx == -1) { + dev->accel.cx += mach->accel.src_width; + } else + dev->accel.cx -= mach->accel.src_width; + dev->accel.cy += (mach->accel.src_y_dir ? 1 : -1); + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.src = (mach->accel.ge_offset << 1) + (dev->accel.cy * (dev->pitch)); + else + dev->accel.src = (mach->accel.ge_offset << 2) + (dev->accel.cy * (dev->pitch)); + } + + dev->accel.dx += mach->accel.stepx; + if ((svga->bpp == 24) && (mach->accel.patt_len == 0x17)) { + mach->accel.color_pattern_idx++; + if (dev->accel.x3) { + if (mach->accel.color_pattern_idx == 9) + mach->accel.color_pattern_idx = 3; + } else { + if (mach->accel.color_pattern_idx == 6) + mach->accel.color_pattern_idx = 0; + } + } else if ((svga->bpp == 24) && (mach->accel.patt_len < 3)) { + mach->accel.color_pattern_idx++; + if (mach->accel.color_pattern_idx == 3) + mach->accel.color_pattern_idx = 0; + } else + mach->accel.color_pattern_idx = (mach->accel.color_pattern_idx + mach->accel.stepx) & mach->accel.patt_len; + + dev->accel.sx++; + if (dev->accel.sx >= mach->accel.width) { + dev->accel.sx = 0; + dev->accel.dy += mach->accel.stepy; + if ((svga->bpp == 15) || (svga->bpp == 16)) + dev->accel.dest = (mach->accel.ge_offset << 1) + (dev->accel.dy * (dev->pitch)); + else + dev->accel.dest = (mach->accel.ge_offset << 2) + (dev->accel.dy * (dev->pitch)); + if (mach->accel.line_idx == 2) { + mach->accel.line_array[0] = dev->accel.dx; + mach->accel.line_array[4] = dev->accel.dx; + } + return; + } + } + break; + + default: + break; + } +} + +static void +mach_accel_out_pixtrans(mach_t *mach, ibm8514_t *dev, UNUSED(uint16_t port), uint16_t val, uint16_t len) +{ + int frgd_sel; + int bkgd_sel; + int mono_src; + + frgd_sel = (mach->accel.dp_config >> 13) & 7; + bkgd_sel = (mach->accel.dp_config >> 7) & 3; + mono_src = (mach->accel.dp_config >> 5) & 3; + + if ((mach->accel.dp_config & 4) && (mach->accel.cmd_type != 5)) { + val = (val >> 8) | (val << 8); + } + + switch (mach->accel.dp_config & 0x200) { + case 0x000: /*8-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + if ((mach->accel.dp_config & 0x1000) && dev->local) + val = (val >> 8) | (val << 8); + mach_accel_start(mach->accel.cmd_type, 1, 8, val | (val << 16), 0, mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, val | (val << 16), mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, val | (val << 16), mach, dev, len); + break; + case 0x200: /*16-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + if (mach->accel.dp_config & 0x1000) + val = (val >> 8) | (val << 8); + mach_accel_start(mach->accel.cmd_type, 1, 16, val | (val << 16), 0, mach, dev, len); + } else { + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, val | (val << 16), mach, dev, len); + } + } else { + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, val | (val << 16), mach, dev, len); + } + break; + + default: + break; + } +} + +static void +mach_out(uint16_t addr, uint8_t val, void *priv) +{ + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + const ibm8514_t *dev = &svga->dev8514; + uint8_t old; + uint8_t rs2; + + if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) + addr ^= 0x60; + + switch (addr) { + case 0x1ce: + mach->index = val; + break; + case 0x1cf: + old = mach->regs[mach->index]; + mach->regs[mach->index] = val; + mach_log("ATI VGA write reg=0x%02X, val=0x%02X\n", mach->index, val); + switch (mach->index) { + case 0xa3: + if ((old ^ val) & 0x10) + svga_recalctimings(svga); + break; + case 0xa7: + if ((old ^ val) & 0x80) + svga_recalctimings(svga); + break; + case 0xad: + if (dev->local) { + if ((old ^ val) & 0x0c) + svga_recalctimings(svga); + } + break; + case 0xb0: + if ((old ^ val) & 0x60) + svga_recalctimings(svga); + break; + case 0xae: + case 0xb2: + case 0xbe: + mach_log("ATI VGA write reg=0x%02X, val=0x%02X\n", mach->index, val); + if (mach->regs[0xbe] & 0x08) { /* Read/write bank mode */ + mach->bank_r = (((mach->regs[0xb2] & 1) << 3) | ((mach->regs[0xb2] & 0xe0) >> 5)); + mach->bank_w = ((mach->regs[0xb2] & 0x1e) >> 1); + if (dev->local) { + mach->bank_r |= ((mach->regs[0xae] & 0x0c) << 2); + mach->bank_w |= ((mach->regs[0xae] & 3) << 4); + } + if (ibm8514_on) + mach_log("Separate B2Bank = %02x, AEbank = %02x.\n", mach->regs[0xb2], mach->regs[0xae]); + } else { /* Single bank mode */ + mach->bank_w = ((mach->regs[0xb2] & 0x1e) >> 1); + if (dev->local) { + mach->bank_w |= ((mach->regs[0xae] & 3) << 4); + } + mach->bank_r = mach->bank_w; + if (ibm8514_on) + mach_log("Single B2Bank = %02x, AEbank = %02x.\n", mach->regs[0xb2], mach->regs[0xae]); + } + svga->read_bank = mach->bank_r << 16; + svga->write_bank = mach->bank_w << 16; + + if (mach->index == 0xbe) { + if ((old ^ val) & 0x10) + svga_recalctimings(svga); + } + break; + case 0xbd: + if ((old ^ val) & 4) { + mach32_updatemapping(mach); + } + break; + case 0xb3: + ati_eeprom_write(&mach->eeprom, val & 8, val & 2, val & 1); + break; + case 0xb6: + if ((old ^ val) & 0x10) + svga_recalctimings(svga); + break; + case 0xb8: + if (dev->local) { + if ((old ^ val) & 0x40) + svga_recalctimings(svga); + } else { + if ((old ^ val) & 0xc0) + svga_recalctimings(svga); + } + break; + case 0xb9: + if ((old ^ val) & 2) + svga_recalctimings(svga); + break; + + default: + break; + } + break; + + case 0x2ea: + case 0x2eb: + case 0x2ec: + case 0x2ed: + rs2 = !!(mach->accel.ext_ge_config & 0x1000); + if (dev->local) { + if (mach->pci_bus) + ati68860_ramdac_out((addr & 3) | (rs2 << 2), val, svga->ramdac, svga); + else + svga_out(addr, val, svga); + } else + svga_out(addr, val, svga); + return; + + case 0x3C6: + case 0x3C7: + case 0x3C8: + case 0x3C9: + rs2 = !!(mach->accel.ext_ge_config & 0x1000); + if (dev->local) { + if (mach->pci_bus) + ati68860_ramdac_out((addr & 3) | (rs2 << 2), val, svga->ramdac, svga); + else + svga_out(addr, val, svga); + } else + svga_out(addr, val, svga); + return; + + case 0x3CF: + if (svga->gdcaddr == 6) { + uint8_t old_val = svga->gdcreg[6]; + svga->gdcreg[6] = val; + if ((svga->gdcreg[6] & 0xc) != (old_val & 0xc)) + mach32_updatemapping(mach); + return; + } + break; + + case 0x3D4: + svga->crtcreg = val & 0x3f; + return; + case 0x3D5: + if ((svga->crtcreg < 7) && (svga->crtc[0x11] & 0x80)) + return; + if ((svga->crtcreg == 7) && (svga->crtc[0x11] & 0x80)) + val = (svga->crtc[7] & ~0x10) | (val & 0x10); + + old = svga->crtc[svga->crtcreg]; + svga->crtc[svga->crtcreg] = val; + if (old != val) { + if (svga->crtcreg < 0xe || svga->crtcreg > 0x10) { + if ((svga->crtcreg == 0xc) || (svga->crtcreg == 0xd)) { + svga->fullchange = 3; + svga->ma_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); + } else { + svga->fullchange = changeframecount; + svga_recalctimings(svga); + } + } + } + break; + + default: + break; + } + svga_out(addr, val, svga); +} + +static uint8_t +mach_in(uint16_t addr, void *priv) +{ + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + const ibm8514_t *dev = &svga->dev8514; + uint8_t temp; + uint8_t rs2; + + if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) + addr ^= 0x60; + + switch (addr) { + case 0x1ce: + temp = mach->index; + break; + case 0x1cf: + switch (mach->index) { + case 0xa8: + temp = (svga->vc >> 8) & 3; + break; + case 0xa9: + temp = svga->vc & 0xff; + break; + case 0xb0: + temp = mach->regs[0xb0] | 0x80; + if (dev->local) { /*Mach32 VGA 1MB memory*/ + temp |= 0x08; + temp &= ~0x10; + } else { /*ATI 28800 VGA 512kB memory*/ + temp &= ~0x08; + temp |= 0x10; + } + break; + case 0xb7: + temp = mach->regs[0xb7] & ~8; + if (ati_eeprom_read(&mach->eeprom)) + temp |= 8; + break; + + default: + temp = mach->regs[mach->index]; + break; + } + break; + + case 0x2ea: + case 0x2eb: + case 0x2ec: + case 0x2ed: + rs2 = !!(mach->accel.ext_ge_config & 0x1000); + if (dev->local) { + if (mach->pci_bus) + return ati68860_ramdac_in((addr & 3) | (rs2 << 2), svga->ramdac, svga); + else + return svga_in(addr, svga); + } + return svga_in(addr, svga); + + case 0x3C6: + case 0x3C7: + case 0x3C8: + case 0x3C9: + rs2 = !!(mach->accel.ext_ge_config & 0x1000); + if (dev->local) { + if (mach->pci_bus) + return ati68860_ramdac_in((addr & 3) | (rs2 << 2), svga->ramdac, svga); + else + return svga_in(addr, svga); + } + return svga_in(addr, svga); + + case 0x3D4: + temp = svga->crtcreg; + break; + case 0x3D5: + temp = svga->crtc[svga->crtcreg]; + break; + case 0x3DA: + svga->attrff = 0; + if (svga->cgastat & 0x01) + svga->cgastat &= ~0x38; + else + svga->cgastat ^= 0x38; + return svga->cgastat; + + default: + temp = svga_in(addr, svga); + break; + } + return temp; +} + +static void +mach_recalctimings(svga_t *svga) +{ + const mach_t *mach = (mach_t *) svga->priv; + ibm8514_t *dev = &svga->dev8514; + + if (vga_on && !ibm8514_on) { + switch (((mach->regs[0xbe] & 0x10) >> 1) | ((mach->regs[0xb9] & 2) << 1) | ((svga->miscout & 0x0c) >> 2)) { + case 0x00: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 42954000.0; + break; + case 0x01: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 48771000.0; + break; + case 0x02: + mach_log("clock 2\n"); + break; + case 0x03: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; + break; + case 0x04: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; + break; + case 0x05: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 56640000.0; + break; + case 0x06: + mach_log("clock 2\n"); + break; + case 0x07: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + break; + case 0x08: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 30240000.0; + break; + case 0x09: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 32000000.0; + break; + case 0x0A: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 37500000.0; + break; + case 0x0B: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 39000000.0; + break; + case 0x0C: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; + break; + case 0x0D: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 56644000.0; + break; + case 0x0E: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 75000000.0; + break; + case 0x0F: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; + break; + + default: + break; + } + } + + if (mach->regs[0xa3] & 0x10) + svga->ma_latch |= 0x10000; + + if (mach->regs[0xb0] & 0x40) + svga->ma_latch |= 0x20000; + + if (dev->local) { + if (mach->regs[0xad] & 0x04) + svga->ma_latch |= 0x40000; + + if (mach->regs[0xad] & 0x08) + svga->ma_latch |= 0x80000; + + if (mach->regs[0xb8] & 0x40) + svga->clock *= 2; + } else { + switch (mach->regs[0xb8] & 0xc0) { + case 0x40: + svga->clock *= 2; + break; + case 0x80: + svga->clock *= 3; + break; + case 0xc0: + svga->clock *= 4; + break; + + default: + break; + } + } + + if (mach->regs[0xa7] & 0x80) + svga->clock *= 3; + + if (mach->regs[0xb6] & 0x10) { + svga->hdisp <<= 1; + svga->htotal <<= 1; + svga->rowoffset <<= 1; + svga->gdcreg[5] &= ~0x40; + } + + if (mach->regs[0xb0] & 0x20) { + svga->gdcreg[5] |= 0x40; + } + + if (vga_on && !ibm8514_on) { + if (!svga->scrblank && (svga->crtc[0x17] & 0x80) && svga->attr_palette_enable) { + if ((svga->gdcreg[6] & 1) || (svga->attrregs[0x10] & 1)) { + switch (svga->gdcreg[5] & 0x60) { + case 0x00: + if (svga->seqregs[1] & 8) /*Low res (320)*/ + svga->render = svga_render_4bpp_lowres; + else + svga->render = svga_render_4bpp_highres; + break; + case 0x20: /*4 colours*/ + if (svga->seqregs[1] & 8) /*Low res (320)*/ + svga->render = svga_render_2bpp_lowres; + else + svga->render = svga_render_2bpp_highres; + break; + case 0x40: + case 0x60: /*256+ colours*/ + switch (svga->bpp) { + case 8: + svga->map8 = svga->pallook; + if (svga->lowres) + svga->render = svga_render_8bpp_lowres; + else { + svga->render = svga_render_8bpp_highres; + svga->ma_latch <<= 1; + svga->rowoffset <<= 1; + } + break; + + default: + break; + } + break; + + default: + break; + } + } + } + } else if (dev->local) { + if (ibm8514_on) { + svga->hdisp_time = svga->hdisp = (dev->hdisp + 1) << 3; + dev->pitch = (dev->accel.advfunc_cntl & 4) ? 1024 : 640; + svga->htotal = (dev->htotal + 1); + svga->vtotal = (dev->vtotal + 1); + svga->vsyncstart = (dev->vsyncstart + 1); + svga->rowcount = !!(dev->disp_cntl & 0x08); + svga->dispend = ((dev->vdisp >> 1) + 1); + svga->interlace = dev->interlace; + svga->split = 0xffffff; + svga->vblankstart = svga->dispend; + + if (svga->dispend == 766) { + svga->dispend = 768; + svga->vblankstart = svga->dispend; + } + + if (svga->dispend == 598) { + svga->dispend = 600; + svga->vblankstart = svga->dispend; + } + + if (dev->accel.advfunc_cntl & 4) { + if (dev->ibm_mode) { + if (svga->hdisp == 8) { + svga->hdisp = 1024; + svga->dispend = 768; + svga->vtotal = 1536; + svga->vsyncstart = 1536; + } + } + + if (svga->interlace) { + svga->dispend >>= 1; + svga->vsyncstart >>= 2; + svga->vtotal >>= 2; + } else { + svga->vsyncstart >>= 1; + svga->vtotal >>= 1; + } + + dev->pitch = dev->ext_pitch; + svga->rowoffset = dev->ext_crt_pitch; + + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + } else { + if (dev->ibm_mode) { + if ((svga->hdisp == 1024) && !dev->internal_pitch) { + svga->hdisp = 640; + svga->dispend = 480; + } + } + + if (svga->interlace) { + svga->dispend >>= 1; + svga->vsyncstart >>= 2; + svga->vtotal >>= 2; + } else { + svga->vsyncstart >>= 1; + svga->vtotal >>= 1; + } + + dev->pitch = dev->ext_pitch; + svga->rowoffset = dev->ext_crt_pitch; + + svga->clock = (cpuclock * (double) (1ULL << 32)) / 25175000.0; + } + switch (svga->bpp) { + default: + case 8: + svga->render = svga_render_8bpp_highres; + break; + case 15: + svga->render = svga_render_15bpp_highres; + break; + case 16: + svga->render = svga_render_16bpp_highres; + break; + case 24: + svga->render = svga_render_24bpp_highres; + break; + } + mach_log("BPP=%d, VRAM Mask=%08x, NormalPitch=%d, CRTPitch=%d, VSYNCSTART=%d, VTOTAL=%d, ROWCOUNT=%d, mode=%d, highres bit=%x, has_vga?=%d, override=%d.\n", svga->bpp, svga->vram_mask, dev->pitch, dev->ext_crt_pitch, svga->vsyncstart, svga->vtotal, svga->rowcount, dev->ibm_mode, dev->accel.advfunc_cntl & 4, ibm8514_has_vga, svga->override); + } + mach_log("8514 enabled, hdisp=%d, vtotal=%d, htotal=%d, dispend=%d, rowoffset=%d, split=%d, vsyncstart=%d, split=%08x\n", svga->hdisp, svga->vtotal, svga->htotal, svga->dispend, svga->rowoffset, svga->split, svga->vsyncstart, svga->split); + } +} + +static void +mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, uint32_t val, int len) +{ + int frgd_sel; + int bkgd_sel; + int mono_src; + + switch (port) { + case 0x82e8: + case 0xc2e8: + if (len == 1) { + dev->accel.cur_y = (dev->accel.cur_y & 0x700) | val; + } else { + dev->accel.cur_y = val & 0x7ff; + } + break; + case 0x82e9: + case 0xc2e9: + if (len == 1) { + dev->accel.cur_y = (dev->accel.cur_y & 0xff) | ((val & 0x07) << 8); + } + break; + + case 0x86e8: + case 0xc6e8: + if (len == 1) { + dev->accel.cur_x = (dev->accel.cur_x & 0x700) | val; + } else { + dev->accel.cur_x = val & 0x7ff; + } + break; + case 0x86e9: + case 0xc6e9: + if (len == 1) { + dev->accel.cur_x = (dev->accel.cur_x & 0xff) | ((val & 0x07) << 8); + } + break; + + case 0x8ae8: + case 0xcae8: + if (len == 1) + dev->accel.desty_axstp = (dev->accel.desty_axstp & 0x3f00) | val; + else { + mach->accel.src_y = val; + dev->accel.desty_axstp = val & 0x3fff; + if (val & 0x2000) + dev->accel.desty_axstp |= ~0x1fff; + } + break; + case 0x8ae9: + case 0xcae9: + if (len == 1) { + dev->accel.desty_axstp = (dev->accel.desty_axstp & 0xff) | ((val & 0x3f) << 8); + if (val & 0x20) + dev->accel.desty_axstp |= ~0x1fff; + } + break; + + case 0x8ee8: + case 0xcee8: + if (len == 1) + dev->accel.destx_distp = (dev->accel.destx_distp & 0x3f00) | val; + else { + mach->accel.src_x = val; + dev->accel.destx_distp = val & 0x3fff; + if (val & 0x2000) + dev->accel.destx_distp |= ~0x1fff; + } + break; + case 0x8ee9: + case 0xcee9: + if (len == 1) { + dev->accel.destx_distp = (dev->accel.destx_distp & 0xff) | ((val & 0x3f) << 8); + if (val & 0x20) + dev->accel.destx_distp |= ~0x1fff; + } + break; + + case 0x92e8: + if (len != 1) + dev->test = val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case 0xd2e8: + mach_log("92E8 = %04x\n", val); + if (len == 1) + dev->accel.err_term = (dev->accel.err_term & 0x3f00) | val; + else { + dev->accel.err_term = val & 0x3fff; + if (val & 0x2000) + dev->accel.err_term |= ~0x1fff; + } + break; + case 0x92e9: + case 0xd2e9: + if (len == 1) { + dev->accel.err_term = (dev->accel.err_term & 0xff) | ((val & 0x3f) << 8); + if (val & 0x20) + dev->accel.err_term |= ~0x1fff; + } + break; + + case 0x96e8: + case 0xd6e8: + if (len == 1) + dev->accel.maj_axis_pcnt = (dev->accel.maj_axis_pcnt & 0x0700) | val; + else { + mach->accel.test = val & 0x1fff; + dev->accel.maj_axis_pcnt = val & 0x07ff; + } + break; + case 0x96e9: + case 0xd6e9: + if (len == 1) { + dev->accel.maj_axis_pcnt = (dev->accel.maj_axis_pcnt & 0xff) | ((val & 0x07) << 8); + } + break; + + case 0x9ae8: + case 0xdae8: + dev->accel.ssv_state = 0; + if (len == 1) + dev->accel.cmd = (dev->accel.cmd & 0xff00) | val; + else { + dev->data_available = 0; + dev->data_available2 = 0; + dev->accel.cmd = val; + mach_log("CMD8514 = %04x.\n", val); + mach->accel.cmd_type = -1; + if (port == 0xdae8) { + if (dev->accel.cmd & 0x100) + dev->accel.cmd_back = 0; + } + ibm8514_accel_start(-1, 0, -1, 0, svga, len); + } + break; + case 0x9ae9: + case 0xdae9: + if (len == 1) { + dev->data_available = 0; + dev->data_available2 = 0; + dev->accel.cmd = (dev->accel.cmd & 0xff) | (val << 8); + mach->accel.cmd_type = -1; + if (port == 0xdae9) { + if (dev->accel.cmd & 0x100) + dev->accel.cmd_back = 0; + } + ibm8514_accel_start(-1, 0, -1, 0, svga, len); + } + break; + + case 0x9ee8: + case 0xdee8: + dev->accel.ssv_state = 1; + if (len == 1) + dev->accel.short_stroke = (dev->accel.short_stroke & 0xff00) | val; + else { + dev->accel.short_stroke = val; + dev->accel.cx = dev->accel.cur_x; + dev->accel.cy = dev->accel.cur_y; + + if (dev->accel.cur_x >= 0x600) { + dev->accel.cx |= ~0x5ff; + } + if (dev->accel.cur_y >= 0x600) { + dev->accel.cy |= ~0x5ff; + } + + if (dev->accel.cmd & 0x1000) { + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); + } else { + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); + } + } + break; + case 0x9ee9: + case 0xdee9: + if (len == 1) { + dev->accel.short_stroke = (dev->accel.short_stroke & 0xff) | (val << 8); + dev->accel.cx = dev->accel.cur_x; + dev->accel.cy = dev->accel.cur_y; + + if (dev->accel.cur_x >= 0x600) { + dev->accel.cx |= ~0x5ff; + } + if (dev->accel.cur_y >= 0x600) { + dev->accel.cy |= ~0x5ff; + } + + if (dev->accel.cmd & 0x1000) { + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); + } else { + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke >> 8, len); + ibm8514_short_stroke_start(-1, 0, -1, 0, svga, dev->accel.short_stroke & 0xff, len); + } + } + break; + + case 0xa2e8: + case 0xe2e8: + if (port == 0xe2e8) { + if (dev->accel.cmd_back) { + if (len == 1) + dev->accel.bkgd_color = (dev->accel.bkgd_color & 0x00ff) | val; + else + dev->accel.bkgd_color = val; + } else { + if (len == 1) { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + mach->accel.pix_trans[1] = val; + } + } else { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + mach_accel_out_pixtrans(mach, dev, port, val, len); + } else { + if (ibm8514_cpu_dest(svga)) + break; + ibm8514_accel_out_pixtrans(svga, port, val, len); + } + } + } + } else { + if (len == 1) + dev->accel.bkgd_color = (dev->accel.bkgd_color & 0x00ff) | val; + else + dev->accel.bkgd_color = val; + } + break; + case 0xa2e9: + case 0xe2e9: + if (port == 0xe2e9) { + if (dev->accel.cmd_back) { + if (len == 1) + dev->accel.bkgd_color = (dev->accel.bkgd_color & 0xff00) | (val << 8); + } else { + if (len == 1) { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + mach->accel.pix_trans[0] = val; + frgd_sel = (mach->accel.dp_config >> 13) & 7; + bkgd_sel = (mach->accel.dp_config >> 7) & 3; + mono_src = (mach->accel.dp_config >> 5) & 3; + + switch (mach->accel.dp_config & 0x200) { + case 0x000: /*8-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + mach_accel_start(mach->accel.cmd_type, 1, 8, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + break; + case 0x200: /*16-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + if (mach->accel.dp_config & 0x1000) + mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[1] | (mach->accel.pix_trans[0] << 8), 0, mach, dev, len); + else + mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + break; + + default: + break; + } + } + } + } + } else { + if (len == 1) + dev->accel.bkgd_color = (dev->accel.bkgd_color & 0xff00) | (val << 8); + } + break; + + case 0xa6e8: + case 0xe6e8: + if (port == 0xe6e8) { + if (dev->accel.cmd_back) { + if (len == 1) + dev->accel.frgd_color = (dev->accel.frgd_color & 0x00ff) | val; + else + dev->accel.frgd_color = val; + } else { + if (len == 1) { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + mach->accel.pix_trans[1] = val; + } + } else { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + mach_accel_out_pixtrans(mach, dev, port, val, len); + } else { + if (ibm8514_cpu_dest(svga)) + break; + ibm8514_accel_out_pixtrans(svga, port, val, len); + } + } + } + } else { + if (len == 1) + dev->accel.frgd_color = (dev->accel.frgd_color & 0x00ff) | val; + else + dev->accel.frgd_color = val; + } + break; + case 0xa6e9: + case 0xe6e9: + if (port == 0xe6e9) { + if (dev->accel.cmd_back) { + if (len == 1) + dev->accel.frgd_color = (dev->accel.frgd_color & 0xff00) | (val << 8); + } else { + if (len == 1) { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + mach->accel.pix_trans[0] = val; + frgd_sel = (mach->accel.dp_config >> 13) & 7; + bkgd_sel = (mach->accel.dp_config >> 7) & 3; + mono_src = (mach->accel.dp_config >> 5) & 3; + + switch (mach->accel.dp_config & 0x200) { + case 0x000: /*8-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + mach_accel_start(mach->accel.cmd_type, 1, 8, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + break; + case 0x200: /*16-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + if (mach->accel.dp_config & 0x1000) + mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[1] | (mach->accel.pix_trans[0] << 8), 0, mach, dev, len); + else + mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + break; + + default: + break; + } + } + } + } + } else { + if (len == 1) + dev->accel.frgd_color = (dev->accel.frgd_color & 0xff00) | (val << 8); + } + break; + + case 0xaae8: + case 0xeae8: + if (len == 1) + dev->accel.wrt_mask = (dev->accel.wrt_mask & 0x00ff) | val; + else + dev->accel.wrt_mask = val; + break; + case 0xaae9: + case 0xeae9: + if (len == 1) + dev->accel.wrt_mask = (dev->accel.wrt_mask & 0xff00) | (val << 8); + break; + + case 0xaee8: + case 0xeee8: + if (len == 1) + dev->accel.rd_mask = (dev->accel.rd_mask & 0x00ff) | val; + else + dev->accel.rd_mask = val; + break; + case 0xaee9: + case 0xeee9: + if (len == 1) + dev->accel.rd_mask = (dev->accel.rd_mask & 0xff00) | (val << 8); + break; + + case 0xb2e8: + case 0xf2e8: + if (len == 1) + dev->accel.color_cmp = (dev->accel.color_cmp & 0x00ff) | val; + else + dev->accel.color_cmp = val; + break; + case 0xb2e9: + case 0xf2e9: + if (len == 1) + dev->accel.color_cmp = (dev->accel.color_cmp & 0xff00) | (val << 8); + break; + + case 0xb6e8: + case 0xf6e8: + dev->accel.bkgd_mix = val & 0xff; + break; + + case 0xbae8: + case 0xfae8: + dev->accel.frgd_mix = val & 0xff; + break; + + case 0xbee8: + case 0xfee8: + if (len == 1) + dev->accel.multifunc_cntl = (dev->accel.multifunc_cntl & 0xff00) | val; + else { + dev->accel.multifunc_cntl = val; + dev->accel.multifunc[dev->accel.multifunc_cntl >> 12] = dev->accel.multifunc_cntl & 0xfff; + if ((dev->accel.multifunc_cntl >> 12) == 1) { + dev->accel.clip_top = val & 0x7ff; + } + if ((dev->accel.multifunc_cntl >> 12) == 2) { + dev->accel.clip_left = val & 0x7ff; + } + if ((dev->accel.multifunc_cntl >> 12) == 3) { + dev->accel.multifunc[3] = val & 0x7ff; + } + if ((dev->accel.multifunc_cntl >> 12) == 4) { + dev->accel.multifunc[4] = val & 0x7ff; + } + mach_log("CLIPBOTTOM=%d, CLIPRIGHT=%d, bpp=%d, pitch=%d.\n", dev->accel.multifunc[3], dev->accel.multifunc[4], svga->bpp, dev->pitch); + if ((dev->accel.multifunc_cntl >> 12) == 5) { + if (!dev->local || !dev->ext_crt_pitch) + dev->ext_crt_pitch = 128; + svga_recalctimings(svga); + } + if (port == 0xfee8) + dev->accel.cmd_back = 1; + else + dev->accel.cmd_back = 0; + } + break; + case 0xbee9: + case 0xfee9: + if (len == 1) { + dev->accel.multifunc_cntl = (dev->accel.multifunc_cntl & 0xff) | (val << 8); + dev->accel.multifunc[dev->accel.multifunc_cntl >> 12] = dev->accel.multifunc_cntl & 0xfff; + if ((dev->accel.multifunc_cntl >> 12) == 1) { + dev->accel.clip_top = dev->accel.multifunc_cntl & 0x7ff; + } + if ((dev->accel.multifunc_cntl >> 12) == 2) { + dev->accel.clip_left = dev->accel.multifunc_cntl & 0x7ff; + } + if ((dev->accel.multifunc_cntl >> 12) == 5) { + if (!dev->local || !dev->ext_crt_pitch) + dev->ext_crt_pitch = 128; + svga_recalctimings(svga); + } + if (port == 0xfee9) + dev->accel.cmd_back = 1; + else + dev->accel.cmd_back = 0; + } + break; + + /*ATI Mach8/32 specific registers*/ + case 0x82ee: + mach->accel.patt_data_idx = val & 0x1f; + mach_log("Pattern Data Index = %d.\n", val & 0x1f); + break; + + case 0x8eee: + if (len == 1) { + mach->accel.patt_data[mach->accel.patt_data_idx] = val; + } else { + mach->accel.patt_data[mach->accel.patt_data_idx] = val & 0xff; + mach->accel.patt_data[mach->accel.patt_data_idx + 1] = (val >> 8) & 0xff; + if (mach->accel.mono_pattern_enable) + mach->accel.patt_data_idx = (mach->accel.patt_data_idx + 2) & 0x17; + else { + frgd_sel = (mach->accel.dp_config >> 13) & 7; + mono_src = (mach->accel.dp_config >> 5) & 3; + if ((svga->bpp == 24) && (mach->accel.patt_len == 0x17) && (frgd_sel == 5)) { + mach->accel.patt_data_idx += 2; + dev->accel.y1 = 1; + } else { + if (svga->bpp == 24) + mach->accel.patt_data_idx += 2; + else + mach->accel.patt_data_idx = (mach->accel.patt_data_idx + 2) & mach->accel.patt_len; + } + mach_log("ExtCONFIG = %04x, Pattern Mono = %04x, selidx = %d, dataidx = %d, bit 0 = %02x len = %d.\n", mach->accel.ext_ge_config, val, mach->accel.patt_idx, mach->accel.patt_data_idx, val & 1, mach->accel.patt_len); + } + } + break; + case 0x8eef: + if (len == 1) { + mach->accel.patt_data[mach->accel.patt_data_idx + 1] = val; + if (mach->accel.mono_pattern_enable) + mach->accel.patt_data_idx = (mach->accel.patt_data_idx + 2) & 7; + else { + frgd_sel = (mach->accel.dp_config >> 13) & 7; + if ((svga->bpp == 24) && (mach->accel.patt_len == 0x17) && (frgd_sel == 5)) { + mach->accel.patt_data_idx += 2; + dev->accel.y1 = 1; + } else + mach->accel.patt_data_idx = (mach->accel.patt_data_idx + 2) & mach->accel.patt_len; + } + } + break; + + case 0x96ee: + if (len == 1) + mach->accel.bres_count = (mach->accel.bres_count & 0x700) | val; + else { + mach->accel.bres_count = val & 0x7ff; + mach_log("96EE line draw.\n"); + dev->data_available = 0; + dev->data_available2 = 0; + mach->accel.cmd_type = 1; + mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); + } + break; + case 0x96ef: + if (len == 1) { + mach->accel.bres_count = (mach->accel.bres_count & 0xff) | ((val & 0x07) << 8); + mach_log("96EE (2) line draw.\n"); + dev->data_available = 0; + dev->data_available2 = 0; + mach->accel.cmd_type = 1; + mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); + } + break; + + case 0x9aee: + mach->accel.line_idx = val & 0x07; + break; + + case 0xa2ee: + mach_log("Line OPT = %04x\n", val); + if (len == 1) + mach->accel.linedraw_opt = (mach->accel.linedraw_opt & 0xff00) | val; + else { + mach->accel.linedraw_opt = val; + } + break; + case 0xa2ef: + if (len == 1) { + mach->accel.linedraw_opt = (mach->accel.linedraw_opt & 0x00ff) | (val << 8); + } + break; + + case 0xa6ee: + if (len == 1) + mach->accel.dest_x_start = (mach->accel.dest_x_start & 0x700) | val; + else + mach->accel.dest_x_start = val & 0x7ff; + break; + case 0xa6ef: + if (len == 1) + mach->accel.dest_x_start = (mach->accel.dest_x_start & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xaaee: + if (len == 1) + mach->accel.dest_x_end = (mach->accel.dest_x_end & 0x700) | val; + else { + mach->accel.dest_x_end = val & 0x7ff; + } + break; + case 0xaaef: + if (len == 1) + mach->accel.dest_x_end = (mach->accel.dest_x_end & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xaeee: + mach_log("AEEE write val = %04x.\n", val); + if (len == 1) + mach->accel.dest_y_end = (mach->accel.dest_y_end & 0x700) | val; + else { + mach->accel.dest_y_end = val & 0x7ff; + if ((val + 1) == 0x10000) { + mach_log("Dest_Y_end overflow val = %04x\n", val); + mach->accel.dest_y_end = 0; + } + dev->data_available = 0; + dev->data_available2 = 0; + mach_log("BitBLT = %04x.\n", mach->accel.dp_config); + mach->accel.cmd_type = 2; /*Non-conforming BitBLT from dest_y_end register (0xaeee)*/ + mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); + } + break; + case 0xaeef: + if (len == 1) { + mach->accel.dest_y_end = (mach->accel.dest_y_end & 0x0ff) | ((val & 0x07) << 8); + dev->data_available = 0; + dev->data_available2 = 0; + mach->accel.cmd_type = 2; /*Non-conforming BitBLT from dest_y_end register (0xaeee)*/ + mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); + } + break; + + case 0xb2ee: + if (len == 1) + mach->accel.src_x_start = (mach->accel.src_x_start & 0x700) | val; + else + mach->accel.src_x_start = val & 0x7ff; + break; + case 0xb2ef: + if (len == 1) + mach->accel.src_x_start = (mach->accel.src_x_start & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xb6ee: + dev->accel.bkgd_mix = val & 0xff; + break; + + case 0xbaee: + dev->accel.frgd_mix = val & 0xff; + break; + + case 0xbeee: + if (len == 1) + mach->accel.src_x_end = (mach->accel.src_x_end & 0x700) | val; + else { + mach->accel.src_x_end = val & 0x7ff; + } + break; + case 0xbeef: + if (len == 1) + mach->accel.src_x_end = (mach->accel.src_x_end & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xc2ee: + mach->accel.src_y_dir = val & 1; + break; + + case 0xc6ee: + mach->accel.cmd_type = 0; + mach_log("TODO: Short Stroke.\n"); + break; + + case 0xcaee: + mach_log("CAEE write val = %04x.\n", val); + if (len == 1) + mach->accel.scan_to_x = (mach->accel.scan_to_x & 0x700) | val; + else { + mach->accel.scan_to_x = (val & 0x7ff); + if ((val + 1) == 0x10000) { + mach_log("Scan_to_X overflow val = %04x\n", val); + mach->accel.scan_to_x = 0; + } + dev->data_available = 0; + dev->data_available2 = 0; + mach->accel.cmd_type = 5; /*Horizontal Raster Draw from scan_to_x register (0xcaee)*/ + mach_log("ScanToX = %04x.\n", mach->accel.dp_config); + mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); + } + break; + case 0xcaef: + if (len == 1) { + mach->accel.scan_to_x = (mach->accel.scan_to_x & 0x0ff) | ((val & 0x07) << 8); + dev->data_available = 0; + dev->data_available2 = 0; + mach->accel.cmd_type = 5; /*Horizontal Raster Draw from scan_to_x register (0xcaee)*/ + mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); + } + break; + + case 0xceee: + mach_log("CEEE write val = %04x.\n", val); + if (len == 1) + mach->accel.dp_config = (mach->accel.dp_config & 0xff00) | val; + else { + mach->accel.dp_config = val; + } + break; + case 0xceef: + if (len == 1) { + mach->accel.dp_config = (mach->accel.dp_config & 0x00ff) | (val << 8); + } + break; + + case 0xd2ee: + mach->accel.patt_len = val & 0x1f; + mach_log("Pattern Length = %d, val = %04x.\n", val & 0x1f, val); + mach->accel.mono_pattern_enable = !!(val & 0x80); + if (len != 1) { + mach->accel.patt_len_reg = val; + } else { + mach->accel.patt_len_reg = (mach->accel.patt_len_reg & 0xff00) | val; + } + break; + case 0xd2ef: + if (len == 1) + mach->accel.patt_len_reg = (mach->accel.patt_len_reg & 0x00ff) | (val << 8); + break; + + case 0xd6ee: + mach->accel.patt_idx = val & 0x1f; + mach_log("Pattern Index = %d, val = %02x.\n", val & 0x1f, val); + break; + + case 0xdaee: + mach_log("DAEE (extclipl) write val = %d\n", val); + if (len == 1) + dev->accel.clip_left = (dev->accel.clip_left & 0x700) | val; + else { + dev->accel.clip_left = val & 0x7ff; + } + break; + case 0xdaef: + if (len == 1) + dev->accel.clip_left = (dev->accel.clip_left & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xdeee: + mach_log("DEEE (extclipt) write val = %d\n", val); + if (len == 1) + dev->accel.clip_top = (dev->accel.clip_top & 0x700) | val; + else { + dev->accel.clip_top = val & 0x7ff; + } + break; + case 0xdeef: + if (len == 1) + dev->accel.clip_top = (dev->accel.clip_top & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xe2ee: + mach_log("E2EE (extclipr) write val = %d\n", val); + if (len == 1) + dev->accel.multifunc[4] = (dev->accel.multifunc[4] & 0x700) | val; + else { + dev->accel.multifunc[4] = val & 0x7ff; + } + break; + case 0xe2ef: + if (len == 1) + dev->accel.multifunc[4] = (dev->accel.multifunc[4] & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xe6ee: + mach_log("E6EE (extclipb) write val = %d\n", val); + if (len == 1) + dev->accel.multifunc[3] = (dev->accel.multifunc[3] & 0x700) | val; + else { + dev->accel.multifunc[3] = val & 0x7ff; + } + break; + case 0xe6ef: + if (len == 1) + dev->accel.multifunc[3] = (dev->accel.multifunc[3] & 0x0ff) | ((val & 0x07) << 8); + break; + + case 0xeeee: + if (len == 1) + mach->accel.dest_cmp_fn = (mach->accel.dest_cmp_fn & 0xff00) | val; + else + mach->accel.dest_cmp_fn = val; + break; + case 0xeeef: + if (len == 1) + mach->accel.dest_cmp_fn = (mach->accel.dest_cmp_fn & 0x00ff) | (val << 8); + break; + + case 0xf2ee: + mach_log("F2EE.\n"); + if (len == 1) + mach->accel.dst_clr_cmp_mask = (mach->accel.dst_clr_cmp_mask & 0xff00) | val; + else + mach->accel.dst_clr_cmp_mask = val; + break; + case 0xf2ef: + if (len == 1) + mach->accel.dst_clr_cmp_mask = (mach->accel.dst_clr_cmp_mask & 0x00ff) | (val << 8); + break; + + case 0xfeee: + if (mach->accel.dp_config == 0x2231 || mach->accel.dp_config == 0x2211) + mach_log("FEEE val = %d, lineidx = %d, DPCONFIG = %04x, CPUCX = %04x.\n", val, mach->accel.line_idx, mach->accel.dp_config, CX); + if (len != 1) { + mach->accel.line_array[mach->accel.line_idx] = val; + dev->accel.cur_x = mach->accel.line_array[(mach->accel.line_idx == 4) ? 4 : 0]; + dev->accel.cur_y = mach->accel.line_array[(mach->accel.line_idx == 5) ? 5 : 1]; + mach->accel.cx_end_line = mach->accel.line_array[2]; + mach->accel.cy_end_line = mach->accel.line_array[3]; + if ((mach->accel.line_idx == 3) || (mach->accel.line_idx == 5)) { + mach->accel.cmd_type = (mach->accel.line_idx == 5) ? 4 : 3; + mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); + mach->accel.line_idx = (mach->accel.line_idx == 5) ? 4 : 2; + break; + } + mach->accel.line_idx++; + } + break; + + default: + break; + } +} + +static void +mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) +{ + svga_t *svga = &mach->svga; + ibm8514_t *dev = &svga->dev8514; + + mach_log("Port accel out = %04x, val = %04x, len = %d.\n", port, val, len); + + if (port & 0x8000) { + mach_accel_out_fifo(mach, svga, dev, port, val, len); + } else { + switch (port) { + case 0x2e8: + if (len == 1) + dev->htotal = (dev->htotal & 0xff00) | val; + else { + dev->htotal = val; + svga_recalctimings(svga); + } + break; + case 0x2e9: + if (len != 1) { + dev->htotal = (dev->htotal & 0xff) | (val << 8); + mach_log("ATI 8514/A: H_TOTAL write 02E8 = %d\n", dev->htotal + 1); + svga_recalctimings(svga); + } + break; + + case 0x6e8: + dev->hdisp = val; + mach_log("ATI 8514/A: H_DISP write 06E8 = %d\n", dev->hdisp + 1); + svga_recalctimings(svga); + break; + + case 0xae8: + mach_log("ATI 8514/A: H_SYNC_STRT write 0AE8 = %d\n", val + 1); + svga_recalctimings(svga); + break; + + case 0xee8: + mach_log("ATI 8514/A: H_SYNC_WID write 0EE8 = %d\n", val + 1); + svga_recalctimings(svga); + break; + + case 0x12e8: + if (len == 1) + dev->vtotal = (dev->vtotal & 0x1f00) | val; + else { + dev->vtotal = val & 0x1fff; + svga_recalctimings(svga); + } + break; + case 0x12e9: + if (len == 1) { + dev->vtotal = (dev->vtotal & 0xff) | ((val & 0x1f) << 8); + mach_log("ATI 8514/A: V_TOTAL write 12E8 = %d\n", dev->vtotal); + svga_recalctimings(svga); + } + break; + + case 0x16e8: + if (len == 1) + dev->vdisp = (dev->vdisp & 0x1f00) | val; + else { + dev->vdisp = val & 0x1fff; + svga_recalctimings(svga); + } + break; + case 0x16e9: + if (len == 1) { + dev->vdisp = (dev->vdisp & 0xff) | ((val & 0x1f) << 8); + mach_log("ATI 8514/A: V_DISP write 16E8 = %d\n", dev->vdisp); + svga_recalctimings(svga); + } + break; + + case 0x1ae8: + if (len == 1) + dev->vsyncstart = (dev->vsyncstart & 0x1f00) | val; + else { + dev->vsyncstart = val & 0x1fff; + svga_recalctimings(svga); + } + break; + case 0x1ae9: + if (len == 1) { + dev->vsyncstart = (dev->vsyncstart & 0xff) | ((val & 0x1f) << 8); + mach_log("ATI 8514/A: V_SYNC_STRT write 1AE8 = %d\n", dev->vsyncstart); + svga_recalctimings(svga); + } + break; + + case 0x1ee8: + dev->vsyncwidth = val; + mach_log("ATI 8514/A: V_SYNC_WID write 1EE8 = %02x\n", val); + svga_recalctimings(svga); + break; + + case 0x22e8: + dev->disp_cntl = val & 0x7e; + dev->interlace = !!(val & 0x10); + mach_log("ATI 8514/A: DISP_CNTL write 22E8 = %02x, SCANMODULOS = %d\n", dev->disp_cntl, dev->scanmodulos); + svga_recalctimings(svga); + break; + + case 0x42e8: + if (len == 1) { + dev->subsys_stat &= ~val; + } else { + dev->subsys_stat &= ~(val & 0xff); + dev->subsys_cntl = (val >> 8); + mach_log("CNTL = %02x.\n", val >> 8); + } + break; + case 0x42e9: + if (len == 1) { + dev->subsys_cntl = val; + mach_log("CNTL = %02x.\n", val); + } + break; + + case 0x4ae8: + mach_log("ATI 8514/A: VGA ON (0x4ae8) = %i, val = %02x\n", vga_on, val); + if (!val) + break; + if (!dev->local || !dev->ext_crt_pitch) + dev->ext_crt_pitch = 128; + dev->accel.advfunc_cntl = val & 7; + ibm8514_on = (dev->accel.advfunc_cntl & 1); + vga_on = !ibm8514_on; + dev->ibm_mode = 1; + if (ibm8514_on) + svga->adv_flags |= FLAG_ATI; + else + svga->adv_flags &= ~FLAG_ATI; + svga_recalctimings(svga); + break; + + /*ATI Mach8/32 specific registers*/ + case 0x6ee: + mach_log("6EE write val = %02x, len = %d.\n", val, len); + break; + + case 0x6ef: + mach_log("6EF write val = %02x, len = %d.\n", val, len); + break; + + case 0xaee: + if (len == 1) + mach->cursor_offset_lo = (mach->cursor_offset_lo & 0xff00) | val; + else { + mach_log("AEE val=%02x.\n", val); + mach->cursor_offset_lo = val; + svga->hwcursor.addr = mach->cursor_offset_lo << 2; + } + break; + case 0xaef: + if (len == 1) { + mach->cursor_offset_lo = (mach->cursor_offset_lo & 0x00ff) | (val << 8); + svga->hwcursor.addr = mach->cursor_offset_lo << 2; + } + break; + + case 0xeee: + mach->cursor_offset_hi = val & 0x0f; + if (len != 1) { + svga->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16))) << 2; + svga->hwcursor.ena = !!(val & 0x8000); + } + mach_log("EEE val=%08x.\n", svga->hwcursor.addr); + break; + case 0xeef: + if (len == 1) { + svga->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16))) << 2; + svga->hwcursor.ena = !!(val & 0x80); + } + break; + + case 0x12ee: + if (len == 1) { + svga->hwcursor.x = (svga->hwcursor.x & 0x700) | val; + } else { + svga->hwcursor.x = val & 0x7ff; + mach_log("X = %03x.\n", val); + } + break; + case 0x12ef: + if (len == 1) { + svga->hwcursor.x = (svga->hwcursor.x & 0x0ff) | ((val & 0x07) << 8); + } + break; + + case 0x16ee: + if (len == 1) { + svga->hwcursor.y = (svga->hwcursor.y & 0xf00) | val; + } else { + svga->hwcursor.y = val & 0xfff; + } + break; + case 0x16ef: + if (len == 1) { + svga->hwcursor.y = (svga->hwcursor.y & 0x0ff) | ((val & 0x0f) << 8); + } + break; + + case 0x1aee: + if (len != 1) { + mach->cursor_col_0 = val & 0xff; + mach->cursor_col_1 = (val >> 8) & 0xff; + } else + mach->cursor_col_0 = val; + break; + case 0x1aef: + if (len == 1) + mach->cursor_col_1 = val; + break; + + case 0x1eee: + if (len != 1) { + svga->hwcursor.xoff = val & 0x3f; + svga->hwcursor.yoff = (val >> 8) & 0x3f; + } else + svga->hwcursor.xoff = val & 0x3f; + break; + case 0x1eef: + if (len == 1) + svga->hwcursor.yoff = val & 0x3f; + break; + + case 0x2aee: + mach_log("2AEE write val = %04x\n", val); + if (len == 1) + mach->accel.crt_offset_lo = (mach->accel.crt_offset_lo & 0xff00) | val; + else + mach->accel.crt_offset_lo = val; + break; + case 0x2aef: + if (len == 1) + mach->accel.crt_offset_lo = (mach->accel.crt_offset_lo & 0x00ff) | (val << 8); + break; + + case 0x2eee: + mach_log("2EEE write val = %04x\n", val); + if (len == 1) + mach->accel.crt_offset_hi = (mach->accel.crt_offset_hi & 0xff00) | val; + else + mach->accel.crt_offset_hi = val; + break; + case 0x2eef: + if (len == 1) + mach->accel.crt_offset_hi = (mach->accel.crt_offset_hi & 0x00ff) | (val << 8); + break; + + case 0x26ee: + mach_log("CRT Pitch = %d, original val = %d.\n", val << 3, val); + dev->ext_crt_pitch = val; + dev->internal_pitch = val; + if (svga->bpp > 8) { + if (svga->bpp == 24) + dev->ext_crt_pitch *= 3; + else + dev->ext_crt_pitch <<= 1; + } + if (dev->local) { + if (!ibm8514_on) { + ibm8514_on ^= 1; + svga->adv_flags |= FLAG_ATI; + } + } + svga_recalctimings(svga); + break; + + case 0x32ee: + if (len == 1) { + mach->local_cntl = (mach->local_cntl & 0xff00) | val; + } else { + mach->local_cntl = val; + mach32_updatemapping(mach); + } + break; + + case 0x32ef: + if (len == 1) { + mach->local_cntl = (mach->local_cntl & 0x00ff) | (val << 8); + mach32_updatemapping(mach); + } + break; + + case 0x36ee: + if (len == 1) { + mach->misc = (mach->misc & 0xff00) | (val); + } else { + mach->misc = val; + } + break; + case 0x36ef: + if (len == 1) { + mach->misc = (mach->misc & 0x00ff) | (val << 8); + } + break; + + case 0x3aee: + if (len == 1) { + mach->ext_cur_col_0_g = val; + } else { + mach->ext_cur_col_0_g = val & 0xff; + mach->ext_cur_col_0_r = (val >> 8) & 0xff; + } + break; + case 0x3aef: + if (len == 1) { + mach->ext_cur_col_0_r = val; + } + break; + + case 0x3eee: + if (len == 1) { + mach->ext_cur_col_1_g = val; + } else { + mach->ext_cur_col_1_g = val & 0xff; + mach->ext_cur_col_1_r = (val >> 8) & 0xff; + } + break; + case 0x3eef: + if (len == 1) { + mach->ext_cur_col_1_r = val; + } + break; + + case 0x42ee: + mach->accel.test2[0] = val; + break; + case 0x42ef: + mach->accel.test2[1] = val; + break; + + case 0x46ee: + mach->accel.test3[0] = val; + break; + case 0x46ef: + mach->accel.test3[1] = val; + break; + + case 0x4aee: + if (len == 1) + mach->accel.clock_sel = (mach->accel.clock_sel & 0xff00) | val; + else { + mach->accel.clock_sel = val; + ibm8514_on = (mach->accel.clock_sel & 1); + vga_on = !ibm8514_on; + dev->ibm_mode = 0; + if (ibm8514_on) + svga->adv_flags |= FLAG_ATI; + else + svga->adv_flags &= ~FLAG_ATI; + mach_log("ATI 8514/A: VGA ON (0x4aee) = %i, val = %04x\n", vga_on, val); + svga_recalctimings(svga); + } + break; + case 0x4aef: + if (len == 1) { + mach->accel.clock_sel = (mach->accel.clock_sel & 0x00ff) | (val << 8); + ibm8514_on = (mach->accel.clock_sel & 1); + vga_on = !ibm8514_on; + dev->ibm_mode = 0; + if (ibm8514_on) + svga->adv_flags |= FLAG_ATI; + else + svga->adv_flags &= ~FLAG_ATI; + mach_log("ATI 8514/A: VGA ON (0x4aef) = %i, val = %04x\n", vga_on, mach->accel.clock_sel); + svga_recalctimings(svga); + } + break; + + case 0x52ee: + if (len == 1) + mach->accel.scratch0 = (mach->accel.scratch0 & 0xff00) | val; + else + mach->accel.scratch0 = val; + break; + case 0x52ef: + if (len == 1) + mach->accel.scratch0 = (mach->accel.scratch0 & 0x00ff) | (val << 8); + break; + + case 0x56ee: + if (len == 1) + mach->accel.scratch1 = (mach->accel.scratch1 & 0xff00) | val; + else + mach->accel.scratch1 = val; + break; + case 0x56ef: + if (len == 1) + mach->accel.scratch1 = (mach->accel.scratch1 & 0x00ff) | (val << 8); + break; + + case 0x5aee: + mach_log("Shadow set = %04x\n", val); + break; + case 0x5aef: + mach_log("Shadow + 1 set = %02x\n", val); + break; + + case 0x5eee: + mach_log("Memory Aperture = %04x, len = %d.\n", val, len); + if (len == 1) { + mach->memory_aperture = (mach->memory_aperture & 0xff00) | val; + } else { + mach->memory_aperture = val; + if (!mach->pci_bus) + mach->linear_base = (mach->memory_aperture & 0xff00) << 12; + + mach32_updatemapping(mach); + } + break; + + case 0x5eef: + if (len == 1) { + mach->memory_aperture = (mach->memory_aperture & 0x00ff) | (val << 8); + if (!mach->pci_bus) + mach->linear_base = (mach->memory_aperture & 0xff00) << 12; + + mach32_updatemapping(mach); + } + break; + + case 0x62ee: + mach_log("62EE write val = %04x, len = %d.\n", val, len); + break; + + case 0x66ee: + mach_log("66EE write val = %04x, len = %d.\n", val, len); + break; + + case 0x6aee: + mach_log("6AEE write val = %04x.\n", val & 0x400); + if (len == 1) + mach->accel.max_waitstates = (mach->accel.max_waitstates & 0xff00) | val; + else { + mach->accel.max_waitstates = val; + } + break; + case 0x6aef: + if (len == 1) + mach->accel.max_waitstates = (mach->accel.max_waitstates & 0x00ff) | (val << 8); + break; + + case 0x6eee: + mach_log("6EEE write val = %04x\n", val); + if (len == 1) + mach->accel.ge_offset_lo = (mach->accel.ge_offset_lo & 0xff00) | val; + else { + mach->accel.ge_offset_lo = val; + dev->accel.ge_offset = mach->accel.ge_offset_lo; + } + break; + case 0x6eef: + if (len == 1) { + mach->accel.ge_offset_lo = (mach->accel.ge_offset_lo & 0x00ff) | (val << 8); + dev->accel.ge_offset = mach->accel.ge_offset_lo; + } + break; + + case 0x72ee: + mach_log("72EE write val = %04x\n", val); + if (len == 1) + mach->accel.ge_offset_hi = (mach->accel.ge_offset_hi & 0xff00) | val; + else { + mach->accel.ge_offset_hi = val; + dev->accel.ge_offset = mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16); + } + break; + case 0x72ef: + if (len == 1) { + mach->accel.ge_offset_hi = (mach->accel.ge_offset_hi & 0x00ff) | (val << 8); + dev->accel.ge_offset = mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16); + } + break; + + case 0x76ee: + mach_log("76EE write val=%d shifted, normal=%d.\n", val << 3, val); + dev->ext_pitch = val << 3; + svga_recalctimings(svga); + break; + + case 0x7aee: + mach_log("7AEE write val = %04x, len = %d.\n", val, len); + if (len == 1) + mach->accel.ext_ge_config = (mach->accel.ext_ge_config & 0xff00) | val; + else { + mach->accel.ext_ge_config = val; + dev->ext_crt_pitch = dev->internal_pitch; + switch (mach->accel.ext_ge_config & 0x30) { + case 0: + case 0x10: + svga->bpp = 8; + break; + case 0x20: + if ((mach->accel.ext_ge_config & 0xc0) == 0x40) + svga->bpp = 16; + else + svga->bpp = 15; + + dev->ext_crt_pitch <<= 1; + break; + case 0x30: + svga->bpp = 24; + dev->ext_crt_pitch *= 3; + break; + + default: + break; + } + if (mach->accel.ext_ge_config & 0x800) { + svga_recalctimings(svga); + } + if (!(mach->accel.ext_ge_config & 0x8000) && !(mach->accel.ext_ge_config & 0x800)) + svga_recalctimings(svga); + } + break; + case 0x7aef: + mach_log("7AEF write val = %02x.\n", val); + if (len == 1) { + mach->accel.ext_ge_config = (mach->accel.ext_ge_config & 0x00ff) | (val << 8); + dev->ext_crt_pitch = dev->internal_pitch; + switch (mach->accel.ext_ge_config & 0x30) { + case 0: + case 0x10: + svga->bpp = 8; + break; + case 0x20: + if ((mach->accel.ext_ge_config & 0xc0) == 0x40) + svga->bpp = 16; + else + svga->bpp = 15; + + dev->ext_crt_pitch <<= 1; + break; + case 0x30: + svga->bpp = 24; + dev->ext_crt_pitch *= 3; + break; + + default: + break; + } + if (mach->accel.ext_ge_config & 0x800) { + svga_recalctimings(svga); + } + if (!(mach->accel.ext_ge_config & 0x8000) && !(mach->accel.ext_ge_config & 0x800)) + svga_recalctimings(svga); + } + break; + + case 0x7eee: + mach->accel.eeprom_control = val; + break; + + default: + break; + } + } +} + +static uint32_t +mach_accel_in(uint16_t port, mach_t *mach, int len) +{ + svga_t *svga = &mach->svga; + ibm8514_t *dev = &svga->dev8514; + const uint16_t *vram_w = (uint16_t *) svga->vram; + uint16_t temp = 0; + int cmd; + int vpos = dev->displine + svga->y_add; + int vblankend = svga->vblankstart + svga->crtc[0x16]; + int frgd_sel; + int bkgd_sel; + int mono_src; + + switch (port) { + case 0x2e8: + if (dev->local) { + vpos = svga->displine + svga->y_add; + if (vblankend > svga->vtotal) { + vblankend -= svga->vtotal; + if (vpos >= svga->vblankstart || vpos <= vblankend) + temp |= 2; + } else { + if (vpos >= svga->vblankstart && vpos <= vblankend) + temp |= 2; + } + } else { + vpos = dev->displine + svga->y_add; + if (vblankend > dev->vtotal) { + vblankend -= dev->vtotal; + if (vpos >= svga->vblankstart || vpos <= vblankend) + temp |= 2; + } else { + if (vpos >= svga->vblankstart && vpos <= vblankend) + temp |= 2; + } + } + break; + + case 0x6e8: + temp = dev->hdisp; + break; + + case 0x22e8: + temp = dev->disp_cntl; + break; + + case 0x26e8: + if (len == 1) + temp = dev->htotal & 0xff; + else + temp = dev->htotal; + break; + case 0x26e9: + if (len == 1) + temp = dev->htotal >> 8; + break; + + case 0x2ee8: + temp = dev->subsys_cntl; + break; + + case 0x42e8: + if (dev->local) { + vpos = svga->displine + svga->y_add; + if (vblankend > svga->vtotal) { + vblankend -= svga->vtotal; + if (vpos >= svga->vblankstart || vpos <= vblankend) + dev->subsys_stat |= 1; + } else { + if (vpos >= svga->vblankstart && vpos <= vblankend) + dev->subsys_stat |= 1; + } + } else { + vpos = dev->displine + svga->y_add; + if (vblankend > dev->vtotal) { + vblankend -= dev->vtotal; + if (vpos >= svga->vblankstart || vpos <= vblankend) + dev->subsys_stat |= 1; + } else { + if (vpos >= svga->vblankstart && vpos <= vblankend) + dev->subsys_stat |= 1; + } + } + + if (len != 1) { + temp = dev->subsys_stat | 0xa0 | 0x8000; + } else { + temp = dev->subsys_stat | 0xa0; + } + break; + + case 0x4ae8: + temp = dev->accel.advfunc_cntl; + break; + + case 0x42e9: + if (len == 1) { + temp = dev->subsys_stat >> 8; + temp |= 0x80; + } + break; + + case 0x82e8: + case 0xc2e8: + if (len != 1) { + temp = dev->accel.cur_y; + } + break; + + case 0x86e8: + case 0xc6e8: + if (len != 1) { + temp = dev->accel.cur_x; + } + break; + + case 0x92e8: + if (len != 1) { + temp = dev->test; + } + break; + + case 0x96e8: + if (len != 1) { + temp = dev->accel.maj_axis_pcnt; + } + break; + + case 0x9ae8: + case 0xdae8: + if (len != 1) { + if (dev->force_busy) + temp |= 0x200; /*Hardware busy*/ + dev->force_busy = 0; + if (dev->data_available) { + temp |= 0x100; /*Read Data available*/ + if (mach->accel.cmd_type >= 0) { + switch (mach->accel.cmd_type) { + case 2: + if (dev->accel.sy >= mach->accel.height) + dev->data_available = 0; + break; + case 5: + if (dev->accel.sx >= mach->accel.width) + dev->data_available = 0; + break; + default: + if (dev->accel.sy < 0) + dev->data_available = 0; + break; + } + } else { + if (dev->accel.sy < 0) + dev->data_available = 0; + } + } + } + mach_log("[%04X:%08X]: 9AE8: Temp = %04x, len = %d\n\n", CS, cpu_state.pc, temp, len); + break; + case 0x9ae9: + case 0xdae9: + if (len == 1) { + if (dev->force_busy2) + temp |= 2; /*Hardware busy*/ + dev->force_busy2 = 0; + if (dev->data_available2) { + temp |= 1; /*Read Data available*/ + if (mach->accel.cmd_type >= 0) { + switch (mach->accel.cmd_type) { + case 2: + if (dev->accel.sy >= mach->accel.height) + dev->data_available2 = 0; + break; + case 5: + if (dev->accel.sx >= mach->accel.width) + dev->data_available2 = 0; + break; + default: + if (dev->accel.sy < 0) + dev->data_available2 = 0; + break; + } + } else { + if (dev->accel.sy < 0) + dev->data_available2 = 0; + } + } + } + mach_log("[%04X:%08X]: 9AE9: Temp = %04x, len = %d\n\n", CS, cpu_state.pc, temp, len); + break; + + case 0xe2e8: + case 0xe6e8: + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) { + cmd = -1; + if (len == 1) { + READ_PIXTRANS_BYTE_IO(dev->accel.dx, 1, dev->local) + + temp = mach->accel.pix_trans[1]; + } else { + if (mach->accel.cmd_type == 3) { + READ_PIXTRANS_WORD(dev->accel.cx, 0, dev->local) + } else { + READ_PIXTRANS_WORD(dev->accel.dx, 0, dev->local) + } + mach_accel_out_pixtrans(mach, dev, port, temp, len); + } + } + } else { + if (ibm8514_cpu_dest(svga)) { + cmd = (dev->accel.cmd >> 13); + if (len == 1) { + ; // READ_PIXTRANS_BYTE_IO(0) + } else { + READ_PIXTRANS_WORD(dev->accel.cx, 0, dev->local) + if (dev->accel.input && !dev->accel.odd_in && !dev->accel.sx) { + temp &= ~0xff00; + if (dev->local) + temp |= (svga->vram[(dev->accel.newdest_in + dev->accel.cur_x) & svga->vram_mask] << 8); + else + temp |= (dev->vram[(dev->accel.newdest_in + dev->accel.cur_x) & dev->vram_mask] << 8); + } + if (dev->subsys_stat & 1) { + dev->force_busy = 1; + dev->data_available = 1; + } + } + ibm8514_accel_out_pixtrans(svga, port, temp, len); + } + } + break; + case 0xe2e9: + case 0xe6e9: + if (mach->accel.cmd_type >= 0) { + mach_log("%04x pixtrans read, len=%d.\n", port, len); + if (mach_pixel_read(mach)) { + if (len == 1) { + cmd = -1; + READ_PIXTRANS_BYTE_IO(dev->accel.dx, 0, dev->local) + + temp = mach->accel.pix_trans[0]; + frgd_sel = (mach->accel.dp_config >> 13) & 7; + bkgd_sel = (mach->accel.dp_config >> 7) & 3; + mono_src = (mach->accel.dp_config >> 5) & 3; + + switch (mach->accel.dp_config & 0x200) { + case 0x000: /*8-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + mach_accel_start(mach->accel.cmd_type, 1, 8, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + break; + case 0x200: /*16-bit size*/ + if (mono_src == 2) { + if ((frgd_sel != 2) && (bkgd_sel != 2)) { + if (mach->accel.dp_config & 0x1000) + mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[1] | (mach->accel.pix_trans[0] << 8), 0, mach, dev, len); + else + mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + } else + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); + break; + + default: + break; + } + } + } + } + break; + + case 0xbee8: + case 0xfee8: + if (len != 1) { + mach_log("Multifunc_cntl = %d.\n", dev->accel.multifunc_cntl >> 12); + switch ((dev->accel.multifunc_cntl >> 12) & 0x0f) { + case 0: + temp = dev->accel.multifunc[0]; + break; + case 1: + temp = dev->accel.clip_top; + break; + case 2: + temp = dev->accel.clip_left; + break; + case 3: + temp = dev->accel.multifunc[3]; + break; + case 4: + temp = dev->accel.multifunc[4]; + break; + case 5: + temp = dev->accel.multifunc[5]; + break; + case 8: + temp = dev->accel.multifunc[8]; + break; + case 9: + temp = dev->accel.multifunc[9]; + break; + case 0x0a: + temp = dev->accel.multifunc[0x0a]; + break; + + default: + break; + } + } + break; + + /*ATI Mach8/32 specific registers*/ + case 0x12ee: + if (len == 1) + temp = mach->config1 & 0xff; + else + temp = mach->config1; + break; + case 0x12ef: + if (len == 1) + temp = mach->config1 >> 8; + break; + + case 0x16ee: + if (len == 1) + temp = mach->config2 & 0xff; + else + temp = mach->config2; + break; + case 0x16ef: + if (len == 1) + temp = mach->config2 >> 8; + break; + + case 0x32ee: + if (len == 1) + temp = mach->local_cntl & 0xff; + else + temp = mach->local_cntl; + break; + case 0x32ef: + if (len == 1) + temp = mach->local_cntl >> 8; + break; + + case 0x36ee: + if (len == 1) + temp = mach->misc & 0xff; + else + temp = mach->misc; + break; + case 0x36ef: + if (len == 1) + temp = mach->misc >> 8; + break; + + case 0x42ee: + temp = mach->accel.test2[0]; + break; + case 0x42ef: + temp = mach->accel.test2[1]; + break; + + case 0x46ee: + temp = mach->accel.test3[0]; + break; + case 0x46ef: + temp = mach->accel.test3[1]; + break; + + case 0x4aee: + if (len == 1) + temp = mach->accel.clock_sel & 0xff; + else + temp = mach->accel.clock_sel; + break; + case 0x4aef: + if (len == 1) + temp = mach->accel.clock_sel >> 8; + break; + + case 0x52ee: + if (len == 1) + temp = mach->accel.scratch0 & 0xff; + else + temp = mach->accel.scratch0; + break; + case 0x52ef: + if (len == 1) + temp = mach->accel.scratch0 >> 8; + break; + + case 0x56ee: + if (len == 1) + temp = mach->accel.scratch1 & 0xff; + else + temp = mach->accel.scratch1; + break; + case 0x56ef: + if (len == 1) + temp = mach->accel.scratch1 >> 8; + break; + + case 0x5eee: + if (mach->pci_bus) + mach->memory_aperture = (mach->memory_aperture & ~0xfff0) | ((mach->linear_base >> 20) << 4); + + if (len == 1) + temp = mach->memory_aperture & 0xff; + else + temp = mach->memory_aperture; + break; + case 0x5eef: + if (len == 1) + temp = mach->memory_aperture >> 8; + break; + + case 0x62ee: + temp = mach->accel.clip_overrun; + if (len != 1) { + if (mach->force_busy) + temp |= 0x2000; + mach->force_busy = 0; + if (ati_eeprom_read(&mach->eeprom)) + temp |= 0x4000; + } + mach_log("[%04X:%08X]: 62EE: Temp = %04x, len = %d\n\n", CS, cpu_state.pc, temp, len); + break; + case 0x62ef: + if (len == 1) { + if (mach->force_busy2) + temp |= 0x20; + mach->force_busy2 = 0; + if (ati_eeprom_read(&mach->eeprom)) + temp |= 0x40; + } + mach_log("[%04X:%08X]: 62EF: Temp = %04x, len = %d\n\n", CS, cpu_state.pc, temp, len); + break; + + case 0x6aee: + if (len == 1) + temp = mach->accel.max_waitstates & 0xff; + else + temp = mach->accel.max_waitstates; + break; + case 0x6aef: + if (len == 1) + temp = mach->accel.max_waitstates >> 8; + break; + + case 0x72ee: + if (len == 1) + temp = dev->accel.clip_left & 0xff; + else + temp = dev->accel.clip_left; + break; + case 0x72ef: + if (len == 1) + temp = dev->accel.clip_left >> 8; + break; + + case 0x76ee: + if (len == 1) + temp = dev->accel.clip_top & 0xff; + else + temp = dev->accel.clip_top; + break; + case 0x76ef: + if (len == 1) + temp = dev->accel.clip_top >> 8; + break; + + case 0x7aee: + if (len == 1) + temp = dev->accel.multifunc[4] & 0xff; + else + temp = dev->accel.multifunc[4]; + break; + case 0x7aef: + if (len == 1) + temp = dev->accel.multifunc[4] >> 8; + break; + + case 0x7eee: + if (len == 1) + temp = dev->accel.multifunc[3] & 0xff; + else + temp = dev->accel.multifunc[3]; + break; + case 0x7eef: + if (len == 1) + temp = dev->accel.multifunc[3] >> 8; + break; + + case 0x82ee: + temp = mach->accel.patt_data_idx; + break; + + case 0x8eee: + if (len == 1) + temp = mach->accel.ext_ge_config & 0xff; + else + temp = mach->accel.ext_ge_config; + break; + case 0x8eef: + if (len == 1) + temp = mach->accel.ext_ge_config >> 8; + break; + + case 0x92ee: + temp = mach->accel.eeprom_control; + break; + + case 0x96ee: + if (len == 1) { + temp = dev->accel.maj_axis_pcnt & 0xff; + } else { + temp = dev->accel.maj_axis_pcnt; + if ((mach->accel.test == 0x1555) || (mach->accel.test == 0x0aaa)) + temp = mach->accel.test; + } + break; + case 0x96ef: + if (len == 1) + temp = dev->accel.maj_axis_pcnt >> 8; + break; + + case 0xa2ee: + if (len == 1) + temp = mach->accel.linedraw_opt & 0xff; + else { + temp = mach->accel.linedraw_opt; + } + break; + case 0xa2ef: + if (len == 1) + temp = mach->accel.linedraw_opt >> 8; + break; + + case 0xb2ee: + if (len == 1) + temp = dev->hdisp; + else { + temp = dev->hdisp & 0xff; + temp |= (dev->htotal << 8); + mach_log("HDISP read=%d, HTOTAL read=%d.\n", temp & 0xff, temp >> 8); + } + break; + case 0xb2ef: + if (len == 1) { + temp = dev->htotal; + } + break; + + case 0xc2ee: + if (len == 1) + temp = dev->vtotal & 0xff; + else { + temp = dev->vtotal; + mach_log("VTOTAL read=%d.\n", temp); + } + break; + case 0xc2ef: + if (len == 1) + temp = dev->vtotal >> 8; + break; + + case 0xc6ee: + if (len == 1) + temp = dev->vdisp & 0xff; + else { + temp = dev->vdisp; + mach_log("VDISP read=%d.\n", temp); + } + break; + case 0xc6ef: + if (len == 1) + temp = dev->vdisp >> 8; + break; + + case 0xcaee: + if (len == 1) + temp = dev->vsyncstart & 0xff; + else + temp = dev->vsyncstart; + break; + case 0xcaef: + if (len == 1) + temp = dev->vsyncstart >> 8; + break; + + case 0xceee: + if (len == 1) + temp = svga->vc & 0xff; + else + temp = svga->vc & 0x7ff; + break; + case 0xceef: + if (len == 1) + temp = (svga->vc >> 8) & 7; + break; + + case 0xdaee: + if (len != 1) { + temp = mach->accel.src_x; + if (dev->local) { + temp &= 0x7ff; + } + } else + temp = dev->accel.destx_distp & 0xff; + break; + case 0xdaef: + if (len == 1) + temp = dev->accel.destx_distp >> 8; + break; + + case 0xdeee: + if (len != 1) { + temp = mach->accel.src_y; + if (dev->local) + temp &= 0x7ff; + } else + temp = dev->accel.desty_axstp & 0xff; + break; + case 0xdeef: + if (len == 1) + temp = dev->accel.desty_axstp >> 8; + break; + + case 0xfaee: + if (len != 1) { + if (mach->pci_bus) + temp = 0x0017; + else + temp = 0x22f7; + } else { + if (mach->pci_bus) + temp = 0x17; + else + temp = 0xf7; + } + break; + case 0xfaef: + if (len == 1) { + if (mach->pci_bus) + temp = 0x00; + else + temp = 0x22; + } + break; + + default: + break; + } + if (port != 0x9ae8 && port != 0x9ae9 && port != 0x62ee && port != 0x9aee) { + mach_log("Port accel in = %04x, temp = %04x, len = %d, mode = %d.\n", port, temp, len, dev->ibm_mode); + } + return temp; +} + +static void +mach_accel_outb(uint16_t port, uint8_t val, void *priv) +{ + mach_t *mach = (mach_t *) priv; + mach_accel_out(port, val, mach, 1); +} + +static void +mach_accel_outw(uint16_t port, uint16_t val, void *priv) +{ + mach_t *mach = (mach_t *) priv; + mach_accel_out(port, val, mach, 2); +} + +static uint8_t +mach_accel_inb(uint16_t port, void *priv) +{ + mach_t *mach = (mach_t *) priv; + return mach_accel_in(port, mach, 1); +} + +static uint16_t +mach_accel_inw(uint16_t port, void *priv) +{ + mach_t *mach = (mach_t *) priv; + return mach_accel_in(port, mach, 2); +} + +static void +mach32_ap_writeb(uint32_t addr, uint8_t val, void *priv) +{ + mach_t *mach = (mach_t *) priv; + uint8_t port_dword = addr & 0xfc; + + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { + if (addr & 0x100) { + mach_log("Port WORDB Write=%04x.\n", 0x02ee + (port_dword << 8)); + mach_accel_outb(0x02ee + (addr & 1) + (port_dword << 8), val, mach); + } else { + mach_log("Port WORDB Write=%04x.\n", 0x02e8 + (port_dword << 8)); + mach_accel_outb(0x02e8 + (addr & 1) + (port_dword << 8), val, mach); + } + } else { + mach_log("Linear WORDB Write=%08x.\n", addr); + svga_write_linear(addr, val, &mach->svga); + } +} + +static void +mach32_ap_writew(uint32_t addr, uint16_t val, void *priv) +{ + mach_t *mach = (mach_t *) priv; + uint8_t port_dword = addr & 0xfc; + + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { + if (addr & 0x100) { + mach_log("Port WORDW Write=%04x.\n", 0x02ee + (port_dword << 8)); + mach_accel_outw(0x02ee + (port_dword << 8), val, mach); + } else { + mach_log("Port WORDW Write=%04x.\n", 0x02e8 + (port_dword << 8)); + mach_accel_outw(0x02e8 + (port_dword << 8), val, mach); + } + } else { + mach_log("Linear WORDW Write=%08x.\n", addr); + svga_writew_linear(addr, val, &mach->svga); + } +} + +static void +mach32_ap_writel(uint32_t addr, uint32_t val, void *priv) +{ + mach_t *mach = (mach_t *) priv; + uint8_t port_dword = addr & 0xfc; + + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { + if (addr & 0x100) { + mach_log("Port WORDL Write=%04x.\n", 0x02ee + (port_dword << 8)); + mach_accel_outw(0x02ee + (port_dword << 8), val & 0xffff, mach); + mach_accel_outw(0x02ee + (port_dword << 8) + 4, val >> 16, mach); + } else { + mach_log("Port WORDL Write=%04x.\n", 0x02e8 + (port_dword << 8)); + mach_accel_outw(0x02e8 + (port_dword << 8), val & 0xffff, mach); + mach_accel_outw(0x02e8 + (port_dword << 8) + 4, val >> 16, mach); + } + } else { + mach_log("Linear WORDL Write=%08x, val=%08x, mode=%d, rop=%02x.\n", addr, val, mach->svga.writemode, mach->svga.gdcreg[3] & 0x18); + svga_writel_linear(addr, val, &mach->svga); + } +} + +static uint8_t +mach32_ap_readb(uint32_t addr, void *priv) +{ + mach_t *mach = (mach_t *) priv; + uint8_t temp; + uint8_t port_dword = addr & 0xfc; + + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { + if (addr & 0x100) { + temp = mach_accel_inb(0x02ee + (addr & 1) + (port_dword << 8), mach); + } else { + temp = mach_accel_inb(0x02e8 + (addr & 1) + (port_dword << 8), mach); + } + } else + temp = svga_read_linear(addr, &mach->svga); + + return temp; +} + +static uint16_t +mach32_ap_readw(uint32_t addr, void *priv) +{ + mach_t *mach = (mach_t *) priv; + uint16_t temp; + uint8_t port_dword = addr & 0xfc; + + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { + if (addr & 0x100) { + temp = mach_accel_inw(0x02ee + (port_dword << 8), mach); + } else { + temp = mach_accel_inw(0x02e8 + (port_dword << 8), mach); + } + } else + temp = svga_readw_linear(addr, &mach->svga); + + return temp; +} + +static uint32_t +mach32_ap_readl(uint32_t addr, void *priv) +{ + mach_t *mach = (mach_t *) priv; + uint32_t temp; + uint8_t port_dword = addr & 0xfc; + + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { + if (addr & 0x100) { + temp = mach_accel_inw(0x02ee + (port_dword << 8), mach); + temp |= (mach_accel_inw(0x02ee + (port_dword << 8) + 4, mach) << 8); + } else { + temp = mach_accel_inw(0x02e8 + (port_dword << 8), mach); + temp |= (mach_accel_inw(0x02e8 + (port_dword << 8) + 4, mach) << 8); + } + } else + temp = svga_readl_linear(addr, &mach->svga); + + return temp; +} + +static void +mach32_updatemapping(mach_t *mach) +{ + svga_t *svga = &mach->svga; + + if (mach->pci_bus && (!(mach->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM))) { + mem_mapping_disable(&svga->mapping); + mem_mapping_disable(&mach->mmio_linear_mapping); + return; + } + + if (mach->regs[0xbd] & 4) { + mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x20000); + svga->banked_mask = 0xffff; + mach_log("Bit 2 of BD.\n"); + } else { + switch (svga->gdcreg[6] & 0x0c) { + case 0x0: /*128k at A0000*/ + mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x20000); + svga->banked_mask = 0xffff; + break; + case 0x4: /*64k at A0000*/ + mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x10000); + svga->banked_mask = 0xffff; + break; + case 0x8: /*32k at B0000*/ + mem_mapping_set_addr(&svga->mapping, 0xb0000, 0x08000); + svga->banked_mask = 0x7fff; + break; + case 0xC: /*32k at B8000*/ + mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); + svga->banked_mask = 0x7fff; + break; + + default: + break; + } + } + + mach_log("Linear base = %08x, aperture = %04x, localcntl = %02x svgagdc = %x.\n", mach->linear_base, mach->memory_aperture, mach->local_cntl, svga->gdcreg[6] & 0x0c); + if (mach->linear_base) { + if (((mach->memory_aperture & 3) == 1) && !mach->pci_bus) { + /*1 MB aperture*/ + mach->ap_size = 1; + mem_mapping_set_addr(&mach->mmio_linear_mapping, mach->linear_base, mach->ap_size << 20); + } else { + /*4 MB aperture*/ + mach->ap_size = 4; + mem_mapping_set_addr(&mach->mmio_linear_mapping, mach->linear_base, mach->ap_size << 20); + } + /*Force IBM/ATI mode on when the MMIO registers are loaded.*/ + if (mach->local_cntl & 0x20) { + if (!ibm8514_on) { + ibm8514_on ^= 1; + svga->adv_flags |= FLAG_ATI; + svga_recalctimings(svga); + } + } + } else { + mach->ap_size = 4; + mem_mapping_disable(&mach->mmio_linear_mapping); + } +} + +static void +mach32_hwcursor_draw(svga_t *svga, int displine) +{ + const mach_t *mach = (mach_t *) svga->priv; + uint16_t dat; + int comb; + int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; + uint32_t color0; + uint32_t color1; + + if (svga->bpp == 8) { + color0 = svga->pallook[mach->cursor_col_0]; + color1 = svga->pallook[mach->cursor_col_1]; + mach_log("8BPP: Offset = %x, XOFF = %02x, YOFF = %02x.\n", offset, svga->hwcursor_latch.xoff, svga->hwcursor_latch.yoff); + } else if (svga->bpp == 15) { + color0 = video_15to32[((mach->ext_cur_col_0_r << 16) | (mach->ext_cur_col_0_g << 8) | mach->cursor_col_0) & 0xffff]; + color1 = video_15to32[((mach->ext_cur_col_1_r << 16) | (mach->ext_cur_col_1_g << 8) | mach->cursor_col_1) & 0xffff]; + mach_log("15BPP: Offset = %x, XOFF = %02x, YOFF = %02x.\n", offset, svga->hwcursor_latch.xoff, svga->hwcursor_latch.yoff); + } else if (svga->bpp == 16) { + color0 = video_16to32[((mach->ext_cur_col_0_r << 16) | (mach->ext_cur_col_0_g << 8) | mach->cursor_col_0) & 0xffff]; + color1 = video_16to32[((mach->ext_cur_col_1_r << 16) | (mach->ext_cur_col_1_g << 8) | mach->cursor_col_1) & 0xffff]; + mach_log("16BPP: Offset = %x, XOFF = %02x, YOFF = %02x.\n", offset, svga->hwcursor_latch.xoff, svga->hwcursor_latch.yoff); + } else { + color0 = ((mach->ext_cur_col_0_r << 16) | (mach->ext_cur_col_0_g << 8) | mach->cursor_col_0); + color1 = ((mach->ext_cur_col_1_r << 16) | (mach->ext_cur_col_1_g << 8) | mach->cursor_col_1); + mach_log("24BPP: Offset = %x, XOFF = %02x, YOFF = %02x.\n", offset, svga->hwcursor_latch.xoff, svga->hwcursor_latch.yoff); + } + + if (svga->interlace && svga->hwcursor_oddeven) + svga->hwcursor_latch.addr += 16; + + for (int x = 0; x < 64; x += 8) { + dat = svga->vram[svga->hwcursor_latch.addr & svga->vram_mask] | (svga->vram[(svga->hwcursor_latch.addr + 1) & svga->vram_mask] << 8); + for (int xx = 0; xx < 8; xx++) { + comb = (dat >> (xx << 1)) & 0x03; + if (offset >= svga->hwcursor_latch.x) { + switch (comb) { + case 0: + (svga->monitor->target_buffer->line[displine])[offset + svga->x_add] = color0; + break; + case 1: + (svga->monitor->target_buffer->line[displine])[offset + svga->x_add] = color1; + break; + case 3: + (svga->monitor->target_buffer->line[displine])[offset + svga->x_add] ^= 0xffffff; + break; + + default: + break; + } + } + offset++; + } + svga->hwcursor_latch.addr += 2; + } + if (svga->interlace && !svga->hwcursor_oddeven) + svga->hwcursor_latch.addr += 16; +} + +static void +mach_io_remove(mach_t *mach) +{ + io_removehandler(0x01ce, 2, + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); + io_removehandler(0x03c0, 32, + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); + + io_removehandler(0x2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x2ea, 0x0004, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); + io_removehandler(0x6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x12e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x16e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x1ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x1ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x22e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x26e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x2ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x42e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x4ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x52e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x56e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x5ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x5ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x82e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x86e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x8ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x8ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x92e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x96e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x9ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x9ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xa2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xa6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xaae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xaee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xb2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xb6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xbae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xbee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xe2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + + io_removehandler(0xc2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xc6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xcae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xcee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xd2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xd6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xdae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xdee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xe6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xeae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xeee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xf2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xf6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xfae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xfee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + + io_removehandler(0x06ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x0aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x0eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x12ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x16ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x1aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x1eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x26ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x2aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x2eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x32ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x36ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x3aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x3eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x42ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x46ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x4aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x52ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x56ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x5aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x5eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x62ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x66ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x6aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x6eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x72ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x76ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x7aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x7eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x82ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x8eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x92ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x96ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0x9aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xa2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xa6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xaaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xaeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xb2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xb6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xbaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xbeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xc2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xc6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xcaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xceee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xd2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xd6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xdaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xdeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xe2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xe6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xeeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xf2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xfaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_removehandler(0xfeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); +} + +static void +mach_io_set(mach_t *mach) +{ + io_sethandler(0x01ce, 2, + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); + io_sethandler(0x03c0, 32, + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); + + io_sethandler(0x2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x2ea, 0x0004, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); + io_sethandler(0x6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x12e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x16e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x1ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x1ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x22e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x26e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x2ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x42e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x4ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x52e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x56e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x5ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x5ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x82e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x86e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x8ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x8ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x92e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x96e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x9ae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x9ee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xa2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xa6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xaae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xaee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xb2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xb6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xbae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xbee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xe2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + + io_sethandler(0xc2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xc6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xcae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xcee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xd2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xd6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xdae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xdee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xe6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xeae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xeee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xf2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xf6e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xfae8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xfee8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + + io_sethandler(0x06ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x0aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x0eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x12ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x16ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x1aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x1eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x26ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x2aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x2eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x32ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x36ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x3aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x3eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x42ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x46ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x4aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x52ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x56ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x5aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x5eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x62ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x66ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x6aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x6eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x72ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x76ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x7aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x7eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x82ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x8eee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x92ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x96ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0x9aee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xa2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xa6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xaaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xaeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xb2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xb6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xbaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xbeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xc2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xc6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xcaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xceee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xd2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xd6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xdaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xdeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xe2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xe6ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xeeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xf2ee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xfaee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); + io_sethandler(0xfeee, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); +} + +static uint8_t +mach32_pci_read(UNUSED(int func), int addr, void *priv) +{ + const mach_t *mach = (mach_t *) priv; + uint8_t ret = 0x00; + + switch (addr) { + case 0x00: + ret = 0x02; /*ATI*/ + break; + case 0x01: + ret = 0x10; + break; + + case 0x02: + ret = 0x58; + break; + case 0x03: + ret = 0x41; + break; + + case PCI_REG_COMMAND: + ret = mach->pci_regs[PCI_REG_COMMAND] | 0x80; /*Respond to IO and memory accesses*/ + break; + + case 0x07: + ret = 0x01; /*Medium DEVSEL timing*/ + break; + + case 0x0a: + ret = 0x00; /*Supports VGA interface*/ + break; + case 0x0b: + ret = 0x03; + break; + + case 0x10: + ret = 0x00; /*Linear frame buffer address*/ + break; + case 0x11: + ret = 0x00; + break; + case 0x12: + ret = mach->linear_base >> 16; + break; + case 0x13: + ret = mach->linear_base >> 24; + break; + + case 0x30: + ret = (mach->pci_regs[0x30] & 0x01); /*BIOS ROM address*/ + break; + case 0x31: + ret = 0x00; + break; + case 0x32: + ret = mach->pci_regs[0x32]; + break; + case 0x33: + ret = mach->pci_regs[0x33]; + break; + + case 0x3c: + ret = mach->int_line; + break; + case 0x3d: + ret = PCI_INTA; + break; + + default: + break; + } + + return ret; +} + +static void +mach32_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) +{ + mach_t *mach = (mach_t *) priv; + + switch (addr) { + case PCI_REG_COMMAND: + mach->pci_regs[PCI_REG_COMMAND] = val & 0x27; + mach_io_remove(mach); + if (val & PCI_COMMAND_IO) { + mach_io_set(mach); + } + mach32_updatemapping(mach); + break; + + case 0x12: + mach->linear_base = (mach->linear_base & 0xff000000) | ((val & 0xc0) << 16); + mach32_updatemapping(mach); + break; + case 0x13: + mach->linear_base = (mach->linear_base & 0xc00000) | (val << 24); + mach32_updatemapping(mach); + break; + + case 0x30: + case 0x32: + case 0x33: + mach->pci_regs[addr] = val; + if (mach->pci_regs[0x30] & 0x01) { + uint32_t bios_addr = (mach->pci_regs[0x32] << 16) | (mach->pci_regs[0x33] << 24); + mach_log("Mach32 bios_rom enabled at %08x\n", bios_addr); + mem_mapping_set_addr(&mach->bios_rom.mapping, bios_addr, 0x8000); + } else { + mach_log("Mach32 bios_rom disabled\n"); + mem_mapping_disable(&mach->bios_rom.mapping); + } + return; + + case 0x3c: + mach->int_line = val; + break; + + default: + break; + } +} + +static void * +mach8_init(const device_t *info) +{ + mach_t *mach; + svga_t *svga; + ibm8514_t *dev; + uint32_t memory; + + mach = malloc(sizeof(mach_t)); + memset(mach, 0x00, sizeof(mach_t)); + + svga = &mach->svga; + dev = &svga->dev8514; + + mach->pci_bus = !!(info->flags & DEVICE_PCI); + mach->vlb_bus = !!(info->flags & DEVICE_VLB); + dev->local = info->local; + dev->vram_size = (1024 << 10); + dev->vram = calloc(dev->vram_size, 1); + dev->changedvram = calloc(dev->vram_size >> 12, 1); + dev->vram_mask = dev->vram_size - 1; + dev->map8 = svga->pallook; + memory = device_get_config_int("memory"); + + if (dev->local) { + if (mach->vlb_bus) + rom_init(&mach->bios_rom, + BIOS_MACH32_VLB_ROM_PATH, + 0xc0000, 0x8000, 0x7fff, + 0, MEM_MAPPING_EXTERNAL); + else if (mach->pci_bus) + rom_init(&mach->bios_rom, + BIOS_MACH32_PCI_ROM_PATH, + 0xc0000, 0x8000, 0x7fff, + 0, MEM_MAPPING_EXTERNAL); + else + rom_init(&mach->bios_rom, + BIOS_MACH32_ISA_ROM_PATH, + 0xc0000, 0x8000, 0x7fff, + 0, MEM_MAPPING_EXTERNAL); + } else { + rom_init(&mach->bios_rom, + BIOS_MACH8_ROM_PATH, + 0xc0000, 0x8000, 0x7fff, + 0, MEM_MAPPING_EXTERNAL); + } + + svga_init(info, svga, mach, dev->local ? (memory << 10) : (512 << 10), /*default: 512kB for Mach8, 2MB for Mach32*/ + mach_recalctimings, + mach_in, mach_out, + dev->local ? mach32_hwcursor_draw : NULL, + NULL); + + if (dev->local) { + switch (memory) { + case 1024: + mach->misc |= 0x04; + break; + case 2048: + mach->misc |= 0x08; + break; + case 4096: + mach->misc |= 0x0c; + break; + + default: + break; + } + svga->hwcursor.cur_ysize = 64; + mach->config1 = 0x20; + mach->config2 = 0x08; + /*Fake the RAMDAC to give the VLB/MCA variants full 24-bit support until said RAMDAC is implemented.*/ + if (mach->vlb_bus) { + video_inform(VIDEO_FLAG_TYPE_8514, &timing_mach32_vlb); + mach->config1 |= 0x0c; + mach->config1 |= 0x0400; + } else if (mach->pci_bus) { + video_inform(VIDEO_FLAG_TYPE_8514, &timing_mach32_pci); + mach->config1 |= 0x0e; + mach->config1 |= 0x0a00; + mach->config2 |= 0x2000; + svga->ramdac = device_add(&ati68860_ramdac_device); + } else { + video_inform(VIDEO_FLAG_TYPE_8514, &timing_gfxultra_isa); + } + mem_mapping_add(&mach->mmio_linear_mapping, 0, 0, mach32_ap_readb, mach32_ap_readw, mach32_ap_readl, mach32_ap_writeb, mach32_ap_writew, mach32_ap_writel, NULL, MEM_MAPPING_EXTERNAL, mach); + mem_mapping_disable(&mach->mmio_linear_mapping); + } else { + video_inform(VIDEO_FLAG_TYPE_8514, &timing_gfxultra_isa); + mach->config1 = 0x02 | 0x20 | 0x80; + mach->config2 = 0x02; + dev->ext_pitch = 1024; + } + + svga->force_old_addr = 1; + svga->miscout = 1; + svga->bpp = 8; + svga->packed_chain4 = 1; + ibm8514_enabled = 1; + ibm8514_has_vga = 1; + dev->ibm_mode = 1; + dev->rowoffset = 128; + mach_io_set(mach); + + if (dev->local) { + svga->decode_mask = (4 << 20) - 1; + mach->cursor_col_1 = 0xff; + mach->ext_cur_col_1_r = 0xff; + mach->ext_cur_col_1_g = 0xff; + dev->ext_crt_pitch = 128; + if (mach->vlb_bus) + ati_eeprom_load(&mach->eeprom, "mach32_vlb.nvr", 1); + else if (mach->pci_bus) { + ati_eeprom_load(&mach->eeprom, "mach32_pci.nvr", 1); + mem_mapping_disable(&mach->bios_rom.mapping); + mach->card = pci_add_card(PCI_ADD_VIDEO, mach32_pci_read, mach32_pci_write, mach); + mach->pci_regs[PCI_REG_COMMAND] = 0x83; + mach->pci_regs[0x30] = 0x00; + mach->pci_regs[0x32] = 0x0c; + mach->pci_regs[0x33] = 0x00; + } else + ati_eeprom_load(&mach->eeprom, "mach32.nvr", 1); + } else { + ati_eeprom_load_mach8(&mach->eeprom, "mach8.nvr"); + } + + return mach; +} + +static int +mach8_available(void) +{ + return rom_present(BIOS_MACH8_ROM_PATH); +} + +static int +mach32_isa_available(void) +{ + return rom_present(BIOS_MACH32_ISA_ROM_PATH); +} + +static int +mach32_vlb_available(void) +{ + return rom_present(BIOS_MACH32_VLB_ROM_PATH); +} + +static int +mach32_pci_available(void) +{ + return rom_present(BIOS_MACH32_PCI_ROM_PATH); +} + +static void +mach_close(void *priv) +{ + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + ibm8514_t *dev = &svga->dev8514; + + if (dev) { + free(dev->vram); + free(dev->changedvram); + } + + svga_close(svga); + free(mach); +} + +static void +mach_speed_changed(void *priv) +{ + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + + svga_recalctimings(svga); +} + +static void +mach_force_redraw(void *priv) +{ + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + + svga->fullchange = changeframecount; +} + +// clang-format off +static const device_config_t mach32_config[] = { + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 2048, + .selection = { + { + .description = "512 KB", + .value = 512 + }, + { + .description = "1 MB", + .value = 1024 + }, + { + .description = "2 MB", + .value = 2048 + }, + { + .description = "4 MB", + .value = 4096 + }, + { + .description = "" + } + } + }, + { + .type = CONFIG_END + } +}; + +const device_t mach8_isa_device = { + .name = "ATI Mach8 (ISA)", + .internal_name = "mach8_isa", + .flags = DEVICE_ISA, + .local = 0, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + { .available = mach8_available }, + .speed_changed = mach_speed_changed, + .force_redraw = mach_force_redraw, + .config = NULL +}; + +const device_t mach32_isa_device = { + .name = "ATI Mach32 (ISA)", + .internal_name = "mach32_isa", + .flags = DEVICE_ISA, + .local = 1, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + { .available = mach32_isa_available }, + .speed_changed = mach_speed_changed, + .force_redraw = mach_force_redraw, + .config = mach32_config +}; + +const device_t mach32_vlb_device = { + .name = "ATI Mach32 (VLB)", + .internal_name = "mach32_vlb", + .flags = DEVICE_VLB, + .local = 1, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + { .available = mach32_vlb_available }, + .speed_changed = mach_speed_changed, + .force_redraw = mach_force_redraw, + .config = mach32_config +}; + +const device_t mach32_pci_device = { + .name = "ATI Mach32 (PCI)", + .internal_name = "mach32_pci", + .flags = DEVICE_PCI, + .local = 1, + .init = mach8_init, + .close = mach_close, + .reset = NULL, + { .available = mach32_pci_available }, + .speed_changed = mach_speed_changed, + .force_redraw = mach_force_redraw, + .config = mach32_config +}; diff --git a/src/video/vid_att20c49x_ramdac.c b/src/video/vid_att20c49x_ramdac.c index 1874afce9..3f995c56a 100644 --- a/src/video/vid_att20c49x_ramdac.c +++ b/src/video/vid_att20c49x_ramdac.c @@ -63,6 +63,9 @@ att49x_ramdac_control(uint8_t val, void *p, svga_t *svga) case 7: svga->bpp = 24; break; + + default: + break; } if (ramdac->type == ATT_490 || ramdac->type == ATT_491) svga_set_ramdac_type(svga, (val & 2) ? RAMDAC_8BIT : RAMDAC_6BIT); @@ -100,6 +103,9 @@ att49x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga) att49x_ramdac_control(val, ramdac, svga); ramdac->state = 0; break; + + default: + break; } } @@ -143,6 +149,9 @@ att49x_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga) temp = ramdac->ctrl; ramdac->state = 0; break; + + default: + break; } return temp; diff --git a/src/video/vid_att2xc498_ramdac.c b/src/video/vid_att2xc498_ramdac.c index 2dab4b903..9919b7111 100644 --- a/src/video/vid_att2xc498_ramdac.c +++ b/src/video/vid_att2xc498_ramdac.c @@ -102,6 +102,9 @@ att498_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga) case 0x06: att498_ramdac_control(val, ramdac, svga); break; + + default: + break; } } @@ -147,6 +150,9 @@ att498_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga) temp = ramdac->ctrl; ramdac->state = 0; break; + + default: + break; } return temp; diff --git a/src/video/vid_av9194.c b/src/video/vid_av9194.c index f8ebc89de..e7cf75dee 100644 --- a/src/video/vid_av9194.c +++ b/src/video/vid_av9194.c @@ -27,9 +27,10 @@ #include <86box/timer.h> #include <86box/video.h> #include <86box/vid_svga.h> +#include <86box/plat_unused.h> float -av9194_getclock(int clock, void *p) +av9194_getclock(int clock, UNUSED(void *priv)) { float ret = 0.0; @@ -79,13 +80,16 @@ av9194_getclock(int clock, void *p) case 0xf: ret = 94500000.0; break; + + default: + break; } return ret; } static void * -av9194_init(const device_t *info) +av9194_init(UNUSED(const device_t *info)) { /* Return something non-NULL. */ return (void *) &av9194_device; diff --git a/src/video/vid_bt48x_ramdac.c b/src/video/vid_bt48x_ramdac.c index daf840df8..bb276ece6 100644 --- a/src/video/vid_bt48x_ramdac.c +++ b/src/video/vid_bt48x_ramdac.c @@ -77,6 +77,9 @@ bt48x_set_bpp(bt48x_ramdac_t *ramdac, svga_t *svga) case 0x60: svga->bpp = 4; break; + + default: + break; } svga_recalctimings(svga); } @@ -104,7 +107,7 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * svga->dac_status = addr & 0x03; svga->dac_addr = val; if (ramdac->type >= BT485) - svga->dac_addr |= ((int) (ramdac->cmd_r3 & 0x03) << 8); + svga->dac_addr |= ((ramdac->cmd_r3 & 0x03) << 8); if (svga->dac_status) svga->dac_addr = (svga->dac_addr + 1) & da_mask; break; @@ -143,6 +146,9 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * svga->dac_addr = (svga->dac_addr + 1) & 0xff; svga->dac_pos = 0; break; + + default: + break; } break; case 0x06: /* Command Register 0 (RS value = 0110) */ @@ -160,7 +166,7 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * break; case 0x0a: if ((ramdac->type >= BT485) && (ramdac->cmd_r0 & 0x80)) { - switch ((svga->dac_addr & ((ramdac->type >= BT485A) ? 0xff : 0x3f))) { + switch (svga->dac_addr & ((ramdac->type >= BT485A) ? 0xff : 0x3f)) { case 0x01: /* Command Register 3 (RS value = 1010) */ ramdac->cmd_r3 = val; @@ -183,6 +189,9 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * break; } break; + + default: + break; } } break; @@ -215,6 +224,9 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * ramdac->hwc_y = (ramdac->hwc_y & 0x00ff) | ((val & 0x0f) << 8); svga->dac_hwcursor.y = ramdac->hwc_y - svga->dac_hwcursor.cur_ysize; break; + + default: + break; } return; @@ -271,6 +283,9 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) else temp = ramdac->extpal[index].b & 0x3f; break; + + default: + break; } break; case 0x06: /* Command Register 0 (RS value = 0110) */ @@ -284,9 +299,9 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) break; case 0x0a: if ((ramdac->type >= BT485) && (ramdac->cmd_r0 & 0x80)) { - switch ((svga->dac_addr & ((ramdac->type >= BT485A) ? 0xff : 0x3f))) { - case 0x00: + switch (svga->dac_addr & ((ramdac->type >= BT485A) ? 0xff : 0x3f)) { default: + case 0x00: temp = ramdac->status | (svga->dac_status ? 0x04 : 0x00); break; case 0x01: @@ -307,7 +322,6 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) temp = 0xff; break; } - break; } } else temp = ramdac->status | (svga->dac_status ? 0x04 : 0x00); @@ -337,6 +351,9 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) case 0x0f: /* Cursor Y High Register (RS value = 1111) */ temp = (ramdac->hwc_y >> 8) & 0xff; break; + + default: + break; } return temp; @@ -355,11 +372,20 @@ bt48x_recalctimings(void *p, svga_t *svga) void bt48x_hwcursor_draw(svga_t *svga, int displine) { - int x, xx, comb, b0, b1; + int comb; + int b0; + int b1; uint16_t dat[2]; int offset = svga->dac_hwcursor_latch.x - svga->dac_hwcursor_latch.xoff; - int pitch, bppl, mode, x_pos, y_pos; - uint32_t clr1, clr2, clr3, *p; + int pitch; + int bppl; + int mode; + int x_pos; + int y_pos; + uint32_t clr1; + uint32_t clr2; + uint32_t clr3; + uint32_t *p; uint8_t *cd; bt48x_ramdac_t *ramdac = (bt48x_ramdac_t *) svga->ramdac; @@ -384,11 +410,11 @@ bt48x_hwcursor_draw(svga_t *svga, int displine) else cd = (uint8_t *) ramdac->cursor32_data; - for (x = 0; x < svga->dac_hwcursor_latch.cur_xsize; x += 16) { + for (int x = 0; x < svga->dac_hwcursor_latch.cur_xsize; x += 16) { dat[0] = (cd[svga->dac_hwcursor_latch.addr] << 8) | cd[svga->dac_hwcursor_latch.addr + 1]; dat[1] = (cd[svga->dac_hwcursor_latch.addr + bppl] << 8) | cd[svga->dac_hwcursor_latch.addr + bppl + 1]; - for (xx = 0; xx < 16; xx++) { + for (uint8_t xx = 0; xx < 16; xx++) { b0 = (dat[0] >> (15 - xx)) & 1; b1 = (dat[1] >> (15 - xx)) & 1; comb = (b0 | (b1 << 1)); @@ -410,6 +436,9 @@ bt48x_hwcursor_draw(svga_t *svga, int displine) case 3: p[x_pos] = clr3; break; + + default: + break; } break; case 2: /* PM/Windows */ @@ -423,6 +452,9 @@ bt48x_hwcursor_draw(svga_t *svga, int displine) case 3: p[x_pos] ^= 0xffffff; break; + + default: + break; } break; case 3: /* X-Windows */ @@ -433,8 +465,14 @@ bt48x_hwcursor_draw(svga_t *svga, int displine) case 3: p[x_pos] = clr2; break; + + default: + break; } break; + + default: + break; } } offset++; @@ -475,6 +513,9 @@ bt48x_ramdac_init(const device_t *info) case BT485A: ramdac->status = 0x20; break; + + default: + break; } return ramdac; diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index 6ed81f616..14ff3b221 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -33,6 +33,7 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> #define CGA_RGB 0 #define CGA_COMPOSITE 1 @@ -50,9 +51,9 @@ static video_timings_t timing_cga = { .type = VIDEO_ISA, .write_b = 8, .write_w void cga_recalctimings(cga_t *cga); void -cga_out(uint16_t addr, uint8_t val, void *p) +cga_out(uint16_t addr, uint8_t val, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; uint8_t old; if ((addr >= 0x3d0) && (addr <= 0x3d7)) @@ -77,7 +78,7 @@ cga_out(uint16_t addr, uint8_t val, void *p) cga->cgamode = val; if (old ^ val) { - if ((old ^ val) & 0x05) + if ((old ^ val) & 0x07) update_cga16_color(val); cga_recalctimings(cga); @@ -89,13 +90,16 @@ cga_out(uint16_t addr, uint8_t val, void *p) if (old ^ val) cga_recalctimings(cga); return; + + default: + break; } } uint8_t -cga_in(uint16_t addr, void *p) +cga_in(uint16_t addr, void *priv) { - cga_t *cga = (cga_t *) p; + const cga_t *cga = (cga_t *) priv; uint8_t ret = 0xff; @@ -112,29 +116,32 @@ cga_in(uint16_t addr, void *p) case 0x3DA: ret = cga->cgastat; break; + + default: + break; } return ret; } void -cga_pravetz_out(uint16_t addr, uint8_t val, void *p) +cga_pravetz_out(UNUSED(uint16_t addr), uint8_t val, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga->fontbase = (((unsigned int) val) << 8); } uint8_t -cga_pravetz_in(uint16_t addr, void *p) +cga_pravetz_in(UNUSED(uint16_t addr), void *priv) { - cga_t *cga = (cga_t *) p; + const cga_t *cga = (cga_t *) priv; return (cga->fontbase >> 8); } void -cga_waitstates(void *p) +cga_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -144,9 +151,9 @@ cga_waitstates(void *p) } void -cga_write(uint32_t addr, uint8_t val, void *p) +cga_write(uint32_t addr, uint8_t val, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga->vram[addr & 0x3fff] = val; if (cga->snow_enabled) { @@ -158,9 +165,9 @@ cga_write(uint32_t addr, uint8_t val, void *p) } uint8_t -cga_read(uint32_t addr, void *p) +cga_read(uint32_t addr, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga_waitstates(cga); if (cga->snow_enabled) { @@ -175,7 +182,8 @@ void cga_recalctimings(cga_t *cga) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; if (cga->cgamode & 1) { disptime = (double) (cga->crtc[0] + 1); @@ -192,14 +200,18 @@ cga_recalctimings(cga_t *cga) } void -cga_poll(void *p) +cga_poll(void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; uint16_t ca = (cga->crtc[15] | (cga->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int c; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint8_t border; uint16_t dat; int cols[4]; @@ -221,18 +233,18 @@ cga_poll(void *p) cga->lastline = cga->displine; for (c = 0; c < 8; c++) { if ((cga->cgamode & 0x12) == 0x12) { - buffer32->line[(cga->displine << 1)][c] = buffer32->line[(cga->displine << 1) + 1][c] = 0; + buffer32->line[cga->displine << 1][c] = buffer32->line[(cga->displine << 1) + 1][c] = 0; if (cga->cgamode & 1) { - buffer32->line[(cga->displine << 1)][c + (cga->crtc[1] << 3) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 3) + 8] = 0; + buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 3) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 3) + 8] = 0; } else { - buffer32->line[(cga->displine << 1)][c + (cga->crtc[1] << 4) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 4) + 8] = 0; + buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 4) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 4) + 8] = 0; } } else { - buffer32->line[(cga->displine << 1)][c] = buffer32->line[(cga->displine << 1) + 1][c] = (cga->cgacol & 15) + 16; + buffer32->line[cga->displine << 1][c] = buffer32->line[(cga->displine << 1) + 1][c] = (cga->cgacol & 15) + 16; if (cga->cgamode & 1) { - buffer32->line[(cga->displine << 1)][c + (cga->crtc[1] << 3) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 3) + 8] = (cga->cgacol & 15) + 16; + buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 3) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 3) + 8] = (cga->cgacol & 15) + 16; } else { - buffer32->line[(cga->displine << 1)][c + (cga->crtc[1] << 4) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 4) + 8] = (cga->cgacol & 15) + 16; + buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 4) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 4) + 8] = (cga->cgacol & 15) + 16; } } } @@ -253,11 +265,11 @@ cga_poll(void *p) cols[0] = (attr >> 4) + 16; if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(cga->displine << 1)][(x << 3) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[cga->displine << 1][(x << 3) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(cga->displine << 1)][(x << 3) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[cga->displine << 1][(x << 3) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } cga->ma++; @@ -265,8 +277,8 @@ cga_poll(void *p) } else if (!(cga->cgamode & 2)) { for (x = 0; x < cga->crtc[1]; x++) { if (cga->cgamode & 8) { - chr = cga->vram[((cga->ma << 1) & 0x3fff)]; - attr = cga->vram[(((cga->ma << 1) + 1) & 0x3fff)]; + chr = cga->vram[(cga->ma << 1) & 0x3fff]; + attr = cga->vram[((cga->ma << 1) + 1) & 0x3fff]; } else chr = attr = 0; drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron); @@ -280,11 +292,11 @@ cga_poll(void *p) cga->ma++; if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(cga->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(cga->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } @@ -311,7 +323,7 @@ cga_poll(void *p) dat = 0; cga->ma++; for (c = 0; c < 8; c++) { - buffer32->line[(cga->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; + buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; dat <<= 2; } } @@ -325,7 +337,7 @@ cga_poll(void *p) dat = 0; cga->ma++; for (c = 0; c < 16; c++) { - buffer32->line[(cga->displine << 1)][(x << 4) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; + buffer32->line[cga->displine << 1][(x << 4) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; dat <<= 1; } } @@ -347,12 +359,9 @@ cga_poll(void *p) x = (cga->crtc[1] << 4) + 16; if (cga->composite) { - if (cga->cgamode & 0x10) - border = 0x00; - else - border = cga->cgacol & 0x0f; + border = ((cga->cgamode & 0x12) == 0x12) ? 0 : (cga->cgacol & 15); - Composite_Process(cga->cgamode, border, x >> 2, buffer32->line[(cga->displine << 1)]); + Composite_Process(cga->cgamode, border, x >> 2, buffer32->line[cga->displine << 1]); Composite_Process(cga->cgamode, border, x >> 2, buffer32->line[(cga->displine << 1) + 1]); } else { video_process_8(x, cga->displine << 1); @@ -489,11 +498,11 @@ cga_poll(void *p) } if (cga->cgadispon) cga->cgastat &= ~1; - if ((cga->sc == (cga->crtc[10] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[10] & 31) >> 1)))) + if (cga->sc == (cga->crtc[10] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[10] & 31) >> 1))) cga->con = 1; if (cga->cgadispon && (cga->cgamode & 1)) { for (x = 0; x < (cga->crtc[1] << 1); x++) - cga->charbuffer[x] = cga->vram[(((cga->ma << 1) + x) & 0x3fff)]; + cga->charbuffer[x] = cga->vram[((cga->ma << 1) + x) & 0x3fff]; } } } @@ -506,7 +515,7 @@ cga_init(cga_t *cga) } void * -cga_standalone_init(const device_t *info) +cga_standalone_init(UNUSED(const device_t *info)) { int display_type; cga_t *cga = malloc(sizeof(cga_t)); @@ -531,6 +540,7 @@ cga_standalone_init(const device_t *info) cga->rgb_type = device_get_config_int("rgb_type"); cga_palette = (cga->rgb_type << 1); cgapal_rebuild(); + update_cga16_color(cga->cgamode); return cga; } @@ -551,18 +561,18 @@ cga_pravetz_init(const device_t *info) } void -cga_close(void *p) +cga_close(void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; free(cga->vram); free(cga); } void -cga_speed_changed(void *p) +cga_speed_changed(void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga_recalctimings(cga); } diff --git a/src/video/vid_cga_comp.c b/src/video/vid_cga_comp.c index ad9f673fb..31e4a6bf7 100644 --- a/src/video/vid_cga_comp.c +++ b/src/video/vid_cga_comp.c @@ -75,7 +75,12 @@ double mode_hue; double min_v; double max_v; -double video_ri, video_rq, video_gi, video_gq, video_bi, video_bq; +double video_ri; +double video_rq; +double video_gi; +double video_gq; +double video_bi; +double video_bq; int video_sharpness; int tandy_mode_control = 0; @@ -84,11 +89,18 @@ static bool new_cga = 0; void update_cga16_color(uint8_t cgamode) { - int x; - double c, i, v; - double q, a, s, r; - double iq_adjust_i, iq_adjust_q; - double i0, i3, mode_saturation; + double c; + double i; + double v; + double q; + double a; + double s; + double r; + double iq_adjust_i; + double iq_adjust_q; + double i0; + double i3; + double mode_saturation; static const double ri = 0.9563; static const double rq = 0.6210; @@ -117,7 +129,7 @@ update_cga16_color(uint8_t cgamode) mode_brightness += (new_cga ? brightness - 10 : brightness) * 5; /* new CGA: -10 */ mode_saturation = (new_cga ? 4.35 : 2.9) * saturation / 100; /* new CGA: 150% */ - for (x = 0; x < 1024; ++x) { + for (uint16_t x = 0; x < 1024; ++x) { int phase = x & 3; int right = (x >> 2) & 15; int left = (x >> 6) & 15; @@ -160,7 +172,7 @@ update_cga16_color(uint8_t cgamode) video_sharpness = (int) (sharpness * 256 / 100); } -static Bit8u +static uint8_t byte_clamp(int v) { v >>= 13; @@ -174,20 +186,20 @@ static int temp[SCALER_MAXWIDTH + 10] = { 0 }; static int atemp[SCALER_MAXWIDTH + 2] = { 0 }; static int btemp[SCALER_MAXWIDTH + 2] = { 0 }; -Bit32u * -Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewidth*/, Bit32u *TempLine) +uint32_t * +Composite_Process(uint8_t cgamode, uint8_t border, uint32_t blocks /*, bool doublewidth*/, uint32_t *TempLine) { - int x; - Bit32u x2; + uint32_t x2; int w = blocks * 4; - int *o; - Bit32u *rgbi; - int *b; - int *i; - Bit32u *srgb; - int *ap, *bp; + int *o; + const uint32_t *rgbi; + const int *b; + int *i; + uint32_t *srgb; + int *ap; + int *bp; #define COMPOSITE_CONVERT(I, Q) \ do { \ @@ -217,21 +229,21 @@ Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewi o = temp; rgbi = TempLine; b = &CGA_Composite_Table[border * 68]; - for (x = 0; x < 4; ++x) + for (uint8_t x = 0; x < 4; ++x) OUT(b[(x + 3) & 3]); OUT(CGA_Composite_Table[(border << 6) | ((*rgbi & 0x0f) << 2) | 3]); - for (x = 0; x < w - 1; ++x) { + for (int x = 0; x < w - 1; ++x) { OUT(CGA_Composite_Table[((rgbi[0] & 0x0f) << 6) | ((rgbi[1] & 0x0f) << 2) | (x & 3)]); ++rgbi; } OUT(CGA_Composite_Table[((*rgbi & 0x0f) << 6) | (border << 2) | 3]); - for (x = 0; x < 5; ++x) + for (uint8_t x = 0; x < 5; ++x) OUT(b[x & 3]); if ((cgamode & 4) != 0) { /* Decode */ i = temp + 5; - srgb = (Bit32u *) TempLine; + srgb = TempLine; for (x2 = 0; x2 < blocks * 4; ++x2) { int c = (i[0] + i[0]) << 3; int d = (i[-1] + i[1]) << 3; @@ -245,7 +257,7 @@ Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewi i = temp + 4; ap = atemp + 1; bp = btemp + 1; - for (x = -1; x < w + 1; ++x) { + for (int x = -1; x < w + 1; ++x) { ap[x] = i[-4] - ((i[-2] - i[0] + i[2]) << 1) + i[4]; bp[x] = (i[-3] - i[-1] + i[1] - i[3]) << 1; ++i; @@ -255,9 +267,16 @@ Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewi i = temp + 5; i[-1] = (i[-1] << 3) - ap[-1]; i[0] = (i[0] << 3) - ap[0]; - srgb = (Bit32u *) TempLine; + srgb = TempLine; for (x2 = 0; x2 < blocks; ++x2) { - int y, a, b, c, d, rr, gg, bb; + int y; + int a; + int b; + int c; + int d; + int rr; + int gg; + int bb; COMPOSITE_CONVERT(a, b); COMPOSITE_CONVERT(-b, a); COMPOSITE_CONVERT(-a, -b); diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index d402050c7..225810974 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -236,19 +236,19 @@ static video_timings_t timing_gd54xx_vlb = { .type = VIDEO_BUS, .write_b = 4, .w static video_timings_t timing_gd54xx_pci = { .type = VIDEO_PCI, .write_b = 4, .write_w = 4, .write_l = 8, .read_b = 10, .read_w = 10, .read_l = 20 }; static void -gd543x_mmio_write(uint32_t addr, uint8_t val, void *p); +gd543x_mmio_write(uint32_t addr, uint8_t val, void *priv); static void -gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *p); +gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *priv); static void -gd543x_mmio_writew(uint32_t addr, uint16_t val, void *p); +gd543x_mmio_writew(uint32_t addr, uint16_t val, void *priv); static void -gd543x_mmio_writel(uint32_t addr, uint32_t val, void *p); +gd543x_mmio_writel(uint32_t addr, uint32_t val, void *priv); static uint8_t -gd543x_mmio_read(uint32_t addr, void *p); +gd543x_mmio_read(uint32_t addr, void *priv); static uint16_t -gd543x_mmio_readw(uint32_t addr, void *p); +gd543x_mmio_readw(uint32_t addr, void *priv); static uint32_t -gd543x_mmio_readl(uint32_t addr, void *p); +gd543x_mmio_readl(uint32_t addr, void *priv); static void gd54xx_recalc_banking(gd54xx_t *gd54xx); @@ -492,7 +492,7 @@ gd54xx_update_irqs(gd54xx_t *gd54xx) static void gd54xx_vblank_start(svga_t *svga) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; if (gd54xx->vblank_irq >= 0) { gd54xx->vblank_irq = 1; gd54xx_update_irqs(gd54xx); @@ -512,25 +512,28 @@ gd54xx_is_5422(svga_t *svga) static void gd54xx_overlay_draw(svga_t *svga, int displine) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; int shift = (svga->crtc[0x27] >= CIRRUS_ID_CLGD5446) ? 2 : 0; int h_acc = svga->overlay_latch.h_acc; - int r[8], g[8], b[8]; - int x_read = 4, x_write = 4; - int x; + int r[8]; + int g[8]; + int b[8]; + int x_read = 4; + int x_write = 4; uint32_t *p; uint8_t *src = &svga->vram[(svga->overlay_latch.addr << shift) & svga->vram_mask]; int bpp = svga->bpp; int bytesperpix = (bpp + 7) / 8; uint8_t *src2 = &svga->vram[(svga->ma - (svga->hdisp * bytesperpix)) & svga->vram_display_mask]; - int occl, ckval; + int occl; + int ckval; p = &((uint32_t *) svga->monitor->target_buffer->line[displine])[gd54xx->overlay.region1size + svga->x_add]; src2 += gd54xx->overlay.region1size * bytesperpix; OVERLAY_SAMPLE(); - for (x = 0; (x < gd54xx->overlay.region2size) && ((x + gd54xx->overlay.region1size) < svga->hdisp); x++) { + for (int x = 0; (x < gd54xx->overlay.region2size) && ((x + gd54xx->overlay.region1size) < svga->hdisp); x++) { if (gd54xx->overlay.occlusion) { occl = 1; ckval = gd54xx->overlay.ck; @@ -609,13 +612,13 @@ gd54xx_is_5434(svga_t *svga) } static void -gd54xx_out(uint16_t addr, uint8_t val, void *p) +gd54xx_out(uint16_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t old; - int c; - uint8_t o, index; + uint8_t o; + uint8_t index; uint32_t o32; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -637,7 +640,7 @@ gd54xx_out(uint16_t addr, uint8_t val, void *p) if (svga->attraddr < 16) svga->fullchange = changeframecount; if (svga->attraddr == 0x10 || svga->attraddr == 0x14 || svga->attraddr < 0x10) { - for (c = 0; c < 16; c++) { + for (uint8_t c = 0; c < 16; c++) { if (svga->attrregs[0x10] & 0x80) svga->egapal[c] = (svga->attrregs[c] & 0xf) | ((svga->attrregs[0x14] & 0xf) << 4); else @@ -1154,12 +1157,13 @@ gd54xx_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -gd54xx_in(uint16_t addr, void *p) +gd54xx_in(uint16_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; - uint8_t index, ret = 0xff; + uint8_t index; + uint8_t ret = 0xff; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -1550,7 +1554,8 @@ static void gd543x_recalc_mapping(gd54xx_t *gd54xx) { svga_t *svga = &gd54xx->svga; - uint32_t base, size; + uint32_t base; + uint32_t size; if ((gd54xx->pci && (!(gd54xx->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM))) || (gd54xx->mca && (!(gd54xx->pos_regs[2] & 1)))) { mem_mapping_disable(&svga->mapping); @@ -1630,7 +1635,7 @@ gd543x_recalc_mapping(gd54xx_t *gd54xx) if ((svga->crtc[0x27] >= CIRRUS_ID_CLGD5436) && (gd54xx->blt.status & CIRRUS_BLT_APERTURE2) && ((gd54xx->blt.mode & (CIRRUS_BLTMODE_COLOREXPAND | CIRRUS_BLTMODE_MEMSYSSRC)) == (CIRRUS_BLTMODE_COLOREXPAND | CIRRUS_BLTMODE_MEMSYSSRC))) { if (svga->crtc[0x27] == CIRRUS_ID_CLGD5480) - mem_mapping_set_addr(&gd54xx->aperture2_mapping, gd54xx->lfb_base + (16777216), 16777216); + mem_mapping_set_addr(&gd54xx->aperture2_mapping, gd54xx->lfb_base + 16777216, 16777216); else mem_mapping_set_addr(&gd54xx->aperture2_mapping, 0xbc000, 0x04000); } else @@ -1641,8 +1646,9 @@ gd543x_recalc_mapping(gd54xx_t *gd54xx) static void gd54xx_recalctimings(svga_t *svga) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; - uint8_t clocksel, rdmask; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; + uint8_t clocksel; + uint8_t rdmask; uint8_t linedbl = svga->dispend * 9 / 10 >= svga->hdisp; svga->rowoffset = (svga->crtc[0x13]) | (((int) (uint32_t) (svga->crtc[0x1b] & 0x10)) << 4); @@ -1801,7 +1807,7 @@ gd54xx_recalctimings(svga_t *svga) clocksel = (svga->miscout >> 2) & 3; if (!gd54xx->vclk_n[clocksel] || !gd54xx->vclk_d[clocksel]) - svga->clock = (cpuclock * (float) (1ull << 32)) / ((svga->miscout & 0xc) ? 28322000.0 : 25175000.0); + svga->clock = (cpuclock * (float) (1ULL << 32)) / ((svga->miscout & 0xc) ? 28322000.0 : 25175000.0); else { int n = gd54xx->vclk_n[clocksel] & 0x7f; int d = (gd54xx->vclk_d[clocksel] & 0x3e) >> 1; @@ -1818,7 +1824,7 @@ gd54xx_recalctimings(svga_t *svga) break; } } - svga->clock = (cpuclock * (double) (1ull << 32)) / freq; + svga->clock = (cpuclock * (double) (1ULL << 32)) / freq; } svga->vram_display_mask = (svga->crtc[0x1b] & 2) ? gd54xx->vram_mask : 0x3ffff; @@ -1827,8 +1833,10 @@ gd54xx_recalctimings(svga_t *svga) static void gd54xx_hwcursor_draw(svga_t *svga, int displine) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; - int x, xx, comb, b0, b1; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; + int comb; + int b0; + int b1; uint8_t dat[2]; int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; int pitch = (svga->hwcursor.cur_xsize == 64) ? 16 : 4; @@ -1841,13 +1849,13 @@ gd54xx_hwcursor_draw(svga_t *svga, int displine) if (svga->interlace && svga->hwcursor_oddeven) svga->hwcursor_latch.addr += pitch; - for (x = 0; x < svga->hwcursor.cur_xsize; x += 8) { + for (int x = 0; x < svga->hwcursor.cur_xsize; x += 8) { dat[0] = svga->vram[svga->hwcursor_latch.addr & svga->vram_display_mask]; if (svga->hwcursor.cur_xsize == 64) dat[1] = svga->vram[(svga->hwcursor_latch.addr + 0x08) & svga->vram_display_mask]; else dat[1] = svga->vram[(svga->hwcursor_latch.addr + 0x80) & svga->vram_display_mask]; - for (xx = 0; xx < 8; xx++) { + for (uint8_t xx = 0; xx < 8; xx++) { b0 = (dat[0] >> (7 - xx)) & 1; b1 = (dat[1] >> (7 - xx)) & 1; comb = (b1 | (b0 << 1)); @@ -1966,15 +1974,13 @@ gd54xx_mem_sys_dest_read(gd54xx_t *gd54xx) static void gd54xx_mem_sys_src_write(gd54xx_t *gd54xx, uint8_t val) { - int i; - gd54xx->blt.sys_src32 &= ~(0xff << (gd54xx->blt.sys_cnt << 3)); gd54xx->blt.sys_src32 |= (val << (gd54xx->blt.sys_cnt << 3)); gd54xx->blt.sys_cnt = (gd54xx->blt.sys_cnt + 1) & 3; if (gd54xx->blt.sys_cnt == 0) { if ((gd54xx->blt.mode & CIRRUS_BLTMODE_COLOREXPAND) && !(gd54xx->blt.modeext & CIRRUS_BLTMODEEXT_DWORDGRANULARITY)) { - for (i = 0; i < 32; i += 8) + for (uint8_t i = 0; i < 32; i += 8) gd54xx_start_blit((gd54xx->blt.sys_src32 >> i) & 0xff, 8, gd54xx, &gd54xx->svga); } else gd54xx_start_blit(gd54xx->blt.sys_src32, 32, gd54xx, &gd54xx->svga); @@ -1982,9 +1988,9 @@ gd54xx_mem_sys_src_write(gd54xx_t *gd54xx, uint8_t val) } static void -gd54xx_write(uint32_t addr, uint8_t val, void *p) +gd54xx_write(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2003,9 +2009,9 @@ gd54xx_write(uint32_t addr, uint8_t val, void *p) } static void -gd54xx_writew(uint32_t addr, uint16_t val, void *p) +gd54xx_writew(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2030,9 +2036,9 @@ gd54xx_writew(uint32_t addr, uint16_t val, void *p) } static void -gd54xx_writel(uint32_t addr, uint32_t val, void *p) +gd54xx_writel(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2064,7 +2070,8 @@ gd54xx_writel(uint32_t addr, uint32_t val, void *p) static void gd54xx_write_modes45(svga_t *svga, uint8_t val, uint32_t addr) { - uint32_t i, j; + uint32_t i; + uint32_t j; switch (svga->writemode) { case 4: @@ -2140,9 +2147,9 @@ gd54xx_aperture2_enabled(gd54xx_t *gd54xx) } static uint8_t -gd54xx_readb_linear(uint32_t addr, void *p) +gd54xx_readb_linear(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2180,9 +2187,9 @@ gd54xx_readb_linear(uint32_t addr, void *p) } static uint16_t -gd54xx_readw_linear(uint32_t addr, void *p) +gd54xx_readw_linear(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2202,8 +2209,8 @@ gd54xx_readw_linear(uint32_t addr, void *p) /* Do mem sys dest reads here if the blitter is neither paused, nor is there a second aperture. */ if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - temp = gd54xx_readb_linear(addr, p); - temp |= gd54xx_readb_linear(addr + 1, p) << 8; + temp = gd54xx_readb_linear(addr, priv); + temp |= gd54xx_readb_linear(addr + 1, priv) << 8; return temp; } @@ -2228,9 +2235,9 @@ gd54xx_readw_linear(uint32_t addr, void *p) } static uint32_t -gd54xx_readl_linear(uint32_t addr, void *p) +gd54xx_readl_linear(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2250,10 +2257,10 @@ gd54xx_readl_linear(uint32_t addr, void *p) /* Do mem sys dest reads here if the blitter is neither paused, nor is there a second aperture. */ if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - temp = gd54xx_readb_linear(addr, p); - temp |= gd54xx_readb_linear(addr + 1, p) << 8; - temp |= gd54xx_readb_linear(addr + 2, p) << 16; - temp |= gd54xx_readb_linear(addr + 3, p) << 24; + temp = gd54xx_readb_linear(addr, priv); + temp |= gd54xx_readb_linear(addr + 1, priv) << 8; + temp |= gd54xx_readb_linear(addr + 2, priv) << 16; + temp |= gd54xx_readb_linear(addr + 3, priv) << 24; return temp; } @@ -2287,9 +2294,9 @@ gd54xx_readl_linear(uint32_t addr, void *p) } static uint8_t -gd5436_aperture2_readb(uint32_t addr, void *p) +gd5436_aperture2_readb(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) return gd54xx_mem_sys_dest_read(gd54xx); @@ -2298,14 +2305,14 @@ gd5436_aperture2_readb(uint32_t addr, void *p) } static uint16_t -gd5436_aperture2_readw(uint32_t addr, void *p) +gd5436_aperture2_readw(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; uint16_t ret = 0xffff; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd5436_aperture2_readb(addr, p); - ret |= gd5436_aperture2_readb(addr + 1, p) << 8; + ret = gd5436_aperture2_readb(addr, priv); + ret |= gd5436_aperture2_readb(addr + 1, priv) << 8; return ret; } @@ -2313,16 +2320,16 @@ gd5436_aperture2_readw(uint32_t addr, void *p) } static uint32_t -gd5436_aperture2_readl(uint32_t addr, void *p) +gd5436_aperture2_readl(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; uint32_t ret = 0xffffffff; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd5436_aperture2_readb(addr, p); - ret |= gd5436_aperture2_readb(addr + 1, p) << 8; - ret |= gd5436_aperture2_readb(addr + 2, p) << 16; - ret |= gd5436_aperture2_readb(addr + 3, p) << 24; + ret = gd5436_aperture2_readb(addr, priv); + ret |= gd5436_aperture2_readb(addr + 1, priv) << 8; + ret |= gd5436_aperture2_readb(addr + 2, priv) << 16; + ret |= gd5436_aperture2_readb(addr + 3, priv) << 24; return ret; } @@ -2330,9 +2337,9 @@ gd5436_aperture2_readl(uint32_t addr, void *p) } static void -gd5436_aperture2_writeb(uint32_t addr, uint8_t val, void *p) +gd5436_aperture2_writeb(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) @@ -2340,9 +2347,9 @@ gd5436_aperture2_writeb(uint32_t addr, uint8_t val, void *p) } static void -gd5436_aperture2_writew(uint32_t addr, uint16_t val, void *p) +gd5436_aperture2_writew(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2352,9 +2359,9 @@ gd5436_aperture2_writew(uint32_t addr, uint16_t val, void *p) } static void -gd5436_aperture2_writel(uint32_t addr, uint32_t val, void *p) +gd5436_aperture2_writel(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2366,9 +2373,9 @@ gd5436_aperture2_writel(uint32_t addr, uint32_t val, void *p) } static void -gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *p) +gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2394,8 +2401,8 @@ gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *p) } switch (ap) { - case 0: default: + case 0: break; case 1: /* 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2 */ @@ -2413,9 +2420,9 @@ gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *p) } static void -gd54xx_writew_linear(uint32_t addr, uint16_t val, void *p) +gd54xx_writew_linear(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2477,9 +2484,9 @@ gd54xx_writew_linear(uint32_t addr, uint16_t val, void *p) } static void -gd54xx_writel_linear(uint32_t addr, uint32_t val, void *p) +gd54xx_writel_linear(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2554,9 +2561,9 @@ gd54xx_writel_linear(uint32_t addr, uint32_t val, void *p) } static uint8_t -gd54xx_read(uint32_t addr, void *p) +gd54xx_read(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if ((svga->seqregs[0x07] & 0x01) == 0) @@ -2570,9 +2577,9 @@ gd54xx_read(uint32_t addr, void *p) } static uint16_t -gd54xx_readw(uint32_t addr, void *p) +gd54xx_readw(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint16_t ret; @@ -2580,8 +2587,8 @@ gd54xx_readw(uint32_t addr, void *p) return svga_readw(addr, svga); if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd54xx_read(addr, p); - ret |= gd54xx_read(addr + 1, p) << 8; + ret = gd54xx_read(addr, priv); + ret |= gd54xx_read(addr + 1, priv) << 8; return ret; } @@ -2590,9 +2597,9 @@ gd54xx_readw(uint32_t addr, void *p) } static uint32_t -gd54xx_readl(uint32_t addr, void *p) +gd54xx_readl(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint32_t ret; @@ -2600,10 +2607,10 @@ gd54xx_readl(uint32_t addr, void *p) return svga_readl(addr, svga); if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd54xx_read(addr, p); - ret |= gd54xx_read(addr + 1, p) << 8; - ret |= gd54xx_read(addr + 2, p) << 16; - ret |= gd54xx_read(addr + 3, p) << 24; + ret = gd54xx_read(addr, priv); + ret |= gd54xx_read(addr + 1, priv) << 8; + ret |= gd54xx_read(addr + 2, priv) << 16; + ret |= gd54xx_read(addr + 3, priv) << 24; return ret; } @@ -2621,9 +2628,9 @@ gd543x_do_mmio(svga_t *svga, uint32_t addr) } static void -gd543x_mmio_write(uint32_t addr, uint8_t val, void *p) +gd543x_mmio_write(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t old; @@ -2787,9 +2794,9 @@ gd543x_mmio_write(uint32_t addr, uint8_t val, void *p) } static void -gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *p) +gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (!gd543x_do_mmio(svga, addr) && !gd54xx->blt.ms_is_dest && gd54xx->countminusone && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2797,13 +2804,13 @@ gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *p) return; } - gd543x_mmio_write(addr, val, p); + gd543x_mmio_write(addr, val, priv); } static void -gd543x_mmio_writew(uint32_t addr, uint16_t val, void *p) +gd543x_mmio_writew(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd543x_do_mmio(svga, addr)) { @@ -2821,9 +2828,9 @@ gd543x_mmio_writew(uint32_t addr, uint16_t val, void *p) } static void -gd543x_mmio_writel(uint32_t addr, uint32_t val, void *p) +gd543x_mmio_writel(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd543x_do_mmio(svga, addr)) { @@ -2847,9 +2854,9 @@ gd543x_mmio_writel(uint32_t addr, uint32_t val, void *p) } static uint8_t -gd543x_mmio_read(uint32_t addr, void *p) +gd543x_mmio_read(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ret = 0xff; @@ -2986,9 +2993,9 @@ gd543x_mmio_read(uint32_t addr, void *p) } static uint16_t -gd543x_mmio_readw(uint32_t addr, void *p) +gd543x_mmio_readw(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint16_t ret = 0xffff; @@ -2997,8 +3004,8 @@ gd543x_mmio_readw(uint32_t addr, void *p) else if (gd54xx->mmio_vram_overlap) ret = gd54xx_read(addr, gd54xx) | (gd54xx_read(addr + 1, gd54xx) << 8); else if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd543x_mmio_read(addr, p); - ret |= gd543x_mmio_read(addr + 1, p) << 8; + ret = gd543x_mmio_read(addr, priv); + ret |= gd543x_mmio_read(addr + 1, priv) << 8; return ret; } @@ -3006,9 +3013,9 @@ gd543x_mmio_readw(uint32_t addr, void *p) } static uint32_t -gd543x_mmio_readl(uint32_t addr, void *p) +gd543x_mmio_readl(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint32_t ret = 0xffffffff; @@ -3017,10 +3024,10 @@ gd543x_mmio_readl(uint32_t addr, void *p) else if (gd54xx->mmio_vram_overlap) ret = gd54xx_read(addr, gd54xx) | (gd54xx_read(addr + 1, gd54xx) << 8) | (gd54xx_read(addr + 2, gd54xx) << 16) | (gd54xx_read(addr + 3, gd54xx) << 24); else if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd543x_mmio_read(addr, p); - ret |= gd543x_mmio_read(addr + 1, p) << 8; - ret |= gd543x_mmio_read(addr + 2, p) << 16; - ret |= gd543x_mmio_read(addr + 3, p) << 24; + ret = gd543x_mmio_read(addr, priv); + ret |= gd543x_mmio_read(addr + 1, priv) << 8; + ret |= gd543x_mmio_read(addr + 2, priv) << 16; + ret |= gd543x_mmio_read(addr + 3, priv) << 24; return ret; } @@ -3028,86 +3035,86 @@ gd543x_mmio_readl(uint32_t addr, void *p) } static void -gd5480_vgablt_write(uint32_t addr, uint8_t val, void *p) +gd5480_vgablt_write(uint32_t addr, uint8_t val, void *priv) { addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - gd543x_mmio_writeb((addr & 0x000000ff) | 0x000b8000, val, p); + gd543x_mmio_writeb((addr & 0x000000ff) | 0x000b8000, val, priv); else if (addr < 0x00000100) - gd54xx_out(0x03c0 + addr, val, p); + gd54xx_out(0x03c0 + addr, val, priv); } static void -gd5480_vgablt_writew(uint32_t addr, uint16_t val, void *p) +gd5480_vgablt_writew(uint32_t addr, uint16_t val, void *priv) { addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - gd543x_mmio_writew((addr & 0x000000ff) | 0x000b8000, val, p); + gd543x_mmio_writew((addr & 0x000000ff) | 0x000b8000, val, priv); else if (addr < 0x00000100) { - gd5480_vgablt_write(addr, val & 0xff, p); - gd5480_vgablt_write(addr + 1, val >> 8, p); + gd5480_vgablt_write(addr, val & 0xff, priv); + gd5480_vgablt_write(addr + 1, val >> 8, priv); } } static void -gd5480_vgablt_writel(uint32_t addr, uint32_t val, void *p) +gd5480_vgablt_writel(uint32_t addr, uint32_t val, void *priv) { addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - gd543x_mmio_writel((addr & 0x000000ff) | 0x000b8000, val, p); + gd543x_mmio_writel((addr & 0x000000ff) | 0x000b8000, val, priv); else if (addr < 0x00000100) { - gd5480_vgablt_writew(addr, val & 0xffff, p); - gd5480_vgablt_writew(addr + 2, val >> 16, p); + gd5480_vgablt_writew(addr, val & 0xffff, priv); + gd5480_vgablt_writew(addr + 2, val >> 16, priv); } } static uint8_t -gd5480_vgablt_read(uint32_t addr, void *p) +gd5480_vgablt_read(uint32_t addr, void *priv) { uint8_t ret = 0xff; addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - ret = gd543x_mmio_read((addr & 0x000000ff) | 0x000b8000, p); + ret = gd543x_mmio_read((addr & 0x000000ff) | 0x000b8000, priv); else if (addr < 0x00000100) - ret = gd54xx_in(0x03c0 + addr, p); + ret = gd54xx_in(0x03c0 + addr, priv); return ret; } static uint16_t -gd5480_vgablt_readw(uint32_t addr, void *p) +gd5480_vgablt_readw(uint32_t addr, void *priv) { uint16_t ret = 0xffff; addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - ret = gd543x_mmio_readw((addr & 0x000000ff) | 0x000b8000, p); + ret = gd543x_mmio_readw((addr & 0x000000ff) | 0x000b8000, priv); else if (addr < 0x00000100) { - ret = gd5480_vgablt_read(addr, p); - ret |= (gd5480_vgablt_read(addr + 1, p) << 8); + ret = gd5480_vgablt_read(addr, priv); + ret |= (gd5480_vgablt_read(addr + 1, priv) << 8); } return ret; } static uint32_t -gd5480_vgablt_readl(uint32_t addr, void *p) +gd5480_vgablt_readl(uint32_t addr, void *priv) { uint32_t ret = 0xffffffff; addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - ret = gd543x_mmio_readl((addr & 0x000000ff) | 0x000b8000, p); + ret = gd543x_mmio_readl((addr & 0x000000ff) | 0x000b8000, priv); else if (addr < 0x00000100) { - ret = gd5480_vgablt_readw(addr, p); - ret |= (gd5480_vgablt_readw(addr + 2, p) << 16); + ret = gd5480_vgablt_readw(addr, priv); + ret |= (gd5480_vgablt_readw(addr + 2, priv) << 16); } return ret; @@ -3152,7 +3159,8 @@ gd54xx_get_pixel_width(gd54xx_t *gd54xx) static void gd54xx_blit(gd54xx_t *gd54xx, uint8_t mask, uint8_t *dst, uint8_t target, int skip) { - int is_transp, is_bgonly; + int is_transp; + int is_bgonly; /* skip indicates whether or not it is a pixel to be skipped (used for left skip); mask indicates transparency or not (only when transparent comparison is enabled): @@ -3204,10 +3212,16 @@ gd54xx_transparent_comp(gd54xx_t *gd54xx, uint32_t xx, uint8_t src) static void gd54xx_pattern_copy(gd54xx_t *gd54xx) { - uint8_t target, src, *dst; - int x, y, pattern_y, pattern_pitch; - uint32_t bitmask = 0, xx, pixel; - uint32_t srca, srca2, dsta; + uint8_t target; + uint8_t src; + uint8_t *dst; + int pattern_y; + int pattern_pitch; + uint32_t bitmask = 0; + uint32_t pixel; + uint32_t srca; + uint32_t srca2; + uint32_t dsta; svga_t *svga = &gd54xx->svga; pattern_pitch = gd54xx->blt.pixel_width << 3; @@ -3234,18 +3248,18 @@ gd54xx_pattern_copy(gd54xx_t *gd54xx) /* The boundary has to be equal to the size of the pattern. */ srca = (gd54xx->blt.src_addr & ~0x07) & svga->vram_mask; - for (y = 0; y <= gd54xx->blt.height; y++) { + for (uint16_t y = 0; y <= gd54xx->blt.height; y++) { /* Go to the correct pattern line. */ srca2 = srca + (pattern_y * pattern_pitch); pixel = 0; - for (x = 0; x <= gd54xx->blt.width; x += gd54xx->blt.pixel_width) { + for (uint16_t x = 0; x <= gd54xx->blt.width; x += gd54xx->blt.pixel_width) { if (gd54xx->blt.mode & CIRRUS_BLTMODE_COLOREXPAND) { if (gd54xx->blt.modeext & CIRRUS_BLTMODEEXT_SOLIDFILL) bitmask = 1; else bitmask = svga->vram[srca2 & svga->vram_mask] & (0x80 >> pixel); } - for (xx = 0; xx < gd54xx->blt.pixel_width; xx++) { + for (int xx = 0; xx < gd54xx->blt.pixel_width; xx++) { if (gd54xx->blt.mode & CIRRUS_BLTMODE_COLOREXPAND) src = gd54xx_color_expand(gd54xx, bitmask, xx); else { @@ -3280,9 +3294,12 @@ gd54xx_reset_blit(gd54xx_t *gd54xx) static void gd54xx_mem_sys_src(gd54xx_t *gd54xx, uint32_t cpu_dat, uint32_t count) { - uint8_t *dst, exp, target; + uint8_t *dst; + uint8_t exp; + uint8_t target; int mask_shift; - uint32_t byte_pos, bitmask = 0; + uint32_t byte_pos; + uint32_t bitmask = 0; svga_t *svga = &gd54xx->svga; gd54xx->blt.ms_is_dest = 0; @@ -3367,9 +3384,12 @@ gd54xx_mem_sys_src(gd54xx_t *gd54xx, uint32_t cpu_dat, uint32_t count) static void gd54xx_normal_blit(uint32_t count, gd54xx_t *gd54xx, svga_t *svga) { - uint8_t src = 0, dst; + uint8_t src = 0; + uint8_t dst; uint16_t width = gd54xx->blt.width; - int x_max = 0, shift = 0, mask = 0; + int x_max = 0; + int shift = 0; + int mask = 0; uint32_t src_addr = gd54xx->blt.src_addr; uint32_t dst_addr = gd54xx->blt.dst_addr; @@ -3537,9 +3557,9 @@ gd54xx_start_blit(uint32_t cpu_dat, uint32_t count, gd54xx_t *gd54xx, svga_t *sv } static uint8_t -cl_pci_read(int func, int addr, void *p) +cl_pci_read(int func, int addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ret = 0x00; @@ -3636,9 +3656,9 @@ cl_pci_read(int func, int addr, void *p) } static void -cl_pci_write(int func, int addr, uint8_t val, void *p) +cl_pci_write(int func, int addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint32_t byte; @@ -3704,17 +3724,17 @@ cl_pci_write(int func, int addr, uint8_t val, void *p) } static uint8_t -gd5428_mca_read(int port, void *p) +gd5428_mca_read(int port, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; return gd54xx->pos_regs[port & 7]; } static void -gd5428_mca_write(int port, uint8_t val, void *p) +gd5428_mca_write(int port, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (port < 0x102) return; @@ -3724,7 +3744,7 @@ gd5428_mca_write(int port, uint8_t val, void *p) } static uint8_t -gd5428_mca_feedb(void *p) +gd5428_mca_feedb(void *priv) { return 1; } @@ -3740,8 +3760,8 @@ gd54xx_reset(void *priv) memset(svga->gdcreg, 0x00, sizeof(svga->gdcreg)); svga->crtc[0] = 63; svga->crtc[6] = 255; - svga->dispontime = 1000ull << 32; - svga->dispofftime = 1000ull << 32; + svga->dispontime = 1000ULL << 32; + svga->dispofftime = 1000ULL << 32; svga->bpp = 8; io_removehandler(0x03c0, 0x0020, gd54xx_in, NULL, NULL, gd54xx_out, NULL, NULL, gd54xx); @@ -3810,7 +3830,8 @@ static void int id = info->local & 0xff; int vram; char *romfn = NULL; - char *romfn1 = NULL, *romfn2 = NULL; + char *romfn1 = NULL; + char *romfn2 = NULL; memset(gd54xx, 0, sizeof(gd54xx_t)); gd54xx->pci = !!(info->flags & DEVICE_PCI); @@ -3945,7 +3966,10 @@ static void } if (info->flags & DEVICE_MCA) { - vram = 1024; + if (id == CIRRUS_ID_CLGD5428) + vram = 1024; + else + vram = device_get_config_int("memory"); gd54xx->vram_size = vram << 10; } else { if (id <= CIRRUS_ID_CLGD5428) { @@ -4240,9 +4264,9 @@ gd5480_available(void) } void -gd54xx_close(void *p) +gd54xx_close(void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_close(&gd54xx->svga); @@ -4255,17 +4279,17 @@ gd54xx_close(void *p) } void -gd54xx_speed_changed(void *p) +gd54xx_speed_changed(void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_recalctimings(&gd54xx->svga); } void -gd54xx_force_redraw(void *p) +gd54xx_force_redraw(void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; gd54xx->svga.fullchange = gd54xx->svga.monitor->mon_changeframecount; } diff --git a/src/video/vid_colorplus.c b/src/video/vid_colorplus.c index ae24d8ff0..be176d9d0 100644 --- a/src/video/vid_colorplus.c +++ b/src/video/vid_colorplus.c @@ -34,6 +34,7 @@ #include <86box/vid_cga.h> #include <86box/vid_colorplus.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> /* Bits in the colorplus control register: */ #define COLORPLUS_PLANE_SWAP 0x40 /* Swap planes at 0000h and 4000h */ @@ -55,9 +56,9 @@ video_timings_t timing_colorplus = { .type = VIDEO_ISA, .write_b = 8, .write_w = void cga_recalctimings(cga_t *cga); void -colorplus_out(uint16_t addr, uint8_t val, void *p) +colorplus_out(uint16_t addr, uint8_t val, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; if (addr == 0x3DD) { colorplus->control = val & 0x70; @@ -67,17 +68,17 @@ colorplus_out(uint16_t addr, uint8_t val, void *p) } uint8_t -colorplus_in(uint16_t addr, void *p) +colorplus_in(uint16_t addr, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; return cga_in(addr, &colorplus->cga); } void -colorplus_write(uint32_t addr, uint8_t val, void *p) +colorplus_write(uint32_t addr, uint8_t val, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) { addr ^= 0x4000; @@ -94,9 +95,9 @@ colorplus_write(uint32_t addr, uint8_t val, void *p) } uint8_t -colorplus_read(uint32_t addr, void *p) +colorplus_read(uint32_t addr, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) { addr ^= 0x4000; @@ -119,12 +120,14 @@ colorplus_recalctimings(colorplus_t *colorplus) } void -colorplus_poll(void *p) +colorplus_poll(void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; - int x, c; + colorplus_t *colorplus = (colorplus_t *) priv; + int x; + int c; int oldvc; - uint16_t dat0, dat1; + uint16_t dat0; + uint16_t dat1; int cols[4]; int col; int oldsc; @@ -315,11 +318,11 @@ colorplus_poll(void *p) } if (colorplus->cga.cgadispon) colorplus->cga.cgastat &= ~1; - if ((colorplus->cga.sc == (colorplus->cga.crtc[10] & 31) || ((colorplus->cga.crtc[8] & 3) == 3 && colorplus->cga.sc == ((colorplus->cga.crtc[10] & 31) >> 1)))) + if (colorplus->cga.sc == (colorplus->cga.crtc[10] & 31) || ((colorplus->cga.crtc[8] & 3) == 3 && colorplus->cga.sc == ((colorplus->cga.crtc[10] & 31) >> 1))) colorplus->cga.con = 1; if (colorplus->cga.cgadispon && (colorplus->cga.cgamode & 1)) { for (x = 0; x < (colorplus->cga.crtc[1] << 1); x++) - colorplus->cga.charbuffer[x] = colorplus->cga.vram[(((colorplus->cga.ma << 1) + x) & 0x3fff)]; + colorplus->cga.charbuffer[x] = colorplus->cga.vram[((colorplus->cga.ma << 1) + x) & 0x3fff]; } } } @@ -331,7 +334,7 @@ colorplus_init(colorplus_t *colorplus) } void * -colorplus_standalone_init(const device_t *info) +colorplus_standalone_init(UNUSED(const device_t *info)) { int display_type; @@ -360,18 +363,18 @@ colorplus_standalone_init(const device_t *info) } void -colorplus_close(void *p) +colorplus_close(void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; free(colorplus->cga.vram); free(colorplus); } void -colorplus_speed_changed(void *p) +colorplus_speed_changed(void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; cga_recalctimings(&colorplus->cga); } diff --git a/src/video/vid_compaq_cga.c b/src/video/vid_compaq_cga.c index 68255e746..4753ec223 100644 --- a/src/video/vid_compaq_cga.c +++ b/src/video/vid_compaq_cga.c @@ -69,7 +69,9 @@ compaq_cga_log(const char *fmt, ...) void compaq_cga_recalctimings(compaq_cga_t *self) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; disptime = self->cga.crtc[0] + 1; _dispontime = self->cga.crtc[1]; @@ -81,14 +83,18 @@ compaq_cga_recalctimings(compaq_cga_t *self) } void -compaq_cga_poll(void *p) +compaq_cga_poll(void *priv) { - compaq_cga_t *self = (compaq_cga_t *) p; + compaq_cga_t *self = (compaq_cga_t *) priv; uint16_t ca = (self->cga.crtc[15] | (self->cga.crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int c; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint8_t border; uint8_t cols[4]; int oldsc; @@ -176,8 +182,8 @@ compaq_cga_poll(void *p) } } else { for (x = 0; x < self->cga.crtc[1]; x++) { - chr = self->cga.vram[((self->cga.ma << 1) & 0x3fff)]; - attr = self->cga.vram[(((self->cga.ma << 1) + 1) & 0x3fff)]; + chr = self->cga.vram[(self->cga.ma << 1) & 0x3fff]; + attr = self->cga.vram[((self->cga.ma << 1) + 1) & 0x3fff]; drawcursor = ((self->cga.ma == ca) && self->cga.con && self->cga.cursoron); if (vflags) { @@ -380,12 +386,12 @@ compaq_cga_poll(void *p) if (self->cga.cgadispon) self->cga.cgastat &= ~1; - if ((self->cga.sc == (self->cga.crtc[10] & 31) || ((self->cga.crtc[8] & 3) == 3 && self->cga.sc == ((self->cga.crtc[10] & 31) >> 1)))) + if (self->cga.sc == (self->cga.crtc[10] & 31) || ((self->cga.crtc[8] & 3) == 3 && self->cga.sc == ((self->cga.crtc[10] & 31) >> 1))) self->cga.con = 1; if (self->cga.cgadispon && (self->cga.cgamode & 1)) { for (x = 0; x < (self->cga.crtc[1] << 1); x++) - self->cga.charbuffer[x] = self->cga.vram[(((self->cga.ma << 1) + x) & 0x3fff)]; + self->cga.charbuffer[x] = self->cga.vram[((self->cga.ma << 1) + x) & 0x3fff]; } } } @@ -394,7 +400,6 @@ void * compaq_cga_init(const device_t *info) { int display_type; - int c; compaq_cga_t *self = malloc(sizeof(compaq_cga_t)); memset(self, 0, sizeof(compaq_cga_t)); @@ -411,7 +416,7 @@ compaq_cga_init(const device_t *info) io_sethandler(0x03d0, 0x0010, cga_in, NULL, NULL, cga_out, NULL, NULL, self); if (info->local) { - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { mdaattr[c][0][0] = mdaattr[c][1][0] = mdaattr[c][1][1] = 16; if (c & 8) mdaattr[c][0][1] = 15 + 16; @@ -447,18 +452,18 @@ compaq_cga_init(const device_t *info) } void -compaq_cga_close(void *p) +compaq_cga_close(void *priv) { - compaq_cga_t *self = (compaq_cga_t *) p; + compaq_cga_t *self = (compaq_cga_t *) priv; free(self->cga.vram); free(self); } void -compaq_cga_speed_changed(void *p) +compaq_cga_speed_changed(void *priv) { - compaq_cga_t *self = (compaq_cga_t *) p; + compaq_cga_t *self = (compaq_cga_t *) priv; if (self->cga.crtc[9] == 13) /* Character height */ compaq_cga_recalctimings(self); diff --git a/src/video/vid_ddc.c b/src/video/vid_ddc.c index f6c4d4dac..387edaeb8 100644 --- a/src/video/vid_ddc.c +++ b/src/video/vid_ddc.c @@ -24,7 +24,7 @@ #include <86box/86box.h> #include <86box/i2c.h> -#define PIXEL_MM(px) ((uint16_t) (((px) *25.4) / 96)) +#define PIXEL_MM(px) (((px) * 25.4) / 96.0) #define STANDARD_TIMING(slot, width, aspect_ratio, refresh) \ do { \ edid->slot.horiz_pixels = ((width) >> 3) - 31; \ @@ -44,9 +44,9 @@ edid->slot.h_sync_pulse_lsb = (hsp) &0xff; \ edid->slot.v_front_porch_sync_pulse_lsb = (((vfp) &0x0f) << 4) | ((vsp) &0x0f); \ edid->slot.hv_front_porch_sync_pulse_msb = (((hfp) >> 2) & 0xc0) | (((hsp) >> 4) & 0x30) | (((vfp) >> 2) & 0x0c) | (((vsp) >> 4) & 0x03); \ - edid->slot.h_size_lsb = horiz_mm & 0xff; \ - edid->slot.v_size_lsb = vert_mm & 0xff; \ - edid->slot.hv_size_msb = ((horiz_mm >> 4) & 0xf0) | ((vert_mm >> 8) & 0x0f); \ + edid->slot.h_size_lsb = (uint8_t) horiz_mm; \ + edid->slot.v_size_lsb = (uint8_t) vert_mm; \ + edid->slot.hv_size_msb = ((((uint16_t) horiz_mm) >> 4) & 0xf0) | ((((uint16_t) vert_mm) >> 8) & 0x0f); \ } while (0) enum { @@ -133,7 +133,8 @@ ddc_init(void *i2c) memset(edid, 0, sizeof(edid_t)); uint8_t *edid_bytes = (uint8_t *) edid; - uint16_t horiz_mm = PIXEL_MM(1366), vert_mm = PIXEL_MM(768); + double horiz_mm = PIXEL_MM(800); + double vert_mm = PIXEL_MM(600); memset(&edid->magic[1], 0xff, sizeof(edid->magic) - 2); @@ -142,11 +143,11 @@ ddc_init(void *i2c) edid->mfg_week = 48; edid->mfg_year = 2020 - 1990; edid->edid_version = 0x01; - edid->edid_rev = 0x03; /* EDID 1.3 */ + edid->edid_rev = 0x04; /* EDID 1.4, required for Xorg on Linux to use the preferred mode timing */ edid->input_params = 0x0e; /* analog input; separate sync; composite sync; sync on green */ - edid->horiz_size = horiz_mm / 10; - edid->vert_size = vert_mm / 10; + edid->horiz_size = round(horiz_mm / 10.0); + edid->vert_size = round(vert_mm / 10.0); edid->features = 0xeb; /* DPMS standby/suspend/active-off; RGB color; first timing is preferred; GTF/CVT */ edid->red_green_lsb = 0x81; diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index bfac7d503..babd45756 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -54,24 +54,27 @@ enum { static video_timings_t timing_ega = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; static uint8_t ega_rotate[8][256]; -static uint32_t pallook16[256], pallook64[256]; -static int ega_type = 0, old_overscan_color = 0; +static uint32_t pallook16[256]; +static uint32_t pallook64[256]; +static int ega_type = 0; +static int old_overscan_color = 0; -extern uint8_t edatlookup[4][4]; +uint8_t egaremap2bpp[256]; /* 3C2 controls default mode on EGA. On VGA, it determines monitor type (mono or colour): 7=CGA mode (200 lines), 9=EGA mode (350 lines), 8=EGA mode (200 lines). */ -int egaswitchread, egaswitches = 9; +int egaswitchread; +int egaswitches = 9; int update_overscan = 0; -uint8_t ega_in(uint16_t addr, void *p); +uint8_t ega_in(uint16_t addr, void *priv); void -ega_out(uint16_t addr, uint8_t val, void *p) +ega_out(uint16_t addr, uint8_t val, void *priv) { - ega_t *ega = (ega_t *) p; - int c; - uint8_t o, old; + ega_t *ega = (ega_t *) priv; + uint8_t o; + uint8_t old; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(ega->miscout & 1)) addr ^= 0x60; @@ -99,6 +102,9 @@ ega_out(uint16_t addr, uint8_t val, void *p) case 0xb3: ati_eeprom_write((ati_eeprom_t *) ega->eeprom, val & 8, val & 2, val & 1); break; + + default: + break; } break; @@ -117,7 +123,7 @@ ega_out(uint16_t addr, uint8_t val, void *p) if (ega->attraddr < 16) ega->fullchange = changeframecount; if (ega->attraddr == 0x10 || ega->attraddr == 0x14 || ega->attraddr < 0x10) { - for (c = 0; c < 16; c++) { + for (uint8_t c = 0; c < 16; c++) { if (ega->attrregs[0x10] & 0x80) ega->egapal[c] = (ega->attrregs[c] & 0xf) | ((ega->attrregs[0x14] & 0xf) << 4); else @@ -177,6 +183,9 @@ ega_out(uint16_t addr, uint8_t val, void *p) case 4: ega->chain2_write = !(val & 4); break; + + default: + break; } break; case 0x3ce: @@ -210,11 +219,17 @@ ega_out(uint16_t addr, uint8_t val, void *p) case 0xC: /*32k at B8000*/ mem_mapping_set_addr(&ega->mapping, 0xb8000, 0x08000); break; + + default: + break; } break; case 7: ega->colournocare = val; break; + + default: + break; } break; case 0x3d0: @@ -241,13 +256,16 @@ ega_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } } uint8_t -ega_in(uint16_t addr, void *p) +ega_in(uint16_t addr, void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; uint8_t ret = 0xff; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(ega->miscout & 1)) @@ -264,6 +282,7 @@ ega_in(uint16_t addr, void *p) if (ati_eeprom_read((ati_eeprom_t *) ega->eeprom)) ret |= 8; break; + default: ret = ega->regs[ega->index]; break; @@ -312,14 +331,34 @@ ega_in(uint16_t addr, void *p) break; case 0x3d1: case 0x3d5: - if (ega_type) - ret = ega->crtc[ega->crtcreg]; + switch (ega->crtcreg) { + case 0xc: + case 0xd: + case 0xe: + case 0xf: + ret = ega->crtc[ega->crtcreg]; + break; + + case 0x10: + case 0x11: + // TODO: Return light pen address once implemented + if (ega_type) + ret = ega->crtc[ega->crtcreg]; + break; + + default: + if (ega_type) + ret = ega->crtc[ega->crtcreg]; + } break; case 0x3da: ega->attrff = 0; ega->stat ^= 0x30; /*Fools IBM EGA video BIOS self-test*/ ret = ega->stat; break; + + default: + break; } return ret; @@ -330,7 +369,9 @@ ega_recalctimings(ega_t *ega) { int clksel; - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; double crtcconst; ega->vtotal = ega->crtc[6]; @@ -375,20 +416,20 @@ ega_recalctimings(ega_t *ega) switch (clksel) { case 0: - crtcconst = (cpuclock / 25175000.0 * (double) (1ull << 32)); + crtcconst = (cpuclock / 25175000.0 * (double) (1ULL << 32)); break; case 1: - crtcconst = (cpuclock / 28322000.0 * (double) (1ull << 32)); + crtcconst = (cpuclock / 28322000.0 * (double) (1ULL << 32)); break; case 4: - crtcconst = (cpuclock / 14318181.0 * (double) (1ull << 32)); + crtcconst = (cpuclock / 14318181.0 * (double) (1ULL << 32)); break; case 5: - crtcconst = (cpuclock / 16257000.0 * (double) (1ull << 32)); + crtcconst = (cpuclock / 16257000.0 * (double) (1ULL << 32)); break; case 7: default: - crtcconst = (cpuclock / 36000000.0 * (double) (1ull << 32)); + crtcconst = (cpuclock / 36000000.0 * (double) (1ULL << 32)); break; } if (!(ega->seqregs[1] & 1)) @@ -409,32 +450,16 @@ ega_recalctimings(ega_t *ega) ega->render = ega_render_blank; if (!ega->scrblank && ega->attr_palette_enable) { if (!(ega->gdcreg[6] & 1)) { - if (ega->seqregs[1] & 8) { - ega->render = ega_render_text_40; + if (ega->seqregs[1] & 8) ega->hdisp *= (ega->seqregs[1] & 1) ? 16 : 18; - } else { - ega->render = ega_render_text_80; + else ega->hdisp *= (ega->seqregs[1] & 1) ? 8 : 9; - } + ega->render = ega_render_text; ega->hdisp_old = ega->hdisp; } else { ega->hdisp *= (ega->seqregs[1] & 8) ? 16 : 8; + ega->render = ega_render_graphics; ega->hdisp_old = ega->hdisp; - - switch (ega->gdcreg[5] & 0x20) { - case 0x00: - if (ega->seqregs[1] & 8) - ega->render = ega_render_4bpp_lowres; - else - ega->render = ega_render_4bpp_highres; - break; - case 0x20: - if (ega->seqregs[1] & 8) - ega->render = ega_render_2bpp_lowres; - else - ega->render = ega_render_2bpp_highres; - break; - } } } @@ -475,11 +500,13 @@ ega_recalctimings(ega_t *ega) } void -ega_poll(void *p) +ega_poll(void *priv) { - ega_t *ega = (ega_t *) p; - int x, old_ma; - int wx = 640, wy = 350; + ega_t *ega = (ega_t *) priv; + int x; + int old_ma; + int wx = 640; + int wy = 350; uint32_t blink_delay; if (!ega->linepos) { @@ -574,10 +601,11 @@ ega_poll(void *p) ega->vc++; ega->vc &= 511; if (ega->vc == ega->split) { + // TODO: Implement the hardware bug where the first scanline is drawn twice when the split happens if (ega->interlace && ega->oddeven) - ega->ma = ega->maback = ega->ma_latch + (ega->rowoffset << 1); + ega->ma = ega->maback = ega->rowoffset << 1; else - ega->ma = ega->maback = ega->ma_latch; + ega->ma = ega->maback = 0; ega->ma <<= 2; ega->maback <<= 2; ega->sc = 0; @@ -679,14 +707,16 @@ ega_poll(void *p) void ega_doblit(int wx, int wy, ega_t *ega) { - int y_add = (enable_overscan) ? overscan_y : 0; - int x_add = (enable_overscan) ? overscan_x : 0; - int y_start = (enable_overscan) ? 0 : (overscan_y >> 1); - int x_start = (enable_overscan) ? 0 : (overscan_x >> 1); + int y_add = enable_overscan ? overscan_y : 0; + int x_add = enable_overscan ? overscan_x : 0; + int y_start = enable_overscan ? 0 : (overscan_y >> 1); + int x_start = enable_overscan ? 0 : (overscan_x >> 1); int bottom = (overscan_y >> 1) + (ega->crtc[8] & 0x1f); uint32_t *p; - int i, j; - int xs_temp, ys_temp; + int i; + int j; + int xs_temp; + int ys_temp; if (ega->vres) { y_add <<= 1; @@ -752,30 +782,99 @@ ega_doblit(int wx, int wy, ega_t *ega) ega->y_add >>= 1; } -void -ega_write(uint32_t addr, uint8_t val, void *p) +uint32_t +ega_remap_cpu_addr(uint32_t inaddr, ega_t *ega) { - ega_t *ega = (ega_t *) p; - uint8_t vala, valb, valc, vald; + int a0mux; + uint32_t addr = inaddr; + + // The CPU A0 line is multiplexed via a 3-to-8 mux. + // Input bits are: + // bit 0: 1 = 64K, 0 = 128K+ (from memory expansion connector) + // bit 1: 1 = Odd/Even mode, 0 = normal mode (from GC reg 6 bit 1) + // bit 2: 1 = 128K mapping, 0 = other mapping (from memory decode PROM) + a0mux = 0; + + if (ega->gdcreg[6] & 2) { + a0mux |= 2; + } + if (ega->vram_limit <= 64 * 1024) { + a0mux |= 1; + } + + switch (ega->gdcreg[6] & 0xC) { + case 0x0: // 128K A000 + addr &= 0xFFFF; + // TODO: Confirm the behaviour of this on actual hardware + a0mux |= 4; + break; + case 0x4: // 64K A000 + addr &= 0xFFFF; + break; + case 0x8: // 32K B000 + addr &= 0x7FFF; + break; + case 0xC: // 32K B800 + addr &= 0x7FFF; + break; + + default: + break; + } + + switch (a0mux) { + case 0: + case 1: + case 4: + case 5: + case 7: // A0 becomes A0 + break; + case 2: + // A0 becomes the inversion of PGSEL (reg 0x3C2, miscout, bit 5) + // That is, 1 selects the "low" 64k, and 0 selects the "high" 64k. + addr &= ~1; + addr |= (~ega->miscout >> 5) & 1; + break; + case 3: // A0 becomes A14 + addr &= ~1; + addr |= (inaddr >> 14) & 1; + break; + case 6: // A0 becomes A16 + addr &= ~1; + addr |= (inaddr >> 16) & 1; + break; + + default: + break; + } + + // In 64k mode, only select the first 16Kword/64KB bank + if (!(ega->seqregs[4] & 2)) { + addr &= 0x3FFF; + } + return addr; +} + +void +ega_write(uint32_t addr, uint8_t val, void *priv) +{ + ega_t *ega = (ega_t *) priv; + uint8_t vala; + uint8_t valb; + uint8_t valc; + uint8_t vald; int writemask2 = ega->writemask; cycles -= video_timing_write_b; - if (addr >= 0xB0000) - addr &= 0x7fff; - else - addr &= 0xffff; - if (ega->chain2_write) { writemask2 &= ~0xa; if (addr & 1) writemask2 <<= 1; - addr &= ~1; - if (addr & 0x4000) - addr |= 1; - addr &= ~0x4000; } + addr = ega_remap_cpu_addr(addr, ega); + addr <<= 2; if (addr >= ega->vram_limit) @@ -866,6 +965,9 @@ ega_write(uint32_t addr, uint8_t val, void *p) if (writemask2 & 8) ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) ^ ega->ld; break; + + default: + break; } } break; @@ -925,33 +1027,36 @@ ega_write(uint32_t addr, uint8_t val, void *p) if (writemask2 & 8) ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) ^ ega->ld; break; + + default: + break; } } break; + + default: + break; } } uint8_t -ega_read(uint32_t addr, void *p) +ega_read(uint32_t addr, void *priv) { - ega_t *ega = (ega_t *) p; - uint8_t temp, temp2, temp3, temp4; + ega_t *ega = (ega_t *) priv; + uint8_t temp; + uint8_t temp2; + uint8_t temp3; + uint8_t temp4; int readplane = ega->readplane; cycles -= video_timing_read_b; - if (addr >= 0xb0000) - addr &= 0x7fff; - else - addr &= 0xffff; if (ega->chain2_read) { readplane = (readplane & 2) | (addr & 1); - addr &= ~1; - if (addr & 0x4000) - addr |= 1; - addr &= ~0x4000; } + addr = ega_remap_cpu_addr(addr, ega); + addr <<= 2; if (addr >= ega->vram_limit) @@ -982,7 +1087,9 @@ ega_read(uint32_t addr, void *p) void ega_init(ega_t *ega, int monitor_type, int is_mono) { - int c, d, e; + int c; + int d; + int e; ega->vram = malloc(0x40000); ega->vrammask = 0x3ffff; @@ -1009,6 +1116,18 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) } } + for (c = 0; c < 256; c++) { + egaremap2bpp[c] = 0; + if (c & 0x01) + egaremap2bpp[c] |= 0x01; + if (c & 0x04) + egaremap2bpp[c] |= 0x02; + if (c & 0x10) + egaremap2bpp[c] |= 0x04; + if (c & 0x40) + egaremap2bpp[c] |= 0x08; + } + if (is_mono) { for (c = 0; c < 256; c++) { if (((c >> 3) & 3) == 0) @@ -1026,6 +1145,9 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) case 3: pallook64[c] = pallook16[c] = makecol32(0x34, 0xff, 0x5d); break; + + default: + break; } break; case DISPLAY_AMBER: @@ -1039,6 +1161,9 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) case 3: pallook64[c] = pallook16[c] = makecol32(0xff, 0xe3, 0x34); break; + + default: + break; } break; case DISPLAY_WHITE: @@ -1053,6 +1178,9 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) case 3: pallook64[c] = pallook16[c] = makecol32(0xff, 0xfd, 0xed); break; + + default: + break; } break; } @@ -1099,7 +1227,7 @@ static void * ega_standalone_init(const device_t *info) { ega_t *ega = malloc(sizeof(ega_t)); - int monitor_type, c; + int monitor_type; memset(ega, 0, sizeof(ega_t)); @@ -1116,8 +1244,8 @@ ega_standalone_init(const device_t *info) ega_type = 1; switch (info->local) { - case EGA_IBM: default: + case EGA_IBM: rom_init(&ega->bios_rom, BIOS_IBM_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); break; @@ -1144,7 +1272,7 @@ ega_standalone_init(const device_t *info) } if ((ega->bios_rom.rom[0x3ffe] == 0xaa) && (ega->bios_rom.rom[0x3fff] == 0x55)) { - for (c = 0; c < 0x2000; c++) { + for (uint16_t c = 0; c < 0x2000; c++) { uint8_t temp = ega->bios_rom.rom[c]; ega->bios_rom.rom[c] = ega->bios_rom.rom[0x3fff - c]; ega->bios_rom.rom[0x3fff - c] = temp; @@ -1207,9 +1335,9 @@ et2000_standalone_available(void) } static void -ega_close(void *p) +ega_close(void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; if (ega->eeprom) free(ega->eeprom); @@ -1218,9 +1346,9 @@ ega_close(void *p) } static void -ega_speed_changed(void *p) +ega_speed_changed(void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; ega_recalctimings(ega); } diff --git a/src/video/vid_ega_render.c b/src/video/vid_ega_render.c index b2d5cb5c1..2d15d6dc5 100644 --- a/src/video/vid_ega_render.c +++ b/src/video/vid_ega_render.c @@ -18,6 +18,7 @@ */ #include #include +#include #include #include #include <86box/86box.h> @@ -32,7 +33,7 @@ int ega_display_line(ega_t *ega) { - int y_add = (enable_overscan) ? (overscan_y >> 1) : 0; + int y_add = enable_overscan ? (overscan_y >> 1) : 0; unsigned int dl = ega->displine; if (ega->crtc[9] & 0x1f) @@ -46,29 +47,30 @@ ega_display_line(ega_t *ega) void ega_render_blank(ega_t *ega) { - int x, xx; - if ((ega->displine + ega->y_add) < 0) return; - for (x = 0; x < (ega->hdisp + ega->scrollcache); x++) { + for (int x = 0; x < (ega->hdisp + ega->scrollcache); x++) { switch (ega->seqregs[1] & 9) { case 0: - for (xx = 0; xx < 9; xx++) + for (uint8_t xx = 0; xx < 9; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 9) + xx] = 0; break; case 1: - for (xx = 0; xx < 8; xx++) + for (uint8_t xx = 0; xx < 8; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 8) + xx] = 0; break; case 8: - for (xx = 0; xx < 18; xx++) + for (uint8_t xx = 0; xx < 18; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 18) + xx] = 0; break; case 9: - for (xx = 0; xx < 16; xx++) + for (uint8_t xx = 0; xx < 16; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 16) + xx] = 0; break; + + default: + break; } } } @@ -76,22 +78,20 @@ ega_render_blank(ega_t *ega) void ega_render_overscan_left(ega_t *ega) { - int i; - if ((ega->displine + ega->y_add) < 0) return; if (ega->scrblank || (ega->hdisp == 0)) return; - for (i = 0; i < ega->x_add; i++) + for (int i = 0; i < ega->x_add; i++) buffer32->line[ega->displine + ega->y_add][i] = ega->overscan_color; } void ega_render_overscan_right(ega_t *ega) { - int i, right; + int right; if ((ega->displine + ega->y_add) < 0) return; @@ -100,21 +100,13 @@ ega_render_overscan_right(ega_t *ega) return; right = (overscan_x >> 1) + ega->scrollcache; - for (i = 0; i < right; i++) + for (int i = 0; i < right; i++) buffer32->line[ega->displine + ega->y_add][ega->x_add + ega->hdisp + i] = ega->overscan_color; } void -ega_render_text_40(ega_t *ega) +ega_render_text(ega_t *ega) { - uint32_t *p; - int x, xx; - int drawcursor, xinc; - uint8_t chr, attr, dat; - uint32_t charaddr; - int fg, bg; - uint32_t addr; - if ((ega->displine + ega->y_add) < 0) return; @@ -123,316 +115,137 @@ ega_render_text_40(ega_t *ega) ega->lastline_draw = ega->displine; if (ega->fullchange) { - p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - xinc = (ega->seqregs[1] & 1) ? 16 : 18; + const bool doublewidth = ((ega->seqregs[1] & 8) != 0); + const bool attrblink = ((ega->attrregs[0x10] & 8) != 0); + const bool attrlinechars = (ega->attrregs[0x10] & 4); + const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0); + const bool seq9dot = ((ega->seqregs[1] & 1) == 0); + const int dwshift = doublewidth ? 1 : 0; + const int dotwidth = 1 << dwshift; + const int charwidth = dotwidth * (seq9dot ? 9 : 8); + const bool blinked = ega->blink & 0x10; + uint32_t *p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - for (x = 0; x < (ega->hdisp + ega->scrollcache); x += xinc) { - addr = ega->remap_func(ega, ega->ma) & ega->vrammask; + for (int x = 0; x < (ega->hdisp + ega->scrollcache); x += charwidth) { + uint32_t addr = ega->remap_func(ega, ega->ma) & ega->vrammask; - drawcursor = ((ega->ma == ega->ca) && ega->con && ega->cursoron); + int drawcursor = ((ega->ma == ega->ca) && ega->con && ega->cursoron); - if (ega->crtc[0x17] & 0x80) { + uint32_t chr; + uint32_t attr; + if (!crtcreset) { chr = ega->vram[addr]; attr = ega->vram[addr + 1]; } else chr = attr = 0; + uint32_t charaddr; if (attr & 8) - charaddr = ega->charsetb + ((chr * 0x80)); - else - charaddr = ega->charseta + ((chr * 0x80)); - - if (drawcursor) { - bg = ega->pallook[ega->egapal[attr & 0x0f]]; - fg = ega->pallook[ega->egapal[attr >> 4]]; - } else { - fg = ega->pallook[ega->egapal[attr & 0x0f]]; - bg = ega->pallook[ega->egapal[attr >> 4]]; - - if ((attr & 0x80) && ega->attrregs[0x10] & 8) { - bg = ega->pallook[ega->egapal[(attr >> 4) & 7]]; - if (ega->blink & 0x10) - fg = bg; - } - } - - dat = ega->vram[charaddr + (ega->sc << 2)]; - if (ega->seqregs[1] & 1) { - for (xx = 0; xx < 16; xx += 2) - p[xx] = p[xx + 1] = (dat & (0x80 >> (xx >> 1))) ? fg : bg; - } else { - for (xx = 0; xx < 16; xx += 2) - p[xx] = p[xx + 1] = (dat & (0x80 >> (xx >> 1))) ? fg : bg; - if ((chr & ~0x1f) != 0xc0 || !(ega->attrregs[0x10] & 4)) - p[16] = p[17] = bg; - else - p[16] = p[17] = (dat & 1) ? fg : bg; - } - ega->ma += 4; - p += xinc; - } - ega->ma &= ega->vrammask; - } -} - -void -ega_render_text_80(ega_t *ega) -{ - uint32_t *p; - int x, xx; - int drawcursor, xinc; - uint8_t chr, attr, dat; - uint32_t charaddr; - int fg, bg; - uint32_t addr; - - if ((ega->displine + ega->y_add) < 0) - return; - - if (ega->firstline_draw == 2000) - ega->firstline_draw = ega->displine; - ega->lastline_draw = ega->displine; - - if (ega->fullchange) { - p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - xinc = (ega->seqregs[1] & 1) ? 8 : 9; - - for (x = 0; x < (ega->hdisp + ega->scrollcache); x += xinc) { - addr = ega->remap_func(ega, ega->ma) & ega->vrammask; - - drawcursor = ((ega->ma == ega->ca) && ega->con && ega->cursoron); - - if (ega->crtc[0x17] & 0x80) { - chr = ega->vram[addr]; - attr = ega->vram[addr + 1]; - } else - chr = attr = 0; - - if (attr & 0x08) charaddr = ega->charsetb + (chr * 0x80); else charaddr = ega->charseta + (chr * 0x80); + int fg; + int bg; if (drawcursor) { bg = ega->pallook[ega->egapal[attr & 0x0f]]; fg = ega->pallook[ega->egapal[attr >> 4]]; } else { fg = ega->pallook[ega->egapal[attr & 0x0f]]; bg = ega->pallook[ega->egapal[attr >> 4]]; - if ((attr & 0x80) && ega->attrregs[0x10] & 8) { + + if ((attr & 0x80) && attrblink) { bg = ega->pallook[ega->egapal[(attr >> 4) & 7]]; - if (ega->blink & 16) + if (blinked) fg = bg; } } - dat = ega->vram[charaddr + (ega->sc << 2)]; - if (ega->seqregs[1] & 1) { - for (xx = 0; xx < 8; xx++) - p[xx] = (dat & (0x80 >> xx)) ? fg : bg; - } else { - for (xx = 0; xx < 8; xx++) - p[xx] = (dat & (0x80 >> xx)) ? fg : bg; - if ((chr & ~0x1F) != 0xC0 || !(ega->attrregs[0x10] & 4)) - p[8] = bg; - else - p[8] = (dat & 1) ? fg : bg; + uint32_t dat = ega->vram[charaddr + (ega->sc << 2)]; + dat <<= 1; + if ((chr & ~0x1F) == 0xC0 && attrlinechars) + dat |= (dat >> 1) & 1; + + for (int xx = 0; xx < charwidth; xx++) + p[xx] = (dat & (0x100 >> (xx >> dwshift))) ? fg : bg; + + ega->ma += 4; + p += charwidth; + } + ega->ma &= 0x3ffff; + } +} + +void +ega_render_graphics(ega_t *ega) +{ + if ((ega->displine + ega->y_add) < 0) + return; + + if (ega->firstline_draw == 2000) + ega->firstline_draw = ega->displine; + ega->lastline_draw = ega->displine; + + const bool doublewidth = ((ega->seqregs[1] & 8) != 0); + const bool cga2bpp = ((ega->gdcreg[5] & 0x20) != 0); + const bool attrblink = ((ega->attrregs[0x10] & 8) != 0); + const bool blinked = ega->blink & 0x10; + const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0); + const bool seqoddeven = ((ega->seqregs[1] & 4) != 0); + const uint8_t blinkmask = (attrblink && blinked ? 0x8 : 0x0); + uint32_t *p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; + const int dwshift = doublewidth ? 1 : 0; + const int dotwidth = 1 << dwshift; + const int charwidth = dotwidth * 8; + int secondcclk = 0; + for (int x = 0; x <= (ega->hdisp + ega->scrollcache); x += charwidth) { + uint32_t addr = ega->remap_func(ega, ega->ma) & ega->vrammask; + + uint8_t edat[4]; + if (seqoddeven) { + // FIXME: Verify the behaviour of planes 1,3 on actual hardware + edat[0] = ega->vram[(addr | 0) ^ secondcclk]; + edat[1] = ega->vram[(addr | 1) ^ secondcclk]; + edat[2] = ega->vram[(addr | 2) ^ secondcclk]; + edat[3] = ega->vram[(addr | 3) ^ secondcclk]; + secondcclk = (secondcclk + 1) & 1; + if (secondcclk == 0) + ega->ma += 4; + } else { + *(uint32_t *) (&edat[0]) = *(uint32_t *) (&ega->vram[addr]); + ega->ma += 4; + } + ega->ma &= 0x3ffff; + + if (cga2bpp) { + // Remap CGA 2bpp-chunky data into fully planar data + uint8_t dat0 = egaremap2bpp[edat[1]] | (egaremap2bpp[edat[0]] << 4); + uint8_t dat1 = egaremap2bpp[edat[1] >> 1] | (egaremap2bpp[edat[0] >> 1] << 4); + uint8_t dat2 = egaremap2bpp[edat[3]] | (egaremap2bpp[edat[2]] << 4); + uint8_t dat3 = egaremap2bpp[edat[3] >> 1] | (egaremap2bpp[edat[2] >> 1] << 4); + edat[0] = dat0; + edat[1] = dat1; + edat[2] = dat2; + edat[3] = dat3; + } + + if (!crtcreset) { + for (int i = 0; i < 8; i += 2) { + const int outoffs = i << dwshift; + const int inshift = 6 - i; + uint8_t dat = (edatlookup[(edat[0] >> inshift) & 3][(edat[1] >> inshift) & 3]) + | (edatlookup[(edat[2] >> inshift) & 3][(edat[3] >> inshift) & 3] << 2); + // FIXME: Confirm blink behaviour is actually XOR on real hardware + uint32_t p0 = ega->pallook[ega->egapal[((dat >> 4) & ega->plane_mask) ^ blinkmask]]; + uint32_t p1 = ega->pallook[ega->egapal[(dat & ega->plane_mask) ^ blinkmask]]; + for (int subx = 0; subx < dotwidth; subx++) + p[outoffs + subx] = p0; + for (int subx = 0; subx < dotwidth; subx++) + p[outoffs + subx + dotwidth] = p1; } - ega->ma += 4; - p += xinc; - } - ega->ma &= ega->vrammask; - } -} - -void -ega_render_2bpp_lowres(ega_t *ega) -{ - int x; - uint8_t dat[2]; - uint32_t addr, *p; - - if ((ega->displine + ega->y_add) < 0) - return; - - p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - - if (ega->firstline_draw == 2000) - ega->firstline_draw = ega->displine; - ega->lastline_draw = ega->displine; - - for (x = 0; x <= (ega->hdisp + ega->scrollcache); x += 16) { - addr = ega->remap_func(ega, ega->ma); - - dat[0] = ega->vram[addr]; - dat[1] = ega->vram[addr | 0x1]; - if (ega->seqregs[1] & 4) - ega->ma += 2; - else - ega->ma += 4; - - ega->ma &= ega->vrammask; - - if (ega->crtc[0x17] & 0x80) { - p[0] = p[1] = ega->pallook[ega->egapal[(dat[0] >> 6) & 3]]; - p[2] = p[3] = ega->pallook[ega->egapal[(dat[0] >> 4) & 3]]; - p[4] = p[5] = ega->pallook[ega->egapal[(dat[0] >> 2) & 3]]; - p[6] = p[7] = ega->pallook[ega->egapal[dat[0] & 3]]; - p[8] = p[9] = ega->pallook[ega->egapal[(dat[1] >> 6) & 3]]; - p[10] = p[11] = ega->pallook[ega->egapal[(dat[1] >> 4) & 3]]; - p[12] = p[13] = ega->pallook[ega->egapal[(dat[1] >> 2) & 3]]; - p[14] = p[15] = ega->pallook[ega->egapal[dat[1] & 3]]; } else - memset(p, 0x00, 16 * sizeof(uint32_t)); + memset(p, 0x00, charwidth * sizeof(uint32_t)); - p += 16; - } -} - -void -ega_render_2bpp_highres(ega_t *ega) -{ - int x; - uint8_t dat[2]; - uint32_t addr, *p; - - if ((ega->displine + ega->y_add) < 0) - return; - - p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - - if (ega->firstline_draw == 2000) - ega->firstline_draw = ega->displine; - ega->lastline_draw = ega->displine; - - for (x = 0; x <= (ega->hdisp + ega->scrollcache); x += 8) { - addr = ega->remap_func(ega, ega->ma); - - dat[0] = ega->vram[addr]; - dat[1] = ega->vram[addr | 0x1]; - if (ega->seqregs[1] & 4) - ega->ma += 2; - else - ega->ma += 4; - - ega->ma &= ega->vrammask; - - if (ega->crtc[0x17] & 0x80) { - p[0] = ega->pallook[ega->egapal[(dat[0] >> 6) & 3]]; - p[1] = ega->pallook[ega->egapal[(dat[0] >> 4) & 3]]; - p[2] = ega->pallook[ega->egapal[(dat[0] >> 2) & 3]]; - p[3] = ega->pallook[ega->egapal[dat[0] & 3]]; - p[4] = ega->pallook[ega->egapal[(dat[1] >> 6) & 3]]; - p[5] = ega->pallook[ega->egapal[(dat[1] >> 4) & 3]]; - p[6] = ega->pallook[ega->egapal[(dat[1] >> 2) & 3]]; - p[7] = ega->pallook[ega->egapal[dat[1] & 3]]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); - - p += 8; - } -} - -void -ega_render_4bpp_lowres(ega_t *ega) -{ - int x, oddeven; - uint8_t dat, edat[4]; - uint32_t addr, *p; - - if ((ega->displine + ega->y_add) < 0) - return; - - p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - - if (ega->firstline_draw == 2000) - ega->firstline_draw = ega->displine; - ega->lastline_draw = ega->displine; - - for (x = 0; x <= (ega->hdisp + ega->scrollcache); x += 16) { - addr = ega->remap_func(ega, ega->ma); - oddeven = 0; - - if (ega->seqregs[1] & 4) { - oddeven = (addr & 4) ? 1 : 0; - edat[0] = ega->vram[addr | oddeven]; - edat[2] = ega->vram[addr | oddeven | 0x2]; - edat[1] = edat[3] = 0; - ega->ma += 2; - } else { - *(uint32_t *) (&edat[0]) = *(uint32_t *) (&ega->vram[addr]); - ega->ma += 4; - } - ega->ma &= ega->vrammask; - - if (ega->crtc[0x17] & 0x80) { - dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); - p[0] = p[1] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[2] = p[3] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); - p[4] = p[5] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[6] = p[7] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); - p[8] = p[9] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[10] = p[11] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); - p[12] = p[13] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[14] = p[15] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - } else - memset(p, 0x00, 16 * sizeof(uint32_t)); - - p += 16; - } -} - -void -ega_render_4bpp_highres(ega_t *ega) -{ - int x, oddeven; - uint8_t dat, edat[4]; - uint32_t addr, *p; - - if ((ega->displine + ega->y_add) < 0) - return; - - p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - - if (ega->firstline_draw == 2000) - ega->firstline_draw = ega->displine; - ega->lastline_draw = ega->displine; - - for (x = 0; x <= (ega->hdisp + ega->scrollcache); x += 8) { - addr = ega->remap_func(ega, ega->ma); - oddeven = 0; - - if (ega->seqregs[1] & 4) { - oddeven = (addr & 4) ? 1 : 0; - edat[0] = ega->vram[addr | oddeven]; - edat[2] = ega->vram[addr | oddeven | 0x2]; - edat[1] = edat[3] = 0; - ega->ma += 2; - } else { - *(uint32_t *) (&edat[0]) = *(uint32_t *) (&ega->vram[addr]); - ega->ma += 4; - } - ega->ma &= ega->vrammask; - - if (ega->crtc[0x17] & 0x80) { - dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); - p[0] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[1] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); - p[2] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[3] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); - p[4] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[5] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); - p[6] = ega->pallook[ega->egapal[(dat >> 4) & ega->plane_mask]]; - p[7] = ega->pallook[ega->egapal[dat & ega->plane_mask]]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); - - p += 8; + p += charwidth; } } diff --git a/src/video/vid_et3000.c b/src/video/vid_et3000.c index d107afe5c..e1290cd99 100644 --- a/src/video/vid_et3000.c +++ b/src/video/vid_et3000.c @@ -66,6 +66,9 @@ et3000_in(uint16_t addr, void *priv) case 0x3d5: return svga->crtc[svga->crtcreg]; + + default: + break; } return svga_in(addr, svga); @@ -124,6 +127,9 @@ et3000_out(uint16_t addr, uint8_t val, void *priv) svga->write_bank = (val & 7) << 16; svga->read_bank = ((val >> 3) & 7) << 16; break; + + default: + break; } } return; @@ -147,6 +153,9 @@ et3000_out(uint16_t addr, uint8_t val, void *priv) } } break; + + default: + break; } svga_out(addr, val, svga); @@ -184,24 +193,29 @@ et3000_recalctimings(svga_t *svga) case 0x60: svga->render = svga_render_8bpp_highres; break; + + default: + break; } } - /* pclog("HDISP = %i, HTOTAL = %i, ROWOFFSET = %i, INTERLACE = %i\n", - svga->hdisp, svga->htotal, svga->rowoffset, svga->interlace); */ +#if 0 + pclog("HDISP = %i, HTOTAL = %i, ROWOFFSET = %i, INTERLACE = %i\n", + svga->hdisp, svga->htotal, svga->rowoffset, svga->interlace); +#endif switch (((svga->miscout >> 2) & 3) | ((svga->crtc[0x24] << 1) & 4)) { case 0: case 1: break; case 3: - svga->clock = (cpuclock * (double) (1ull << 32)) / 40000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 40000000.0; break; case 5: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; break; default: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; } } @@ -227,6 +241,9 @@ et3000_init(const device_t *info) io_sethandler(0x03c0, 32, et3000_in, NULL, NULL, et3000_out, NULL, NULL, dev); break; + + default: + break; } rom_init(&dev->bios_rom, (char *) fn, @@ -237,7 +254,7 @@ et3000_init(const device_t *info) dev->svga.packed_chain4 = 1; - return (dev); + return dev; } static void diff --git a/src/video/vid_et4000.c b/src/video/vid_et4000.c index 4020c0523..a97d65cdb 100644 --- a/src/video/vid_et4000.c +++ b/src/video/vid_et4000.c @@ -52,6 +52,8 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #define ET4000_TYPE_ISA 1 /* ISA ET4000AX */ #define ET4000_TYPE_MCA 2 /* MCA ET4000AX */ @@ -105,8 +107,8 @@ static const uint8_t crtc_mask[0x40] = { static video_timings_t timing_et4000_isa = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; static video_timings_t timing_et4000_mca = { .type = VIDEO_MCA, .write_b = 4, .write_w = 5, .write_l = 10, .read_b = 5, .read_w = 5, .read_l = 10 }; -static void et4000_kasan_out(uint16_t addr, uint8_t val, void *p); -static uint8_t et4000_kasan_in(uint16_t addr, void *p); +static void et4000_kasan_out(uint16_t addr, uint8_t val, void *priv); +static uint8_t et4000_kasan_in(uint16_t addr, void *priv); static uint8_t et4000_in(uint16_t addr, void *priv) @@ -146,6 +148,9 @@ et4000_in(uint16_t addr, void *priv) case 0x3d5: return svga->crtc[svga->crtcreg]; + + default: + break; } return svga_in(addr, svga); @@ -288,6 +293,9 @@ et4000_out(uint16_t addr, uint8_t val, void *priv) } } break; + + default: + break; } svga_out(addr, val, svga); @@ -425,6 +433,9 @@ et4000_kasan_out(uint16_t addr, uint8_t val, void *priv) case 5: et4000->kasan_cfg_regs[5] = val; et4000->svga.ksc5601_english_font_type = 0x100 | val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 6: case 7: et4000->svga.ksc5601_udc_area_msb[et4000->kasan_cfg_index - 0xF6] = val; @@ -474,9 +485,9 @@ et4000_kasan_out(uint16_t addr, uint8_t val, void *priv) } uint32_t -get_et4000_addr(uint32_t addr, void *p) +get_et4000_addr(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; uint32_t nbank; switch (svga->crtc[0x37] & 0x0B) { @@ -536,7 +547,7 @@ get_et4000_addr(uint32_t addr, void *p) static void et4000_recalctimings(svga_t *svga) { - et4000_t *dev = (et4000_t *) svga->p; + et4000_t *dev = (et4000_t *) svga->priv; svga->ma_latch |= (svga->crtc[0x33] & 3) << 16; if (svga->crtc[0x35] & 1) @@ -561,13 +572,13 @@ et4000_recalctimings(svga_t *svga) case 1: break; case 3: - svga->clock = (cpuclock * (double) (1ull << 32)) / 40000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 40000000.0; break; case 5: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; break; default: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; } @@ -580,6 +591,9 @@ et4000_recalctimings(svga_t *svga) case 24: svga->hdisp /= 3; break; + + default: + break; } if (dev->type == ET4000_TYPE_KOREAN || dev->type == ET4000_TYPE_TRIGEM || dev->type == ET4000_TYPE_KASAN) { @@ -598,7 +612,7 @@ et4000_recalctimings(svga_t *svga) static void et4000_kasan_recalctimings(svga_t *svga) { - et4000_t *et4000 = (et4000_t *) svga->p; + et4000_t *et4000 = (et4000_t *) svga->priv; et4000_recalctimings(svga); @@ -633,7 +647,7 @@ et4000_mca_write(int port, uint8_t val, void *priv) } static uint8_t -et4000_mca_feedb(void *priv) +et4000_mca_feedb(UNUSED(void *priv)) { return 1; } @@ -747,7 +761,7 @@ et4000_init(const device_t *info) dev->svga.packed_chain4 = 1; - return (dev); + return dev; } static void diff --git a/src/video/vid_et4000w32.c b/src/video/vid_et4000w32.c index 2f6e6497c..c2ce39778 100644 --- a/src/video/vid_et4000w32.c +++ b/src/video/vid_et4000w32.c @@ -96,12 +96,12 @@ typedef struct et4000w32p_t { uint8_t suspend_terminate, osr; uint8_t status; uint16_t x_count, y_count; + uint16_t cpu_x_cnt, cpu_x_cnt_back, cpu_y_cnt; int pattern_x, source_x, pattern_x_back, source_x_back, pattern_y, source_y, cpu_dat_pos, pix_pos, cpu_input_num, fifo_queue; - int pattern_x_diff, pattern_y_diff, pattern_x_diff2, pattern_y_diff2; - int patcnt, mmu_start; + int mmu_start; uint32_t pattern_addr, source_addr, dest_addr, mix_addr, pattern_back, source_back, dest_back, mix_back, @@ -121,7 +121,7 @@ typedef struct et4000w32p_t { static int et4000w32_vbus[4] = { 1, 2, 4, 4 }; static int et4000w32_max_x[8] = { 0, 0, 4, 8, 0x10, 0x20, 0x40, 0x70000000 }; -static int et4000w32_wrap_x[8] = { 0, 0, 3, 7, 0x0F, 0x1F, 0x3F, ~0 }; +static int et4000w32_wrap_x[8] = { 0, 0, 3, 7, 0x0f, 0x1f, 0x3f, ~0 }; static int et4000w32_wrap_y[8] = { 1, 2, 4, 8, ~0, ~0, ~0, ~0 }; static video_timings_t timing_et4000w32_vlb = { .type = VIDEO_BUS, .write_b = 4, .write_w = 4, .write_l = 4, .read_b = 10, .read_w = 10, .read_l = 10 }; @@ -130,14 +130,14 @@ static video_timings_t timing_et4000w32_isa = { .type = VIDEO_ISA, .write_b = 4, void et4000w32p_recalcmapping(et4000w32p_t *et4000); -static uint8_t et4000w32p_mmu_read(uint32_t addr, void *p); -static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p); +static uint8_t et4000w32p_mmu_read(uint32_t addr, void *priv); +static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *priv); static void et4000w32_blit_start(et4000w32p_t *et4000); static void et4000w32p_blit_start(et4000w32p_t *et4000); static void et4000w32_blit(int count, int cpu_input, uint32_t src_dat, uint32_t mix_dat, et4000w32p_t *et4000); static void et4000w32p_blit(int count, uint32_t mix, uint32_t sdat, int cpu_input, et4000w32p_t *et4000); -uint8_t et4000w32p_in(uint16_t addr, void *p); +uint8_t et4000w32p_in(uint16_t addr, void *priv); #ifdef ENABLE_ET4000W32_LOG int et4000w32_do_log = ENABLE_ET4000W32_LOG; @@ -158,9 +158,9 @@ et4000w32_log(const char *fmt, ...) #endif void -et4000w32p_out(uint16_t addr, uint8_t val, void *p) +et4000w32p_out(uint16_t addr, uint8_t val, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; uint8_t old; uint32_t add2addr = 0; @@ -272,14 +272,20 @@ et4000w32p_out(uint16_t addr, uint8_t val, void *p) case 0x216b: case 0x217b: et4000->regs[et4000->index] = val; - svga->hwcursor.cur_xsize = svga->hwcursor.cur_ysize = ((et4000->regs[0xEF] & 4) || (et4000->type == ET4000W32)) ? 128 : 64; svga->hwcursor.x = et4000->regs[0xE0] | ((et4000->regs[0xE1] & 7) << 8); svga->hwcursor.y = et4000->regs[0xE4] | ((et4000->regs[0xE5] & 7) << 8); svga->hwcursor.ena = !!(et4000->regs[0xF7] & 0x80); svga->hwcursor.xoff = et4000->regs[0xE2]; svga->hwcursor.yoff = et4000->regs[0xE6]; + svga->hwcursor.cur_xsize = svga->hwcursor.cur_ysize = ((et4000->regs[0xEF] & 4) || ((et4000->type == ET4000W32) && (et4000->regs[0xe2] >= 0x1f) && (et4000->regs[0xe6] >= 0x1f))) ? 128 : 64; if (et4000->type == ET4000W32) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { + svga->hwcursor.cur_xsize = svga->hwcursor.cur_ysize = 128; + } + } + + if ((et4000->type == ET4000W32) && (svga->hwcursor.cur_xsize == 128)) { switch (svga->bpp) { case 8: svga->hwcursor.xoff += 32; @@ -297,7 +303,7 @@ et4000w32p_out(uint16_t addr, uint8_t val, void *p) } } else { if (et4000->type > ET4000W32P_REVC) { - if (svga->bpp == 24 && et4000->adjust_cursor) { + if ((svga->bpp == 24) && et4000->adjust_cursor) { et4000->adjust_cursor = 0; } } @@ -315,9 +321,9 @@ et4000w32p_out(uint16_t addr, uint8_t val, void *p) } uint8_t -et4000w32p_in(uint16_t addr, void *p) +et4000w32p_in(uint16_t addr, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -337,7 +343,6 @@ et4000w32p_in(uint16_t addr, void *p) return sdac_ramdac_in(addr, 0, svga->ramdac, svga); else return stg_ramdac_in(addr, svga->ramdac, svga); - break; case 0x3cb: return et4000->banking2; @@ -411,7 +416,7 @@ et4000w32p_in(uint16_t addr, void *p) void et4000w32p_recalctimings(svga_t *svga) { - et4000w32p_t *et4000 = (et4000w32p_t *) svga->p; + et4000w32p_t *et4000 = (et4000w32p_t *) svga->priv; svga->ma_latch |= (svga->crtc[0x33] & 0x7) << 16; if (svga->crtc[0x35] & 0x01) @@ -431,7 +436,7 @@ et4000w32p_recalctimings(svga_t *svga) if (svga->attrregs[0x16] & 0x20) svga->hdisp <<= 1; - svga->clock = (cpuclock * (double) (1ull << 32)) / svga->getclock((svga->miscout >> 2) & 3, svga->clock_gen); + svga->clock = (cpuclock * (double) (1ULL << 32)) / svga->getclock((svga->miscout >> 2) & 3, svga->clock_gen); if (et4000->type != ET4000W32P_DIAMOND) { if ((svga->gdcreg[6] & 1) || (svga->attrregs[0x10] & 1)) { @@ -457,7 +462,7 @@ et4000w32p_recalctimings(svga_t *svga) if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) { /* Text mode */ svga->ma_latch--; - if ((svga->seqregs[1] & 8)) /*40 column*/ + if (svga->seqregs[1] & 8) /*40 column*/ svga->hdisp += (svga->seqregs[1] & 1) ? 16 : 18; else svga->hdisp += (svga->seqregs[1] & 1) ? 8 : 9; @@ -674,40 +679,46 @@ et4000w32p_accel_write_fifo(et4000w32p_t *et4000, uint32_t addr, uint8_t val) et4000->acl.fifo_queue++; switch (addr & 0xff) { case 0x80: - et4000->acl.queued.pattern_addr = (et4000->acl.queued.pattern_addr & 0x3fff00) | val; + et4000->acl.queued.pattern_addr = (et4000->acl.queued.pattern_addr & 0xffffff00) | val; break; case 0x81: - et4000->acl.queued.pattern_addr = (et4000->acl.queued.pattern_addr & 0x3f00ff) | (val << 8); + et4000->acl.queued.pattern_addr = (et4000->acl.queued.pattern_addr & 0xffff00ff) | (val << 8); break; case 0x82: - et4000->acl.queued.pattern_addr = (et4000->acl.queued.pattern_addr & 0x00ffff) | ((val & 0x3f) << 16); + et4000->acl.queued.pattern_addr = (et4000->acl.queued.pattern_addr & 0xff00ffff) | (val << 16); + break; + case 0x83: + et4000->acl.queued.pattern_addr = (et4000->acl.queued.pattern_addr & 0x00ffffff) | (val << 24); break; case 0x84: - et4000->acl.queued.source_addr = (et4000->acl.queued.source_addr & 0x3fff00) | val; + et4000->acl.queued.source_addr = (et4000->acl.queued.source_addr & 0xffffff00) | val; break; case 0x85: - et4000->acl.queued.source_addr = (et4000->acl.queued.source_addr & 0x3f00ff) | (val << 8); + et4000->acl.queued.source_addr = (et4000->acl.queued.source_addr & 0xffff00ff) | (val << 8); break; case 0x86: - et4000->acl.queued.source_addr = (et4000->acl.queued.source_addr & 0x00ffff) | ((val & 0x3f) << 16); + et4000->acl.queued.source_addr = (et4000->acl.queued.source_addr & 0xff00ffff) | (val << 16); + break; + case 0x87: + et4000->acl.queued.source_addr = (et4000->acl.queued.source_addr & 0x00ffffff) | (val << 24); break; case 0x88: - et4000->acl.queued.pattern_off = (et4000->acl.queued.pattern_off & 0x0f00) | val; + et4000->acl.queued.pattern_off = (et4000->acl.queued.pattern_off & 0xff00) | val; break; case 0x89: - et4000->acl.queued.pattern_off = (et4000->acl.queued.pattern_off & 0x00ff) | ((val & 0x0f) << 8); + et4000->acl.queued.pattern_off = (et4000->acl.queued.pattern_off & 0x00ff) | (val << 8); break; case 0x8a: - et4000->acl.queued.source_off = (et4000->acl.queued.source_off & 0x0f00) | val; + et4000->acl.queued.source_off = (et4000->acl.queued.source_off & 0xff00) | val; break; case 0x8b: - et4000->acl.queued.source_off = (et4000->acl.queued.source_off & 0x00ff) | ((val & 0x0f) << 8); + et4000->acl.queued.source_off = (et4000->acl.queued.source_off & 0x00ff) | (val << 8); break; case 0x8c: - et4000->acl.queued.dest_off = (et4000->acl.queued.dest_off & 0x0f00) | val; + et4000->acl.queued.dest_off = (et4000->acl.queued.dest_off & 0xff00) | val; break; case 0x8d: - et4000->acl.queued.dest_off = (et4000->acl.queued.dest_off & 0x00ff) | ((val & 0x0f) << 8); + et4000->acl.queued.dest_off = (et4000->acl.queued.dest_off & 0x00ff) | (val << 8); break; case 0x8e: if (et4000->type >= ET4000W32P_REVC) @@ -728,16 +739,16 @@ et4000w32p_accel_write_fifo(et4000w32p_t *et4000, uint32_t addr, uint8_t val) et4000->acl.queued.source_wrap = val & 0x77; break; case 0x98: - et4000->acl.queued.count_x = (et4000->acl.queued.count_x & 0x0f00) | val; + et4000->acl.queued.count_x = (et4000->acl.queued.count_x & 0xff00) | val; break; case 0x99: - et4000->acl.queued.count_x = (et4000->acl.queued.count_x & 0x00ff) | ((val & 0x0f) << 8); + et4000->acl.queued.count_x = (et4000->acl.queued.count_x & 0x00ff) | (val << 8); break; case 0x9a: - et4000->acl.queued.count_y = (et4000->acl.queued.count_y & 0x0f00) | val; + et4000->acl.queued.count_y = (et4000->acl.queued.count_y & 0xff00) | val; break; case 0x9b: - et4000->acl.queued.count_y = (et4000->acl.queued.count_y & 0x00ff) | ((val & 0x0f) << 8); + et4000->acl.queued.count_y = (et4000->acl.queued.count_y & 0x00ff) | (val << 8); break; case 0x9c: if (et4000->type >= ET4000W32P_REVC) @@ -755,15 +766,16 @@ et4000w32p_accel_write_fifo(et4000w32p_t *et4000, uint32_t addr, uint8_t val) et4000->acl.queued.rop_fg = val; break; case 0xa0: - et4000->acl.queued.dest_addr = (et4000->acl.queued.dest_addr & 0x3fff00) | val; + et4000->acl.queued.dest_addr = (et4000->acl.queued.dest_addr & 0xffffff00) | val; break; case 0xa1: - et4000->acl.queued.dest_addr = (et4000->acl.queued.dest_addr & 0x3f00ff) | (val << 8); + et4000->acl.queued.dest_addr = (et4000->acl.queued.dest_addr & 0xffff00ff) | (val << 8); break; case 0xa2: - et4000->acl.queued.dest_addr = (et4000->acl.queued.dest_addr & 0x00ffff) | ((val & 0x3f) << 16); + et4000->acl.queued.dest_addr = (et4000->acl.queued.dest_addr & 0xff00ffff) | (val << 16); break; case 0xa3: + et4000->acl.queued.dest_addr = (et4000->acl.queued.dest_addr & 0x00ffffff) | (val << 24); et4000->acl.internal = et4000->acl.queued; if (et4000->type >= ET4000W32P_REVC) { et4000w32p_blit_start(et4000); @@ -778,9 +790,10 @@ et4000w32p_accel_write_fifo(et4000w32p_t *et4000, uint32_t addr, uint8_t val) et4000w32_blit_start(et4000); et4000->acl.cpu_input_num = 0; if (!(et4000->acl.queued.ctrl_routing & 0x37)) { - et4000->acl.mmu_start = 0; + et4000->acl.mmu_start = 1; et4000w32_blit(-1, 0, 0, 0xffffffff, et4000); - } + } else + et4000->acl.mmu_start = 0; } break; case 0xa4: @@ -843,11 +856,13 @@ et4000w32p_accel_write_mmu(et4000w32p_t *et4000, uint32_t addr, uint8_t val, uin et4000->acl.queued.dest_addr = ((addr & 0x1fff) + et4000->mmu.base[bank]); et4000->acl.internal = et4000->acl.queued; et4000w32_blit_start(et4000); - et4000w32_log("ET4000W32 Accelerated MMU aperture start XY Block (Implicit): bank = %i, patx = %i, paty = %i, wrap y = %i\n", et4000->bank, et4000->acl.pattern_x, et4000->acl.pattern_y, et4000w32_wrap_y[(et4000->acl.internal.pattern_wrap >> 4) & 7]); + et4000w32_log("ET4000W32 Accelerated MMU aperture start XY Block (Implicit): bank = %i, patx = %i, paty = %i, wrap x = %i, wrap y = %i\n", et4000->bank, et4000->acl.pattern_x, et4000->acl.pattern_y, et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7], et4000w32_wrap_y[(et4000->acl.internal.pattern_wrap >> 4) & 7]); et4000->acl.cpu_input_num = 0; if (!(et4000->acl.queued.ctrl_routing & 0x37)) { et4000->acl.mmu_start = 1; et4000w32_blit(-1, 0, 0, 0xffffffff, et4000); + } else { + et4000->acl.mmu_start = 0; } } @@ -865,18 +880,27 @@ et4000w32p_accel_write_mmu(et4000w32p_t *et4000, uint32_t addr, uint8_t val, uin et4000->acl.cpu_input_num = 0; } - if ((et4000->acl.internal.ctrl_routing & 7) == 4) /*CPU data is X Count*/ - et4000w32_blit(val | (et4000->acl.queued.count_x << 8), 0, 0, 0xffffffff, et4000); - if ((et4000->acl.internal.ctrl_routing & 7) == 5) /*CPU data is Y Count*/ - et4000w32_blit(val | (et4000->acl.queued.count_y << 8), 0, 0, 0xffffffff, et4000); + if (et4000w32_vbus[et4000->acl.internal.vbus] == 1) { + if ((et4000->acl.internal.ctrl_routing & 7) == 4) { /*CPU data is X Count*/ + et4000w32_log("ET4000W32 Accelerated MMU aperture routing = %02x: val = %02x, cx = %02x.\n", et4000->acl.internal.ctrl_routing, val, et4000->acl.internal.count_x); + et4000->acl.cpu_x_cnt = val + 1; + et4000->acl.cpu_x_cnt |= ((et4000->acl.queued.count_x >> 8) << 8); + et4000w32_blit(et4000->acl.cpu_x_cnt, 3, 0, 0xffffffff, et4000); + } else if ((et4000->acl.internal.ctrl_routing & 7) == 5) { /*CPU data is Y Count*/ + et4000w32_log("ET4000W32 Accelerated MMU aperture routing = %02x: val = %02x, cy = %02x.\n", et4000->acl.internal.ctrl_routing, val, et4000->acl.internal.count_y); + et4000->acl.cpu_y_cnt = val + 1; + et4000->acl.cpu_y_cnt |= ((et4000->acl.queued.count_y >> 8) << 8); + et4000w32_blit(et4000->acl.cpu_y_cnt, 4, 0, 0xffffffff, et4000); + } + } } } } static void -et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p) +et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; switch (addr & 0x6000) { @@ -899,31 +923,40 @@ et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p) } else { switch (addr & 0xff) { case 0x00: - et4000->mmu.base[0] = (et4000->mmu.base[0] & 0x3fff00) | val; + et4000->mmu.base[0] = (et4000->mmu.base[0] & 0xffffff00) | val; break; case 0x01: - et4000->mmu.base[0] = (et4000->mmu.base[0] & 0x3f00ff) | (val << 8); + et4000->mmu.base[0] = (et4000->mmu.base[0] & 0xffff00ff) | (val << 8); break; case 0x02: - et4000->mmu.base[0] = (et4000->mmu.base[0] & 0x00ffff) | ((val & 0x3f) << 16); + et4000->mmu.base[0] = (et4000->mmu.base[0] & 0xff00ffff) | (val << 16); + break; + case 0x03: + et4000->mmu.base[0] = (et4000->mmu.base[0] & 0x00ffffff) | (val << 24); break; case 0x04: - et4000->mmu.base[1] = (et4000->mmu.base[1] & 0x3fff00) | val; + et4000->mmu.base[1] = (et4000->mmu.base[1] & 0xffffff00) | val; break; case 0x05: - et4000->mmu.base[1] = (et4000->mmu.base[1] & 0x3f00ff) | (val << 8); + et4000->mmu.base[1] = (et4000->mmu.base[1] & 0xffff00ff) | (val << 8); break; case 0x06: - et4000->mmu.base[1] = (et4000->mmu.base[1] & 0x00ffff) | ((val & 0x3f) << 16); + et4000->mmu.base[1] = (et4000->mmu.base[1] & 0xff00ffff) | (val << 16); + break; + case 0x07: + et4000->mmu.base[1] = (et4000->mmu.base[1] & 0x00ffffff) | (val << 24); break; case 0x08: - et4000->mmu.base[2] = (et4000->mmu.base[2] & 0x3fff00) | val; + et4000->mmu.base[2] = (et4000->mmu.base[2] & 0xffffff00) | val; break; case 0x09: - et4000->mmu.base[2] = (et4000->mmu.base[2] & 0x3f00ff) | (val << 8); + et4000->mmu.base[2] = (et4000->mmu.base[2] & 0xffff00ff) | (val << 8); break; case 0x0a: - et4000->mmu.base[2] = (et4000->mmu.base[2] & 0x00ffff) | ((val & 0x3f) << 16); + et4000->mmu.base[2] = (et4000->mmu.base[2] & 0xff00ffff) | (val << 16); + break; + case 0x0b: + et4000->mmu.base[2] = (et4000->mmu.base[2] & 0x00ffffff) | (val << 24); break; case 0x13: et4000->mmu.ctrl = val; @@ -941,9 +974,9 @@ et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p) } static uint8_t -et4000w32p_mmu_read(uint32_t addr, void *p) +et4000w32p_mmu_read(uint32_t addr, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; uint8_t temp; @@ -1041,7 +1074,6 @@ et4000w32p_mmu_read(uint32_t addr, void *p) return et4000->acl.internal.pixel_depth; else return et4000->acl.internal.vbus; - break; case 0x8f: return et4000->acl.internal.xy_dir; case 0x90: @@ -1127,6 +1159,26 @@ et4000w32_blit_start(et4000w32p_t *et4000) et4000->acl.source_back &= ~(((et4000w32_wrap_x[et4000->acl.internal.source_wrap & 7] + 1) * et4000w32_wrap_y[(et4000->acl.internal.source_wrap >> 4) & 7]) - 1); } et4000->acl.source_x_back = et4000->acl.source_x; + + if ((et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7] == 7) && !(et4000->acl.internal.ctrl_routing & 0x37) && (et4000->acl.internal.rop_fg == 0x5a)) { + if ((et4000->acl.internal.count_y > 0) && (et4000->acl.pattern_y > 0)) { + if (et4000->acl.pattern_addr == et4000->acl.pattern_back) + et4000->acl.pattern_y = 0; + else { + et4000->acl.pattern_y = (et4000->acl.pattern_addr - et4000->acl.pattern_back) & 0x70; + et4000->acl.pattern_y >>= 4; + } + } + } else if ((et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7] == 15) && !(et4000->acl.internal.ctrl_routing & 0x37) && (et4000->acl.internal.rop_fg == 0x5a)) { + if ((et4000->acl.internal.count_y > 0) && (et4000->acl.pattern_y > 0)) { + if (et4000->acl.pattern_addr == et4000->acl.pattern_back) + et4000->acl.pattern_y = 0; + else { + et4000->acl.pattern_y = (et4000->acl.pattern_addr - et4000->acl.pattern_back) & 0xf0; + et4000->acl.pattern_y >>= 5; + } + } + } } static void @@ -1137,6 +1189,7 @@ et4000w32p_blit_start(et4000w32p_t *et4000) if (!(et4000->acl.queued.xy_dir & 0x20)) et4000->acl.internal.error = et4000->acl.internal.dmaj / 2; + et4000->acl.pattern_addr = et4000->acl.internal.pattern_addr; et4000->acl.source_addr = et4000->acl.internal.source_addr; et4000->acl.mix_addr = et4000->acl.internal.mix_addr; @@ -1236,12 +1289,12 @@ et4000w32_decy(et4000w32p_t *et4000) et4000->acl.mix_addr -= et4000->acl.internal.mix_off + 1; et4000->acl.dest_addr -= et4000->acl.internal.dest_off + 1; et4000->acl.pattern_y--; - if (et4000->acl.pattern_y < 0 && !(et4000->acl.internal.pattern_wrap & 0x40)) { + if ((et4000->acl.pattern_y < 0) && !(et4000->acl.internal.pattern_wrap & 0x40)) { et4000->acl.pattern_y = et4000w32_wrap_y[(et4000->acl.internal.pattern_wrap >> 4) & 7] - 1; et4000->acl.pattern_addr = et4000->acl.pattern_back + (et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7] * (et4000w32_wrap_y[(et4000->acl.internal.pattern_wrap >> 4) & 7] - 1)); } et4000->acl.source_y--; - if (et4000->acl.source_y < 0 && !(et4000->acl.internal.source_wrap & 0x40)) { + if ((et4000->acl.source_y < 0) && !(et4000->acl.internal.source_wrap & 0x40)) { et4000->acl.source_y = et4000w32_wrap_y[(et4000->acl.internal.source_wrap >> 4) & 7] - 1; et4000->acl.source_addr = et4000->acl.source_back + (et4000w32_wrap_x[et4000->acl.internal.source_wrap & 7] * (et4000w32_wrap_y[(et4000->acl.internal.source_wrap >> 4) & 7] - 1)); } @@ -2025,104 +2078,175 @@ static void et4000w32_blit(int count, int cpu_input, uint32_t src_dat, uint32_t mix_dat, et4000w32p_t *et4000) { svga_t *svga = &et4000->svga; - uint8_t pattern, source, dest; + uint8_t pattern; + uint8_t source; + uint8_t dest; uint8_t rop; - uint8_t out; + uint8_t out = 0; int mixmap; - while (count-- && et4000->acl.y_count >= 0) { - pattern = svga->vram[(et4000->acl.pattern_addr + et4000->acl.pattern_x) & et4000->vram_mask]; + if (!(et4000->acl.status & ACL_XYST) && !et4000->acl.mmu_start) { + et4000w32_log("XY Block not started\n"); + return; + } - if (cpu_input == 1) { - source = src_dat & 0xff; - src_dat >>= 8; - } else /*The source data is from the display memory if the Control Routing register is not set to 1*/ + if (cpu_input == 3) { + while (1) { + pattern = svga->vram[(et4000->acl.pattern_addr + et4000->acl.pattern_x) & et4000->vram_mask]; source = svga->vram[(et4000->acl.source_addr + et4000->acl.source_x) & et4000->vram_mask]; - dest = svga->vram[et4000->acl.dest_addr & et4000->vram_mask]; - mixmap = mix_dat & 1; + dest = svga->vram[et4000->acl.dest_addr & et4000->vram_mask]; + mixmap = mix_dat & 1; - /*Now determine the Raster Operation*/ - rop = mixmap ? et4000->acl.internal.rop_fg : et4000->acl.internal.rop_bg; - mix_dat >>= 1; - mix_dat |= 0x80000000; + rop = mixmap ? et4000->acl.internal.rop_fg : et4000->acl.internal.rop_bg; + mix_dat >>= 1; + mix_dat |= 0x80000000; - ROPMIX(rop, dest, pattern, source, out); + ROPMIX(rop, dest, pattern, source, out); - /*Write the data*/ - svga->vram[et4000->acl.dest_addr & et4000->vram_mask] = out; - svga->changedvram[(et4000->acl.dest_addr & et4000->vram_mask) >> 12] = changeframecount; + /*Write the data*/ + svga->vram[et4000->acl.dest_addr & et4000->vram_mask] = out; + svga->changedvram[(et4000->acl.dest_addr & et4000->vram_mask) >> 12] = changeframecount; - if (et4000->acl.internal.xy_dir & 1) { - et4000->acl.dest_addr--; - et4000->acl.pattern_x--; - et4000->acl.source_x--; - if (et4000->acl.pattern_x < 0) - et4000->acl.pattern_x += (et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7] + 1); - if (et4000->acl.source_x < 0) - et4000->acl.source_x += (et4000w32_wrap_x[et4000->acl.internal.source_wrap & 7] + 1); - } else { - et4000->acl.dest_addr++; - et4000->acl.pattern_x++; - et4000->acl.source_x++; - if (et4000->acl.pattern_x >= (et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7] + 1)) - et4000->acl.pattern_x -= (et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7] + 1); - if (et4000->acl.source_x >= (et4000w32_wrap_x[et4000->acl.internal.source_wrap & 7] + 1)) - et4000->acl.source_x -= (et4000w32_wrap_x[et4000->acl.internal.source_wrap & 7] + 1); + if (et4000->acl.internal.xy_dir & 1) + et4000w32_decx(1, et4000); + else + et4000w32_incx(1, et4000); + + count--; + if (!count) { + count = et4000->acl.cpu_x_cnt; + + if (et4000->acl.internal.xy_dir & 2) { + et4000w32_decy(et4000); + et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back - (et4000->acl.internal.dest_off + 1); + } else { + et4000w32_incy(et4000); + et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back + et4000->acl.internal.dest_off + 1; + } + + et4000->acl.pattern_x = et4000->acl.pattern_x_back; + et4000->acl.source_x = et4000->acl.source_x_back; + + et4000->acl.y_count--; + if (et4000->acl.y_count == 0xffff) { + et4000->acl.status &= ~ACL_XYST; + if (!(et4000->acl.internal.ctrl_routing & 7) || (et4000->acl.internal.ctrl_routing & 4)) { + et4000w32_log("W32i: end blit, xcount = %i\n", et4000->acl.x_count); + et4000->acl.status &= ~ACL_SSO; + } + return; + } + } } + } else if (cpu_input == 4) { + while (1) { + pattern = svga->vram[(et4000->acl.pattern_addr + et4000->acl.pattern_x) & et4000->vram_mask]; + source = svga->vram[(et4000->acl.source_addr + et4000->acl.source_x) & et4000->vram_mask]; - et4000->acl.x_count--; - if (et4000->acl.x_count == 0xffff) { - et4000->acl.x_count = et4000->acl.internal.count_x; + dest = svga->vram[et4000->acl.dest_addr & et4000->vram_mask]; + mixmap = mix_dat & 1; - if (et4000->acl.internal.xy_dir & 2) { - et4000->acl.pattern_addr -= (et4000->acl.internal.pattern_off + 1); - et4000->acl.source_addr -= (et4000->acl.internal.source_off + 1); - et4000->acl.dest_addr -= (et4000->acl.internal.dest_off + 1); - et4000->acl.pattern_y--; - if ((et4000->acl.pattern_y < 0) && !(et4000->acl.internal.pattern_wrap & 0x40)) { - et4000->acl.pattern_y = et4000w32_wrap_y[(et4000->acl.internal.pattern_wrap >> 4) & 7] - 1; - et4000->acl.pattern_addr = et4000->acl.pattern_back + (et4000w32_wrap_x[et4000->acl.internal.pattern_wrap & 7] * (et4000w32_wrap_y[(et4000->acl.internal.pattern_wrap >> 4) & 7] - 1)); + rop = mixmap ? et4000->acl.internal.rop_fg : et4000->acl.internal.rop_bg; + mix_dat >>= 1; + mix_dat |= 0x80000000; + + ROPMIX(rop, dest, pattern, source, out); + + /*Write the data*/ + svga->vram[et4000->acl.dest_addr & et4000->vram_mask] = out; + svga->changedvram[(et4000->acl.dest_addr & et4000->vram_mask) >> 12] = changeframecount; + + if (et4000->acl.internal.xy_dir & 1) + et4000w32_decx(1, et4000); + else + et4000w32_incx(1, et4000); + + et4000->acl.x_count--; + if (et4000->acl.x_count == 0xffff) { + et4000->acl.x_count = et4000->acl.internal.count_x; + + if (et4000->acl.internal.xy_dir & 2) { + et4000w32_decy(et4000); + et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back - (et4000->acl.internal.dest_off + 1); + } else { + et4000w32_incy(et4000); + et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back + et4000->acl.internal.dest_off + 1; } - et4000->acl.source_y--; - if ((et4000->acl.source_y < 0) && !(et4000->acl.internal.source_wrap & 0x40)) { - et4000->acl.source_y = et4000w32_wrap_y[(et4000->acl.internal.source_wrap >> 4) & 7] - 1; - et4000->acl.source_addr = et4000->acl.source_back + (et4000w32_wrap_x[et4000->acl.internal.source_wrap & 7] * (et4000w32_wrap_y[(et4000->acl.internal.source_wrap >> 4) & 7] - 1)); + + et4000->acl.pattern_x = et4000->acl.pattern_x_back; + et4000->acl.source_x = et4000->acl.source_x_back; + + count--; + if (!count) { + et4000->acl.status &= ~ACL_XYST; + if (!(et4000->acl.internal.ctrl_routing & 7) || (et4000->acl.internal.ctrl_routing & 4)) { + et4000w32_log("W32i: end blit, xcount = %i\n", et4000->acl.x_count); + et4000->acl.status &= ~ACL_SSO; + } + return; } - et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back - (et4000->acl.internal.dest_off + 1); - } else { - et4000->acl.pattern_addr += (et4000->acl.internal.pattern_off + 1); - et4000->acl.source_addr += (et4000->acl.internal.source_off + 1); - et4000->acl.dest_addr += (et4000->acl.internal.dest_off + 1); - et4000->acl.pattern_y++; - if (et4000->acl.pattern_y == et4000w32_wrap_y[(et4000->acl.internal.pattern_wrap >> 4) & 7]) { - et4000->acl.pattern_y = 0; - et4000->acl.pattern_addr = et4000->acl.pattern_back; - } - et4000->acl.source_y++; - if (et4000->acl.source_y == et4000w32_wrap_y[(et4000->acl.internal.source_wrap >> 4) & 7]) { - et4000->acl.source_y = 0; - et4000->acl.source_addr = et4000->acl.source_back; - } - et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back + (et4000->acl.internal.dest_off + 1); } + } + } else { + while (count-- && (et4000->acl.y_count >= 0)) { + pattern = svga->vram[(et4000->acl.pattern_addr + et4000->acl.pattern_x) & et4000->vram_mask]; - et4000->acl.pattern_x = et4000->acl.pattern_x_back; - et4000->acl.source_x = et4000->acl.source_x_back; + if (cpu_input == 1) { + source = src_dat & 0xff; + src_dat >>= 8; + } else /*The source data is from the display memory if the Control Routing register is not set to 1*/ + source = svga->vram[(et4000->acl.source_addr + et4000->acl.source_x) & et4000->vram_mask]; - et4000->acl.y_count--; - if (et4000->acl.y_count == 0xffff) { - et4000->acl.status &= ~ACL_XYST; - if (!(et4000->acl.internal.ctrl_routing & 7) || (et4000->acl.internal.ctrl_routing & 4)) { - et4000w32_log("W32i: end blit, xcount = %i\n", et4000->acl.x_count); - et4000->acl.status &= ~ACL_SSO; + dest = svga->vram[et4000->acl.dest_addr & et4000->vram_mask]; + mixmap = mix_dat & 1; + + /*Now determine the Raster Operation*/ + rop = mixmap ? et4000->acl.internal.rop_fg : et4000->acl.internal.rop_bg; + mix_dat >>= 1; + mix_dat |= 0x80000000; + + ROPMIX(rop, dest, pattern, source, out); + + /*Write the data*/ + svga->vram[et4000->acl.dest_addr & et4000->vram_mask] = out; + svga->changedvram[(et4000->acl.dest_addr & et4000->vram_mask) >> 12] = changeframecount; + + if (et4000->acl.internal.xy_dir & 1) + et4000w32_decx(1, et4000); + else + et4000w32_incx(1, et4000); + + et4000->acl.x_count--; + if (et4000->acl.x_count == 0xffff) { + et4000->acl.x_count = et4000->acl.internal.count_x; + + if (et4000->acl.internal.xy_dir & 2) { + et4000w32_decy(et4000); + et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back - (et4000->acl.internal.dest_off + 1); + } else { + et4000w32_incy(et4000); + et4000->acl.dest_back = et4000->acl.dest_addr = et4000->acl.dest_back + et4000->acl.internal.dest_off + 1; } - et4000->acl.cpu_input_num = 0; - return; - } - if (cpu_input) - return; + et4000->acl.pattern_x = et4000->acl.pattern_x_back; + et4000->acl.source_x = et4000->acl.source_x_back; + + et4000->acl.y_count--; + if (et4000->acl.y_count == 0xffff) { + et4000->acl.status &= ~ACL_XYST; + if (!(et4000->acl.internal.ctrl_routing & 7) || (et4000->acl.internal.ctrl_routing & 4)) { + et4000w32_log("W32i: end blit, xcount = %i\n", et4000->acl.x_count); + et4000->acl.status &= ~ACL_SSO; + } + et4000->acl.cpu_input_num = 0; + return; + } + + if (cpu_input) { + return; + } + } } } } @@ -2131,7 +2255,10 @@ static void et4000w32p_blit(int count, uint32_t mix, uint32_t sdat, int cpu_input, et4000w32p_t *et4000) { svga_t *svga = &et4000->svga; - uint8_t pattern, source, dest, out; + uint8_t pattern; + uint8_t source; + uint8_t dest; + uint8_t out; uint8_t rop; int mixdat; @@ -2324,8 +2451,10 @@ et4000w32p_blit(int count, uint32_t mix, uint32_t sdat, int cpu_input, et4000w32 void et4000w32p_hwcursor_draw(svga_t *svga, int displine) { - et4000w32p_t *et4000 = (et4000w32p_t *) svga->p; - int x, offset, xx, xx2; + et4000w32p_t *et4000 = (et4000w32p_t *) svga->priv; + int offset; + int xx; + int xx2; int shift = (et4000->adjust_cursor + 1); int width = (svga->hwcursor_latch.cur_xsize - svga->hwcursor_latch.xoff); int pitch = (svga->hwcursor_latch.cur_xsize == 128) ? 32 : 16; @@ -2334,7 +2463,7 @@ et4000w32p_hwcursor_draw(svga_t *svga, int displine) uint8_t dat; offset = svga->hwcursor_latch.xoff; - if (et4000->type == ET4000W32) { + if ((et4000->type == ET4000W32) && (pitch == 32)) { switch (svga->bpp) { case 8: minus_width = 0; @@ -2348,7 +2477,7 @@ et4000w32p_hwcursor_draw(svga_t *svga, int displine) } } - for (x = 0; x < (width - minus_width); x += x_acc) { + for (int x = 0; x < (width - minus_width); x += x_acc) { dat = svga->vram[svga->hwcursor_latch.addr + (offset >> 2)]; xx = svga->hwcursor_latch.x + svga->x_add + x; @@ -2428,9 +2557,9 @@ et4000w32p_io_set(et4000w32p_t *et4000) } uint8_t -et4000w32p_pci_read(int func, int addr, void *p) +et4000w32p_pci_read(UNUSED(int func), int addr, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; addr &= 0xff; @@ -2484,9 +2613,9 @@ et4000w32p_pci_read(int func, int addr, void *p) } void -et4000w32p_pci_write(int func, int addr, uint8_t val, void *p) +et4000w32p_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; addr &= 0xff; @@ -2742,9 +2871,9 @@ et4000w32p_cardex_available(void) } void -et4000w32p_close(void *p) +et4000w32p_close(void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_close(&et4000->svga); @@ -2752,17 +2881,17 @@ et4000w32p_close(void *p) } void -et4000w32p_speed_changed(void *p) +et4000w32p_speed_changed(void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_recalctimings(&et4000->svga); } void -et4000w32p_force_redraw(void *p) +et4000w32p_force_redraw(void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; et4000->svga.fullchange = changeframecount; } diff --git a/src/video/vid_f82c425.c b/src/video/vid_f82c425.c index 15f4ce496..a2ffeddb5 100644 --- a/src/video/vid_f82c425.c +++ b/src/video/vid_f82c425.c @@ -63,6 +63,7 @@ #include "cpu.h" #include <86box/video.h> #include <86box/vid_cga.h> +#include <86box/plat_unused.h> #define F82C425_XSIZE 640 #define F82C425_YSIZE 200 @@ -179,9 +180,7 @@ f82c425_smartmap_add(int a, int b, int sat) static void f82c425_smartmap(f82c425_t *f82c425) { - int i; - - for (i = 0; i < 256; i++) { + for (uint16_t i = 0; i < 256; i++) { uint8_t bg = f82c425_rgbi(i >> 4); uint8_t fg = f82c425_rgbi(i & 0xf); @@ -223,16 +222,14 @@ f82c425_smartmap(f82c425_t *f82c425) static void f82c425_colormap(f82c425_t *f82c425) { - int i; - - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) colormap[i] = f82c425_makecol(5 * i, 0, f82c425->function & 0x80); } static void -f82c425_out(uint16_t addr, uint8_t val, void *p) +f82c425_out(uint16_t addr, uint8_t val, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; if (addr == 0x3d4) f82c425->crtcreg = val; @@ -275,9 +272,9 @@ f82c425_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -f82c425_in(uint16_t addr, void *p) +f82c425_in(uint16_t addr, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; if ((f82c425->function & 0x01) == 0) return 0xff; @@ -309,18 +306,18 @@ f82c425_in(uint16_t addr, void *p) } static void -f82c425_write(uint32_t addr, uint8_t val, void *p) +f82c425_write(uint32_t addr, uint8_t val, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; f82c425->vram[addr & 0x3fff] = val; cycles -= 4; } static uint8_t -f82c425_read(uint32_t addr, void *p) +f82c425_read(uint32_t addr, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; cycles -= 4; return f82c425->vram[addr & 0x3fff]; @@ -330,7 +327,8 @@ static void f82c425_recalctimings(f82c425_t *f82c425) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; if (f82c425->function & 0x08) { cga_recalctimings(&f82c425->cga); @@ -349,8 +347,9 @@ static void f82c425_text_row(f82c425_t *f82c425) { uint32_t colors[2]; - int x, c; - uint8_t chr, attr; + int c; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int blink; @@ -371,7 +370,7 @@ f82c425_text_row(f82c425_t *f82c425) cursorline = ((f82c425->cga.crtc[0x0a] & 0x0F) <= sc) && ((f82c425->cga.crtc[0x0b] & 0x0F) >= sc); } - for (x = 0; x < columns; x++) { + for (int x = 0; x < columns; x++) { chr = f82c425->vram[(addr + 2 * x) & 0x3FFF]; attr = f82c425->vram[(addr + 2 * x + 1) & 0x3FFF]; drawcursor = ((ma == ca) && cursorline && (f82c425->cga.cgamode & 0x8) && (f82c425->cga.cgablink & 0x10)); @@ -409,7 +408,6 @@ f82c425_text_row(f82c425_t *f82c425) static void f82c425_cgaline6(f82c425_t *f82c425) { - int x, c; uint8_t dat; uint16_t addr; @@ -417,11 +415,11 @@ f82c425_cgaline6(f82c425_t *f82c425) addr = ((f82c425->displine) & 1) * 0x2000 + (f82c425->displine >> 1) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = f82c425->vram[addr & 0x3FFF]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { ((uint32_t *) buffer32->line[f82c425->displine])[x * 8 + c] = colormap[dat & 0x80 ? 3 : 0]; dat = dat << 1; @@ -433,18 +431,18 @@ f82c425_cgaline6(f82c425_t *f82c425) static void f82c425_cgaline4(f82c425_t *f82c425) { - int x, c; - uint8_t dat, pattern; + uint8_t dat; + uint8_t pattern; uint16_t addr; uint16_t ma = (f82c425->cga.crtc[0x0d] | (f82c425->cga.crtc[0x0c] << 8)) & 0x3fff; addr = ((f82c425->displine) & 1) * 0x2000 + (f82c425->displine >> 1) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = f82c425->vram[addr & 0x3FFF]; addr++; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; if (!(f82c425->cga.cgamode & 0x08)) pattern = 0; @@ -457,9 +455,9 @@ f82c425_cgaline4(f82c425_t *f82c425) } static void -f82c425_poll(void *p) +f82c425_poll(void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; if (f82c425->video_options != st_video_options || !!(f82c425->function & 1) != st_enabled) { f82c425->video_options = st_video_options; @@ -563,9 +561,10 @@ f82c425_poll(void *p) } static void * -f82c425_init(const device_t *info) +f82c425_init(UNUSED(const device_t *info)) { f82c425_t *f82c425 = malloc(sizeof(f82c425_t)); + memset(f82c425, 0, sizeof(f82c425_t)); cga_init(&f82c425->cga); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_f82c425); @@ -598,18 +597,18 @@ f82c425_init(const device_t *info) } static void -f82c425_close(void *p) +f82c425_close(void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; free(f82c425->vram); free(f82c425); } static void -f82c425_speed_changed(void *p) +f82c425_speed_changed(void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; f82c425_recalctimings(f82c425); } diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index cbf4eabfe..763cfe540 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -138,13 +138,13 @@ static uint8_t genius_pal[4]; static uint8_t mdaattr[256][2][2]; void genius_recalctimings(genius_t *genius); -void genius_write(uint32_t addr, uint8_t val, void *p); -uint8_t genius_read(uint32_t addr, void *p); +void genius_write(uint32_t addr, uint8_t val, void *priv); +uint8_t genius_read(uint32_t addr, void *priv); void -genius_out(uint16_t addr, uint8_t val, void *p) +genius_out(uint16_t addr, uint8_t val, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; switch (addr) { case 0x3b0: /* Command / control register */ @@ -208,9 +208,9 @@ genius_out(uint16_t addr, uint8_t val, void *p) } uint8_t -genius_in(uint16_t addr, void *p) +genius_in(uint16_t addr, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; uint8_t ret = 0xff; switch (addr) { @@ -269,9 +269,9 @@ genius_waitstates(void) } void -genius_write(uint32_t addr, uint8_t val, void *p) +genius_write(uint32_t addr, uint8_t val, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; genius_waitstates(); if (genius->genius_control & 1) { @@ -293,9 +293,9 @@ genius_write(uint32_t addr, uint8_t val, void *p) } uint8_t -genius_read(uint32_t addr, void *p) +genius_read(uint32_t addr, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; uint8_t ret; genius_waitstates(); @@ -322,7 +322,8 @@ void genius_recalctimings(genius_t *genius) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; disptime = 0x31; _dispontime = 0x28; @@ -374,15 +375,24 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) { int w = 80; /* 80 characters across */ int cw = 9; /* Each character is 9 pixels wide */ - uint8_t chr, attr, sc, ctrl; - uint8_t *crtc, bitmap[2]; - int x, blink, c, row, charh; - int drawcursor, cursorline; + uint8_t chr; + uint8_t attr; + uint8_t sc; + uint8_t ctrl; + uint8_t *crtc; + uint8_t bitmap[2]; + int blink; + int c; + int row; + int charh; + int drawcursor; + int cursorline; uint16_t addr; uint16_t ma = (genius->mda_crtc[13] | (genius->mda_crtc[12] << 8)) & 0x3fff; uint16_t ca = (genius->mda_crtc[15] | (genius->mda_crtc[14] << 8)) & 0x3fff; unsigned char *framebuf = genius->vram + 0x10000; - uint32_t col, dl = genius->displine; + uint32_t col; + uint32_t dl = genius->displine; /* Character height is 12-15 */ if (mda) { @@ -437,7 +447,7 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) else cursorline = ((crtc[10] & 0x1F) <= sc) && ((crtc[11] & 0x1F) >= sc); - for (x = 0; x < w; x++) { + for (int x = 0; x < w; x++) { #if 0 if ((genius->genius_charh & 0x10) && ((addr + 2 * x) > 0x0FFF)) chr = 0x00; @@ -549,9 +559,10 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) void genius_cgaline(genius_t *genius) { - int x, c; - uint32_t dat, addr; - uint8_t ink_f, ink_b; + uint32_t dat; + uint32_t addr; + uint8_t ink_f; + uint8_t ink_b; ink_f = (genius->genius_control & 0x20) ? genius_pal[0] : genius_pal[3]; ink_b = (genius->genius_control & 0x20) ? genius_pal[3] : genius_pal[0]; @@ -564,11 +575,11 @@ genius_cgaline(genius_t *genius) if ((genius->displine - 512) & 2) addr += 0x2000; - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = genius->vram[addr]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { if (dat & 0x80) buffer32->line[genius->displine][(x << 3) + c] = ink_f; else @@ -583,9 +594,10 @@ genius_cgaline(genius_t *genius) void genius_hiresline(genius_t *genius) { - int x, c; - uint32_t dat, addr; - uint8_t ink_f, ink_b; + uint32_t dat; + uint32_t addr; + uint8_t ink_f; + uint8_t ink_b; ink_f = (genius->genius_control & 0x20) ? genius_pal[0] : genius_pal[3]; ink_b = (genius->genius_control & 0x20) ? genius_pal[3] : genius_pal[0]; @@ -596,10 +608,10 @@ genius_hiresline(genius_t *genius) else /* The second 496 live at B8000 */ addr = 0x18000 + (128 * (genius->displine - 512)); - for (x = 0; x < 91; x++) { + for (uint8_t x = 0; x < 91; x++) { dat = genius->vram[addr + x]; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { if (dat & 0x80) buffer32->line[genius->displine][(x << 3) + c] = ink_f; else @@ -611,10 +623,9 @@ genius_hiresline(genius_t *genius) } void -genius_poll(void *p) +genius_poll(void *priv) { - genius_t *genius = (genius_t *) p; - int x; + genius_t *genius = (genius_t *) priv; uint8_t background; if (!genius->linepos) { @@ -633,7 +644,7 @@ genius_poll(void *p) video_wait_for_buffer(); /* Start off with a blank line */ - for (x = 0; x < GENIUS_XSIZE; x++) + for (uint16_t x = 0; x < GENIUS_XSIZE; x++) buffer32->line[genius->displine][x] = background; /* If graphics display enabled, draw graphics on top @@ -714,7 +725,6 @@ void * genius_init(const device_t *info) { - int c; genius_t *genius = malloc(sizeof(genius_t)); memset(genius, 0, sizeof(genius_t)); @@ -744,7 +754,7 @@ void /* MDA attributes */ /* I don't know if the Genius's MDA emulation actually does * emulate bright / non-bright. For the time being pretend it does. */ - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { mdaattr[c][0][0] = mdaattr[c][1][0] = mdaattr[c][1][1] = genius_pal[0]; if (c & 8) mdaattr[c][0][1] = genius_pal[3]; @@ -774,9 +784,9 @@ void } void -genius_close(void *p) +genius_close(void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; free(genius->vram); free(genius); @@ -789,9 +799,9 @@ genius_available(void) } void -genius_speed_changed(void *p) +genius_speed_changed(void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; genius_recalctimings(genius); } diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index 5920ff27d..e2879cec3 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -32,6 +32,7 @@ #include <86box/device.h> #include <86box/video.h> #include <86box/vid_hercules.h> +#include <86box/plat_unused.h> static video_timings_t timing_hercules = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; @@ -39,7 +40,8 @@ static void recalc_timings(hercules_t *dev) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; disptime = dev->crtc[0] + 1; _dispontime = dev->crtc[1]; @@ -187,11 +189,11 @@ hercules_in(uint16_t addr, void *priv) break; } - return (ret); + return ret; } static void -hercules_waitstates(void *p) +hercules_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -236,7 +238,6 @@ hercules_read(uint32_t addr, void *priv) static void hercules_render_overscan_left(hercules_t *dev) { - int i; uint32_t width; if (dev->ctrl & 0x02) @@ -250,14 +251,13 @@ hercules_render_overscan_left(hercules_t *dev) if (width == 0) return; - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) buffer32->line[dev->displine + 14][i] = 0x00000000; } static void hercules_render_overscan_right(hercules_t *dev) { - int i; uint32_t width; if (dev->ctrl & 0x02) @@ -271,7 +271,7 @@ hercules_render_overscan_right(hercules_t *dev) if (width == 0) return; - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) buffer32->line[dev->displine + 14][8 + width + i] = 0x00000000; } @@ -279,11 +279,19 @@ static void hercules_poll(void *priv) { hercules_t *dev = (hercules_t *) priv; - uint8_t chr, attr; - uint16_t ca, dat; + uint8_t chr; + uint8_t attr; + uint16_t ca; + uint16_t dat; uint16_t pa; - int oldsc, blink; - int x, xx, y, yy, c, oldvc; + int oldsc; + int blink; + int x; + int xx; + int y; + int yy; + int c; + int oldvc; int drawcursor; uint32_t *p; @@ -486,7 +494,9 @@ hercules_poll(void *priv) else video_blit_memtoscreen(8, dev->firstline + 14, xsize, ysize); frames++; - // if ((dev->ctrl & 2) && (dev->ctrl2 & 1)) { +#if 0 + if ((dev->ctrl & 2) && (dev->ctrl2 & 1)) { +#endif if (dev->ctrl & 0x02) { video_res_x = dev->crtc[1] * 16; video_res_y = dev->crtc[6] * 4; @@ -507,7 +517,7 @@ hercules_poll(void *priv) dev->ma = dev->maback; } - if ((dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1)))) + if (dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1))) dev->con = 1; if (dev->dispon && !(dev->ctrl & 0x02)) { for (x = 0; x < (dev->crtc[1] << 1); x++) { @@ -520,10 +530,9 @@ hercules_poll(void *priv) } static void * -hercules_init(const device_t *info) +hercules_init(UNUSED(const device_t *info)) { hercules_t *dev; - int c; dev = (hercules_t *) malloc(sizeof(hercules_t)); memset(dev, 0x00, sizeof(hercules_t)); @@ -543,7 +552,7 @@ hercules_init(const device_t *info) io_sethandler(0x03b0, 16, hercules_in, NULL, NULL, hercules_out, NULL, NULL, dev); - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { dev->cols[c][0][0] = dev->cols[c][1][0] = dev->cols[c][1][1] = 16; if (c & 0x08) @@ -578,7 +587,7 @@ hercules_init(const device_t *info) /* Force the LPT3 port to be enabled. */ lpt3_init(0x3BC); - return (dev); + return dev; } static void diff --git a/src/video/vid_herculesplus.c b/src/video/vid_herculesplus.c index 6561f9429..587410c07 100644 --- a/src/video/vid_herculesplus.c +++ b/src/video/vid_herculesplus.c @@ -30,6 +30,7 @@ #include <86box/rom.h> #include <86box/device.h> #include <86box/video.h> +#include <86box/plat_unused.h> /* extended CRTC registers */ #define HERCULESPLUS_CRTC_XMODE 20 /* xMode register */ @@ -103,7 +104,8 @@ static void recalc_timings(herculesplus_t *dev) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; disptime = dev->crtc[0] + 1; _dispontime = dev->crtc[1]; @@ -161,6 +163,9 @@ herculesplus_out(uint16_t port, uint8_t val, void *priv) else mem_mapping_set_addr(&dev->mapping, 0xb0000, 0x08000); return; + + default: + break; } } @@ -190,6 +195,9 @@ herculesplus_in(uint16_t port, void *priv) /* 0x10: Hercules Plus card identity */ ret = (dev->stat & 0xf) | ((dev->stat & 8) << 4) | 0x10; break; + + default: + break; } return ret; @@ -214,9 +222,13 @@ herculesplus_read(uint32_t addr, void *priv) static void draw_char_rom(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) { - unsigned ull, val, ifg, ibg; + unsigned ull; + unsigned val; + unsigned ifg; + unsigned ibg; const uint8_t *fnt; - int i, elg, blk; + int elg; + int blk; int cw = HERCULESPLUS_CW; blk = 0; @@ -259,7 +271,7 @@ draw_char_rom(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) val |= (val >> 1) & 1; } - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { buffer32->line[dev->displine][x * cw + i] = (val & 0x100) ? ifg : ibg; val = val << 1; } @@ -268,9 +280,13 @@ draw_char_rom(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) static void draw_char_ram4(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) { - unsigned ull, val, ibg, cfg; + unsigned ull; + unsigned val; + unsigned ibg; + unsigned cfg; const uint8_t *fnt; - int i, elg, blk; + int elg; + int blk; int cw = HERCULESPLUS_CW; int blink = dev->ctrl & HERCULESPLUS_CTRL_BLINK; @@ -310,7 +326,7 @@ draw_char_ram4(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) val |= (val >> 1) & 1; } - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { /* Generate pixel colour */ cfg = 0; @@ -318,7 +334,7 @@ draw_char_ram4(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) if ((attr & 0x77) == 0) cfg = ibg; /* 'blank' attribute */ - buffer32->line[dev->displine][x * cw + i] = dev->cols[attr][blink][cfg]; + buffer32->line[dev->displine][x * cw + i] = dev->cols[attr][!!blink][cfg]; val = val << 1; } } @@ -326,9 +342,18 @@ draw_char_ram4(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) static void draw_char_ram48(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) { - int i, elg, blk, ul, ol, bld; - unsigned ull, oll, ulc = 0, olc = 0; - unsigned val, ibg, cfg; + int elg; + int blk; + int ul; + int ol; + int bld; + unsigned ull; + unsigned oll; + unsigned ulc = 0; + unsigned olc = 0; + unsigned val; + unsigned ibg; + unsigned cfg; const unsigned char *fnt; int cw = HERCULESPLUS_CW; int blink = dev->ctrl & HERCULESPLUS_CTRL_BLINK; @@ -395,7 +420,7 @@ draw_char_ram48(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) val |= (val >> 1); } - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { /* Generate pixel colour */ cfg = val & 0x100; if (dev->sc == oll) @@ -405,7 +430,7 @@ draw_char_ram48(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) else cfg |= ibg; - buffer32->line[dev->displine][(x * cw) + i] = dev->cols[attr][blink][cfg]; + buffer32->line[dev->displine][(x * cw) + i] = dev->cols[attr][!!blink][cfg]; val = val << 1; } } @@ -414,11 +439,11 @@ static void text_line(herculesplus_t *dev, uint16_t ca) { int drawcursor; - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint32_t col; - for (x = 0; x < dev->crtc[1]; x++) { + for (uint8_t x = 0; x < dev->crtc[1]; x++) { if (dev->ctrl & 8) { chr = dev->vram[(dev->ma << 1) & 0xfff]; attr = dev->vram[((dev->ma << 1) + 1) & 0xfff]; @@ -440,6 +465,9 @@ text_line(herculesplus_t *dev, uint16_t ca) case 5: /* 48k RAMfont */ draw_char_ram48(dev, x, chr, attr); break; + + default: + break; } ++dev->ma; @@ -447,7 +475,7 @@ text_line(herculesplus_t *dev, uint16_t ca) int cw = HERCULESPLUS_CW; col = dev->cols[attr][0][1]; - for (c = 0; c < cw; c++) + for (int c = 0; c < cw; c++) buffer32->line[dev->displine][x * cw + c] = col; } } @@ -457,7 +485,8 @@ static void graphics_line(herculesplus_t *dev) { uint16_t ca; - int x, c, plane = 0; + int c; + int plane = 0; uint16_t val; /* Graphics mode. */ @@ -465,7 +494,7 @@ graphics_line(herculesplus_t *dev) if ((dev->ctrl & HERCULESPLUS_CTRL_PAGE1) && (dev->ctrl2 & HERCULESPLUS_CTRL2_PAGE1)) ca += 0x8000; - for (x = 0; x < dev->crtc[1]; x++) { + for (uint8_t x = 0; x < dev->crtc[1]; x++) { if (dev->ctrl & 8) val = (dev->vram[((dev->ma << 1) & 0x1fff) + ca + 0x10000 * plane] << 8) | dev->vram[((dev->ma << 1) & 0x1fff) + ca + 0x10000 * plane + 1]; @@ -489,7 +518,9 @@ herculesplus_poll(void *priv) { herculesplus_t *dev = (herculesplus_t *) priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; - int x, oldvc, oldsc; + int x; + int oldvc; + int oldsc; VIDEO_MONITOR_PROLOGUE(); if (!dev->linepos) { @@ -612,7 +643,7 @@ herculesplus_poll(void *priv) dev->ma = dev->maback; } - if ((dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1)))) + if (dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1))) dev->con = 1; } @@ -620,10 +651,9 @@ herculesplus_poll(void *priv) } static void * -herculesplus_init(const device_t *info) +herculesplus_init(UNUSED(const device_t *info)) { herculesplus_t *dev; - int c; dev = (herculesplus_t *) malloc(sizeof(herculesplus_t)); memset(dev, 0, sizeof(herculesplus_t)); @@ -641,7 +671,7 @@ herculesplus_init(const device_t *info) io_sethandler(0x03b0, 16, herculesplus_in, NULL, NULL, herculesplus_out, NULL, NULL, dev); - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { dev->cols[c][0][0] = dev->cols[c][1][0] = dev->cols[c][1][1] = 16; if (c & 8) dev->cols[c][0][1] = 15 + 16; diff --git a/src/video/vid_ht216.c b/src/video/vid_ht216.c index 255a9e8b8..bd09a9ede 100644 --- a/src/video/vid_ht216.c +++ b/src/video/vid_ht216.c @@ -35,6 +35,8 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> typedef struct ht216_t { svga_t svga; @@ -92,8 +94,8 @@ typedef struct ht216_t { void ht216_remap(ht216_t *ht216); -void ht216_out(uint16_t addr, uint8_t val, void *p); -uint8_t ht216_in(uint16_t addr, void *p); +void ht216_out(uint16_t addr, uint8_t val, void *priv); +uint8_t ht216_in(uint16_t addr, void *priv); #define BIOS_G2_GC205_PATH "roms/video/video7/BIOS.BIN" #define BIOS_VIDEO7_VGA_1024I_PATH "roms/video/video7/Video Seven VGA 1024i - BIOS - v2.19 - 435-0062-05 - U17 - 27C256.BIN" @@ -164,9 +166,9 @@ ht216_recalc_bank_regs(ht216_t *ht216, int mode) } void -ht216_out(uint16_t addr, uint8_t val, void *p) +ht216_out(uint16_t addr, uint8_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint8_t old; @@ -319,7 +321,9 @@ ht216_out(uint16_t addr, uint8_t val, void *p) svga->adv_flags &= ~FLAG_RAMDAC_SHIFT; if (val & 0x04) svga->adv_flags |= FLAG_RAMDAC_SHIFT; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif /*Bank registers*/ case 0xe8: case 0xe9: @@ -463,9 +467,9 @@ ht216_out(uint16_t addr, uint8_t val, void *p) } uint8_t -ht216_in(uint16_t addr, void *p) +ht216_in(uint16_t addr, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint8_t ret = 0xff; @@ -606,7 +610,7 @@ ht216_remap(ht216_t *ht216) void ht216_recalctimings(svga_t *svga) { - ht216_t *ht216 = (ht216_t *) svga->p; + ht216_t *ht216 = (ht216_t *) svga->priv; int high_res_256 = 0; switch ((((((svga->miscout >> 2) & 3) || ((ht216->ht_regs[0xa4] >> 2) & 3)) | ((ht216->ht_regs[0xa4] >> 2) & 4)) || ((ht216->ht_regs[0xf8] >> 5) & 0x0f)) | ((ht216->ht_regs[0xf8] << 1) & 8)) { @@ -614,16 +618,16 @@ ht216_recalctimings(svga_t *svga) case 1: break; case 4: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50350000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; break; case 5: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; break; case 7: - svga->clock = (cpuclock * (double) (1ull << 32)) / 40000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 40000000.0; break; default: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; } @@ -702,8 +706,8 @@ ht216_recalctimings(svga_t *svga) static void ht216_hwcursor_draw(svga_t *svga, int displine) { - ht216_t *ht216 = (ht216_t *) svga->p; - int x, shift = (ht216->adjust_cursor ? 2 : 1); + ht216_t *ht216 = (ht216_t *) svga->priv; + int shift = (ht216->adjust_cursor ? 2 : 1); uint32_t dat[2]; int offset = svga->hwcursor_latch.x + svga->hwcursor_latch.xoff; int width = (ht216->adjust_cursor ? 16 : 32); @@ -717,7 +721,7 @@ ht216_hwcursor_draw(svga_t *svga, int displine) dat[0] = (svga->vram[svga->hwcursor_latch.addr] << 24) | (svga->vram[svga->hwcursor_latch.addr + 1] << 16) | (svga->vram[svga->hwcursor_latch.addr + 2] << 8) | svga->vram[svga->hwcursor_latch.addr + 3]; dat[1] = (svga->vram[svga->hwcursor_latch.addr + 128] << 24) | (svga->vram[svga->hwcursor_latch.addr + 128 + 1] << 16) | (svga->vram[svga->hwcursor_latch.addr + 128 + 2] << 8) | svga->vram[svga->hwcursor_latch.addr + 128 + 3]; - for (x = 0; x < width; x++) { + for (int x = 0; x < width; x++) { if (!(dat[0] & 0x80000000)) ((uint32_t *) buffer32->line[displine])[svga->x_add + offset + x] = 0; if (dat[1] & 0x80000000) @@ -796,10 +800,13 @@ static void ht216_dm_write(ht216_t *ht216, uint32_t addr, uint8_t cpu_dat, uint8_t cpu_dat_unexpanded) { svga_t *svga = &ht216->svga; - int writemask2 = svga->writemask, reset_wm = 0; + int writemask2 = svga->writemask; + int reset_wm = 0; latch_t vall; - uint8_t i, wm = svga->writemask; - uint8_t count = 4, fg_data[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + uint8_t i; + uint8_t wm = svga->writemask; + uint8_t count = 4; + uint8_t fg_data[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; if (ht216->ht_regs[0xcd] & HT_REG_CD_P8PCEXP) writemask2 = svga->seqregs[2]; @@ -984,8 +991,10 @@ ht216_dm_extalu_write(ht216_t *ht216, uint32_t addr, uint8_t cpu_dat, uint8_t bi 01 = Bit mask (3CF:8) 1x = (3C4:F5)*/ svga_t *svga = &ht216->svga; - uint8_t input_a = 0, input_b = 0; - uint8_t fg, bg; + uint8_t input_a = 0; + uint8_t input_b = 0; + uint8_t fg; + uint8_t bg; uint8_t output; uint32_t remapped_addr = dword_remap(svga, addr); @@ -1024,7 +1033,8 @@ ht216_dm_masked_write(ht216_t *ht216, uint32_t addr, uint8_t val, uint8_t bit_ma { svga_t *svga = &ht216->svga; int writemask2 = svga->writemask; - uint8_t count = 4, i; + uint8_t count = 4; + uint8_t i; uint8_t full_mask = 0x0f; if (ht216->ht_regs[0xcd] & HT_REG_CD_P8PCEXP) @@ -1098,7 +1108,8 @@ ht216_write_common(ht216_t *ht216, uint32_t addr, uint8_t val) */ svga_t *svga = &ht216->svga; int i; - uint8_t bit_mask = 0, rop_select = 0; + uint8_t bit_mask = 0; + uint8_t rop_select = 0; cycles -= video_timing_write_b; @@ -1157,9 +1168,9 @@ ht216_write_common(ht216_t *ht216, uint32_t addr, uint8_t val) } static void -ht216_write(uint32_t addr, uint8_t val, void *p) +ht216_write(uint32_t addr, uint8_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1178,9 +1189,9 @@ ht216_write(uint32_t addr, uint8_t val, void *p) } static void -ht216_writew(uint32_t addr, uint16_t val, void *p) +ht216_writew(uint32_t addr, uint16_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1201,9 +1212,9 @@ ht216_writew(uint32_t addr, uint16_t val, void *p) } static void -ht216_writel(uint32_t addr, uint32_t val, void *p) +ht216_writel(uint32_t addr, uint32_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1226,9 +1237,9 @@ ht216_writel(uint32_t addr, uint32_t val, void *p) } static void -ht216_write_linear(uint32_t addr, uint8_t val, void *p) +ht216_write_linear(uint32_t addr, uint8_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1243,9 +1254,9 @@ ht216_write_linear(uint32_t addr, uint8_t val, void *p) } static void -ht216_writew_linear(uint32_t addr, uint16_t val, void *p) +ht216_writew_linear(uint32_t addr, uint16_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1262,9 +1273,9 @@ ht216_writew_linear(uint32_t addr, uint16_t val, void *p) } static void -ht216_writel_linear(uint32_t addr, uint32_t val, void *p) +ht216_writel_linear(uint32_t addr, uint32_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1287,11 +1298,12 @@ ht216_read_common(ht216_t *ht216, uint32_t addr) { svga_t *svga = &ht216->svga; uint32_t latch_addr = 0; - int offset, readplane = svga->readplane; - uint8_t or, i; - uint8_t count = 2; - uint8_t plane, pixel; - uint8_t temp, ret; + int offset; + int readplane = svga->readplane; + uint8_t or; + uint8_t count = 2; + uint8_t temp; + uint8_t ret; if (ht216->ht_regs[0xc8] & HT_REG_C8_MOVSB) addr <<= 3; @@ -1309,7 +1321,7 @@ ht216_read_common(ht216_t *ht216, uint32_t addr) latch_addr = (addr & svga->vram_mask) & ~7; if (ht216->ht_regs[0xcd] & HT_REG_CD_ASTODE) latch_addr += (svga->gdcreg[3] & 7); - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) ht216->bg_latch[i] = svga->vram[dword_remap(svga, latch_addr + i)]; return svga->vram[dword_remap(svga, addr) & svga->vram_mask]; } else if (svga->chain4) { @@ -1332,22 +1344,22 @@ ht216_read_common(ht216_t *ht216, uint32_t addr) latch_addr = addr & ~7; if (ht216->ht_regs[0xcd] & HT_REG_CD_ASTODE) { offset = addr & 7; - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) ht216->bg_latch[i] = svga->vram[latch_addr | ((offset + i) & 7)]; } else { - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) ht216->bg_latch[i] = svga->vram[latch_addr | i]; } or = addr & 4; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) svga->latch.b[i] = ht216->bg_latch[i | or ]; if (svga->readmode) { temp = 0xff; - for (pixel = 0; pixel < 8; pixel++) { - for (plane = 0; plane < (1 << count); plane++) { + for (uint8_t pixel = 0; pixel < 8; pixel++) { + for (uint8_t plane = 0; plane < (uint8_t)(1 << count); plane++) { if (svga->colournocare & (1 << plane)) { /* If we care about a plane, and the pixel has a mismatch on it, clear its bit. */ if (((svga->latch.b[plane] >> pixel) & 1) != ((svga->colourcompare >> plane) & 1)) @@ -1364,9 +1376,9 @@ ht216_read_common(ht216_t *ht216, uint32_t addr) } static uint8_t -ht216_read(uint32_t addr, void *p) +ht216_read(uint32_t addr, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1382,9 +1394,9 @@ ht216_read(uint32_t addr, void *p) } static uint8_t -ht216_read_linear(uint32_t addr, void *p) +ht216_read_linear(uint32_t addr, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1419,7 +1431,7 @@ radius_mca_write(int port, uint8_t val, void *priv) } static uint8_t -radius_mca_feedb(void *priv) +radius_mca_feedb(UNUSED(void *priv)) { return 1; } @@ -1603,9 +1615,9 @@ radius_svga_multiview_available(void) } void -ht216_close(void *p) +ht216_close(void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_close(&ht216->svga); @@ -1613,17 +1625,17 @@ ht216_close(void *p) } void -ht216_speed_changed(void *p) +ht216_speed_changed(void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_recalctimings(&ht216->svga); } void -ht216_force_redraw(void *p) +ht216_force_redraw(void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; ht216->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ibm_rgb528_ramdac.c b/src/video/vid_ibm_rgb528_ramdac.c index adfc6ea39..b7a27781b 100644 --- a/src/video/vid_ibm_rgb528_ramdac.c +++ b/src/video/vid_ibm_rgb528_ramdac.c @@ -25,6 +25,7 @@ #include <86box/timer.h> #include <86box/video.h> #include <86box/vid_svga.h> +#include <86box/plat_unused.h> typedef union { uint8_t pixel; @@ -74,7 +75,6 @@ typedef struct void ibm_rgb528_render_4bpp(svga_t *svga) { - int x; uint32_t *p; ibm_rgb528_pixel32_t dat_out; uint8_t dat; @@ -98,7 +98,7 @@ ibm_rgb528_render_4bpp(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { + for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 3) { if (!(x & 31)) { dat64 = *(uint64_t *) (&svga->vram[svga->ma]); @@ -155,7 +155,6 @@ ibm_rgb528_render_4bpp(svga_t *svga) void ibm_rgb528_render_8bpp(svga_t *svga) { - int x; uint32_t *p; ibm_rgb528_pixel32_t dat_out; uint8_t dat; @@ -177,7 +176,7 @@ ibm_rgb528_render_8bpp(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { + for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 3) { if (!(x & 15)) { dat64 = *(uint64_t *) (&svga->vram[svga->ma]); @@ -225,7 +224,6 @@ ibm_rgb528_render_8bpp(svga_t *svga) void ibm_rgb528_render_15_16bpp(svga_t *svga) { - int x; uint32_t *p; ibm_rgb528_pixel16_t *dat_ex; ibm_rgb528_pixel32_t dat_out; @@ -242,7 +240,8 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) uint8_t b6bit_lin = ramdac->indexed_data[0x07] & 0x80; uint8_t swaprb = ramdac->indexed_data[0x72] & 0x80; uint8_t swap_word = ramdac->indexed_data[0x72] & 0x10; - uint8_t vram_size = ramdac->indexed_data[0x70] & 0x01, temp; + uint8_t vram_size = ramdac->indexed_data[0x70] & 0x01; + uint8_t temp; if ((svga->displine + svga->y_add) < 0) return; @@ -257,7 +256,7 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { + for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 2) { if (!(x & 7)) { dat64 = *(uint64_t *) (&svga->vram[svga->ma]); @@ -350,7 +349,6 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) void ibm_rgb528_render_24bpp(svga_t *svga) { - int x; uint32_t *p; ibm_rgb528_pixel32_t *dat_ex; uint32_t dat; @@ -361,7 +359,8 @@ ibm_rgb528_render_24bpp(svga_t *svga) uint8_t swaprb = ramdac->indexed_data[0x72] & 0x80; uint8_t swap_word = ramdac->indexed_data[0x72] & 0x10; uint8_t vram_size = ramdac->indexed_data[0x70] & 0x01; - uint8_t b6bit_lin = ramdac->indexed_data[0x07] & 0x80, temp; + uint8_t b6bit_lin = ramdac->indexed_data[0x07] & 0x80; + uint8_t temp; if ((svga->displine + svga->y_add) < 0) return; @@ -373,7 +372,7 @@ ibm_rgb528_render_24bpp(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { + for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { dat_ex = (ibm_rgb528_pixel32_t *) &dat; if (vram_size == 3) { if ((x & 15) == 0) { @@ -392,7 +391,7 @@ ibm_rgb528_render_24bpp(svga_t *svga) dat64[5] = (dat64[5] << 32ULL) | (dat64[5] >> 32ULL); } } - dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[((x & 15) * 3)]); + dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[(x & 15) * 3]); } else if (vram_size == 1) { if ((x & 7) == 0) { dat64[0] = *(uint64_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); @@ -404,7 +403,7 @@ ibm_rgb528_render_24bpp(svga_t *svga) dat64[2] = (dat64[2] << 32ULL) | (dat64[2] >> 32ULL); } } - dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[((x & 7) * 3)]); + dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[(x & 7) * 3]); } else dat = 0x00000000; if (swaprb) { @@ -439,7 +438,6 @@ ibm_rgb528_render_24bpp(svga_t *svga) void ibm_rgb528_render_32bpp(svga_t *svga) { - int x; uint32_t *p; ibm_rgb528_pixel32_t *dat_ex; uint32_t dat = 0x00000000; @@ -451,7 +449,8 @@ ibm_rgb528_render_32bpp(svga_t *svga) uint8_t swaprb = ramdac->indexed_data[0x72] & 0x80; uint8_t swap_word = ramdac->indexed_data[0x72] & 0x10; uint8_t vram_size = ramdac->indexed_data[0x70] & 0x01; - uint8_t b6bit_lin = ramdac->indexed_data[0x07] & 0x80, temp; + uint8_t b6bit_lin = ramdac->indexed_data[0x07] & 0x80; + uint8_t temp; if ((svga->displine + svga->y_add) < 0) return; @@ -463,7 +462,7 @@ ibm_rgb528_render_32bpp(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { + for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 3) { if (!(x & 3)) { dat64 = *(uint64_t *) (&svga->vram[svga->ma]); @@ -489,7 +488,7 @@ ibm_rgb528_render_32bpp(svga_t *svga) dat_ex->r = dat_ex->b; dat_ex->b = temp; } - if ((b32_dcol < 0x03) && (by32_pol)) + if ((b32_dcol < 0x03) && by32_pol) dat ^= 0x01000000; if ((b32_dcol == 0x00) || ((b32_dcol == 0x01) && !(dat & 0x01000000))) { dat_ex->a = 0x00; @@ -825,8 +824,12 @@ ibm_rgb528_recalctimings(void *p, svga_t *svga) void ibm_rgb528_hwcursor_draw(svga_t *svga, int displine) { - uint8_t dat, four_pixels = 0x00; - int x, pitch, x_pos, y_pos, offset = svga->dac_hwcursor_latch.x - svga->dac_hwcursor_latch.xoff; + uint8_t dat; + uint8_t four_pixels = 0x00; + int pitch; + int x_pos; + int y_pos; + int offset = svga->dac_hwcursor_latch.x - svga->dac_hwcursor_latch.xoff; uint32_t *p; ibm_rgb528_ramdac_t *ramdac = (ibm_rgb528_ramdac_t *) svga->ramdac; uint8_t pix_ordr = ramdac->indexed_data[0x30] & 0x20; @@ -844,7 +847,7 @@ ibm_rgb528_hwcursor_draw(svga_t *svga, int displine) x_pos = offset + svga->x_add; p = buffer32->line[y_pos]; - for (x = 0; x < svga->dac_hwcursor_latch.cur_xsize; x++) { + for (int x = 0; x < svga->dac_hwcursor_latch.cur_xsize; x++) { if (!(x & 3)) four_pixels = ramdac->indexed_data[svga->dac_hwcursor_latch.addr]; @@ -911,7 +914,7 @@ ibm_rgb528_hwcursor_draw(svga_t *svga, int displine) } void * -ibm_rgb528_ramdac_init(const device_t *info) +ibm_rgb528_ramdac_init(UNUSED(const device_t *info)) { ibm_rgb528_ramdac_t *ramdac = (ibm_rgb528_ramdac_t *) malloc(sizeof(ibm_rgb528_ramdac_t)); memset(ramdac, 0, sizeof(ibm_rgb528_ramdac_t)); diff --git a/src/video/vid_icd2061.c b/src/video/vid_icd2061.c index 3fafb65d9..adfaf6ad4 100644 --- a/src/video/vid_icd2061.c +++ b/src/video/vid_icd2061.c @@ -29,6 +29,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> +#include <86box/plat_unused.h> typedef struct icd2061_t { float freq[3]; @@ -61,8 +62,16 @@ icd2061_write(void *p, int val) { icd2061_t *icd2061 = (icd2061_t *) p; - int nd, oc, nc; - int a, qa, q, pa, p_, m, ps; + int nd; + int oc; + int nc; + int a; + int qa; + int q; + int pa; + int p_; + int m; + int ps; nd = (val & 2) >> 1; /* Old data. */ oc = icd2061->state & 1; /* Old clock. */ @@ -127,9 +136,9 @@ icd2061_write(void *p, int val) } float -icd2061_getclock(int clock, void *p) +icd2061_getclock(int clock, void *priv) { - icd2061_t *icd2061 = (icd2061_t *) p; + icd2061_t *icd2061 = (icd2061_t *) priv; if (clock > 2) clock = 2; @@ -138,7 +147,7 @@ icd2061_getclock(int clock, void *p) } static void * -icd2061_init(const device_t *info) +icd2061_init(UNUSED(const device_t *info)) { icd2061_t *icd2061 = (icd2061_t *) malloc(sizeof(icd2061_t)); memset(icd2061, 0, sizeof(icd2061_t)); diff --git a/src/video/vid_ics2494.c b/src/video/vid_ics2494.c index 8bb4b0cb8..16c4139fe 100644 --- a/src/video/vid_ics2494.c +++ b/src/video/vid_ics2494.c @@ -49,12 +49,12 @@ ics2494_log(const char *fmt, ...) #endif float -ics2494_getclock(int clock, void *p) +ics2494_getclock(int clock, void *priv) { - ics2494_t *ics2494 = (ics2494_t *) p; + ics2494_t *ics2494 = (ics2494_t *) priv; - if (clock > 16) - clock = 16; + if (clock > 15) + clock = 15; return ics2494->freq[clock]; } diff --git a/src/video/vid_ics2595.c b/src/video/vid_ics2595.c index 10fc5ba39..6420ee7e4 100644 --- a/src/video/vid_ics2595.c +++ b/src/video/vid_ics2595.c @@ -23,6 +23,7 @@ #include #include <86box/86box.h> #include <86box/device.h> +#include <86box/plat_unused.h> typedef struct ics2595_t { int oldfs3, oldfs2; @@ -45,7 +46,8 @@ void ics2595_write(void *p, int strobe, int dat) { ics2595_t *ics2595 = (ics2595_t *) p; - int d, n; + int d; + int n; int l; if (strobe) { @@ -69,6 +71,9 @@ ics2595_write(void *p, int strobe, int dat) ics2595->state = ICS2595_IDLE; } break; + + default: + break; } } @@ -80,7 +85,7 @@ ics2595_write(void *p, int strobe, int dat) } static void * -ics2595_init(const device_t *info) +ics2595_init(UNUSED(const device_t *info)) { ics2595_t *ics2595 = (ics2595_t *) malloc(sizeof(ics2595_t)); memset(ics2595, 0, sizeof(ics2595_t)); @@ -98,9 +103,9 @@ ics2595_close(void *priv) } double -ics2595_getclock(void *p) +ics2595_getclock(void *priv) { - ics2595_t *ics2595 = (ics2595_t *) p; + ics2595_t *ics2595 = (ics2595_t *) priv; return ics2595->output_clock; } diff --git a/src/video/vid_im1024.c b/src/video/vid_im1024.c index 12d884127..25ba92e9c 100644 --- a/src/video/vid_im1024.c +++ b/src/video/vid_im1024.c @@ -147,7 +147,7 @@ fifo_read(im1024_t *dev) im1024_log("IM1024: fifo_read: %02x\n", ret); - return (ret); + return ret; } /* @@ -168,12 +168,12 @@ input_byte(pgc_t *pgc, uint8_t *result) } if (pgc->stopped) - return (0); + return 0; if (pgc->mapram[0x3ff]) { /* Reset triggered. */ pgc_reset(pgc); - return (0); + return 0; } if (dev->fifo_wrptr == dev->fifo_rdptr) { @@ -182,7 +182,7 @@ input_byte(pgc_t *pgc, uint8_t *result) } else *result = fifo_read(dev); - return (1); + return 1; } /* Macros to disable clipping and save clip state. */ @@ -214,7 +214,7 @@ im1024_read(uint32_t addr, void *priv) if (addr == 0xc6331 && dev->pgc.mapram[0x330] == 1) { /* Hardcode that there are 128 bytes free. */ - return (0x80); + return 0x80; } return (pgc_read(addr, &dev->pgc)); @@ -255,8 +255,10 @@ hndl_imgsiz(pgc_t *pgc) #if 0 im1024_t *dev = (im1024_t *)pgc; #endif - int16_t w, h; - uint8_t a, b; + int16_t w; + int16_t h; + uint8_t a; + uint8_t b; if (!pgc_param_word(pgc, &w)) return; @@ -318,7 +320,8 @@ hndl_linfun(pgc_t *pgc) static void hndl_pan(pgc_t *pgc) { - int16_t x, y; + int16_t x; + int16_t y; if (!pgc_param_word(pgc, &x)) return; @@ -335,7 +338,8 @@ hndl_pan(pgc_t *pgc) static void hndl_pline(pgc_t *pgc) { - int16_t x[257], y[257]; + int16_t x[257]; + int16_t y[257]; uint16_t linemask = pgc->line_pattern; uint8_t count; unsigned n; @@ -405,9 +409,12 @@ blkmov_row(pgc_t *pgc, int16_t x0, int16_t x1, int16_t x2, int16_t sy, int16_t t static void hndl_blkmov(pgc_t *pgc) { - int16_t x0, y0; - int16_t x1, y1; - int16_t x2, y2; + int16_t x0; + int16_t y0; + int16_t x1; + int16_t y1; + int16_t x2; + int16_t y2; int16_t y; if (!pgc_param_word(pgc, &x0)) @@ -451,7 +458,8 @@ hndl_blkmov(pgc_t *pgc) static void hndl_ellipse(pgc_t *pgc) { - int16_t x, y; + int16_t x; + int16_t y; if (!pgc_param_word(pgc, &x)) return; @@ -471,7 +479,8 @@ hndl_ellipse(pgc_t *pgc) static void hndl_move(pgc_t *pgc) { - int16_t x, y; + int16_t x; + int16_t y; if (!pgc_param_word(pgc, &x)) return; @@ -491,7 +500,8 @@ hndl_move(pgc_t *pgc) static void hndl_draw(pgc_t *pgc) { - int16_t x, y; + int16_t x; + int16_t y; if (!pgc_param_word(pgc, &x)) return; @@ -513,10 +523,16 @@ hndl_draw(pgc_t *pgc) static void hndl_poly(pgc_t *pgc) { - int32_t *x, *y, *nx, *ny; - int16_t xw, yw, mask; + int32_t *x; + int32_t *y; + int32_t *nx; + int32_t *ny; + int16_t xw; + int16_t yw; + int16_t mask; unsigned realcount = 0; - unsigned n, as = 256; + unsigned n; + unsigned as = 256; int parsing = 1; uint8_t count; @@ -596,7 +612,7 @@ hndl_poly(pgc_t *pgc) /* Swallow the POLY. */ pgc->clcur->rdptr++; } - }; + } im1024_log("IM1024: POLY (%i) fill_mode=%i\n", realcount, pgc->fill_mode); #ifdef ENABLE_IM1024_LOG @@ -619,7 +635,7 @@ hndl_poly(pgc_t *pgc) } static int -parse_poly(pgc_t *pgc, pgc_cl_t *cl, int c) +parse_poly(pgc_t *pgc, pgc_cl_t *cl, UNUSED(int c)) { uint8_t count; @@ -648,7 +664,12 @@ parse_poly(pgc_t *pgc, pgc_cl_t *cl, int c) static void hndl_rect(pgc_t *pgc) { - int16_t x0, y0, x1, y1, p, q; + int16_t x0; + int16_t y0; + int16_t x1; + int16_t y1; + int16_t p; + int16_t q; x0 = pgc->x >> 16; y0 = pgc->y >> 16; @@ -698,9 +719,11 @@ static void hndl_tdefin(pgc_t *pgc) { im1024_t *dev = (im1024_t *) pgc; - uint8_t ch, bt; - uint8_t rows, cols; - unsigned len, n; + uint8_t ch; + uint8_t bt; + uint8_t rows; + uint8_t cols; + unsigned len; if (!pgc_param_byte(pgc, &ch)) return; @@ -713,7 +736,7 @@ hndl_tdefin(pgc_t *pgc) ch, rows, cols, pgc->mapram[0x300], pgc->mapram[0x301]); len = ((cols + 7) / 8) * rows; - for (n = 0; n < len; n++) { + for (unsigned int n = 0; n < len; n++) { if (!pgc_param_byte(pgc, &bt)) return; @@ -742,8 +765,11 @@ hndl_twrite(pgc_t *pgc) { uint8_t buf[256]; im1024_t *dev = (im1024_t *) pgc; - uint8_t count, mask, *row; - int x, y, wb, n; + uint8_t count; + uint8_t mask; + uint8_t *row; + int wb; + int n; int16_t x0 = pgc->x >> 16; int16_t y0 = pgc->y >> 16; @@ -764,10 +790,10 @@ hndl_twrite(pgc_t *pgc) im1024_log("IM1024: ch=0x%02x w=%i h=%i wb=%i\n", buf[n], dev->fontx[buf[n]], dev->fonty[buf[n]], wb); - for (y = 0; y < dev->fonty[buf[n]]; y++) { + for (uint8_t y = 0; y < dev->fonty[buf[n]]; y++) { mask = 0x80; row = &dev->font[buf[n]][y * wb]; - for (x = 0; x < dev->fontx[buf[n]]; x++) { + for (uint8_t x = 0; x < dev->fontx[buf[n]]; x++) { if (row[0] & mask) pgc_plot(pgc, x + x0, y0 - y); mask = mask >> 1; @@ -786,11 +812,12 @@ static void hndl_txt88(pgc_t *pgc) { uint8_t buf[256]; - uint8_t count, mask, *row; + uint8_t count; + uint8_t mask; + uint8_t *row; int16_t x0 = pgc->x >> 16; int16_t y0 = pgc->y >> 16; unsigned n; - int x, y; if (!pgc_param_byte(pgc, &count)) return; @@ -807,10 +834,10 @@ hndl_txt88(pgc_t *pgc) for (n = 0; n < count; n++) { im1024_log("ch=0x%02x w=12 h=18\n", buf[n]); - for (y = 0; y < 18; y++) { + for (uint8_t y = 0; y < 18; y++) { mask = 0x80; row = &fontdat12x18[buf[n]][y * 2]; - for (x = 0; x < 12; x++) { + for (uint8_t x = 0; x < 12; x++) { if (row[0] & mask) pgc_plot(pgc, x + x0, y0 - y); mask = mask >> 1; @@ -828,9 +855,15 @@ hndl_txt88(pgc_t *pgc) static void hndl_imagew(pgc_t *pgc) { - int16_t vp_x1, vp_y1, vp_x2, vp_y2; - int16_t row1, col1, col2; - uint8_t v1, v2; + int16_t vp_x1; + int16_t vp_y1; + int16_t vp_x2; + int16_t vp_y2; + int16_t row1; + int16_t col1; + int16_t col2; + uint8_t v1; + uint8_t v2; if (!pgc_param_word(pgc, &row1)) return; @@ -908,8 +941,8 @@ hndl_imagew(pgc_t *pgc) static void hndl_dot(pgc_t *pgc) { - int16_t x = pgc->x >> 16, - y = pgc->y >> 16; + int16_t x = pgc->x >> 16; + int16_t y = pgc->y >> 16; pgc_sto_raster(pgc, &x, &y); @@ -928,8 +961,10 @@ hndl_dot(pgc_t *pgc) static void hndl_imagex(pgc_t *pgc) { - int16_t x0, x1, y0, y1; - int16_t p, q; + int16_t x0; + int16_t x1; + int16_t y0; + int16_t y1; if (!pgc_param_word(pgc, &x0)) return; @@ -943,8 +978,8 @@ hndl_imagex(pgc_t *pgc) /* Already using raster coordinates, no need to convert. */ im1024_log("IM1024: IMAGEX (%i,%i,%i,%i)\n", x0, y0, x1, y1); - for (p = y0; p <= y1; p++) { - for (q = x0; q <= x1; q++) { + for (int16_t p = y0; p <= y1; p++) { + for (int16_t q = x0; q <= x1; q++) { if (!pgc_result_byte(pgc, pgc_read_pixel(pgc, q, p))) return; } @@ -996,7 +1031,7 @@ static const pgc_cmd_t im1024_commands[] = { }; static void * -im1024_init(const device_t *info) +im1024_init(UNUSED(const device_t *info)) { im1024_t *dev; @@ -1020,7 +1055,7 @@ im1024_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_CGA, &timing_im1024); - return (dev); + return dev; } static void diff --git a/src/video/vid_incolor.c b/src/video/vid_incolor.c index 68673c061..7a3b416fc 100644 --- a/src/video/vid_incolor.c +++ b/src/video/vid_incolor.c @@ -30,6 +30,7 @@ #include <86box/rom.h> #include <86box/device.h> #include <86box/video.h> +#include <86box/plat_unused.h> /* extended CRTC registers */ #define INCOLOR_CRTC_XMODE 20 /* xMode register */ @@ -186,7 +187,8 @@ static void recalc_timings(incolor_t *dev) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; disptime = dev->crtc[0] + 1; _dispontime = dev->crtc[1]; @@ -299,10 +301,8 @@ incolor_write(uint32_t addr, uint8_t val, void *priv) unsigned char fg = dev->crtc[INCOLOR_CRTC_RWCOL] & 0x0F; unsigned char bg = (dev->crtc[INCOLOR_CRTC_RWCOL] >> 4) & 0x0F; unsigned char w = 0; - unsigned char vmask; /* Mask of bit within byte */ unsigned char pmask; /* Mask of plane within colour value */ unsigned char latch; - int plane; addr &= 0xffff; @@ -319,13 +319,13 @@ incolor_write(uint32_t addr, uint8_t val, void *priv) * 3: 1 => source latch, 0 => ~source latch */ pmask = 1; - for (plane = 0; plane < 4; pmask <<= 1, wmask >>= 1, addr += 0x10000, plane++) { + for (uint8_t plane = 0; plane < 4; pmask <<= 1, wmask >>= 1, addr += 0x10000, plane++) { if (wmask & 0x10) /* Ignore writes to selected plane */ { continue; } latch = dev->latch[plane]; - for (vmask = 0x80; vmask != 0; vmask >>= 1) { + for (unsigned char vmask = 0x80 /* Mask of bit within byte */; vmask != 0; vmask >>= 1) { switch (wmode) { case 0x00: if (val & vmask) @@ -375,7 +375,7 @@ incolor_read(uint32_t addr, void *priv) unsigned char dc; /* "don't care" register */ unsigned char bg; /* background colour */ unsigned char fg; - unsigned char mask, pmask; + unsigned char pmask; addr &= 0xffff; @@ -393,7 +393,7 @@ incolor_read(uint32_t addr, void *priv) } /* For each pixel, work out if its colour matches the background */ - for (mask = 0x80; mask != 0; mask >>= 1) { + for (unsigned char mask = 0x80; mask != 0; mask >>= 1) { fg = 0; dc = dev->crtc[INCOLOR_CRTC_RWCTRL] & 0x0F; bg = (dev->crtc[INCOLOR_CRTC_RWCOL] >> 4) & 0x0F; @@ -417,13 +417,15 @@ incolor_read(uint32_t addr, void *priv) static void draw_char_rom(incolor_t *dev, int x, uint8_t chr, uint8_t attr) { - int i; - int elg, blk; + int elg; + int blk; unsigned ull; unsigned val; - unsigned ifg, ibg; + unsigned ifg; + unsigned ibg; const unsigned char *fnt; - uint32_t fg, bg; + uint32_t fg; + uint32_t bg; int cw = INCOLOR_CW; blk = 0; @@ -488,7 +490,7 @@ draw_char_rom(incolor_t *dev, int x, uint8_t chr, uint8_t attr) val |= (val >> 1) & 1; } } - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { buffer32->line[dev->displine][x * cw + i] = (val & 0x100) ? fg : bg; val = val << 1; } @@ -497,11 +499,14 @@ draw_char_rom(incolor_t *dev, int x, uint8_t chr, uint8_t attr) static void draw_char_ram4(incolor_t *dev, int x, uint8_t chr, uint8_t attr) { - int i; - int elg, blk; + int elg; + int blk; unsigned ull; unsigned val[4]; - unsigned ifg, ibg, cfg, pmask, plane; + unsigned ifg; + unsigned ibg; + unsigned cfg; + unsigned pmask; const unsigned char *fnt; uint32_t fg; int cw = INCOLOR_CW; @@ -569,11 +574,11 @@ draw_char_ram4(incolor_t *dev, int x, uint8_t chr, uint8_t attr) val[3] |= (val[3] >> 1) & 1; } } - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { /* Generate pixel colour */ cfg = 0; pmask = 1; - for (plane = 0; plane < 4; plane++, pmask = pmask << 1) { + for (uint8_t plane = 0; plane < 4; plane++, pmask = pmask << 1) { if (val[plane] & 0x100) cfg |= (ifg & pmask); else @@ -599,11 +604,20 @@ draw_char_ram4(incolor_t *dev, int x, uint8_t chr, uint8_t attr) static void draw_char_ram48(incolor_t *dev, int x, uint8_t chr, uint8_t attr) { - int i; - int elg, blk, ul, ol, bld; - unsigned ull, oll, ulc = 0, olc = 0; + int elg; + int blk; + int ul; + int ol; + int bld; + unsigned ull; + unsigned oll; + unsigned ulc = 0; + unsigned olc = 0; unsigned val[4]; - unsigned ifg = 0, ibg, cfg, pmask, plane; + unsigned ifg = 0; + unsigned ibg; + unsigned cfg; + unsigned pmask; const unsigned char *fnt; uint32_t fg; int cw = INCOLOR_CW; @@ -692,7 +706,7 @@ draw_char_ram48(incolor_t *dev, int x, uint8_t chr, uint8_t attr) val[3] |= (val[3] >> 1); } } - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { /* Generate pixel colour */ cfg = 0; pmask = 1; @@ -701,7 +715,7 @@ draw_char_ram48(incolor_t *dev, int x, uint8_t chr, uint8_t attr) } else if (dev->sc == ull) { cfg = ulc ^ ibg; /* Underline */ } else { - for (plane = 0; plane < 4; plane++, pmask = pmask << 1) { + for (uint8_t plane = 0; plane < 4; plane++, pmask = pmask << 1) { if (val[plane] & 0x100) { if (altattr) cfg |= ((~ibg) & pmask); @@ -729,11 +743,11 @@ static void text_line(incolor_t *dev, uint16_t ca) { int drawcursor; - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint32_t col; - for (x = 0; x < dev->crtc[1]; x++) { + for (uint8_t x = 0; x < dev->crtc[1]; x++) { if (dev->ctrl & 8) { chr = dev->vram[(dev->ma << 1) & 0xfff]; attr = dev->vram[((dev->ma << 1) + 1) & 0xfff]; @@ -774,7 +788,7 @@ text_line(incolor_t *dev, uint16_t ca) } else { col = dev->rgb[defpal[ink]]; } - for (c = 0; c < cw; c++) { + for (int c = 0; c < cw; c++) { buffer32->line[dev->displine][x * cw + c] = col; } } @@ -786,7 +800,8 @@ graphics_line(incolor_t *dev) { uint8_t mask; uint16_t ca; - int x, c, plane, col; + int plane; + int col; uint8_t ink; uint16_t val[4]; @@ -795,7 +810,7 @@ graphics_line(incolor_t *dev) if ((dev->ctrl & INCOLOR_CTRL_PAGE1) && (dev->ctrl2 & INCOLOR_CTRL2_PAGE1)) ca += 0x8000; - for (x = 0; x < dev->crtc[1]; x++) { + for (uint8_t x = 0; x < dev->crtc[1]; x++) { mask = dev->crtc[INCOLOR_CRTC_MASK]; /* Planes to display */ for (plane = 0; plane < 4; plane++, mask = mask >> 1) { if (dev->ctrl & 8) { @@ -808,7 +823,7 @@ graphics_line(incolor_t *dev) } dev->ma++; - for (c = 0; c < 16; c++) { + for (uint8_t c = 0; c < 16; c++) { ink = 0; for (plane = 0; plane < 4; plane++) { ink = ink >> 1; @@ -952,13 +967,13 @@ incolor_poll(void *priv) dev->ma = dev->maback; } - if ((dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1)))) + if (dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1))) dev->con = 1; } } static void * -incolor_init(const device_t *info) +incolor_init(UNUSED(const device_t *info)) { incolor_t *dev; int c; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 57e91637c..f743885c5 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -31,6 +31,7 @@ #include <86box/device.h> #include <86box/video.h> #include <86box/vid_mda.h> +#include <86box/plat_unused.h> static int mdacols[256][2][2]; @@ -39,9 +40,10 @@ static video_timings_t timing_mda = { .type = VIDEO_ISA, .write_b = 8, .write_w void mda_recalctimings(mda_t *mda); void -mda_out(uint16_t addr, uint8_t val, void *p) +mda_out(uint16_t addr, uint8_t val, void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; + switch (addr) { case 0x3b0: case 0x3b2: @@ -64,13 +66,17 @@ mda_out(uint16_t addr, uint8_t val, void *p) case 0x3b8: mda->ctrl = val; return; + + default: + break; } } uint8_t -mda_in(uint16_t addr, void *p) +mda_in(uint16_t addr, void *priv) { - mda_t *mda = (mda_t *) p; + const mda_t *mda = (mda_t *) priv; + switch (addr) { case 0x3b0: case 0x3b2: @@ -84,28 +90,34 @@ mda_in(uint16_t addr, void *p) return mda->crtc[mda->crtcreg]; case 0x3ba: return mda->stat | 0xF0; + + default: + break; } return 0xff; } void -mda_write(uint32_t addr, uint8_t val, void *p) +mda_write(uint32_t addr, uint8_t val, void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; mda->vram[addr & 0xfff] = val; } uint8_t -mda_read(uint32_t addr, void *p) +mda_read(uint32_t addr, void *priv) { - mda_t *mda = (mda_t *) p; + const mda_t *mda = (mda_t *) priv; + return mda->vram[addr & 0xfff]; } void mda_recalctimings(mda_t *mda) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; disptime = mda->crtc[0] + 1; _dispontime = mda->crtc[1]; _dispofftime = disptime - _dispontime; @@ -116,14 +128,16 @@ mda_recalctimings(mda_t *mda) } void -mda_poll(void *p) +mda_poll(void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; uint16_t ca = (mda->crtc[15] | (mda->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c; + int x; + int c; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int oldsc; int blink; @@ -252,7 +266,7 @@ mda_poll(void *p) mda->sc &= 31; mda->ma = mda->maback; } - if ((mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1)))) { + if (mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1))) { mda->con = 1; } } @@ -262,9 +276,7 @@ mda_poll(void *p) void mda_init(mda_t *mda) { - int c; - - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { mdacols[c][0][0] = mdacols[c][1][0] = mdacols[c][1][1] = 16; if (c & 8) mdacols[c][0][1] = 15 + 16; @@ -297,7 +309,7 @@ mda_init(mda_t *mda) } void * -mda_standalone_init(const device_t *info) +mda_standalone_init(UNUSED(const device_t *info)) { mda_t *mda = malloc(sizeof(mda_t)); memset(mda, 0, sizeof(mda_t)); @@ -322,18 +334,18 @@ mda_setcol(int chr, int blink, int fg, uint8_t cga_ink) } void -mda_close(void *p) +mda_close(void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; free(mda->vram); free(mda); } void -mda_speed_changed(void *p) +mda_speed_changed(void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; mda_recalctimings(mda); } diff --git a/src/video/vid_mga.c b/src/video/vid_mga.c index a70a9552d..67f8d5751 100644 --- a/src/video/vid_mga.c +++ b/src/video/vid_mga.c @@ -633,28 +633,28 @@ static void wake_fifo_thread(mystique_t *mystique); static void wait_fifo_idle(mystique_t *mystique); static void mystique_queue(mystique_t *mystique, uint32_t addr, uint32_t val, uint32_t type); -static uint8_t mystique_readb_linear(uint32_t addr, void *p); -static uint16_t mystique_readw_linear(uint32_t addr, void *p); -static uint32_t mystique_readl_linear(uint32_t addr, void *p); -static void mystique_writeb_linear(uint32_t addr, uint8_t val, void *p); -static void mystique_writew_linear(uint32_t addr, uint16_t val, void *p); -static void mystique_writel_linear(uint32_t addr, uint32_t val, void *p); +static uint8_t mystique_readb_linear(uint32_t addr, void *priv); +static uint16_t mystique_readw_linear(uint32_t addr, void *priv); +static uint32_t mystique_readl_linear(uint32_t addr, void *priv); +static void mystique_writeb_linear(uint32_t addr, uint8_t val, void *priv); +static void mystique_writew_linear(uint32_t addr, uint16_t val, void *priv); +static void mystique_writel_linear(uint32_t addr, uint32_t val, void *priv); static void mystique_recalc_mapping(mystique_t *mystique); static int mystique_line_compare(svga_t *svga); -static uint8_t mystique_iload_read_b(uint32_t addr, void *p); -static uint32_t mystique_iload_read_l(uint32_t addr, void *p); -static void mystique_iload_write_b(uint32_t addr, uint8_t val, void *p); -static void mystique_iload_write_l(uint32_t addr, uint32_t val, void *p); +static uint8_t mystique_iload_read_b(uint32_t addr, void *priv); +static uint32_t mystique_iload_read_l(uint32_t addr, void *priv); +static void mystique_iload_write_b(uint32_t addr, uint8_t val, void *priv); +static void mystique_iload_write_l(uint32_t addr, uint32_t val, void *priv); static uint32_t blit_idump_read(mystique_t *mystique); static void blit_iload_write(mystique_t *mystique, uint32_t data, int size); void -mystique_out(uint16_t addr, uint8_t val, void *p) +mystique_out(uint16_t addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint8_t old; @@ -664,6 +664,9 @@ mystique_out(uint16_t addr, uint8_t val, void *p) switch (addr) { case 0x3c8: mystique->xreg_idx = val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x3c6: case 0x3c7: case 0x3c9: @@ -746,9 +749,9 @@ mystique_out(uint16_t addr, uint8_t val, void *p) } uint8_t -mystique_in(uint16_t addr, void *p) +mystique_in(uint16_t addr, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint8_t temp = 0xff; @@ -803,7 +806,7 @@ mystique_in(uint16_t addr, void *p) static int mystique_line_compare(svga_t *svga) { - mystique_t *mystique = (mystique_t *) svga->p; + mystique_t *mystique = (mystique_t *) svga->priv; mystique->status |= STATUS_VLINEPEN; mystique_update_irqs(mystique); @@ -814,7 +817,7 @@ mystique_line_compare(svga_t *svga) static void mystique_vsync_callback(svga_t *svga) { - mystique_t *mystique = (mystique_t *) svga->p; + mystique_t *mystique = (mystique_t *) svga->priv; if (svga->crtc[0x11] & 0x10) { mystique->status |= STATUS_VSYNCPEN; @@ -823,9 +826,9 @@ mystique_vsync_callback(svga_t *svga) } static float -mystique_getclock(int clock, void *p) +mystique_getclock(int clock, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; if (clock == 0) return 25175000.0; @@ -845,10 +848,10 @@ mystique_getclock(int clock, void *p) void mystique_recalctimings(svga_t *svga) { - mystique_t *mystique = (mystique_t *) svga->p; + mystique_t *mystique = (mystique_t *) svga->priv; int clk_sel = (svga->miscout >> 2) & 3; - svga->clock = (cpuclock * (float) (1ull << 32)) / svga->getclock(clk_sel & 3, svga->clock_gen); + svga->clock = (cpuclock * (float) (1ULL << 32)) / svga->getclock(clk_sel & 3, svga->clock_gen); if (mystique->crtcext_regs[1] & CRTCX_R1_HTOTAL8) svga->htotal += 0x100; @@ -1361,15 +1364,16 @@ mystique_write_xreg(mystique_t *mystique, int reg, uint8_t val) } static uint8_t -mystique_ctrl_read_b(uint32_t addr, void *p) +mystique_ctrl_read_b(uint32_t addr, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint8_t ret = 0xff; int fifocount; uint16_t addr_0x0f = 0; uint16_t addr_0x03 = 0; - int rs2 = 0, rs3 = 0; + int rs2 = 0; + int rs3 = 0; if ((mystique->type == MGA_2064W) && (addr & 0x3e00) == 0x3c00) { /*RAMDAC*/ @@ -1585,11 +1589,10 @@ mystique_ctrl_read_b(uint32_t addr, void *p) } static void -mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *p) +mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; int start_blit = 0; - int x; if ((addr & 0x300) == 0x100) { addr &= ~0x100; @@ -1620,7 +1623,7 @@ mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *p) case REG_PAT1 + 1: case REG_PAT1 + 2: case REG_PAT1 + 3: - for (x = 0; x < 8; x++) + for (uint8_t x = 0; x < 8; x++) mystique->dwgreg.pattern[addr & 7][x] = mystique->dwgreg.pattern[addr & 7][x + 8] = val & (1 << (7 - x)); break; @@ -1705,7 +1708,9 @@ mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *p) case REG_YDSTLEN: case REG_YDSTLEN + 1: WRITE8(addr, mystique->dwgreg.length, val); - /* pclog("Write YDSTLEN+%i %i\n", addr&1, mystique->dwgreg.length); */ +#if 0 + pclog("Write YDSTLEN+%i %i\n", addr&1, mystique->dwgreg.length); +#endif break; case REG_YDSTLEN + 2: mystique->dwgreg.ydst = (mystique->dwgreg.ydst & ~0xff) | val; @@ -1924,13 +1929,14 @@ mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *p) } static void -mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *p) +mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint16_t addr_0x0f = 0; uint16_t addr_0x03 = 0; - int rs2 = 0, rs3 = 0; + int rs2 = 0; + int rs3 = 0; if ((mystique->type == MGA_2064W) && (addr & 0x3e00) == 0x3c00) { /*RAMDAC*/ @@ -1961,7 +1967,7 @@ mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *p) } if ((addr & 0x3fff) < 0x1c00) { - mystique_iload_write_b(addr, val, p); + mystique_iload_write_b(addr, val, priv); return; } if ((addr & 0x3e00) == 0x1c00 || (addr & 0x3e00) == 0x2c00) { @@ -2143,25 +2149,25 @@ mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *p) } static uint32_t -mystique_ctrl_read_l(uint32_t addr, void *p) +mystique_ctrl_read_l(uint32_t addr, void *priv) { uint32_t ret; if ((addr & 0x3fff) < 0x1c00) - return mystique_iload_read_l(addr, p); + return mystique_iload_read_l(addr, priv); - ret = mystique_ctrl_read_b(addr, p); - ret |= mystique_ctrl_read_b(addr + 1, p) << 8; - ret |= mystique_ctrl_read_b(addr + 2, p) << 16; - ret |= mystique_ctrl_read_b(addr + 3, p) << 24; + ret = mystique_ctrl_read_b(addr, priv); + ret |= mystique_ctrl_read_b(addr + 1, priv) << 8; + ret |= mystique_ctrl_read_b(addr + 2, priv) << 16; + ret |= mystique_ctrl_read_b(addr + 3, priv) << 24; return ret; } static void -mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) +mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; int start_blit = 0; if ((addr & 0x300) == 0x100) { @@ -2174,10 +2180,8 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) mystique->dwgreg.dwgctrl = val; if (val & DWGCTRL_SOLID) { - int x, y; - - for (y = 0; y < 8; y++) { - for (x = 0; x < 16; x++) + for (uint8_t y = 0; y < 8; y++) { + for (uint8_t x = 0; x < 16; x++) mystique->dwgreg.pattern[y][x] = 1; } mystique->dwgreg.src[0] = 0xffffffff; @@ -2251,24 +2255,24 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) case REG_SRC0: { - int x = 0, y = 0; mystique->dwgreg.src[0] = val; - for (y = 0; y < 2; y++) { - for (x = 0; x < 16; x++) { + for (uint8_t y = 0; y < 2; y++) { + for (uint8_t x = 0; x < 16; x++) { mystique->dwgreg.pattern[y][x] = val & (1 << (x + (y * 16))); } } - // pclog("SRC0 = 0x%08X\n", val); +#if 0 + pclog("SRC0 = 0x%08X\n", val); +#endif if (mystique->busy && (mystique->dwgreg.dwgctrl_running & DWGCTRL_OPCODE_MASK) == DWGCTRL_OPCODE_ILOAD) blit_iload_write(mystique, mystique->dwgreg.src[0], 32); } break; case REG_SRC1: { - int x = 0, y = 0; mystique->dwgreg.src[1] = val; - for (y = 2; y < 4; y++) { - for (x = 0; x < 16; x++) { + for (uint8_t y = 2; y < 4; y++) { + for (uint8_t x = 0; x < 16; x++) { mystique->dwgreg.pattern[y][x] = val & (1 << (x + ((y - 2) * 16))); } } @@ -2279,10 +2283,9 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) break; case REG_SRC2: { - int x = 0, y = 0; mystique->dwgreg.src[2] = val; - for (y = 4; y < 6; y++) { - for (x = 0; x < 16; x++) { + for (uint8_t y = 4; y < 6; y++) { + for (uint8_t x = 0; x < 16; x++) { mystique->dwgreg.pattern[y][x] = val & (1 << (x + ((y - 4) * 16))); } } @@ -2293,10 +2296,9 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) } case REG_SRC3: { - int x = 0, y = 0; mystique->dwgreg.src[3] = val; - for (y = 6; y < 8; y++) { - for (x = 0; x < 16; x++) { + for (uint8_t y = 6; y < 8; y++) { + for (uint8_t x = 0; x < 16; x++) { mystique->dwgreg.pattern[y][x] = val & (1 << (x + ((y - 6) * 16))); } } @@ -2384,10 +2386,10 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) break; default: - mystique_accel_ctrl_write_b(addr, val & 0xff, p); - mystique_accel_ctrl_write_b(addr + 1, (val >> 8) & 0xff, p); - mystique_accel_ctrl_write_b(addr + 2, (val >> 16) & 0xff, p); - mystique_accel_ctrl_write_b(addr + 3, (val >> 24) & 0xff, p); + mystique_accel_ctrl_write_b(addr, val & 0xff, priv); + mystique_accel_ctrl_write_b(addr + 1, (val >> 8) & 0xff, priv); + mystique_accel_ctrl_write_b(addr + 2, (val >> 16) & 0xff, priv); + mystique_accel_ctrl_write_b(addr + 3, (val >> 24) & 0xff, priv); break; } @@ -2396,13 +2398,13 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) } static void -mystique_ctrl_write_l(uint32_t addr, uint32_t val, void *p) +mystique_ctrl_write_l(uint32_t addr, uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; uint32_t reg_addr; if ((addr & 0x3fff) < 0x1c00) { - mystique_iload_write_l(addr, val, p); + mystique_iload_write_l(addr, val, priv); return; } @@ -2457,18 +2459,18 @@ mystique_ctrl_write_l(uint32_t addr, uint32_t val, void *p) break; default: - mystique_ctrl_write_b(addr, val & 0xff, p); - mystique_ctrl_write_b(addr + 1, (val >> 8) & 0xff, p); - mystique_ctrl_write_b(addr + 2, (val >> 16) & 0xff, p); - mystique_ctrl_write_b(addr + 3, (val >> 24) & 0xff, p); + mystique_ctrl_write_b(addr, val & 0xff, priv); + mystique_ctrl_write_b(addr + 1, (val >> 8) & 0xff, priv); + mystique_ctrl_write_b(addr + 2, (val >> 16) & 0xff, priv); + mystique_ctrl_write_b(addr + 3, (val >> 24) & 0xff, priv); break; } } static uint8_t -mystique_iload_read_b(uint32_t addr, void *p) +mystique_iload_read_b(UNUSED(uint32_t addr), void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; wait_fifo_idle(mystique); @@ -2479,9 +2481,9 @@ mystique_iload_read_b(uint32_t addr, void *p) } static uint32_t -mystique_iload_read_l(uint32_t addr, void *p) +mystique_iload_read_l(UNUSED(uint32_t addr), void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; wait_fifo_idle(mystique); @@ -2493,22 +2495,23 @@ mystique_iload_read_l(uint32_t addr, void *p) } static void -mystique_iload_write_b(uint32_t addr, uint8_t val, void *p) +mystique_iload_write_b(UNUSED(uint32_t addr), UNUSED(uint8_t val), UNUSED(void *priv)) { + // } static void -mystique_iload_write_l(uint32_t addr, uint32_t val, void *p) +mystique_iload_write_l(UNUSED(uint32_t addr), uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; mystique_queue(mystique, 0, val, FIFO_WRITE_ILOAD_LONG); } static void -mystique_accel_iload_write_l(uint32_t addr, uint32_t val, void *p) +mystique_accel_iload_write_l(UNUSED(uint32_t addr), uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; switch (mystique->dwgreg.dmamod) { case DMA_MODE_REG: @@ -2536,15 +2539,18 @@ mystique_accel_iload_write_l(uint32_t addr, uint32_t val, void *p) blit_iload_write(mystique, val, 32); break; - /* default: - pclog("ILOAD write DMAMOD %i\n", mystique->dwgreg.dmamod); */ + default: +#if 0 + pclog("ILOAD write DMAMOD %i\n", mystique->dwgreg.dmamod); */ +#endif + break; } } static uint8_t -mystique_readb_linear(uint32_t addr, void *p) +mystique_readb_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_read_b; @@ -2556,9 +2562,9 @@ mystique_readb_linear(uint32_t addr, void *p) } static uint16_t -mystique_readw_linear(uint32_t addr, void *p) +mystique_readw_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_read_w; @@ -2570,9 +2576,9 @@ mystique_readw_linear(uint32_t addr, void *p) } static uint32_t -mystique_readl_linear(uint32_t addr, void *p) +mystique_readl_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_read_l; @@ -2584,9 +2590,9 @@ mystique_readl_linear(uint32_t addr, void *p) } static void -mystique_writeb_linear(uint32_t addr, uint8_t val, void *p) +mystique_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_write_b; @@ -2599,9 +2605,9 @@ mystique_writeb_linear(uint32_t addr, uint8_t val, void *p) } static void -mystique_writew_linear(uint32_t addr, uint16_t val, void *p) +mystique_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_write_w; @@ -2614,9 +2620,9 @@ mystique_writew_linear(uint32_t addr, uint16_t val, void *p) } static void -mystique_writel_linear(uint32_t addr, uint32_t val, void *p) +mystique_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_write_l; @@ -2651,7 +2657,8 @@ run_dma(mystique_t *mystique) } if ((mystique->dma.pri_header & 0xff) != 0x15) { - uint32_t val, reg_addr; + uint32_t val; + uint32_t reg_addr; dma_bm_read(mystique->dma.primaddress & DMA_ADDR_MASK, (uint8_t *) &val, 4, 4); mystique->dma.primaddress += 4; @@ -2693,7 +2700,8 @@ run_dma(mystique_t *mystique) mystique->dma.secaddress += 4; } - uint32_t val, reg_addr; + uint32_t val; + uint32_t reg_addr; dma_bm_read(mystique->dma.secaddress & DMA_ADDR_MASK, (uint8_t *) &val, 4, 4); mystique->dma.secaddress += 4; @@ -2754,9 +2762,9 @@ run_dma(mystique_t *mystique) } static void -fifo_thread(void *p) +fifo_thread(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; while (mystique->thread_run) { thread_set_event(mystique->fifo_not_full_event); @@ -2818,9 +2826,9 @@ wake_fifo_thread_now(mystique_t *mystique) } static void -mystique_wake_timer(void *p) +mystique_wake_timer(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; thread_set_event(mystique->wake_fifo_thread); /*Wake up FIFO thread if moving from idle*/ } @@ -2840,9 +2848,9 @@ wait_fifo_idle(mystique_t *mystique) SOFTRAP IRQs and code reading the status register. Croc will get into an IRQ loop and triple fault if the ENDPRDMASTS flag is seen before the IRQ is taken*/ static void -mystique_softrap_pending_timer(void *p) +mystique_softrap_pending_timer(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; timer_advance_u64(&mystique->softrap_pending_timer, TIMER_USEC * 100); @@ -3131,18 +3139,18 @@ blit_fbitblt(mystique_t *mystique) { svga_t *svga = &mystique->svga; uint32_t src_addr; - int y; int x_dir = mystique->dwgreg.sgn.scanleft ? -1 : 1; int16_t x_start = mystique->dwgreg.sgn.scanleft ? mystique->dwgreg.fxright : mystique->dwgreg.fxleft; int16_t x_end = mystique->dwgreg.sgn.scanleft ? mystique->dwgreg.fxleft : mystique->dwgreg.fxright; src_addr = mystique->dwgreg.ar[3]; - for (y = 0; y < mystique->dwgreg.length; y++) { + for (uint16_t y = 0; y < mystique->dwgreg.length; y++) { int16_t x = x_start; while (1) { if (x >= mystique->dwgreg.cxleft && x <= mystique->dwgreg.cxright && mystique->dwgreg.ydst_lin >= mystique->dwgreg.ytop && mystique->dwgreg.ydst_lin <= mystique->dwgreg.ybot) { - uint32_t src, old_dst; + uint32_t src; + uint32_t old_dst; switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: @@ -3206,11 +3214,13 @@ static void blit_iload_iload(mystique_t *mystique, uint32_t data, int size) { svga_t *svga = &mystique->svga; - uint32_t src, dst; + uint32_t src; + uint32_t dst; uint32_t dst2; uint64_t data64; int min_size = 8; - uint32_t bltckey = mystique->dwgreg.fcol, bltcmsk = mystique->dwgreg.bcol; + uint32_t bltckey = mystique->dwgreg.fcol; + uint32_t bltcmsk = mystique->dwgreg.bcol; const int transc = mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANSC; const int trans_sel = (mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANS_MASK) >> DWGCTRL_TRANS_SHIFT; uint8_t const *const trans = &trans_masks[trans_sel][(mystique->dwgreg.selline & 3) * 4]; @@ -3269,6 +3279,9 @@ blit_iload_iload(mystique_t *mystique, uint32_t data, int size) case MACCESS_PWIDTH_32: min_size = 32; break; + + default: + break; } while (size >= min_size) { @@ -3561,11 +3574,19 @@ blit_iload_iload_scale(mystique_t *mystique, uint32_t data, int size) { svga_t *svga = &mystique->svga; uint64_t data64 = 0; - int y0, y1; - int u, v; - int dR, dG, dB; - int r0, g0, b0; - int r1, g1, b1; + int y0; + int y1; + int u; + int v; + int dR; + int dG; + int dB; + int r0; + int g0; + int b0; + int r1; + int g1; + int b1; switch (mystique->dwgreg.dwgctrl_running & DWGCTRL_BLTMOD_MASK) { case DWGCTRL_BLTMOD_BUYUV: @@ -3692,10 +3713,19 @@ blit_iload_iload_high(mystique_t *mystique, uint32_t data, int size) { svga_t *svga = &mystique->svga; uint32_t out_data; - int y0, y1, u, v; - int dR, dG, dB; - int r = 0, g = 0, b = 0; - int next_r = 0, next_g = 0, next_b = 0; + int y0; + int y1; + int u; + int v; + int dR; + int dG; + int dB; + int r = 0; + int g = 0; + int b = 0; + int next_r = 0; + int next_g = 0; + int next_b = 0; switch (mystique->dwgreg.dwgctrl_running & DWGCTRL_BLTMOD_MASK) { case DWGCTRL_BLTMOD_BUYUV: @@ -3811,7 +3841,8 @@ blit_iload_iload_high(mystique_t *mystique, uint32_t data, int size) static void blit_iload_iload_highv(mystique_t *mystique, uint32_t data, int size) { - uint8_t *src0, *src1; + uint8_t *src0; + uint8_t *src1; switch (mystique->dwgreg.dwgctrl_running & DWGCTRL_BLTMOD_MASK) { case DWGCTRL_BLTMOD_BUYUV: @@ -3890,7 +3921,9 @@ static void blit_line(mystique_t *mystique, int closed) { svga_t *svga = &mystique->svga; - uint32_t src, dst, old_dst; + uint32_t src; + uint32_t dst; + uint32_t old_dst; int x; int z_write; @@ -3971,7 +4004,9 @@ blit_line(mystique_t *mystique, int closed) uint16_t old_z = z_p[x]; if (z_check(z, old_z, mystique->dwgreg.dwgctrl_running & DWGCTRL_ZMODE_MASK)) { - int r = 0, g = 0, b = 0; + int r = 0; + int g = 0; + int b = 0; if (z_write) z_p[x] = z; @@ -4072,7 +4107,10 @@ static void blit_trap(mystique_t *mystique) { svga_t *svga = &mystique->svga; - uint32_t z_back, r_back, g_back, b_back; + uint32_t z_back; + uint32_t r_back; + uint32_t g_back; + uint32_t b_back; int z_write; int y; const int trans_sel = (mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANS_MASK) >> DWGCTRL_TRANS_SHIFT; @@ -4160,7 +4198,8 @@ blit_trap(mystique_t *mystique) int xoff = (mystique->dwgreg.xoff + (x_l & 7)) & 15; int pattern = mystique->dwgreg.pattern[yoff][xoff]; uint32_t src = pattern ? mystique->dwgreg.fcol : mystique->dwgreg.bcol; - uint32_t dst, old_dst; + uint32_t dst; + uint32_t old_dst; switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: @@ -4250,8 +4289,11 @@ blit_trap(mystique_t *mystique) uint16_t old_z = z_p[x_l]; if (z_check(z, old_z, mystique->dwgreg.dwgctrl_running & DWGCTRL_ZMODE_MASK)) { - uint32_t dst = 0, old_dst; - int r = 0, g = 0, b = 0; + uint32_t dst = 0; + uint32_t old_dst; + int r = 0; + int g = 0; + int b = 0; if (!(mystique->dwgreg.dr[4] & (1 << 23))) r = (mystique->dwgreg.dr[4] >> 15) & 0xff; @@ -4351,7 +4393,8 @@ texture_read(mystique_t *mystique, int *tex_r, int *tex_g, int *tex_b, int *atra const unsigned int w_mask = (mystique->dwgreg.texwidth & TEXWIDTH_TWMASK_MASK) >> TEXWIDTH_TWMASK_SHIFT; const unsigned int h_mask = (mystique->dwgreg.texheight & TEXHEIGHT_THMASK_MASK) >> TEXHEIGHT_THMASK_SHIFT; uint16_t src = 0; - int s, t; + int s; + int t; if (mystique->dwgreg.texctl & TEXCTL_NPCEN) { const int s_shift = 20 - (mystique->dwgreg.texwidth & TEXWIDTH_TW_MASK); @@ -4362,7 +4405,7 @@ texture_read(mystique_t *mystique, int *tex_r, int *tex_g, int *tex_b, int *atra } else { const int s_shift = (20 + 16) - (mystique->dwgreg.texwidth & TEXWIDTH_TW_MASK); const int t_shift = (20 + 16) - (mystique->dwgreg.texheight & TEXHEIGHT_TH_MASK); - int64_t q = mystique->dwgreg.tmr[8] ? ((0x100000000ll / (int64_t) (int32_t) mystique->dwgreg.tmr[8]) /*>> 16*/) : 0; + int64_t q = mystique->dwgreg.tmr[8] ? (0x100000000LL / (int64_t) (int32_t) mystique->dwgreg.tmr[8] /*>> 16*/) : 0; s = (((int64_t) (int32_t) mystique->dwgreg.tmr[6] * q) /*<< 8*/) >> s_shift; /*((16+20)-12);*/ t = (((int64_t) (int32_t) mystique->dwgreg.tmr[7] * q) /*<< 8*/) >> t_shift; /*((16+20)-9);*/ @@ -4466,9 +4509,14 @@ blit_texture_trap(mystique_t *mystique) uint16_t old_z = z_p[x_l]; if (z_check(z, old_z, mystique->dwgreg.dwgctrl_running & DWGCTRL_ZMODE_MASK)) { - int tex_r = 0, tex_g = 0, tex_b = 0; - int ctransp, atransp = 0; - int i_r = 0, i_g = 0, i_b = 0; + int tex_r = 0; + int tex_g = 0; + int tex_b = 0; + int ctransp; + int atransp = 0; + int i_r = 0; + int i_g = 0; + int i_b = 0; if (!(mystique->dwgreg.dr[4] & (1 << 23))) i_r = (mystique->dwgreg.dr[4] >> 15) & 0xff; @@ -4726,7 +4774,8 @@ blit_bitblt(mystique_t *mystique) if (x >= mystique->dwgreg.cxleft && x <= mystique->dwgreg.cxright && mystique->dwgreg.ydst_lin >= mystique->dwgreg.ytop && mystique->dwgreg.ydst_lin <= mystique->dwgreg.ybot && ((svga->vram[byte_addr] & (1 << bit_offset)) || !(mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANSC)) && trans[x & 3]) { uint32_t src = (svga->vram[byte_addr] & (1 << bit_offset)) ? mystique->dwgreg.fcol : mystique->dwgreg.bcol; - uint32_t dst, old_dst; + uint32_t dst; + uint32_t old_dst; switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: @@ -4801,7 +4850,9 @@ blit_bitblt(mystique_t *mystique) while (1) { if (x >= mystique->dwgreg.cxleft && x <= mystique->dwgreg.cxright && mystique->dwgreg.ydst_lin >= mystique->dwgreg.ytop && mystique->dwgreg.ydst_lin <= mystique->dwgreg.ybot && trans[x & 3]) { - uint32_t src, dst, old_dst; + uint32_t src; + uint32_t dst; + uint32_t old_dst; switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: @@ -5111,8 +5162,7 @@ mystique_start_blit(mystique_t *mystique) static void mystique_hwcursor_draw(svga_t *svga, int displine) { - mystique_t *mystique = (mystique_t *) svga->p; - int x; + mystique_t *mystique = (mystique_t *) svga->priv; uint64_t dat[2]; int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; @@ -5124,11 +5174,11 @@ mystique_hwcursor_draw(svga_t *svga, int displine) svga->hwcursor_latch.addr += 16; switch (mystique->xcurctrl & XCURCTRL_CURMODE_MASK) { case XCURCTRL_CURMODE_XGA: - for (x = 0; x < 64; x++) { - if (!(dat[1] & (1ull << 63))) - buffer32->line[displine][offset + svga->x_add] = (dat[0] & (1ull << 63)) ? mystique->cursor.col[1] : mystique->cursor.col[0]; - else if (dat[0] & (1ull << 63)) - buffer32->line[displine][offset + svga->x_add] ^= 0xffffff; + for (uint8_t x = 0; x < 64; x++) { + if (!(dat[1] & (1ULL << 63))) + svga->monitor->target_buffer->line[displine][offset + svga->x_add] = (dat[0] & (1ULL << 63)) ? mystique->cursor.col[1] : mystique->cursor.col[0]; + else if (dat[0] & (1ULL << 63)) + svga->monitor->target_buffer->line[displine][offset + svga->x_add] ^= 0xffffff; offset++; dat[0] <<= 1; @@ -5142,9 +5192,9 @@ mystique_hwcursor_draw(svga_t *svga, int displine) } static uint8_t -mystique_pci_read(int func, int addr, void *p) +mystique_pci_read(UNUSED(int func), int addr, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; uint8_t ret = 0x00; if ((addr >= 0x30) && (addr <= 0x33) && !(mystique->pci_regs[0x43] & 0x40)) @@ -5292,9 +5342,9 @@ mystique_pci_read(int func, int addr, void *p) } static void -mystique_pci_write(int func, int addr, uint8_t val, void *p) +mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; switch (addr) { case PCI_REG_COMMAND: @@ -5409,7 +5459,6 @@ mystique_pci_write(int func, int addr, uint8_t val, void *p) static void * mystique_init(const device_t *info) { - int c; mystique_t *mystique = malloc(sizeof(mystique_t)); char *romfn; @@ -5487,7 +5536,7 @@ mystique_init(const device_t *info) mystique->pci_regs[0x41] = 0x01; /* vgaboot = 1 */ mystique->pci_regs[0x43] = 0x40; /* biosen = 1 */ - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { dither5[c][0][0] = c >> 3; dither5[c][1][1] = (c + 2) >> 3; dither5[c][1][0] = (c + 4) >> 3; @@ -5534,9 +5583,9 @@ mystique_init(const device_t *info) } static void -mystique_close(void *p) +mystique_close(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; mystique->thread_run = 0; thread_set_event(mystique->wake_fifo_thread); @@ -5573,17 +5622,17 @@ mystique_220_available(void) } static void -mystique_speed_changed(void *p) +mystique_speed_changed(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_recalctimings(&mystique->svga); } static void -mystique_force_redraw(void *p) +mystique_force_redraw(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; mystique->svga.fullchange = changeframecount; } diff --git a/src/video/vid_nga.c b/src/video/vid_nga.c index e2e8fdc9c..32c103a8b 100644 --- a/src/video/vid_nga.c +++ b/src/video/vid_nga.c @@ -38,6 +38,7 @@ #include <86box/vid_cga.h> #include <86box/vid_nga.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> #define CGA_RGB 0 #define CGA_COMPOSITE 1 @@ -50,9 +51,11 @@ static video_timings_t timing_nga = { .type = VIDEO_ISA, .write_b = 8, .write_w void nga_recalctimings(nga_t *nga) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; - if ((nga->cga.cgamode & 1)) { + if (nga->cga.cgamode & 1) { disptime = nga->cga.crtc[0] + 1; _dispontime = nga->cga.crtc[1]; } else { @@ -84,7 +87,7 @@ nga_in(uint16_t addr, void *priv) } void -nga_waitstates(void *p) +nga_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -136,7 +139,7 @@ nga_read(uint32_t addr, void *priv) nga->cga.charbuffer[offset | 1] = nga->cga.vram[addr & 0x7fff]; } - return (ret); + return ret; } void @@ -146,10 +149,15 @@ nga_poll(void *priv) /* set cursor position in memory */ uint16_t ca = (nga->cga.crtc[15] | (nga->cga.crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int c; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; - uint16_t dat, dat2; + uint8_t chr; + uint8_t attr; + uint16_t dat; + uint16_t dat2; int cols[4]; int col; int oldsc; @@ -338,7 +346,7 @@ nga_poll(void *priv) /* nga specific */ cols[0] = ((nga->cga.cgamode & 0x12) == 0x12) ? 0 : (nga->cga.cgacol & 15) + 16; /* 80-col */ - if ((nga->cga.cgamode & 1)) { + if (nga->cga.cgamode & 1) { hline(buffer32, 0, (nga->cga.displine << 1), ((nga->cga.crtc[1] << 3) + 16) << 2, cols[0]); hline(buffer32, 0, (nga->cga.displine << 1) + 1, ((nga->cga.crtc[1] << 3) + 16) << 2, cols[0]); } else { @@ -347,7 +355,7 @@ nga_poll(void *priv) } } - if ((nga->cga.cgamode & 1)) + if (nga->cga.cgamode & 1) /* set screen width */ x = (nga->cga.crtc[1] << 3) + 16; else @@ -444,7 +452,7 @@ nga_poll(void *priv) nga->cga.vsynctime = 16; /* vsync pos */ if (nga->cga.crtc[7]) { - if ((nga->cga.cgamode & 1)) + if (nga->cga.cgamode & 1) /* set screen width */ x = (nga->cga.crtc[1] << 3) + 16; else @@ -515,7 +523,7 @@ nga_poll(void *priv) nga->cga.cgastat &= ~1; /* enable cursor if its scanline was reached */ - if ((nga->cga.sc == (nga->cga.crtc[10] & 31) || ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == ((nga->cga.crtc[10] & 31) >> 1)))) + if (nga->cga.sc == (nga->cga.crtc[10] & 31) || ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == ((nga->cga.crtc[10] & 31) >> 1))) nga->cga.con = 1; } /* 80-columns */ @@ -546,7 +554,7 @@ nga_speed_changed(void *priv) } void * -nga_init(const device_t *info) +nga_init(UNUSED(const device_t *info)) { int mem; uint8_t charset; diff --git a/src/video/vid_oak_oti.c b/src/video/vid_oak_oti.c index cc07dc0a4..932e13913 100644 --- a/src/video/vid_oak_oti.c +++ b/src/video/vid_oak_oti.c @@ -29,6 +29,7 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_unused.h> #define BIOS_037C_PATH "roms/video/oti/bios.bin" #define BIOS_067_AMA932J_PATH "roms/machines/ama932j/OTI067.BIN" @@ -64,12 +65,13 @@ typedef struct { static video_timings_t timing_oti = { .type = VIDEO_ISA, .write_b = 6, .write_w = 8, .write_l = 16, .read_b = 6, .read_w = 8, .read_l = 16 }; static void -oti_out(uint16_t addr, uint8_t val, void *p) +oti_out(uint16_t addr, uint8_t val, void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_t *svga = &oti->svga; uint8_t old; - uint8_t idx, enable; + uint8_t idx; + uint8_t enable; if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3C3)) return; @@ -84,7 +86,6 @@ oti_out(uint16_t addr, uint8_t val, void *p) return; } else break; - break; case 0x3c6: case 0x3c7: @@ -198,11 +199,12 @@ oti_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -oti_in(uint16_t addr, void *p) +oti_in(uint16_t addr, void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_t *svga = &oti->svga; - uint8_t idx, temp; + uint8_t idx; + uint8_t temp; if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3C3)) return 0xff; @@ -313,13 +315,13 @@ oti_in(uint16_t addr, void *p) break; } - return (temp); + return temp; } static void -oti_pos_out(uint16_t addr, uint8_t val, void *p) +oti_pos_out(UNUSED(uint16_t addr), uint8_t val, void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; if ((val ^ oti->pos) & 8) { if (val & 8) @@ -334,9 +336,9 @@ oti_pos_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -oti_pos_in(uint16_t addr, void *p) +oti_pos_in(UNUSED(uint16_t addr), void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; return (oti->pos); } @@ -371,10 +373,10 @@ oti_getclock(int clock) static void oti_recalctimings(svga_t *svga) { - oti_t *oti = (oti_t *) svga->p; + oti_t *oti = (oti_t *) svga->priv; int clk_sel = ((svga->miscout >> 2) & 3) | ((oti->regs[0x0d] & 0x20) >> 3); - svga->clock = (cpuclock * (double) (1ull << 32)) / oti_getclock(clk_sel); + svga->clock = (cpuclock * (double) (1ULL << 32)) / oti_getclock(clk_sel); if (oti->chip_id > 0) { if (oti->regs[0x14] & 0x08) @@ -473,13 +475,13 @@ oti_init(const device_t *info) oti->svga.miscout = 1; oti->svga.packed_chain4 = 1; - return (oti); + return oti; } static void -oti_close(void *p) +oti_close(void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_close(&oti->svga); @@ -487,17 +489,17 @@ oti_close(void *p) } static void -oti_speed_changed(void *p) +oti_speed_changed(void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_recalctimings(&oti->svga); } static void -oti_force_redraw(void *p) +oti_force_redraw(void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; oti->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ogc.c b/src/video/vid_ogc.c index 38d993216..edc4c841e 100644 --- a/src/video/vid_ogc.c +++ b/src/video/vid_ogc.c @@ -39,6 +39,7 @@ #include <86box/vid_cga.h> #include <86box/vid_ogc.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> /* * Current bugs: @@ -59,7 +60,9 @@ static uint8_t mdaattr[256][2][2]; void ogc_recalctimings(ogc_t *ogc) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; if (ogc->cga.cgamode & 1) { disptime = ogc->cga.crtc[0] + 1; @@ -134,11 +137,11 @@ ogc_in(uint16_t addr, void *priv) } } - return (ret); + return ret; } void -ogc_waitstates(void *p) +ogc_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -188,10 +191,15 @@ ogc_poll(void *priv) ogc_t *ogc = (ogc_t *) priv; uint16_t ca = (ogc->cga.crtc[15] | (ogc->cga.crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int c; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; - uint16_t dat, dat2; + uint8_t chr; + uint8_t attr; + uint16_t dat; + uint16_t dat2; int cols[4]; int oldsc; int blink = 0; @@ -537,9 +545,7 @@ ogc_speed_changed(void *priv) void ogc_mdaattr_rebuild(void) { - int c; - - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { mdaattr[c][0][0] = mdaattr[c][1][0] = mdaattr[c][1][1] = 16; if (c & 8) mdaattr[c][0][1] = 15 + 16; @@ -567,7 +573,7 @@ ogc_mdaattr_rebuild(void) * - Optional EGC expansion board (which handles 640x400x16) not implemented */ void * -ogc_init(const device_t *info) +ogc_init(UNUSED(const device_t *info)) { // int display_type; ogc_t *ogc = (ogc_t *) malloc(sizeof(ogc_t)); diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index f2ec8aeb2..a00015f9e 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -75,9 +75,9 @@ static video_timings_t timing_paradise_wd90c = { .type = VIDEO_ISA, .write_b = void paradise_remap(paradise_t *paradise); uint8_t -paradise_in(uint16_t addr, void *p) +paradise_in(uint16_t addr, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -135,9 +135,9 @@ paradise_in(uint16_t addr, void *p) } void -paradise_out(uint16_t addr, uint8_t val, void *p) +paradise_out(uint16_t addr, uint8_t val, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; uint8_t old; @@ -289,7 +289,7 @@ paradise_remap(paradise_t *paradise) paradise->write_bank[1] = paradise->write_bank[3] = (svga->gdcreg[9] << 12) + ((svga->gdcreg[6] & 0x08) ? 0 : 0x8000); } - if ((((svga->gdcreg[0x0b] & 0xc0) == 0xc0) && !svga->chain4 && (svga->crtc[0x14] & 0x40) && ((svga->gdcreg[6] >> 2) & 3) == 1)) + if (((svga->gdcreg[0x0b] & 0xc0) == 0xc0) && !svga->chain4 && (svga->crtc[0x14] & 0x40) && ((svga->gdcreg[6] >> 2) & 3) == 1) paradise->check = 1; if (paradise->bank_mask == 0x7f) { @@ -301,7 +301,7 @@ paradise_remap(paradise_t *paradise) void paradise_recalctimings(svga_t *svga) { - paradise_t *paradise = (paradise_t *) svga->p; + paradise_t *paradise = (paradise_t *) svga->priv; svga->lowres = !(svga->gdcreg[0x0e] & 0x01); @@ -345,11 +345,12 @@ paradise_recalctimings(svga_t *svga) } static void -paradise_write(uint32_t addr, uint8_t val, void *p) +paradise_write(uint32_t addr, uint8_t val, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; - uint32_t prev_addr, prev_addr2; + uint32_t prev_addr; + uint32_t prev_addr2; addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; @@ -393,11 +394,12 @@ paradise_write(uint32_t addr, uint8_t val, void *p) svga_write_linear(addr, val, svga); } static void -paradise_writew(uint32_t addr, uint16_t val, void *p) +paradise_writew(uint32_t addr, uint16_t val, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; - uint32_t prev_addr, prev_addr2; + uint32_t prev_addr; + uint32_t prev_addr2; addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; @@ -442,11 +444,12 @@ paradise_writew(uint32_t addr, uint16_t val, void *p) } static uint8_t -paradise_read(uint32_t addr, void *p) +paradise_read(uint32_t addr, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; - uint32_t prev_addr, prev_addr2; + uint32_t prev_addr; + uint32_t prev_addr2; addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; @@ -490,11 +493,12 @@ paradise_read(uint32_t addr, void *p) return svga_read_linear(addr, svga); } static uint16_t -paradise_readw(uint32_t addr, void *p) +paradise_readw(uint32_t addr, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; - uint32_t prev_addr, prev_addr2; + uint32_t prev_addr; + uint32_t prev_addr2; addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; @@ -724,9 +728,9 @@ paradise_wd90c30_standalone_available(void) } void -paradise_close(void *p) +paradise_close(void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_close(¶dise->svga); @@ -734,17 +738,17 @@ paradise_close(void *p) } void -paradise_speed_changed(void *p) +paradise_speed_changed(void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_recalctimings(¶dise->svga); } void -paradise_force_redraw(void *p) +paradise_force_redraw(void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; paradise->svga.fullchange = changeframecount; } diff --git a/src/video/vid_pgc.c b/src/video/vid_pgc.c index 74a20145c..0033e96d1 100644 --- a/src/video/vid_pgc.c +++ b/src/video/vid_pgc.c @@ -324,7 +324,6 @@ read_command(pgc_t *dev) static int parse_command(pgc_t *dev, const pgc_cmd_t **pcmd) { - const pgc_cmd_t *cmd; char match[7]; *pcmd = NULL; @@ -343,7 +342,7 @@ parse_command(pgc_t *dev, const pgc_cmd_t **pcmd) * dev->commands may be a subclass list (terminated with '*') * or the core list (terminated with '@') */ - for (cmd = dev->commands; cmd->ascii[0] != '@'; cmd++) { + for (const pgc_cmd_t *cmd = dev->commands; cmd->ascii[0] != '@'; cmd++) { /* End of subclass command list, chain to core. */ if (cmd->ascii[0] == '*') cmd = dev->master; @@ -415,7 +414,7 @@ hndl_clbeg(pgc_t *dev) } static void -hndl_clend(pgc_t *dev) +hndl_clend(UNUSED(pgc_t *dev)) { /* Should not happen outside a CLBEG. */ } @@ -465,12 +464,11 @@ static void hndl_clread(pgc_t *dev) { uint8_t param = 0; - uint32_t n; if (!pgc_param_byte(dev, ¶m)) return; - for (n = 0; n < dev->clist[param].wrptr; n++) { + for (uint32_t n = 0; n < dev->clist[param].wrptr; n++) { if (!pgc_result_byte(dev, dev->clist[param].list[n])) return; } @@ -493,12 +491,11 @@ static void hndl_clears(pgc_t *dev) { uint8_t param = 0; - uint32_t y; if (!pgc_param_byte(dev, ¶m)) return; - for (y = 0; y < dev->screenh; y++) + for (uint32_t y = 0; y < dev->screenh; y++) memset(dev->vram + y * dev->maxw, param, dev->screenw); } @@ -569,7 +566,8 @@ hndl_prmfil(pgc_t *dev) static void hndl_move(pgc_t *dev) { - int32_t x = 0, y = 0; + int32_t x = 0; + int32_t y = 0; if (!pgc_param_coord(dev, &x)) return; @@ -586,7 +584,9 @@ hndl_move(pgc_t *dev) static void hndl_move3(pgc_t *dev) { - int32_t x = 0, y = 0, z = 0; + int32_t x = 0; + int32_t y = 0; + int32_t z = 0; if (!pgc_param_coord(dev, &x)) return; @@ -604,7 +604,8 @@ hndl_move3(pgc_t *dev) static void hndl_mover(pgc_t *dev) { - int32_t x = 0, y = 0; + int32_t x = 0; + int32_t y = 0; if (!pgc_param_coord(dev, &x)) return; @@ -619,7 +620,9 @@ hndl_mover(pgc_t *dev) static void hndl_mover3(pgc_t *dev) { - int32_t x = 0, y = 0, z = 0; + int32_t x = 0; + int32_t y = 0; + int32_t z = 0; if (!pgc_param_coord(dev, &x)) return; @@ -752,7 +755,12 @@ pgc_plot(pgc_t *dev, uint16_t x, uint16_t y) uint16_t pgc_draw_line_r(pgc_t *dev, int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint16_t linemask) { - int32_t dx, dy, sx, sy, err, e2; + int32_t dx; + int32_t dy; + int32_t sx; + int32_t sy; + int32_t err; + int32_t e2; dx = abs(x1 - x0); dy = abs(y1 - y0); @@ -850,8 +858,11 @@ pgc_fill_polygon(pgc_t *dev, unsigned corners, int32_t *x, int32_t *y) double *nodex; double *dx; double *dy; - unsigned n, nodes, i, j; - double ymin, ymax, ypos; + unsigned nodes; + unsigned i; + unsigned j; + double ymin; + double ymax; pgc_log("PGC: fill_polygon(%i corners)\n", corners); @@ -878,7 +889,7 @@ pgc_fill_polygon(pgc_t *dev, unsigned corners, int32_t *x, int32_t *y) } ymin = ymax = y[0] / 65536.0; - for (n = 0; n < corners; n++) { + for (unsigned int n = 0; n < corners; n++) { /* Convert from PGC fixed-point to native floating-point. */ dx[n] = x[n] / 65536.0; dy[n] = y[n] / 65536.0; @@ -892,7 +903,7 @@ pgc_fill_polygon(pgc_t *dev, unsigned corners, int32_t *x, int32_t *y) /* Polygon fill. Based on */ /* For each row, work out where the polygon lines intersect with * that row. */ - for (ypos = ymin; ypos <= ymax; ypos++) { + for (double ypos = ymin; ypos <= ymax; ypos++) { nodes = 0; j = corners - 1; for (i = 0; i < corners; i++) { @@ -908,8 +919,10 @@ pgc_fill_polygon(pgc_t *dev, unsigned corners, int32_t *x, int32_t *y) /* And fill between them. */ for (i = 0; i < nodes; i += 2) { - int16_t x1 = (int16_t) nodex[i], x2 = (int16_t) nodex[i + 1], - y1 = (int16_t) ypos, y2 = (int16_t) ypos; + int16_t x1 = (int16_t) nodex[i]; + int16_t x2 = (int16_t) nodex[i + 1]; + int16_t y1 = (int16_t) ypos; + int16_t y2 = (int16_t) ypos; pgc_sto_raster(dev, &x1, &y1); pgc_sto_raster(dev, &x2, &y2); pgc_fill_line_r(dev, x1, x2, y1); @@ -930,7 +943,6 @@ pgc_draw_ellipse(pgc_t *dev, int32_t x, int32_t y) double w = x / 65536.0; double y0 = dev->y / 65536.0; double x0 = dev->x / 65536.0; - double ypos, xpos; double x1; double xlast = 0.0; int16_t linemask = dev->line_pattern; @@ -940,7 +952,7 @@ pgc_draw_ellipse(pgc_t *dev, int32_t x, int32_t y) pgc_dto_raster(dev, &x0, &y0); - for (ypos = 0; ypos <= h; ypos++) { + for (double ypos = 0; ypos <= h; ypos++) { if (ypos == 0) { if (dev->fill_mode) pgc_fill_line_r(dev, (uint16_t) (x0 - w), @@ -966,7 +978,7 @@ pgc_draw_ellipse(pgc_t *dev, int32_t x, int32_t y) } /* Draw border. */ - for (xpos = xlast; xpos >= x1; xpos--) { + for (double xpos = xlast; xpos >= x1; xpos--) { if (linemask & 0x8000) { pgc_plot(dev, (uint16_t) (x0 + xpos), (uint16_t) (y0 + ypos)); @@ -990,7 +1002,8 @@ pgc_draw_ellipse(pgc_t *dev, int32_t x, int32_t y) static void hndl_ellipse(pgc_t *dev) { - int32_t x = 0, y = 0; + int32_t x = 0; + int32_t y = 0; if (!pgc_param_coord(dev, &x)) return; @@ -1007,13 +1020,12 @@ hndl_poly(pgc_t *dev) uint8_t count; int32_t x[256]; int32_t y[256]; - int32_t n; if (!pgc_param_byte(dev, &count)) return; pgc_log("PGC: POLY (%i)\n", count); - for (n = 0; n < count; n++) { + for (uint8_t n = 0; n < count; n++) { if (!pgc_param_coord(dev, &x[n])) return; if (!pgc_param_coord(dev, &y[n])) @@ -1023,7 +1035,7 @@ hndl_poly(pgc_t *dev) /* Parse but don't execute a POLY command (for adding to a command list) */ static int -parse_poly(pgc_t *dev, pgc_cl_t *cl, int c) +parse_poly(pgc_t *dev, pgc_cl_t *cl, UNUSED(int c)) { uint8_t count; @@ -1064,8 +1076,11 @@ hndl_display(pgc_t *dev) static void hndl_imagew(pgc_t *dev) { - int16_t row, col1, col2; - uint8_t v1, v2; + int16_t row; + int16_t col1; + int16_t col2; + uint8_t v1; + uint8_t v2; if (!pgc_param_word(dev, &row)) return; @@ -1174,9 +1189,8 @@ static void hndl_lut(pgc_t *dev) { uint8_t param[4]; - int n; - for (n = 0; n < 4; n++) { + for (uint8_t n = 0; n < 4; n++) { if (!pgc_param_byte(dev, ¶m[n])) return; if (n > 0 && param[n] > 15) { @@ -1215,9 +1229,8 @@ void pgc_hndl_lut8(pgc_t *dev) { uint8_t param[4]; - int n; - for (n = 0; n < 4; n++) + for (uint8_t n = 0; n < 4; n++) if (!pgc_param_byte(dev, ¶m[n])) return; @@ -1229,9 +1242,8 @@ static void hndl_areapt(pgc_t *dev) { int16_t pat[16]; - int n; - for (n = 0; n < 16; n++) + for (uint8_t n = 0; n < 16; n++) if (!pgc_param_word(dev, &pat[n])) return; @@ -1319,7 +1331,10 @@ hndl_tsize(pgc_t *pgc) static void hndl_vwport(pgc_t *dev) { - int16_t x1, x2, y1, y2; + int16_t x1; + int16_t x2; + int16_t y1; + int16_t y2; if (!pgc_param_word(dev, &x1)) return; @@ -1341,7 +1356,10 @@ hndl_vwport(pgc_t *dev) static void hndl_window(pgc_t *dev) { - int16_t x1, x2, y1, y2; + int16_t x1; + int16_t x2; + int16_t y1; + int16_t y2; if (!pgc_param_word(dev, &x1)) return; @@ -1583,8 +1601,6 @@ pgc_error(pgc_t *dev, int err) void pgc_reset(pgc_t *dev) { - int n; - memset(dev->mapram, 0x00, sizeof(dev->mapram)); /* The 'CGA disable' jumper is not currently implemented. */ @@ -1617,7 +1633,7 @@ pgc_reset(pgc_t *dev) dev->vp_y2 = dev->vish - 1; /* Empty command lists. */ - for (n = 0; n < 256; n++) { + for (uint16_t n = 0; n < 256; n++) { dev->clist[n].wrptr = 0; dev->clist[n].rdptr = 0; dev->clist[n].repeat = 0; @@ -1763,7 +1779,8 @@ pgc_param_byte(pgc_t *dev, uint8_t *val) int pgc_param_word(pgc_t *dev, int16_t *val) { - uint8_t lo, hi; + uint8_t lo; + uint8_t hi; int32_t c; if (dev->clcur) { @@ -1881,7 +1898,6 @@ pgc_param_coord(pgc_t *dev, int32_t *value) pgc_error(dev, PGC_ERROR_MISSING); return err_digit(dev); } - break; /* Scientific notation. */ case 'd': @@ -1995,14 +2011,13 @@ int pgc_parse_bytes(pgc_t *dev, pgc_cl_t *cl, int count) { uint8_t *param = (uint8_t *) malloc(count); - int n; if (!param) { pgc_error(dev, PGC_ERROR_OVERFLOW); return 0; } - for (n = 0; n < count; n++) { + for (int n = 0; n < count; n++) { if (!pgc_param_byte(dev, ¶m[n])) { free(param); return 0; @@ -2025,14 +2040,13 @@ int pgc_parse_words(pgc_t *dev, pgc_cl_t *cl, int count) { int16_t *param = (int16_t *) malloc(count * sizeof(int16_t)); - int n; if (!param) { pgc_error(dev, PGC_ERROR_OVERFLOW); return 0; } - for (n = 0; n < count; n++) { + for (int n = 0; n < count; n++) { if (!pgc_param_word(dev, ¶m[n])) { free(param); return 0; @@ -2110,7 +2124,8 @@ pgc_dto_raster(pgc_t *dev, double *x, double *y) void pgc_sto_raster(pgc_t *dev, int16_t *x, int16_t *y) { - double xd = *x, yd = *y; + double xd = *x; + double yd = *y; pgc_dto_raster(dev, &xd, &yd); *x = (int16_t) xd; @@ -2120,7 +2135,8 @@ pgc_sto_raster(pgc_t *dev, int16_t *x, int16_t *y) void pgc_ito_raster(pgc_t *dev, int32_t *x, int32_t *y) { - double xd = *x, yd = *y; + double xd = *x; + double yd = *y; pgc_dto_raster(dev, &xd, &yd); *x = (int32_t) xd; @@ -2130,9 +2146,12 @@ pgc_ito_raster(pgc_t *dev, int32_t *x, int32_t *y) void pgc_recalctimings(pgc_t *dev) { - double disptime, _dispontime, _dispofftime; - double pixel_clock = (cpuclock / (dev->cga_selected ? 25175000.0 : dev->native_pixel_clock) * (double) (1ull << 32)); - uint8_t crtc0 = 97, crtc1 = 80; /* Values from MDA, taken from there due to the 25 MHz refresh rate. */ + double disptime; + double _dispontime; + double _dispofftime; + double pixel_clock = (cpuclock / (dev->cga_selected ? 25175000.0 : dev->native_pixel_clock) * (double) (1ULL << 32)); + uint8_t crtc0 = 97; /* Value from MDA, taken from there due to the 25 MHz refresh rate. */ + uint8_t crtc1 = 80; /* Value from MDA, taken from there due to the 25 MHz refresh rate. */ /* Multiply pixel clock by 8. */ pixel_clock *= 8.0; @@ -2309,8 +2328,8 @@ pgc_read(uint32_t addr, void *priv) void pgc_cga_text(pgc_t *dev, int w) { - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int drawcursor = 0; uint32_t cols[2]; int pitch = (dev->mapram[0x3e9] + 1) * 2; @@ -2324,7 +2343,7 @@ pgc_cga_text(pgc_t *dev, int w) addr = &dev->cga_vram[((ma + ((dev->displine / pitch) * w)) * 2) & 0x3ffe]; ma += (dev->displine / pitch) * w; - for (x = 0; x < w; x++) { + for (int x = 0; x < w; x++) { chr = *addr++; attr = *addr++; @@ -2344,7 +2363,7 @@ pgc_cga_text(pgc_t *dev, int w) cols[0] = (attr >> 4) + 16; } - for (c = 0; c < cw; c++) { + for (int c = 0; c < cw; c++) { if (drawcursor) val = cols[(fontdatm[chr + dev->fontbase][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ 0x0f; else @@ -2365,7 +2384,6 @@ pgc_cga_text(pgc_t *dev, int w) void pgc_cga_gfx40(pgc_t *dev) { - int x, c; uint32_t cols[4]; int col; uint16_t ma = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; @@ -2394,11 +2412,11 @@ pgc_cga_gfx40(pgc_t *dev) cols[3] = col | 6; } - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { addr = &dev->cga_vram[(ma + 2 * x + 80 * (dev->displine >> 2) + 0x2000 * ((dev->displine >> 1) & 1)) & 0x3fff]; dat = (addr[0] << 8) | addr[1]; dev->ma++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[dev->displine][(x << 4) + (c << 1)] = buffer32->line[dev->displine][(x << 4) + (c << 1) + 1] = cols[dat >> 14]; dat <<= 2; } @@ -2409,7 +2427,6 @@ pgc_cga_gfx40(pgc_t *dev) void pgc_cga_gfx80(pgc_t *dev) { - int x, c; uint32_t cols[2]; uint16_t ma = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; uint8_t *addr; @@ -2418,11 +2435,11 @@ pgc_cga_gfx80(pgc_t *dev) cols[0] = 16; cols[1] = (dev->mapram[0x3d9] & 15) + 16; - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { addr = &dev->cga_vram[(ma + 2 * x + 80 * (dev->displine >> 2) + 0x2000 * ((dev->displine >> 1) & 1)) & 0x3fff]; dat = (addr[0] << 8) | addr[1]; dev->ma++; - for (c = 0; c < 16; c++) { + for (uint8_t c = 0; c < 16; c++) { buffer32->line[dev->displine][(x << 4) + c] = cols[dat >> 15]; dat <<= 1; } @@ -2512,7 +2529,7 @@ void pgc_poll(void *priv) { pgc_t *dev = (pgc_t *) priv; - uint32_t x, y; + uint32_t y; if (dev->cga_selected) { pgc_cga_poll(dev); @@ -2532,7 +2549,7 @@ pgc_poll(void *priv) * the IM1024 driver uses PAN -112 for an offset of * 224. */ y = dev->displine - 2 * dev->pan_y; - for (x = 0; x < dev->screenw; x++) { + for (uint32_t x = 0; x < dev->screenw; x++) { if (x + dev->pan_x < dev->maxw) buffer32->line[dev->displine][x] = dev->palette[dev->vram[y * dev->maxw + x]]; else @@ -2643,8 +2660,6 @@ void pgc_init(pgc_t *dev, int maxw, int maxh, int visw, int vish, int (*inpbyte)(pgc_t *, uint8_t *), double npc) { - int i; - /* Make it a 16k mapping at C4000 (will be C4000-C7FFF), because of the emulator's granularity - the original mapping will conflict with hard disk controller BIOS'es. */ @@ -2671,7 +2686,7 @@ pgc_init(pgc_t *dev, int maxw, int maxh, int visw, int vish, /* Create and initialize command lists. */ dev->clist = (pgc_cl_t *) malloc(256 * sizeof(pgc_cl_t)); memset(dev->clist, 0x00, 256 * sizeof(pgc_cl_t)); - for (i = 0; i < 256; i++) { + for (uint16_t i = 0; i < 256; i++) { dev->clist[i].list = NULL; dev->clist[i].listmax = 0; dev->clist[i].wrptr = 0; @@ -2708,7 +2723,7 @@ pgc_standalone_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_CGA, &timing_pgc); - return (dev); + return dev; } const device_t pgc_device = { diff --git a/src/video/vid_rtg310x.c b/src/video/vid_rtg310x.c index 6f317426b..f643fd1e4 100644 --- a/src/video/vid_rtg310x.c +++ b/src/video/vid_rtg310x.c @@ -209,22 +209,22 @@ rtg_recalctimings(svga_t *svga) case 1: break; case 2: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; case 3: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65100000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65100000.0; break; case 4: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; break; case 5: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50000000.0; break; case 6: - svga->clock = (cpuclock * (double) (1ull << 32)) / 80000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 80000000.0; break; case 7: - svga->clock = (cpuclock * (double) (1ull << 32)) / 75000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 75000000.0; break; } @@ -317,7 +317,7 @@ rtg_init(const device_t *info) rom_init(&dev->bios_rom, (char *) fn, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - return (dev); + return dev; } static void diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index 68b84d9db..bcdd64d40 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -376,24 +376,24 @@ typedef struct s3_t { static void s3_updatemapping(s3_t *s3); -static void s3_accel_write(uint32_t addr, uint8_t val, void *p); -static void s3_accel_write_w(uint32_t addr, uint16_t val, void *p); -static void s3_accel_write_l(uint32_t addr, uint32_t val, void *p); -static uint8_t s3_accel_read(uint32_t addr, void *p); -static uint16_t s3_accel_read_w(uint32_t addr, void *p); -static uint32_t s3_accel_read_l(uint32_t addr, void *p); +static void s3_accel_write(uint32_t addr, uint8_t val, void *priv); +static void s3_accel_write_w(uint32_t addr, uint16_t val, void *priv); +static void s3_accel_write_l(uint32_t addr, uint32_t val, void *priv); +static uint8_t s3_accel_read(uint32_t addr, void *priv); +static uint16_t s3_accel_read_w(uint32_t addr, void *priv); +static uint32_t s3_accel_read_l(uint32_t addr, void *priv); -static void s3_out(uint16_t addr, uint8_t val, void *p); -static uint8_t s3_in(uint16_t addr, void *p); +static void s3_out(uint16_t addr, uint8_t val, void *priv); +static uint8_t s3_in(uint16_t addr, void *priv); -static void s3_accel_out(uint16_t port, uint8_t val, void *p); -static void s3_accel_out_w(uint16_t port, uint16_t val, void *p); -static void s3_accel_out_l(uint16_t port, uint32_t val, void *p); -static uint8_t s3_accel_in(uint16_t port, void *p); -static uint16_t s3_accel_in_w(uint16_t port, void *p); -static uint32_t s3_accel_in_l(uint16_t port, void *p); -static uint8_t s3_pci_read(int func, int addr, void *p); -static void s3_pci_write(int func, int addr, uint8_t val, void *p); +static void s3_accel_out(uint16_t port, uint8_t val, void *priv); +static void s3_accel_out_w(uint16_t port, uint16_t val, void *priv); +static void s3_accel_out_l(uint16_t port, uint32_t val, void *priv); +static uint8_t s3_accel_in(uint16_t port, void *priv); +static uint16_t s3_accel_in_w(uint16_t port, void *priv); +static uint32_t s3_accel_in_l(uint16_t port, void *priv); +static uint8_t s3_pci_read(int func, int addr, void *priv); +static void s3_pci_write(int func, int addr, uint8_t val, void *priv); /*Remap address for chain-4/doubleword style layout. These will stay for convenience.*/ @@ -498,7 +498,7 @@ static void s3_visionx68_video_engine_op(uint32_t cpu_dat, s3_t *s3); temp = svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx)) & s3->vram_mask]; #define READ_PIXTRANS_WORD \ - if (s3->bpp == 0 && !s3->color_16bit) { \ + if ((s3->bpp == 0) && !s3->color_16bit) { \ temp = svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx)) & s3->vram_mask]; \ temp |= (svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx + 1)) & s3->vram_mask] << 8); \ } else { \ @@ -506,7 +506,7 @@ static void s3_visionx68_video_engine_op(uint32_t cpu_dat, s3_t *s3); } #define READ_PIXTRANS_LONG \ - if (s3->bpp == 0 && !s3->color_16bit) { \ + if ((s3->bpp == 0) && !s3->color_16bit) { \ temp = svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx)) & s3->vram_mask]; \ temp |= (svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx + 1)) & s3->vram_mask] << 8); \ temp |= (svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx + 2)) & s3->vram_mask] << 16); \ @@ -1980,7 +1980,7 @@ s3_accel_write_fifo_l(s3_t *s3, uint32_t addr, uint32_t val) static void s3_vblank_start(svga_t *svga) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; s3->subsys_stat |= INT_VSY; s3_update_irqs(s3); @@ -2003,13 +2003,14 @@ s3_hwcursor_convert_addr(svga_t *svga) static void s3_hwcursor_draw(svga_t *svga, int displine) { - s3_t *s3 = (s3_t *) svga->p; - int x, shift = 1; + s3_t *s3 = (s3_t *) svga->priv; + int shift = 1; int width = 16; uint16_t dat[2]; int xx; int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; - uint32_t fg, bg; + uint32_t fg; + uint32_t bg; uint32_t real_addr; uint32_t remapped_addr; @@ -2070,7 +2071,7 @@ s3_hwcursor_draw(svga_t *svga, int displine) real_addr = s3_hwcursor_convert_addr(svga); - for (x = 0; x < 64; x += 16) { + for (uint8_t x = 0; x < 64; x += 16) { remapped_addr = dword_remap(svga, real_addr); dat[0] = (svga->vram[remapped_addr & s3->vram_mask] << 8) | svga->vram[(remapped_addr + 1) & s3->vram_mask]; @@ -2331,12 +2332,15 @@ s3_hwcursor_draw(svga_t *svga, int displine) static void s3_trio64v_overlay_draw(svga_t *svga, int displine) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; int offset = (s3->streams.sec_x - s3->streams.pri_x) + 1; int h_acc = s3->streams.dda_horiz_accumulator; - int r[8], g[8], b[8]; - int x_size, x_read = 4, x_write = 4; - int x; + int r[8]; + int g[8]; + int b[8]; + int x_size; + int x_read = 4; + int x_write = 4; uint32_t *p; uint8_t *src = &svga->vram[svga->overlay_latch.addr]; @@ -2349,7 +2353,7 @@ s3_trio64v_overlay_draw(svga_t *svga, int displine) OVERLAY_SAMPLE(); - for (x = 0; x < x_size; x++) { + for (int x = 0; x < x_size; x++) { *p++ = r[x_read] | (g[x_read] << 8) | (b[x_read] << 16); h_acc += s3->streams.k1_horiz_scale; @@ -2558,12 +2562,14 @@ s3_io_set(s3_t *s3) } static void -s3_out(uint16_t addr, uint8_t val, void *p) +s3_out(uint16_t addr, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; - uint8_t old, mask; - int rs2, rs3; + uint8_t old; + uint8_t mask; + int rs2; + int rs3; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -2632,7 +2638,7 @@ s3_out(uint16_t addr, uint8_t val, void *p) bt48x_ramdac_out(addr, rs2, rs3, val, svga->ramdac, svga); } else if ((s3->chip == S3_VISION964 && s3->card_type == S3_ELSAWIN2KPROX_964) || (s3->chip == S3_VISION968 && (s3->card_type == S3_ELSAWIN2KPROX || s3->card_type == S3_PHOENIX_VISION968 || s3->card_type == S3_NUMBER9_9FX_771))) ibm_rgb528_ramdac_out(addr, rs2, val, svga->ramdac, svga); - else if ((s3->chip == S3_VISION968 && (s3->card_type == S3_SPEA_MERCURY_P64V || s3->card_type == S3_MIROVIDEO40SV_ERGO_968))) { + else if (s3->chip == S3_VISION968 && (s3->card_type == S3_SPEA_MERCURY_P64V || s3->card_type == S3_MIROVIDEO40SV_ERGO_968)) { rs3 = !!(svga->crtc[0x55] & 0x02); tvp3026_ramdac_out(addr, rs2, rs3, val, svga->ramdac, svga); } else if (((s3->chip == S3_86C801) || (s3->chip == S3_86C805)) && (s3->card_type != S3_MIROCRYSTAL10SD_805 && s3->card_type != S3_MIROCRYSTAL8S_805)) @@ -2665,6 +2671,7 @@ s3_out(uint16_t addr, uint8_t val, void *p) return; if ((s3->chip <= S3_86C924) && (svga->crtcreg >= 0x50)) return; + old = svga->crtc[svga->crtcreg]; svga->crtc[svga->crtcreg] = val; @@ -2902,11 +2909,12 @@ s3_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -s3_in(uint16_t addr, void *p) +s3_in(uint16_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; - int rs2, rs3; + int rs2; + int rs3; uint8_t temp; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -3010,7 +3018,6 @@ s3_in(uint16_t addr, void *p) } } else return svga->crtc[0x6b]; - break; case 0x6c: if (s3->chip != S3_TRIO64V2) { if (svga->crtc[0x53] & 0x08) { @@ -3019,7 +3026,6 @@ s3_in(uint16_t addr, void *p) return (svga->crtc[0x5a] & 0x80); } else return svga->crtc[0x6c]; - break; } return svga->crtc[svga->crtcreg]; } @@ -3029,7 +3035,7 @@ s3_in(uint16_t addr, void *p) static void s3_recalctimings(svga_t *svga) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; int clk_sel = (svga->miscout >> 2) & 3; if (!svga->scrblank && svga->attr_palette_enable) { @@ -3068,7 +3074,7 @@ s3_recalctimings(svga_t *svga) svga->rowoffset |= 0x100; } if (!svga->rowoffset) - svga->rowoffset = 256; + svga->rowoffset = 0x100; if ((s3->chip == S3_VISION964) || (s3->chip == S3_86C928)) { if (s3->card_type == S3_ELSAWIN2KPROX_964) @@ -3086,7 +3092,7 @@ s3_recalctimings(svga_t *svga) if ((((svga->miscout >> 2) & 3) == 3) && s3->chip < S3_TRIO32) clk_sel = svga->crtc[0x42] & 0x0f; - svga->clock = (cpuclock * (double) (1ull << 32)) / svga->getclock(clk_sel, svga->clock_gen); + svga->clock = (cpuclock * (double) (1ULL << 32)) / svga->getclock(clk_sel, svga->clock_gen); switch (svga->crtc[0x67] >> 4) { case 3: @@ -3113,7 +3119,7 @@ s3_recalctimings(svga_t *svga) } } else { if (s3->card_type == S3_NUMBER9_9FX_531) { - if (svga->hdisp == 1600 && s3->width == 1600) + if ((svga->hdisp == 1600) && (s3->width == 1600)) s3->width = 800; } } @@ -3124,10 +3130,10 @@ s3_recalctimings(svga_t *svga) } } - if ((svga->crtc[0x43] & 0x08) && (s3->color_16bit == 0) && (s3->chip <= S3_86C805)) { + if ((svga->crtc[0x43] & 0x08) && !s3->color_16bit && (s3->chip <= S3_86C805)) { s3->color_16bit = 1; - s3->width = 1024; - } else if (!(svga->crtc[0x43] & 0x08) && (s3->color_16bit == 1) && (s3->chip <= S3_86C805)) { + s3->width = 1024; + } else if (!(svga->crtc[0x43] & 0x08) && s3->color_16bit && (s3->chip <= S3_86C805)) { s3->color_16bit = 0; if (s3->chip <= S3_86C924) { if (s3->accel.advfunc_cntl & 4) @@ -3340,7 +3346,7 @@ s3_recalctimings(svga_t *svga) static void s3_trio64v_recalctimings(svga_t *svga) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; int clk_sel = (svga->miscout >> 2) & 3; if (!svga->scrblank && svga->attr_palette_enable) { @@ -3368,7 +3374,7 @@ s3_trio64v_recalctimings(svga_t *svga) svga->split |= 0x400; svga->interlace = svga->crtc[0x42] & 0x20; - svga->clock = (cpuclock * (double) (1ull << 32)) / svga->getclock(clk_sel, svga->clock_gen); + svga->clock = (cpuclock * (double) (1ULL << 32)) / svga->getclock(clk_sel, svga->clock_gen); if ((svga->crtc[0x67] & 0xc) != 0xc) /*VGA mode*/ { @@ -3574,12 +3580,14 @@ s3_updatemapping(s3_t *s3) } static float -s3_trio64_getclock(int clock, void *p) +s3_trio64_getclock(int clock, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; float t; - int m, n1, n2; + int m; + int n1; + int n2; if (clock == 0) return 25175000.0; if (clock == 1) @@ -3592,9 +3600,9 @@ s3_trio64_getclock(int clock, void *p) } static void -s3_accel_out(uint16_t port, uint8_t val, void *p) +s3_accel_out(uint16_t port, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (port >= 0x8000) { @@ -3640,9 +3648,9 @@ s3_accel_out(uint16_t port, uint8_t val, void *p) } static void -s3_accel_out_w(uint16_t port, uint16_t val, void *p) +s3_accel_out_w(uint16_t port, uint16_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; if (!s3->enable_8514) return; @@ -3654,9 +3662,9 @@ s3_accel_out_w(uint16_t port, uint16_t val, void *p) } static void -s3_accel_out_l(uint16_t port, uint32_t val, void *p) +s3_accel_out_l(uint16_t port, uint32_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; if (!s3->enable_8514) return; @@ -3668,9 +3676,9 @@ s3_accel_out_l(uint16_t port, uint32_t val, void *p) } static uint8_t -s3_accel_in(uint16_t port, void *p) +s3_accel_in(uint16_t port, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; int temp; @@ -4252,9 +4260,9 @@ s3_accel_in(uint16_t port, void *p) } static uint16_t -s3_accel_in_w(uint16_t port, void *p) +s3_accel_in_w(uint16_t port, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint16_t temp = 0x0000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4308,9 +4316,9 @@ s3_accel_in_w(uint16_t port, void *p) } static uint32_t -s3_accel_in_l(uint16_t port, void *p) +s3_accel_in_l(UNUSED(uint16_t port), void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint32_t temp = 0x00000000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4361,9 +4369,9 @@ s3_accel_in_l(uint16_t port, void *p) } static void -s3_accel_write(uint32_t addr, uint8_t val, void *p) +s3_accel_write(uint32_t addr, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (!s3->enable_8514) @@ -4379,9 +4387,9 @@ s3_accel_write(uint32_t addr, uint8_t val, void *p) } static void -s3_accel_write_w(uint32_t addr, uint16_t val, void *p) +s3_accel_write_w(uint32_t addr, uint16_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (!s3->enable_8514) @@ -4397,9 +4405,9 @@ s3_accel_write_w(uint32_t addr, uint16_t val, void *p) } static void -s3_accel_write_l(uint32_t addr, uint32_t val, void *p) +s3_accel_write_l(uint32_t addr, uint32_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (!s3->enable_8514) @@ -4415,9 +4423,9 @@ s3_accel_write_l(uint32_t addr, uint32_t val, void *p) } static uint8_t -s3_accel_read(uint32_t addr, void *p) +s3_accel_read(uint32_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint8_t temp = 0x00; @@ -4482,12 +4490,12 @@ s3_accel_read(uint32_t addr, void *p) case 0x8505: return s3->subsys_cntl; default: - return s3_accel_in(addr & 0xffff, p); + return s3_accel_in(addr & 0xffff, priv); } return 0xff; } else { if (addr & 0x8000) { - temp = s3_accel_in(addr & 0xffff, p); + temp = s3_accel_in(addr & 0xffff, priv); } else if (s3_cpu_dest(s3)) { READ_PIXTRANS_BYTE_MM @@ -4518,9 +4526,9 @@ s3_accel_read(uint32_t addr, void *p) } static uint16_t -s3_accel_read_w(uint32_t addr, void *p) +s3_accel_read_w(uint32_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint16_t temp = 0x0000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4536,7 +4544,7 @@ s3_accel_read_w(uint32_t addr, void *p) return s3->accel.short_stroke; default: - return s3_accel_read(addr, p) | s3_accel_read(addr + 1, p) << 8; + return s3_accel_read(addr, priv) | s3_accel_read(addr + 1, priv) << 8; } return 0xffff; } else { @@ -4546,8 +4554,8 @@ s3_accel_read_w(uint32_t addr, void *p) s3_wait_fifo_idle(s3); temp = s3->accel.short_stroke; } else { - temp = s3_accel_read((addr & 0xfffe), p); - temp |= s3_accel_read((addr & 0xfffe) + 1, p) << 8; + temp = s3_accel_read((addr & 0xfffe), priv); + temp |= s3_accel_read((addr & 0xfffe) + 1, priv) << 8; } } else if (s3_cpu_dest(s3)) { READ_PIXTRANS_WORD @@ -4579,9 +4587,9 @@ s3_accel_read_w(uint32_t addr, void *p) } static uint32_t -s3_accel_read_l(uint32_t addr, void *p) +s3_accel_read_l(uint32_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint32_t temp = 0x00000000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4711,15 +4719,15 @@ s3_accel_read_l(uint32_t addr, void *p) break; default: - temp = s3_accel_read_w(addr, p) | (s3_accel_read_w(addr + 2, p) << 16); + temp = s3_accel_read_w(addr, priv) | (s3_accel_read_w(addr + 2, priv) << 16); break; } } else { if (addr & 0x8000) { - temp = s3_accel_read((addr & 0xfffc), p); - temp |= s3_accel_read((addr & 0xfffc) + 1, p) << 8; - temp |= s3_accel_read((addr & 0xfffc) + 2, p) << 16; - temp |= s3_accel_read((addr & 0xfffc) + 3, p) << 24; + temp = s3_accel_read((addr & 0xfffc), priv); + temp |= s3_accel_read((addr & 0xfffc) + 1, priv) << 8; + temp |= s3_accel_read((addr & 0xfffc) + 2, priv) << 16; + temp |= s3_accel_read((addr & 0xfffc) + 3, priv) << 24; } else if (s3_cpu_dest(s3)) { READ_PIXTRANS_LONG @@ -4799,9 +4807,9 @@ polygon_setup(s3_t *s3) } #define READ(addr, dat) \ - if (s3->bpp == 0 && !s3->color_16bit) \ + if ((s3->bpp == 0) && !s3->color_16bit) \ dat = svga->vram[dword_remap(svga, addr) & s3->vram_mask]; \ - else if (s3->bpp == 1 || s3->color_16bit) \ + else if ((s3->bpp == 1) || s3->color_16bit) \ dat = vram_w[dword_remap_w(svga, addr) & (s3->vram_mask >> 1)]; \ else if (s3->bpp == 2) \ dat = svga->vram[dword_remap(svga, addr) & s3->vram_mask]; \ @@ -5651,10 +5659,10 @@ polygon_setup(s3_t *s3) } #define WRITE(addr, dat) \ - if (s3->bpp == 0 && !s3->color_16bit) { \ + if ((s3->bpp == 0) && !s3->color_16bit) { \ svga->vram[dword_remap(svga, addr) & s3->vram_mask] = dat; \ svga->changedvram[(dword_remap(svga, addr) & s3->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ - } else if (s3->bpp == 1 || s3->color_16bit) { \ + } else if ((s3->bpp == 1) || s3->color_16bit) { \ vram_w[dword_remap_w(svga, addr) & (s3->vram_mask >> 1)] = dat; \ svga->changedvram[(dword_remap_w(svga, addr) & (s3->vram_mask >> 1)) >> 11] = svga->monitor->mon_changeframecount; \ } else if (s3->bpp == 2) { \ @@ -5668,9 +5676,15 @@ polygon_setup(s3_t *s3) static __inline void convert_to_rgb32(int idf, int is_yuv, uint32_t val, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *r2, uint8_t *g2, uint8_t *b2) { - static double dr = 0.0, dg = 0.0, db = 0.0; - static double dY1 = 0.0, dCr = 0.0, dY2 = 0.0, dCb = 0.0; - static double dU = 0.0, dV = 0.0; + static double dr = 0.0; + static double dg = 0.0; + static double db = 0.0; + static double dY1 = 0.0; + static double dCr = 0.0; + static double dY2 = 0.0; + static double dCb = 0.0; + static double dU = 0.0; + static double dV = 0.0; switch (idf) { case 0: /* 8 bpp, RGB 3-3-2 */ @@ -5750,10 +5764,18 @@ convert_to_rgb32(int idf, int is_yuv, uint32_t val, uint8_t *r, uint8_t *g, uint static __inline void convert_from_rgb32(int idf, int odf, int is_yuv, uint32_t *val, uint8_t r, uint8_t g, uint8_t b, uint8_t r2, uint8_t g2, uint8_t b2) { - static double dr = 0.0, dg = 0.0, db = 0.0; - static double dr2 = 0.0, dg2 = 0.0, db2 = 0.0; - static double dY1 = 0.0, dCr = 0.0, dY2 = 0.0, dCb = 0.0; - static double dU = 0.0, dV = 0.0; + static double dr = 0.0; + static double dg = 0.0; + static double db = 0.0; + static double dr2 = 0.0; + static double dg2 = 0.0; + static double db2 = 0.0; + static double dY1 = 0.0; + static double dCr = 0.0; + static double dY2 = 0.0; + static double dCb = 0.0; + static double dU = 0.0; + static double dV = 0.0; dr = (double) r; dg = (double) g; @@ -5832,13 +5854,23 @@ static void s3_visionx68_video_engine_op(uint32_t cpu_dat, s3_t *s3) { svga_t *svga = &s3->svga; - int idf, odf, host; + int idf; + int odf; + int host; int is_yuv; - uint32_t src, dest = 0x00000000; - uint8_t r = 0x00, g = 0x00, b = 0x00, r2 = 0x00, g2 = 0x00, b2 = 0x00; + uint32_t src; + uint32_t dest = 0x00000000; + uint8_t r = 0x00; + uint8_t g = 0x00; + uint8_t b = 0x00; + uint8_t r2 = 0x00; + uint8_t g2 = 0x00; + uint8_t b2 = 0x00; uint16_t *vram_w = (uint16_t *) svga->vram; uint32_t *vram_l = (uint32_t *) svga->vram; - uint32_t k2 = 0, dda = 0, diff = 0; + uint32_t k2 = 0; + uint32_t dda = 0; + uint32_t diff = 0; int count = -1; idf = s3->videoengine.idf; @@ -5879,8 +5911,8 @@ s3_visionx68_video_engine_op(uint32_t cpu_dat, s3_t *s3) s3->videoengine.sx = k2 - dda + diff - 1; s3->videoengine.sx_backup = s3->videoengine.len - s3->videoengine.start - 1; } - s3->videoengine.sx_scale_inc = (double) ((s3->videoengine.sx_backup >> 1)); - s3->videoengine.sx_scale_inc = s3->videoengine.sx_scale_inc / (double) ((s3->videoengine.sx >> 1)); + s3->videoengine.sx_scale_inc = (double) (s3->videoengine.sx_backup >> 1); + s3->videoengine.sx_scale_inc = s3->videoengine.sx_scale_inc / (double) (s3->videoengine.sx >> 1); } else { s3->videoengine.sx_scale = (double) (s3->videoengine.k1 - 2); s3->videoengine.sx_scale_dec = (s3->videoengine.sx_scale / (double) (s3->videoengine.len - s3->videoengine.start - 2)); @@ -5942,8 +5974,8 @@ s3_visionx68_video_engine_op(uint32_t cpu_dat, s3_t *s3) s3->videoengine.sx = k2 - dda + diff - 1; s3->videoengine.sx_backup = s3->videoengine.len - s3->videoengine.start - 1; } - s3->videoengine.sx_scale_inc = (double) ((s3->videoengine.sx_backup >> 1)); - s3->videoengine.sx_scale_inc = s3->videoengine.sx_scale_inc / (double) ((s3->videoengine.sx >> 1)); + s3->videoengine.sx_scale_inc = (double) (s3->videoengine.sx_backup >> 1); + s3->videoengine.sx_scale_inc = s3->videoengine.sx_scale_inc / (double) (s3->videoengine.sx >> 1); s3->videoengine.cx = 0.0; s3->videoengine.dx = 0.0; @@ -6036,9 +6068,13 @@ void s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_t *s3) { svga_t *svga = &s3->svga; - uint32_t src_dat = 0, dest_dat, old_dest_dat; - uint32_t out, pat_dat = 0; - int frgd_mix, bkgd_mix; + uint32_t src_dat = 0; + uint32_t dest_dat; + uint32_t old_dest_dat; + uint32_t out; + uint32_t pat_dat = 0; + int frgd_mix; + int bkgd_mix; int clip_t = s3->accel.multifunc[1] & 0xfff; int clip_l = s3->accel.multifunc[2] & 0xfff; int clip_b = s3->accel.multifunc[3] & 0xfff; @@ -6052,7 +6088,8 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ int compare_mode = (s3->accel.multifunc[0xe] >> 7) & 3; uint32_t rd_mask = s3->accel.rd_mask; int cmd = s3->accel.cmd >> 13; - uint32_t srcbase, dstbase; + uint32_t srcbase; + uint32_t dstbase; if ((s3->chip >= S3_TRIO64 || s3->chip == S3_VISION968 || s3->chip == S3_VISION868) && (s3->accel.cmd & (1 << 11))) { cmd |= 8; @@ -6077,7 +6114,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ dstbase >>= 2; } - if ((s3->accel.cmd & 0x100) && ((s3_cpu_src(s3) || (s3_cpu_dest(s3)))) && (!cpu_input || (s3_enable_fifo(s3) == 0))) { + if ((s3->accel.cmd & 0x100) && (s3_cpu_src(s3) || (s3_cpu_dest(s3))) && (!cpu_input || (s3_enable_fifo(s3) == 0))) { s3->force_busy = 1; } @@ -6085,7 +6122,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ s3->accel.dat_count = 0; if (cpu_input && (((s3->accel.multifunc[0xa] & 0xc0) != 0x80) || (!(s3->accel.cmd & 2)))) { - if ((s3->bpp == 3) && count == 2) { + if ((s3->bpp == 3) && (count == 2)) { if (s3->accel.dat_count) { cpu_dat = ((cpu_dat & 0xffff) << 16) | s3->accel.dat_buf; count = 4; @@ -6095,20 +6132,20 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ s3->accel.dat_count = 1; } } - if (s3->bpp == 1 || s3->color_16bit) + if ((s3->bpp == 1) || s3->color_16bit) count >>= 1; if (s3->bpp == 3) count >>= 2; } - if (s3->bpp == 0 && !s3->color_16bit) + if ((s3->bpp == 0) && !s3->color_16bit) rd_mask &= 0xff; - else if (s3->bpp == 1 || s3->color_16bit) + else if ((s3->bpp == 1) || s3->color_16bit) rd_mask &= 0xffff; - if (s3->bpp == 0 && !s3->color_16bit) + if ((s3->bpp == 0) && !s3->color_16bit) compare &= 0xff; - if (s3->bpp == 1 || s3->color_16bit) + if ((s3->bpp == 1) || s3->color_16bit) compare &= 0xffff; switch (s3->accel.cmd & 0x600) { @@ -6174,6 +6211,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ cpu_dat >>= 8; else cpu_dat >>= 16; + if (!s3->accel.ssv_len) break; @@ -6221,18 +6259,16 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ s3->accel.cx = s3->accel.cur_x & 0x7ff; s3->accel.cy = s3->accel.cur_y & 0x7ff; - if (s3->accel.cur_x & 0x800) { + if (s3->accel.cur_x & 0x800) s3->accel.cx |= ~0x7ff; - } - if (s3->accel.cur_y & 0x800) { + + if (s3->accel.cur_y & 0x800) s3->accel.cy |= ~0x7ff; - } s3->accel.sy = s3->accel.maj_axis_pcnt; - if (s3_cpu_src(s3)) { + if (s3_cpu_src(s3)) return; /*Wait for data from CPU*/ - } } frgd_mix = (s3->accel.frgd_mix >> 5) & 3; bkgd_mix = (s3->accel.bkgd_mix >> 5) & 3; @@ -6267,11 +6303,10 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ mix_dat <<= 1; mix_dat |= 1; - if (s3->bpp == 0 && !s3->color_16bit) + if ((s3->bpp == 0) && !s3->color_16bit) cpu_dat >>= 8; - else { + else cpu_dat >>= 16; - } if (!s3->accel.sy) { break; @@ -6313,13 +6348,13 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ s3->accel.cur_y = s3->accel.cy; } else /*Bresenham*/ { - if (s3->accel.b2e8_pix && s3_cpu_src(s3) && count == 16) { /*Stupid undocumented 0xB2E8 on 911/924*/ + if (s3->accel.b2e8_pix && s3_cpu_src(s3) && (count == 16)) { /*Stupid undocumented 0xB2E8 on 911/924*/ count = s3->accel.maj_axis_pcnt + 1; s3->accel.temp_cnt = 16; } while (count-- && s3->accel.sy >= 0) { - if (s3->accel.b2e8_pix && s3_cpu_src(s3) && s3->accel.temp_cnt == 0) { + if (s3->accel.b2e8_pix && s3_cpu_src(s3) && !s3->accel.temp_cnt) { mix_dat >>= 16; s3->accel.temp_cnt = 16; } @@ -6476,7 +6511,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ s3->accel.temp_cnt = 16; } - if (((s3->accel.cx & 0xfff) >= clip_l && (s3->accel.cx & 0xfff) <= clip_r && (s3->accel.cy & 0xfff) >= clip_t && (s3->accel.cy & 0xfff) <= clip_b)) { + if ((s3->accel.cx & 0xfff) >= clip_l && (s3->accel.cx & 0xfff) <= clip_r && (s3->accel.cy & 0xfff) >= clip_t && (s3->accel.cy & 0xfff) <= clip_b) { if (s3_cpu_dest(s3) && ((s3->accel.multifunc[0xa] & 0xc0) == 0x00)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ } else if (s3_cpu_dest(s3) && vram_mask) { @@ -6506,7 +6541,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ break; } - if (((compare_mode == 2 && src_dat != compare) || (compare_mode == 3 && src_dat == compare) || compare_mode < 2)) { + if ((compare_mode == 2 && src_dat != compare) || (compare_mode == 3 && src_dat == compare) || compare_mode < 2) { READ(s3->accel.dest + s3->accel.cx, dest_dat); MIX @@ -6529,7 +6564,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ mix_dat |= 1; } - if (s3->bpp == 0 && !s3->color_16bit) + if ((s3->bpp == 0) && !s3->color_16bit) cpu_dat >>= 8; else { cpu_dat >>= 16; @@ -6574,7 +6609,8 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ case 3: /*Polygon Fill Solid (Vision868/968 and Trio64 only)*/ { - int end_y1, end_y2; + int end_y1; + int end_y2; if (s3->chip != S3_TRIO64 && s3->chip != S3_VISION968 && s3->chip != S3_VISION868) break; @@ -6612,7 +6648,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ break; } - if (((compare_mode == 2 && src_dat != compare) || (compare_mode == 3 && src_dat == compare) || compare_mode < 2)) { + if ((compare_mode == 2 && src_dat != compare) || (compare_mode == 3 && src_dat == compare) || compare_mode < 2) { READ(s3->accel.dest + s3->accel.poly_x, dest_dat); MIX @@ -6688,7 +6724,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ if (!cpu_input && frgd_mix == 3 && !vram_mask && !compare_mode && (s3->accel.cmd & 0xa0) == 0xa0 && (s3->accel.frgd_mix & 0xf) == 7 && (s3->accel.bkgd_mix & 0xf) == 7) { while (1) { - if (((s3->accel.dx & 0xfff) >= clip_l && (s3->accel.dx & 0xfff) <= clip_r && (s3->accel.dy & 0xfff) >= clip_t && (s3->accel.dy & 0xfff) <= clip_b)) { + if ((s3->accel.dx & 0xfff) >= clip_l && (s3->accel.dx & 0xfff) <= clip_r && (s3->accel.dy & 0xfff) >= clip_t && (s3->accel.dy & 0xfff) <= clip_b) { READ(s3->accel.src + s3->accel.cx, src_dat); READ(s3->accel.dest + s3->accel.dx, dest_dat); @@ -6747,6 +6783,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ } if ((((compare_mode == 2 && src_dat != compare) || (compare_mode == 3 && src_dat == compare) || compare_mode < 2))) { + READ(s3->accel.dest + s3->accel.dx, dest_dat); MIX @@ -7029,7 +7066,8 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ case 11: /*Polygon Fill Pattern (Vision868/968 and Trio64 only)*/ { - int end_y1, end_y2; + int end_y1; + int end_y2; if (s3->chip != S3_TRIO64 && s3->chip != S3_VISION968 && s3->chip != S3_VISION868) break; @@ -7279,9 +7317,9 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ } static uint8_t -s3_pci_read(int func, int addr, void *p) +s3_pci_read(UNUSED(int func), int addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; switch (addr) { @@ -7300,7 +7338,6 @@ s3_pci_read(int func, int addr, void *p) return s3->pci_regs[PCI_REG_COMMAND] | 0x80; /*Respond to IO and memory accesses*/ else return s3->pci_regs[PCI_REG_COMMAND]; /*Respond to IO and memory accesses*/ - break; case 0x07: return (s3->chip == S3_TRIO64V2) ? (s3->pci_regs[0x07] & 0x36) : (1 << 1); /*Medium DEVSEL timing*/ @@ -7315,17 +7352,14 @@ s3_pci_read(int func, int addr, void *p) return 0x00; /*Supports VGA interface*/ else return 0x01; - break; case 0x0b: if (s3->chip >= S3_TRIO32 || s3->chip == S3_VISION968 || s3->chip == S3_VISION868) return 0x03; else return 0x00; - break; case 0x0d: return (s3->chip == S3_TRIO64V2) ? (s3->pci_regs[0x0d] & 0xf8) : 0x00; - break; case 0x10: return 0x00; /*Linear frame buffer address*/ @@ -7336,7 +7370,6 @@ s3_pci_read(int func, int addr, void *p) return 0x00; else return (svga->crtc[0x5a] & 0x80); - break; case 0x13: if (svga->crtc[0x53] & 0x08) { @@ -7344,7 +7377,6 @@ s3_pci_read(int func, int addr, void *p) } else { return svga->crtc[0x59]; } - break; case 0x30: return s3->has_bios ? (s3->pci_regs[0x30] & 0x01) : 0x00; /*BIOS ROM address*/ @@ -7365,15 +7397,14 @@ s3_pci_read(int func, int addr, void *p) break; case 0x3f: return (s3->chip == S3_TRIO64V2) ? 0xff : 0x00; - break; } return 0; } static void -s3_pci_write(int func, int addr, uint8_t val, void *p) +s3_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; switch (addr) { @@ -7455,7 +7486,8 @@ static void fifo_thread(void *param) { s3_t *s3 = (s3_t *) param; - uint64_t start_time, end_time; + uint64_t start_time; + uint64_t end_time; while (s3->fifo_thread_run) { thread_set_event(s3->fifo_not_full_event); @@ -7523,8 +7555,8 @@ s3_reset(void *priv) memset(svga->crtc, 0x00, sizeof(svga->crtc)); svga->crtc[0] = 63; svga->crtc[6] = 255; - svga->dispontime = 1000ull << 32; - svga->dispofftime = 1000ull << 32; + svga->dispontime = 1000ULL << 32; + svga->dispofftime = 1000ULL << 32; svga->bpp = 8; if (s3->pci) @@ -7661,7 +7693,8 @@ static void * s3_init(const device_t *info) { const char *bios_fn; - int chip, stepping; + int chip; + int stepping; s3_t *s3 = malloc(sizeof(s3_t)); svga_t *svga = &s3->svga; int vram; @@ -7978,7 +8011,7 @@ s3_init(const device_t *info) switch (vram) { case 0: /* 512 kB */ svga->vram_mask = (1 << 19) - 1; - svga->vram_max = 2 << 20; + svga->vram_max = 1 << 19; break; case 1: /* 1 MB */ /* VRAM in first MB, mirrored in 2nd MB, 3rd and 4th MBs are open bus. @@ -7986,7 +8019,7 @@ s3_init(const device_t *info) This works with the #9 9FX BIOS, and matches how my real Trio64 behaves, but does not work with the Phoenix EDO BIOS. Possibly an FPM/EDO difference? */ svga->vram_mask = (1 << 20) - 1; - svga->vram_max = 2 << 20; + svga->vram_max = 1 << 20; break; case 2: default: /*2 MB */ @@ -8523,9 +8556,9 @@ s3_trio64v2_dx_available(void) } static void -s3_close(void *p) +s3_close(void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; s3->fifo_thread_run = 0; thread_set_event(s3->wake_fifo_thread); @@ -8542,17 +8575,17 @@ s3_close(void *p) } static void -s3_speed_changed(void *p) +s3_speed_changed(void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_recalctimings(&s3->svga); } static void -s3_force_redraw(void *p) +s3_force_redraw(void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; s3->svga.fullchange = s3->svga.monitor->mon_changeframecount; } @@ -8928,7 +8961,7 @@ const device_t s3_9fx_771_pci_device = { { .available = s3_9fx_771_available }, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, - .config = s3_standard_config + .config = s3_968_config }; const device_t s3_phoenix_vision968_pci_device = { diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index d79053f0e..6c382cf7f 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -279,6 +279,7 @@ typedef struct virge_t { uint32_t dma_ptr; uint64_t blitter_time; volatile int fifo_slot; + int fifo_slots_num; pc_timer_t tri_timer; @@ -307,12 +308,12 @@ static void s3_virge_updatemapping(virge_t *virge); static void s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat); -static uint8_t s3_virge_mmio_read(uint32_t addr, void *p); -static uint16_t s3_virge_mmio_read_w(uint32_t addr, void *p); -static uint32_t s3_virge_mmio_read_l(uint32_t addr, void *p); -static void s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p); -static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p); -static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *p); +static uint8_t s3_virge_mmio_read(uint32_t addr, void *priv); +static uint16_t s3_virge_mmio_read_w(uint32_t addr, void *rivp); +static uint32_t s3_virge_mmio_read_l(uint32_t addr, void *priv); +static void s3_virge_mmio_write(uint32_t addr, uint8_t val, void *priv); +static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *priv); +static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv); enum { CMD_SET_AE = 1, @@ -387,9 +388,9 @@ s3_virge_log(const char *fmt, ...) #endif static void -s3_virge_tri_timer(void *p) +s3_virge_tri_timer(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; thread_set_event(virge->wake_render_thread); /*Wake up FIFO thread if moving from idle*/ } @@ -447,9 +448,9 @@ render_thread(void *param) } static void -s3_virge_out(uint16_t addr, uint8_t val, void *p) +s3_virge_out(uint16_t addr, uint8_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; uint8_t old; uint32_t cursoraddr; @@ -653,9 +654,9 @@ s3_virge_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -s3_virge_in(uint16_t addr, void *p) +s3_virge_in(uint16_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; uint8_t ret; @@ -760,7 +761,7 @@ s3_virge_in(uint16_t addr, void *p) static void s3_virge_recalctimings(svga_t *svga) { - virge_t *virge = (virge_t *) svga->p; + virge_t *virge = (virge_t *) svga->priv; svga->hdisp = svga->hdisp_old; @@ -796,7 +797,7 @@ s3_virge_recalctimings(svga_t *svga) int m = svga->seqregs[0x13] & 0x7f; double freq = (((double) m + 2) / (((double) n + 2) * (double) (1 << r))) * 14318184.0; - svga->clock = (cpuclock * (float) (1ull << 32)) / freq; + svga->clock = (cpuclock * (float) (1ULL << 32)) / freq; } if ((svga->crtc[0x67] & 0xc) != 0xc) /*VGA mode*/ @@ -988,7 +989,7 @@ s3_virge_updatemapping(virge_t *virge) static void s3_virge_vblank_start(svga_t *svga) { - virge_t *virge = (virge_t *) svga->p; + virge_t *virge = (virge_t *) svga->priv; virge->subsys_stat |= INT_VSY; s3_virge_update_irqs(virge); @@ -1031,6 +1032,8 @@ s3_virge_mmio_fifo_write_l(uint32_t addr, uint32_t val, virge_t *virge) else s3_virge_bitblt(virge, 32, val); } else { + if (virge->fifo_slot >= virge->fifo_slots_num) + return; virge->fifo_slot++; switch (addr & 0xfffc) { case 0x8590: @@ -1179,7 +1182,7 @@ s3_virge_mmio_fifo_write_l(uint32_t addr, uint32_t val, virge_t *virge) { int x = addr & 4; int y = (addr >> 3) & 7; - int color, xx; + int color; int byte; virge->s3d.pattern_8[y * 8 + x] = val & 0xff; virge->s3d.pattern_8[y * 8 + x + 1] = val >> 8; @@ -1192,7 +1195,7 @@ s3_virge_mmio_fifo_write_l(uint32_t addr, uint32_t val, virge_t *virge) virge->s3d.pattern_16[y * 8 + x + 1] = val >> 16; addr &= 0x00ff; - for (xx = 0; xx < 4; xx++) { + for (uint8_t xx = 0; xx < 4; xx++) { x = ((addr + xx) / 3) % 8; y = ((addr + xx) / 24) % 8; color = ((addr + xx) % 3) << 3; @@ -1471,25 +1474,34 @@ s3_virge_mmio_fifo_write_l(uint32_t addr, uint32_t val, virge_t *virge) } static uint8_t -s3_virge_mmio_read(uint32_t addr, void *p) +s3_virge_mmio_read(uint32_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; uint8_t ret = 0xff; s3_virge_log("[%04X:%08X]: MMIO ReadB addr = %04x\n", CS, cpu_state.pc, addr & 0xffff); switch (addr & 0xffff) { case 0x8505: - ret = 0; - if (virge->s3d_busy || virge->fifo_slot) { - ret = 0x10; - } else { - ret = 0x30; - } + ret = 0xc0; + if (!virge->s3d_busy && !virge->fifo_slot) + ret |= 0x20; if (virge->fifo_slot) virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot); return ret; + case 0x850c: + ret = virge->advfunc_cntl & 0x3f; + if (virge->fifo_slot) + virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 6; + ret &= 0xff; + break; + case 0x850d: + ret = (virge->fifo_slots_num - virge->fifo_slot) >> 2; + break; + case 0x83b0: case 0x83b1: case 0x83b2: @@ -1555,24 +1567,34 @@ s3_virge_mmio_read(uint32_t addr, void *p) return 0xff; } static uint16_t -s3_virge_mmio_read_w(uint32_t addr, void *p) +s3_virge_mmio_read_w(uint32_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; uint16_t ret = 0xffff; s3_virge_log("[%04X:%08X]: MMIO ReadW addr = %04x\n", CS, cpu_state.pc, addr & 0xfffe); switch (addr & 0xfffe) { case 0x8504: + ret = 0xc000; + if (!virge->s3d_busy && !virge->fifo_slot) + ret |= 0x2000; if (!virge->fifo_slot) virge->subsys_stat |= INT_FIFO_EMP; ret |= virge->subsys_stat; if (virge->fifo_slot) virge->fifo_slot--; - ret |= 0x30; /*A bit of a workaround at the moment.*/ + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 8; s3_virge_update_irqs(virge); return ret; + case 0x850c: + ret = virge->advfunc_cntl & 0x3f; + if (virge->fifo_slot) + virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 6; + break; + case 0x859c: return virge->cmd_dma; @@ -1584,9 +1606,9 @@ s3_virge_mmio_read_w(uint32_t addr, void *p) } static uint32_t -s3_virge_mmio_read_l(uint32_t addr, void *p) +s3_virge_mmio_read_l(uint32_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; uint32_t ret = 0xffffffff; s3_virge_log("[%04X:%08X]: MMIO ReadL addr = %04x\n", CS, cpu_state.pc, addr & 0xfffc); @@ -1660,10 +1682,9 @@ s3_virge_mmio_read_l(uint32_t addr, void *p) break; case 0x8504: - if (virge->s3d_busy || virge->fifo_slot) { - ret = (0x10 << 8); - } else { - ret = (0x10 << 8) | (1 << 13); + ret = 0x0000c000; + if (!virge->s3d_busy && !virge->fifo_slot) { + ret |= 0x00002000; if (!virge->s3d_busy) virge->subsys_stat |= INT_3DF_EMP; if (!virge->fifo_slot) @@ -1672,9 +1693,17 @@ s3_virge_mmio_read_l(uint32_t addr, void *p) ret |= virge->subsys_stat; if (virge->fifo_slot) virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 8; s3_virge_update_irqs(virge); break; + case 0x850c: + ret = virge->advfunc_cntl & 0x3f; + if (virge->fifo_slot) + virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 6; + break; + case 0x8590: ret = virge->cmd_dma_base; break; @@ -1745,9 +1774,9 @@ s3_virge_mmio_read_l(uint32_t addr, void *p) } static void -s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p) +s3_virge_mmio_write(uint32_t addr, uint8_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; s3_virge_log("MMIO WriteB addr = %04x, val = %02x\n", addr & 0xffff, val); if (((addr & 0xffff) >= 0x8590) || ((addr & 0xffff) < 0x8000)) { if ((addr & 0xffff) == 0xff20) { @@ -1812,9 +1841,9 @@ s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p) } static void -s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p) +s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; s3_virge_log("[%04X:%08X]: MMIO WriteW addr = %04x, val = %04x\n", CS, cpu_state.pc, addr & 0xfffe, val); if (((addr & 0xfffe) >= 0x8590) || ((addr & 0xfffe) < 0x8000)) if ((addr & 0xfffe) == 0xff20) @@ -1830,9 +1859,9 @@ s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p) } static void -s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *p) +s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; s3_virge_log("[%04X:%08X]: MMIO WriteL addr = %04x, val = %04x\n", CS, cpu_state.pc, addr & 0xfffc, val); @@ -2045,10 +2074,13 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) int x_mul; int cpu_dat_shift; uint32_t *pattern_data; - uint32_t src_fg_clr, src_bg_clr; + uint32_t src_fg_clr; + uint32_t src_bg_clr; uint32_t src_addr; uint32_t dest_addr; - uint32_t source = 0, dest = 0, pattern; + uint32_t source = 0; + uint32_t dest = 0; + uint32_t pattern; uint32_t out = 0; int update; @@ -2095,9 +2127,8 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) break; } if (virge->s3d.cmd_set & CMD_SET_MP) { - int x, y; - for (y = 0; y < 4; y++) { - for (x = 0; x < 8; x++) { + for (uint8_t y = 0; y < 4; y++) { + for (uint8_t x = 0; x < 8; x++) { if (virge->s3d.mono_pat_0 & (1 << (x + y * 8))) mono_pattern[y * 8 + (7 - x)] = virge->s3d.pat_fg_clr; else @@ -2311,7 +2342,9 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) do { uint32_t dest_addr = virge->s3d.dest_base + (x * x_mul) + (virge->s3d.dest_y * virge->s3d.dest_str); - uint32_t source = 0, dest = 0, pattern; + uint32_t source = 0; + uint32_t dest = 0; + uint32_t pattern; uint32_t out = 0; int update = 1; @@ -2361,7 +2394,9 @@ skip_line: int xdir = (x < xend) ? 1 : -1; do { uint32_t dest_addr = virge->s3d.dest_base + (x * x_mul) + (y * virge->s3d.dest_str); - uint32_t source = 0, dest = 0, pattern; + uint32_t source = 0; + uint32_t dest = 0; + uint32_t pattern; uint32_t out = 0; int update = 1; @@ -2452,7 +2487,8 @@ static void (*dest_pixel)(s3d_state_t *state); #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) -static int _x, _y; +static int _x; +static int _y; static void tex_ARGB1555(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) @@ -2553,7 +2589,8 @@ tex_sample_normal_filter(s3d_state_t *state) s3d_texture_state_t texture_state; int tex_offset; rgba_t tex_samples[4]; - int du, dv; + int du; + int dv; int d[4]; texture_state.level = state->max_d; @@ -2610,7 +2647,8 @@ tex_sample_mipmap_filter(s3d_state_t *state) s3d_texture_state_t texture_state; int tex_offset; rgba_t tex_samples[4]; - int du, dv; + int du; + int dv; int d[4]; texture_state.level = (state->d < 0) ? state->max_d : state->max_d - ((state->d >> 27) & 0xf); @@ -2669,10 +2707,13 @@ static void tex_sample_persp_normal_filter(s3d_state_t *state) { s3d_texture_state_t texture_state; - int32_t w = 0, u, v; + int32_t w = 0; + int32_t u; + int32_t v; int tex_offset; rgba_t tex_samples[4]; - int du, dv; + int du; + int dv; int d[4]; if (state->w) @@ -2735,10 +2776,13 @@ static void tex_sample_persp_normal_filter_375(s3d_state_t *state) { s3d_texture_state_t texture_state; - int32_t w = 0, u, v; + int32_t w = 0; + int32_t u; + int32_t v; int tex_offset; rgba_t tex_samples[4]; - int du, dv; + int du; + int dv; int d[4]; if (state->w) @@ -2803,10 +2847,13 @@ static void tex_sample_persp_mipmap_filter(s3d_state_t *state) { s3d_texture_state_t texture_state; - int32_t w = 0, u, v; + int32_t w = 0; + int32_t u; + int32_t v; int tex_offset; rgba_t tex_samples[4]; - int du, dv; + int du; + int dv; int d[4]; if (state->w) @@ -2873,10 +2920,13 @@ static void tex_sample_persp_mipmap_filter_375(s3d_state_t *state) { s3d_texture_state_t texture_state; - int32_t w = 0, u, v; + int32_t w = 0; + int32_t u; + int32_t v; int tex_offset; rgba_t tex_samples[4]; - int du, dv; + int du; + int dv; int d[4]; if (state->w) @@ -3031,10 +3081,13 @@ tri(virge_t *virge, s3d_t *s3d_tri, s3d_state_t *state, int yc, int32_t dx1, int int bpp = (s3d_tri->cmd_set >> 2) & 7; - uint32_t dest_offset = 0, z_offset = 0; + uint32_t dest_offset = 0; + uint32_t z_offset = 0; uint32_t src_col; - int src_r = 0, src_g = 0, src_b = 0; + int src_r = 0; + int src_g = 0; + int src_b = 0; int x; int xe; @@ -3324,7 +3377,6 @@ s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) s3d_state_t state; uint32_t tex_base; - int c; uint64_t start_time = plat_timer_read(); uint64_t end_time; @@ -3349,7 +3401,7 @@ s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) state.base_w = s3d_tri->tws; tex_base = s3d_tri->tex_base; - for (c = 9; c >= 0; c--) { + for (int c = 9; c >= 0; c--) { state.texture[c] = (uint16_t *) &virge->svga.vram[tex_base]; if (c <= state.max_d) tex_base += ((1 << (c * 2)) * tex_size[(s3d_tri->cmd_set >> 5) & 7]) / 2; @@ -3463,47 +3515,65 @@ s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) static void s3_virge_hwcursor_draw(svga_t *svga, int displine) { - virge_t *virge = (virge_t *) svga->p; - int x; + virge_t *virge = (virge_t *) svga->priv; uint16_t dat[2]; int xx; int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; - uint32_t fg, bg; + uint32_t fg; + uint32_t bg; uint32_t vram_mask = virge->vram_mask; if (svga->interlace && svga->hwcursor_oddeven) svga->hwcursor_latch.addr += 16; switch (svga->bpp) { + default: + if (virge->chip != S3_VIRGEGX2) { + fg = svga->pallook[virge->hwc_fg_col & 0xff]; + bg = svga->pallook[virge->hwc_bg_col & 0xff]; + break; + } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case 15: - fg = video_15to32[virge->hwc_fg_col & 0xffff]; - bg = video_15to32[virge->hwc_bg_col & 0xffff]; - break; + if (virge->chip != S3_VIRGEGX2) { + fg = video_15to32[virge->hwc_fg_col & 0xffff]; + bg = video_15to32[virge->hwc_bg_col & 0xffff]; + break; + } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 16: - fg = video_16to32[virge->hwc_fg_col & 0xffff]; - bg = video_16to32[virge->hwc_bg_col & 0xffff]; - break; + if (virge->chip != S3_VIRGEGX2) { + fg = video_16to32[virge->hwc_fg_col & 0xffff]; + bg = video_16to32[virge->hwc_bg_col & 0xffff]; + break; + } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 24: case 32: fg = virge->hwc_fg_col; bg = virge->hwc_bg_col; break; - - default: - fg = svga->pallook[virge->hwc_fg_col & 0xff]; - bg = svga->pallook[virge->hwc_bg_col & 0xff]; - break; } - for (x = 0; x < 64; x += 16) { + for (uint8_t x = 0; x < 64; x += 16) { dat[0] = (svga->vram[svga->hwcursor_latch.addr & vram_mask] << 8) | svga->vram[(svga->hwcursor_latch.addr + 1) & vram_mask]; dat[1] = (svga->vram[(svga->hwcursor_latch.addr + 2) & vram_mask] << 8) | svga->vram[(svga->hwcursor_latch.addr + 3) & vram_mask]; if (svga->crtc[0x55] & 0x10) { /*X11*/ for (xx = 0; xx < 16; xx++) { if (offset >= 0) { + if (virge->chip == S3_VIRGEGX2) + dat[0] ^= 0x8000; + if (dat[0] & 0x8000) buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; } @@ -3748,12 +3818,15 @@ s3_virge_hwcursor_draw(svga_t *svga, int displine) static void s3_virge_overlay_draw(svga_t *svga, int displine) { - virge_t *virge = (virge_t *) svga->p; + virge_t *virge = (virge_t *) svga->priv; int offset = (virge->streams.sec_x - virge->streams.pri_x) + 1; int h_acc = virge->streams.dda_horiz_accumulator; - int r[8], g[8], b[8]; - int x_size, x_read = 4, x_write = 4; - int x; + int r[8]; + int g[8]; + int b[8]; + int x_size; + int x_read = 4; + int x_write = 4; uint32_t *p; uint8_t *src = &svga->vram[svga->overlay_latch.addr]; @@ -3766,7 +3839,7 @@ s3_virge_overlay_draw(svga_t *svga, int displine) OVERLAY_SAMPLE(); - for (x = 0; x < x_size; x++) { + for (int x = 0; x < x_size; x++) { *p++ = r[x_read] | (g[x_read] << 8) | (b[x_read] << 16); h_acc += virge->streams.k1_horiz_scale; @@ -3787,9 +3860,9 @@ s3_virge_overlay_draw(svga_t *svga, int displine) } static uint8_t -s3_virge_pci_read(int func, int addr, void *p) +s3_virge_pci_read(UNUSED(int func), int addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; uint8_t ret = 0; @@ -3949,9 +4022,9 @@ s3_virge_pci_read(int func, int addr, void *p) } static void -s3_virge_pci_write(int func, int addr, uint8_t val, void *p) +s3_virge_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; switch (addr) { case 0x00: @@ -4039,8 +4112,8 @@ s3_virge_reset(void *priv) memset(svga->crtc, 0x00, sizeof(svga->crtc)); svga->crtc[0] = 63; svga->crtc[6] = 255; - svga->dispontime = 1000ull << 32; - svga->dispofftime = 1000ull << 32; + svga->dispontime = 1000ULL << 32; + svga->dispofftime = 1000ULL << 32; svga->bpp = 8; io_removehandler(0x03c0, 0x0020, s3_virge_in, NULL, NULL, s3_virge_out, NULL, NULL, virge); @@ -4060,24 +4133,29 @@ s3_virge_reset(void *priv) switch (virge->local) { case S3_VIRGE_325: case S3_DIAMOND_STEALTH3D_2000: + virge->fifo_slots_num = 8; virge->svga.crtc[0x59] = 0x70; break; case S3_DIAMOND_STEALTH3D_3000: case S3_STB_VELOCITY_3D: + virge->fifo_slots_num = 8; virge->svga.crtc[0x59] = 0x70; break; case S3_VIRGE_GX2: case S3_DIAMOND_STEALTH3D_4000: + virge->fifo_slots_num = 16; virge->svga.crtc[0x6c] = 1; virge->svga.crtc[0x59] = 0x70; break; case S3_TRIO_3D2X: + virge->fifo_slots_num = 16; virge->svga.crtc[0x6c] = 1; virge->svga.crtc[0x59] = 0x70; break; default: + virge->fifo_slots_num = 8; virge->svga.crtc[0x6c] = 1; virge->svga.crtc[0x59] = 0x70; break; @@ -4236,6 +4314,7 @@ s3_virge_init(const device_t *info) switch (info->local) { case S3_VIRGE_325: case S3_DIAMOND_STEALTH3D_2000: + virge->fifo_slots_num = 8; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x56; virge->virge_id_low = 0x31; @@ -4245,6 +4324,7 @@ s3_virge_init(const device_t *info) break; case S3_DIAMOND_STEALTH3D_3000: case S3_STB_VELOCITY_3D: + virge->fifo_slots_num = 8; virge->svga.decode_mask = (8 << 20) - 1; virge->virge_id_high = 0x88; virge->virge_id_low = 0x3d; @@ -4254,6 +4334,7 @@ s3_virge_init(const device_t *info) break; case S3_VIRGE_GX2: case S3_DIAMOND_STEALTH3D_4000: + virge->fifo_slots_num = 16; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x10; @@ -4265,6 +4346,7 @@ s3_virge_init(const device_t *info) break; case S3_TRIO_3D2X: + virge->fifo_slots_num = 16; virge->svga.decode_mask = (8 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x13; @@ -4278,8 +4360,12 @@ s3_virge_init(const device_t *info) case S3_VIRGE_GX: virge->virge_rev = 0x01; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + default: + virge->fifo_slots_num = 8; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x01; @@ -4356,9 +4442,9 @@ s3_virge_init(const device_t *info) } static void -s3_virge_close(void *p) +s3_virge_close(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; virge->render_thread_run = 0; thread_set_event(virge->wake_render_thread); @@ -4436,17 +4522,17 @@ s3_trio3d2x_available(void) } static void -s3_virge_speed_changed(void *p) +s3_virge_speed_changed(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_recalctimings(&virge->svga); } static void -s3_virge_force_redraw(void *p) +s3_virge_force_redraw(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; virge->svga.fullchange = changeframecount; } diff --git a/src/video/vid_sc1148x_ramdac.c b/src/video/vid_sc1148x_ramdac.c index 873f66e92..ee75d192d 100644 --- a/src/video/vid_sc1148x_ramdac.c +++ b/src/video/vid_sc1148x_ramdac.c @@ -93,7 +93,8 @@ uint8_t sc1148x_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga) { sc1148x_ramdac_t *ramdac = (sc1148x_ramdac_t *) p; - uint8_t ret = 0xff, rs = (addr & 0x03) | ((!!rs2) << 2); + uint8_t ret = 0xff; + uint8_t rs = (addr & 0x03) | ((!!rs2) << 2); switch (rs) { case 2: diff --git a/src/video/vid_sdac_ramdac.c b/src/video/vid_sdac_ramdac.c index 45fe714ec..d68af2bfa 100644 --- a/src/video/vid_sdac_ramdac.c +++ b/src/video/vid_sdac_ramdac.c @@ -243,11 +243,13 @@ sdac_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga) } float -sdac_getclock(int clock, void *p) +sdac_getclock(int clock, void *priv) { - sdac_ramdac_t *ramdac = (sdac_ramdac_t *) p; + sdac_ramdac_t *ramdac = (sdac_ramdac_t *) priv; float t; - int m, n1, n2; + int m; + int n1; + int n2; if (ramdac->regs[0xe] & (1 << 5)) clock = ramdac->regs[0xe] & 7; diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index 0e1833b1e..97383bc65 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -192,9 +192,9 @@ static video_timings_t timing_sigma = { .type = VIDEO_ISA, .write_b = 8, .write_ static void sigma_recalctimings(sigma_t *cga); static void -sigma_out(uint16_t addr, uint8_t val, void *p) +sigma_out(uint16_t addr, uint8_t val, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; uint8_t old; if (addr >= 0x3D0 && addr < 0x3E0) { @@ -246,7 +246,7 @@ sigma_out(uint16_t addr, uint8_t val, void *p) return; case 0x2DD: /* Page in RAM at 0xC1800 */ if (sigma->rom_paged != 0) - mmu_invalidate(0xC0000); + flushmmucache_nopc(); sigma->rom_paged = 0x00; return; @@ -260,10 +260,10 @@ sigma_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -sigma_in(uint16_t addr, void *p) +sigma_in(uint16_t addr, void *priv) { uint8_t result = 0xFF; - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; switch (addr) { case 0x2D0: @@ -290,7 +290,7 @@ sigma_in(uint16_t addr, void *p) case 0x2DD: /* Page in ROM at 0xC1800 */ result = (sigma->rom_paged ? 0x80 : 0); if (sigma->rom_paged != 0x80) - mmu_invalidate(0xC0000); + flushmmucache_nopc(); sigma->rom_paged = 0x80; break; case 0x3D1: @@ -332,27 +332,27 @@ sigma_in(uint16_t addr, void *p) } static void -sigma_write(uint32_t addr, uint8_t val, void *p) +sigma_write(uint32_t addr, uint8_t val, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; sigma->vram[sigma->plane * 0x8000 + (addr & 0x7fff)] = val; cycles -= 4; } static uint8_t -sigma_read(uint32_t addr, void *p) +sigma_read(uint32_t addr, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; cycles -= 4; return sigma->vram[sigma->plane * 0x8000 + (addr & 0x7fff)]; } static void -sigma_bwrite(uint32_t addr, uint8_t val, void *p) +sigma_bwrite(uint32_t addr, uint8_t val, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; addr &= 0x3FFF; if ((addr < 0x1800) || sigma->rom_paged || (addr >= 0x2000)) @@ -362,9 +362,9 @@ sigma_bwrite(uint32_t addr, uint8_t val, void *p) } static uint8_t -sigma_bread(uint32_t addr, void *p) +sigma_bread(uint32_t addr, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; uint8_t result; addr &= 0x3FFF; @@ -382,7 +382,8 @@ static void sigma_recalctimings(sigma_t *sigma) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; if (sigma->sigmamode & MODE_80COLS) { disptime = (sigma->crtc[0] + 1) << 1; @@ -403,8 +404,8 @@ sigma_recalctimings(sigma_t *sigma) static void sigma_text80(sigma_t *sigma) { - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t ca = (sigma->crtc[15] | (sigma->crtc[14] << 8)); uint16_t ma = ((sigma->ma & 0x3FFF) << 1); int drawcursor; @@ -418,7 +419,7 @@ sigma_text80(sigma_t *sigma) /* The Sigma 400 seems to use screen widths stated in words (40 for 80-column, 20 for 40-column) */ - for (x = 0; x < (sigma->crtc[1] << 1); x++) { + for (uint32_t x = 0; x < (sigma->crtc[1] << 1); x++) { chr = vram[x << 1]; attr = vram[(x << 1) + 1]; drawcursor = ((ma == ca) && sigma->con && sigma->cursoron); @@ -434,14 +435,14 @@ sigma_text80(sigma_t *sigma) } if (drawcursor) { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { if (sigma->sigmamode & MODE_FONT16) buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdatm[chr][sigma->sc & 15] & (1 << (c ^ 7))) ? 1 : 0] ^ 0xf; else buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdat[chr][sigma->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 0xf; } } else { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { if (sigma->sigmamode & MODE_FONT16) buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdatm[chr][sigma->sc & 15] & (1 << (c ^ 7))) ? 1 : 0]; else @@ -458,8 +459,8 @@ sigma_text80(sigma_t *sigma) static void sigma_text40(sigma_t *sigma) { - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t ca = (sigma->crtc[15] | (sigma->crtc[14] << 8)); uint16_t ma = ((sigma->ma & 0x3FFF) << 1); int drawcursor; @@ -473,7 +474,7 @@ sigma_text40(sigma_t *sigma) /* The Sigma 400 seems to use screen widths stated in words (40 for 80-column, 20 for 40-column) */ - for (x = 0; x < (sigma->crtc[1] << 1); x++) { + for (uint32_t x = 0; x < (sigma->crtc[1] << 1); x++) { chr = vram[x << 1]; attr = vram[(x << 1) + 1]; drawcursor = ((ma == ca) && sigma->con && sigma->cursoron); @@ -489,11 +490,11 @@ sigma_text40(sigma_t *sigma) } if (drawcursor) { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[sigma->displine][(x << 4) + 2 * c + 8] = buffer32->line[sigma->displine][(x << 4) + 2 * c + 9] = cols[(fontdatm[chr][sigma->sc & 15] & (1 << (c ^ 7))) ? 1 : 0] ^ 0xf; } } else { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[sigma->displine][(x << 4) + 2 * c + 8] = buffer32->line[sigma->displine][(x << 4) + 2 * c + 9] = cols[(fontdatm[chr][sigma->sc & 15] & (1 << (c ^ 7))) ? 1 : 0]; } } @@ -507,18 +508,17 @@ sigma_text40(sigma_t *sigma) static void sigma_gfx400(sigma_t *sigma) { - int x; unsigned char *vram = &sigma->vram[((sigma->ma << 1) & 0x1FFF) + (sigma->sc & 3) * 0x2000]; uint8_t plane[4]; - uint8_t mask, col, c; + uint8_t col; - for (x = 0; x < (sigma->crtc[1] << 1); x++) { + for (uint32_t x = 0; x < (sigma->crtc[1] << 1); x++) { plane[0] = vram[x]; plane[1] = vram[0x8000 + x]; plane[2] = vram[0x10000 + x]; plane[3] = vram[0x18000 + x]; - for (c = 0, mask = 0x80; c < 8; c++, mask >>= 1) { + for (uint8_t c = 0, mask = 0x80; c < 8; c++, mask >>= 1) { col = ((plane[3] & mask) ? 8 : 0) | ((plane[2] & mask) ? 4 : 0) | ((plane[1] & mask) ? 2 : 0) | ((plane[0] & mask) ? 1 : 0); col |= 16; buffer32->line[sigma->displine][(x << 3) + c + 8] = col; @@ -536,18 +536,17 @@ sigma_gfx400(sigma_t *sigma) static void sigma_gfx200(sigma_t *sigma) { - int x; unsigned char *vram = &sigma->vram[((sigma->ma << 1) & 0x1FFF) + (sigma->sc & 2) * 0x1000]; uint8_t plane[4]; - uint8_t mask, col, c; + uint8_t col; - for (x = 0; x < (sigma->crtc[1] << 1); x++) { + for (uint32_t x = 0; x < (sigma->crtc[1] << 1); x++) { plane[0] = vram[x]; plane[1] = vram[0x8000 + x]; plane[2] = vram[0x10000 + x]; plane[3] = vram[0x18000 + x]; - for (c = 0, mask = 0x80; c < 8; c++, mask >>= 1) { + for (uint8_t c = 0, mask = 0x80; c < 8; c++, mask >>= 1) { col = ((plane[3] & mask) ? 8 : 0) | ((plane[2] & mask) ? 4 : 0) | ((plane[1] & mask) ? 2 : 0) | ((plane[0] & mask) ? 1 : 0); col |= 16; buffer32->line[sigma->displine][(x << 3) + c + 8] = col; @@ -562,19 +561,19 @@ sigma_gfx200(sigma_t *sigma) static void sigma_gfx4col(sigma_t *sigma) { - int x; unsigned char *vram = &sigma->vram[((sigma->ma << 1) & 0x1FFF) + (sigma->sc & 2) * 0x1000]; uint8_t plane[4]; - uint8_t mask, col, c; + uint8_t mask; + uint8_t col; - for (x = 0; x < (sigma->crtc[1] << 1); x++) { + for (uint32_t x = 0; x < (sigma->crtc[1] << 1); x++) { plane[0] = vram[x]; plane[1] = vram[0x8000 + x]; plane[2] = vram[0x10000 + x]; plane[3] = vram[0x18000 + x]; mask = 0x80; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { col = ((plane[3] & mask) ? 2 : 0) | ((plane[2] & mask) ? 1 : 0); mask = mask >> 1; col |= ((plane[3] & mask) ? 8 : 0) | ((plane[2] & mask) ? 4 : 0); @@ -590,10 +589,11 @@ sigma_gfx4col(sigma_t *sigma) } static void -sigma_poll(void *p) +sigma_poll(void *priv) { - sigma_t *sigma = (sigma_t *) p; - int x, c; + sigma_t *sigma = (sigma_t *) priv; + int x; + int c; int oldvc; uint32_t cols[4]; int oldsc; @@ -767,7 +767,7 @@ sigma_poll(void *p) } if (sigma->cgadispon) sigma->sigmastat &= ~STATUS_RETR_H; - if ((sigma->sc == (sigma->crtc[10] & 31) || ((sigma->crtc[8] & 3) == 3 && sigma->sc == ((sigma->crtc[10] & 31) >> 1)))) + if (sigma->sc == (sigma->crtc[10] & 31) || ((sigma->crtc[8] & 3) == 3 && sigma->sc == ((sigma->crtc[10] & 31) >> 1))) sigma->con = 1; } } @@ -829,22 +829,22 @@ static void static int sigma_available(void) { - return ((rom_present(ROM_SIGMA_FONT) && rom_present(ROM_SIGMA_BIOS))); + return (rom_present(ROM_SIGMA_FONT) && rom_present(ROM_SIGMA_BIOS)); } static void -sigma_close(void *p) +sigma_close(void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; free(sigma->vram); free(sigma); } void -sigma_speed_changed(void *p) +sigma_speed_changed(void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; sigma_recalctimings(sigma); } diff --git a/src/video/vid_stg_ramdac.c b/src/video/vid_stg_ramdac.c index 78a477acb..64dd27def 100644 --- a/src/video/vid_stg_ramdac.c +++ b/src/video/vid_stg_ramdac.c @@ -90,7 +90,8 @@ void stg_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga) { stg_ramdac_t *ramdac = (stg_ramdac_t *) p; - int didwrite, old; + int didwrite; + int old; switch (addr) { case 0x3c6: @@ -198,11 +199,13 @@ stg_ramdac_in(uint16_t addr, void *p, svga_t *svga) } float -stg_getclock(int clock, void *p) +stg_getclock(int clock, void *priv) { - stg_ramdac_t *ramdac = (stg_ramdac_t *) p; + stg_ramdac_t *ramdac = (stg_ramdac_t *) priv; float t; - int m, n, n2; + int m; + int n; + int n2; uint16_t *c; if (clock == 0) diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index 6f8cc0448..0e83c034a 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -41,6 +41,7 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/vid_xga_device.h> void svga_doblit(int wx, int wy, svga_t *svga); @@ -54,7 +55,8 @@ uint8_t svga_rotate[8][256]; /*Primary SVGA device. As multiple video cards are not yet supported this is the only SVGA device.*/ static svga_t *svga_pri; -int vga_on, ibm8514_on; +int vga_on; +int ibm8514_on; #ifdef ENABLE_SVGA_LOG int svga_do_log = ENABLE_SVGA_LOG; @@ -106,11 +108,11 @@ svga_set_override(svga_t *svga, int val) } void -svga_out(uint16_t addr, uint8_t val, void *p) +svga_out(uint16_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; - int c; - uint8_t o, index; + svga_t *svga = (svga_t *) priv; + uint8_t o; + uint8_t index; switch (addr) { case 0x3c0: @@ -130,7 +132,7 @@ svga_out(uint16_t addr, uint8_t val, void *p) if (svga->attraddr < 16) svga->fullchange = svga->monitor->mon_changeframecount; if (svga->attraddr == 0x10 || svga->attraddr == 0x14 || svga->attraddr < 0x10) { - for (c = 0; c < 16; c++) { + for (int c = 0; c < 16; c++) { if (svga->attrregs[0x10] & 0x80) { svga->egapal[c] = (svga->attrregs[c] & 0xf) | ((svga->attrregs[0x14] & 0xf) << 4); } else { @@ -159,11 +161,17 @@ svga_out(uint16_t addr, uint8_t val, void *p) case 0x3c2: svga->miscout = val; svga->vidclock = val & 4; - io_removehandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->p); + io_removehandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); if (!(val & 1)) - io_sethandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->p); + io_sethandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); svga_recalctimings(svga); break; + case 0x3c3: + if (xga_enabled) { + svga->xga.on = (val & 0x01) ? 0 : 1; + vga_on = !svga->xga.on; + } + break; case 0x3c4: svga->seqaddr = val; break; @@ -197,17 +205,24 @@ svga_out(uint16_t addr, uint8_t val, void *p) svga->chain4 = val & 8; svga->fast = (svga->gdcreg[8] == 0xff && !(svga->gdcreg[3] & 0x18) && !svga->gdcreg[1]) && ((svga->chain4 && (svga->packed_chain4 || svga->force_old_addr)) || svga->fb_only) && !(svga->adv_flags & FLAG_ADDR_BY8); break; + + default: + break; } break; + case 0x2ea: case 0x3c6: svga->dac_mask = val; break; + case 0x2eb: + case 0x2ec: case 0x3c7: case 0x3c8: svga->dac_pos = 0; svga->dac_status = addr & 0x03; svga->dac_addr = (val + (addr & 0x01)) & 255; break; + case 0x2ed: case 0x3c9: if (svga->adv_flags & FLAG_RAMDAC_SHIFT) val <<= 2; @@ -233,6 +248,9 @@ svga_out(uint16_t addr, uint8_t val, void *p) svga->dac_pos = 0; svga->dac_addr = (svga->dac_addr + 1) & 255; break; + + default: + break; } break; case 0x3ce: @@ -271,26 +289,36 @@ svga_out(uint16_t addr, uint8_t val, void *p) mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); svga->banked_mask = 0x7fff; break; + + default: + break; } } break; case 7: svga->colournocare = val; break; + + default: + break; } svga->gdcreg[svga->gdcaddr & 15] = val; svga->fast = (svga->gdcreg[8] == 0xff && !(svga->gdcreg[3] & 0x18) && !svga->gdcreg[1]) && ((svga->chain4 && (svga->packed_chain4 || svga->force_old_addr)) || svga->fb_only); if (((svga->gdcaddr & 15) == 5 && (val ^ o) & 0x70) || ((svga->gdcaddr & 15) == 6 && (val ^ o) & 1)) svga_recalctimings(svga); break; + + default: + break; } } uint8_t -svga_in(uint16_t addr, void *p) +svga_in(uint16_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - uint8_t index, ret = 0xff; + svga_t *svga = (svga_t *) priv; + uint8_t index; + uint8_t ret = 0xff; switch (addr) { case 0x3c0: @@ -311,15 +339,19 @@ svga_in(uint16_t addr, void *p) case 0x3c5: ret = svga->seqregs[svga->seqaddr & 0x0f]; break; + case 0x2ea: case 0x3c6: ret = svga->dac_mask; break; + case 0x2eb: case 0x3c7: ret = svga->dac_status; break; + case 0x2ec: case 0x3c8: ret = svga->dac_addr; break; + case 0x2ed: case 0x3c9: index = (svga->dac_addr - 1) & 255; switch (svga->dac_pos) { @@ -345,6 +377,9 @@ svga_in(uint16_t addr, void *p) else ret = svga->vgapal[index].b & 0x3f; break; + + default: + break; } if (svga->adv_flags & FLAG_RAMDAC_SHIFT) ret >>= 2; @@ -386,20 +421,21 @@ svga_in(uint16_t addr, void *p) ret = svga->cgastat; break; + + default: + break; } - return (ret); + return ret; } void svga_set_ramdac_type(svga_t *svga, int type) { - int c; - if (svga->ramdac_type != type) { svga->ramdac_type = type; - for (c = 0; c < 256; c++) { + for (int c = 0; c < 256; c++) { if (svga->ramdac_type == RAMDAC_8BIT) svga->pallook[c] = makecol32(svga->vgapal[c].r, svga->vgapal[c].g, svga->vgapal[c].b); else @@ -413,7 +449,10 @@ svga_set_ramdac_type(svga_t *svga, int type) void svga_recalctimings(svga_t *svga) { - double crtcconst, _dispontime, _dispofftime, disptime; + double crtcconst; + double _dispontime; + double _dispofftime; + double disptime; svga->vtotal = svga->crtc[6]; svga->dispend = svga->crtc[0x12]; @@ -543,8 +582,14 @@ svga_recalctimings(svga_t *svga) else svga->render = svga_render_32bpp_highres; break; + + default: + break; } break; + + default: + break; } } } @@ -572,12 +617,21 @@ svga_recalctimings(svga_t *svga) svga->recalctimings_ex(svga); } } else { - if (ibm8514_on && ibm8514_enabled) - ibm8514_recalctimings(svga); + if (ibm8514_enabled) { + if (svga->dev8514.local) { + if (svga->recalctimings_ex) { + svga->recalctimings_ex(svga); + } + } else + ibm8514_recalctimings(svga); + } if (xga_enabled) xga_recalctimings(svga); } + if (svga->hdisp >= 2048) + svga->monitor->mon_overscan_x = 0; + svga->y_add = (svga->monitor->mon_overscan_y >> 1) - (svga->crtc[8] & 0x1f); svga->x_add = (svga->monitor->mon_overscan_x >> 1); @@ -586,8 +640,13 @@ svga_recalctimings(svga_t *svga) crtcconst = svga->clock * svga->char_width; - disptime = svga->htotal; - _dispontime = svga->hdisp_time; + if (ibm8514_on && !svga->dev8514.local) { + disptime = svga->dev8514.h_total; + _dispontime = svga->dev8514.h_disp; + } else { + disptime = svga->htotal; + _dispontime = svga->hdisp_time; + } if (svga->seqregs[1] & 8) { disptime *= 2; @@ -664,16 +723,23 @@ svga_do_render(svga_t *svga) } void -svga_poll(void *p) +svga_poll(void *priv) { - svga_t *svga = (svga_t *) p; - uint32_t x, blink_delay; - int wx, wy; - int ret, old_ma; + svga_t *svga = (svga_t *) priv; + ibm8514_t *dev = &svga->dev8514; + uint32_t x; + uint32_t blink_delay; + int wx; + int wy; + int ret; + int old_ma; + int linecountff = 0; if (!vga_on && ibm8514_enabled && ibm8514_on) { - ibm8514_poll(&svga->dev8514, svga); - return; + if (!dev->local) { + ibm8514_poll(dev, svga); + return; + } } else if (!vga_on && xga_enabled && svga->xga.on) { xga_poll(&svga->xga, svga); return; @@ -681,22 +747,22 @@ svga_poll(void *p) if (!svga->linepos) { if (svga->displine == svga->hwcursor_latch.y && svga->hwcursor_latch.ena) { - svga->hwcursor_on = svga->hwcursor.cur_ysize - svga->hwcursor_latch.yoff; + svga->hwcursor_on = svga->hwcursor_latch.cur_ysize - svga->hwcursor_latch.yoff; svga->hwcursor_oddeven = 0; } if (svga->displine == (svga->hwcursor_latch.y + 1) && svga->hwcursor_latch.ena && svga->interlace) { - svga->hwcursor_on = svga->hwcursor.cur_ysize - (svga->hwcursor_latch.yoff + 1); + svga->hwcursor_on = svga->hwcursor_latch.cur_ysize - (svga->hwcursor_latch.yoff + 1); svga->hwcursor_oddeven = 1; } if (svga->displine == svga->dac_hwcursor_latch.y && svga->dac_hwcursor_latch.ena) { - svga->dac_hwcursor_on = svga->dac_hwcursor.cur_ysize - svga->dac_hwcursor_latch.yoff; + svga->dac_hwcursor_on = svga->dac_hwcursor_latch.cur_ysize - svga->dac_hwcursor_latch.yoff; svga->dac_hwcursor_oddeven = 0; } if (svga->displine == (svga->dac_hwcursor_latch.y + 1) && svga->dac_hwcursor_latch.ena && svga->interlace) { - svga->dac_hwcursor_on = svga->dac_hwcursor.cur_ysize - (svga->dac_hwcursor_latch.yoff + 1); + svga->dac_hwcursor_on = svga->dac_hwcursor_latch.cur_ysize - (svga->dac_hwcursor_latch.yoff + 1); svga->dac_hwcursor_oddeven = 1; } @@ -756,7 +822,7 @@ svga_poll(void *p) if ((svga->cgastat & 8) && ((svga->displine & 15) == (svga->crtc[0x11] & 15)) && svga->vslines) svga->cgastat &= ~8; svga->vslines++; - if (svga->displine > 1500) + if (svga->displine > 2000) svga->displine = 0; } else { timer_advance_u64(&svga->timer, svga->dispontime); @@ -769,7 +835,13 @@ svga_poll(void *p) if ((svga->sc == (svga->crtc[11] & 31)) || (svga->sc == svga->rowcount)) svga->con = 0; if (svga->dispon) { - if (svga->linedbl && !svga->linecountff) { + /*Real IBM 8514/A or compatibility mode doesn't have linedbl, so skip those.*/ + if (dev->local && ibm8514_on) { + svga->linedbl = 0; + svga->linecountff = 0; + linecountff = 1; + } + if (svga->linedbl && !svga->linecountff && !linecountff) { svga->linecountff = 1; svga->ma = svga->maback; } else if (svga->sc == svga->rowcount) { @@ -779,23 +851,24 @@ svga_poll(void *p) svga->maback += (svga->rowoffset << 3); if (svga->interlace) svga->maback += (svga->rowoffset << 3); + svga->maback &= svga->vram_display_mask; svga->ma = svga->maback; } else { svga->linecountff = 0; svga->sc++; - svga->sc &= 31; + svga->sc &= 0x1f; svga->ma = svga->maback; } } - svga->hsync_divisor = !svga->hsync_divisor; + svga->hsync_divisor ^= 1; if (svga->hsync_divisor && (svga->crtc[0x17] & 4)) return; svga->vc++; - svga->vc &= 2047; + svga->vc &= 0x7ff; if (svga->vc == svga->split) { ret = 1; @@ -821,6 +894,7 @@ svga_poll(void *p) if (svga->vc == svga->dispend) { if (svga->vblank_start) svga->vblank_start(svga); + svga->dispon = 0; blink_delay = (svga->crtc[11] & 0x60) >> 5; if (svga->crtc[10] & 0x20) @@ -832,6 +906,7 @@ svga_poll(void *p) if (!(svga->gdcreg[6] & 1) && !(svga->blink & 15)) svga->fullchange = 2; + svga->blink = (svga->blink + 1) & 0x7f; for (x = 0; x < ((svga->vram_mask + 1) >> 12); x++) { @@ -874,12 +949,18 @@ svga_poll(void *p) svga->monitor->mon_changeframecount = svga->interlace ? 3 : 2; svga->vslines = 0; - if (svga->interlace && svga->oddeven) - svga->ma = svga->maback = svga->ma_latch + (svga->rowoffset << 1) + ((svga->crtc[5] & 0x60) >> 5); - else - svga->ma = svga->maback = svga->ma_latch + ((svga->crtc[5] & 0x60) >> 5); - svga->ca = ((svga->crtc[0xe] << 8) | svga->crtc[0xf]) + ((svga->crtc[0xb] & 0x60) >> 5) + svga->ca_adj; - + if ((dev->local && vga_on) || !dev->local) { + if (svga->interlace && svga->oddeven) + svga->ma = svga->maback = svga->ma_latch + (svga->rowoffset << 1) + ((svga->crtc[5] & 0x60) >> 5); + else + svga->ma = svga->maback = svga->ma_latch + ((svga->crtc[5] & 0x60) >> 5); + } else if (dev->local && ibm8514_on) { + if (svga->interlace && svga->oddeven) + svga->ma = svga->maback = svga->ma_latch + (svga->rowoffset << 1); + else + svga->ma = svga->maback = svga->ma_latch; + } + svga->ca = ((svga->crtc[0xe] << 8) | svga->crtc[0xf]) + ((svga->crtc[0xb] & 0x60) >> 5) + svga->ca_adj; svga->ma = (svga->ma << 2); svga->maback = (svga->maback << 2); svga->ca = (svga->ca << 2); @@ -893,22 +974,24 @@ svga_poll(void *p) svga->dispon = 1; svga->displine = (svga->interlace && svga->oddeven) ? 1 : 0; - svga->scrollcache = (svga->attrregs[0x13] & 0x0f); - if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) { /*Text mode*/ - if (svga->seqregs[1] & 1) + if (!ibm8514_on) { + svga->scrollcache = (svga->attrregs[0x13] & 0x0f); + if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) { /*Text mode*/ + if (svga->seqregs[1] & 1) + svga->scrollcache &= 0x07; + else { + svga->scrollcache++; + if (svga->scrollcache > 8) + svga->scrollcache = 0; + } + } else if ((svga->render == svga_render_2bpp_lowres) || (svga->render == svga_render_2bpp_highres) || (svga->render == svga_render_4bpp_lowres) || (svga->render == svga_render_4bpp_highres)) svga->scrollcache &= 0x07; - else { - svga->scrollcache++; - if (svga->scrollcache > 8) - svga->scrollcache = 0; - } - } else if ((svga->render == svga_render_2bpp_lowres) || (svga->render == svga_render_2bpp_highres) || (svga->render == svga_render_4bpp_lowres) || (svga->render == svga_render_4bpp_highres)) - svga->scrollcache &= 0x07; - else - svga->scrollcache = (svga->scrollcache & 0x06) >> 1; + else + svga->scrollcache = (svga->scrollcache & 0x06) >> 1; - if ((svga->seqregs[1] & 8) || (svga->render == svga_render_8bpp_lowres)) - svga->scrollcache <<= 1; + if ((svga->seqregs[1] & 8) || (svga->render == svga_render_8bpp_lowres)) + svga->scrollcache <<= 1; + } svga->x_add = (svga->monitor->mon_overscan_x >> 1) - svga->scrollcache; @@ -929,22 +1012,22 @@ svga_poll(void *p) } int -svga_init(const device_t *info, svga_t *svga, void *p, int memsize, +svga_init(const device_t *info, svga_t *svga, void *priv, int memsize, void (*recalctimings_ex)(struct svga_t *svga), - uint8_t (*video_in)(uint16_t addr, void *p), - void (*video_out)(uint16_t addr, uint8_t val, void *p), + uint8_t (*video_in)(uint16_t addr, void *priv), + void (*video_out)(uint16_t addr, uint8_t val, void *priv), void (*hwcursor_draw)(struct svga_t *svga, int displine), void (*overlay_draw)(struct svga_t *svga, int displine)) { - int c, d, e; + int e; - svga->p = p; + svga->priv = priv; svga->monitor_index = monitor_index_global; svga->monitor = &monitors[svga->monitor_index]; - for (c = 0; c < 256; c++) { + for (int c = 0; c < 256; c++) { e = c; - for (d = 0; d < 8; d++) { + for (int d = 0; d < 8; d++) { svga_rotate[d][c] = e; e = (e >> 1) | ((e & 1) ? 0x80 : 0); } @@ -961,8 +1044,8 @@ svga_init(const device_t *info, svga_t *svga, void *p, int memsize, svga->crtc[0] = 63; svga->crtc[6] = 255; - svga->dispontime = 1000ull << 32; - svga->dispofftime = 1000ull << 32; + svga->dispontime = 1000ULL << 32; + svga->dispofftime = 1000ULL << 32; svga->bpp = 8; svga->vram = calloc(memsize, 1); svga->vram_max = memsize; @@ -1066,14 +1149,16 @@ svga_decode_addr(svga_t *svga, uint32_t addr, int write) } static __inline void -svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) +svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; - int writemask2 = svga->writemask, reset_wm = 0; + int writemask2 = svga->writemask; + int reset_wm = 0; latch_t vall; uint8_t wm = svga->writemask; - uint8_t count, i; + uint8_t count; + uint8_t i; if (svga->adv_flags & FLAG_ADDR_BY8) writemask2 = svga->seqregs[2]; @@ -1082,7 +1167,7 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) if (!linear) { if (xga_enabled) { - if (((svga->xga.op_mode & 7) >= 4) && (svga->xga.aperture_cntl == 1)) { + if (((svga->xga.op_mode & 7) >= 4) && (svga->xga.aperture_cntl >= 1)) { if (val == 0xa5) { /*Memory size test of XGA*/ svga->xga.test = val; svga->xga.a5_test = 1; @@ -1090,14 +1175,16 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) } else if (val == 0x5a) { svga->xga.test = val; return; - } else if (val == 0x12 || val == 0x34) { + } else if ((val == 0x12) || (val == 0x34)) { addr += svga->xga.write_bank; svga->xga.vram[addr & svga->xga.vram_mask] = val; svga->xga.linear_endian_reverse = 1; return; } - } else + } else { svga->xga.on = 0; + vga_on = !svga->xga.on; + } } addr = svga_decode_addr(svga, addr, 1); @@ -1125,14 +1212,22 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) if (addr & 1) writemask2 <<= 1; addr &= ~1; - addr <<= 2; - } else - addr <<= 2; - + if (linear && ibm8514_on && (svga->adv_flags & FLAG_ATI)) { + addr &= svga->vram_mask; + } else + addr <<= 2; + } else { + if (linear && ibm8514_on && (svga->adv_flags & FLAG_ATI)) { + writemask2 = 1 << (addr & 3); + addr &= ~3; + addr &= svga->vram_mask; + } else + addr <<= 2; + } addr &= svga->decode_mask; if (svga->translate_address) - addr = svga->translate_address(addr, p); + addr = svga->translate_address(addr, priv); if (addr >= svga->vram_max) return; @@ -1260,6 +1355,9 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) } } break; + + default: + break; } if (reset_wm) @@ -1267,14 +1365,14 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) } static __inline uint8_t -svga_read_common(uint32_t addr, uint8_t linear, void *p) +svga_read_common(uint32_t addr, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; uint32_t latch_addr = 0; int readplane = svga->readplane; - uint8_t count, i; - uint8_t plane, pixel; - uint8_t temp, ret; + uint8_t count; + uint8_t temp; + uint8_t ret; if (svga->adv_flags & FLAG_ADDR_BY8) readplane = svga->gdcreg[4] & 7; @@ -1283,19 +1381,23 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) if (!linear) { if (xga_enabled) { - if (((svga->xga.op_mode & 7) >= 4) && (svga->xga.aperture_cntl == 1)) { + if (((svga->xga.op_mode & 7) >= 4) && (svga->xga.aperture_cntl >= 1)) { if (svga->xga.test == 0xa5) { /*Memory size test of XGA*/ svga->xga.on = 1; + vga_on = !svga->xga.on; return svga->xga.test; } else if (svga->xga.test == 0x5a) { svga->xga.on = 1; + vga_on = !svga->xga.on; return svga->xga.test; - } else if (addr == 0xa0000 || addr == 0xa0010) { + } else if ((addr == 0xa0000) || (addr == 0xa0010)) { addr += svga->xga.read_bank; return svga->xga.vram[addr & svga->xga.vram_mask]; } - } else + } else { svga->xga.on = 0; + vga_on = !svga->xga.on; + } } addr = svga_decode_addr(svga, addr, 0); @@ -1317,11 +1419,11 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) else if ((svga->chain4 && (svga->packed_chain4 || svga->force_old_addr)) || svga->fb_only) { addr &= svga->decode_mask; if (svga->translate_address) - addr = svga->translate_address(addr, p); + addr = svga->translate_address(addr, priv); if (addr >= svga->vram_max) return 0xff; latch_addr = (addr & svga->vram_mask) & ~3; - for (i = 0; i < count; i++) + for (uint8_t i = 0; i < count; i++) svga->latch.b[i] = svga->vram[latch_addr | i]; return svga->vram[addr & svga->vram_mask]; } else if (svga->chain4 && !svga->force_old_addr) { @@ -1330,24 +1432,37 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) } else if (svga->chain2_read) { readplane = (readplane & 2) | (addr & 1); addr &= ~1; - addr <<= 2; - } else - addr <<= 2; - + if (linear && ibm8514_on && (svga->adv_flags & FLAG_ATI)) + addr &= svga->vram_mask; + else + addr <<= 2; + } else { + if (linear && ibm8514_on && (svga->adv_flags & FLAG_ATI)) { + addr &= svga->decode_mask; + if (addr >= svga->vram_max) + return 0xff; + latch_addr = (addr & svga->vram_mask) & ~3; + for (uint8_t i = 0; i < count; i++) + svga->latch.b[i] = svga->vram[latch_addr | i]; + return svga->vram[addr & svga->vram_mask]; + } else + addr <<= 2; + } addr &= svga->decode_mask; + if (svga->translate_address) { - latch_addr = svga->translate_address(latch_addr, p); - addr = svga->translate_address(addr, p); + latch_addr = svga->translate_address(latch_addr, priv); + addr = svga->translate_address(addr, priv); } /* standard VGA latched access */ if (latch_addr >= svga->vram_max) { - for (i = 0; i < count; i++) + for (uint8_t i = 0; i < count; i++) svga->latch.b[i] = 0xff; } else { latch_addr &= svga->vram_mask; - for (i = 0; i < count; i++) + for (uint8_t i = 0; i < count; i++) svga->latch.b[i] = svga->vram[latch_addr | i]; } @@ -1359,8 +1474,8 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) if (svga->readmode) { temp = 0xff; - for (pixel = 0; pixel < 8; pixel++) { - for (plane = 0; plane < count; plane++) { + for (uint8_t pixel = 0; pixel < 8; pixel++) { + for (uint8_t plane = 0; plane < count; plane++) { if (svga->colournocare & (1 << plane)) { /* If we care about a plane, and the pixel has a mismatch on it, clear its bit. */ if (((svga->latch.b[plane] >> pixel) & 1) != ((svga->colourcompare >> plane) & 1)) @@ -1377,41 +1492,47 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) } void -svga_write(uint32_t addr, uint8_t val, void *p) +svga_write(uint32_t addr, uint8_t val, void *priv) { - svga_write_common(addr, val, 0, p); + svga_write_common(addr, val, 0, priv); } void -svga_write_linear(uint32_t addr, uint8_t val, void *p) +svga_write_linear(uint32_t addr, uint8_t val, void *priv) { - svga_write_common(addr, val, 1, p); + svga_write_common(addr, val, 1, priv); } uint8_t -svga_read(uint32_t addr, void *p) +svga_read(uint32_t addr, void *priv) { - return svga_read_common(addr, 0, p); + return svga_read_common(addr, 0, priv); } uint8_t -svga_read_linear(uint32_t addr, void *p) +svga_read_linear(uint32_t addr, void *priv) { - return svga_read_common(addr, 1, p); + return svga_read_common(addr, 1, priv); } void svga_doblit(int wx, int wy, svga_t *svga) { - int y_add, x_add, y_start, x_start, bottom; + int y_add; + int x_add; + int y_start; + int x_start; + int bottom; uint32_t *p; - int i, j; - int xs_temp, ys_temp; + int i; + int j; + int xs_temp; + int ys_temp; - y_add = (enable_overscan) ? svga->monitor->mon_overscan_y : 0; - x_add = (enable_overscan) ? svga->monitor->mon_overscan_x : 0; - y_start = (enable_overscan) ? 0 : (svga->monitor->mon_overscan_y >> 1); - x_start = (enable_overscan) ? 0 : (svga->monitor->mon_overscan_x >> 1); + y_add = enable_overscan ? svga->monitor->mon_overscan_y : 0; + x_add = enable_overscan ? svga->monitor->mon_overscan_x : 0; + y_start = enable_overscan ? 0 : (svga->monitor->mon_overscan_y >> 1); + x_start = enable_overscan ? 0 : (svga->monitor->mon_overscan_x >> 1); bottom = (svga->monitor->mon_overscan_y >> 1) + (svga->crtc[8] & 0x1f); if (svga->vertical_linedbl) { @@ -1482,12 +1603,12 @@ svga_doblit(int wx, int wy, svga_t *svga) } void -svga_writeb_linear(uint32_t addr, uint8_t val, void *p) +svga_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - svga_write_linear(addr, val, p); + svga_write_linear(addr, val, priv); return; } @@ -1495,18 +1616,18 @@ svga_writeb_linear(uint32_t addr, uint8_t val, void *p) if (addr >= svga->vram_max) return; addr &= svga->vram_mask; - svga->changedvram[addr >> 12] = svga->monitor->mon_changeframecount; - *(uint8_t *) &svga->vram[addr] = val; + svga->changedvram[addr >> 12] = svga->monitor->mon_changeframecount; + *&svga->vram[addr] = val; } void -svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) +svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - svga_write_common(addr, val, linear, p); - svga_write_common(addr + 1, val >> 8, linear, p); + svga_write_common(addr, val, linear, priv); + svga_write_common(addr + 1, val >> 8, linear, priv); return; } @@ -1521,12 +1642,12 @@ svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint32_t addr2 = svga->translate_address(addr, p); + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = val & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 8) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; @@ -1542,27 +1663,27 @@ svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) } void -svga_writew(uint32_t addr, uint16_t val, void *p) +svga_writew(uint32_t addr, uint16_t val, void *priv) { - svga_writew_common(addr, val, 0, p); + svga_writew_common(addr, val, 0, priv); } void -svga_writew_linear(uint32_t addr, uint16_t val, void *p) +svga_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_writew_common(addr, val, 1, p); + svga_writew_common(addr, val, 1, priv); } void -svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) +svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - svga_write_common(addr, val, linear, p); - svga_write_common(addr + 1, val >> 8, linear, p); - svga_write_common(addr + 2, val >> 16, linear, p); - svga_write_common(addr + 3, val >> 24, linear, p); + svga_write_common(addr, val, linear, priv); + svga_write_common(addr + 1, val >> 8, linear, priv); + svga_write_common(addr + 2, val >> 16, linear, priv); + svga_write_common(addr + 3, val >> 24, linear, priv); return; } @@ -1577,22 +1698,22 @@ svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint32_t addr2 = svga->translate_address(addr, p); + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = val & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 8) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 2, p); + addr2 = svga->translate_address(addr + 2, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 16) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 3, p); + addr2 = svga->translate_address(addr + 3, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 24) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; @@ -1608,39 +1729,39 @@ svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) } void -svga_writel(uint32_t addr, uint32_t val, void *p) +svga_writel(uint32_t addr, uint32_t val, void *priv) { - svga_writel_common(addr, val, 0, p); + svga_writel_common(addr, val, 0, priv); } void -svga_writel_linear(uint32_t addr, uint32_t val, void *p) +svga_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_writel_common(addr, val, 1, p); + svga_writel_common(addr, val, 1, priv); } uint8_t -svga_readb_linear(uint32_t addr, void *p) +svga_readb_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + const svga_t *svga = (svga_t *) priv; if (!svga->fast) - return svga_read_linear(addr, p); + return svga_read_linear(addr, priv); addr &= svga->decode_mask; if (addr >= svga->vram_max) return 0xff; - return *(uint8_t *) &svga->vram[addr & svga->vram_mask]; + return *&svga->vram[addr & svga->vram_mask]; } uint16_t -svga_readw_common(uint32_t addr, uint8_t linear, void *p) +svga_readw_common(uint32_t addr, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) - return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8); + return svga_read_common(addr, linear, priv) | (svga_read_common(addr + 1, linear, priv) << 8); cycles -= svga->monitor->mon_video_timing_read_w; @@ -1653,11 +1774,12 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint8_t val1 = 0xff, val2 = 0xff; - uint32_t addr2 = svga->translate_address(addr, p); + uint8_t val1 = 0xff; + uint8_t val2 = 0xff; + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) val1 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) val2 = svga->vram[addr2 & svga->vram_mask]; return (val2 << 8) | val1; @@ -1669,24 +1791,24 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *p) } uint16_t -svga_readw(uint32_t addr, void *p) +svga_readw(uint32_t addr, void *priv) { - return svga_readw_common(addr, 0, p); + return svga_readw_common(addr, 0, priv); } uint16_t -svga_readw_linear(uint32_t addr, void *p) +svga_readw_linear(uint32_t addr, void *priv) { - return svga_readw_common(addr, 1, p); + return svga_readw_common(addr, 1, priv); } uint32_t -svga_readl_common(uint32_t addr, uint8_t linear, void *p) +svga_readl_common(uint32_t addr, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8) | (svga_read_common(addr + 2, linear, p) << 16) | (svga_read_common(addr + 3, linear, p) << 24); + return svga_read_common(addr, linear, priv) | (svga_read_common(addr + 1, linear, priv) << 8) | (svga_read_common(addr + 2, linear, priv) << 16) | (svga_read_common(addr + 3, linear, priv) << 24); } cycles -= svga->monitor->mon_video_timing_read_l; @@ -1700,17 +1822,20 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint8_t val1 = 0xff, val2 = 0xff, val3 = 0xff, val4 = 0xff; - uint32_t addr2 = svga->translate_address(addr, p); + uint8_t val1 = 0xff; + uint8_t val2 = 0xff; + uint8_t val3 = 0xff; + uint8_t val4 = 0xff; + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) val1 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) val2 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 2, p); + addr2 = svga->translate_address(addr + 2, priv); if (addr2 < svga->vram_max) val3 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 3, p); + addr2 = svga->translate_address(addr + 3, priv); if (addr2 < svga->vram_max) val4 = svga->vram[addr2 & svga->vram_mask]; return (val4 << 24) | (val3 << 16) | (val2 << 8) | val1; @@ -1722,13 +1847,13 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *p) } uint32_t -svga_readl(uint32_t addr, void *p) +svga_readl(uint32_t addr, void *priv) { - return svga_readl_common(addr, 0, p); + return svga_readl_common(addr, 0, priv); } uint32_t -svga_readl_linear(uint32_t addr, void *p) +svga_readl_linear(uint32_t addr, void *priv) { - return svga_readl_common(addr, 1, p); + return svga_readl_common(addr, 1, priv); } diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index 81621681f..c9369f09c 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -65,6 +65,9 @@ svga_render_blank(svga_t *svga) case 9: char_width = 16; break; + + default: + break; } uint32_t *line_ptr = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -75,8 +78,6 @@ svga_render_blank(svga_t *svga) void svga_render_overscan_left(svga_t *svga) { - int i; - if ((svga->displine + svga->y_add) < 0) return; @@ -84,14 +85,14 @@ svga_render_overscan_left(svga_t *svga) return; uint32_t *line_ptr = svga->monitor->target_buffer->line[svga->displine + svga->y_add]; - for (i = 0; i < svga->x_add; i++) + for (int i = 0; i < svga->x_add; i++) *line_ptr++ = svga->overscan_color; } void svga_render_overscan_right(svga_t *svga) { - int i, right; + int right; if ((svga->displine + svga->y_add) < 0) return; @@ -101,7 +102,7 @@ svga_render_overscan_right(svga_t *svga) uint32_t *line_ptr = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add + svga->hdisp]; right = (overscan_x >> 1); - for (i = 0; i < right; i++) + for (int i = 0; i < right; i++) *line_ptr++ = svga->overscan_color; } @@ -109,11 +110,15 @@ void svga_render_text_40(svga_t *svga) { uint32_t *p; - int x, xx; - int drawcursor, xinc; - uint8_t chr, attr, dat; + int xx; + int drawcursor; + int xinc; + uint8_t chr; + uint8_t attr; + uint8_t dat; uint32_t charaddr; - int fg, bg; + int fg; + int bg; uint32_t addr = 0; if ((svga->displine + svga->y_add) < 0) @@ -127,7 +132,7 @@ svga_render_text_40(svga_t *svga) p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; xinc = (svga->seqregs[1] & 1) ? 16 : 18; - for (x = 0; x < (svga->hdisp + svga->scrollcache); x += xinc) { + for (int x = 0; x < (svga->hdisp + svga->scrollcache); x += xinc) { if (!svga->force_old_addr) addr = svga->remap_func(svga, svga->ma) & svga->vram_display_mask; @@ -183,11 +188,15 @@ void svga_render_text_80(svga_t *svga) { uint32_t *p; - int x, xx; - int drawcursor, xinc; - uint8_t chr, attr, dat; + int xx; + int drawcursor; + int xinc; + uint8_t chr; + uint8_t attr; + uint8_t dat; uint32_t charaddr; - int fg, bg; + int fg; + int bg; uint32_t addr = 0; if ((svga->displine + svga->y_add) < 0) @@ -201,7 +210,7 @@ svga_render_text_80(svga_t *svga) p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; xinc = (svga->seqregs[1] & 1) ? 8 : 9; - for (x = 0; x < (svga->hdisp + svga->scrollcache); x += xinc) { + for (int x = 0; x < (svga->hdisp + svga->scrollcache); x += xinc) { if (!svga->force_old_addr) addr = svga->remap_func(svga, svga->ma) & svga->vram_display_mask; @@ -257,11 +266,16 @@ void svga_render_text_80_ksc5601(svga_t *svga) { uint32_t *p; - int x, xx; - int drawcursor, xinc; - uint8_t chr, attr, dat, nextchr; + int xx; + int drawcursor; + int xinc; + uint8_t chr; + uint8_t attr; + uint8_t dat; + uint8_t nextchr; uint32_t charaddr; - int fg, bg; + int fg; + int bg; if ((svga->displine + svga->y_add) < 0) return; @@ -275,7 +289,7 @@ svga_render_text_80_ksc5601(svga_t *svga) xinc = (svga->seqregs[1] & 1) ? 8 : 9; - for (x = 0; x < (svga->hdisp + svga->scrollcache); x += xinc) { + for (int x = 0; x < (svga->hdisp + svga->scrollcache); x += xinc) { uint32_t addr = svga->remap_func(svga, svga->ma) & svga->vram_display_mask; drawcursor = ((svga->ma == svga->ca) && svga->con && svga->cursoron); chr = svga->vram[addr]; @@ -381,11 +395,12 @@ svga_render_text_80_ksc5601(svga_t *svga) void svga_render_2bpp_lowres(svga_t *svga) { - int changed_offset; - int x; - uint8_t dat[2]; - uint32_t addr, *p; - uint32_t changed_addr; + int changed_offset; + int x; + uint8_t dat[2]; + uint32_t addr; + uint32_t *p; + uint32_t changed_addr; if ((svga->displine + svga->y_add) < 0) return; @@ -478,11 +493,12 @@ svga_render_2bpp_lowres(svga_t *svga) void svga_render_2bpp_highres(svga_t *svga) { - int changed_offset; - int x; - uint8_t dat[2]; - uint32_t addr, *p; - uint32_t changed_addr; + int changed_offset; + int x; + uint8_t dat[2]; + uint32_t addr; + uint32_t *p; + uint32_t changed_addr; if ((svga->displine + svga->y_add) < 0) return; @@ -575,12 +591,12 @@ svga_render_2bpp_highres(svga_t *svga) void svga_render_2bpp_headland_highres(svga_t *svga) { - int x; - int oddeven; - uint32_t addr, *p; - uint8_t edat[4]; - uint8_t dat; - uint32_t changed_addr; + int oddeven; + uint32_t addr; + uint32_t *p; + uint8_t edat[4]; + uint8_t dat; + uint32_t changed_addr; if ((svga->displine + svga->y_add) < 0) return; @@ -594,7 +610,7 @@ svga_render_2bpp_headland_highres(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { + for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { addr = svga->remap_func(svga, svga->ma); oddeven = 0; @@ -630,11 +646,13 @@ svga_render_2bpp_headland_highres(svga_t *svga) void svga_render_4bpp_lowres(svga_t *svga) { - int x, oddeven; - uint32_t addr, *p; - uint8_t edat[4]; - uint8_t dat; - uint32_t changed_addr; + int x; + int oddeven; + uint32_t addr; + uint32_t *p; + uint8_t edat[4]; + uint8_t dat; + uint32_t changed_addr; if ((svga->displine + svga->y_add) < 0) return; @@ -745,12 +763,14 @@ svga_render_4bpp_lowres(svga_t *svga) void svga_render_4bpp_highres(svga_t *svga) { - int changed_offset; - int x, oddeven; - uint32_t addr, *p; - uint8_t edat[4]; - uint8_t dat; - uint32_t changed_addr; + int changed_offset; + int x; + int oddeven; + uint32_t addr; + uint32_t *p; + uint8_t edat[4]; + uint8_t dat; + uint32_t changed_addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1018,7 +1038,6 @@ svga_render_8bpp_highres(svga_t *svga) void svga_render_8bpp_tseng_lowres(svga_t *svga) { - int x; uint32_t *p; uint32_t dat; @@ -1032,7 +1051,7 @@ svga_render_8bpp_tseng_lowres(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { + for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); if (svga->attrregs[0x10] & 0x80) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); @@ -1060,7 +1079,6 @@ svga_render_8bpp_tseng_lowres(svga_t *svga) void svga_render_8bpp_tseng_highres(svga_t *svga) { - int x; uint32_t *p; uint32_t dat; @@ -1074,7 +1092,7 @@ svga_render_8bpp_tseng_highres(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 8) { + for (int x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 8) { dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); if (svga->attrregs[0x10] & 0x80) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); @@ -1122,7 +1140,8 @@ svga_render_15bpp_lowres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1138,7 +1157,7 @@ svga_render_15bpp_lowres(svga_t *svga) for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[(x << 1)] = p[(x << 1) + 1] = video_15to32[dat & 0xffff]; + p[x << 1] = p[(x << 1) + 1] = video_15to32[dat & 0xffff]; p[(x << 1) + 2] = p[(x << 1) + 3] = video_15to32[dat >> 16]; dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); @@ -1193,7 +1212,8 @@ svga_render_15bpp_highres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1288,8 +1308,8 @@ svga_render_15bpp_mix_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[(x << 1)] = p[(x << 1) + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + p[x << 1] = p[(x << 1) + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; dat >>= 16; p[(x << 1) + 2] = p[(x << 1) + 3] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; @@ -1354,7 +1374,8 @@ svga_render_16bpp_lowres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1368,8 +1389,8 @@ svga_render_16bpp_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[(x << 1)] = p[(x << 1) + 1] = video_16to32[dat & 0xffff]; + dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + p[x << 1] = p[(x << 1) + 1] = video_16to32[dat & 0xffff]; p[(x << 1) + 2] = p[(x << 1) + 3] = video_16to32[dat >> 16]; dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); @@ -1423,7 +1444,8 @@ svga_render_16bpp_highres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1506,8 +1528,11 @@ svga_render_24bpp_lowres(svga_t *svga) { int x; uint32_t *p; - uint32_t changed_addr, addr; - uint32_t dat0, dat1, dat2; + uint32_t changed_addr; + uint32_t addr; + uint32_t dat0; + uint32_t dat1; + uint32_t dat2; uint32_t fg; if ((svga->displine + svga->y_add) < 0) @@ -1579,8 +1604,11 @@ svga_render_24bpp_highres(svga_t *svga) { int x; uint32_t *p; - uint32_t changed_addr, addr; - uint32_t dat0, dat1, dat2; + uint32_t changed_addr; + uint8_t addr; + uint32_t dat0; + uint32_t dat1; + uint32_t dat2; uint32_t dat; if ((svga->displine + svga->y_add) < 0) @@ -1662,7 +1690,8 @@ svga_render_32bpp_lowres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1717,7 +1746,8 @@ svga_render_32bpp_highres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1773,7 +1803,8 @@ svga_render_ABGR8888_highres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; @@ -1812,7 +1843,8 @@ svga_render_RGBA8888_highres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr; + uint32_t addr; if ((svga->displine + svga->y_add) < 0) return; diff --git a/src/video/vid_table.c b/src/video/vid_table.c index fb6624ced..eb999eb3f 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -36,6 +36,7 @@ #include <86box/vid_ega.h> #include <86box/vid_colorplus.h> #include <86box/vid_mda.h> +#include <86box/vid_xga_device.h> typedef struct { const device_t *device; @@ -79,6 +80,8 @@ video_cards[] = { { &vid_none_device }, { &vid_internal_device }, { &atiega_device }, + { &mach8_isa_device, VIDEO_FLAG_TYPE_8514 }, + { &mach32_isa_device, VIDEO_FLAG_TYPE_8514 }, { &mach64gx_isa_device }, { &ati28800k_device }, { &ati18800_vga88_device }, @@ -112,6 +115,7 @@ video_cards[] = { { &hercules_device, VIDEO_FLAG_TYPE_MDA }, { &herculesplus_device, VIDEO_FLAG_TYPE_MDA }, { &incolor_device }, + { &inmos_isa_device, VIDEO_FLAG_TYPE_XGA }, { &im1024_device }, { &iskra_ega_device }, { &et4000_kasan_isa_device }, @@ -154,6 +158,7 @@ video_cards[] = { { &gd5428_mca_device }, { &et4000_mca_device }, { &radius_svga_multiview_mca_device }, + { &mach32_pci_device, VIDEO_FLAG_TYPE_8514 }, { &mach64gx_pci_device }, { &mach64vt2_device }, { &et4000w32p_videomagic_revb_pci_device }, @@ -199,7 +204,7 @@ video_cards[] = { { &s3_diamond_stealth_4000_pci_device }, { &s3_trio3d2x_pci_device }, #if defined(DEV_BRANCH) && defined(USE_MGA) - { &millennium_device }, + { &millennium_device, VIDEO_FLAG_TYPE_SPECIAL }, { &mystique_device }, { &mystique_220_device }, #endif @@ -211,6 +216,7 @@ video_cards[] = { { &voodoo_3_1000_device }, { &voodoo_3_2000_device }, { &voodoo_3_3000_device }, + { &mach32_vlb_device, VIDEO_FLAG_TYPE_8514 }, { &mach64gx_vlb_device }, { &et4000w32i_vlb_device }, { &et4000w32p_videomagic_revb_vlb_device }, @@ -370,7 +376,7 @@ video_card_available(int card) if (video_cards[card].device) return (device_available(video_cards[card].device)); - return (1); + return 1; } int @@ -389,7 +395,7 @@ int video_card_has_config(int card) { if (video_cards[card].device == NULL) - return (0); + return 0; return (device_has_config(video_cards[card].device) ? 1 : 0); } @@ -406,12 +412,12 @@ video_get_video_from_internal_name(char *s) int c = 0; while (video_cards[c].device != NULL) { - if (!strcmp((char *) video_cards[c].device->internal_name, s)) - return (c); + if (!strcmp(video_cards[c].device->internal_name, s)) + return c; c++; } - return (0); + return 0; } int @@ -431,3 +437,15 @@ video_is_ega_vga(void) { return (video_get_type() == VIDEO_FLAG_TYPE_SPECIAL); } + +int +video_is_8514(void) +{ + return (video_get_type() == VIDEO_FLAG_TYPE_8514); +} + +int +video_is_xga(void) +{ + return (video_get_type() == VIDEO_FLAG_TYPE_XGA); +} diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index f2475888b..f659f90fe 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -169,17 +169,17 @@ typedef struct tgui_t { video_timings_t timing_tgui_vlb = { .type = VIDEO_BUS, .write_b = 4, .write_w = 8, .write_l = 16, .read_b = 4, .read_w = 8, .read_l = 16 }; video_timings_t timing_tgui_pci = { .type = VIDEO_PCI, .write_b = 4, .write_w = 8, .write_l = 16, .read_b = 4, .read_w = 8, .read_l = 16 }; -static void tgui_out(uint16_t addr, uint8_t val, void *p); -static uint8_t tgui_in(uint16_t addr, void *p); +static void tgui_out(uint16_t addr, uint8_t val, void *priv); +static uint8_t tgui_in(uint16_t addr, void *priv); static void tgui_recalcmapping(tgui_t *tgui); -static void tgui_accel_out(uint16_t addr, uint8_t val, void *p); -static void tgui_accel_out_w(uint16_t addr, uint16_t val, void *p); -static void tgui_accel_out_l(uint16_t addr, uint32_t val, void *p); -static uint8_t tgui_accel_in(uint16_t addr, void *p); -static uint16_t tgui_accel_in_w(uint16_t addr, void *p); -static uint32_t tgui_accel_in_l(uint16_t addr, void *p); +static void tgui_accel_out(uint16_t addr, uint8_t val, void *priv); +static void tgui_accel_out_w(uint16_t addr, uint16_t val, void *priv); +static void tgui_accel_out_l(uint16_t addr, uint32_t val, void *priv); +static uint8_t tgui_accel_in(uint16_t addr, void *priv); +static uint16_t tgui_accel_in_w(uint16_t addr, void *priv); +static uint32_t tgui_accel_in_l(uint16_t addr, void *priv); static uint8_t tgui_accel_read(uint32_t addr, void *priv); static uint16_t tgui_accel_read_w(uint32_t addr, void *priv); @@ -193,15 +193,15 @@ static void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *priv); static void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *priv); static void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *priv); -static uint8_t tgui_ext_linear_read(uint32_t addr, void *p); -static void tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p); -static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p); -static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *p); +static uint8_t tgui_ext_linear_read(uint32_t addr, void *priv); +static void tgui_ext_linear_write(uint32_t addr, uint8_t val, void *priv); +static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *priv); +static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *priv); -static uint8_t tgui_ext_read(uint32_t addr, void *p); -static void tgui_ext_write(uint32_t addr, uint8_t val, void *p); -static void tgui_ext_writew(uint32_t addr, uint16_t val, void *p); -static void tgui_ext_writel(uint32_t addr, uint32_t val, void *p); +static uint8_t tgui_ext_read(uint32_t addr, void *priv); +static void tgui_ext_write(uint32_t addr, uint8_t val, void *priv); +static void tgui_ext_writew(uint32_t addr, uint16_t val, void *priv); +static void tgui_ext_writel(uint32_t addr, uint32_t val, void *priv); /*Remap address for chain-4/doubleword style layout*/ static __inline uint32_t @@ -289,9 +289,9 @@ tgui_set_io(tgui_t *tgui) } static void -tgui_out(uint16_t addr, uint8_t val, void *p) +tgui_out(uint16_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint8_t old; @@ -531,9 +531,9 @@ tgui_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -tgui_in(uint16_t addr, void *p) +tgui_in(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint8_t temp; @@ -624,7 +624,7 @@ tgui_in(uint16_t addr, void *p) void tgui_recalctimings(svga_t *svga) { - tgui_t *tgui = (tgui_t *) svga->p; + tgui_t *tgui = (tgui_t *) svga->priv; uint8_t ger22lower = tgui->accel.ger22 & 0xff; uint8_t ger22upper = (tgui->accel.ger22 >> 8); @@ -678,7 +678,7 @@ tgui_recalctimings(svga_t *svga) if (tgui->type >= TGUI_9440) { if (svga->miscout & 8) - svga->clock = (cpuclock * (double) (1ull << 32)) / (((tgui->clock_n + 8) * 14318180.0) / ((tgui->clock_m + 2) * (1 << tgui->clock_k))); + svga->clock = (cpuclock * (double) (1ULL << 32)) / (((tgui->clock_n + 8) * 14318180.0) / ((tgui->clock_m + 2) * (1 << tgui->clock_k))); if (svga->gdcreg[0xf] & 0x08) svga->clock *= 2; @@ -687,46 +687,46 @@ tgui_recalctimings(svga_t *svga) } else { switch (((svga->miscout >> 2) & 3) | ((tgui->newctrl2 << 2) & 4) | ((tgui->newctrl2 >> 3) & 8)) { case 0x02: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; break; case 0x03: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; case 0x04: - svga->clock = (cpuclock * (double) (1ull << 32)) / 57272000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 57272000.0; break; case 0x05: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; break; case 0x06: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50350000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; break; case 0x07: - svga->clock = (cpuclock * (double) (1ull << 32)) / 40000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 40000000.0; break; case 0x08: - svga->clock = (cpuclock * (double) (1ull << 32)) / 88000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 88000000.0; break; case 0x09: - svga->clock = (cpuclock * (double) (1ull << 32)) / 98000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 98000000.0; break; case 0x0a: - svga->clock = (cpuclock * (double) (1ull << 32)) / 118800000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 118800000.0; break; case 0x0b: - svga->clock = (cpuclock * (double) (1ull << 32)) / 108000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 108000000.0; break; case 0x0c: - svga->clock = (cpuclock * (double) (1ull << 32)) / 72000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 72000000.0; break; case 0x0d: - svga->clock = (cpuclock * (double) (1ull << 32)) / 77000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 77000000.0; break; case 0x0e: - svga->clock = (cpuclock * (double) (1ull << 32)) / 80000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 80000000.0; break; case 0x0f: - svga->clock = (cpuclock * (double) (1ull << 32)) / 75000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 75000000.0; break; } if (svga->gdcreg[0xf] & 0x08) { @@ -894,7 +894,6 @@ static void tgui_hwcursor_draw(svga_t *svga, int displine) { uint32_t dat[2]; - int xx; int offset = svga->hwcursor_latch.x + svga->hwcursor_latch.xoff; int pitch = (svga->hwcursor_latch.cur_xsize == 64) ? 16 : 8; @@ -903,7 +902,7 @@ tgui_hwcursor_draw(svga_t *svga, int displine) dat[0] = (svga->vram[svga->hwcursor_latch.addr] << 24) | (svga->vram[svga->hwcursor_latch.addr + 1] << 16) | (svga->vram[svga->hwcursor_latch.addr + 2] << 8) | svga->vram[svga->hwcursor_latch.addr + 3]; dat[1] = (svga->vram[svga->hwcursor_latch.addr + 4] << 24) | (svga->vram[svga->hwcursor_latch.addr + 5] << 16) | (svga->vram[svga->hwcursor_latch.addr + 6] << 8) | svga->vram[svga->hwcursor_latch.addr + 7]; - for (xx = 0; xx < 32; xx++) { + for (uint8_t xx = 0; xx < 32; xx++) { if (svga->crtc[0x50] & 0x40) { if (offset >= svga->hwcursor_latch.x) { if (dat[0] & 0x80000000) @@ -928,9 +927,9 @@ tgui_hwcursor_draw(svga_t *svga, int displine) } uint8_t -tgui_pci_read(int func, int addr, void *p) +tgui_pci_read(int func, int addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x00: @@ -995,9 +994,9 @@ tgui_pci_read(int func, int addr, void *p) } void -tgui_pci_write(int func, int addr, uint8_t val, void *p) +tgui_pci_write(int func, int addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; switch (addr) { @@ -1065,11 +1064,10 @@ tgui_pci_write(int func, int addr, uint8_t val, void *p) } static uint8_t -tgui_ext_linear_read(uint32_t addr, void *p) +tgui_ext_linear_read(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; - int c; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; cycles -= video_timing_read_b; @@ -1080,7 +1078,7 @@ tgui_ext_linear_read(uint32_t addr, void *p) addr &= ~0xf; addr = dword_remap(svga, addr); - for (c = 0; c < 16; c++) { + for (uint8_t c = 0; c < 16; c++) { tgui->copy_latch[c] = svga->vram[addr + c]; addr += ((c & 3) == 3) ? 13 : 1; } @@ -1089,9 +1087,9 @@ tgui_ext_linear_read(uint32_t addr, void *p) } static uint8_t -tgui_ext_read(uint32_t addr, void *p) +tgui_ext_read(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; @@ -1099,10 +1097,10 @@ tgui_ext_read(uint32_t addr, void *p) } static void -tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p) +tgui_ext_linear_write(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; int c; uint8_t fg[2] = { tgui->ext_gdc_regs[4], tgui->ext_gdc_regs[5] }; uint8_t bg[2] = { tgui->ext_gdc_regs[1], tgui->ext_gdc_regs[2] }; @@ -1173,10 +1171,10 @@ tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p) } static void -tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p) +tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; int c; uint8_t fg[2] = { tgui->ext_gdc_regs[4], tgui->ext_gdc_regs[5] }; uint8_t bg[2] = { tgui->ext_gdc_regs[1], tgui->ext_gdc_regs[2] }; @@ -1249,33 +1247,33 @@ tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p) } static void -tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *p) +tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *priv) { - tgui_ext_linear_writew(addr, val, p); + tgui_ext_linear_writew(addr, val, priv); } static void -tgui_ext_write(uint32_t addr, uint8_t val, void *p) +tgui_ext_write(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; tgui_ext_linear_write(addr, val, svga); } static void -tgui_ext_writew(uint32_t addr, uint16_t val, void *p) +tgui_ext_writew(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; tgui_ext_linear_writew(addr, val, svga); } static void -tgui_ext_writel(uint32_t addr, uint32_t val, void *p) +tgui_ext_writel(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; @@ -1341,10 +1339,14 @@ tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) { svga_t *svga = &tgui->svga; uint32_t *pattern_data; - int x, y; - int c, d; + int x; + int y; + int c; + int d; uint32_t out; - uint32_t src_dat = 0, dst_dat, pat_dat; + uint32_t src_dat = 0; + uint32_t dst_dat; + uint32_t pat_dat; int xdir = (tgui->accel.flags & 0x200) ? -1 : 1; int ydir = (tgui->accel.flags & 0x100) ? -1 : 1; uint32_t trans_col = (tgui->accel.flags & TGUI_TRANSREV) ? tgui->accel.fg_col : tgui->accel.bg_col; @@ -1993,9 +1995,9 @@ tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) } static void -tgui_accel_out(uint16_t addr, uint8_t val, void *p) +tgui_accel_out(uint16_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x2122: @@ -2337,17 +2339,17 @@ tgui_accel_out(uint16_t addr, uint8_t val, void *p) } static void -tgui_accel_out_w(uint16_t addr, uint16_t val, void *p) +tgui_accel_out_w(uint16_t addr, uint16_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; tgui_accel_out(addr, val, tgui); tgui_accel_out(addr + 1, val >> 8, tgui); } static void -tgui_accel_out_l(uint16_t addr, uint32_t val, void *p) +tgui_accel_out_l(uint16_t addr, uint32_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x2124: /*Long version of Command and ROP together*/ @@ -2367,9 +2369,9 @@ tgui_accel_out_l(uint16_t addr, uint32_t val, void *p) } static uint8_t -tgui_accel_in(uint16_t addr, void *p) +tgui_accel_in(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x2120: /*Status*/ @@ -2620,23 +2622,23 @@ tgui_accel_in(uint16_t addr, void *p) } static uint16_t -tgui_accel_in_w(uint16_t addr, void *p) +tgui_accel_in_w(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; return tgui_accel_in(addr, tgui) | (tgui_accel_in(addr + 1, tgui) << 8); } static uint32_t -tgui_accel_in_l(uint16_t addr, void *p) +tgui_accel_in_l(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; return tgui_accel_in_w(addr, tgui) | (tgui_accel_in_w(addr + 2, tgui) << 16); } static void -tgui_accel_write(uint32_t addr, uint8_t val, void *p) +tgui_accel_write(uint32_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; if ((svga->crtc[0x36] & 0x03) == 0x02) { @@ -2987,18 +2989,18 @@ tgui_accel_write(uint32_t addr, uint8_t val, void *p) } static void -tgui_accel_write_w(uint32_t addr, uint16_t val, void *p) +tgui_accel_write_w(uint32_t addr, uint16_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; tgui_accel_write(addr, val, tgui); tgui_accel_write(addr + 1, val >> 8, tgui); } static void -tgui_accel_write_l(uint32_t addr, uint32_t val, void *p) +tgui_accel_write_l(uint32_t addr, uint32_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; switch (addr & 0xff) { @@ -3024,9 +3026,9 @@ tgui_accel_write_l(uint32_t addr, uint32_t val, void *p) } static uint8_t -tgui_accel_read(uint32_t addr, void *p) +tgui_accel_read(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; if ((svga->crtc[0x36] & 0x03) == 0x02) { @@ -3286,24 +3288,26 @@ tgui_accel_read(uint32_t addr, void *p) } static uint16_t -tgui_accel_read_w(uint32_t addr, void *p) +tgui_accel_read_w(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; + return tgui_accel_read(addr, tgui) | (tgui_accel_read(addr + 1, tgui) << 8); } static uint32_t -tgui_accel_read_l(uint32_t addr, void *p) +tgui_accel_read_l(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; + return tgui_accel_read_w(addr, tgui) | (tgui_accel_read_w(addr + 2, tgui) << 16); } static void -tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *p) +tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; if (tgui->write_blitter) { tgui_accel_command(8, val << 24, tgui); @@ -3312,10 +3316,10 @@ tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *p) } static void -tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *p) +tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; if (tgui->write_blitter) tgui_accel_command(16, (((val & 0xff00) >> 8) | ((val & 0x00ff) << 8)) << 16, tgui); @@ -3324,10 +3328,10 @@ tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *p) } static void -tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *p) +tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; if (tgui->write_blitter) tgui_accel_command(32, ((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24), tgui); @@ -3336,63 +3340,63 @@ tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *p) } static void -tgui_mmio_write(uint32_t addr, uint8_t val, void *p) +tgui_mmio_write(uint32_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - tgui_accel_out(addr, val, p); + tgui_accel_out(addr, val, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - tgui_accel_write(addr, val, p); + tgui_accel_write(addr, val, priv); else - tgui_out(addr, val, p); + tgui_out(addr, val, priv); } static void -tgui_mmio_write_w(uint32_t addr, uint16_t val, void *p) +tgui_mmio_write_w(uint32_t addr, uint16_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - tgui_accel_out_w(addr, val, p); + tgui_accel_out_w(addr, val, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - tgui_accel_write_w(addr, val, p); + tgui_accel_write_w(addr, val, priv); else { - tgui_out(addr, val & 0xff, p); - tgui_out(addr + 1, val >> 8, p); + tgui_out(addr, val & 0xff, priv); + tgui_out(addr + 1, val >> 8, priv); } } static void -tgui_mmio_write_l(uint32_t addr, uint32_t val, void *p) +tgui_mmio_write_l(uint32_t addr, uint32_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - tgui_accel_out_l(addr, val, p); + tgui_accel_out_l(addr, val, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - tgui_accel_write_l(addr, val, p); + tgui_accel_write_l(addr, val, priv); else { - tgui_out(addr, val & 0xff, p); - tgui_out(addr + 1, val >> 8, p); - tgui_out(addr + 2, val >> 16, p); - tgui_out(addr + 3, val >> 24, p); + tgui_out(addr, val & 0xff, priv); + tgui_out(addr + 1, val >> 8, priv); + tgui_out(addr + 2, val >> 16, priv); + tgui_out(addr + 3, val >> 24, priv); } } static uint8_t -tgui_mmio_read(uint32_t addr, void *p) +tgui_mmio_read(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint8_t ret = 0xff; @@ -3400,49 +3404,49 @@ tgui_mmio_read(uint32_t addr, void *p) addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - ret = tgui_accel_in(addr, p); + ret = tgui_accel_in(addr, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - ret = tgui_accel_read(addr, p); + ret = tgui_accel_read(addr, priv); else - ret = tgui_in(addr, p); + ret = tgui_in(addr, priv); return ret; } static uint16_t -tgui_mmio_read_w(uint32_t addr, void *p) +tgui_mmio_read_w(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint16_t ret = 0xffff; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - ret = tgui_accel_in_w(addr, p); + ret = tgui_accel_in_w(addr, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - ret = tgui_accel_read_w(addr, p); + ret = tgui_accel_read_w(addr, priv); else - ret = tgui_in(addr, p) | (tgui_in(addr + 1, p) << 8); + ret = tgui_in(addr, priv) | (tgui_in(addr + 1, priv) << 8); return ret; } static uint32_t -tgui_mmio_read_l(uint32_t addr, void *p) +tgui_mmio_read_l(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint32_t ret = 0xffffffff; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - ret = tgui_accel_in_l(addr, p); + ret = tgui_accel_in_l(addr, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - ret = tgui_accel_read_l(addr, p); + ret = tgui_accel_read_l(addr, priv); else - ret = tgui_in(addr, p) | (tgui_in(addr + 1, p) << 8) | (tgui_in(addr + 2, p) << 16) | (tgui_in(addr + 3, p) << 24); + ret = tgui_in(addr, priv) | (tgui_in(addr + 1, priv) << 8) | (tgui_in(addr + 2, priv) << 16) | (tgui_in(addr + 3, priv) << 24); return ret; } @@ -3554,32 +3558,32 @@ tgui96xx_available(void) } void -tgui_close(void *p) +tgui_close(void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_close(&tgui->svga); if (tgui->type >= TGUI_9440) { ddc_close(tgui->ddc); i2c_gpio_close(tgui->i2c); - }; + } free(tgui); } void -tgui_speed_changed(void *p) +tgui_speed_changed(void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_recalctimings(&tgui->svga); } void -tgui_force_redraw(void *p) +tgui_force_redraw(void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; tgui->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ti_cf62011.c b/src/video/vid_ti_cf62011.c index f804a6dde..32c37ca8b 100644 --- a/src/video/vid_ti_cf62011.c +++ b/src/video/vid_ti_cf62011.c @@ -195,7 +195,7 @@ vid_in(uint16_t addr, void *priv) break; } - return (ret); + return ret; } static void @@ -252,7 +252,7 @@ vid_init(const device_t *info) ti->svga.bpp = 8; ti->svga.miscout = 1; - return (ti); + return ti; } const device_t ibm_ps1_2121_device = { diff --git a/src/video/vid_tvga.c b/src/video/vid_tvga.c index 384770ba4..8483bbd33 100644 --- a/src/video/vid_tvga.c +++ b/src/video/vid_tvga.c @@ -74,9 +74,9 @@ static uint8_t crtc_mask[0x40] = { static void tvga_recalcbanking(tvga_t *tvga); void -tvga_out(uint16_t addr, uint8_t val, void *p) +tvga_out(uint16_t addr, uint8_t val, void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_t *svga = &tvga->svga; uint8_t old; @@ -199,9 +199,9 @@ tvga_out(uint16_t addr, uint8_t val, void *p) } uint8_t -tvga_in(uint16_t addr, void *p) +tvga_in(uint16_t addr, void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_t *svga = &tvga->svga; if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) @@ -261,7 +261,7 @@ tvga_recalcbanking(tvga_t *tvga) void tvga_recalctimings(svga_t *svga) { - tvga_t *tvga = (tvga_t *) svga->p; + tvga_t *tvga = (tvga_t *) svga->priv; int clksel; int high_res_256 = 0; @@ -305,46 +305,46 @@ tvga_recalctimings(svga_t *svga) switch (clksel) { case 0x2: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; break; case 0x3: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; case 0x4: - svga->clock = (cpuclock * (double) (1ull << 32)) / 57272000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 57272000.0; break; case 0x5: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; break; case 0x6: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50350000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; break; case 0x7: - svga->clock = (cpuclock * (double) (1ull << 32)) / 40000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 40000000.0; break; case 0x8: - svga->clock = (cpuclock * (double) (1ull << 32)) / 88000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 88000000.0; break; case 0x9: - svga->clock = (cpuclock * (double) (1ull << 32)) / 98000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 98000000.0; break; case 0xa: - svga->clock = (cpuclock * (double) (1ull << 32)) / 118800000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 118800000.0; break; case 0xb: - svga->clock = (cpuclock * (double) (1ull << 32)) / 108000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 108000000.0; break; case 0xc: - svga->clock = (cpuclock * (double) (1ull << 32)) / 72000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 72000000.0; break; case 0xd: - svga->clock = (cpuclock * (double) (1ull << 32)) / 77000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 77000000.0; break; case 0xe: - svga->clock = (cpuclock * (double) (1ull << 32)) / 80000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 80000000.0; break; case 0xf: - svga->clock = (cpuclock * (double) (1ull << 32)) / 75000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 75000000.0; break; } @@ -458,9 +458,9 @@ tvga9000b_nec_sv9000_available(void) } void -tvga_close(void *p) +tvga_close(void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_close(&tvga->svga); @@ -468,17 +468,17 @@ tvga_close(void *p) } void -tvga_speed_changed(void *p) +tvga_speed_changed(void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_recalctimings(&tvga->svga); } void -tvga_force_redraw(void *p) +tvga_force_redraw(void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; tvga->svga.fullchange = changeframecount; } diff --git a/src/video/vid_tvp3026_ramdac.c b/src/video/vid_tvp3026_ramdac.c index 148c9b748..da75543ca 100644 --- a/src/video/vid_tvp3026_ramdac.c +++ b/src/video/vid_tvp3026_ramdac.c @@ -452,11 +452,20 @@ tvp3026_recalctimings(void *p, svga_t *svga) void tvp3026_hwcursor_draw(svga_t *svga, int displine) { - int x, xx, comb, b0, b1; + int comb; + int b0; + int b1; uint16_t dat[2]; int offset = svga->dac_hwcursor_latch.x + svga->dac_hwcursor_latch.xoff; - int pitch, bppl, mode, x_pos, y_pos; - uint32_t clr1, clr2, clr3, *p; + int pitch; + int bppl; + int mode; + int x_pos; + int y_pos; + uint32_t clr1; + uint32_t clr2; + uint32_t clr3; + uint32_t *p; uint8_t *cd; tvp3026_ramdac_t *ramdac = (tvp3026_ramdac_t *) svga->ramdac; @@ -478,18 +487,18 @@ tvp3026_hwcursor_draw(svga_t *svga, int displine) cd = (uint8_t *) ramdac->cursor64_data; - for (x = 0; x < svga->dac_hwcursor_latch.cur_xsize; x += 16) { + for (int x = 0; x < svga->dac_hwcursor_latch.cur_xsize; x += 16) { dat[0] = (cd[svga->dac_hwcursor_latch.addr] << 8) | cd[svga->dac_hwcursor_latch.addr + 1]; dat[1] = (cd[svga->dac_hwcursor_latch.addr + bppl] << 8) | cd[svga->dac_hwcursor_latch.addr + bppl + 1]; - for (xx = 0; xx < 16; xx++) { + for (uint8_t xx = 0; xx < 16; xx++) { b0 = (dat[0] >> (15 - xx)) & 1; b1 = (dat[1] >> (15 - xx)) & 1; comb = (b0 | (b1 << 1)); y_pos = displine; x_pos = offset + svga->x_add; - p = buffer32->line[y_pos]; + p = svga->monitor->target_buffer->line[y_pos]; if (offset >= svga->dac_hwcursor_latch.x) { switch (mode) { @@ -541,11 +550,14 @@ tvp3026_hwcursor_draw(svga_t *svga, int displine) } float -tvp3026_getclock(int clock, void *p) +tvp3026_getclock(int clock, void *priv) { - tvp3026_ramdac_t *ramdac = (tvp3026_ramdac_t *) p; - int n, m, pl; - float f_vco, f_pll; + tvp3026_ramdac_t *ramdac = (tvp3026_ramdac_t *) priv; + int n; + int m; + int pl; + float f_vco; + float f_pll; if (clock == 0) return 25175000.0; diff --git a/src/video/vid_vga.c b/src/video/vid_vga.c index ac26c2b5d..43b8a2750 100644 --- a/src/video/vid_vga.c +++ b/src/video/vid_vga.c @@ -35,9 +35,9 @@ static video_timings_t timing_ps1_svga_isa = { .type = VIDEO_ISA, .write_b = 6, static video_timings_t timing_ps1_svga_mca = { .type = VIDEO_MCA, .write_b = 6, .write_w = 8, .write_l = 16, .read_b = 6, .read_w = 8, .read_l = 16 }; void -vga_out(uint16_t addr, uint8_t val, void *p) +vga_out(uint16_t addr, uint8_t val, void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_t *svga = &vga->svga; uint8_t old; @@ -69,14 +69,17 @@ vga_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } uint8_t -vga_in(uint16_t addr, void *p) +vga_in(uint16_t addr, void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_t *svga = &vga->svga; uint8_t temp; @@ -157,9 +160,9 @@ vga_available(void) } void -vga_close(void *p) +vga_close(void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_close(&vga->svga); @@ -167,17 +170,17 @@ vga_close(void *p) } void -vga_speed_changed(void *p) +vga_speed_changed(void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_recalctimings(&vga->svga); } void -vga_force_redraw(void *p) +vga_force_redraw(void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; vga->svga.fullchange = changeframecount; } diff --git a/src/video/vid_voodoo.c b/src/video/vid_voodoo.c index cb5491c03..610e15e6c 100644 --- a/src/video/vid_voodoo.c +++ b/src/video/vid_voodoo.c @@ -48,7 +48,12 @@ #include <86box/vid_voodoo_render.h> #include <86box/vid_voodoo_texture.h> -rgba8_t rgb332[0x100], ai44[0x100], rgb565[0x10000], argb1555[0x10000], argb4444[0x10000], ai88[0x10000]; +rgba8_t rgb332[0x100]; +rgba8_t ai44[0x100]; +rgba8_t rgb565[0x10000]; +rgba8_t argb1555[0x10000]; +rgba8_t argb4444[0x10000]; +rgba8_t ai88[0x10000]; int tris = 0; @@ -144,9 +149,9 @@ voodoo_recalc(voodoo_t *voodoo) } static uint16_t -voodoo_readw(uint32_t addr, void *p) +voodoo_readw(uint32_t addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; addr &= 0xffffff; @@ -179,9 +184,9 @@ voodoo_readw(uint32_t addr, void *p) } static uint32_t -voodoo_readl(uint32_t addr, void *p) +voodoo_readl(uint32_t addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; uint32_t temp = 0xffffffff; int fifo_size; voodoo->rd_count++; @@ -389,9 +394,9 @@ voodoo_readl(uint32_t addr, void *p) } static void -voodoo_writew(uint32_t addr, uint16_t val, void *p) +voodoo_writew(uint32_t addr, uint16_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; voodoo->wr_count++; addr &= 0xffffff; @@ -402,9 +407,9 @@ voodoo_writew(uint32_t addr, uint16_t val, void *p) } static void -voodoo_writel(uint32_t addr, uint32_t val, void *p) +voodoo_writel(uint32_t addr, uint32_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; voodoo->wr_count++; @@ -665,32 +670,32 @@ voodoo_writel(uint32_t addr, uint32_t val, void *p) } static uint16_t -voodoo_snoop_readw(uint32_t addr, void *p) +voodoo_snoop_readw(uint32_t addr, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; return voodoo_readw(addr, set->voodoos[0]); } static uint32_t -voodoo_snoop_readl(uint32_t addr, void *p) +voodoo_snoop_readl(uint32_t addr, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; return voodoo_readl(addr, set->voodoos[0]); } static void -voodoo_snoop_writew(uint32_t addr, uint16_t val, void *p) +voodoo_snoop_writew(uint32_t addr, uint16_t val, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; voodoo_writew(addr, val, set->voodoos[0]); voodoo_writew(addr, val, set->voodoos[1]); } static void -voodoo_snoop_writel(uint32_t addr, uint32_t val, void *p) +voodoo_snoop_writel(uint32_t addr, uint32_t val, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; voodoo_writel(addr, val, set->voodoos[0]); voodoo_writel(addr, val, set->voodoos[1]); @@ -742,14 +747,16 @@ voodoo_recalcmapping(voodoo_set_t *set) } uint8_t -voodoo_pci_read(int func, int addr, void *p) +voodoo_pci_read(int func, int addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; if (func) return 0; - // voodoo_log("Voodoo PCI read %08X PC=%08x\n", addr, cpu_state.pc); +#if 0 + voodoo_log("Voodoo PCI read %08X PC=%08x\n", addr, cpu_state.pc); +#endif switch (addr) { case 0x00: @@ -801,14 +808,16 @@ voodoo_pci_read(int func, int addr, void *p) } void -voodoo_pci_write(int func, int addr, uint8_t val, void *p) +voodoo_pci_write(int func, int addr, uint8_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; if (func) return; - // voodoo_log("Voodoo PCI write %04X %02X PC=%08x\n", addr, val, cpu_state.pc); +#if 0 + voodoo_log("Voodoo PCI write %04X %02X PC=%08x\n", addr, val, cpu_state.pc); +#endif switch (addr) { case 0x04: @@ -839,9 +848,9 @@ voodoo_pci_write(int func, int addr, uint8_t val, void *p) } static void -voodoo_speed_changed(void *p) +voodoo_speed_changed(void *priv) { - voodoo_set_t *voodoo_set = (voodoo_set_t *) p; + voodoo_set_t *voodoo_set = (voodoo_set_t *) priv; voodoo_pixelclock_update(voodoo_set->voodoos[0]); voodoo_set->voodoos[0]->read_time = pci_nonburst_time + pci_burst_time * ((voodoo_set->voodoos[0]->fbiInit4 & 1) ? 2 : 1); @@ -853,13 +862,15 @@ voodoo_speed_changed(void *p) voodoo_set->voodoos[1]->write_time = pci_nonburst_time + pci_burst_time * ((voodoo_set->voodoos[1]->fbiInit1 & 2) ? 1 : 0); voodoo_set->voodoos[1]->burst_time = pci_burst_time * ((voodoo_set->voodoos[1]->fbiInit1 & 2) ? 2 : 1); } - // voodoo_log("Voodoo read_time=%i write_time=%i burst_time=%i %08x %08x\n", voodoo->read_time, voodoo->write_time, voodoo->burst_time, voodoo->fbiInit1, voodoo->fbiInit4); +#if 0 + voodoo_log("Voodoo read_time=%i write_time=%i burst_time=%i %08x %08x\n", voodoo->read_time, voodoo->write_time, voodoo->burst_time, voodoo->fbiInit1, voodoo->fbiInit4); +#endif } static void -voodoo_force_blit(void *p) +voodoo_force_blit(void *priv) { - voodoo_set_t *voodoo_set = (voodoo_set_t *) p; + voodoo_set_t *voodoo_set = (voodoo_set_t *) priv; thread_wait_mutex(voodoo_set->voodoos[0]->force_blit_mutex); if (voodoo_set->voodoos[0]->can_blit) { @@ -1208,8 +1219,6 @@ voodoo_init(const device_t *info) void voodoo_card_close(voodoo_t *voodoo) { - int c; - voodoo->fifo_thread_run = 0; thread_set_event(voodoo->wake_fifo_thread); thread_wait(voodoo->fifo_thread); @@ -1237,7 +1246,7 @@ voodoo_card_close(voodoo_t *voodoo) thread_destroy_event(voodoo->render_not_full_event[0]); thread_destroy_event(voodoo->render_not_full_event[1]); - for (c = 0; c < TEX_CACHE_MAX; c++) { + for (uint8_t c = 0; c < TEX_CACHE_MAX; c++) { if (voodoo->dual_tmus) free(voodoo->texture_cache[1][c].data); free(voodoo->texture_cache[0][c].data); @@ -1258,9 +1267,9 @@ voodoo_card_close(voodoo_t *voodoo) } void -voodoo_close(void *p) +voodoo_close(void *priv) { - voodoo_set_t *voodoo_set = (voodoo_set_t *) p; + voodoo_set_t *voodoo_set = (voodoo_set_t *) priv; if (voodoo_set->nr_cards == 2) voodoo_card_close(voodoo_set->voodoos[1]); diff --git a/src/video/vid_voodoo_banshee.c b/src/video/vid_voodoo_banshee.c index ef94f9846..0b3a3a043 100644 --- a/src/video/vid_voodoo_banshee.c +++ b/src/video/vid_voodoo_banshee.c @@ -315,7 +315,7 @@ banshee_update_irqs(banshee_t *banshee) static void banshee_vblank_start(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; if (banshee->vblank_irq >= 0) { banshee->vblank_irq = 1; banshee_update_irqs(banshee); @@ -323,14 +323,16 @@ banshee_vblank_start(svga_t *svga) } static void -banshee_out(uint16_t addr, uint8_t val, void *p) +banshee_out(uint16_t addr, uint8_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; svga_t *svga = &banshee->svga; uint8_t old; - // /*if (addr != 0x3c9) */banshee_log("banshee_out : %04X %02X %04X:%04X\n", addr, val, CS,cpu_state.pc); - +#if 0 + if (addr != 0x3c9) + banshee_log("banshee_out : %04X %02X %04X:%04X\n", addr, val, CS,cpu_state.pc); +#endif if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -373,13 +375,16 @@ banshee_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -banshee_in(uint16_t addr, void *p) +banshee_in(uint16_t addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; svga_t *svga = &banshee->svga; uint8_t temp; - // if (addr != 0x3da) banshee_log("banshee_in : %04X ", addr); +#if 0 + if (addr != 0x3da) + banshee_log("banshee_in : %04X ", addr); +#endif if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -403,7 +408,10 @@ banshee_in(uint16_t addr, void *p) temp = svga_in(addr, svga); break; } - // if (addr != 0x3da) banshee_log("%02X %04X:%04X %i\n", temp, CS,cpu_state.pc, ins); +#if 0 + if (addr != 0x3da) + banshee_log("%02X %04X:%04X %i\n", temp, CS,cpu_state.pc, ins); +#endif return temp; } @@ -452,8 +460,7 @@ banshee_updatemapping(banshee_t *banshee) static void banshee_render_16bpp_tiled(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; - int x; + banshee_t *banshee = (banshee_t *) svga->priv; uint32_t *p = &((uint32_t *) svga->monitor->target_buffer->line[svga->displine + svga->y_add])[svga->x_add]; uint32_t addr; int drawn = 0; @@ -466,14 +473,13 @@ banshee_render_16bpp_tiled(svga_t *svga) else addr = banshee->desktop_addr + (banshee->desktop_y & 31) * 128 + ((banshee->desktop_y >> 5) * banshee->desktop_stride_tiled); - for (x = 0; x <= svga->hdisp; x += 64) { + for (int x = 0; x <= svga->hdisp; x += 64) { if (svga->hwcursor_on || svga->overlay_on) svga->changedvram[addr >> 12] = 2; if (svga->changedvram[addr >> 12] || svga->fullchange) { uint16_t *vram_p = (uint16_t *) &svga->vram[addr & svga->vram_display_mask]; - int xx; - for (xx = 0; xx < 64; xx++) + for (uint8_t xx = 0; xx < 64; xx++) *p++ = video_16to32[*vram_p++]; drawn = 1; @@ -494,7 +500,7 @@ banshee_render_16bpp_tiled(svga_t *svga) static void banshee_recalctimings(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; voodoo_t *voodoo = banshee->voodoo; /*7 R/W Horizontal Retrace End bit 5. - @@ -524,7 +530,9 @@ banshee_recalctimings(svga_t *svga) svga->vblankstart += 0x400; if (svga->crtc[0x1b] & 0x40) svga->vsyncstart += 0x400; - // banshee_log("svga->hdisp=%i\n", svga->hdisp); +#if 0 + banshee_log("svga->hdisp=%i\n", svga->hdisp); +#endif svga->interlace = 0; @@ -559,7 +567,9 @@ banshee_recalctimings(svga_t *svga) svga->rowoffset = (banshee->vidDesktopOverlayStride & 0x3fff) >> 3; svga->ma_latch = banshee->vidDesktopStartAddr >> 2; banshee->desktop_stride_tiled = (banshee->vidDesktopOverlayStride & 0x3fff) * 128 * 32; - // banshee_log("Extended shift out %i rowoffset=%i %02x\n", VIDPROCCFG_DESKTOP_PIX_FORMAT, svga->rowoffset, svga->crtc[1]); +#if 0 + banshee_log("Extended shift out %i rowoffset=%i %02x\n", VIDPROCCFG_DESKTOP_PIX_FORMAT, svga->rowoffset, svga->crtc[1]); +#endif svga->char_width = 8; svga->split = 99999; @@ -583,11 +593,13 @@ banshee_recalctimings(svga_t *svga) if (svga->overlay.cur_xsize <= 0 || svga->overlay.cur_ysize <= 0) svga->overlay.ena = 0; if (svga->overlay.ena) { - /* banshee_log("Overlay enabled : start=%i,%i end=%i,%i size=%i,%i pitch=%x\n", - voodoo->overlay.start_x, voodoo->overlay.start_y, - voodoo->overlay.end_x, voodoo->overlay.end_y, - voodoo->overlay.size_x, voodoo->overlay.size_y, - svga->overlay.pitch);*/ +#if 0 + banshee_log("Overlay enabled : start=%i,%i end=%i,%i size=%i,%i pitch=%x\n", + voodoo->overlay.start_x, voodoo->overlay.start_y, + voodoo->overlay.end_x, voodoo->overlay.end_y, + voodoo->overlay.size_x, voodoo->overlay.size_y, + svga->overlay.pitch); +#endif if (!voodoo->overlay.start_x && !voodoo->overlay.start_y && svga->hdisp == voodoo->overlay.size_x && svga->dispend == voodoo->overlay.size_y) { /*Overlay is full screen, so don't bother rendering the desktop behind it*/ @@ -596,7 +608,9 @@ banshee_recalctimings(svga_t *svga) } } } else { - // banshee_log("Normal shift out\n"); +#if 0 + banshee_log("Normal shift out\n"); +#endif svga->bpp = 8; } @@ -608,20 +622,28 @@ banshee_recalctimings(svga_t *svga) int n = (banshee->pllCtrl0 >> 8) & 0xff; double freq = (((double) n + 2) / (((double) m + 2) * (double) (1 << k))) * 14318184.0; - svga->clock = (cpuclock * (float) (1ull << 32)) / freq; - // svga->clock = cpuclock / freq; + svga->clock = (cpuclock * (float) (1ULL << 32)) / freq; +#if 0 + svga->clock = cpuclock / freq; +#endif - // banshee_log("svga->clock = %g %g m=%i k=%i n=%i\n", freq, freq / 1000000.0, m, k, n); +#if 0 + banshee_log("svga->clock = %g %g m=%i k=%i n=%i\n", freq, freq / 1000000.0, m, k, n); +#endif } } static void -banshee_ext_out(uint16_t addr, uint8_t val, void *p) +banshee_ext_out(uint16_t addr, uint8_t val, void *priv) { - // banshee_t *banshee = (banshee_t *)p; - // svga_t *svga = &banshee->svga; +#if 0 + banshee_t *banshee = (banshee_t *)priv; + svga_t *svga = &banshee->svga; +#endif - // banshee_log("banshee_ext_out: addr=%04x val=%02x\n", addr, val); +#if 0 + banshee_log("banshee_ext_out: addr=%04x val=%02x\n", addr, val); +#endif switch (addr & 0xff) { case 0xb0: @@ -672,7 +694,7 @@ banshee_ext_out(uint16_t addr, uint8_t val, void *p) case 0xdd: case 0xde: case 0xdf: - banshee_out((addr & 0xff) + 0x300, val, p); + banshee_out((addr & 0xff) + 0x300, val, priv); break; default: @@ -680,13 +702,15 @@ banshee_ext_out(uint16_t addr, uint8_t val, void *p) } } static void -banshee_ext_outl(uint16_t addr, uint32_t val, void *p) +banshee_ext_outl(uint16_t addr, uint32_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; - // banshee_log("banshee_ext_outl: addr=%04x val=%08x %04x(%08x):%08x\n", addr, val, CS,cs,cpu_state.pc); +#if 0 + banshee_log("banshee_ext_outl: addr=%04x val=%08x %04x(%08x):%08x\n", addr, val, CS,cs,cpu_state.pc); +#endif switch (addr & 0xff) { case Init_pciInit0: @@ -698,7 +722,9 @@ banshee_ext_outl(uint16_t addr, uint32_t val, void *p) case Init_lfbMemoryConfig: banshee->lfbMemoryConfig = val; - // banshee_log("lfbMemoryConfig=%08x\n", val); +#if 0 + banshee_log("lfbMemoryConfig=%08x\n", val); +#endif voodoo->tile_base = (val & 0x1fff) << 12; voodoo->tile_stride = 1024 << ((val >> 13) & 7); voodoo->tile_stride_shift = 10 + ((val >> 13) & 7); @@ -764,7 +790,9 @@ banshee_ext_outl(uint16_t addr, uint32_t val, void *p) case Video_vidProcCfg: banshee->vidProcCfg = val; - // banshee_log("vidProcCfg=%08x\n", val); +#if 0 + banshee_log("vidProcCfg=%08x\n", val); +#endif banshee->overlay_pix_fmt = (val & VIDPROCCFG_OVERLAY_PIX_FORMAT_MASK) >> VIDPROCCFG_OVERLAY_PIX_FORMAT_SHIFT; svga->hwcursor.ena = val & VIDPROCCFG_HWCURSOR_ENA; svga->fullchange = changeframecount; @@ -797,7 +825,9 @@ banshee_ext_outl(uint16_t addr, uint32_t val, void *p) svga->hwcursor.addr = (banshee->hwCurPatAddr & 0xfffff0) + (svga->hwcursor.yoff * 16); svga->hwcursor.cur_xsize = 64; svga->hwcursor.cur_ysize = 64; - // banshee_log("hwCurLoc %08x %i\n", val, svga->hwcursor.y); +#if 0 + banshee_log("hwCurLoc %08x %i\n", val, svga->hwcursor.y); +#endif break; case Video_hwCurC0: banshee->hwCurC0 = val; @@ -808,7 +838,9 @@ banshee_ext_outl(uint16_t addr, uint32_t val, void *p) case Video_vidSerialParallelPort: banshee->vidSerialParallelPort = val; - // banshee_log("vidSerialParallelPort: write %08x %08x %04x(%08x):%08x\n", val, val & (VIDSERIAL_DDC_DCK_W | VIDSERIAL_DDC_DDA_W), CS,cs,cpu_state.pc); +#if 0 + banshee_log("vidSerialParallelPort: write %08x %08x %04x(%08x):%08x\n", val, val & (VIDSERIAL_DDC_DCK_W | VIDSERIAL_DDC_DDA_W), CS,cs,cpu_state.pc); +#endif i2c_gpio_set(banshee->i2c_ddc, !!(val & VIDSERIAL_DDC_DCK_W), !!(val & VIDSERIAL_DDC_DDA_W)); i2c_gpio_set(banshee->i2c, !!(val & VIDSERIAL_I2C_SCK_W), !!(val & VIDSERIAL_I2C_SDA_W)); break; @@ -836,16 +868,22 @@ banshee_ext_outl(uint16_t addr, uint32_t val, void *p) break; case Video_vidOverlayDudx: voodoo->overlay.vidOverlayDudx = val & VID_DUDX_MASK; - // banshee_log("vidOverlayDudx=%08x\n", val); +#if 0 + banshee_log("vidOverlayDudx=%08x\n", val); +#endif break; case Video_vidOverlayDudxOffsetSrcWidth: voodoo->overlay.vidOverlayDudxOffsetSrcWidth = val; voodoo->overlay.overlay_bytes = (val & OVERLAY_SRC_WIDTH_MASK) >> OVERLAY_SRC_WIDTH_SHIFT; - // banshee_log("vidOverlayDudxOffsetSrcWidth=%08x\n", val); +#if 0 + banshee_log("vidOverlayDudxOffsetSrcWidth=%08x\n", val); +#endif break; case Video_vidOverlayDvdy: voodoo->overlay.vidOverlayDvdy = val & VID_DVDY_MASK; - // banshee_log("vidOverlayDvdy=%08x\n", val); +#if 0 + banshee_log("vidOverlayDvdy=%08x\n", val); +#endif break; case Video_vidOverlayDvdyOffset: voodoo->overlay.vidOverlayDvdyOffset = val; @@ -853,26 +891,34 @@ banshee_ext_outl(uint16_t addr, uint32_t val, void *p) case Video_vidDesktopStartAddr: banshee->vidDesktopStartAddr = val & 0xffffff; - // banshee_log("vidDesktopStartAddr=%08x\n", val); +#if 0 + banshee_log("vidDesktopStartAddr=%08x\n", val); +#endif svga->fullchange = changeframecount; svga_recalctimings(svga); break; case Video_vidDesktopOverlayStride: banshee->vidDesktopOverlayStride = val; - // banshee_log("vidDesktopOverlayStride=%08x\n", val); +#if 0 + banshee_log("vidDesktopOverlayStride=%08x\n", val); +#endif svga->fullchange = changeframecount; svga_recalctimings(svga); break; - // default: - // fatal("bad banshee_ext_outl: addr=%04x val=%08x\n", addr, val); +#if 0 + default: + fatal("bad banshee_ext_outl: addr=%04x val=%08x\n", addr, val); +#endif } } static uint8_t -banshee_ext_in(uint16_t addr, void *p) +banshee_ext_in(uint16_t addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; - // svga_t *svga = &banshee->svga; + banshee_t *banshee = (banshee_t *) priv; +#if 0 + svga_t *svga = &banshee->svga; +#endif uint8_t ret = 0xff; switch (addr & 0xff) { @@ -881,7 +927,9 @@ banshee_ext_in(uint16_t addr, void *p) case Init_status + 2: case Init_status + 3: ret = (banshee_status(banshee) >> ((addr & 3) * 8)) & 0xff; - // banshee_log("Read status reg! %04x(%08x):%08x\n", CS, cs, cpu_state.pc); +#if 0 + banshee_log("Read status reg! %04x(%08x):%08x\n", CS, cs, cpu_state.pc); +#endif break; case 0xb0: @@ -932,7 +980,7 @@ banshee_ext_in(uint16_t addr, void *p) case 0xdd: case 0xde: case 0xdf: - ret = banshee_in((addr & 0xff) + 0x300, p); + ret = banshee_in((addr & 0xff) + 0x300, priv); break; default: @@ -979,15 +1027,17 @@ banshee_status(banshee_t *banshee) if (!voodoo->voodoo_busy) voodoo_wake_fifo_thread(voodoo); - // banshee_log("banshee_status: busy %i %i (%i %i) %i %i %i %04x(%08x):%08x %08x\n", busy, written, voodoo->cmd_written, voodoo->cmd_written_fifo, voodoo->cmd_read, voodoo->cmdfifo_depth_rd, voodoo->cmdfifo_depth_wr, CS,cs,cpu_state.pc, ret); +#if 0 + banshee_log("banshee_status: busy %i %i (%i %i) %i %i %i %04x(%08x):%08x %08x\n", busy, written, voodoo->cmd_written, voodoo->cmd_written_fifo, voodoo->cmd_read, voodoo->cmdfifo_depth_rd, voodoo->cmdfifo_depth_wr, CS,cs,cpu_state.pc, ret); +#endif return ret; } static uint32_t -banshee_ext_inl(uint16_t addr, void *p) +banshee_ext_inl(uint16_t addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; uint32_t ret = 0xffffffff; @@ -997,7 +1047,9 @@ banshee_ext_inl(uint16_t addr, void *p) switch (addr & 0xff) { case Init_status: ret = banshee_status(banshee); - // banshee_log("Read status reg! %04x(%08x):%08x\n", CS, cs, cpu_state.pc); +#if 0 + banshee_log("Read status reg! %04x(%08x):%08x\n", CS, cs, cpu_state.pc); +#endif break; case Init_pciInit0: ret = banshee->pciInit0; @@ -1090,7 +1142,9 @@ banshee_ext_inl(uint16_t addr, void *p) if (i2c_gpio_get_sda(banshee->i2c)) ret |= VIDSERIAL_I2C_SDA_R; } - // banshee_log("vidSerialParallelPort: read %08x %08x %04x(%08x):%08x\n", ret, ret & (VIDSERIAL_DDC_DCK_R | VIDSERIAL_DDC_DDA_R), CS,cs,cpu_state.pc); +#if 0 + banshee_log("vidSerialParallelPort: read %08x %08x %04x(%08x):%08x\n", ret, ret & (VIDSERIAL_DDC_DCK_R | VIDSERIAL_DDC_DDA_R), CS,cs,cpu_state.pc); +#endif break; case Video_vidScreenSize: @@ -1127,25 +1181,32 @@ banshee_ext_inl(uint16_t addr, void *p) break; } - // /*if (addr) */banshee_log("banshee_ext_inl: addr=%04x val=%08x\n", addr, ret); +#if 0 + if (addr) + banshee_log("banshee_ext_inl: addr=%04x val=%08x\n", addr, ret); +#endif return ret; } -static uint32_t banshee_reg_readl(uint32_t addr, void *p); +static uint32_t banshee_reg_readl(uint32_t addr, void *priv); static uint8_t -banshee_reg_read(uint32_t addr, void *p) +banshee_reg_read(uint32_t addr, void *priv) { - // banshee_log("banshee_reg_read: addr=%08x\n", addr); - return banshee_reg_readl(addr & ~3, p) >> (8 * (addr & 3)); +#if 0 + banshee_log("banshee_reg_read: addr=%08x\n", addr); +#endif + return banshee_reg_readl(addr & ~3, priv) >> (8 * (addr & 3)); } static uint16_t -banshee_reg_readw(uint32_t addr, void *p) +banshee_reg_readw(uint32_t addr, void *priv) { - // banshee_log("banshee_reg_readw: addr=%08x\n", addr); - return banshee_reg_readl(addr & ~3, p) >> (8 * (addr & 2)); +#if 0 + banshee_log("banshee_reg_readw: addr=%08x\n", addr); +#endif + return banshee_reg_readl(addr & ~3, priv) >> (8 * (addr & 2)); } static uint32_t @@ -1209,9 +1270,9 @@ banshee_cmd_read(banshee_t *banshee, uint32_t addr) } static uint32_t -banshee_reg_readl(uint32_t addr, void *p) +banshee_reg_readl(uint32_t addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; uint32_t ret = 0xffffffff; @@ -1360,26 +1421,33 @@ banshee_reg_readl(uint32_t addr, void *p) break; } - // /*if (addr != 0xe0000000) */banshee_log("banshee_reg_readl: addr=%08x ret=%08x %04x(%08x):%08x\n", addr, ret, CS,cs,cpu_state.pc); +#if 0 + if (addr != 0xe0000000) + banshee_log("banshee_reg_readl: addr=%08x ret=%08x %04x(%08x):%08x\n", addr, ret, CS,cs,cpu_state.pc); +#endif return ret; } static void -banshee_reg_write(uint32_t addr, uint8_t val, void *p) +banshee_reg_write(UNUSED(uint32_t addr), UNUSED(uint8_t val), UNUSED(void *priv)) { - // banshee_log("banshee_reg_writeb: addr=%08x val=%02x\n", addr, val); +#if 0 + banshee_log("banshee_reg_writeb: addr=%08x val=%02x\n", addr, val); +#endif } static void -banshee_reg_writew(uint32_t addr, uint16_t val, void *p) +banshee_reg_writew(uint32_t addr, uint16_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; cycles -= voodoo->write_time; - // banshee_log("banshee_reg_writew: addr=%08x val=%04x\n", addr, val); +#if 0 + banshee_log("banshee_reg_writew: addr=%08x val=%04x\n", addr, val); +#endif switch (addr & 0x1f00000) { case 0x1000000: case 0x1100000: @@ -1406,7 +1474,9 @@ static void banshee_cmd_write(banshee_t *banshee, uint32_t addr, uint32_t val) { voodoo_t *voodoo = banshee->voodoo; - // banshee_log("banshee_cmd_write: addr=%03x val=%08x\n", addr & 0x1fc, val); +#if 0 + banshee_log("banshee_cmd_write: addr=%03x val=%08x\n", addr & 0x1fc, val); +#endif switch (addr & 0x1fc) { case Agp_agpHostAddressLow: banshee->agpHostAddressLow = val; @@ -1431,7 +1501,9 @@ banshee_cmd_write(banshee_t *banshee, uint32_t addr, uint32_t val) case cmdBaseAddr0: voodoo->cmdfifo_base = (val & 0xfff) << 12; voodoo->cmdfifo_end = voodoo->cmdfifo_base + (((voodoo->cmdfifo_size & 0xff) + 1) << 12); - // banshee_log("cmdfifo_base=%08x cmdfifo_end=%08x %08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end, val); +#if 0 + banshee_log("cmdfifo_base=%08x cmdfifo_end=%08x %08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end, val); +#endif break; case cmdBaseSize0: @@ -1440,12 +1512,16 @@ banshee_cmd_write(banshee_t *banshee, uint32_t addr, uint32_t val) voodoo->cmdfifo_enabled = val & 0x100; if (!voodoo->cmdfifo_enabled) voodoo->cmdfifo_in_sub = 0; /*Not sure exactly when this should be reset*/ - // banshee_log("cmdfifo_base=%08x cmdfifo_end=%08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end); +#if 0 + banshee_log("cmdfifo_base=%08x cmdfifo_end=%08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end); +#endif break; - // voodoo->cmdfifo_end = ((val >> 16) & 0x3ff) << 12; - // banshee_log("CMDFIFO base=%08x end=%08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end); - // break; +#if 0 + voodoo->cmdfifo_end = ((val >> 16) & 0x3ff) << 12; + banshee_log("CMDFIFO base=%08x end=%08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end); + break; +#endif case cmdRdPtrL0: voodoo->cmdfifo_rp = val; @@ -1466,21 +1542,23 @@ banshee_cmd_write(banshee_t *banshee, uint32_t addr, uint32_t val) break; } - /* cmdBaseSize0 = 0x24, - cmdBump0 = 0x28, - cmdRdPtrL0 = 0x2c, - cmdRdPtrH0 = 0x30, - cmdAMin0 = 0x34, - cmdAMax0 = 0x3c, - cmdFifoDepth0 = 0x44, - cmdHoleCnt0 = 0x48 - }*/ +#if 0 + cmdBaseSize0 = 0x24, + cmdBump0 = 0x28, + cmdRdPtrL0 = 0x2c, + cmdRdPtrH0 = 0x30, + cmdAMin0 = 0x34, + cmdAMax0 = 0x3c, + cmdFifoDepth0 = 0x44, + cmdHoleCnt0 = 0x48 + } +#endif } static void -banshee_reg_writel(uint32_t addr, uint32_t val, void *p) +banshee_reg_writel(uint32_t addr, uint32_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; if (addr == voodoo->last_write_addr + 4) @@ -1489,7 +1567,9 @@ banshee_reg_writel(uint32_t addr, uint32_t val, void *p) cycles -= voodoo->write_time; voodoo->last_write_addr = addr; - // banshee_log("banshee_reg_writel: addr=%08x val=%08x\n", addr, val); +#if 0 + banshee_log("banshee_reg_writel: addr=%08x val=%08x\n", addr, val); +#endif switch (addr & 0x1f00000) { case 0x0000000: /*IO remap*/ @@ -1497,7 +1577,9 @@ banshee_reg_writel(uint32_t addr, uint32_t val, void *p) banshee_ext_outl(addr & 0xff, val, banshee); else banshee_cmd_write(banshee, addr, val); - // banshee_log("CMD!!! write %08x %08x\n", addr, val); +#if 0 + banshee_log("CMD!!! write %08x %08x\n", addr, val); +#endif break; case 0x0100000: /*2D registers*/ @@ -1515,7 +1597,9 @@ banshee_reg_writel(uint32_t addr, uint32_t val, void *p) switch (addr & 0x3fc) { case SST_intrCtrl: banshee->intrCtrl = val & 0x0030003f; - // banshee_log("intrCtrl=%08x\n", val); +#if 0 + banshee_log("intrCtrl=%08x\n", val); +#endif break; case SST_userIntrCMD: @@ -1527,7 +1611,9 @@ banshee_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo_queue_command(voodoo, (addr & 0x3fc) | FIFO_WRITEL_REG, val); if (!voodoo->voodoo_busy) voodoo_wake_fifo_threads(voodoo->set, voodoo); - // banshee_log("SST_swapbufferCMD write: %i %i\n", voodoo->cmd_written, voodoo->cmd_written_fifo); +#if 0 + banshee_log("SST_swapbufferCMD write: %i %i\n", voodoo->cmd_written, voodoo->cmd_written_fifo); +#endif break; case SST_triangleCMD: voodoo->cmd_written++; @@ -1558,7 +1644,9 @@ banshee_reg_writel(uint32_t addr, uint32_t val, void *p) thread_wait_mutex(voodoo->swap_mutex); voodoo->swap_count++; thread_release_mutex(voodoo->swap_mutex); - // voodoo->cmd_written++; +#if 0 + voodoo->cmd_written++; +#endif break; default: @@ -1595,9 +1683,9 @@ banshee_reg_writel(uint32_t addr, uint32_t val, void *p) } static uint8_t -banshee_read_linear(uint32_t addr, void *p) +banshee_read_linear(uint32_t addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; @@ -1608,34 +1696,39 @@ banshee_read_linear(uint32_t addr, void *p) } addr &= svga->decode_mask; if (addr >= voodoo->tile_base) { - int x, y; + int x; + int y; addr -= voodoo->tile_base; x = addr & (voodoo->tile_stride - 1); y = addr >> voodoo->tile_stride_shift; addr = voodoo->tile_base + (x & 127) + ((x >> 7) * 128 * 32) + ((y & 31) * 128) + (y >> 5) * voodoo->tile_x_real; - // banshee_log(" Tile rb %08x->%08x %i %i\n", old_addr, addr, x, y); +#if 0 + banshee_log(" Tile rb %08x->%08x %i %i\n", old_addr, addr, x, y); +#endif } if (addr >= svga->vram_max) return 0xff; cycles -= svga->monitor->mon_video_timing_read_b; - // banshee_log("read_linear: addr=%08x val=%02x\n", addr, svga->vram[addr & svga->vram_mask]); +#if 0 + banshee_log("read_linear: addr=%08x val=%02x\n", addr, svga->vram[addr & svga->vram_mask]); +#endif return svga->vram[addr & svga->vram_mask]; } static uint16_t -banshee_read_linear_w(uint32_t addr, void *p) +banshee_read_linear_w(uint32_t addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; if (addr & 1) - return banshee_read_linear(addr, p) | (banshee_read_linear(addr + 1, p) << 8); + return banshee_read_linear(addr, priv) | (banshee_read_linear(addr + 1, priv) << 8); cycles -= voodoo->read_time; if ((banshee->pci_regs[0x30] & 0x01) && addr >= banshee->bios_rom.mapping.base && addr < (banshee->bios_rom.mapping.base + banshee->bios_rom.sz)) { @@ -1643,34 +1736,39 @@ banshee_read_linear_w(uint32_t addr, void *p) } addr &= svga->decode_mask; if (addr >= voodoo->tile_base) { - int x, y; + int x; + int y; addr -= voodoo->tile_base; x = addr & (voodoo->tile_stride - 1); y = addr >> voodoo->tile_stride_shift; addr = voodoo->tile_base + (x & 127) + ((x >> 7) * 128 * 32) + ((y & 31) * 128) + (y >> 5) * voodoo->tile_x_real; - // banshee_log(" Tile rb %08x->%08x %i %i\n", old_addr, addr, x, y); +#if 0 + banshee_log(" Tile rb %08x->%08x %i %i\n", old_addr, addr, x, y); +#endif } if (addr >= svga->vram_max) return 0xff; cycles -= svga->monitor->mon_video_timing_read_w; - // banshee_log("read_linear: addr=%08x val=%02x\n", addr, svga->vram[addr & svga->vram_mask]); +#if 0 + banshee_log("read_linear: addr=%08x val=%02x\n", addr, svga->vram[addr & svga->vram_mask]); +#endif return *(uint16_t *) &svga->vram[addr & svga->vram_mask]; } static uint32_t -banshee_read_linear_l(uint32_t addr, void *p) +banshee_read_linear_l(uint32_t addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; if (addr & 3) - return banshee_read_linear_w(addr, p) | (banshee_read_linear_w(addr + 2, p) << 16); + return banshee_read_linear_w(addr, priv) | (banshee_read_linear_w(addr + 2, priv) << 16); cycles -= voodoo->read_time; @@ -1679,45 +1777,55 @@ banshee_read_linear_l(uint32_t addr, void *p) } addr &= svga->decode_mask; if (addr >= voodoo->tile_base) { - int x, y; + int x; + int y; addr -= voodoo->tile_base; x = addr & (voodoo->tile_stride - 1); y = addr >> voodoo->tile_stride_shift; addr = voodoo->tile_base + (x & 127) + ((x >> 7) * 128 * 32) + ((y & 31) * 128) + (y >> 5) * voodoo->tile_x_real; - // banshee_log(" Tile rb %08x->%08x %i %i\n", old_addr, addr, x, y); +#if 0 + banshee_log(" Tile rb %08x->%08x %i %i\n", old_addr, addr, x, y); +#endif } if (addr >= svga->vram_max) return 0xff; cycles -= svga->monitor->mon_video_timing_read_l; - // banshee_log("read_linear: addr=%08x val=%02x\n", addr, svga->vram[addr & svga->vram_mask]); +#if 0 + banshee_log("read_linear: addr=%08x val=%02x\n", addr, svga->vram[addr & svga->vram_mask]); +#endif return *(uint32_t *) &svga->vram[addr & svga->vram_mask]; } static void -banshee_write_linear(uint32_t addr, uint8_t val, void *p) +banshee_write_linear(uint32_t addr, uint8_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; cycles -= voodoo->write_time; - // banshee_log("write_linear: addr=%08x val=%02x\n", addr, val); +#if 0 + banshee_log("write_linear: addr=%08x val=%02x\n", addr, val); +#endif addr &= svga->decode_mask; if (addr >= voodoo->tile_base) { - int x, y; + int x; + int y; addr -= voodoo->tile_base; x = addr & (voodoo->tile_stride - 1); y = addr >> voodoo->tile_stride_shift; addr = voodoo->tile_base + (x & 127) + ((x >> 7) * 128 * 32) + ((y & 31) * 128) + (y >> 5) * voodoo->tile_x_real; - // banshee_log(" Tile b %08x->%08x %i %i\n", old_addr, addr, x, y); +#if 0 + banshee_log(" Tile b %08x->%08x %i %i\n", old_addr, addr, x, y); +#endif } if (addr >= svga->vram_max) return; @@ -1729,30 +1837,35 @@ banshee_write_linear(uint32_t addr, uint8_t val, void *p) } static void -banshee_write_linear_w(uint32_t addr, uint16_t val, void *p) +banshee_write_linear_w(uint32_t addr, uint16_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; if (addr & 1) { - banshee_write_linear(addr, val, p); - banshee_write_linear(addr + 1, val >> 8, p); + banshee_write_linear(addr, val, priv); + banshee_write_linear(addr + 1, val >> 8, priv); return; } cycles -= voodoo->write_time; - // banshee_log("write_linear: addr=%08x val=%02x\n", addr, val); +#if 0 + banshee_log("write_linear: addr=%08x val=%02x\n", addr, val); +#endif addr &= svga->decode_mask; if (addr >= voodoo->tile_base) { - int x, y; + int x; + int y; addr -= voodoo->tile_base; x = addr & (voodoo->tile_stride - 1); y = addr >> voodoo->tile_stride_shift; addr = voodoo->tile_base + (x & 127) + ((x >> 7) * 128 * 32) + ((y & 31) * 128) + (y >> 5) * voodoo->tile_x_real; - // banshee_log(" Tile b %08x->%08x %i %i\n", old_addr, addr, x, y); +#if 0 + banshee_log(" Tile b %08x->%08x %i %i\n", old_addr, addr, x, y); +#endif } if (addr >= svga->vram_max) return; @@ -1764,16 +1877,16 @@ banshee_write_linear_w(uint32_t addr, uint16_t val, void *p) } static void -banshee_write_linear_l(uint32_t addr, uint32_t val, void *p) +banshee_write_linear_l(uint32_t addr, uint32_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; svga_t *svga = &banshee->svga; int timing; if (addr & 3) { - banshee_write_linear_w(addr, val, p); - banshee_write_linear_w(addr + 2, val >> 16, p); + banshee_write_linear_w(addr, val, priv); + banshee_write_linear_w(addr + 2, val >> 16, priv); return; } @@ -1784,17 +1897,23 @@ banshee_write_linear_l(uint32_t addr, uint32_t val, void *p) cycles -= timing; voodoo->last_write_addr = addr; - // /*if (val) */banshee_log("write_linear_l: addr=%08x val=%08x %08x\n", addr, val, voodoo->tile_base); +#if 0 + if (val) + banshee_log("write_linear_l: addr=%08x val=%08x %08x\n", addr, val, voodoo->tile_base); +#endif addr &= svga->decode_mask; if (addr >= voodoo->tile_base) { - int x, y; + int x; + int y; addr -= voodoo->tile_base; x = addr & (voodoo->tile_stride - 1); y = addr >> voodoo->tile_stride_shift; addr = voodoo->tile_base + (x & 127) + ((x >> 7) * 128 * 32) + ((y & 31) * 128) + (y >> 5) * voodoo->tile_x_real; - // banshee_log(" Tile %08x->%08x->%08x->%08x %i %i tile_x=%i\n", old_addr, addr_off, addr2, addr, x, y, voodoo->tile_x_real); +#if 0 + banshee_log(" Tile %08x->%08x->%08x->%08x %i %i tile_x=%i\n", old_addr, addr_off, addr2, addr, x, y, voodoo->tile_x_real); +#endif } if (addr >= svga->vram_max) @@ -1805,26 +1924,34 @@ banshee_write_linear_l(uint32_t addr, uint32_t val, void *p) svga->changedvram[addr >> 12] = changeframecount; *(uint32_t *) &svga->vram[addr & svga->vram_mask] = val; if (voodoo->cmdfifo_enabled && addr >= voodoo->cmdfifo_base && addr < voodoo->cmdfifo_end) { - // banshee_log("CMDFIFO write %08x %08x old amin=%08x amax=%08x hlcnt=%i depth_wr=%i rp=%08x\n", addr, val, voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, voodoo->cmdfifo_holecount, voodoo->cmdfifo_depth_wr, voodoo->cmdfifo_rp); +#if 0 + banshee_log("CMDFIFO write %08x %08x old amin=%08x amax=%08x hlcnt=%i depth_wr=%i rp=%08x\n", addr, val, voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, voodoo->cmdfifo_holecount, voodoo->cmdfifo_depth_wr, voodoo->cmdfifo_rp); +#endif if (addr == voodoo->cmdfifo_base && !voodoo->cmdfifo_holecount) { - // if (voodoo->cmdfifo_holecount) - // fatal("CMDFIFO reset pointers while outstanding holes\n"); +#if 0 + if (voodoo->cmdfifo_holecount) + fatal("CMDFIFO reset pointers while outstanding holes\n"); +#endif /*Reset pointers*/ voodoo->cmdfifo_amin = voodoo->cmdfifo_base; voodoo->cmdfifo_amax = voodoo->cmdfifo_base; voodoo->cmdfifo_depth_wr++; voodoo_wake_fifo_thread(voodoo); } else if (voodoo->cmdfifo_holecount) { - // if ((addr <= voodoo->cmdfifo_amin && voodoo->cmdfifo_amin != -4) || addr >= voodoo->cmdfifo_amax) - // fatal("CMDFIFO holecount write outside of amin/amax - amin=%08x amax=%08x holecount=%i\n", voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, voodoo->cmdfifo_holecount); - // banshee_log("holecount %i\n", voodoo->cmdfifo_holecount); +#if 0 + if ((addr <= voodoo->cmdfifo_amin && voodoo->cmdfifo_amin != -4) || addr >= voodoo->cmdfifo_amax) + fatal("CMDFIFO holecount write outside of amin/amax - amin=%08x amax=%08x holecount=%i\n", voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, voodoo->cmdfifo_holecount); + banshee_log("holecount %i\n", voodoo->cmdfifo_holecount); +#endif voodoo->cmdfifo_holecount--; if (!voodoo->cmdfifo_holecount) { /*Filled in holes, resume normal operation*/ voodoo->cmdfifo_depth_wr += ((voodoo->cmdfifo_amax - voodoo->cmdfifo_amin) >> 2); voodoo->cmdfifo_amin = voodoo->cmdfifo_amax; voodoo_wake_fifo_thread(voodoo); - // banshee_log("hole filled! amin=%08x amax=%08x added %i words\n", voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, words_to_add); +#if 0 + banshee_log("hole filled! amin=%08x amax=%08x added %i words\n", voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, words_to_add); +#endif } } else if (addr == voodoo->cmdfifo_amax + 4) { /*In-order write*/ @@ -1838,11 +1965,15 @@ banshee_write_linear_l(uint32_t addr, uint32_t val, void *p) /*Reset back to start. Note that write is still out of order!*/ voodoo->cmdfifo_amin = voodoo->cmdfifo_base - 4; } - // else if (addr < voodoo->cmdfifo_amax) - // fatal("Out-of-order write really out of order\n"); +#if 0 + else if (addr < voodoo->cmdfifo_amax) + fatal("Out-of-order write really out of order\n"); +#endif voodoo->cmdfifo_amax = addr; voodoo->cmdfifo_holecount = ((voodoo->cmdfifo_amax - voodoo->cmdfifo_amin) >> 2) - 1; - // banshee_log("CMDFIFO out of order: amin=%08x amax=%08x holecount=%i\n", voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, voodoo->cmdfifo_holecount); +#if 0 + banshee_log("CMDFIFO out of order: amin=%08x amax=%08x holecount=%i\n", voodoo->cmdfifo_amin, voodoo->cmdfifo_amax, voodoo->cmdfifo_holecount); +#endif } } } @@ -1850,17 +1981,18 @@ banshee_write_linear_l(uint32_t addr, uint32_t val, void *p) void banshee_hwcursor_draw(svga_t *svga, int displine) { - banshee_t *banshee = (banshee_t *) svga->p; - int x, c; + banshee_t *banshee = (banshee_t *) svga->priv; + int x; int x_off; int xx; uint32_t col0 = banshee->hwCurC0; uint32_t col1 = banshee->hwCurC1; - uint8_t plane0[8], plane1[8]; + uint8_t plane0[8]; + uint8_t plane1[8]; - for (c = 0; c < 8; c++) + for (uint8_t c = 0; c < 8; c++) plane0[c] = svga->vram[svga->hwcursor_latch.addr + c]; - for (c = 0; c < 8; c++) + for (uint8_t c = 0; c < 8; c++) plane1[c] = svga->vram[svga->hwcursor_latch.addr + c + 8]; svga->hwcursor_latch.addr += 16; @@ -2054,10 +2186,14 @@ banshee_hwcursor_draw(svga_t *svga, int displine) void voodoo_generate_vb_filters(voodoo_t *voodoo, int fcr, int fcg) { - int g, h; - float difference, diffg; - float thiscol, thiscolg; - float clr, clg = 0; + int g; + int h; + float difference; + float diffg; + float thiscol; + float thiscolg; + float clr; + float clg = 0; float hack = 1.0f; // pre-clamping @@ -2129,8 +2265,8 @@ voodoo_generate_vb_filters(voodoo_t *voodoo, int fcr, int fcg) if (thiscolg > 255) thiscolg = 255; - vb_filter_bx_rb[g][h] = (thiscol); - vb_filter_bx_g[g][h] = (thiscolg); + vb_filter_bx_rb[g][h] = thiscol; + vb_filter_bx_g[g][h] = thiscolg; } float lined = g + 4; if (lined > 255) @@ -2145,8 +2281,10 @@ voodoo_generate_vb_filters(voodoo_t *voodoo, int fcr, int fcg) } /* 4x1 and 2x2 filter */ - // fcr *= 5; - // fcg *= 6; +#if 0 + fcr *= 5; + fcg *= 6; +#endif for (g = 0; g < 256; g++) // pixel 1 { @@ -2191,7 +2329,7 @@ voodoo_generate_vb_filters(voodoo_t *voodoo, int fcr, int fcg) static void banshee_overlay_draw(svga_t *svga, int displine) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; voodoo_t *voodoo = banshee->voodoo; uint32_t *p; int x; @@ -2211,9 +2349,11 @@ banshee_overlay_draw(svga_t *svga, int displine) if ((voodoo->overlay.src_y >> 20) < 2048) voodoo->dirty_line[voodoo->overlay.src_y >> 20] = 0; - // pclog("displine=%i addr=%08x %08x %08x %08x\n", displine, svga->overlay_latch.addr, src_addr, voodoo->overlay.vidOverlayDvdy, *(uint32_t *)src); - // if (src_addr >= 0x800000) - // fatal("overlay out of range!\n"); +#if 0 + pclog("displine=%i addr=%08x %08x %08x %08x\n", displine, svga->overlay_latch.addr, src_addr, voodoo->overlay.vidOverlayDvdy, *(uint32_t *)src); + if (src_addr >= 0x800000) + fatal("overlay out of range!\n"); +#endif p = &((uint32_t *) svga->monitor->target_buffer->line[displine])[svga->overlay_latch.x + svga->x_add]; if (banshee->voodoo->scrfilter && banshee->voodoo->scrfilterEnabled) @@ -2265,16 +2405,15 @@ banshee_overlay_draw(svga_t *svga, int displine) case VIDPROCCFG_FILTER_MODE_DITHER_4X4: if (banshee->voodoo->scrfilter && banshee->voodoo->scrfilterEnabled) { - uint8_t fil[64 * 3]; - uint8_t fil3[64 * 3]; + uint8_t fil[2048 * 3]; + uint8_t fil3[2048 * 3]; - assert(svga->overlay_latch.cur_xsize <= 64); if (banshee->vidProcCfg & VIDPROCCFG_H_SCALE_ENABLE) /* leilei HACK - don't know of real 4x1 hscaled behavior yet, double for now */ { for (x = 0; x < svga->overlay_latch.cur_xsize; x++) { - fil[x * 3] = ((banshee->overlay_buffer[0][src_x >> 20])); - fil[x * 3 + 1] = ((banshee->overlay_buffer[0][src_x >> 20] >> 8)); - fil[x * 3 + 2] = ((banshee->overlay_buffer[0][src_x >> 20] >> 16)); + fil[x * 3] = (banshee->overlay_buffer[0][src_x >> 20]); + fil[x * 3 + 1] = (banshee->overlay_buffer[0][src_x >> 20] >> 8); + fil[x * 3 + 2] = (banshee->overlay_buffer[0][src_x >> 20] >> 16); fil3[x * 3 + 0] = fil[x * 3 + 0]; fil3[x * 3 + 1] = fil[x * 3 + 1]; fil3[x * 3 + 2] = fil[x * 3 + 2]; @@ -2282,9 +2421,9 @@ banshee_overlay_draw(svga_t *svga, int displine) } } else { for (x = 0; x < svga->overlay_latch.cur_xsize; x++) { - fil[x * 3] = ((banshee->overlay_buffer[0][x])); - fil[x * 3 + 1] = ((banshee->overlay_buffer[0][x] >> 8)); - fil[x * 3 + 2] = ((banshee->overlay_buffer[0][x] >> 16)); + fil[x * 3] = (banshee->overlay_buffer[0][x]); + fil[x * 3 + 1] = (banshee->overlay_buffer[0][x] >> 8); + fil[x * 3 + 2] = (banshee->overlay_buffer[0][x] >> 16); fil3[x * 3 + 0] = fil[x * 3 + 0]; fil3[x * 3 + 1] = fil[x * 3 + 1]; fil3[x * 3 + 2] = fil[x * 3 + 2]; @@ -2299,24 +2438,24 @@ banshee_overlay_draw(svga_t *svga, int displine) } for (x = 1; x < svga->overlay_latch.cur_xsize; x++) { - fil3[(x) *3] = vb_filter_v1_rb[fil[x * 3]][fil[(x - 1) * 3]]; - fil3[(x) *3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; - fil3[(x) *3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; + fil3[x * 3] = vb_filter_v1_rb[fil[x * 3]][fil[(x - 1) * 3]]; + fil3[x * 3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; + fil3[x * 3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; } for (x = 1; x < svga->overlay_latch.cur_xsize; x++) { - fil[(x) *3] = vb_filter_v1_rb[fil[x * 3]][fil3[(x - 1) * 3]]; - fil[(x) *3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil3[(x - 1) * 3 + 1]]; - fil[(x) *3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil3[(x - 1) * 3 + 2]]; + fil[x * 3] = vb_filter_v1_rb[fil[x * 3]][fil3[(x - 1) * 3]]; + fil[x * 3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil3[(x - 1) * 3 + 1]]; + fil[x * 3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil3[(x - 1) * 3 + 2]]; } for (x = 1; x < svga->overlay_latch.cur_xsize; x++) { - fil3[(x) *3] = vb_filter_v1_rb[fil[x * 3]][fil[(x - 1) * 3]]; - fil3[(x) *3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; - fil3[(x) *3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; + fil3[x * 3] = vb_filter_v1_rb[fil[x * 3]][fil[(x - 1) * 3]]; + fil3[x * 3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; + fil3[x * 3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; } for (x = 0; x < svga->overlay_latch.cur_xsize; x++) { - fil[(x) *3] = vb_filter_v1_rb[fil[x * 3]][fil3[(x + 1) * 3]]; - fil[(x) *3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil3[(x + 1) * 3 + 1]]; - fil[(x) *3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil3[(x + 1) * 3 + 2]]; + fil[x * 3] = vb_filter_v1_rb[fil[x * 3]][fil3[(x + 1) * 3]]; + fil[x * 3 + 1] = vb_filter_v1_g[fil[x * 3 + 1]][fil3[(x + 1) * 3 + 1]]; + fil[x * 3 + 2] = vb_filter_v1_rb[fil[x * 3 + 2]][fil3[(x + 1) * 3 + 2]]; p[x] = (fil[x * 3 + 2] << 16) | (fil[x * 3 + 1] << 8) | fil[x * 3]; } } else /* filter disabled by emulator option */ @@ -2335,34 +2474,33 @@ banshee_overlay_draw(svga_t *svga, int displine) case VIDPROCCFG_FILTER_MODE_DITHER_2X2: if (banshee->voodoo->scrfilter && banshee->voodoo->scrfilterEnabled) { - uint8_t fil[64 * 3]; - uint8_t soak[64 * 3]; - uint8_t soak2[64 * 3]; + uint8_t fil[2048 * 3]; + uint8_t soak[2048 * 3]; + uint8_t soak2[2048 * 3]; - uint8_t samp1[64 * 3]; - uint8_t samp2[64 * 3]; - uint8_t samp3[64 * 3]; - uint8_t samp4[64 * 3]; + uint8_t samp1[2048 * 3]; + uint8_t samp2[2048 * 3]; + uint8_t samp3[2048 * 3]; + uint8_t samp4[2048 * 3]; - assert(svga->overlay_latch.cur_xsize <= 64); src = &svga->vram[src_addr2 & svga->vram_mask]; OVERLAY_SAMPLE(banshee->overlay_buffer[1]); for (x = 0; x < svga->overlay_latch.cur_xsize; x++) { - samp1[x * 3] = ((banshee->overlay_buffer[0][x])); - samp1[x * 3 + 1] = ((banshee->overlay_buffer[0][x] >> 8)); - samp1[x * 3 + 2] = ((banshee->overlay_buffer[0][x] >> 16)); + samp1[x * 3] = (banshee->overlay_buffer[0][x]); + samp1[x * 3 + 1] = (banshee->overlay_buffer[0][x] >> 8); + samp1[x * 3 + 2] = (banshee->overlay_buffer[0][x] >> 16); - samp2[x * 3 + 0] = ((banshee->overlay_buffer[0][x + 1])); - samp2[x * 3 + 1] = ((banshee->overlay_buffer[0][x + 1] >> 8)); - samp2[x * 3 + 2] = ((banshee->overlay_buffer[0][x + 1] >> 16)); + samp2[x * 3 + 0] = (banshee->overlay_buffer[0][x + 1]); + samp2[x * 3 + 1] = (banshee->overlay_buffer[0][x + 1] >> 8); + samp2[x * 3 + 2] = (banshee->overlay_buffer[0][x + 1] >> 16); - samp3[x * 3 + 0] = ((banshee->overlay_buffer[1][x])); - samp3[x * 3 + 1] = ((banshee->overlay_buffer[1][x] >> 8)); - samp3[x * 3 + 2] = ((banshee->overlay_buffer[1][x] >> 16)); + samp3[x * 3 + 0] = (banshee->overlay_buffer[1][x]); + samp3[x * 3 + 1] = (banshee->overlay_buffer[1][x] >> 8); + samp3[x * 3 + 2] = (banshee->overlay_buffer[1][x] >> 16); - samp4[x * 3 + 0] = ((banshee->overlay_buffer[1][x + 1])); - samp4[x * 3 + 1] = ((banshee->overlay_buffer[1][x + 1] >> 8)); - samp4[x * 3 + 2] = ((banshee->overlay_buffer[1][x + 1] >> 16)); + samp4[x * 3 + 0] = (banshee->overlay_buffer[1][x + 1]); + samp4[x * 3 + 1] = (banshee->overlay_buffer[1][x + 1] >> 8); + samp4[x * 3 + 2] = (banshee->overlay_buffer[1][x + 1] >> 16); /* sample two lines */ @@ -2430,9 +2568,9 @@ banshee_overlay_draw(svga_t *svga, int displine) } void -banshee_set_overlay_addr(void *p, uint32_t addr) +banshee_set_overlay_addr(void *priv, UNUSED(uint32_t addr)) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_t *voodoo = banshee->voodoo; banshee->svga.overlay.addr = banshee->voodoo->leftOverlayBuf & 0xfffffff; @@ -2443,7 +2581,7 @@ banshee_set_overlay_addr(void *p, uint32_t addr) static void banshee_vsync_callback(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; voodoo_t *voodoo = banshee->voodoo; voodoo->retrace_count++; @@ -2468,10 +2606,12 @@ banshee_vsync_callback(svga_t *svga) } static uint8_t -banshee_pci_read(int func, int addr, void *p) +banshee_pci_read(int func, int addr, void *priv) { - banshee_t *banshee = (banshee_t *) p; - // svga_t *svga = &banshee->svga; + banshee_t *banshee = (banshee_t *) priv; +#if 0 + svga_t *svga = &banshee->svga; +#endif uint8_t ret = 0; if (func) @@ -2664,19 +2804,25 @@ banshee_pci_read(int func, int addr, void *p) ret = banshee->pci_regs[0x67]; break; } - // banshee_log("%02X\n", ret); +#if 0 + banshee_log("%02X\n", ret); +#endif return ret; } static void -banshee_pci_write(int func, int addr, uint8_t val, void *p) +banshee_pci_write(int func, int addr, uint8_t val, void *priv) { - banshee_t *banshee = (banshee_t *) p; - // svga_t *svga = &banshee->svga; + banshee_t *banshee = (banshee_t *) priv; +#if 0 + svga_t *svga = &banshee->svga; +#endif if (func) return; - // banshee_log("Banshee write %08X %02X %04X:%08X\n", addr, val, CS, cpu_state.pc); +#if 0 + banshee_log("Banshee write %08X %02X %04X:%08X\n", addr, val, CS, cpu_state.pc); +#endif switch (addr) { case 0x00: case 0x01: @@ -2937,7 +3083,9 @@ banshee_init_common(const device_t *info, char *fn, int has_sgram, int type, int } if (!banshee->has_bios) - // mem_size = info->local; /* fixed size for on-board chips */ +#if 0 + mem_size = info->local; /* fixed size for on-board chips */ +#endif mem_size = device_get_config_int("memory"); /* MS-6168 / Bora Pro can do both 8 and 16 MB. */ else if (has_sgram) { if (banshee->type == TYPE_VELOCITY100) @@ -2984,7 +3132,9 @@ banshee_init_common(const device_t *info, char *fn, int has_sgram, int type, int banshee->svga.vblank_start = banshee_vblank_start; - // io_sethandler(0x03c0, 0x0020, banshee_in, NULL, NULL, banshee_out, NULL, NULL, banshee); +#if 0 + io_sethandler(0x03c0, 0x0020, banshee_in, NULL, NULL, banshee_out, NULL, NULL, banshee); +#endif banshee->svga.bpp = 8; banshee->svga.miscout = 1; @@ -3267,9 +3417,9 @@ velocity_200_available(void) } static void -banshee_close(void *p) +banshee_close(void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; voodoo_card_close(banshee->voodoo); svga_close(&banshee->svga); @@ -3281,17 +3431,17 @@ banshee_close(void *p) } static void -banshee_speed_changed(void *p) +banshee_speed_changed(void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; svga_recalctimings(&banshee->svga); } static void -banshee_force_redraw(void *p) +banshee_force_redraw(void *priv) { - banshee_t *banshee = (banshee_t *) p; + banshee_t *banshee = (banshee_t *) priv; banshee->svga.fullchange = changeframecount; } @@ -3307,7 +3457,7 @@ const device_t voodoo_banshee_device = { { .available = banshee_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sgram_config + .config = banshee_sgram_config }; const device_t creative_voodoo_banshee_device = { @@ -3321,7 +3471,7 @@ const device_t creative_voodoo_banshee_device = { { .available = creative_banshee_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_1000_device = { @@ -3335,7 +3485,7 @@ const device_t voodoo_3_1000_device = { { .available = v3_1000_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sgram_config + .config = banshee_sgram_config }; const device_t voodoo_3_1000_agp_device = { @@ -3349,7 +3499,7 @@ const device_t voodoo_3_1000_agp_device = { { .available = v3_1000_agp_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sgram_config + .config = banshee_sgram_config }; const device_t voodoo_3_2000_device = { @@ -3363,7 +3513,7 @@ const device_t voodoo_3_2000_device = { { .available = v3_2000_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_2000_agp_device = { @@ -3377,7 +3527,7 @@ const device_t voodoo_3_2000_agp_device = { { .available = v3_2000_agp_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_2000_agp_onboard_8m_device = { @@ -3391,7 +3541,7 @@ const device_t voodoo_3_2000_agp_onboard_8m_device = { { .available = NULL }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sgram_config + .config = banshee_sgram_config }; const device_t voodoo_3_3000_device = { @@ -3405,7 +3555,7 @@ const device_t voodoo_3_3000_device = { { .available = v3_3000_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_3000_agp_device = { @@ -3419,7 +3569,7 @@ const device_t voodoo_3_3000_agp_device = { { .available = v3_3000_agp_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_3500_agp_ntsc_device = { @@ -3433,7 +3583,7 @@ const device_t voodoo_3_3500_agp_ntsc_device = { { .available = v3_3500_agp_ntsc_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_3500_agp_pal_device = { @@ -3447,7 +3597,7 @@ const device_t voodoo_3_3500_agp_pal_device = { { .available = v3_3500_agp_pal_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t compaq_voodoo_3_3500_agp_device = { @@ -3461,7 +3611,7 @@ const device_t compaq_voodoo_3_3500_agp_device = { { .available = compaq_v3_3500_agp_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_3500_se_agp_device = { @@ -3475,7 +3625,7 @@ const device_t voodoo_3_3500_se_agp_device = { { .available = v3_3500_se_agp_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t voodoo_3_3500_si_agp_device = { @@ -3489,7 +3639,7 @@ const device_t voodoo_3_3500_si_agp_device = { { .available = v3_3500_si_agp_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t velocity_100_agp_device = { @@ -3503,7 +3653,7 @@ const device_t velocity_100_agp_device = { { .available = velocity_100_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sdram_config + .config = banshee_sdram_config }; const device_t velocity_200_agp_device = { @@ -3517,5 +3667,5 @@ const device_t velocity_200_agp_device = { { .available = velocity_200_available }, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, - banshee_sgram_config + .config = banshee_sgram_config }; diff --git a/src/video/vid_voodoo_banshee_blitter.c b/src/video/vid_voodoo_banshee_blitter.c index 98f439d79..f5009e0b8 100644 --- a/src/video/vid_voodoo_banshee_blitter.c +++ b/src/video/vid_voodoo_banshee_blitter.c @@ -127,18 +127,30 @@ colorkey(voodoo_t *voodoo, uint32_t src, int src_notdst, int color_format) case COLORKEY_16: { - int r = (src >> 11) & 0x1f, r_min = (min >> 11) & 0x1f, r_max = (max >> 11) & 0x1f; - int g = (src >> 5) & 0x3f, g_min = (min >> 5) & 0x3f, g_max = (max >> 5) & 0x3f; - int b = src & 0x1f, b_min = min & 0x1f, b_max = max & 0x1f; + int r = (src >> 11) & 0x1f; + int r_min = (min >> 11) & 0x1f; + int r_max = (max >> 11) & 0x1f; + int g = (src >> 5) & 0x3f; + int g_min = (min >> 5) & 0x3f; + int g_max = (max >> 5) & 0x3f; + int b = src & 0x1f; + int b_min = min & 0x1f; + int b_max = max & 0x1f; return (r >= r_min) && (r <= r_max) && (g >= g_min) && (g <= g_max) && (b >= b_min) && (b <= b_max); } case COLORKEY_32: { - int r = (src >> 16) & 0xff, r_min = (min >> 16) & 0xff, r_max = (max >> 16) & 0xff; - int g = (src >> 8) & 0xff, g_min = (min >> 8) & 0xff, g_max = (max >> 8) & 0xff; - int b = src & 0xff, b_min = min & 0xff, b_max = max & 0xff; + int r = (src >> 16) & 0xff; + int r_min = (min >> 16) & 0xff; + int r_max = (max >> 16) & 0xff; + int g = (src >> 8) & 0xff; + int g_min = (min >> 8) & 0xff; + int g_max = (max >> 8) & 0xff; + int b = src & 0xff; + int b_min = min & 0xff; + int b_max = max & 0xff; return (r >= r_min) && (r <= r_max) && (g >= g_min) && (g <= g_max) && (b >= b_min) && (b <= b_max); } @@ -195,7 +207,7 @@ get_addr(voodoo_t *voodoo, int x, int y, int src_notdst, uint32_t src_stride) } static void -PLOT(voodoo_t *voodoo, int x, int y, int pat_x, int pat_y, uint8_t pattern_mask, uint8_t rop, uint32_t src, int src_colorkey) +PLOT(voodoo_t *voodoo, int x, int y, int pat_x, int pat_y, uint8_t pattern_mask, UNUSED(uint8_t rop), uint32_t src, int src_colorkey) { switch (voodoo->banshee_blt.dstFormat & DST_FORMAT_COL_MASK) { case DST_FORMAT_COL_8_BPP: @@ -242,7 +254,7 @@ PLOT(voodoo_t *voodoo, int x, int y, int pat_x, int pat_y, uint8_t pattern_mask, } static void -PLOT_LINE(voodoo_t *voodoo, int x, int y, uint8_t rop, uint32_t pattern, int src_colorkey) +PLOT_LINE(voodoo_t *voodoo, int x, int y, UNUSED(uint8_t rop), uint32_t pattern, int src_colorkey) { switch (voodoo->banshee_blt.dstFormat & DST_FORMAT_COL_MASK) { case DST_FORMAT_COL_8_BPP: @@ -318,7 +330,9 @@ update_src_stride(voodoo_t *voodoo) voodoo->banshee_blt.src_stride_dest = voodoo->banshee_blt.src_stride; // voodoo->banshee_blt.srcFormat & SRC_FORMAT_STRIDE_MASK; voodoo->banshee_blt.host_data_size_src = (voodoo->banshee_blt.srcSizeX * bpp + 7) >> 3; voodoo->banshee_blt.host_data_size_dest = (voodoo->banshee_blt.dstSizeX * bpp + 7) >> 3; - // bansheeblt_log("Stride packing %08x %08x bpp=%i dstSizeX=%i\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest, bpp, voodoo->banshee_blt.dstSizeX); +#if 0 + bansheeblt_log("Stride packing %08x %08x bpp=%i dstSizeX=%i\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest, bpp, voodoo->banshee_blt.dstSizeX); +#endif break; case SRC_FORMAT_PACKING_BYTE: @@ -326,7 +340,9 @@ update_src_stride(voodoo_t *voodoo) voodoo->banshee_blt.src_stride_dest = (voodoo->banshee_blt.dstSizeX * bpp + 7) >> 3; voodoo->banshee_blt.host_data_size_src = voodoo->banshee_blt.src_stride_src; voodoo->banshee_blt.host_data_size_dest = voodoo->banshee_blt.src_stride_dest; - // bansheeblt_log("Byte packing %08x %08x\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#if 0 + bansheeblt_log("Byte packing %08x %08x\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#endif break; case SRC_FORMAT_PACKING_WORD: @@ -334,7 +350,9 @@ update_src_stride(voodoo_t *voodoo) voodoo->banshee_blt.src_stride_dest = ((voodoo->banshee_blt.dstSizeX * bpp + 15) >> 4) * 2; voodoo->banshee_blt.host_data_size_src = voodoo->banshee_blt.src_stride_src; voodoo->banshee_blt.host_data_size_dest = voodoo->banshee_blt.src_stride_dest; - // bansheeblt_log("Word packing %08x %08x\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#if 0 + bansheeblt_log("Word packing %08x %08x\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#endif break; case SRC_FORMAT_PACKING_DWORD: @@ -342,7 +360,9 @@ update_src_stride(voodoo_t *voodoo) voodoo->banshee_blt.src_stride_dest = ((voodoo->banshee_blt.dstSizeX * bpp + 31) >> 5) * 4; voodoo->banshee_blt.host_data_size_src = voodoo->banshee_blt.src_stride_src; voodoo->banshee_blt.host_data_size_dest = voodoo->banshee_blt.src_stride_dest; - // bansheeblt_log("Dword packing %08x %08x\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#if 0 + bansheeblt_log("Dword packing %08x %08x\n", voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#endif break; } } @@ -372,9 +392,11 @@ banshee_do_rectfill(voodoo_t *voodoo) int use_pattern_trans = (voodoo->banshee_blt.command & (COMMAND_PATTERN_MONO | COMMAND_TRANS_MONO)) == (COMMAND_PATTERN_MONO | COMMAND_TRANS_MONO); uint8_t rop = voodoo->banshee_blt.command >> 24; - // bansheeblt_log("banshee_do_rectfill: size=%i,%i dst=%i,%i\n", voodoo->banshee_blt.dstSizeX, voodoo->banshee_blt.dstSizeY, voodoo->banshee_blt.dstX, voodoo->banshee_blt.dstY); - // bansheeblt_log("clipping: %i,%i -> %i,%i\n", clip->x_min, clip->y_min, clip->x_max, clip->y_max); - // bansheeblt_log("colorFore=%08x\n", voodoo->banshee_blt.colorFore); +#if 0 + bansheeblt_log("banshee_do_rectfill: size=%i,%i dst=%i,%i\n", voodoo->banshee_blt.dstSizeX, voodoo->banshee_blt.dstSizeY, voodoo->banshee_blt.dstX, voodoo->banshee_blt.dstY); + bansheeblt_log("clipping: %i,%i -> %i,%i\n", clip->x_min, clip->y_min, clip->x_max, clip->y_max); + bansheeblt_log("colorFore=%08x\n", voodoo->banshee_blt.colorFore); +#endif for (voodoo->banshee_blt.cur_y = 0; voodoo->banshee_blt.cur_y < voodoo->banshee_blt.dstSizeY; voodoo->banshee_blt.cur_y++) { int dst_x = voodoo->banshee_blt.dstX; @@ -406,10 +428,16 @@ DECODE_YUYV422(uint32_t *buf, uint8_t *src) do { int wp = 0; - uint8_t y1, y2; - int8_t Cr, Cb; - int dR, dG, dB; - int r, g, b; + uint8_t y1; + uint8_t y2; + int8_t Cr; + int8_t Cb; + int dR; + int dG; + int dB; + int r; + int g; + int b; y1 = src[0]; Cr = src[1] - 0x80; @@ -444,10 +472,16 @@ DECODE_YUYV422_16BPP(uint16_t *buf, uint8_t *src) do { int wp = 0; - uint8_t y1, y2; - int8_t Cr, Cb; - int dR, dG, dB; - int r, g, b; + uint8_t y1; + uint8_t y2; + int8_t Cr; + int8_t Cb; + int dR; + int dG; + int dB; + int r; + int g; + int b; y1 = src[0]; Cr = src[1] - 0x80; @@ -504,7 +538,9 @@ do_screen_to_screen_line(voodoo_t *voodoo, uint8_t *src_p, int use_x_dir, int sr src_colorkey = COLORKEY_32; break; } - // bansheeblt_log("do_screen_to_screen_line: srcFormat=%08x dst=%08x\n", voodoo->banshee_blt.srcFormat, voodoo->banshee_blt.dstFormat); +#if 0 + bansheeblt_log("do_screen_to_screen_line: srcFormat=%08x dst=%08x\n", voodoo->banshee_blt.srcFormat, voodoo->banshee_blt.dstFormat); +#endif if ((voodoo->banshee_blt.srcFormat & SRC_FORMAT_COL_MASK) == (voodoo->banshee_blt.dstFormat & DST_FORMAT_COL_MASK)) { /*No conversion required*/ if (dst_y >= clip->y_min && dst_y < clip->y_max) { @@ -607,7 +643,9 @@ do_screen_to_screen_line(voodoo_t *voodoo, uint8_t *src_p, int use_x_dir, int sr src_data = (src_byte & (0x80 >> (src_x & 7))) ? voodoo->banshee_blt.colorFore : voodoo->banshee_blt.colorBack; if (voodoo->banshee_blt.command & COMMAND_TRANS_MONO) transparent = !(src_byte & (0x80 >> (src_x & 7))); - // bansheeblt_log(" 1bpp src_byte=%02x src_x=%i src_data=%x transparent=%i\n", src_byte, src_x, src_data, transparent); +#if 0 + bansheeblt_log(" 1bpp src_byte=%02x src_x=%i src_data=%x transparent=%i\n", src_byte, src_x, src_data, transparent); +#endif break; } case SRC_FORMAT_COL_8_BPP: @@ -723,12 +761,16 @@ do_screen_to_screen_line(voodoo_t *voodoo, uint8_t *src_p, int use_x_dir, int sr static void banshee_do_screen_to_screen_blt(voodoo_t *voodoo) { - // bansheeblt_log("screen_to_screen: %08x %08x %08x\n", voodoo->banshee_blt.srcFormat, voodoo->banshee_blt.src_stride, voodoo->banshee_blt.src_stride_dest); - // return; +#if 0 + bansheeblt_log("screen_to_screen: %08x %08x %08x\n", voodoo->banshee_blt.srcFormat, voodoo->banshee_blt.src_stride, voodoo->banshee_blt.src_stride_dest); + return; +#endif for (voodoo->banshee_blt.cur_y = 0; voodoo->banshee_blt.cur_y < voodoo->banshee_blt.dstSizeY; voodoo->banshee_blt.cur_y++) { uint32_t src_addr = get_addr(voodoo, 0, voodoo->banshee_blt.srcY, 1, voodoo->banshee_blt.src_stride_dest); - // if ((voodoo->banshee_blt.srcFormat & SRC_FORMAT_COL_MASK) == SRC_FORMAT_COL_1_BPP) - // bansheeblt_log(" srcY=%i src_addr=%08x\n", voodoo->banshee_blt.srcY, src_addr); +#if 0 + if ((voodoo->banshee_blt.srcFormat & SRC_FORMAT_COL_MASK) == SRC_FORMAT_COL_1_BPP) + bansheeblt_log(" srcY=%i src_addr=%08x\n", voodoo->banshee_blt.srcY, src_addr); +#endif do_screen_to_screen_line(voodoo, &voodoo->vram[src_addr], 1, voodoo->banshee_blt.srcX, voodoo->banshee_blt.srcBaseAddr_tiled); } end_command(voodoo); @@ -737,8 +779,10 @@ banshee_do_screen_to_screen_blt(voodoo_t *voodoo) static void banshee_do_host_to_screen_blt(voodoo_t *voodoo, int count, uint32_t data) { - // if (voodoo->banshee_blt.dstBaseAddr == 0xee5194) - // bansheeblt_log("banshee_do_host_to_screen_blt: data=%08x host_data_count=%i src_stride_dest=%i host_data_size_dest=%i\n", data, voodoo->banshee_blt.host_data_count, voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#if 0 + if (voodoo->banshee_blt.dstBaseAddr == 0xee5194) + bansheeblt_log("banshee_do_host_to_screen_blt: data=%08x host_data_count=%i src_stride_dest=%i host_data_size_dest=%i\n", data, voodoo->banshee_blt.host_data_count, voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#endif if (voodoo->banshee_blt.srcFormat & SRC_FORMAT_BYTE_SWIZZLE) data = (data >> 24) | ((data >> 8) & 0xff00) | ((data << 8) & 0xff0000) | (data << 24); @@ -756,7 +800,9 @@ banshee_do_host_to_screen_blt(voodoo_t *voodoo, int count, uint32_t data) *(uint32_t *) &voodoo->banshee_blt.host_data[voodoo->banshee_blt.host_data_count] = data; voodoo->banshee_blt.host_data_count += 4; if (voodoo->banshee_blt.host_data_count >= last_byte) { - // bansheeblt_log(" %i %i srcX=%i srcFormat=%08x\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY, voodoo->banshee_blt.srcX); +#if 0 + bansheeblt_log(" %i %i srcX=%i srcFormat=%08x\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY, voodoo->banshee_blt.srcX); +#endif if (voodoo->banshee_blt.cur_y < voodoo->banshee_blt.dstSizeY) { if ((voodoo->banshee_blt.srcFormat & SRC_FORMAT_COL_MASK) == SRC_FORMAT_COL_1_BPP) do_screen_to_screen_line(voodoo, &voodoo->banshee_blt.host_data[(voodoo->banshee_blt.srcX >> 3) & 3], 0, voodoo->banshee_blt.srcX & 7, 0); @@ -780,7 +826,9 @@ banshee_do_host_to_screen_blt(voodoo_t *voodoo, int count, uint32_t data) while (voodoo->banshee_blt.host_data_count >= voodoo->banshee_blt.src_stride_dest) { voodoo->banshee_blt.host_data_count -= voodoo->banshee_blt.src_stride_dest; - // bansheeblt_log(" %i %i\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY); +#if 0 + bansheeblt_log(" %i %i\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY); +#endif if (voodoo->banshee_blt.cur_y < voodoo->banshee_blt.dstSizeY) { do_screen_to_screen_line(voodoo, voodoo->banshee_blt.host_data, 0, 0, 0); voodoo->banshee_blt.cur_y++; @@ -789,7 +837,9 @@ banshee_do_host_to_screen_blt(voodoo_t *voodoo, int count, uint32_t data) } if (voodoo->banshee_blt.host_data_count) { - // bansheeblt_log(" remaining=%i\n", voodoo->banshee_blt.host_data_count); +#if 0 + bansheeblt_log(" remaining=%i\n", voodoo->banshee_blt.host_data_count); +#endif *(uint32_t *) &voodoo->banshee_blt.host_data[0] = data >> (4 - voodoo->banshee_blt.host_data_count) * 8; } } @@ -800,26 +850,34 @@ static void do_screen_to_screen_stretch_line(voodoo_t *voodoo, uint8_t *src_p, int src_x, int *src_y) { clip_t *clip = &voodoo->banshee_blt.clip[(voodoo->banshee_blt.command & COMMAND_CLIP_SEL) ? 1 : 0]; - // int src_y = voodoo->banshee_blt.srcY; +#if 0 + int src_y = voodoo->banshee_blt.srcY; +#endif int dst_y = voodoo->banshee_blt.dstY; int pat_y = (voodoo->banshee_blt.commandExtra & CMDEXTRA_FORCE_PAT_ROW0) ? 0 : (voodoo->banshee_blt.patoff_y + voodoo->banshee_blt.dstY); uint8_t *pattern_mono = (uint8_t *) voodoo->banshee_blt.colorPattern; int use_pattern_trans = (voodoo->banshee_blt.command & (COMMAND_PATTERN_MONO | COMMAND_TRANS_MONO)) == (COMMAND_PATTERN_MONO | COMMAND_TRANS_MONO); uint32_t *colorPattern = voodoo->banshee_blt.colorPattern; - // int error_y = voodoo->banshee_blt.dstSizeY / 2; +#if 0 + int error_y = voodoo->banshee_blt.dstSizeY / 2; - /* bansheeblt_log("banshee_do_screen_to_screen_stretch_blt:\n"); - bansheeblt_log(" srcXY=%i,%i srcsizeXY=%i,%i\n", voodoo->banshee_blt.srcX, voodoo->banshee_blt.srcY, voodoo->banshee_blt.srcSizeX, voodoo->banshee_blt.srcSizeY); - bansheeblt_log(" dstXY=%i,%i dstsizeXY=%i,%i\n", voodoo->banshee_blt.dstX, voodoo->banshee_blt.dstY, voodoo->banshee_blt.dstSizeX, voodoo->banshee_blt.dstSizeY);*/ + bansheeblt_log("banshee_do_screen_to_screen_stretch_blt:\n"); + bansheeblt_log(" srcXY=%i,%i srcsizeXY=%i,%i\n", voodoo->banshee_blt.srcX, voodoo->banshee_blt.srcY, voodoo->banshee_blt.srcSizeX, voodoo->banshee_blt.srcSizeY); + bansheeblt_log(" dstXY=%i,%i dstsizeXY=%i,%i\n", voodoo->banshee_blt.dstX, voodoo->banshee_blt.dstY, voodoo->banshee_blt.dstSizeX, voodoo->banshee_blt.dstSizeY);*/ +#endif if (dst_y >= clip->y_min && dst_y < clip->y_max) { - // int src_x = voodoo->banshee_blt.srcX; +#if 0 + int src_x = voodoo->banshee_blt.srcX; +#endif int dst_x = voodoo->banshee_blt.dstX; int pat_x = voodoo->banshee_blt.patoff_x + voodoo->banshee_blt.dstX; uint8_t pattern_mask = pattern_mono[pat_y & 7]; int error_x = voodoo->banshee_blt.dstSizeX / 2; - // bansheeblt_log(" Plot dest line %03i : src line %03i\n", dst_y, src_y); +#if 0 + bansheeblt_log(" Plot dest line %03i : src line %03i\n", dst_y, src_y); +#endif for (voodoo->banshee_blt.cur_x = 0; voodoo->banshee_blt.cur_x < voodoo->banshee_blt.dstSizeX; voodoo->banshee_blt.cur_x++) { int pattern_trans = use_pattern_trans ? (pattern_mask & (1 << (7 - (pat_x & 7)))) : 1; @@ -845,7 +903,9 @@ do_screen_to_screen_stretch_line(voodoo_t *voodoo, uint8_t *src_p, int src_x, in uint32_t pattern = (voodoo->banshee_blt.command & COMMAND_PATTERN_MONO) ? ((pattern_mask & (1 << (7 - (pat_x & 7)))) ? voodoo->banshee_blt.colorFore : voodoo->banshee_blt.colorBack) : colorPattern[(pat_x & 7) + (pat_y & 7) * 8]; *(uint16_t *) &voodoo->vram[dst_addr] = MIX(voodoo, dest, src, pattern, COLORKEY_16, COLORKEY_16); - // bansheeblt_log("%i,%i : sdp=%02x,%02x,%02x res=%02x\n", voodoo->banshee_blt.cur_x, voodoo->banshee_blt.cur_y, src, dest, pattern, *(uint16_t *)&voodoo->vram[dst_addr]); +#if 0 + bansheeblt_log("%i,%i : sdp=%02x,%02x,%02x res=%02x\n", voodoo->banshee_blt.cur_x, voodoo->banshee_blt.cur_y, src, dest, pattern, *(uint16_t *)&voodoo->vram[dst_addr]); +#endif voodoo->changedvram[dst_addr >> 12] = changeframecount; break; } @@ -857,7 +917,9 @@ do_screen_to_screen_stretch_line(voodoo_t *voodoo, uint8_t *src_p, int src_x, in uint32_t pattern = (voodoo->banshee_blt.command & COMMAND_PATTERN_MONO) ? ((pattern_mask & (1 << (7 - (pat_x & 7)))) ? voodoo->banshee_blt.colorFore : voodoo->banshee_blt.colorBack) : colorPattern[(pat_x & 7) + (pat_y & 7) * 8]; *(uint32_t *) &voodoo->vram[dst_addr] = (MIX(voodoo, dest, src, pattern, COLORKEY_32, COLORKEY_32) & 0xffffff) | (*(uint32_t *) &voodoo->vram[dst_addr] & 0xff000000); - // bansheeblt_log("%i,%i : sdp=%02x,%02x,%02x res=%02x\n", voodoo->banshee_blt.cur_x, voodoo->banshee_blt.cur_y, src, dest, pattern, voodoo->vram[dst_addr]); +#if 0 + bansheeblt_log("%i,%i : sdp=%02x,%02x,%02x res=%02x\n", voodoo->banshee_blt.cur_x, voodoo->banshee_blt.cur_y, src, dest, pattern, voodoo->vram[dst_addr]); +#endif voodoo->changedvram[dst_addr >> 12] = changeframecount; break; } @@ -869,7 +931,9 @@ do_screen_to_screen_stretch_line(voodoo_t *voodoo, uint8_t *src_p, int src_x, in uint32_t pattern = (voodoo->banshee_blt.command & COMMAND_PATTERN_MONO) ? ((pattern_mask & (1 << (7 - (pat_x & 7)))) ? voodoo->banshee_blt.colorFore : voodoo->banshee_blt.colorBack) : colorPattern[(pat_x & 7) + (pat_y & 7) * 8]; *(uint32_t *) &voodoo->vram[dst_addr] = MIX(voodoo, dest, src, pattern, COLORKEY_32, COLORKEY_32); - // bansheeblt_log("%i,%i : sdp=%02x,%02x,%02x res=%02x\n", voodoo->banshee_blt.cur_x, voodoo->banshee_blt.cur_y, src, dest, pattern, voodoo->vram[dst_addr]); +#if 0 + bansheeblt_log("%i,%i : sdp=%02x,%02x,%02x res=%02x\n", voodoo->banshee_blt.cur_x, voodoo->banshee_blt.cur_y, src, dest, pattern, voodoo->vram[dst_addr]); +#endif voodoo->changedvram[dst_addr >> 12] = changeframecount; break; } @@ -893,30 +957,39 @@ do_screen_to_screen_stretch_line(voodoo_t *voodoo, uint8_t *src_p, int src_x, in (*src_y) += (voodoo->banshee_blt.command & COMMAND_DY) ? -1 : 1; } voodoo->banshee_blt.dstY += (voodoo->banshee_blt.command & COMMAND_DY) ? -1 : 1; - // pat_y += (voodoo->banshee_blt.command & COMMAND_DY) ? -1 : 1; +#if 0 + pat_y += (voodoo->banshee_blt.command & COMMAND_DY) ? -1 : 1; +#endif + } static void banshee_do_screen_to_screen_stretch_blt(voodoo_t *voodoo) { - // bansheeblt_log("screen_to_screen: %08x %08x %08x\n", voodoo->banshee_blt.srcFormat, voodoo->banshee_blt.src_stride, voodoo->banshee_blt.src_stride_dest); - // return; +#if 0 + bansheeblt_log("screen_to_screen: %08x %08x %08x\n", voodoo->banshee_blt.srcFormat, voodoo->banshee_blt.src_stride, voodoo->banshee_blt.src_stride_dest); + return; +#endif for (voodoo->banshee_blt.cur_y = 0; voodoo->banshee_blt.cur_y < voodoo->banshee_blt.dstSizeY; voodoo->banshee_blt.cur_y++) { uint32_t src_addr = get_addr(voodoo, 0, voodoo->banshee_blt.srcY, 1, voodoo->banshee_blt.src_stride_src); //(voodoo->banshee_blt.srcBaseAddr + voodoo->banshee_blt.srcY*voodoo->banshee_blt.src_stride_src) & voodoo->fb_mask; - // bansheeblt_log("scale_blit %i %08x %08x\n", voodoo->banshee_blt.cur_y, src_addr, voodoo->banshee_blt.command); - // if ((voodoo->banshee_blt.srcFormat & SRC_FORMAT_COL_MASK) == SRC_FORMAT_COL_1_BPP) - // bansheeblt_log(" srcY=%i src_addr=%08x\n", voodoo->banshee_blt.srcY, src_addr); +#if 0 + + bansheeblt_log("scale_blit %i %08x %08x\n", voodoo->banshee_blt.cur_y, src_addr, voodoo->banshee_blt.command); + if ((voodoo->banshee_blt.srcFormat & SRC_FORMAT_COL_MASK) == SRC_FORMAT_COL_1_BPP) + bansheeblt_log(" srcY=%i src_addr=%08x\n", voodoo->banshee_blt.srcY, src_addr); +#endif do_screen_to_screen_stretch_line(voodoo, &voodoo->vram[src_addr], voodoo->banshee_blt.srcX, &voodoo->banshee_blt.srcY); } end_command(voodoo); } static void -banshee_do_host_to_screen_stretch_blt(voodoo_t *voodoo, int count, uint32_t data) +banshee_do_host_to_screen_stretch_blt(voodoo_t *voodoo, UNUSED(int count), uint32_t data) { - // if (voodoo->banshee_blt.dstBaseAddr == 0xee5194) - // bansheeblt_log("banshee_do_host_to_screen_blt: data=%08x host_data_count=%i src_stride_dest=%i host_data_size_dest=%i\n", data, voodoo->banshee_blt.host_data_count, voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); - +#if 0 + if (voodoo->banshee_blt.dstBaseAddr == 0xee5194) + bansheeblt_log("banshee_do_host_to_screen_blt: data=%08x host_data_count=%i src_stride_dest=%i host_data_size_dest=%i\n", data, voodoo->banshee_blt.host_data_count, voodoo->banshee_blt.src_stride_dest, voodoo->banshee_blt.host_data_size_dest); +#endif if (voodoo->banshee_blt.srcFormat & SRC_FORMAT_BYTE_SWIZZLE) data = (data >> 24) | ((data >> 8) & 0xff00) | ((data << 8) & 0xff0000) | (data << 24); if (voodoo->banshee_blt.srcFormat & SRC_FORMAT_WORD_SWIZZLE) @@ -928,7 +1001,9 @@ banshee_do_host_to_screen_stretch_blt(voodoo_t *voodoo, int count, uint32_t data *(uint32_t *) &voodoo->banshee_blt.host_data[voodoo->banshee_blt.host_data_count] = data; voodoo->banshee_blt.host_data_count += 4; if (voodoo->banshee_blt.host_data_count >= last_byte) { - // bansheeblt_log(" %i %i srcX=%i srcFormat=%08x\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY, voodoo->banshee_blt.srcX); +#if 0 + bansheeblt_log(" %i %i srcX=%i srcFormat=%08x\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY, voodoo->banshee_blt.srcX); +#endif if (voodoo->banshee_blt.cur_y < voodoo->banshee_blt.dstSizeY) { if ((voodoo->banshee_blt.srcFormat & SRC_FORMAT_COL_MASK) == SRC_FORMAT_COL_1_BPP) do_screen_to_screen_stretch_line(voodoo, &voodoo->banshee_blt.host_data[(voodoo->banshee_blt.srcX >> 3) & 3], voodoo->banshee_blt.srcX & 7, NULL); @@ -952,7 +1027,9 @@ banshee_do_host_to_screen_stretch_blt(voodoo_t *voodoo, int count, uint32_t data while (voodoo->banshee_blt.host_data_count >= voodoo->banshee_blt.src_stride_src) { voodoo->banshee_blt.host_data_count -= voodoo->banshee_blt.src_stride_src; - // bansheeblt_log(" %i %i\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY); +#if 0 + bansheeblt_log(" %i %i\n", voodoo->banshee_blt.cur_y, voodoo->banshee_blt.dstSizeY); +#endif if (voodoo->banshee_blt.cur_y < voodoo->banshee_blt.dstSizeY) { do_screen_to_screen_stretch_line(voodoo, voodoo->banshee_blt.host_data, 0, NULL); voodoo->banshee_blt.cur_y++; @@ -961,7 +1038,9 @@ banshee_do_host_to_screen_stretch_blt(voodoo_t *voodoo, int count, uint32_t data } if (voodoo->banshee_blt.host_data_count) { - // bansheeblt_log(" remaining=%i\n", voodoo->banshee_blt.host_data_count); +#if 0 + bansheeblt_log(" remaining=%i\n", voodoo->banshee_blt.host_data_count); +#endif *(uint32_t *) &voodoo->banshee_blt.host_data[0] = data >> (4 - voodoo->banshee_blt.host_data_count) * 8; } } @@ -1071,8 +1150,9 @@ banshee_polyfill_continue(voodoo_t *voodoo, uint32_t data) int y = MAX(voodoo->banshee_blt.ly[0], voodoo->banshee_blt.ry[0]); int y_end; - // bansheeblt_log("Polyfill : data %08x\n", data); - +#if 0 + bansheeblt_log("Polyfill : data %08x\n", data); +#endif /*if r1.y>=l1.y, next vertex is left*/ if (voodoo->banshee_blt.ry[1] >= voodoo->banshee_blt.ly[1]) { voodoo->banshee_blt.lx[1] = ((int32_t) (data << 19)) >> 19; @@ -1090,21 +1170,26 @@ banshee_polyfill_continue(voodoo_t *voodoo, uint32_t data) voodoo->banshee_blt.error[1] = voodoo->banshee_blt.dy[1] / 2; } - /* bansheeblt_log(" verts now : %03i,%03i %03i,%03i\n", voodoo->banshee_blt.lx[0], voodoo->banshee_blt.ly[0], voodoo->banshee_blt.rx[0], voodoo->banshee_blt.ry[0]); - bansheeblt_log(" %03i,%03i %03i,%03i\n", voodoo->banshee_blt.lx[1], voodoo->banshee_blt.ly[1], voodoo->banshee_blt.rx[1], voodoo->banshee_blt.ry[1]); - bansheeblt_log(" left dx=%i dy=%i x_inc=%i error=%i\n", voodoo->banshee_blt.dx[0],voodoo->banshee_blt.dy[0],voodoo->banshee_blt.x_inc[0],voodoo->banshee_blt.error[0]); - bansheeblt_log(" right dx=%i dy=%i x_inc=%i error=%i\n", voodoo->banshee_blt.dx[1],voodoo->banshee_blt.dy[1],voodoo->banshee_blt.x_inc[1],voodoo->banshee_blt.error[1]);*/ +#if 0 + bansheeblt_log(" verts now : %03i,%03i %03i,%03i\n", voodoo->banshee_blt.lx[0], voodoo->banshee_blt.ly[0], voodoo->banshee_blt.rx[0], voodoo->banshee_blt.ry[0]); + bansheeblt_log(" %03i,%03i %03i,%03i\n", voodoo->banshee_blt.lx[1], voodoo->banshee_blt.ly[1], voodoo->banshee_blt.rx[1], voodoo->banshee_blt.ry[1]); + bansheeblt_log(" left dx=%i dy=%i x_inc=%i error=%i\n", voodoo->banshee_blt.dx[0],voodoo->banshee_blt.dy[0],voodoo->banshee_blt.x_inc[0],voodoo->banshee_blt.error[0]); + bansheeblt_log(" right dx=%i dy=%i x_inc=%i error=%i\n", voodoo->banshee_blt.dx[1],voodoo->banshee_blt.dy[1],voodoo->banshee_blt.x_inc[1],voodoo->banshee_blt.error[1]); +#endif y_end = MIN(voodoo->banshee_blt.ly[1], voodoo->banshee_blt.ry[1]); - // bansheeblt_log("Polyfill : draw spans from %i-%i\n", y, y_end); +#if 0 + bansheeblt_log("Polyfill : draw spans from %i-%i\n", y, y_end); +#endif for (; y < y_end; y++) { - // bansheeblt_log(" %i: %i %i\n", y, voodoo->banshee_blt.lx_cur, voodoo->banshee_blt.rx_cur); +#if 0 + bansheeblt_log(" %i: %i %i\n", y, voodoo->banshee_blt.lx_cur, voodoo->banshee_blt.rx_cur); +#endif /*Draw span from lx_cur to rx_cur*/ if (y >= clip->y_min && y < clip->y_max) { int pat_y = (voodoo->banshee_blt.commandExtra & CMDEXTRA_FORCE_PAT_ROW0) ? 0 : (voodoo->banshee_blt.patoff_y + y); uint8_t pattern_mask = pattern_mono[pat_y & 7]; - int x; - for (x = voodoo->banshee_blt.lx_cur; x < voodoo->banshee_blt.rx_cur; x++) { + for (int x = voodoo->banshee_blt.lx_cur; x < voodoo->banshee_blt.rx_cur; x++) { int pat_x = voodoo->banshee_blt.patoff_x + x; int pattern_trans = use_pattern_trans ? (pattern_mask & (1 << (7 - (pat_x & 7)))) : 1; @@ -1182,7 +1267,11 @@ banshee_do_2d_blit(voodoo_t *voodoo, int count, uint32_t data) void voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) { - // /*if ((addr & 0x1fc) != 0x80) */bansheeblt_log("2D reg write %03x %08x\n", addr & 0x1fc, val); +#if 0 + if ((addr & 0x1fc) != 0x80) + bansheeblt_log("2D reg write %03x %08x\n", addr & 0x1fc, val); +#endif + switch (addr & 0x1fc) { case 0x08: voodoo->banshee_blt.clip0Min = val; @@ -1201,7 +1290,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) voodoo->banshee_blt.dst_stride = (voodoo->banshee_blt.dstFormat & DST_FORMAT_STRIDE_MASK) * 128 * 32; else voodoo->banshee_blt.dst_stride = voodoo->banshee_blt.dstFormat & DST_FORMAT_STRIDE_MASK; - // bansheeblt_log("dstBaseAddr=%08x\n", val); +#if 0 + bansheeblt_log("dstBaseAddr=%08x\n", val); +#endif break; case 0x14: voodoo->banshee_blt.dstFormat = val; @@ -1209,7 +1300,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) voodoo->banshee_blt.dst_stride = (voodoo->banshee_blt.dstFormat & DST_FORMAT_STRIDE_MASK) * 128 * 32; else voodoo->banshee_blt.dst_stride = voodoo->banshee_blt.dstFormat & DST_FORMAT_STRIDE_MASK; - // bansheeblt_log("dstFormat=%08x\n", val); +#if 0 + bansheeblt_log("dstFormat=%08x\n", val); +#endif break; case 0x18: @@ -1239,7 +1332,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) voodoo->banshee_blt.rops[1] = val & 0xff; voodoo->banshee_blt.rops[2] = (val >> 8) & 0xff; voodoo->banshee_blt.rops[3] = (val >> 16) & 0xff; - // bansheeblt_log("rop=%08x\n", val); +#if 0 + bansheeblt_log("rop=%08x\n", val); +#endif break; case 0x34: voodoo->banshee_blt.srcBaseAddr = val & 0xffffff; @@ -1249,11 +1344,15 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) else voodoo->banshee_blt.src_stride = voodoo->banshee_blt.srcFormat & SRC_FORMAT_STRIDE_MASK; update_src_stride(voodoo); - // bansheeblt_log("srcBaseAddr=%08x\n", val); +#if 0 + bansheeblt_log("srcBaseAddr=%08x\n", val); +#endif break; case 0x38: voodoo->banshee_blt.commandExtra = val; - // bansheeblt_log("commandExtra=%08x\n", val); +#if 0 + bansheeblt_log("commandExtra=%08x\n", val); +#endif break; case 0x3c: voodoo->banshee_blt.lineStipple = val; @@ -1267,7 +1366,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) break; case 0x44: voodoo->banshee_blt.colorPattern[0] = val; - // bansheeblt_log("colorPattern0=%08x\n", val); +#if 0 + bansheeblt_log("colorPattern0=%08x\n", val); +#endif voodoo->banshee_blt.colorPattern24[0] = val & 0xffffff; voodoo->banshee_blt.colorPattern24[1] = (voodoo->banshee_blt.colorPattern24[1] & 0xffff00) | (val >> 24); voodoo->banshee_blt.colorPattern16[0] = val & 0xffff; @@ -1279,7 +1380,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) break; case 0x48: voodoo->banshee_blt.colorPattern[1] = val; - // bansheeblt_log("colorPattern1=%08x\n", val); +#if 0 + bansheeblt_log("colorPattern1=%08x\n", val); +#endif voodoo->banshee_blt.colorPattern24[1] = (voodoo->banshee_blt.colorPattern24[1] & 0xff) | ((val & 0xffff) << 8); voodoo->banshee_blt.colorPattern24[2] = (voodoo->banshee_blt.colorPattern24[2] & 0xff0000) | (val >> 16); voodoo->banshee_blt.colorPattern16[2] = val & 0xffff; @@ -1325,21 +1428,27 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) voodoo->banshee_blt.src_bpp = 16; break; } - // bansheeblt_log("srcFormat=%08x\n", val); +#if 0 + bansheeblt_log("srcFormat=%08x\n", val); +#endif break; case 0x58: voodoo->banshee_blt.srcSize = val; voodoo->banshee_blt.srcSizeX = voodoo->banshee_blt.srcSize & 0x1fff; voodoo->banshee_blt.srcSizeY = (voodoo->banshee_blt.srcSize >> 16) & 0x1fff; update_src_stride(voodoo); - // bansheeblt_log("srcSize=%08x\n", val); +#if 0 + bansheeblt_log("srcSize=%08x\n", val); +#endif break; case 0x5c: voodoo->banshee_blt.srcXY = val; voodoo->banshee_blt.srcX = ((int32_t) (val << 19)) >> 19; voodoo->banshee_blt.srcY = ((int32_t) (val << 3)) >> 19; update_src_stride(voodoo); - // bansheeblt_log("srcXY=%08x\n", val); +#if 0 + bansheeblt_log("srcXY=%08x\n", val); +#endif break; case 0x60: voodoo->banshee_blt.colorBack = val; @@ -1352,19 +1461,25 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) voodoo->banshee_blt.dstSizeX = voodoo->banshee_blt.dstSize & 0x1fff; voodoo->banshee_blt.dstSizeY = (voodoo->banshee_blt.dstSize >> 16) & 0x1fff; update_src_stride(voodoo); - // bansheeblt_log("dstSize=%08x\n", val); +#if 0 + bansheeblt_log("dstSize=%08x\n", val); +#endif break; case 0x6c: voodoo->banshee_blt.dstXY = val; voodoo->banshee_blt.dstX = ((int32_t) (val << 19)) >> 19; voodoo->banshee_blt.dstY = ((int32_t) (val << 3)) >> 19; - // bansheeblt_log("dstXY=%08x\n", val); +#if 0 + bansheeblt_log("dstXY=%08x\n", val); +#endif break; case 0x70: voodoo_wait_for_render_thread_idle(voodoo); voodoo->banshee_blt.command = val; voodoo->banshee_blt.rops[0] = val >> 24; - // bansheeblt_log("command=%x %08x\n", voodoo->banshee_blt.command & COMMAND_CMD_MASK, val); +#if 0 + bansheeblt_log("command=%x %08x\n", voodoo->banshee_blt.command & COMMAND_CMD_MASK, val); +#endif voodoo->banshee_blt.patoff_x = (val & COMMAND_PATOFF_X_MASK) >> COMMAND_PATOFF_X_SHIFT; voodoo->banshee_blt.patoff_y = (val & COMMAND_PATOFF_Y_MASK) >> COMMAND_PATOFF_Y_SHIFT; voodoo->banshee_blt.cur_x = 0; @@ -1377,19 +1492,22 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) voodoo->banshee_blt.host_data_remainder = 0; voodoo->banshee_blt.host_data_count = 0; switch (voodoo->banshee_blt.command & COMMAND_CMD_MASK) { - /* case COMMAND_CMD_SCREEN_TO_SCREEN_STRETCH_BLT: - if (voodoo->banshee_blt.bresError0 & BRES_ERROR_USE) - voodoo->banshee_blt.bres_error_0 = (int32_t)(int16_t)(voodoo->banshee_blt.bresError0 & BRES_ERROR_MASK); - else - voodoo->banshee_blt.bres_error_0 = voodoo->banshee_blt.dstSizeY / 2; - if (voodoo->banshee_blt.bresError1 & BRES_ERROR_USE) - voodoo->banshee_blt.bres_error_1 = (int32_t)(int16_t)(voodoo->banshee_blt.bresError1 & BRES_ERROR_MASK); - else - voodoo->banshee_blt.bres_error_1 = voodoo->banshee_blt.dstSizeX / 2; - if (val & COMMAND_INITIATE) - banshee_do_2d_blit(voodoo, -1, 0); - break;*/ +#if 0 + case COMMAND_CMD_SCREEN_TO_SCREEN_STRETCH_BLT: + if (voodoo->banshee_blt.bresError0 & BRES_ERROR_USE) + voodoo->banshee_blt.bres_error_0 = (int32_t)(int16_t)(voodoo->banshee_blt.bresError0 & BRES_ERROR_MASK); + else + voodoo->banshee_blt.bres_error_0 = voodoo->banshee_blt.dstSizeY / 2; + if (voodoo->banshee_blt.bresError1 & BRES_ERROR_USE) + voodoo->banshee_blt.bres_error_1 = (int32_t)(int16_t)(voodoo->banshee_blt.bresError1 & BRES_ERROR_MASK); + else + voodoo->banshee_blt.bres_error_1 = voodoo->banshee_blt.dstSizeX / 2; + + if (val & COMMAND_INITIATE) + banshee_do_2d_blit(voodoo, -1, 0); + break;*/ +#endif case COMMAND_CMD_POLYFILL: if (val & COMMAND_INITIATE) { @@ -1403,7 +1521,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) default: if (val & COMMAND_INITIATE) { banshee_do_2d_blit(voodoo, -1, 0); - // fatal("Initiate command!\n"); +#if 0 + fatal("Initiate command!\n"); +#endif } break; } @@ -1441,7 +1561,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) case 0xf4: case 0xf8: case 0xfc: - // bansheeblt_log("launch %08x %08x %08x %08x\n", voodoo->banshee_blt.command, voodoo->banshee_blt.commandExtra, voodoo->banshee_blt.srcColorkeyMin, voodoo->banshee_blt.srcColorkeyMax); +#if 0 + bansheeblt_log("launch %08x %08x %08x %08x\n", voodoo->banshee_blt.command, voodoo->banshee_blt.commandExtra, voodoo->banshee_blt.srcColorkeyMin, voodoo->banshee_blt.srcColorkeyMax); +#endif switch (voodoo->banshee_blt.command & COMMAND_CMD_MASK) { case COMMAND_CMD_SCREEN_TO_SCREEN_BLT: voodoo->banshee_blt.srcXY = val; @@ -1573,7 +1695,9 @@ voodoo_2d_reg_writel(voodoo_t *voodoo, uint32_t addr, uint32_t val) voodoo->banshee_blt.colorPattern8[(addr & 60) + 2] = (val >> 16) & 0xff; voodoo->banshee_blt.colorPattern8[(addr & 60) + 3] = (val >> 24) & 0xff; } - // bansheeblt_log("colorPattern%02x=%08x\n", (addr >> 2) & 63, val); +#if 0 + bansheeblt_log("colorPattern%02x=%08x\n", (addr >> 2) & 63, val); +#endif break; default: diff --git a/src/video/vid_voodoo_blitter.c b/src/video/vid_voodoo_blitter.c index f60d9e184..ff45fc837 100644 --- a/src/video/vid_voodoo_blitter.c +++ b/src/video/vid_voodoo_blitter.c @@ -152,19 +152,24 @@ void voodoo_v2_blit_start(voodoo_t *voodoo) { uint64_t dat64; - int size_x = ABS(voodoo->bltSizeX), size_y = ABS(voodoo->bltSizeY); + int size_x = ABS(voodoo->bltSizeX); + int size_y = ABS(voodoo->bltSizeY); int x_dir = (voodoo->bltSizeX > 0) ? 1 : -1; int y_dir = (voodoo->bltSizeY > 0) ? 1 : -1; int dst_x; - int src_y = voodoo->bltSrcY & 0x7ff, dst_y = voodoo->bltDstY & 0x7ff; + int src_y = voodoo->bltSrcY & 0x7ff; + int dst_y = voodoo->bltDstY & 0x7ff; int src_stride = (voodoo->bltCommand & BLTCMD_SRC_TILED) ? ((voodoo->bltSrcXYStride & 0x3f) * 32 * 2) : (voodoo->bltSrcXYStride & 0xff8); int dst_stride = (voodoo->bltCommand & BLTCMD_DST_TILED) ? ((voodoo->bltDstXYStride & 0x3f) * 32 * 2) : (voodoo->bltDstXYStride & 0xff8); uint32_t src_base_addr = (voodoo->bltCommand & BLTCMD_SRC_TILED) ? ((voodoo->bltSrcBaseAddr & 0x3ff) << 12) : (voodoo->bltSrcBaseAddr & 0x3ffff8); uint32_t dst_base_addr = (voodoo->bltCommand & BLTCMD_DST_TILED) ? ((voodoo->bltDstBaseAddr & 0x3ff) << 12) : (voodoo->bltDstBaseAddr & 0x3ffff8); - int x, y; + int x; + int y; - /* voodooblt_log("blit_start: command=%08x srcX=%i srcY=%i dstX=%i dstY=%i sizeX=%i sizeY=%i color=%04x,%04x\n", - voodoo->bltCommand, voodoo->bltSrcX, voodoo->bltSrcY, voodoo->bltDstX, voodoo->bltDstY, voodoo->bltSizeX, voodoo->bltSizeY, voodoo->bltColorFg, voodoo->bltColorBg);*/ +#if 0 + voodooblt_log("blit_start: command=%08x srcX=%i srcY=%i dstX=%i dstY=%i sizeX=%i sizeY=%i color=%04x,%04x\n", + voodoo->bltCommand, voodoo->bltSrcX, voodoo->bltSrcY, voodoo->bltDstX, voodoo->bltDstY, voodoo->bltSizeX, voodoo->bltSizeY, voodoo->bltColorFg, voodoo->bltColorBg); +#endif voodoo_wait_for_render_thread_idle(voodoo); @@ -173,7 +178,8 @@ voodoo_v2_blit_start(voodoo_t *voodoo) for (y = 0; y <= size_y; y++) { uint16_t *src = (uint16_t *) &voodoo->fb_mem[src_base_addr + src_y * src_stride]; uint16_t *dst = (uint16_t *) &voodoo->fb_mem[dst_base_addr + dst_y * dst_stride]; - int src_x = voodoo->bltSrcX, dst_x = voodoo->bltDstX; + int src_x = voodoo->bltSrcX; + int dst_x = voodoo->bltDstX; for (x = 0; x <= size_x; x++) { uint16_t src_dat = src[src_x]; @@ -316,8 +322,11 @@ voodoo_v2_blit_data(voodoo_t *voodoo, uint32_t data) } while (src_bits && voodoo->blt.cur_x <= voodoo->blt.size_x) { - int r = 0, g = 0, b = 0; - uint16_t src_dat = 0, dst_dat; + int r = 0; + int g = 0; + int b = 0; + uint16_t src_dat = 0; + uint16_t dst_dat; int x = (voodoo->blt.x_dir > 0) ? (voodoo->blt.dst_x + voodoo->blt.cur_x) : (voodoo->blt.dst_x - voodoo->blt.cur_x); int rop = 0; @@ -438,7 +447,8 @@ void voodoo_fastfill(voodoo_t *voodoo, voodoo_params_t *params) { int y; - int low_y, high_y; + int low_y; + int high_y; if (params->fbzMode & (1 << 17)) { int y_origin = (voodoo->type >= VOODOO_BANSHEE) ? (voodoo->y_origin_swap + 1) : voodoo->v_disp; @@ -451,7 +461,9 @@ voodoo_fastfill(voodoo_t *voodoo, voodoo_params_t *params) } if (params->fbzMode & FBZ_RGB_WMASK) { - int r, g, b; + int r; + int g; + int b; uint16_t col; r = ((params->color1 >> 16) >> 3) & 0x1f; @@ -462,26 +474,23 @@ voodoo_fastfill(voodoo_t *voodoo, voodoo_params_t *params) if (SLI_ENABLED) { for (y = low_y; y < high_y; y += 2) { uint16_t *cbuf = (uint16_t *) &voodoo->fb_mem[(params->draw_offset + (y >> 1) * voodoo->row_width) & voodoo->fb_mask]; - int x; - for (x = params->clipLeft; x < params->clipRight; x++) + for (int x = params->clipLeft; x < params->clipRight; x++) cbuf[x] = col; } } else { for (y = low_y; y < high_y; y++) { if (voodoo->col_tiled) { uint16_t *cbuf = (uint16_t *) &voodoo->fb_mem[(params->draw_offset + (y >> 5) * voodoo->row_width + (y & 31) * 128) & voodoo->fb_mask]; - int x; - for (x = params->clipLeft; x < params->clipRight; x++) { + for (int x = params->clipLeft; x < params->clipRight; x++) { int x2 = (x & 63) | ((x >> 6) * 128 * 32 / 2); cbuf[x2] = col; } } else { uint16_t *cbuf = (uint16_t *) &voodoo->fb_mem[(params->draw_offset + y * voodoo->row_width) & voodoo->fb_mask]; - int x; - for (x = params->clipLeft; x < params->clipRight; x++) + for (int x = params->clipLeft; x < params->clipRight; x++) cbuf[x] = col; } } @@ -491,26 +500,23 @@ voodoo_fastfill(voodoo_t *voodoo, voodoo_params_t *params) if (SLI_ENABLED) { for (y = low_y; y < high_y; y += 2) { uint16_t *abuf = (uint16_t *) &voodoo->fb_mem[(params->aux_offset + (y >> 1) * voodoo->row_width) & voodoo->fb_mask]; - int x; - for (x = params->clipLeft; x < params->clipRight; x++) + for (int x = params->clipLeft; x < params->clipRight; x++) abuf[x] = params->zaColor & 0xffff; } } else { for (y = low_y; y < high_y; y++) { if (voodoo->aux_tiled) { uint16_t *abuf = (uint16_t *) &voodoo->fb_mem[(params->aux_offset + (y >> 5) * voodoo->aux_row_width + (y & 31) * 128) & voodoo->fb_mask]; - int x; - for (x = params->clipLeft; x < params->clipRight; x++) { + for (int x = params->clipLeft; x < params->clipRight; x++) { int x2 = (x & 63) | ((x >> 6) * 128 * 32 / 2); abuf[x2] = params->zaColor & 0xffff; } } else { uint16_t *abuf = (uint16_t *) &voodoo->fb_mem[(params->aux_offset + y * voodoo->aux_row_width) & voodoo->fb_mask]; - int x; - for (x = params->clipLeft; x < params->clipRight; x++) + for (int x = params->clipLeft; x < params->clipRight; x++) abuf[x] = params->zaColor & 0xffff; } } diff --git a/src/video/vid_voodoo_display.c b/src/video/vid_voodoo_display.c index aded37e2d..84f376a8f 100644 --- a/src/video/vid_voodoo_display.c +++ b/src/video/vid_voodoo_display.c @@ -61,15 +61,17 @@ voodoodisp_log(const char *fmt, ...) void voodoo_update_ncc(voodoo_t *voodoo, int tmu) { - int tbl; - - for (tbl = 0; tbl < 2; tbl++) { - int col; - - for (col = 0; col < 256; col++) { - int y = (col >> 4), i = (col >> 2) & 3, q = col & 3; - int i_r, i_g, i_b; - int q_r, q_g, q_b; + for (uint8_t tbl = 0; tbl < 2; tbl++) { + for (uint16_t col = 0; col < 256; col++) { + int y = (col >> 4); + int i = (col >> 2) & 3; + int q = col & 3; + int i_r; + int i_g; + int i_b; + int q_r; + int q_g; + int q_b; y = (voodoo->nccTable[tmu][tbl].y[y >> 2] >> ((y & 3) * 8)) & 0xff; @@ -121,7 +123,7 @@ voodoo_pixelclock_update(voodoo_t *voodoo) voodoo->pixel_clock = t; clock_const = cpuclock / t; - voodoo->line_time = (uint64_t) ((double) line_length * clock_const * (double) (1ull << 32)); + voodoo->line_time = (uint64_t) ((double) line_length * clock_const * (double) (1ULL << 32)); } static void @@ -139,33 +141,42 @@ voodoo_calc_clutData(voodoo_t *voodoo) int r = (c >> 8) & 0xf8; int g = (c >> 3) & 0xfc; int b = (c << 3) & 0xf8; - // r |= (r >> 5); - // g |= (g >> 6); - // b |= (b >> 5); - +#if 0 + r |= (r >> 5); + g |= (g >> 6); + b |= (b >> 5); +#endif voodoo->video_16to32[c] = (voodoo->clutData256[r].r << 16) | (voodoo->clutData256[g].g << 8) | voodoo->clutData256[b].b; } } #define FILTDIV 256 -static int FILTCAP, FILTCAPG, FILTCAPB = 0; /* color filter threshold values */ +static int FILTCAP; +static int FILTCAPG; +static int FILTCAPB = 0; /* color filter threshold values */ void voodoo_generate_filter_v1(voodoo_t *voodoo) { - int g, h; - float difference, diffg, diffb; - float thiscol, thiscolg, thiscolb, lined; - float fcr, fcg, fcb; + float difference; + float diffg; + float diffb; + float thiscol; + float thiscolg; + float thiscolb; + float lined; + float fcr; + float fcg; + float fcb; fcr = FILTCAP * 5; fcg = FILTCAPG * 6; fcb = FILTCAPB * 5; - for (g = 0; g < FILTDIV; g++) // pixel 1 + for (uint16_t g = 0; g < FILTDIV; g++) // pixel 1 { - for (h = 0; h < FILTDIV; h++) // pixel 2 + for (uint16_t h = 0; h < FILTDIV; h++) // pixel 2 { difference = (float) (h - g); diffg = difference; @@ -236,11 +247,16 @@ voodoo_generate_filter_v1(voodoo_t *voodoo) void voodoo_generate_filter_v2(voodoo_t *voodoo) { - int g, h; float difference; - float thiscol, thiscolg, thiscolb; - float clr, clg, clb = 0; - float fcr, fcg, fcb = 0; + float thiscol; + float thiscolg; + float thiscolb; + float clr; + float clg; + float clb = 0; + float fcr; + float fcg; + float fcb = 0; // pre-clamping @@ -255,9 +271,9 @@ voodoo_generate_filter_v2(voodoo_t *voodoo) if (fcb > 32) fcb = 32; - for (g = 0; g < 256; g++) // pixel 1 - our target pixel we want to bleed into + for (uint16_t g = 0; g < 256; g++) // pixel 1 - our target pixel we want to bleed into { - for (h = 0; h < 256; h++) // pixel 2 - our main pixel + for (uint16_t h = 0; h < 256; h++) // pixel 2 - our main pixel { float avg; float avgdiff; @@ -325,9 +341,9 @@ voodoo_generate_filter_v2(voodoo_t *voodoo) thiscolb = 255; // add to the table - voodoo->thefilter[g][h] = (thiscol); - voodoo->thefilterg[g][h] = (thiscolg); - voodoo->thefilterb[g][h] = (thiscolb); + voodoo->thefilter[g][h] = thiscol; + voodoo->thefilterg[g][h] = thiscolg; + voodoo->thefilterb[g][h] = thiscolb; // debug the ones that don't give us much of a difference // if (difference < FILTCAP) @@ -339,7 +355,9 @@ voodoo_generate_filter_v2(voodoo_t *voodoo) void voodoo_threshold_check(voodoo_t *voodoo) { - int r, g, b; + int r; + int g; + int b; if (!voodoo->scrfilterEnabled) return; /* considered disabled; don't check and generate */ @@ -371,14 +389,12 @@ voodoo_threshold_check(voodoo_t *voodoo) static void voodoo_filterline_v1(voodoo_t *voodoo, uint8_t *fil, int column, uint16_t *src, int line) { - int x; - // Scratchpad for avoiding feedback streaks uint8_t fil3[4096 * 3]; assert(voodoo->h_disp <= 4096); /* 16 to 32-bit */ - for (x = 0; x < column; x++) { + for (int x = 0; x < column; x++) { fil[x * 3] = ((src[x] & 31) << 3); fil[x * 3 + 1] = (((src[x] >> 5) & 63) << 2); fil[x * 3 + 2] = (((src[x] >> 11) & 31) << 3); @@ -392,7 +408,7 @@ voodoo_filterline_v1(voodoo_t *voodoo, uint8_t *fil, int column, uint16_t *src, /* lines */ if (line & 1) { - for (x = 0; x < column; x++) { + for (int x = 0; x < column; x++) { fil[x * 3] = voodoo->purpleline[fil[x * 3]][0]; fil[x * 3 + 1] = voodoo->purpleline[fil[x * 3 + 1]][1]; fil[x * 3 + 2] = voodoo->purpleline[fil[x * 3 + 2]][2]; @@ -401,33 +417,33 @@ voodoo_filterline_v1(voodoo_t *voodoo, uint8_t *fil, int column, uint16_t *src, /* filtering time */ - for (x = 1; x < column; x++) { - fil3[(x) *3] = voodoo->thefilterb[fil[x * 3]][fil[(x - 1) * 3]]; - fil3[(x) *3 + 1] = voodoo->thefilterg[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; - fil3[(x) *3 + 2] = voodoo->thefilter[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; + for (int x = 1; x < column; x++) { + fil3[x * 3] = voodoo->thefilterb[fil[x * 3]][fil[(x - 1) * 3]]; + fil3[x * 3 + 1] = voodoo->thefilterg[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; + fil3[x * 3 + 2] = voodoo->thefilter[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; } - for (x = 1; x < column; x++) { - fil[(x) *3] = voodoo->thefilterb[fil3[x * 3]][fil3[(x - 1) * 3]]; - fil[(x) *3 + 1] = voodoo->thefilterg[fil3[x * 3 + 1]][fil3[(x - 1) * 3 + 1]]; - fil[(x) *3 + 2] = voodoo->thefilter[fil3[x * 3 + 2]][fil3[(x - 1) * 3 + 2]]; + for (int x = 1; x < column; x++) { + fil[x * 3] = voodoo->thefilterb[fil3[x * 3]][fil3[(x - 1) * 3]]; + fil[x * 3 + 1] = voodoo->thefilterg[fil3[x * 3 + 1]][fil3[(x - 1) * 3 + 1]]; + fil[x * 3 + 2] = voodoo->thefilter[fil3[x * 3 + 2]][fil3[(x - 1) * 3 + 2]]; } - for (x = 1; x < column; x++) { - fil3[(x) *3] = voodoo->thefilterb[fil[x * 3]][fil[(x - 1) * 3]]; - fil3[(x) *3 + 1] = voodoo->thefilterg[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; - fil3[(x) *3 + 2] = voodoo->thefilter[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; + for (int x = 1; x < column; x++) { + fil3[x * 3] = voodoo->thefilterb[fil[x * 3]][fil[(x - 1) * 3]]; + fil3[x * 3 + 1] = voodoo->thefilterg[fil[x * 3 + 1]][fil[(x - 1) * 3 + 1]]; + fil3[x * 3 + 2] = voodoo->thefilter[fil[x * 3 + 2]][fil[(x - 1) * 3 + 2]]; } - for (x = 0; x < column - 1; x++) { - fil[(x) *3] = voodoo->thefilterb[fil3[x * 3]][fil3[(x + 1) * 3]]; - fil[(x) *3 + 1] = voodoo->thefilterg[fil3[x * 3 + 1]][fil3[(x + 1) * 3 + 1]]; - fil[(x) *3 + 2] = voodoo->thefilter[fil3[x * 3 + 2]][fil3[(x + 1) * 3 + 2]]; + for (int x = 0; x < column - 1; x++) { + fil[x * 3] = voodoo->thefilterb[fil3[x * 3]][fil3[(x + 1) * 3]]; + fil[x * 3 + 1] = voodoo->thefilterg[fil3[x * 3 + 1]][fil3[(x + 1) * 3 + 1]]; + fil[x * 3 + 2] = voodoo->thefilter[fil3[x * 3 + 2]][fil3[(x + 1) * 3 + 2]]; } } static void -voodoo_filterline_v2(voodoo_t *voodoo, uint8_t *fil, int column, uint16_t *src, int line) +voodoo_filterline_v2(voodoo_t *voodoo, uint8_t *fil, int column, uint16_t *src, UNUSED(int line)) { int x; @@ -446,54 +462,54 @@ voodoo_filterline_v2(voodoo_t *voodoo, uint8_t *fil, int column, uint16_t *src, /* filtering time */ for (x = 1; x < column - 3; x++) { - fil3[(x + 3) * 3] = voodoo->thefilterb[((src[x + 3] & 31) << 3)][((src[x] & 31) << 3)]; - fil3[(x + 3) * 3 + 1] = voodoo->thefilterg[(((src[x + 3] >> 5) & 63) << 2)][(((src[x] >> 5) & 63) << 2)]; - fil3[(x + 3) * 3 + 2] = voodoo->thefilter[(((src[x + 3] >> 11) & 31) << 3)][(((src[x] >> 11) & 31) << 3)]; + fil3[(x + 3) * 3] = voodoo->thefilterb[(src[x + 3] & 31) << 3][(src[x] & 31) << 3]; + fil3[(x + 3) * 3 + 1] = voodoo->thefilterg[((src[x + 3] >> 5) & 63) << 2][((src[x] >> 5) & 63) << 2]; + fil3[(x + 3) * 3 + 2] = voodoo->thefilter[((src[x + 3] >> 11) & 31) << 3][((src[x] >> 11) & 31) << 3]; - fil[(x + 2) * 3] = voodoo->thefilterb[fil3[(x + 2) * 3]][((src[x] & 31) << 3)]; - fil[(x + 2) * 3 + 1] = voodoo->thefilterg[fil3[(x + 2) * 3 + 1]][(((src[x] >> 5) & 63) << 2)]; - fil[(x + 2) * 3 + 2] = voodoo->thefilter[fil3[(x + 2) * 3 + 2]][(((src[x] >> 11) & 31) << 3)]; + fil[(x + 2) * 3] = voodoo->thefilterb[fil3[(x + 2) * 3]][(src[x] & 31) << 3]; + fil[(x + 2) * 3 + 1] = voodoo->thefilterg[fil3[(x + 2) * 3 + 1]][((src[x] >> 5) & 63) << 2]; + fil[(x + 2) * 3 + 2] = voodoo->thefilter[fil3[(x + 2) * 3 + 2]][((src[x] >> 11) & 31) << 3]; - fil3[(x + 1) * 3] = voodoo->thefilterb[fil[(x + 1) * 3]][((src[x] & 31) << 3)]; - fil3[(x + 1) * 3 + 1] = voodoo->thefilterg[fil[(x + 1) * 3 + 1]][(((src[x] >> 5) & 63) << 2)]; - fil3[(x + 1) * 3 + 2] = voodoo->thefilter[fil[(x + 1) * 3 + 2]][(((src[x] >> 11) & 31) << 3)]; + fil3[(x + 1) * 3] = voodoo->thefilterb[fil[(x + 1) * 3]][(src[x] & 31) << 3]; + fil3[(x + 1) * 3 + 1] = voodoo->thefilterg[fil[(x + 1) * 3 + 1]][((src[x] >> 5) & 63) << 2]; + fil3[(x + 1) * 3 + 2] = voodoo->thefilter[fil[(x + 1) * 3 + 2]][((src[x] >> 11) & 31) << 3]; - fil[(x - 1) * 3] = voodoo->thefilterb[fil3[(x - 1) * 3]][((src[x] & 31) << 3)]; - fil[(x - 1) * 3 + 1] = voodoo->thefilterg[fil3[(x - 1) * 3 + 1]][(((src[x] >> 5) & 63) << 2)]; - fil[(x - 1) * 3 + 2] = voodoo->thefilter[fil3[(x - 1) * 3 + 2]][(((src[x] >> 11) & 31) << 3)]; + fil[(x - 1) * 3] = voodoo->thefilterb[fil3[(x - 1) * 3]][(src[x] & 31) << 3]; + fil[(x - 1) * 3 + 1] = voodoo->thefilterg[fil3[(x - 1) * 3 + 1]][((src[x] >> 5) & 63) << 2]; + fil[(x - 1) * 3 + 2] = voodoo->thefilter[fil3[(x - 1) * 3 + 2]][((src[x] >> 11) & 31) << 3]; } // unroll for edge cases - fil3[(column - 3) * 3] = voodoo->thefilterb[((src[column - 3] & 31) << 3)][((src[column] & 31) << 3)]; - fil3[(column - 3) * 3 + 1] = voodoo->thefilterg[(((src[column - 3] >> 5) & 63) << 2)][(((src[column] >> 5) & 63) << 2)]; - fil3[(column - 3) * 3 + 2] = voodoo->thefilter[(((src[column - 3] >> 11) & 31) << 3)][(((src[column] >> 11) & 31) << 3)]; + fil3[(column - 3) * 3] = voodoo->thefilterb[(src[column - 3] & 31) << 3][(src[column] & 31) << 3]; + fil3[(column - 3) * 3 + 1] = voodoo->thefilterg[((src[column - 3] >> 5) & 63) << 2][((src[column] >> 5) & 63) << 2]; + fil3[(column - 3) * 3 + 2] = voodoo->thefilter[((src[column - 3] >> 11) & 31) << 3][((src[column] >> 11) & 31) << 3]; - fil3[(column - 2) * 3] = voodoo->thefilterb[((src[column - 2] & 31) << 3)][((src[column] & 31) << 3)]; - fil3[(column - 2) * 3 + 1] = voodoo->thefilterg[(((src[column - 2] >> 5) & 63) << 2)][(((src[column] >> 5) & 63) << 2)]; - fil3[(column - 2) * 3 + 2] = voodoo->thefilter[(((src[column - 2] >> 11) & 31) << 3)][(((src[column] >> 11) & 31) << 3)]; + fil3[(column - 2) * 3] = voodoo->thefilterb[(src[column - 2] & 31) << 3][(src[column] & 31) << 3]; + fil3[(column - 2) * 3 + 1] = voodoo->thefilterg[((src[column - 2] >> 5) & 63) << 2][((src[column] >> 5) & 63) << 2]; + fil3[(column - 2) * 3 + 2] = voodoo->thefilter[((src[column - 2] >> 11) & 31) << 3][((src[column] >> 11) & 31) << 3]; - fil3[(column - 1) * 3] = voodoo->thefilterb[((src[column - 1] & 31) << 3)][((src[column] & 31) << 3)]; - fil3[(column - 1) * 3 + 1] = voodoo->thefilterg[(((src[column - 1] >> 5) & 63) << 2)][(((src[column] >> 5) & 63) << 2)]; - fil3[(column - 1) * 3 + 2] = voodoo->thefilter[(((src[column - 1] >> 11) & 31) << 3)][(((src[column] >> 11) & 31) << 3)]; + fil3[(column - 1) * 3] = voodoo->thefilterb[(src[column - 1] & 31) << 3][(src[column] & 31) << 3]; + fil3[(column - 1) * 3 + 1] = voodoo->thefilterg[((src[column - 1] >> 5) & 63) << 2][((src[column] >> 5) & 63) << 2]; + fil3[(column - 1) * 3 + 2] = voodoo->thefilter[((src[column - 1] >> 11) & 31) << 3][((src[column] >> 11) & 31) << 3]; - fil[(column - 2) * 3] = voodoo->thefilterb[fil3[(column - 2) * 3]][((src[column] & 31) << 3)]; - fil[(column - 2) * 3 + 1] = voodoo->thefilterg[fil3[(column - 2) * 3 + 1]][(((src[column] >> 5) & 63) << 2)]; - fil[(column - 2) * 3 + 2] = voodoo->thefilter[fil3[(column - 2) * 3 + 2]][(((src[column] >> 11) & 31) << 3)]; + fil[(column - 2) * 3] = voodoo->thefilterb[fil3[(column - 2) * 3]][(src[column] & 31) << 3]; + fil[(column - 2) * 3 + 1] = voodoo->thefilterg[fil3[(column - 2) * 3 + 1]][((src[column] >> 5) & 63) << 2]; + fil[(column - 2) * 3 + 2] = voodoo->thefilter[fil3[(column - 2) * 3 + 2]][((src[column] >> 11) & 31) << 3]; - fil[(column - 1) * 3] = voodoo->thefilterb[fil3[(column - 1) * 3]][((src[column] & 31) << 3)]; - fil[(column - 1) * 3 + 1] = voodoo->thefilterg[fil3[(column - 1) * 3 + 1]][(((src[column] >> 5) & 63) << 2)]; - fil[(column - 1) * 3 + 2] = voodoo->thefilter[fil3[(column - 1) * 3 + 2]][(((src[column] >> 11) & 31) << 3)]; + fil[(column - 1) * 3] = voodoo->thefilterb[fil3[(column - 1) * 3]][(src[column] & 31) << 3]; + fil[(column - 1) * 3 + 1] = voodoo->thefilterg[fil3[(column - 1) * 3 + 1]][((src[column] >> 5) & 63) << 2]; + fil[(column - 1) * 3 + 2] = voodoo->thefilter[fil3[(column - 1) * 3 + 2]][((src[column] >> 11) & 31) << 3]; - fil3[(column - 1) * 3] = voodoo->thefilterb[fil[(column - 1) * 3]][((src[column] & 31) << 3)]; - fil3[(column - 1) * 3 + 1] = voodoo->thefilterg[fil[(column - 1) * 3 + 1]][(((src[column] >> 5) & 63) << 2)]; - fil3[(column - 1) * 3 + 2] = voodoo->thefilter[fil[(column - 1) * 3 + 2]][(((src[column] >> 11) & 31) << 3)]; + fil3[(column - 1) * 3] = voodoo->thefilterb[fil[(column - 1) * 3]][(src[column] & 31) << 3]; + fil3[(column - 1) * 3 + 1] = voodoo->thefilterg[fil[(column - 1) * 3 + 1]][((src[column] >> 5) & 63) << 2]; + fil3[(column - 1) * 3 + 2] = voodoo->thefilter[fil[(column - 1) * 3 + 2]][((src[column] >> 11) & 31) << 3]; } void -voodoo_callback(void *p) +voodoo_callback(void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; monitor_t *monitor = &monitors[voodoo->monitor_index]; if (voodoo->fbiInit0 & FBIINIT0_VGA_PASS) { @@ -561,7 +577,9 @@ voodoo_callback(void *p) } skip_draw: if (voodoo->line == voodoo->v_disp) { - // voodoodisp_log("retrace %i %i %08x %i\n", voodoo->retrace_count, voodoo->swap_interval, voodoo->swap_offset, voodoo->swap_pending); +#if 0 + voodoodisp_log("retrace %i %i %08x %i\n", voodoo->retrace_count, voodoo->swap_interval, voodoo->swap_offset, voodoo->swap_pending); +#endif voodoo->retrace_count++; if (SLI_ENABLED && (voodoo->fbiInit2 & FBIINIT2_SWAP_ALGORITHM_MASK) == FBIINIT2_SWAP_ALGORITHM_SLI_SYNC) { if (voodoo == voodoo->set->voodoos[0]) { diff --git a/src/video/vid_voodoo_fb.c b/src/video/vid_voodoo_fb.c index f4a4edca6..5e06836b1 100644 --- a/src/video/vid_voodoo_fb.c +++ b/src/video/vid_voodoo_fb.c @@ -59,10 +59,11 @@ voodoo_fb_log(const char *fmt, ...) #endif uint16_t -voodoo_fb_readw(uint32_t addr, void *p) +voodoo_fb_readw(uint32_t addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; - int x, y; + voodoo_t *voodoo = (voodoo_t *) priv; + int x; + int y; uint32_t read_addr; uint16_t temp; @@ -99,10 +100,11 @@ voodoo_fb_readw(uint32_t addr, void *p) return temp; } uint32_t -voodoo_fb_readl(uint32_t addr, void *p) +voodoo_fb_readl(uint32_t addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; - int x, y; + voodoo_t *voodoo = (voodoo_t *) priv; + int x; + int y; uint32_t read_addr; uint32_t temp; @@ -142,7 +144,9 @@ voodoo_fb_readl(uint32_t addr, void *p) static inline uint16_t do_dither(voodoo_params_t *params, rgba8_t col, int x, int y) { - int r, g, b; + int r; + int g; + int b; if (dither) { if (dither2x2) { @@ -164,12 +168,14 @@ do_dither(voodoo_params_t *params, rgba8_t col, int x, int y) } void -voodoo_fb_writew(uint32_t addr, uint16_t val, void *p) +voodoo_fb_writew(uint32_t addr, uint16_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; voodoo_params_t *params = &voodoo->params; - int x, y; - uint32_t write_addr, write_addr_aux; + int x; + int y; + uint32_t write_addr; + uint32_t write_addr_aux; rgba8_t colour_data; uint16_t depth_data; uint8_t alpha_data; @@ -180,10 +186,14 @@ voodoo_fb_writew(uint32_t addr, uint16_t val, void *p) depth_data = voodoo->params.zaColor & 0xffff; alpha_data = voodoo->params.zaColor >> 24; - // while (!RB_EMPTY) - // thread_reset_event(voodoo->not_full_event); +#if 0 + while (!RB_EMPTY) + thread_reset_event(voodoo->not_full_event); +#endif - // voodoo_fb_log("voodoo_fb_writew : %08X %04X\n", addr, val); +#if 0 + voodoo_fb_log("voodoo_fb_writew : %08X %04X\n", addr, val); +#endif switch (voodoo->lfbMode & LFB_FORMAT_MASK) { case LFB_FORMAT_RGB565: @@ -265,7 +275,10 @@ voodoo_fb_writew(uint32_t addr, uint16_t val, void *p) if (params->alphaMode & (1 << 4)) { uint16_t dat = *(uint16_t *) (&voodoo->fb_mem[write_addr & voodoo->fb_mask]); - int dest_r, dest_g, dest_b, dest_a; + int dest_r; + int dest_g; + int dest_b; + int dest_a; dest_r = (dat >> 8) & 0xf8; dest_g = (dat >> 3) & 0xfc; @@ -295,23 +308,30 @@ skip_pixel: } void -voodoo_fb_writel(uint32_t addr, uint32_t val, void *p) +voodoo_fb_writel(uint32_t addr, uint32_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; voodoo_params_t *params = &voodoo->params; - int x, y; - uint32_t write_addr, write_addr_aux; + int x; + int y; + uint32_t write_addr; + uint32_t write_addr_aux; rgba8_t colour_data[2]; uint16_t depth_data[2]; uint8_t alpha_data[2]; - int write_mask = 0, count = 1; + int write_mask = 0; + int count = 1; depth_data[0] = depth_data[1] = voodoo->params.zaColor & 0xffff; alpha_data[0] = alpha_data[1] = voodoo->params.zaColor >> 24; - // while (!RB_EMPTY) - // thread_reset_event(voodoo->not_full_event); +#if 0 + while (!RB_EMPTY) + thread_reset_event(voodoo->not_full_event); +#endif - // voodoo_fb_log("voodoo_fb_writel : %08X %08X\n", addr, val); +#if 0 + voodoo_fb_log("voodoo_fb_writel : %08X %08X\n", addr, val); +#endif switch (voodoo->lfbMode & LFB_FORMAT_MASK) { case LFB_FORMAT_RGB565: @@ -381,12 +401,12 @@ voodoo_fb_writel(uint32_t addr, uint32_t val, void *p) else write_addr_aux = voodoo->params.aux_offset + x + (y * voodoo->row_width); - // voodoo_fb_log("fb_writel %08x x=%i y=%i rw=%i %08x wo=%08x\n", addr, x, y, voodoo->row_width, write_addr, voodoo->fb_write_offset); +#if 0 + voodoo_fb_log("fb_writel %08x x=%i y=%i rw=%i %08x wo=%08x\n", addr, x, y, voodoo->row_width, write_addr, voodoo->fb_write_offset); +#endif if (voodoo->lfbMode & 0x100) { - int c; - - for (c = 0; c < count; c++) { + for (int c = 0; c < count; c++) { rgba8_t write_data = colour_data[c]; uint16_t new_depth = depth_data[c]; @@ -412,7 +432,10 @@ voodoo_fb_writel(uint32_t addr, uint32_t val, void *p) if (params->alphaMode & (1 << 4)) { uint16_t dat = *(uint16_t *) (&voodoo->fb_mem[write_addr & voodoo->fb_mask]); - int dest_r, dest_g, dest_b, dest_a; + int dest_r; + int dest_g; + int dest_b; + int dest_a; dest_r = (dat >> 8) & 0xf8; dest_g = (dat >> 3) & 0xfc; @@ -435,9 +458,7 @@ skip_pixel: write_addr_aux += 2; } } else { - int c; - - for (c = 0; c < count; c++) { + for (int c = 0; c < count; c++) { if (write_mask & LFB_WRITE_COLOUR) *(uint16_t *) (&voodoo->fb_mem[write_addr & voodoo->fb_mask]) = do_dither(&voodoo->params, colour_data[c], (x >> 1) + c, y); if (write_mask & LFB_WRITE_DEPTH) diff --git a/src/video/vid_voodoo_fifo.c b/src/video/vid_voodoo_fifo.c index 646e5876c..8a84dabe4 100644 --- a/src/video/vid_voodoo_fifo.c +++ b/src/video/vid_voodoo_fifo.c @@ -81,9 +81,9 @@ voodoo_wake_fifo_thread_now(voodoo_t *voodoo) } void -voodoo_wake_timer(void *p) +voodoo_wake_timer(void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; thread_set_event(voodoo->wake_fifo_thread); /*Wake up FIFO thread if moving from idle*/ } @@ -148,11 +148,9 @@ voodoo_wait_for_swap_complete(voodoo_t *voodoo) voodoo->swap_count--; voodoo->swap_pending = 0; thread_release_mutex(voodoo->swap_mutex); - ; break; } else thread_release_mutex(voodoo->swap_mutex); - ; } } @@ -297,21 +295,27 @@ voodoo_fifo_thread(void *param) int num_verticies; int v_num; - // voodoo_fifo_log(" CMDFIFO header %08x at %08x\n", header, voodoo->cmdfifo_rp); +#if 0 + voodoo_fifo_log(" CMDFIFO header %08x at %08x\n", header, voodoo->cmdfifo_rp); +#endif voodoo->cmd_status &= ~7; voodoo->cmd_status |= (header & 7); voodoo->cmd_status |= (1 << 11); switch (header & 7) { case 0: - // voodoo_fifo_log("CMDFIFO0\n"); +#if 0 + voodoo_fifo_log("CMDFIFO0\n"); +#endif voodoo->cmd_status = (voodoo->cmd_status & 0xffff8fff) | (((header >> 3) & 7) << 12); switch ((header >> 3) & 7) { case 0: /*NOP*/ break; case 1: /*JSR*/ - // voodoo_fifo_log("JSR %08x\n", (header >> 4) & 0xfffffc); +#if 0 + voodoo_fifo_log("JSR %08x\n", (header >> 4) & 0xfffffc); +#endif voodoo->cmdfifo_ret_addr = voodoo->cmdfifo_rp; voodoo->cmdfifo_rp = (header >> 4) & 0xfffffc; voodoo->cmdfifo_in_sub = 1; @@ -324,7 +328,9 @@ voodoo_fifo_thread(void *param) case 3: /*JMP local frame buffer*/ voodoo->cmdfifo_rp = (header >> 4) & 0xfffffc; - // voodoo_fifo_log("JMP to %08x %04x\n", voodoo->cmdfifo_rp, header); +#if 0 + voodoo_fifo_log("JMP to %08x %04x\n", voodoo->cmdfifo_rp, header); +#endif break; default: @@ -336,13 +342,20 @@ voodoo_fifo_thread(void *param) case 1: num = header >> 16; addr = (header & 0x7ff8) >> 1; - // voodoo_fifo_log("CMDFIFO1 addr=%08x\n",addr); +#if 0 + voodoo_fifo_log("CMDFIFO1 addr=%08x\n",addr); +#endif while (num--) { uint32_t val = cmdfifo_get(voodoo); if ((addr & (1 << 13)) && voodoo->type >= VOODOO_BANSHEE) { - // if (voodoo->type != VOODOO_BANSHEE) - // fatal("CMDFIFO1: Not Banshee\n"); - // voodoo_fifo_log("CMDFIFO1: write %08x %08x\n", addr, val); +#if 0 + if (voodoo->type != VOODOO_BANSHEE) + fatal("CMDFIFO1: Not Banshee\n"); +#endif + +#if 0 + voodoo_fifo_log("CMDFIFO1: write %08x %08x\n", addr, val); +#endif voodoo_2d_reg_writel(voodoo, addr, val); } else { if ((addr & 0x3ff) == SST_triangleCMD || (addr & 0x3ff) == SST_ftriangleCMD || (addr & 0x3ff) == SST_fastfillCMD || (addr & 0x3ff) == SST_nopCMD) @@ -384,8 +397,10 @@ voodoo_fifo_thread(void *param) v_num = 0; if (((header >> 3) & 7) == 2) v_num = 1; - // voodoo_fifo_log("CMDFIFO3: num=%i verts=%i mask=%02x\n", num, num_verticies, (header >> 10) & 0xff); - // voodoo_fifo_log("CMDFIFO3 %02x %i\n", (header >> 10), (header >> 3) & 7); +#if 0 + voodoo_fifo_log("CMDFIFO3: num=%i verts=%i mask=%02x\n", num, num_verticies, (header >> 10) & 0xff); + voodoo_fifo_log("CMDFIFO3 %02x %i\n", (header >> 10), (header >> 3) & 7); +#endif while (num_verticies--) { voodoo->verts[3].sVx = cmdfifo_get_f(voodoo); @@ -437,7 +452,9 @@ voodoo_fifo_thread(void *param) num = (header >> 29) & 7; mask = (header >> 15) & 0x3fff; addr = (header & 0x7ff8) >> 1; - // voodoo_fifo_log("CMDFIFO4 addr=%08x\n",addr); +#if 0 + voodoo_fifo_log("CMDFIFO4 addr=%08x\n",addr); +#endif while (mask) { if (mask & 1) { uint32_t val = cmdfifo_get(voodoo); @@ -445,7 +462,10 @@ voodoo_fifo_thread(void *param) if ((addr & (1 << 13)) && voodoo->type >= VOODOO_BANSHEE) { if (voodoo->type < VOODOO_BANSHEE) fatal("CMDFIFO1: Not Banshee\n"); - // voodoo_fifo_log("CMDFIFO1: write %08x %08x\n", addr, val); +#if 0 + voodoo_fifo_log("CMDFIFO1: write %08x %08x\n", addr, val); +#endif + voodoo_2d_reg_writel(voodoo, addr, val); } else { if ((addr & 0x3ff) == SST_triangleCMD || (addr & 0x3ff) == SST_ftriangleCMD || (addr & 0x3ff) == SST_fastfillCMD || (addr & 0x3ff) == SST_nopCMD) @@ -465,22 +485,30 @@ voodoo_fifo_thread(void *param) break; case 5: - // if (header & 0x3fc00000) - // fatal("CMDFIFO packet 5 has byte disables set %08x\n", header); +#if 0 + if (header & 0x3fc00000) + fatal("CMDFIFO packet 5 has byte disables set %08x\n", header); +#endif num = (header >> 3) & 0x7ffff; addr = cmdfifo_get(voodoo) & 0xffffff; if (!num) num = 1; - // voodoo_fifo_log("CMDFIFO5 addr=%08x num=%i\n", addr, num); +#if 0 + voodoo_fifo_log("CMDFIFO5 addr=%08x num=%i\n", addr, num); +#endif switch (header >> 30) { case 0: /*Linear framebuffer (Banshee)*/ case 1: /*Planar YUV*/ if (voodoo->texture_present[0][(addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT]) { - // voodoo_fifo_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#if 0 + voodoo_fifo_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#endif flush_texture_cache(voodoo, addr & voodoo->texture_mask, 0); } if (voodoo->texture_present[1][(addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT]) { - // voodoo_fifo_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#if 0 + voodoo_fifo_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#endif flush_texture_cache(voodoo, addr & voodoo->texture_mask, 1); } while (num--) { diff --git a/src/video/vid_voodoo_reg.c b/src/video/vid_voodoo_reg.c index 51b9568b8..4a66161f5 100644 --- a/src/video/vid_voodoo_reg.c +++ b/src/video/vid_voodoo_reg.c @@ -70,9 +70,9 @@ voodoo_reg_log(const char *fmt, ...) #endif void -voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) +voodoo_reg_writel(uint32_t addr, uint32_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; void (*voodoo_recalc_tex)(voodoo_t * voodoo, int tmu) = NULL; union { uint32_t i; @@ -89,7 +89,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo_recalc_tex = voodoo_recalc_tex12; tempif.i = val; - // voodoo_reg_log("voodoo_reg_write_l: addr=%08x val=%08x(%f) chip=%x\n", addr, val, tempif.f, chip); +#if 0 + voodoo_reg_log("voodoo_reg_write_l: addr=%08x val=%08x(%f) chip=%x\n", addr, val, tempif.f, chip); +#endif addr &= 0x3fc; if ((voodoo->fbiInit3 & FBIINIT3_REMAP) && addr < 0x100 && ad21) @@ -97,7 +99,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) switch (addr) { case SST_swapbufferCMD: if (voodoo->type >= VOODOO_BANSHEE) { - // voodoo_reg_log("swapbufferCMD %08x %08x\n", val, voodoo->leftOverlayBuf); +#if 0 + voodoo_reg_log("swapbufferCMD %08x %08x\n", val, voodoo->leftOverlayBuf); +#endif voodoo_wait_for_render_thread_idle(voodoo); if (!(val & 1)) { @@ -136,8 +140,10 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->params.swapbufferCMD = val; - // voodoo_reg_log("Swap buffer %08x %d %p %i\n", val, voodoo->swap_count, &voodoo->swap_count, (voodoo == voodoo->set->voodoos[1]) ? 1 : 0); - // voodoo->front_offset = params->front_offset; +#if 0 + voodoo_reg_log("Swap buffer %08x %d %p %i\n", val, voodoo->swap_count, &voodoo->swap_count, (voodoo == voodoo->set->voodoos[1]) ? 1 : 0); + voodoo->front_offset = params->front_offset; +#endif voodoo_wait_for_render_thread_idle(voodoo); if (!(val & 1)) { memset(voodoo->dirty_line, 1, sizeof(voodoo->dirty_line)); @@ -670,7 +676,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) if (voodoo->type >= VOODOO_BANSHEE) { voodoo->params.draw_offset = val & 0xfffff0; voodoo->fb_write_offset = voodoo->params.draw_offset; - // voodoo_reg_log("colorBufferAddr=%06x\n", voodoo->params.draw_offset); +#if 0 + voodoo_reg_log("colorBufferAddr=%06x\n", voodoo->params.draw_offset); +#endif } break; case SST_colBufferStride: @@ -679,10 +687,14 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->params.col_tiled = voodoo->col_tiled; if (voodoo->col_tiled) { voodoo->row_width = (val & 0x7f) * 128 * 32; - // voodoo_reg_log("colBufferStride tiled = %i bytes, tiled %08x\n", voodoo->row_width, val); +#if 0 + voodoo_reg_log("colBufferStride tiled = %i bytes, tiled %08x\n", voodoo->row_width, val); +#endif } else { voodoo->row_width = val & 0x3fff; - // voodoo_reg_log("colBufferStride linear = %i bytes, linear\n", voodoo->row_width); +#if 0 + voodoo_reg_log("colBufferStride linear = %i bytes, linear\n", voodoo->row_width); +#endif } voodoo->params.row_width = voodoo->row_width; } @@ -690,7 +702,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) case SST_auxBufferAddr: if (voodoo->type >= VOODOO_BANSHEE) { voodoo->params.aux_offset = val & 0xfffff0; - // pclog("auxBufferAddr=%06x\n", voodoo->params.aux_offset); +#if 0 + pclog("auxBufferAddr=%06x\n", voodoo->params.aux_offset); +#endif } break; case SST_auxBufferStride: @@ -699,10 +713,14 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->params.aux_tiled = voodoo->aux_tiled; if (voodoo->aux_tiled) { voodoo->aux_row_width = (val & 0x7f) * 128 * 32; - // voodoo_reg_log("auxBufferStride tiled = %i bytes, tiled\n", voodoo->aux_row_width); +#if 0 + voodoo_reg_log("auxBufferStride tiled = %i bytes, tiled\n", voodoo->aux_row_width); +#endif } else { voodoo->aux_row_width = val & 0x3fff; - // voodoo_reg_log("auxBufferStride linear = %i bytes, linear\n", voodoo->aux_row_width); +#if 0 + voodoo_reg_log("auxBufferStride linear = %i bytes, linear\n", voodoo->aux_row_width); +#endif } voodoo->params.aux_row_width = voodoo->aux_row_width; } @@ -726,12 +744,16 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) case SST_sVx: tempif.i = val; voodoo->verts[3].sVx = tempif.f; - // voodoo_reg_log("sVx[%i]=%f\n", voodoo->vertex_num, tempif.f); +#if 0 + voodoo_reg_log("sVx[%i]=%f\n", voodoo->vertex_num, tempif.f); +#endif break; case SST_sVy: tempif.i = val; voodoo->verts[3].sVy = tempif.f; - // voodoo_reg_log("sVy[%i]=%f\n", voodoo->vertex_num, tempif.f); +#if 0 + voodoo_reg_log("sVy[%i]=%f\n", voodoo->vertex_num, tempif.f); +#endif break; case SST_sARGB: voodoo->verts[3].sBlue = (float) (val & 0xff); @@ -789,7 +811,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) break; case SST_sBeginTriCMD: - // voodoo_reg_log("sBeginTriCMD %i %f\n", voodoo->vertex_num, voodoo->verts[4].sVx); +#if 0 + voodoo_reg_log("sBeginTriCMD %i %f\n", voodoo->vertex_num, voodoo->verts[4].sVx); +#endif voodoo->verts[0] = voodoo->verts[3]; voodoo->verts[1] = voodoo->verts[3]; voodoo->verts[2] = voodoo->verts[3]; @@ -800,7 +824,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->cull_pingpong = 0; break; case SST_sDrawTriCMD: - // voodoo_reg_log("sDrawTriCMD %i %i\n", voodoo->num_verticies, voodoo->sSetupMode & SETUPMODE_STRIP_MODE); +#if 0 + voodoo_reg_log("sDrawTriCMD %i %i\n", voodoo->num_verticies, voodoo->sSetupMode & SETUPMODE_STRIP_MODE); +#endif /*I'm not sure this is the vertex selection algorithm actually used in the 3dfx chips, but this works with a number of games that switch between strip and fan mode in the middle of a run (eg Black & White, Viper Racing)*/ @@ -840,7 +866,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->num_verticies++; if (voodoo->num_verticies == 3) { - // voodoo_reg_log("triangle_setup\n"); +#if 0 + voodoo_reg_log("triangle_setup\n"); +#endif voodoo_triangle_setup(voodoo); voodoo->cull_pingpong = !voodoo->cull_pingpong; @@ -852,7 +880,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->bltSrcBaseAddr = val & 0x3fffff; break; case SST_bltDstBaseAddr: - // voodoo_reg_log("Write bltDstBaseAddr %08x\n", val); +#if 0 + voodoo_reg_log("Write bltDstBaseAddr %08x\n", val); +#endif voodoo->bltDstBaseAddr = val & 0x3fffff; break; case SST_bltXYStrides: @@ -969,7 +999,9 @@ voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->params.texBaseAddr[0] = val & 0xfffff0; else voodoo->params.texBaseAddr[0] = (val & 0x7ffff) << 3; - // voodoo_reg_log("texBaseAddr = %08x %08x\n", voodoo->params.texBaseAddr[0], val); +#if 0 + voodoo_reg_log("texBaseAddr = %08x %08x\n", voodoo->params.texBaseAddr[0], val); +#endif voodoo_recalc_tex(voodoo, 0); } if (chip & CHIP_TREX1) { diff --git a/src/video/vid_voodoo_render.c b/src/video/vid_voodoo_render.c index 4b09cfadb..052a0b51e 100644 --- a/src/video/vid_voodoo_render.c +++ b/src/video/vid_voodoo_render.c @@ -178,7 +178,9 @@ voodoo_fls(uint16_t val) { int num = 0; - // voodoo_render_log("fls(%04x) = ", val); +#if 0 + voodoo_render_log("fls(%04x) = ", val); +#endif if (!(val & 0xff00)) { num += 8; val <<= 8; @@ -195,7 +197,9 @@ voodoo_fls(uint16_t val) num += 1; val <<= 1; } - // voodoo_render_log("%i %04x\n", num, val); +#if 0 + voodoo_render_log("%i %04x\n", num, val); +#endif return num; } @@ -241,13 +245,12 @@ tex_read(voodoo_state_t *state, voodoo_texture_state_t *texture_state, int tmu) #define HIGH4(x) ((x & 0xf0) | ((x & 0xf0) >> 4)) static inline void -tex_read_4(voodoo_state_t *state, voodoo_texture_state_t *texture_state, int s, int t, int *d, int tmu, int x) +tex_read_4(voodoo_state_t *state, voodoo_texture_state_t *texture_state, int s, int t, int *d, int tmu, UNUSED(int x)) { rgba_u dat[4]; if (((s | (s + 1)) & ~texture_state->w_mask) || ((t | (t + 1)) & ~texture_state->h_mask)) { - int c; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { int _s = s + (c & 1); int _t = t + ((c & 2) >> 1); @@ -289,7 +292,8 @@ voodoo_get_texture(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *st { voodoo_texture_state_t texture_state; int d[4]; - int s, t; + int s; + int t; int tex_lod = state->tex_lod[tmu][state->lod]; texture_state.w_mask = state->tex_w_mask[tmu][state->lod]; @@ -306,7 +310,8 @@ voodoo_get_texture(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *st } if (voodoo->bilinear_enabled && params->textureMode[tmu] & 6) { - int _ds, dt; + int _ds; + int dt; state->tex_s -= 1 << (3 + tex_lod); state->tex_t -= 1 << (3 + tex_lod); @@ -319,36 +324,44 @@ voodoo_get_texture(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *st s >>= 4; t >>= 4; - // if (x == 80) - // if (voodoo_output) - // voodoo_render_log("s=%08x t=%08x _ds=%02x _dt=%02x\n", s, t, _ds, dt); +#if 0 + if (x == 80) + if (voodoo_output) + voodoo_render_log("s=%08x t=%08x _ds=%02x _dt=%02x\n", s, t, _ds, dt); +#endif d[0] = (16 - _ds) * (16 - dt); d[1] = _ds * (16 - dt); d[2] = (16 - _ds) * dt; d[3] = _ds * dt; - // texture_state.s = s; - // texture_state.t = t; +#if 0 + texture_state.s = s; + texture_state.t = t; +#endif tex_read_4(state, &texture_state, s, t, d, tmu, x); - /* state->tex_r = (tex_samples[0].rgba.r * d[0] + tex_samples[1].rgba.r * d[1] + tex_samples[2].rgba.r * d[2] + tex_samples[3].rgba.r * d[3]) >> 8; - state->tex_g = (tex_samples[0].rgba.g * d[0] + tex_samples[1].rgba.g * d[1] + tex_samples[2].rgba.g * d[2] + tex_samples[3].rgba.g * d[3]) >> 8; - state->tex_b = (tex_samples[0].rgba.b * d[0] + tex_samples[1].rgba.b * d[1] + tex_samples[2].rgba.b * d[2] + tex_samples[3].rgba.b * d[3]) >> 8; - state->tex_a = (tex_samples[0].rgba.a * d[0] + tex_samples[1].rgba.a * d[1] + tex_samples[2].rgba.a * d[2] + tex_samples[3].rgba.a * d[3]) >> 8;*/ - /* state->tex_r = tex_samples[0].r; - state->tex_g = tex_samples[0].g; - state->tex_b = tex_samples[0].b; - state->tex_a = tex_samples[0].a;*/ +#if 0 + state->tex_r = (tex_samples[0].rgba.r * d[0] + tex_samples[1].rgba.r * d[1] + tex_samples[2].rgba.r * d[2] + tex_samples[3].rgba.r * d[3]) >> 8; + state->tex_g = (tex_samples[0].rgba.g * d[0] + tex_samples[1].rgba.g * d[1] + tex_samples[2].rgba.g * d[2] + tex_samples[3].rgba.g * d[3]) >> 8; + state->tex_b = (tex_samples[0].rgba.b * d[0] + tex_samples[1].rgba.b * d[1] + tex_samples[2].rgba.b * d[2] + tex_samples[3].rgba.b * d[3]) >> 8; + state->tex_a = (tex_samples[0].rgba.a * d[0] + tex_samples[1].rgba.a * d[1] + tex_samples[2].rgba.a * d[2] + tex_samples[3].rgba.a * d[3]) >> 8;*/ +#endif +#if 0 + state->tex_r = tex_samples[0].r; + state->tex_g = tex_samples[0].g; + state->tex_b = tex_samples[0].b; + state->tex_a = tex_samples[0].a; +#endif } else { - // rgba_t tex_samples; - // voodoo_texture_state_t texture_state; - // int s = state->tex_s >> (18+state->lod); - // int t = state->tex_t >> (18+state->lod); - // int s, t; - - // state->tex_s -= 1 << (17+state->lod); - // state->tex_t -= 1 << (17+state->lod); +#if 0 + rgba_t tex_samples; + voodoo_texture_state_t texture_state; + int s = state->tex_s >> (18+state->lod); + int t = state->tex_t >> (18+state->lod); + state->tex_s -= 1 << (17+state->lod); + state->tex_t -= 1 << (17+state->lod); +#endif s = state->tex_s >> (4 + tex_lod); t = state->tex_t >> (4 + tex_lod); @@ -356,10 +369,12 @@ voodoo_get_texture(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *st texture_state.t = t; tex_read(state, &texture_state, tmu); - /* state->tex_r = tex_samples[0].rgba.r; - state->tex_g = tex_samples[0].rgba.g; - state->tex_b = tex_samples[0].rgba.b; - state->tex_a = tex_samples[0].rgba.a;*/ +#if 0 + state->tex_r = tex_samples[0].rgba.r; + state->tex_g = tex_samples[0].rgba.g; + state->tex_b = tex_samples[0].rgba.b; + state->tex_a = tex_samples[0].rgba.a; +#endif } } @@ -407,10 +422,20 @@ voodoo_tmu_fetch(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat static inline void voodoo_tmu_fetch_and_blend(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *state, int x) { - int r, g, b, a; - int c_reverse, a_reverse; - // int c_reverse1, a_reverse1; - int factor_r = 0, factor_g = 0, factor_b = 0, factor_a = 0; + int r; + int g; + int b; + int a; + int c_reverse; + int a_reverse; +#if 0 + int c_reverse1; + int a_reverse1; +#endif + int factor_r = 0; + int factor_g = 0; + int factor_b = 0; + int factor_a = 0; voodoo_tmu_fetch(voodoo, params, state, 1, x); @@ -421,8 +446,10 @@ voodoo_tmu_fetch_and_blend(voodoo_t *voodoo, voodoo_params_t *params, voodoo_sta c_reverse = !tc_reverse_blend; a_reverse = !tca_reverse_blend; } - /* c_reverse1 = c_reverse; - a_reverse1 = a_reverse;*/ +#if 0 + c_reverse1 = c_reverse; + a_reverse1 = a_reverse; +#endif if (tc_sub_clocal_1) { switch (tc_mselect_1) { case TC_MSELECT_ZERO: @@ -628,32 +655,33 @@ int voodoo_recomp = 0; static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *state, int ystart, int yend, int odd_even) { - /* int rgb_sel = params->fbzColorPath & 3; - int a_sel = (params->fbzColorPath >> 2) & 3; - int cc_localselect = params->fbzColorPath & (1 << 4); - int cca_localselect = (params->fbzColorPath >> 5) & 3; - int cc_localselect_override = params->fbzColorPath & (1 << 7); - int cc_zero_other = params->fbzColorPath & (1 << 8); - int cc_sub_clocal = params->fbzColorPath & (1 << 9); - int cc_mselect = (params->fbzColorPath >> 10) & 7; - int cc_reverse_blend = params->fbzColorPath & (1 << 13); - int cc_add = (params->fbzColorPath >> 14) & 3; - int cc_add_alocal = params->fbzColorPath & (1 << 15); - int cc_invert_output = params->fbzColorPath & (1 << 16); - int cca_zero_other = params->fbzColorPath & (1 << 17); - int cca_sub_clocal = params->fbzColorPath & (1 << 18); - int cca_mselect = (params->fbzColorPath >> 19) & 7; - int cca_reverse_blend = params->fbzColorPath & (1 << 22); - int cca_add = (params->fbzColorPath >> 23) & 3; - int cca_invert_output = params->fbzColorPath & (1 << 25); - int src_afunc = (params->alphaMode >> 8) & 0xf; - int dest_afunc = (params->alphaMode >> 12) & 0xf; - int alpha_func = (params->alphaMode >> 1) & 7; - int a_ref = params->alphaMode >> 24; - int depth_op = (params->fbzMode >> 5) & 7; - int dither = params->fbzMode & FBZ_DITHER;*/ +#if 0 + int rgb_sel = params->fbzColorPath & 3; + int a_sel = (params->fbzColorPath >> 2) & 3; + int cc_localselect = params->fbzColorPath & (1 << 4); + int cca_localselect = (params->fbzColorPath >> 5) & 3; + int cc_localselect_override = params->fbzColorPath & (1 << 7); + int cc_zero_other = params->fbzColorPath & (1 << 8); + int cc_sub_clocal = params->fbzColorPath & (1 << 9); + int cc_mselect = (params->fbzColorPath >> 10) & 7; + int cc_reverse_blend = params->fbzColorPath & (1 << 13); + int cc_add = (params->fbzColorPath >> 14) & 3; + int cc_add_alocal = params->fbzColorPath & (1 << 15); + int cc_invert_output = params->fbzColorPath & (1 << 16); + int cca_zero_other = params->fbzColorPath & (1 << 17); + int cca_sub_clocal = params->fbzColorPath & (1 << 18); + int cca_mselect = (params->fbzColorPath >> 19) & 7; + int cca_reverse_blend = params->fbzColorPath & (1 << 22); + int cca_add = (params->fbzColorPath >> 23) & 3; + int cca_invert_output = params->fbzColorPath & (1 << 25); + int src_afunc = (params->alphaMode >> 8) & 0xf; + int dest_afunc = (params->alphaMode >> 12) & 0xf; + int alpha_func = (params->alphaMode >> 1) & 7; + int a_ref = params->alphaMode >> 24; + int depth_op = (params->fbzMode >> 5) & 7; + int dither = params->fbzMode & FBZ_DITHER;*/ +#endif int texels; - int c; #ifndef NO_CODEGEN uint8_t (*voodoo_draw)(voodoo_state_t * state, voodoo_params_t * params, int x, int real_y); #endif @@ -672,7 +700,7 @@ voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t * // int last_x; // voodoo_render_log("voodoo_triangle : bottom-half %X %X %X %X %X %i %i %i %i\n", xstart, xend, dx1, dx2, dx2 * 36, xdir, y, yend, ydir); - for (c = 0; c <= LOD_MAX; c++) { + for (uint8_t c = 0; c <= LOD_MAX; c++) { state->tex[0][c] = &voodoo->texture_cache[0][params->tex_entry[0]].data[texture_offset[c]]; state->tex[1][c] = &voodoo->texture_cache[1][params->tex_entry[1]].data[texture_offset[c]]; } @@ -713,7 +741,9 @@ voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t * yend = params->clipHighY; state->y = ystart; - // yend--; +#if 0 + yend--; +#endif if (SLI_ENABLED) { int test_y; @@ -750,14 +780,18 @@ voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t * #endif voodoo_render_log("dxAB=%08x dxBC=%08x dxAC=%08x\n", state->dxAB, state->dxBC, state->dxAC); - // voodoo_render_log("Start %i %i\n", ystart, voodoo->fbzMode & (1 << 17)); +#if 0 + voodoo_render_log("Start %i %i\n", ystart, voodoo->fbzMode & (1 << 17)); +#endif for (; state->y < yend; state->y += y_diff) { - int x, x2; + int x; + int x2; int real_y = (state->y << 4) + 8; int start_x; int dx; - uint16_t *fb_mem, *aux_mem; + uint16_t *fb_mem; + uint16_t *aux_mem; state->ir = state->base_r; state->ig = state->base_g; @@ -904,17 +938,35 @@ voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t * voodoo->fbiPixelsIn++; voodoo_render_log(" X=%03i T=%08x\n", x, state->tmu0_t); - // if (voodoo->fbzMode & FBZ_RGB_WMASK) +#if 0 + if (voodoo->fbzMode & FBZ_RGB_WMASK) +#endif { int update = 1; - uint8_t cother_r = 0, cother_g = 0, cother_b = 0, aother; - uint8_t clocal_r, clocal_g, clocal_b, alocal; - int src_r = 0, src_g = 0, src_b = 0, src_a = 0; - int msel_r, msel_g, msel_b, msel_a; - uint8_t dest_r, dest_g, dest_b, dest_a; + uint8_t cother_r = 0; + uint8_t cother_g = 0; + uint8_t cother_b = 0; + uint8_t aother; + uint8_t clocal_r; + uint8_t clocal_g; + uint8_t clocal_b; + uint8_t alocal; + int src_r = 0; + int src_g = 0; + int src_b = 0; + int src_a = 0; + int msel_r; + int msel_g; + int msel_b; + int msel_a; + uint8_t dest_r; + uint8_t dest_g; + uint8_t dest_b; + uint8_t dest_a; uint16_t dat; int sel; - int32_t new_depth, w_depth; + int32_t new_depth; + int32_t w_depth; if (state->w & 0xffff00000000) w_depth = 0; @@ -922,13 +974,15 @@ voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t * w_depth = 0xf001; else { int exp = voodoo_fls((uint16_t) ((uint32_t) state->w >> 16)); - int mant = ((~(uint32_t) state->w >> (19 - exp))) & 0xfff; + int mant = (~(uint32_t) state->w >> (19 - exp)) & 0xfff; w_depth = (exp << 12) + mant + 1; if (w_depth > 0xffff) w_depth = 0xffff; } - // w_depth = CLAMP16(w_depth); +#if 0 + w_depth = CLAMP16(w_depth); +#endif if (params->fbzMode & FBZ_W_BUFFER) new_depth = w_depth; @@ -1328,9 +1382,11 @@ voodoo_triangle(voodoo_t *voodoo, voodoo_params_t *params, int odd_even) voodoo_state_t state; int vertexAy_adjusted; int vertexCy_adjusted; - int dx, dy; + int dx; + int dy; - uint64_t tempdx, tempdy; + uint64_t tempdx; + uint64_t tempdy; uint64_t tempLOD; int LOD; int lodbias; diff --git a/src/video/vid_voodoo_setup.c b/src/video/vid_voodoo_setup.c index 40018ddf8..e1d13ba35 100644 --- a/src/video/vid_voodoo_setup.c +++ b/src/video/vid_voodoo_setup.c @@ -60,9 +60,14 @@ voodoo_setup_log(const char *fmt, ...) void voodoo_triangle_setup(voodoo_t *voodoo) { - float dxAB, dxBC, dyAB, dyBC; + float dxAB; + float dxBC; + float dyAB; + float dyBC; float area; - int va = 0, vb = 1, vc = 2; + int va = 0; + int vb = 1; + int vc = 2; vert_t verts[3]; verts[0] = voodoo->verts[0]; diff --git a/src/video/vid_voodoo_texture.c b/src/video/vid_voodoo_texture.c index 4f81f6d00..8b8f1366d 100644 --- a/src/video/vid_voodoo_texture.c +++ b/src/video/vid_voodoo_texture.c @@ -62,9 +62,9 @@ void voodoo_recalc_tex12(voodoo_t *voodoo, int tmu) { int aspect = (voodoo->params.tLOD[tmu] >> 21) & 3; - int width = 256, height = 256; + int width = 256; + int height = 256; int shift = 8; - int lod; uint32_t base = voodoo->params.texBaseAddr[tmu]; uint32_t offset = 0; int tex_lod = 0; @@ -85,7 +85,7 @@ voodoo_recalc_tex12(voodoo_t *voodoo, int tmu) base = voodoo->params.texBaseAddr1[tmu]; } - for (lod = 0; lod <= LOD_MAX + 1; lod++) { + for (uint8_t lod = 0; lod <= LOD_MAX + 1; lod++) { if (!width) width = 1; if (!height) @@ -149,14 +149,17 @@ void voodoo_recalc_tex3(voodoo_t *voodoo, int tmu) { int aspect = (voodoo->params.tLOD[tmu] >> 21) & 3; - int width = 256, height = 256; + int width = 256; + int height = 256; int shift = 8; int lod; uint32_t base = voodoo->params.texBaseAddr[tmu]; uint32_t offset = 0; int tex_lod = 0; uint32_t offsets[LOD_MAX + 3]; - int widths[LOD_MAX + 3], heights[LOD_MAX + 3], shifts[LOD_MAX + 3]; + int widths[LOD_MAX + 3]; + int heights[LOD_MAX + 3]; + int shifts[LOD_MAX + 3]; if (voodoo->params.tLOD[tmu] & LOD_S_IS_WIDER) height >>= aspect; @@ -237,10 +240,11 @@ voodoo_recalc_tex3(voodoo_t *voodoo, int tmu) void voodoo_use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) { - int c, d; - int lod; - int lod_min, lod_max; - uint32_t addr = 0, addr_end; + int c; + int lod_min; + int lod_max; + uint32_t addr = 0; + uint32_t addr_end; uint32_t palette_checksum; lod_min = (params->tLOD[tmu] >> 2) & 15; @@ -301,10 +305,11 @@ voodoo_use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) // voodoo_texture_log(" add new texture to %i tformat=%i %08x LOD=%i-%i tmu=%i\n", c, voodoo->params.tformat[tmu], params->texBaseAddr[tmu], lod_min, lod_max, tmu); lod_min = MIN(lod_min, 8); lod_max = MIN(lod_max, 8); - for (lod = lod_min; lod <= lod_max; lod++) { + for (int lod = lod_min; lod <= lod_max; lod++) { uint32_t *base = &voodoo->texture_cache[tmu][c].data[texture_offset[lod]]; uint32_t tex_addr = params->tex_base[tmu][lod] & voodoo->texture_mask; - int x, y; + int x; + int y; int shift = 8 - params->tex_lod[tmu][lod]; rgba_u *pal; @@ -525,7 +530,7 @@ voodoo_use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) } else voodoo->texture_cache[tmu][c].addr_start[3] = voodoo->texture_cache[tmu][c].addr_end[3] = 0; - for (d = 0; d < 4; d++) { + for (uint8_t d = 0; d < 4; d++) { addr = voodoo->texture_cache[tmu][c].addr_start[d]; addr_end = voodoo->texture_cache[tmu][c].addr_end[d]; @@ -543,15 +548,14 @@ void flush_texture_cache(voodoo_t *voodoo, uint32_t dirty_addr, int tmu) { int wait_for_idle = 0; - int c; memset(voodoo->texture_present[tmu], 0, sizeof(voodoo->texture_present[0])); - // voodoo_texture_log("Evict %08x %i\n", dirty_addr, sizeof(voodoo->texture_present)); - for (c = 0; c < TEX_CACHE_MAX; c++) { +#if 0 + voodoo_texture_log("Evict %08x %i\n", dirty_addr, sizeof(voodoo->texture_present)); +#endif + for (uint8_t c = 0; c < TEX_CACHE_MAX; c++) { if (voodoo->texture_cache[tmu][c].base != -1) { - int d; - - for (d = 0; d < 4; d++) { + for (uint8_t d = 0; d < 4; d++) { int addr_start = voodoo->texture_cache[tmu][c].addr_start[d]; int addr_end = voodoo->texture_cache[tmu][c].addr_end[d]; @@ -581,10 +585,12 @@ flush_texture_cache(voodoo_t *voodoo, uint32_t dirty_addr, int tmu) } void -voodoo_tex_writel(uint32_t addr, uint32_t val, void *p) +voodoo_tex_writel(uint32_t addr, uint32_t val, void *priv) { - int lod, s, t; - voodoo_t *voodoo = (voodoo_t *) p; + int lod; + int s; + int t; + voodoo_t *voodoo = (voodoo_t *) priv; int tmu; if (addr & 0x400000) @@ -614,8 +620,10 @@ voodoo_tex_writel(uint32_t addr, uint32_t val, void *p) if (lod > LOD_MAX) return; - // if (addr >= 0x200000) - // return; +#if 0 + if (addr >= 0x200000) + return; +#endif if (voodoo->params.tformat[tmu] & 8) addr = voodoo->params.tex_base[tmu][lod] + s * 2 + (t << voodoo->params.tex_shift[tmu][lod]) * 2; @@ -625,11 +633,15 @@ voodoo_tex_writel(uint32_t addr, uint32_t val, void *p) addr = (addr & 0x1ffffc) + voodoo->params.tex_base[tmu][0]; if (voodoo->texture_present[tmu][(addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT]) { - // voodoo_texture_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#if 0 + voodoo_texture_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#endif flush_texture_cache(voodoo, addr & voodoo->texture_mask, tmu); } if (voodoo->type == VOODOO_3 && voodoo->texture_present[tmu ^ 1][(addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT]) { - // voodoo_texture_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#if 0 + voodoo_texture_log("texture_present at %08x %i\n", addr, (addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#endif flush_texture_cache(voodoo, addr & voodoo->texture_mask, tmu ^ 1); } *(uint32_t *) (&voodoo->tex_mem[tmu][addr & voodoo->texture_mask]) = val; diff --git a/src/video/vid_wy700.c b/src/video/vid_wy700.c index 1a4babb99..6695709cc 100644 --- a/src/video/vid_wy700.c +++ b/src/video/vid_wy700.c @@ -216,16 +216,16 @@ static int cgacols[256][2][2]; static int mdacols[256][2][2]; void wy700_recalctimings(wy700_t *wy700); -void wy700_write(uint32_t addr, uint8_t val, void *p); -uint8_t wy700_read(uint32_t addr, void *p); +void wy700_write(uint32_t addr, uint8_t val, void *priv); +uint8_t wy700_read(uint32_t addr, void *priv); void wy700_checkchanges(wy700_t *wy700); static video_timings_t timing_wy700 = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; void -wy700_out(uint16_t addr, uint8_t val, void *p) +wy700_out(uint16_t addr, uint8_t val, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; switch (addr) { /* These three registers are only mapped in the 3Dx range, * not the 3Bx range. */ @@ -287,9 +287,9 @@ wy700_out(uint16_t addr, uint8_t val, void *p) } uint8_t -wy700_in(uint16_t addr, void *p) +wy700_in(uint16_t addr, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; switch (addr) { case 0x3b0: case 0x3b2: @@ -327,7 +327,8 @@ wy700_in(uint16_t addr, void *p) void wy700_checkchanges(wy700_t *wy700) { - uint8_t curstart, curend; + uint8_t curstart; + uint8_t curend; if (wy700->last_03D8 == wy700->cga_ctrl && wy700->last_03DD == (wy700->wy700_base & 0xFF) && wy700->last_03DF == wy700->wy700_control && wy700->last_crtc_0E == wy700->cga_crtc[0x0E]) { return; /* Nothing changed */ @@ -455,9 +456,9 @@ wy700_checkchanges(wy700_t *wy700) } void -wy700_write(uint32_t addr, uint8_t val, void *p) +wy700_write(uint32_t addr, uint8_t val, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; if (wy700->wy700_mode & 0x80) /* High-res mode. */ { @@ -474,9 +475,9 @@ wy700_write(uint32_t addr, uint8_t val, void *p) } uint8_t -wy700_read(uint32_t addr, void *p) +wy700_read(uint32_t addr, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; if (wy700->wy700_mode & 0x80) /* High-res mode. */ { addr &= 0xFFFF; @@ -495,7 +496,8 @@ void wy700_recalctimings(wy700_t *wy700) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; disptime = wy700->real_crtc[0] + 1; _dispontime = wy700->real_crtc[1]; @@ -510,14 +512,16 @@ wy700_recalctimings(wy700_t *wy700) void wy700_textline(wy700_t *wy700) { - int x; int w = (wy700->wy700_mode == 0) ? 40 : 80; int cw = (wy700->wy700_mode == 0) ? 32 : 16; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint8_t bitmap[2]; uint8_t *fontbase = &fontdatw[0][0]; - int blink, c; - int drawcursor, cursorline; + int blink; + int c; + int drawcursor; + int cursorline; int mda = 0; uint16_t addr; uint8_t sc; @@ -544,7 +548,7 @@ wy700_textline(wy700_t *wy700) cursorline = ((wy700->real_crtc[10] & 0x1F) <= sc) && ((wy700->real_crtc[11] & 0x1F) >= sc); } - for (x = 0; x < w; x++) { + for (int x = 0; x < w; x++) { chr = wy700->vram[(addr + 2 * x) & 0x3FFF]; attr = wy700->vram[(addr + 2 * x + 1) & 0x3FFF]; drawcursor = ((ma == ca) && cursorline && wy700->enabled && (wy700->cga_ctrl & 8) && (wy700->blink & 16)); @@ -588,7 +592,7 @@ wy700_textline(wy700_t *wy700) void wy700_cgaline(wy700_t *wy700) { - int x, c; + int c; uint32_t dat; uint8_t ink = 0; uint16_t addr; @@ -598,7 +602,7 @@ wy700_cgaline(wy700_t *wy700) /* The fixed mode setting here programs the real CRTC with a screen * width to 20, so draw in 20 fixed chunks of 4 bytes each */ - for (x = 0; x < 20; x++) { + for (uint8_t x = 0; x < 20; x++) { dat = ((wy700->vram[addr & 0x3FFF] << 24) | (wy700->vram[(addr + 1) & 0x3FFF] << 16) | (wy700->vram[(addr + 2) & 0x3FFF] << 8) | (wy700->vram[(addr + 3) & 0x3FFF])); addr += 4; @@ -639,14 +643,14 @@ wy700_cgaline(wy700_t *wy700) void wy700_medresline(wy700_t *wy700) { - int x, c; + int c; uint32_t dat; uint8_t ink = 0; uint32_t addr; addr = (wy700->displine >> 1) * 80 + 4 * wy700->wy700_base; - for (x = 0; x < 20; x++) { + for (uint8_t x = 0; x < 20; x++) { dat = ((wy700->vram[addr & 0x1FFFF] << 24) | (wy700->vram[(addr + 1) & 0x1FFFF] << 16) | (wy700->vram[(addr + 2) & 0x1FFFF] << 8) | (wy700->vram[(addr + 3) & 0x1FFFF])); addr += 4; @@ -689,7 +693,7 @@ wy700_medresline(wy700_t *wy700) void wy700_hiresline(wy700_t *wy700) { - int x, c; + int c; uint32_t dat; uint8_t ink = 0; uint32_t addr; @@ -701,7 +705,7 @@ wy700_hiresline(wy700_t *wy700) if (wy700->displine & 1) addr += 0x10000; } - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { dat = ((wy700->vram[addr & 0x1FFFF] << 24) | (wy700->vram[(addr + 1) & 0x1FFFF] << 16) | (wy700->vram[(addr + 2) & 0x1FFFF] << 8) | (wy700->vram[(addr + 3) & 0x1FFFF])); addr += 4; @@ -741,9 +745,9 @@ wy700_hiresline(wy700_t *wy700) } void -wy700_poll(void *p) +wy700_poll(void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; int mode; if (!wy700->linepos) { @@ -955,18 +959,18 @@ wy700_init(const device_t *info) } void -wy700_close(void *p) +wy700_close(void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; free(wy700->vram); free(wy700); } void -wy700_speed_changed(void *p) +wy700_speed_changed(void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; wy700_recalctimings(wy700); } diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index 84c1805ff..350fc1c50 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -1,18 +1,18 @@ /* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. * - * This file is part of the 86Box distribution. + * This file is part of the 86Box distribution. * - * IBM XGA emulation. + * IBM XGA emulation. * * * - * Authors: TheCollector1995. + * Authors: TheCollector1995. * - * Copyright 2022 TheCollector1995. + * Copyright 2022 TheCollector1995. */ #include #include @@ -34,73 +34,136 @@ #include <86box/vid_svga_render.h> #include <86box/vid_xga_device.h> #include "cpu.h" +#include <86box/plat_unused.h> -#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" -#define XGA2_BIOS_PATH "roms/video/xga/xga2_v300.bin" +#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" +#define XGA2_BIOS_PATH "roms/video/xga/xga2_v300.bin" +#define INMOS_XGA_BIOS_PATH "roms/video/xga/InMOS XGA - Fairchild NM27C256Q-150.BIN" -static void xga_ext_outb(uint16_t addr, uint8_t val, void *p); -static uint8_t xga_ext_inb(uint16_t addr, void *p); +static video_timings_t timing_xga_isa = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; +static video_timings_t timing_xga_mca = { .type = VIDEO_MCA, .write_b = 4, .write_w = 5, .write_l = 10, .read_b = 5, .read_w = 5, .read_l = 10 }; -static void +static void xga_ext_outb(uint16_t addr, uint8_t val, void *priv); +static uint8_t xga_ext_inb(uint16_t addr, void *priv); + +static void xga_writew(uint32_t addr, uint16_t val, void *priv); +static uint16_t xga_readw(uint32_t addr, void *priv); + +int xga_has_vga = 0; + +void +svga_xga_out(uint16_t addr, uint8_t val, void *priv) +{ + svga_t *svga = (svga_t *) priv; + uint8_t old; + + if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) + addr ^= 0x60; + + switch (addr) { + case 0x3D4: + svga->crtcreg = val & 0x3f; + return; + case 0x3D5: + if (svga->crtcreg & 0x20) + return; + if ((svga->crtcreg < 7) && (svga->crtc[0x11] & 0x80)) + return; + if ((svga->crtcreg == 7) && (svga->crtc[0x11] & 0x80)) + val = (svga->crtc[7] & ~0x10) | (val & 0x10); + old = svga->crtc[svga->crtcreg]; + svga->crtc[svga->crtcreg] = val; + if (old != val) { + if (svga->crtcreg < 0xe || svga->crtcreg > 0x10) { + if ((svga->crtcreg == 0xc) || (svga->crtcreg == 0xd)) { + svga->fullchange = 3; + svga->ma_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); + } else { + svga->fullchange = changeframecount; + svga_recalctimings(svga); + } + } + } + break; + + default: + break; + } + svga_out(addr, val, svga); +} + +uint8_t +svga_xga_in(uint16_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + uint8_t temp; + + if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) + addr ^= 0x60; + + switch (addr) { + case 0x3D4: + temp = svga->crtcreg; + break; + case 0x3D5: + if (svga->crtcreg & 0x20) + temp = 0xff; + else + temp = svga->crtc[svga->crtcreg]; + break; + default: + temp = svga_in(addr, svga); + break; + } + return temp; +} + +void xga_updatemapping(svga_t *svga) { xga_t *xga = &svga->xga; - // pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, opmodereset1 = %d, access mode = %x, map = %x.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->op_mode_reset, xga->access_mode, svga->gdcreg[6] & 0x0c); - if ((xga->op_mode & 7) >= 4) { - if (xga->aperture_cntl == 1) { +#if 0 + pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, access mode = %x, map = %x, endian reverse = %d, a5test = %d, XGA on = %d.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->access_mode, svga->gdcreg[6] & 0x0c, xga->linear_endian_reverse, xga->a5_test, xga->on); +#endif + if (((xga->op_mode & 7) >= 4) || ((xga->op_mode & 7) == 0)) { + if ((xga->aperture_cntl == 1) || (xga->aperture_cntl == 2)) { mem_mapping_disable(&svga->mapping); - mem_mapping_set_addr(&xga->video_mapping, 0xa0000, 0x10000); + if (xga->aperture_cntl == 1) + mem_mapping_set_addr(&xga->video_mapping, 0xa0000, 0x10000); + else + mem_mapping_set_addr(&xga->video_mapping, 0xb0000, 0x10000); + mem_mapping_enable(&xga->video_mapping); xga->banked_mask = 0xffff; if (!xga->linear_endian_reverse) mem_mapping_disable(&xga->linear_mapping); } else if (xga->aperture_cntl == 0) { -linear: mem_mapping_disable(&svga->mapping); mem_mapping_set_addr(&xga->video_mapping, 0xa0000, 0x10000); mem_mapping_enable(&xga->video_mapping); xga->banked_mask = 0xffff; - if ((xga->pos_regs[4] & 1) && !xga->base_addr_1mb) { - xga->linear_size = 0x400000; - mem_mapping_set_addr(&xga->linear_mapping, xga->linear_base, xga->linear_size); - } else { - if (xga->base_addr_1mb) { - xga->linear_size = 0x100000; - mem_mapping_set_addr(&xga->linear_mapping, xga->base_addr_1mb, xga->linear_size); - } else - mem_mapping_disable(&xga->linear_mapping); - } - xga->on = 0; - vga_on = 1; - if (((xga->op_mode & 7) == 4) && ((svga->gdcreg[6] & 0x0c) == 0x0c) && !xga->a5_test) + if (xga->base_addr_1mb) + mem_mapping_set_addr(&xga->linear_mapping, xga->base_addr_1mb, 0x100000); + else + mem_mapping_set_addr(&xga->linear_mapping, xga->linear_base, 0x400000); + if (((xga->op_mode & 7) == 4) && ((svga->gdcreg[6] & 0x0c) == 0x0c) && !xga->a5_test && xga->on) xga->linear_endian_reverse = 1; - } else { - mem_mapping_disable(&svga->mapping); - mem_mapping_set_addr(&xga->video_mapping, 0xb0000, 0x10000); - mem_mapping_enable(&xga->video_mapping); - xga->banked_mask = 0xffff; - mem_mapping_disable(&xga->linear_mapping); + else if (((xga->op_mode & 7) == 0) && ((svga->gdcreg[6] & 0x0c) == 0x0c) && !xga->a5_test && !xga->on) { + xga->linear_endian_reverse = 1; + } + if (xga->a5_test && (xga->access_mode & 8) && !xga->linear_endian_reverse) { + xga->on = 0; + vga_on = !xga->on; + } } - } else { - if (!(xga->op_mode & 7)) { - goto linear; - } - if (xga->aperture_cntl == 2) { - mem_mapping_disable(&svga->mapping); - mem_mapping_set_addr(&xga->video_mapping, 0xb0000, 0x10000); - mem_mapping_enable(&xga->video_mapping); - xga->banked_mask = 0xffff; - } else { - mem_mapping_disable(&svga->mapping); - mem_mapping_set_addr(&xga->video_mapping, 0xa0000, 0x10000); - mem_mapping_enable(&xga->video_mapping); - xga->banked_mask = 0xffff; - } - mem_mapping_disable(&xga->linear_mapping); - xga->on = 0; - vga_on = 1; +#if 0 + pclog("XGA opmode (extended) = %d, disp mode = %d, aperture = %d.\n", xga->op_mode & 7, xga->disp_cntl_2 & 7, xga->aperture_cntl); +#endif } +#if 0 + pclog("VGA on = %d.\n", vga_on); +#endif } void @@ -132,23 +195,24 @@ xga_recalctimings(svga_t *svga) xga->ma_latch = xga->disp_start_addr; - switch (xga->clk_sel_1 & 0x0c) { + switch ((xga->clk_sel_1 >> 2) & 3) { case 0: if (xga->clk_sel_2 & 0x80) { - svga->clock = (cpuclock * (double) (1ull << 32)) / 41539000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 41539000.0; } else { - svga->clock = (cpuclock * (double) (1ull << 32)) / 25175000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 25175000.0; } break; - case 4: - svga->clock = (cpuclock * (double) (1ull << 32)) / 28322000.0; + case 1: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 28322000.0; break; - case 0x0c: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + case 3: + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + break; + + default: break; } - } else { - vga_on = 1; } } @@ -292,6 +356,8 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) case 0x51: xga->disp_cntl_2 = val; + xga->on = ((val & 7) >= 3); + vga_on = !xga->on; svga_recalctimings(svga); break; @@ -300,6 +366,10 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) svga_recalctimings(svga); break; + case 0x55: + xga->border_color = val; + break; + case 0x59: xga->direct_color = val; break; @@ -315,10 +385,10 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) if ((xga->sprite_pos >= 0) && (xga->sprite_pos <= 16)) { if ((xga->op_mode & 7) >= 5) xga->cursor_data_on = 1; - else if (xga->sprite_pos >= 1) + else if ((xga->sprite_pos >= 1) || ((xga->disp_cntl_2 & 7) > 3)) xga->cursor_data_on = 1; else if (xga->aperture_cntl == 0) { - if (xga->linear_endian_reverse) + if (xga->linear_endian_reverse && !(xga->access_mode & 8)) xga->cursor_data_on = 0; } } @@ -333,7 +403,9 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) xga->cursor_data_on = 0; } } - // pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); +#if 0 + pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); +#endif break; case 0x62: @@ -351,7 +423,7 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x65: - svga->fullchange = changeframecount; + svga->fullchange = svga->monitor->mon_changeframecount; switch (svga->dac_pos) { case 0: svga->dac_r = val; @@ -371,6 +443,9 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) svga->dac_pos = 0; svga->dac_addr = (svga->dac_addr + 1) & 0xff; break; + + default: + break; } break; @@ -397,16 +472,21 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) xga->clk_sel_2 = val; svga_recalctimings(svga); break; + + default: + break; } } static void -xga_ext_outb(uint16_t addr, uint8_t val, void *p) +xga_ext_outb(uint16_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; - // pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); +#if 0 + pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); +#endif switch (addr & 0x0f) { case 0: xga->op_mode = val; @@ -420,13 +500,11 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) if ((xga->disp_cntl_2 & 7) == 4) xga->aperture_cntl = 0; break; - case 6: - vga_on = 0; - xga->on = 1; - break; case 8: xga->ap_idx = val; - // pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); +#if 0 + pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); +#endif if ((xga->op_mode & 7) < 4) { xga->write_bank = xga->read_bank = 0; } else { @@ -448,15 +526,19 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) xga->regs[xga->regs_idx] = val; xga_ext_out_reg(xga, svga, xga->regs_idx, xga->regs[xga->regs_idx]); break; + + default: + break; } } static uint8_t -xga_ext_inb(uint16_t addr, void *p) +xga_ext_inb(uint16_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; - uint8_t ret, index; + uint8_t ret = 0; + uint8_t index; switch (addr & 0x0f) { case 0: @@ -481,7 +563,10 @@ xga_ext_inb(uint16_t addr, void *p) case 0x0f: switch (xga->regs_idx) { case 4: - ret = (xga->bus & DEVICE_MCA) ? 1 : 0; + if (xga->bus & DEVICE_MCA) + ret = 0x01; /*32-bit MCA*/ + else + ret = 0x10; /*16-bit ISA*/ break; case 0x10: ret = xga->htotal & 0xff; @@ -586,14 +671,17 @@ xga_ext_inb(uint16_t addr, void *p) ret = xga->disp_cntl_2; break; case 0x52: - ret = 0x0b; + ret = xga->type ? 0xfa : 0xea; break; case 0x53: - ret = 0x70; + ret = xga->type ? 0x53 : 0x30; break; case 0x54: ret = xga->clk_sel_1; break; + case 0x55: + ret = xga->border_color; + break; case 0x59: ret = xga->direct_color; @@ -633,6 +721,9 @@ xga_ext_inb(uint16_t addr, void *p) svga->dac_addr = (svga->dac_addr + 1) & 0xff; ret = svga->vgapal[index].b; break; + + default: + break; } break; @@ -651,7 +742,9 @@ xga_ext_inb(uint16_t addr, void *p) break; case 0x6a: - // pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); +#if 0 + pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); +#endif ret = xga->sprite_data[xga->sprite_pos_prefetch]; xga->sprite_pos_prefetch = (xga->sprite_pos_prefetch + 1) & 0x3ff; break; @@ -660,14 +753,30 @@ xga_ext_inb(uint16_t addr, void *p) ret = xga->clk_sel_2; break; + case 0x74: + if (xga->bus & DEVICE_MCA) + ret = xga->regs[xga->regs_idx]; + else { + ret = (xga->dma_channel << 1); + if (xga->dma_channel) + ret |= 1; + } + break; + default: ret = xga->regs[xga->regs_idx]; break; } break; + + default: + break; } - // pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); +#if 0 + pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); +#endif + return ret; } @@ -676,23 +785,23 @@ xga_ext_inb(uint16_t addr, void *p) #define WRITE(addr, dat) \ xga->vram[((addr)) & (xga->vram_mask)] = dat; \ - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; + xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; #define READW(addr, dat) \ dat = *(uint16_t *) &xga->vram[(addr) & (xga->vram_mask)]; -#define READW_REVERSE(addr, dat) \ - dat = xga->vram[(addr + 1) & (xga->vram_mask - 1)] & 0xff; \ - dat |= (xga->vram[(addr) & (xga->vram_mask - 1)] << 8); +#define READW_INV(addr, dat) \ + dat = xga->vram[(addr + 1) & (xga->vram_mask)]; \ + dat |= (xga->vram[(addr) & (xga->vram_mask)] << 8); #define WRITEW(addr, dat) \ *(uint16_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; + xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; -#define WRITEW_REVERSE(addr, dat) \ - xga->vram[((addr + 1)) & (xga->vram_mask - 1)] = dat & 0xff; \ - xga->vram[((addr)) & (xga->vram_mask - 1)] = dat >> 8; \ - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; +#define WRITEW_INV(addr, dat) \ + xga->vram[((addr + 1)) & (xga->vram_mask)] = dat & 0xff; \ + xga->vram[((addr)) & (xga->vram_mask)] = dat >> 8; \ + xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; #define ROP(mix, d, s) \ { \ @@ -769,12 +878,12 @@ xga_ext_inb(uint16_t addr, void *p) static uint32_t xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) { - xga_t *xga = &svga->xga; - uint32_t addr = base; - int bits; - uint32_t byte; - uint8_t px; - int skip = 0; + const xga_t *xga = &svga->xga; + uint32_t addr = base; + int bits; + uint32_t byte; + uint8_t px; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -791,20 +900,21 @@ xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t b } else { byte = mem_readb_phys(addr); } - if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) - if (xga->linear_endian_reverse) - bits = 7 - (x & 7); - else - bits = (x & 7); - else { + if (xga->linear_endian_reverse) { bits = 7 - (x & 7); + } else { + if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) + bits = (x & 7); + else { + bits = 7 - (x & 7); + } } px = (byte >> bits) & 1; return px; } static uint32_t -xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) +xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width, UNUSED(int usesrc)) { xga_t *xga = &svga->xga; uint32_t addr = base; @@ -830,13 +940,14 @@ xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int } else { byte = mem_readb_phys(addr); } - if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) - if (xga->linear_endian_reverse) - bits = 7 - (x & 7); - else - bits = (x & 7); - else { + if (xga->linear_endian_reverse) { bits = 7 - (x & 7); + } else { + if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) + bits = (x & 7); + else { + bits = 7 - (x & 7); + } } px = (byte >> bits) & 1; return px; @@ -852,22 +963,24 @@ xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int case 4: /*16-bit*/ addr += (y * (width << 1)); addr += (x << 1); - if (!skip) { - if ((xga->accel.px_map_format[map] & 8)) { - if (xga->linear_endian_reverse) { - READW(addr, byte); - } else { - READW_REVERSE(addr, byte); - } - } else { - READW(addr, byte); - } - } else { + if (xga->linear_endian_reverse) { byte = mem_readw_phys(addr); + if ((xga->access_mode & 7) == 4) + byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); + else if (xga->access_mode & 8) + byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); + } else { + if (!skip) { + READW(addr, byte); + } else { + byte = mem_readb_phys(addr) | (mem_readb_phys(addr + 1) << 8); + } } return byte; - } + default: + break; + } return 0; } @@ -876,7 +989,8 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui { xga_t *xga = &svga->xga; uint32_t addr = base; - uint8_t byte, mask; + uint8_t byte; + uint8_t mask; int skip = 0; if (xga->base_addr_1mb) { @@ -889,31 +1003,32 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui switch (xga->accel.px_map_format[map] & 7) { case 0: /*1-bit*/ - addr += (y * (width) >> 3); + addr += (y * width >> 3); addr += (x >> 3); if (!skip) { READ(addr, byte); } else { byte = mem_readb_phys(addr); } - if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) { - if (xga->linear_endian_reverse) - mask = 1 << (7 - (x & 7)); - else - mask = 1 << (x & 7); - } else { + if (xga->linear_endian_reverse) { mask = 1 << (7 - (x & 7)); + } else { + if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) { + mask = 1 << (x & 7); + } else { + mask = 1 << (7 - (x & 7)); + } } byte = (byte & ~mask) | ((pixel ? 0xff : 0) & mask); if (pixel & 1) { if (!skip) { - xga->vram[((addr)) & (xga->vram_mask)] |= mask; - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; + xga->vram[addr & (xga->vram_mask)] |= mask; + xga->changedvram[(addr & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; } } else { if (!skip) { - xga->vram[((addr)) & (xga->vram_mask)] &= ~mask; - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; + xga->vram[addr & (xga->vram_mask)] &= ~mask; + xga->changedvram[(addr & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; } } mem_writeb_phys(addr, byte); @@ -927,20 +1042,24 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui mem_writeb_phys(addr, pixel & 0xff); break; case 4: /*16-bit*/ - addr += (y * (width) << 1); + addr += (y * width << 1); addr += (x << 1); - if (!skip) { - if ((xga->accel.px_map_format[map] & 8)) { - if (xga->linear_endian_reverse) { - WRITEW(addr, pixel); - } else { - WRITEW_REVERSE(addr, pixel); - } - } else { + if (xga->linear_endian_reverse) { + if ((xga->access_mode & 7) == 4) + pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); + else if (xga->access_mode & 8) + pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); + + mem_writew_phys(addr, pixel); + } else { + if (!skip) { WRITEW(addr, pixel); } + mem_writew_phys(addr, pixel); } - mem_writew_phys(addr, pixel); + break; + + default: break; } } @@ -949,21 +1068,26 @@ static void xga_short_stroke(svga_t *svga, uint8_t ssv) { xga_t *xga = &svga->xga; - uint32_t src_dat, dest_dat, old_dest_dat; + uint32_t src_dat; + uint32_t dest_dat; + uint32_t old_dest_dat; uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; int y = ssv & 0x0f; int x = 0; - int dx, dy, dirx = 0, diry = 0; + int dx; + int dy; + int dirx = 0; + int diry = 0; dx = xga->accel.dst_map_x & 0x1fff; - if (xga->accel.dst_map_x & 0x1800) + if (xga->accel.dst_map_x >= 0x1800) dx |= ~0x17ff; dy = xga->accel.dst_map_y & 0x1fff; - if (xga->accel.dst_map_y & 0x1800) + if (xga->accel.dst_map_y >= 0x1800) dy |= ~0x17ff; switch ((ssv >> 5) & 7) { @@ -999,14 +1123,17 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) dirx = 1; diry = 1; break; + + default: + break; } if (xga->accel.pat_src == 8) { while (y >= 0) { if (xga->accel.command & 0xc0) { if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1025,8 +1152,8 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1070,30 +1197,38 @@ static void xga_line_draw_write(svga_t *svga) { xga_t *xga = &svga->xga; - uint32_t src_dat, dest_dat, old_dest_dat; + uint32_t src_dat; + uint32_t dest_dat; + uint32_t old_dest_dat; uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; - int dminor, destxtmp, dmajor, err, tmpswap; + int dminor; + int destxtmp; + int dmajor; + int err; + int tmpswap; int steep = 1; - int xdir, ydir; + int xdir; + int ydir; int y = xga->accel.blt_width; int x = 0; - int dx, dy; + int dx; + int dy; - dminor = ((int16_t) xga->accel.bres_k1); + dminor = (xga->accel.bres_k1); if (xga->accel.bres_k1 & 0x2000) dminor |= ~0x1fff; dminor >>= 1; - destxtmp = ((int16_t) xga->accel.bres_k2); + destxtmp = (xga->accel.bres_k2); if (xga->accel.bres_k2 & 0x2000) destxtmp |= ~0x1fff; dmajor = -(destxtmp - (dminor << 1)) >> 1; - err = ((int16_t) xga->accel.bres_err_term); + err = (xga->accel.bres_err_term); if (xga->accel.bres_err_term & 0x2000) destxtmp |= ~0x1fff; @@ -1110,11 +1245,11 @@ xga_line_draw_write(svga_t *svga) } dx = xga->accel.dst_map_x & 0x1fff; - if (xga->accel.dst_map_x & 0x1800) + if (xga->accel.dst_map_x >= 0x1800) dx |= ~0x17ff; dy = xga->accel.dst_map_y & 0x1fff; - if (xga->accel.dst_map_y & 0x1800) + if (xga->accel.dst_map_y >= 0x1800) dy |= ~0x17ff; if (xga->accel.octant & 0x01) { @@ -1128,8 +1263,8 @@ xga_line_draw_write(svga_t *svga) if (xga->accel.command & 0xc0) { if (steep) { if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1145,8 +1280,8 @@ xga_line_draw_write(svga_t *svga) } } else { if ((dy >= xga->accel.mask_map_origin_x_off) && (dy <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dx >= xga->accel.mask_map_origin_y_off) && (dx <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1163,8 +1298,8 @@ xga_line_draw_write(svga_t *svga) } } else { if (steep) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1178,8 +1313,8 @@ xga_line_draw_write(svga_t *svga) xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map] + 1); } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1221,18 +1356,13 @@ xga_line_draw_write(svga_t *svga) } } -static int16_t -xga_dst_wrap(int16_t addr) -{ - addr &= 0x1fff; - return (addr & 0x1800) == 0x1800 ? (addr | 0xf800) : addr; -} - static void xga_bitblt(svga_t *svga) { xga_t *xga = &svga->xga; - uint32_t src_dat, dest_dat, old_dest_dat; + uint32_t src_dat; + uint32_t dest_dat; + uint32_t old_dest_dat; uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; uint32_t patbase = xga->accel.px_map_base[xga->accel.pat_src]; @@ -1243,8 +1373,14 @@ xga_bitblt(svga_t *svga) uint32_t srcwidth = xga->accel.px_map_width[xga->accel.src_map]; uint32_t patheight = xga->accel.px_map_height[xga->accel.pat_src]; uint32_t srcheight = xga->accel.px_map_height[xga->accel.src_map]; - int mix = 0; - int xdir, ydir; +#if 0 + uint32_t dstheight = xga->accel.px_map_height[xga->accel.dst_map]; +#endif + uint32_t frgdcol = xga->accel.frgd_color; + uint32_t bkgdcol = xga->accel.bkgd_color; + int mix = 0; + int xdir; + int ydir; if (xga->accel.octant & 0x02) { ydir = -1; @@ -1265,11 +1401,20 @@ xga_bitblt(svga_t *svga) xga->accel.sy = xga->accel.src_map_y & 0xfff; xga->accel.px = xga->accel.pat_map_x & 0xfff; xga->accel.py = xga->accel.pat_map_y & 0xfff; - xga->accel.dx = xga_dst_wrap(xga->accel.dst_map_x); - xga->accel.dy = xga_dst_wrap(xga->accel.dst_map_y); + xga->accel.dx = xga->accel.dst_map_x & 0x1fff; + if (xga->accel.dst_map_x >= 0x1800) + xga->accel.dx |= ~0x17ff; + xga->accel.dy = xga->accel.dst_map_y & 0x1fff; + if (xga->accel.dst_map_y >= 0x1800) + xga->accel.dy |= ~0x17ff; xga->accel.pattern = 0; +#if 0 + pclog("XGA bitblt linear endian reverse=%d, access_mode=%x, octanty=%d, src command = %08x, pxsrcmap=%x, pxpatmap=%x, pxdstmap=%x, srcmap=%d, patmap=%d, dstmap=%d, usesrcvramfr=%d, usevrambk=%d.\n", + xga->linear_endian_reverse, xga->access_mode & 0x0f, ydir, xga->accel.command, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.px_map_format[xga->accel.pat_src] & 0x0f, xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.src_map, xga->accel.pat_src, xga->accel.dst_map, ((xga->accel.command >> 28) & 3), ((xga->accel.command >> 30) & 3)); +#endif + if (xga->accel.pat_src == 8) { if (srcheight == 7) xga->accel.pattern = 1; @@ -1282,15 +1427,15 @@ xga_bitblt(svga_t *svga) } } } - - // pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); - // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#if 0 + pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); + pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#endif while (xga->accel.y >= 0) { if (xga->accel.command & 0xc0) { if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); @@ -1299,9 +1444,8 @@ xga_bitblt(svga_t *svga) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); @@ -1314,15 +1458,17 @@ xga_bitblt(svga_t *svga) xga->accel.sx = ((xga->accel.sx + xdir) & srcwidth) | (xga->accel.sx & ~srcwidth); else xga->accel.sx += xdir; - xga->accel.dx = xga_dst_wrap(xga->accel.dx + xdir); + xga->accel.dx += xdir; xga->accel.x--; if (xga->accel.x < 0) { xga->accel.x = (xga->accel.blt_width & 0xfff); - xga->accel.dx = xga_dst_wrap(xga->accel.dst_map_x); + xga->accel.dx = xga->accel.dst_map_x & 0x1fff; + if (xga->accel.dst_map_x >= 0x1800) + xga->accel.dx |= ~0x17ff; xga->accel.sx = xga->accel.src_map_x & 0xfff; - xga->accel.dy = xga_dst_wrap(xga->accel.dy + ydir); + xga->accel.dy += ydir; if (xga->accel.pattern) xga->accel.sy = ((xga->accel.sy + ydir) & srcheight) | (xga->accel.sy & ~srcheight); else @@ -1361,20 +1507,22 @@ xga_bitblt(svga_t *svga) } } - // pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); - // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#if 0 + pclog("XGA bitblt linear endian reverse=%d, octanty=%d, src command = %08x, pxsrcmap=%x, pxdstmap=%x, srcmap=%d, patmap=%d, dstmap=%d, dstwidth=%d, dstheight=%d, srcwidth=%d, srcheight=%d, dstbase=%08x, srcbase=%08x.\n", xga->linear_endian_reverse, ydir, xga->accel.command, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.src_map, xga->accel.pat_src, xga->accel.dst_map, dstwidth, dstheight, srcwidth, srcheight, dstbase, srcbase); + pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); + pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#endif while (xga->accel.y >= 0) { mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, xga->accel.pat_src, patbase, patwidth + 1); if (xga->accel.command & 0xc0) { if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - if (mix) - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - else - src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.bkgd_color; - - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + if (mix) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + } else { + src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : bkgdcol; + } + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); @@ -1383,13 +1531,12 @@ xga_bitblt(svga_t *svga) } } } else { - if (mix) - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - else - src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.bkgd_color; - - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + if (mix) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + } else { + src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : bkgdcol; + } + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); @@ -1403,13 +1550,15 @@ xga_bitblt(svga_t *svga) xga->accel.px = ((xga->accel.px + xdir) & patwidth) | (xga->accel.px & ~patwidth); else xga->accel.px += xdir; - xga->accel.dx = xga_dst_wrap(xga->accel.dx + xdir); + xga->accel.dx += xdir; xga->accel.x--; if (xga->accel.x < 0) { xga->accel.y--; xga->accel.x = (xga->accel.blt_width & 0xfff); - xga->accel.dx = xga_dst_wrap(xga->accel.dst_map_x); + xga->accel.dx = xga->accel.dst_map_x & 0x1fff; + if (xga->accel.dst_map_x >= 0x1800) + xga->accel.dx |= ~0x17ff; xga->accel.sx = xga->accel.src_map_x & 0xfff; xga->accel.px = xga->accel.pat_map_x & 0xfff; @@ -1418,7 +1567,7 @@ xga_bitblt(svga_t *svga) xga->accel.py = ((xga->accel.py + ydir) & patheight) | (xga->accel.py & ~patheight); else xga->accel.py += ydir; - xga->accel.dy = xga_dst_wrap(xga->accel.dy + ydir); + xga->accel.dy += ydir; if (xga->accel.y < 0) { xga->accel.dst_map_x = xga->accel.dx; @@ -1437,6 +1586,10 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) if (addr >= 0x1800) { switch (addr & 0x7f) { + case 0x11: + xga->accel.control = val; + break; + case 0x12: xga->accel.px_map_idx = val & 3; break; @@ -1549,7 +1702,9 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) xga->accel.short_stroke_vector3 = (xga->accel.short_stroke >> 16) & 0xff; xga->accel.short_stroke_vector4 = (xga->accel.short_stroke >> 24) & 0xff; - // pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); +#if 0 + pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); +#endif xga_short_stroke(svga, xga->accel.short_stroke_vector1); xga_short_stroke(svga, xga->accel.short_stroke_vector2); xga_short_stroke(svga, xga->accel.short_stroke_vector3); @@ -1816,39 +1971,58 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) exec_command: xga->accel.octant = xga->accel.command & 0x07; xga->accel.draw_mode = xga->accel.command & 0x30; - xga->accel.mask_mode = xga->accel.command & 0xc0; xga->accel.pat_src = ((xga->accel.command >> 12) & 0x0f); xga->accel.dst_map = ((xga->accel.command >> 16) & 0x0f); xga->accel.src_map = ((xga->accel.command >> 20) & 0x0f); - // if (xga->accel.pat_src) { - // pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", - // CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], - // xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], - // xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], - // xga->accel.px_map_height[xga->accel.src_map], - // xga->accel.pat_map_x, xga->accel.pat_map_y, - // xga->accel.dst_map_x, xga->accel.dst_map_y, - // xga->accel.src_map_x, xga->accel.src_map_y, - // xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, - // xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], - // xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); - // //pclog("\n"); - // } +#if 0 + if (xga->accel.pat_src) { + pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", + CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], + xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], + xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], + xga->accel.px_map_height[xga->accel.src_map], + xga->accel.pat_map_x, xga->accel.pat_map_y, + xga->accel.dst_map_x, xga->accel.dst_map_y, + xga->accel.src_map_x, xga->accel.src_map_y, + xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, + xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], + xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); + pclog("\n"); + } +#endif switch ((xga->accel.command >> 24) & 0x0f) { case 3: /*Bresenham Line Draw Read*/ - // pclog("Line Draw Read\n"); +#if 0 + pclog("Line Draw Read\n"); +#endif break; case 4: /*Short Stroke Vectors*/ +#if 0 + pclog("Short Stroke Vectors.\n"); +#endif break; case 5: /*Bresenham Line Draw Write*/ +#if 0 + pclog("Line Draw Write.\n"); +#endif xga_line_draw_write(svga); break; case 8: /*BitBLT*/ xga_bitblt(svga); break; case 9: /*Inverting BitBLT*/ - // pclog("Inverting BitBLT\n"); +#if 0 + pclog("Inverting BitBLT\n"); +#endif + break; + case 0x0a: /*Area Fill*/ +#if 0 + pclog("Area Fill.\n"); +#endif + break; + + default: break; } } else if (len == 2) { @@ -1873,51 +2047,70 @@ exec_command: goto exec_command; } break; + + default: + break; } } } static void -xga_memio_writeb(uint32_t addr, uint8_t val, void *p) +xga_memio_writeb(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 1); - // pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); +#if 0 + pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); +#endif } static void -xga_memio_writew(uint32_t addr, uint16_t val, void *p) +xga_memio_writew(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 2); - // pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); +#if 0 + pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); +#endif } static void -xga_memio_writel(uint32_t addr, uint32_t val, void *p) +xga_memio_writel(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 4); - // pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); +#if 0 + pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); +#endif } static uint8_t -xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) +xga_mem_read(uint32_t addr, xga_t *xga, UNUSED(svga_t *svga)) { uint8_t temp = 0; addr &= 0x1fff; - if (addr < 0x1800) { - temp = xga->bios_rom.rom[addr]; + if (!xga_has_vga) + temp = xga->bios_rom.rom[addr]; + else + temp = xga->vga_bios_rom.rom[addr]; } else { switch (addr & 0x7f) { + case 0x11: + temp = xga->accel.control; + if (xga->accel.control & 0x08) + temp |= 0x10; + else + temp &= ~0x10; + break; + case 0x20: temp = xga->accel.bres_err_term & 0xff; break; @@ -1972,6 +2165,9 @@ xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) case 0x7b: temp = xga->accel.dst_map_y >> 8; break; + + default: + break; } } @@ -1979,36 +2175,41 @@ xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) } static uint8_t -xga_memio_readb(uint32_t addr, void *p) +xga_memio_readb(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; uint8_t temp; temp = xga_mem_read(addr, xga, svga); - // pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); +#if 0 + pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); +#endif + return temp; } static uint16_t -xga_memio_readw(uint32_t addr, void *p) +xga_memio_readw(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; uint16_t temp; temp = xga_mem_read(addr, xga, svga); temp |= (xga_mem_read(addr + 1, xga, svga) << 8); - // pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); +#if 0 + pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); +#endif return temp; } static uint32_t -xga_memio_readl(uint32_t addr, void *p) +xga_memio_readl(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; uint32_t temp; @@ -2017,7 +2218,9 @@ xga_memio_readl(uint32_t addr, void *p) temp |= (xga_mem_read(addr + 2, xga, svga) << 16); temp |= (xga_mem_read(addr + 3, xga, svga) << 24); - // pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); +#if 0 + pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); +#endif return temp; } @@ -2027,7 +2230,8 @@ xga_hwcursor_draw(svga_t *svga, int displine) xga_t *xga = &svga->xga; uint8_t dat = 0; int offset = xga->hwcursor_latch.x - xga->hwcursor_latch.xoff; - int x, x_pos, y_pos; + int x_pos; + int y_pos; int comb = 0; uint32_t *p; int idx = (xga->cursor_data_on) ? 32 : 0; @@ -2039,7 +2243,7 @@ xga_hwcursor_draw(svga_t *svga, int displine) x_pos = offset + svga->x_add; p = buffer32->line[y_pos]; - for (x = 0; x < xga->hwcursor_latch.cur_xsize; x++) { + for (int x = 0; x < xga->hwcursor_latch.cur_xsize; x++) { if (x >= idx) { if (!(x & 0x03)) dat = xga->sprite_data[xga->hwcursor_latch.addr & 0x3ff]; @@ -2061,6 +2265,9 @@ xga_hwcursor_draw(svga_t *svga, int displine) /* Complement */ p[x_pos] ^= 0xffffff; break; + + default: + break; } } @@ -2075,22 +2282,21 @@ xga_hwcursor_draw(svga_t *svga, int displine) static void xga_render_overscan_left(xga_t *xga, svga_t *svga) { - int i; - if ((xga->displine + svga->y_add) < 0) return; if (svga->scrblank || (xga->h_disp == 0)) return; - for (i = 0; i < svga->x_add; i++) - buffer32->line[xga->displine + svga->y_add][i] = svga->overscan_color; + uint32_t *line_ptr = svga->monitor->target_buffer->line[xga->displine + svga->y_add]; + for (int i = 0; i < svga->x_add; i++) + *line_ptr++ = svga->overscan_color; } static void xga_render_overscan_right(xga_t *xga, svga_t *svga) { - int i, right; + int right; if ((xga->displine + svga->y_add) < 0) return; @@ -2098,15 +2304,15 @@ xga_render_overscan_right(xga_t *xga, svga_t *svga) if (svga->scrblank || (xga->h_disp == 0)) return; - right = (overscan_x >> 1); - for (i = 0; i < right; i++) - buffer32->line[xga->displine + svga->y_add][svga->x_add + xga->h_disp + i] = svga->overscan_color; + uint32_t *line_ptr = &svga->monitor->target_buffer->line[xga->displine + svga->y_add][svga->x_add + xga->h_disp]; + right = (overscan_x >> 1); + for (int i = 0; i < right; i++) + *line_ptr++ = svga->overscan_color; } static void xga_render_8bpp(xga_t *xga, svga_t *svga) { - int x; uint32_t *p; uint32_t dat; @@ -2114,13 +2320,13 @@ xga_render_8bpp(xga_t *xga, svga_t *svga) return; if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { - p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; + p = &svga->monitor->target_buffer->line[xga->displine + svga->y_add][svga->x_add]; if (xga->firstline_draw == 2000) xga->firstline_draw = xga->displine; xga->lastline_draw = xga->displine; - for (x = 0; x <= xga->h_disp; x += 8) { + for (int x = 0; x <= xga->h_disp; x += 8) { dat = *(uint32_t *) (&xga->vram[xga->ma & xga->vram_mask]); p[0] = svga->pallook[dat & 0xff]; p[1] = svga->pallook[(dat >> 8) & 0xff]; @@ -2151,7 +2357,7 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) return; if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { - p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; + p = &svga->monitor->target_buffer->line[xga->displine + svga->y_add][svga->x_add]; if (xga->firstline_draw == 2000) xga->firstline_draw = xga->displine; @@ -2180,9 +2386,9 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) } static void -xga_write(uint32_t addr, uint8_t val, void *p) +xga_write(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; if (!xga->on) { @@ -2198,39 +2404,113 @@ xga_write(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; - xga->changedvram[(addr & xga->vram_mask) >> 12] = changeframecount; + if (xga->access_mode & 8) { + if ((xga->access_mode & 7) == 4) + addr ^= 1; + } + + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; xga->vram[addr & xga->vram_mask] = val; } static void -xga_writeb(uint32_t addr, uint8_t val, void *p) +xga_writew(uint32_t addr, uint16_t val, void *priv) { - // pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); - xga_write(addr, val, p); + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + + if (!xga->on) { + svga_writew(addr, val, svga); + return; + } + + xga_write(addr, val & 0xff, svga); + xga_write(addr + 1, val >> 8, svga); } static void -xga_writew(uint32_t addr, uint16_t val, void *p) +xga_writel(uint32_t addr, uint32_t val, void *priv) { - // pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); - xga_write(addr, val, p); - xga_write(addr + 1, val >> 8, p); + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + + if (!xga->on) { + svga_writel(addr, val, svga); + return; + } + + xga_write(addr, val & 0xff, svga); + xga_write(addr + 1, (val >> 8) & 0xff, svga); + xga_write(addr + 2, (val >> 16) & 0xff, svga); + xga_write(addr + 3, (val >> 24) & 0xff, svga); +} + +static uint8_t +xga_read(uint32_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint8_t ret = 0xff; + + if (!xga->on) + return svga_read(addr, svga); + + addr &= xga->banked_mask; + addr += xga->read_bank; + + if (addr >= xga->vram_size) + return ret; + + cycles -= video_timing_read_b; + + if (xga->access_mode & 8) { + if ((xga->access_mode & 7) == 4) + addr ^= 1; + } + + ret = xga->vram[addr & xga->vram_mask]; + + return ret; +} + +static uint16_t +xga_readw(uint32_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint16_t ret = 0xffff; + + if (!xga->on) + return svga_readw(addr, svga); + + ret = xga_read(addr, svga); + ret |= (xga_read(addr + 1, svga) << 8); + + return ret; +} + +static uint32_t +xga_readl(uint32_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint32_t ret = 0xffffffff; + + if (!xga->on) + return svga_readl(addr, svga); + + ret = xga_read(addr, svga); + ret |= (xga_read(addr + 1, svga) << 8); + ret |= (xga_read(addr + 2, svga) << 16); + ret |= (xga_read(addr + 3, svga) << 24); + + return ret; } static void -xga_writel(uint32_t addr, uint32_t val, void *p) +xga_write_linear(uint32_t addr, uint8_t val, void *priv) { - // pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); - xga_write(addr, val, p); - xga_write(addr + 1, val >> 8, p); - xga_write(addr + 2, val >> 16, p); - xga_write(addr + 3, val >> 24, p); -} - -static void -xga_write_linear(uint32_t addr, uint8_t val, void *p) -{ - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; if (!xga->on) { @@ -2245,122 +2525,58 @@ xga_write_linear(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; - xga->changedvram[(addr & xga->vram_mask) >> 12] = changeframecount; + if (xga->linear_endian_reverse) { + if ((xga->access_mode & 7) == 4) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } else if (xga->access_mode & 8) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } + } + + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; xga->vram[addr & xga->vram_mask] = val; } static void -xga_writew_linear(uint32_t addr, uint16_t val, void *p) +xga_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; if (!xga->on) { svga_writew_linear(addr, val, svga); return; } - if (xga->linear_endian_reverse) { - if (xga->accel.px_map_format[xga->accel.dst_map] == 0x0c) { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } else if (xga->accel.px_map_format[xga->accel.dst_map] == 4) { - xga_write_linear(addr + 1, val, p); - xga_write_linear(addr, val >> 8, p); - } else { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } - } else { - if (xga->accel.px_map_format[xga->accel.dst_map] == 0x0c) { - xga_write_linear(addr + 1, val, p); - xga_write_linear(addr, val >> 8, p); - } else if (xga->accel.px_map_format[xga->accel.dst_map] == 4) { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } else { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } - } + xga_write_linear(addr, val, priv); + xga_write_linear(addr + 1, val >> 8, priv); } static void -xga_writel_linear(uint32_t addr, uint32_t val, void *p) +xga_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; if (!xga->on) { svga_writel_linear(addr, val, svga); return; } - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - xga_write_linear(addr + 2, val >> 16, p); - xga_write_linear(addr + 3, val >> 24, p); + xga_write_linear(addr, val, priv); + xga_write_linear(addr + 1, val >> 8, priv); + xga_write_linear(addr + 2, val >> 16, priv); + xga_write_linear(addr + 3, val >> 24, priv); } static uint8_t -xga_read(uint32_t addr, void *p) +xga_read_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; - - if (!xga->on) - return svga_read(addr, svga); - - addr &= xga->banked_mask; - addr += xga->read_bank; - - if (addr >= xga->vram_size) - return 0xff; - - cycles -= video_timing_read_b; - - return xga->vram[addr & xga->vram_mask]; -} - -static uint8_t -xga_readb(uint32_t addr, void *p) -{ - uint8_t ret; - - ret = xga_read(addr, p); - - return ret; -} - -static uint16_t -xga_readw(uint32_t addr, void *p) -{ - uint16_t ret; - - ret = xga_read(addr, p); - ret |= (xga_read(addr + 1, p) << 8); - - return ret; -} - -static uint32_t -xga_readl(uint32_t addr, void *p) -{ - uint32_t ret; - - ret = xga_read(addr, p); - ret |= (xga_read(addr + 1, p) << 8); - ret |= (xga_read(addr + 2, p) << 16); - ret |= (xga_read(addr + 3, p) << 24); - - return ret; -} - -static uint8_t -xga_read_linear(uint32_t addr, void *p) -{ - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint8_t ret = 0xff; if (!xga->on) return svga_read_linear(addr, svga); @@ -2368,51 +2584,55 @@ xga_read_linear(uint32_t addr, void *p) addr &= svga->decode_mask; if (addr >= xga->vram_size) - return 0xff; + return ret; cycles -= video_timing_read_b; + if (xga->linear_endian_reverse) { + if ((xga->access_mode & 7) == 4) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } else if (xga->access_mode & 8) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } + } + return xga->vram[addr & xga->vram_mask]; } static uint16_t -xga_readw_linear(uint32_t addr, void *p) +xga_readw_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; - uint16_t ret; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint16_t ret; if (!xga->on) return svga_readw_linear(addr, svga); - if (xga->linear_endian_reverse) { - if (xga->accel.px_map_format[xga->accel.src_map] == 0x0c) { - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } else if (xga->accel.px_map_format[xga->accel.src_map] == 4) { - ret = xga_read_linear(addr + 1, p) | (xga_read_linear(addr, p) << 8); - } else - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } else { - if (xga->accel.px_map_format[xga->accel.src_map] == 0x0c) { - ret = xga_read_linear(addr + 1, p) | (xga_read_linear(addr, p) << 8); - } else if (xga->accel.px_map_format[xga->accel.src_map] == 4) { - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } else - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } + ret = xga_read_linear(addr, svga); + ret |= (xga_read_linear(addr + 1, svga) << 8); + return ret; } static uint32_t -xga_readl_linear(uint32_t addr, void *p) +xga_readl_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint32_t ret; if (!xga->on) return svga_readl_linear(addr, svga); - return xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8) | (xga_read_linear(addr + 2, p) << 16) | (xga_read_linear(addr + 3, p) << 24); + ret = xga_read_linear(addr, svga); + ret |= (xga_read_linear(addr + 1, svga) << 8); + ret |= (xga_read_linear(addr + 2, svga) << 16); + ret |= (xga_read_linear(addr + 3, svga) << 24); + + return ret; } static void @@ -2427,6 +2647,9 @@ xga_do_render(svga_t *svga) case 4: xga_render_16bpp(xga, svga); break; + + default: + break; } svga->x_add = (overscan_x >> 1); @@ -2446,7 +2669,8 @@ void xga_poll(xga_t *xga, svga_t *svga) { uint32_t x; - int wx, wy; + int wx; + int wy; if (!xga->linepos) { if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { @@ -2515,7 +2739,7 @@ xga_poll(xga_t *xga, svga_t *svga) } xga->vc++; - xga->vc &= 2047; + xga->vc &= 0x7ff; if (xga->vc == xga->split) { if (xga->interlace && xga->oddeven) @@ -2559,7 +2783,7 @@ xga_poll(xga_t *xga, svga_t *svga) xga->oddeven ^= 1; - changeframecount = xga->interlace ? 3 : 2; + svga->monitor->mon_changeframecount = xga->interlace ? 3 : 2; if (xga->interlace && xga->oddeven) xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); @@ -2586,11 +2810,18 @@ xga_poll(xga_t *xga, svga_t *svga) static uint8_t xga_mca_read(int port, void *priv) { - svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; + const svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint8_t ret = xga->pos_regs[port & 7]; - // pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); - return (xga->pos_regs[port & 7]); + if (((port & 7) == 3) && !(ret & 1)) /*Always enable the mapping.*/ + ret |= 1; + +#if 0 + pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); +#endif + + return ret; } static void @@ -2606,12 +2837,14 @@ xga_mca_write(int port, uint8_t val, void *priv) io_removehandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); mem_mapping_disable(&xga->bios_rom.mapping); mem_mapping_disable(&xga->memio_mapping); - xga->on = 0; - vga_on = 1; + xga->on = 0; + vga_on = !xga->on; + xga->linear_endian_reverse = 0; + xga->a5_test = 0; /* Save the MCA register value. */ xga->pos_regs[port & 7] = val; - if (!(xga->pos_regs[4] & 1)) /*MCA 4MB addressing on systems with more than 16MB of memory*/ + if (!(xga->pos_regs[4] & 1) && (mem_size >= 16384)) /*MCA 4MB addressing on systems with more than 16MB of memory*/ xga->pos_regs[4] |= 1; if (xga->pos_regs[2] & 1) { @@ -2622,52 +2855,237 @@ xga_mca_write(int port, uint8_t val, void *priv) io_sethandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); - if (xga->pos_regs[3] & 1) { + if (xga->pos_regs[3] & 1) mem_mapping_set_addr(&xga->bios_rom.mapping, xga->rom_addr, 0x2000); - } else { + else mem_mapping_set_addr(&xga->memio_mapping, xga->rom_addr + 0x1c00 + (xga->instance * 0x80), 0x80); - } } - // pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); +#if 0 + pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); +#endif } static uint8_t xga_mca_feedb(void *priv) { - svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; + const svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; return xga->pos_regs[2] & 1; } static void -xga_mca_reset(void *p) +xga_mca_reset(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; + xga_t *xga = &svga->xga; + xga->on = 0; + vga_on = !xga->on; xga_mca_write(0x102, 0, svga); } +static void +xga_reset(void *priv) +{ + svga_t *svga = (svga_t *) priv; + xga_t *xga = &svga->xga; + + mem_mapping_disable(&xga->bios_rom.mapping); + mem_mapping_disable(&xga->memio_mapping); + xga->on = 0; + vga_on = !xga->on; + xga->linear_endian_reverse = 0; + xga->a5_test = 0; +} + static uint8_t xga_pos_in(uint16_t addr, void *priv) { svga_t *svga = (svga_t *) priv; + xga_t *xga = &svga->xga; + uint8_t ret = 0xff; - return (xga_mca_read(addr, svga)); + if (xga_has_vga) { + switch (addr) { + case 0x0100: + case 0x0101: + if (xga->instance_isa == xga->instance_num) + ret = xga->pos_regs[addr & 7]; + else + ret = 0xff; + break; + case 0x0102: + case 0x0105: + ret = xga->pos_regs[addr & 7]; + break; + case 0x0106: + ret = xga->pos_idx >> 8; + break; + case 0x0107: + ret = xga->pos_idx & 0xff; + break; + case 0x0103: + if (!(xga->pos_idx & 3)) { + ret = xga->pos_regs[3]; + } else + ret = 0; +#if 0 + pclog("POS IDX for 0103 = %d, ret = %02x.\n", xga->pos_idx & 3, ret); +#endif + break; + case 0x0104: + switch (xga->pos_idx & 3) { + case 0: + ret = xga->pos_regs[4]; + break; + case 1: + ret = xga->pos_regs[0]; + break; + case 2: + ret = xga->pos_regs[1]; + break; + case 3: + ret = 0; + break; + + default: + break; + } +#if 0 + pclog("POS IDX for 0104 = %d, ret = %02x.\n", xga->pos_idx & 3, ret); +#endif + break; + case 0x0108: + case 0x0109: + case 0x010a: + case 0x010b: + case 0x010c: + case 0x010d: + case 0x010e: + case 0x010f: + xga->instance_num = addr & 7; + if (xga->instance_isa == xga->instance_num) + ret = xga->instance_isa; + else + ret = 0; + + ret |= xga->isa_pos_enable; + break; + + default: + break; + } + } else { + switch (addr) { + case 0x0100: + case 0x0101: + ret = xga->pos_regs[addr & 7]; + break; + case 0x0103: + ret = xga->pos_regs[3] | 7; + ret |= (xga->dma_channel << 3); + break; + case 0x0102: + case 0x0104: + case 0x0105: + case 0x0106: + case 0x0107: + ret = (xga_mca_read(addr, svga)); + break; + case 0x0108: + case 0x0109: + case 0x010a: + case 0x010b: + case 0x010c: + case 0x010d: + case 0x010e: + case 0x010f: + xga->instance_num = addr & 7; + if (xga->instance_isa == xga->instance_num) + ret = xga->instance_isa; + else + ret = 0; + + ret |= xga->isa_pos_enable; + break; + + default: + break; + } + } + return ret; } static void - * - xga_init(const device_t *info) +xga_pos_out(uint16_t addr, uint8_t val, void *priv) { + svga_t *svga = (svga_t *) priv; + xga_t *xga = &svga->xga; + + if (xga_has_vga) { + switch (addr) { + case 0x0106: + xga->pos_idx = (xga->pos_idx & 0x00ff) | (val << 8); + break; + case 0x0107: + xga->pos_idx = (xga->pos_idx & 0xff00) | val; +#if 0 + pclog("POS IDX Write = %04x.\n", xga->pos_idx); +#endif + break; + case 0x0108: + case 0x0109: + case 0x010a: + case 0x010b: + case 0x010c: + case 0x010d: + case 0x010e: + case 0x010f: + xga->instance_num = addr & 7; + xga->isa_pos_enable = val & 0x08; + break; + + default: + break; + } + } else { + switch (addr) { + case 0x0108: + case 0x0109: + case 0x010a: + case 0x010b: + case 0x010c: + case 0x010d: + case 0x010e: + case 0x010f: + xga->instance_num = addr & 7; + xga->isa_pos_enable = val & 0x08; + break; + + default: + break; + } + } +} + +static void * +xga_init(const device_t *info) +{ + if (svga_get_pri() == NULL) + return NULL; + svga_t *svga = svga_get_pri(); xga_t *xga = &svga->xga; FILE *f; - uint32_t initial_bios_addr = device_get_config_hex20("init_bios_addr"); - uint8_t *rom = NULL; + uint32_t temp; + uint8_t *rom = NULL; - xga->type = device_get_config_int("type"); - xga->bus = info->flags; + xga->ext_mem_addr = device_get_config_hex16("ext_mem_addr"); + xga->instance_isa = device_get_config_int("instance"); + xga->type = device_get_config_int("type"); + xga->dma_channel = device_get_config_int("dma"); + xga->bus = info->flags; xga->vram_size = (1024 << 10); xga->vram_mask = xga->vram_size - 1; @@ -2682,11 +3100,13 @@ static void f = rom_fopen(xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, "rb"); (void) fseek(f, 0L, SEEK_END); + temp = ftell(f); (void) fseek(f, 0L, SEEK_SET); rom = malloc(xga->bios_rom.sz); memset(rom, 0xff, xga->bios_rom.sz); - (void) !fread(rom, xga->bios_rom.sz, 1, f); + (void) fread(rom, xga->bios_rom.sz, 1, f); + temp -= xga->bios_rom.sz; (void) fclose(f); xga->bios_rom.rom = rom; @@ -2697,27 +3117,33 @@ static void xga->base_addr_1mb = 0; if (info->flags & DEVICE_MCA) { + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_xga_mca); xga->linear_base = 0; xga->instance = 0; xga->rom_addr = 0; - rom_init(&xga->bios_rom, xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, initial_bios_addr, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(&xga->bios_rom, xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, 0xc0000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); } else { - xga->pos_regs[2] = 1 | 0x0c | 0xf0; + if (xga_has_vga) { + rom_init(&xga->vga_bios_rom, INMOS_XGA_BIOS_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + } else + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_xga_isa); + + xga->pos_regs[2] = 1 | (xga->instance_isa << 1) | xga->ext_mem_addr; xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; xga->pos_regs[4] = 1 | 2; xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); } - mem_mapping_add(&xga->video_mapping, 0, 0, xga_readb, xga_readw, xga_readl, - xga_writeb, xga_writew, xga_writel, + mem_mapping_add(&xga->video_mapping, 0, 0, xga_read, xga_readw, xga_readl, + xga_write, xga_writew, xga_writel, NULL, MEM_MAPPING_EXTERNAL, svga); mem_mapping_add(&xga->linear_mapping, 0, 0, xga_read_linear, xga_readw_linear, xga_readl_linear, xga_write_linear, xga_writew_linear, xga_writel_linear, NULL, MEM_MAPPING_EXTERNAL, svga); mem_mapping_add(&xga->memio_mapping, 0, 0, xga_memio_readb, xga_memio_readw, xga_memio_readl, xga_memio_writeb, xga_memio_writew, xga_memio_writel, - xga->bios_rom.rom, MEM_MAPPING_EXTERNAL, svga); + xga_has_vga ? xga->vga_bios_rom.rom : xga->bios_rom.rom, MEM_MAPPING_EXTERNAL, svga); mem_mapping_disable(&xga->video_mapping); mem_mapping_disable(&xga->linear_mapping); @@ -2730,17 +3156,44 @@ static void mca_add(xga_mca_read, xga_mca_write, xga_mca_feedb, xga_mca_reset, svga); } else { io_sethandler(0x0100, 0x0008, xga_pos_in, NULL, NULL, NULL, NULL, NULL, svga); + if (xga_has_vga) + io_sethandler(0x0106, 0x0002, NULL, NULL, NULL, xga_pos_out, NULL, NULL, svga); + io_sethandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); + io_sethandler(0x0108, 0x0008, xga_pos_in, NULL, NULL, xga_pos_out, NULL, NULL, svga); mem_mapping_set_addr(&xga->memio_mapping, xga->rom_addr + 0x1c00 + (xga->instance * 0x80), 0x80); } - return svga; } -static void -xga_close(void *p) +static void * +svga_xga_init(const device_t *info) { - svga_t *svga = (svga_t *) p; + svga_t *svga = malloc(sizeof(svga_t)); + memset(svga, 0, sizeof(svga_t)); + + video_inform(VIDEO_FLAG_TYPE_XGA, &timing_xga_isa); + + svga_init(info, svga, svga, 1 << 18, /*256kB*/ + NULL, + svga_xga_in, svga_xga_out, + NULL, + NULL); + + io_sethandler(0x03c0, 0x0020, svga_xga_in, NULL, NULL, svga_xga_out, NULL, NULL, svga); + + svga->bpp = 8; + svga->miscout = 1; + xga_has_vga = 1; + xga_enabled = 1; + + return xga_init(info); +} + +static void +xga_close(void *priv) +{ + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; if (svga) { @@ -2755,43 +3208,30 @@ xga_available(void) return rom_present(XGA_BIOS_PATH) && rom_present(XGA2_BIOS_PATH); } -static void -xga_speed_changed(void *p) +static int +inmos_xga_available(void) { - svga_t *svga = (svga_t *) p; + return rom_present(INMOS_XGA_BIOS_PATH); +} + +static void +xga_speed_changed(void *priv) +{ + svga_t *svga = (svga_t *) priv; svga_recalctimings(svga); } static void -xga_force_redraw(void *p) +xga_force_redraw(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; - svga->fullchange = changeframecount; + svga->fullchange = svga->monitor->mon_changeframecount; } -static const device_config_t xga_configuration[] = { +static const device_config_t xga_mca_configuration[] = { // clang-format off - { - .name = "init_bios_addr", - .description = "Initial MCA BIOS Address (before POS configuration)", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc0000, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "C000H", .value = 0xc0000 }, - { .description = "C800H", .value = 0xc8000 }, - { .description = "CC00H", .value = 0xcc000 }, - { .description = "D000H", .value = 0xd0000 }, - { .description = "D400H", .value = 0xd4000 }, - { .description = "D800H", .value = 0xd8000 }, - { .description = "DC00H", .value = 0xdc000 }, - { .description = "" } - }, - }, { .name = "type", .description = "XGA type", @@ -2816,6 +3256,91 @@ static const device_config_t xga_configuration[] = { // clang-format on }; +static const device_config_t xga_isa_configuration[] = { + // clang-format off + { + .name = "type", + .description = "XGA type", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { + .description = "XGA-1", + .value = 0 + }, + { + .description = "XGA-2", + .value = 1 + }, + { .description = "" } + } + }, + { + .name = "instance", + .description = "Instance", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 6, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "0 (2100h-210Fh)", .value = 0 }, + { .description = "1 (2110h-211Fh)", .value = 1 }, + { .description = "2 (2120h-212Fh)", .value = 2 }, + { .description = "3 (2130h-213Fh)", .value = 3 }, + { .description = "4 (2140h-214Fh)", .value = 4 }, + { .description = "5 (2150h-215Fh)", .value = 5 }, + { .description = "6 (2160h-216Fh)", .value = 6 }, + { .description = "7 (2170h-217Fh)", .value = 7 }, + { .description = "" } + }, + }, + { + .name = "ext_mem_addr", + .description = "MMIO address", + .type = CONFIG_HEX16, + .default_string = "", + .default_int = 0x00f0, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "C800h", .value = 0x0040 }, + { .description = "CA00h", .value = 0x0050 }, + { .description = "CC00h", .value = 0x0060 }, + { .description = "CE00h", .value = 0x0070 }, + { .description = "D000h", .value = 0x0080 }, + { .description = "D200h", .value = 0x0090 }, + { .description = "D400h", .value = 0x00a0 }, + { .description = "D600h", .value = 0x00b0 }, + { .description = "D800h", .value = 0x00c0 }, + { .description = "DA00h", .value = 0x00d0 }, + { .description = "DC00h", .value = 0x00e0 }, + { .description = "DE00h", .value = 0x00f0 }, + { .description = "" } + }, + }, + { + .name = "dma", + .description = "DMA channel", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 7, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "DMA 6", .value = 6 }, + { .description = "DMA 7", .value = 7 }, + { .description = "" } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + const device_t xga_device = { .name = "XGA (MCA)", .internal_name = "xga_mca", @@ -2823,11 +3348,11 @@ const device_t xga_device = { .local = 0, .init = xga_init, .close = xga_close, - .reset = NULL, + .reset = xga_reset, { .available = xga_available }, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, - .config = xga_configuration + .config = xga_mca_configuration }; const device_t xga_isa_device = { @@ -2837,17 +3362,31 @@ const device_t xga_isa_device = { .local = 0, .init = xga_init, .close = xga_close, - .reset = NULL, + .reset = xga_reset, { .available = xga_available }, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, - .config = xga_configuration + .config = xga_isa_configuration +}; + +const device_t inmos_isa_device = { + .name = "INMOS XGA (ISA)", + .internal_name = "inmos_xga_isa", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = svga_xga_init, + .close = xga_close, + .reset = xga_reset, + { .available = inmos_xga_available }, + .speed_changed = xga_speed_changed, + .force_redraw = xga_force_redraw, + .config = xga_isa_configuration }; void xga_device_add(void) { - if (!xga_enabled) + if (!xga_enabled || (xga_has_vga && xga_enabled)) return; if (machine_has_bus(machine, MACHINE_BUS_MCA)) diff --git a/src/video/video.c b/src/video/video.c index 0253e3c03..7ecb0e5f9 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -91,11 +91,11 @@ int fullchange = 0; int video_grayscale = 0; int video_graytype = 0; int monitor_index_global = 0; -uint32_t *video_6to8 = NULL, - *video_8togs = NULL, - *video_8to32 = NULL, - *video_15to32 = NULL, - *video_16to32 = NULL; +uint32_t *video_6to8 = NULL; +uint32_t *video_8togs = NULL; +uint32_t *video_8to32 = NULL; +uint32_t *video_15to32 = NULL; +uint32_t *video_16to32 = NULL; monitor_t monitors[MONITORS_NUM]; monitor_settings_t monitor_settings[MONITORS_NUM]; atomic_bool doresize_monitors[MONITORS_NUM]; @@ -308,7 +308,6 @@ static png_infop info_ptr[MONITORS_NUM]; static void video_take_screenshot_monitor(const char *fn, uint32_t *buf, int start_x, int start_y, int row_len, int monitor_index) { - int i, x, y; png_bytep *b_rgb = NULL; FILE *fp = NULL; uint32_t temp = 0x00000000; @@ -350,9 +349,9 @@ video_take_screenshot_monitor(const char *fn, uint32_t *buf, int start_x, int st return; } - for (y = 0; y < blit_data_ptr->h; ++y) { + for (int y = 0; y < blit_data_ptr->h; ++y) { b_rgb[y] = (png_byte *) malloc(png_get_rowbytes(png_ptr[monitor_index], info_ptr[monitor_index])); - for (x = 0; x < blit_data_ptr->w; ++x) { + for (int x = 0; x < blit_data_ptr->w; ++x) { if (buf == NULL) memset(&(b_rgb[y][x * 3]), 0x00, 3); else { @@ -371,7 +370,7 @@ video_take_screenshot_monitor(const char *fn, uint32_t *buf, int start_x, int st png_write_end(png_ptr[monitor_index], NULL); /* cleanup heap allocation */ - for (i = 0; i < blit_data_ptr->h; i++) + for (int i = 0; i < blit_data_ptr->h; i++) if (b_rgb[i]) free(b_rgb[i]); @@ -385,7 +384,8 @@ video_take_screenshot_monitor(const char *fn, uint32_t *buf, int start_x, int st void video_screenshot_monitor(uint32_t *buf, int start_x, int start_y, int row_len, int monitor_index) { - char path[1024], fn[256]; + char path[1024]; + char fn[256]; memset(fn, 0, sizeof(fn)); memset(path, 0, sizeof(path)); @@ -423,14 +423,13 @@ void * video_transform_copy(void *__restrict _Dst, const void *__restrict _Src, size_t _Size) #endif { - int i; uint32_t *dest_ex = (uint32_t *) _Dst; uint32_t *src_ex = (uint32_t *) _Src; _Size /= sizeof(uint32_t); if ((dest_ex != NULL) && (src_ex != NULL)) { - for (i = 0; i < _Size; i++) { + for (size_t i = 0; i < _Size; i++) { *dest_ex = video_color_transform(*src_ex); dest_ex++; src_ex++; @@ -483,10 +482,9 @@ video_blit_memtoscreen_monitor(int x, int y, int w, int h, int monitor_index) uint8_t pixels8(uint32_t *pixels) { - int i; uint8_t temp = 0; - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) temp |= (!!*(pixels + i) << (i ^ 7)); return temp; @@ -511,9 +509,10 @@ pixel_to_color(uint8_t *pixels32, uint8_t pos) void video_blend_monitor(int x, int y, int monitor_index) { - int xx; - uint32_t pixels32_1, pixels32_2; - unsigned int val1, val2; + uint32_t pixels32_1; + uint32_t pixels32_2; + unsigned int val1; + unsigned int val2; static unsigned int carry = 0; if (!herc_blend) @@ -527,7 +526,7 @@ video_blend_monitor(int x, int y, int monitor_index) carry = (val1 & 1) << 7; pixels32_1 = cga_2_table[val1 >> 4] + cga_2_table[val2 >> 4]; pixels32_2 = cga_2_table[val1 & 0xf] + cga_2_table[val2 & 0xf]; - for (xx = 0; xx < 4; xx++) { + for (uint8_t xx = 0; xx < 4; xx++) { monitors[monitor_index].target_buffer->line[y][x + xx] = pixel_to_color((uint8_t *) &pixels32_1, xx); monitors[monitor_index].target_buffer->line[y][x + (xx | 4)] = pixel_to_color((uint8_t *) &pixels32_2, xx); } @@ -536,9 +535,7 @@ video_blend_monitor(int x, int y, int monitor_index) void video_process_8_monitor(int x, int y, int monitor_index) { - int xx; - - for (xx = 0; xx < x; xx++) { + for (int xx = 0; xx < x; xx++) { if (monitors[monitor_index].target_buffer->line[y][xx] <= 0xff) monitors[monitor_index].target_buffer->line[y][xx] = monitors[monitor_index].mon_pal_lookup[monitors[monitor_index].target_buffer->line[y][xx]]; else @@ -630,9 +627,8 @@ video_update_timing(void) int *vid_timing_write_b = NULL; int *vid_timing_write_l = NULL; int *vid_timing_write_w = NULL; - int i = 0; - for (i = 0; i < MONITORS_NUM; i++) { + for (uint8_t i = 0; i < MONITORS_NUM; i++) { monitor_vid_timings = monitors[i].mon_vid_timings; if (!monitor_vid_timings) continue; @@ -683,7 +679,8 @@ video_update_timing(void) int calc_6to8(int c) { - int ic, i8; + int ic; + int i8; double d8; ic = c; @@ -700,8 +697,12 @@ calc_6to8(int c) int calc_8to32(int c) { - int b, g, r; - double db, dg, dr; + int b; + int g; + int r; + double db; + double dg; + double dr; b = (c & 3); g = ((c >> 2) & 7); @@ -719,8 +720,12 @@ calc_8to32(int c) int calc_15to32(int c) { - int b, g, r; - double db, dg, dr; + int b; + int g; + int r; + double db; + double dg; + double dr; b = (c & 31); g = ((c >> 5) & 31); @@ -738,8 +743,12 @@ calc_15to32(int c) int calc_16to32(int c) { - int b, g, r; - double db, dg, dr; + int b; + int g; + int r; + double db; + double dg; + double dr; b = (c & 31); g = ((c >> 5) & 63); @@ -757,12 +766,10 @@ calc_16to32(int c) void hline(bitmap_t *b, int x1, int y, int x2, uint32_t col) { - int x; - if (y < 0 || y >= b->h) return; - for (x = x1; x < x2; x++) + for (int x = x1; x < x2; x++) b->line[y][x] = col; } @@ -800,15 +807,14 @@ bitmap_t * create_bitmap(int x, int y) { bitmap_t *b = malloc(sizeof(bitmap_t) + (y * sizeof(uint32_t *))); - int c; b->dat = malloc((size_t) x * y * 4); - for (c = 0; c < y; c++) + for (int c = 0; c < y; c++) b->line[c] = &(b->dat[c * x]); b->w = x; b->h = y; - return (b); + return b; } void @@ -871,7 +877,8 @@ video_monitor_close(int monitor_index) void video_init(void) { - int c, d; + int c; + int d; uint8_t total[2] = { 0, 1 }; for (c = 0; c < 16; c++) { @@ -966,7 +973,8 @@ video_force_resize_set_monitor(uint8_t res, int monitor_index) void loadfont_common(FILE *f, int format) { - int c, d; + int c; + int d; switch (format) { case 0: /* MDA */ diff --git a/src/vnc.c b/src/vnc.c index eaa1d89fe..30caff9e2 100644 --- a/src/vnc.c +++ b/src/vnc.c @@ -40,9 +40,11 @@ static rfbScreenInfoPtr rfb = NULL; static int clients; static int updatingSize; -static int allowedX, - allowedY; -static int ptr_x, ptr_y, ptr_but; +static int allowedX; +static int allowedY; +static int ptr_x; +static int ptr_y; +static int ptr_but; typedef struct { int buttons; @@ -91,13 +93,23 @@ vnc_mouse_poll(void) ms.dx = 0; ms.dy = 0; - // pclog("dx=%d, dy=%d, dwheel=%d\n", mouse_x, mouse_y, mouse_z); +#if 0 + pclog("dx=%d, dy=%d, dwheel=%d\n", mouse_x, mouse_y, mouse_z); +#endif } if (b != ms.buttons) { mouse_buttons = ms.buttons; b = ms.buttons; } + + mouse_x_abs = (double)ptr_x / (double)allowedX; + mouse_y_abs = (double)ptr_y / (double)allowedY; + + if (mouse_x_abs > 1.0) mouse_x_abs = 1.0; + if (mouse_y_abs > 1.0) mouse_y_abs = 1.0; + if (mouse_x_abs < 0.0) mouse_x_abs = 0.0; + if (mouse_y_abs < 0.0) mouse_y_abs = 0.0; } static void @@ -122,7 +134,7 @@ vnc_ptrevent(int but, int x, int y, rfbClientPtr cl) } static void -vnc_clientgone(rfbClientPtr cl) +vnc_clientgone(UNUSED(rfbClientPtr cl)) { vnc_log("VNC: client disconnected: %s\n", cl->host); @@ -133,7 +145,9 @@ vnc_clientgone(rfbClientPtr cl) vnc_log("VNC: no clients, pausing..\n"); /* Disable the mouse. */ - // plat_mouse_capture(0); +#if 0 + plat_mouse_capture(0); +#endif mouse_set_poll_ex(NULL); plat_pause(1); @@ -159,14 +173,16 @@ vnc_newclient(rfbClientPtr cl) vnc_log("VNC: unpausing..\n"); /* Enable the mouse. */ - // plat_mouse_capture(1); +#if 0 + plat_mouse_capture(1); +#endif mouse_set_poll_ex(vnc_mouse_poll); plat_pause(0); } /* For now, we always accept clients. */ - return (RFB_CLIENT_ACCEPT); + return RFB_CLIENT_ACCEPT; } static void @@ -186,14 +202,12 @@ vnc_display(rfbClientPtr cl) static void vnc_blit(int x, int y, int w, int h, int monitor_index) { - int row; - if (monitor_index || (x < 0) || (y < 0) || (w < VNC_MIN_X) || (h < VNC_MIN_Y) || (w > VNC_MAX_X) || (h > VNC_MAX_Y) || (buffer32 == NULL)) { video_blit_complete_monitor(monitor_index); return; } - for (row = 0; row < h; ++row) + for (int row = 0; row < h; ++row) video_copy(&(((uint8_t *) rfb->frameBuffer)[row * 2048 * sizeof(uint32_t)]), &(buffer32->line[y + row][x]), w * sizeof(uint32_t)); if (screenshots) @@ -259,7 +273,7 @@ vnc_init(UNUSED(void *arg)) vnc_log("VNC: init complete.\n"); - return (1); + return 1; } void @@ -317,7 +331,7 @@ vnc_pause(void) } void -vnc_take_screenshot(wchar_t *fn) +vnc_take_screenshot(UNUSED(wchar_t *fn)) { vnc_log("VNC: take_screenshot\n"); } diff --git a/src/vnc_keymap.c b/src/vnc_keymap.c index 923f6ecf0..599ba1d9b 100644 --- a/src/vnc_keymap.c +++ b/src/vnc_keymap.c @@ -623,21 +623,21 @@ static int keysyms_ff[] = { #ifdef ENABLE_VNC_KEYMAP_LOG int vnc_keymap_do_log = ENABLE_VNC_KEYMAP_LOG; -#endif static void -vnc_keymap_log(const char *format, ...) +vnc_keymap_log(const char *fmt, ...) { -#ifdef ENABLE_VNC_KEYMAP_LOG va_list ap; if (vnc_keymap_do_log) { - va_start(ap, format); - pclog_ex(format, ap); + va_start(ap, fmt); + pclog_ex(fmt, ap); va_end(ap); } -#endif } +#else +# define vnc_keymap_log(fmt, ...) +#endif void vnc_kbinput(int down, int k) @@ -665,8 +665,8 @@ vnc_kbinput(int down, int k) /* Send this scancode sequence to the PC keyboard. */ switch (scan >> 8) { - case 0x00: default: + case 0x00: if (scan & 0xff) keyboard_input(down, scan & 0xff); break; diff --git a/src/win/86Box.rc b/src/win/86Box.rc index e180873ff..2932b7d62 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -42,7 +42,7 @@ BEGIN #ifdef MTR_ENABLED "T", IDM_ACTION_TRACE, CONTROL, VIRTKEY #endif - VK_PRIOR,IDM_VID_FULLSCREEN, VIRTKEY, CONTROL , ALT + // VK_PRIOR,IDM_VID_FULLSCREEN, VIRTKEY, CONTROL , ALT VK_F11, IDM_ACTION_SCREENSHOT, VIRTKEY, CONTROL VK_F12, IDM_ACTION_RESET_CAD, VIRTKEY, CONTROL VK_PAUSE,IDM_ACTION_PAUSE, VIRTKEY diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 3f6bf5cdb..a947dfb62 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -209,6 +209,9 @@ endif ifndef MINITRACE MINITRACE := n endif +ifndef AVX + AVX := n +endif ifeq ($(DYNAREC), y) ifeq ($(ARM), y) ifeq ($(NEW_DYNAREC), n) @@ -238,14 +241,14 @@ PROG := 86Box ######################################################################### # Nothing should need changing from here on.. # ######################################################################### -VPATH := $(EXPATH) . $(CODEGEN) minitrace cpu \ - cdrom chipset device disk disk/minivhd floppy \ +VPATH := $(EXPATH) . $(CODEGEN) minitrace cpu cpu/softfloat \ + cpu/808x cdrom chipset device disk disk/minivhd floppy \ game machine mem printer \ sio sound \ sound/munt sound/munt/c_interface sound/munt/sha1 \ sound/munt/srchelper sound/munt/srchelper/srctools/src \ sound/resid-fp sound/ymfm \ - scsi video network network/slirp win + scsi video network win WINDRES := windres STRIP := strip @@ -266,8 +269,8 @@ else endif ifeq ($(CLANG), y) - CPP := ${TOOL_PREFIX}clang++ - CC := ${TOOL_PREFIX}clang + CPP := clang++ + CC := clang else CPP := ${TOOL_PREFIX}g++ CC := ${TOOL_PREFIX}gcc @@ -301,20 +304,45 @@ ifeq ($(DEBUG), y) ifndef COPTIM COPTIM := -Og endif + ifndef CXXOPTIM + ifeq ($(CLANG), y) + CXXOPTIM := -Os + else + CXXOPTIM := -Og + endif + endif else DFLAGS += -g0 ifeq ($(OPTIM), y) AOPTIM := -mtune=native ifndef COPTIM - COPTIM := -O3 -ffp-contract=fast -flto + CXXOPTIM := -O3 -ffp-contract=fast -flto + endif + ifndef CXXOPTIM + ifeq ($(CLANG), y) + CXXOPTIM := -Os -ffp-contract=fast -flto + else + CXXOPTIM := -O3 -ffp-contract=fast -flto + endif endif else ifndef COPTIM COPTIM := -O3 endif + ifndef CXXOPTIM + ifeq ($(CLANG), y) + CXXOPTIM := -Os + else + CXXOPTIM := -O3 + endif + endif endif endif -AFLAGS := -msse2 -mfpmath=sse +ifeq ($(AVX), y) + AFLAGS := -msse2 -msse3 -mssse3 -msse4 -msse4a -mavx -mavx2 -mfpmath=sse +else + AFLAGS := -msse2 -mfpmath=sse +endif ifeq ($(ARM), y) DFLAGS := -march=armv7-a AOPTIM := @@ -524,7 +552,9 @@ CFLAGS := $(OPTS) $(DFLAGS) $(COPTIM) $(AOPTIM) \ # Add freetyp2 references through pkgconfig CFLAGS := $(CFLAGS) `pkg-config --cflags freetype2` -CXXFLAGS := $(CFLAGS) +CXXFLAGS := $(OPTS) $(DFLAGS) $(CXXOPTIM) $(AOPTIM) \ + $(AFLAGS) -fomit-frame-pointer -mstackrealign -Wall \ + -fno-strict-aliasing CFLAGS += -Werror=implicit-int -Werror=implicit-function-declaration \ -Werror=int-conversion -Werror=strict-prototypes -Werror=old-style-definition @@ -538,13 +568,17 @@ MAINOBJ := 86box.o config.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma. usb.o device.o nvr.o nvr_at.o nvr_ps2.o machine_status.o ini.o \ $(VNCOBJ) -MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o +MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o row.o smram.o spd.o sst_flash.o + +CPU808XOBJ := queue.o CPUOBJ := $(DYNARECOBJ) \ $(CGTOBJ) \ cpu.o cpu_table.o fpu.o x86.o \ 8080.o 808x.o 386.o 386_common.o 386_dynarec.o 386_dynarec_ops.o \ - x86seg.o x87.o x87_timings.o + x86_ops_mmx.o x86seg.o x87.o x87_timings.o \ + f2xm1.o fpatan.o fprem.o fsincos.o fyl2x.o softfloat_poly.o softfloat.o softfloat16.o \ + softfloat-muladd.o softfloat-round-pack.o softfloat-specialize.o softfloatx80.o CHIPSETOBJ := 82c100.o acc2168.o \ contaq_82c59x.o \ @@ -581,11 +615,8 @@ MCHOBJ := machine.o machine_table.o \ m_at_socket8.o m_at_slot1.o m_at_slot2.o m_at_socket370.o \ m_at_misc.o -ifeq ($(NEW_KBC), y) - KBCOBJ := kbc_at.o kbd_at.o -else - KBCOBJ := keyboard_at.o -endif +KBCOBJ := kbc_at.o kbc_at_dev.o \ + keyboard_at.o DEVOBJ := bugger.o cartridge.o cassette.o hasp.o hwm.o hwm_lm75.o hwm_lm78.o hwm_gl518sm.o hwm_vt82c686.o \ ibm_5161.o isamem.o isartc.o lpt.o pci_bridge.o postcard.o serial.o \ @@ -631,9 +662,8 @@ HDDOBJ := hdd.o \ hdc_ide_cmd640.o hdc_ide_cmd646.o \ hdc_ide_sff8038i.o -MINIVHDOBJ := cwalk.o libxml2_encoding.o minivhd_convert.o \ - minivhd_create.o minivhd_io.o minivhd_manage.o \ - minivhd_struct_rw.o minivhd_util.o +MINIVHDOBJ := cwalk.o xml2_encoding.o convert.o \ + create.o minivhd_io.o manage.o struct_rw.o minivhd_util.o CDROMOBJ := cdrom.o \ cdrom_image_backend.o cdrom_image_viso.o cdrom_image.o cdrom_mitsumi.o @@ -649,22 +679,14 @@ SCSIOBJ := scsi.o scsi_device.o \ scsi_ncr5380.o scsi_ncr53c8xx.o \ scsi_pcscsi.o scsi_spock.o -SLIRPOBJ := net_slirp.o tinyglib.o \ - arp_table.o bootp.o cksum.o dhcpv6.o dnssearch.o if.o \ - ip_icmp.o ip_input.o ip_output.o \ - ip6_icmp.o ip6_input.o ip6_output.o \ - mbuf.o misc.o sbuf.o slirp.o socket.o \ - tcp_input.o tcp_output.o tcp_subr.o tcp_timer.o \ - udp.o udp6.o \ - util.o version.o \ - NETOBJ := network.o \ net_pcap.o \ - ${SLIRPOBJ} \ + net_slirp.o \ net_dp8390.o net_3c501.o \ net_3c503.o net_ne2000.o \ net_pcnet.o net_wd8003.o \ - net_plip.o net_event.o + net_plip.o net_event.o \ + net_null.o PRINTOBJ := png.o prt_cpmap.o \ prt_escp.o prt_text.o prt_ps.o @@ -714,6 +736,7 @@ VIDOBJ := agpgart.o video.o \ vid_vga.o \ vid_ati_eeprom.o \ vid_ati18800.o vid_ati28800.o \ + vid_ati_mach8.o \ vid_ati_mach64.o vid_ati68860_ramdac.o \ vid_bt48x_ramdac.o \ vid_av9194.o vid_icd2061.o vid_ics2494.o vid_ics2595.o \ @@ -775,7 +798,7 @@ ifeq ($(RTMIDI), y) SNDOBJ += midi_rtmidi.o endif -OBJ := $(MAINOBJ) $(CPUOBJ) $(CHIPSETOBJ) $(MCHOBJ) $(DEVOBJ) $(MEMOBJ) \ +OBJ := $(MAINOBJ) $(CPU808XOBJ) $(CPUOBJ) $(CHIPSETOBJ) $(MCHOBJ) $(DEVOBJ) $(MEMOBJ) \ $(FDDOBJ) $(GAMEOBJ) $(CDROMOBJ) $(ZIPOBJ) $(MOOBJ) $(HDDOBJ) $(MINIVHDOBJ) \ $(NETOBJ) $(PRINTOBJ) $(SCSIOBJ) $(SIOOBJ) $(SNDOBJ) $(VIDOBJ) $(VOODOOOBJ) \ $(PLATOBJ) $(UIOBJ) $(FSYNTHOBJ) $(MUNTOBJ) $(DEVBROBJ) $(MINITRACEOBJ) $(THREADOBJ) @@ -789,24 +812,43 @@ else MWIN := -mwindows endif +LIBS := -lfreetype -lfluidsynth -lslirp -lbz2 -lharfbuzz -lgraphite2 -lbrotlidec \ + -lbrotlicommon -lusp10 -lrpcrt4 -lgomp -lsndfile -lflac -lmp3lame -lmpg123 \ + -lopus -lvorbis -lvorbisenc -logg -ldsound -lshlwapi -lksuser -lreadline \ + -ltermcap -lportaudio -lgmodule-2.0 -lglib-2.0 -lintl -liconv + ifeq ($(OPENAL), y) - LIBS := $(MWIN) -lopenal -lcomctl32 -lSDL2 -limagehlp -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -lws2_32 + LIBS += $(MWIN) -lopenal -lcomctl32 -lSDL2 -limagehlp -ldinput8 -ldxguid -ldxerr8 \ + -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion \ + -luuid -lws2_32 else ifeq ($(FAUDIO), y) - LIBS := $(MWIN) -lfaudio -lcomctl32 -lSDL2 -limagehlp -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -lws2_32 + LIBS += $(MWIN) -lfaudio -lcomctl32 -lSDL2 -limagehlp -ldinput8 -ldxguid -ldxerr8 \ + -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion \ + -luuid -lws2_32 else - LIBS := $(MWIN) -lcomctl32 -lSDL2 -limagehlp -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -lws2_32 + LIBS += $(MWIN) -lcomctl32 -lSDL2 -limagehlp -ldinput8 -ldxguid -ldxerr8 -luser32 \ + -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid \ + -lws2_32 endif endif ifeq ($(RTMIDI), y) - LIBS += -lrtmidi -lwinmm + ifeq ($(CLANG), y) + LIBS += -lrtmidi.dll -lwinmm + else + LIBS += -lrtmidi -lwinmm + endif endif ifeq ($(VNC), y) LIBS += $(VNCLIB) -lws2_32 endif -LIBS += -lpng -lz -lwsock32 -liphlpapi -lpsapi -lhid -lsetupapi -luxtheme -static -lstdc++ +ifeq ($(CLANG), y) + LIBS += -lpng -lz -lwsock32 -liphlpapi -lpsapi -lhid -lsetupapi -luxtheme -static -lstdc++.dll +else + LIBS += -lpng -lz -lwsock32 -liphlpapi -lpsapi -lhid -lsetupapi -luxtheme -static -lstdc++ +endif ifneq ($(X64), y) ifneq ($(ARM64), y) LIBS += -Wl,--large-address-aware @@ -871,7 +913,7 @@ all: $(PROG).exe 86Box.res: 86Box.rc @echo Processing $< - @$(WINDRES) $(RFLAGS) $(EXTRAS) -i $< -o 86Box.res + @$(WINDRES) -v $(RFLAGS) $(EXTRAS) -i $< -o 86Box.res $(PROG).exe: $(OBJ) 86Box.res @echo Linking $(PROG).exe .. diff --git a/src/win/languages/cs-CZ.rc b/src/win/languages/cs-CZ.rc index a46700771..ae7e3daf8 100644 --- a/src/win/languages/cs-CZ.rc +++ b/src/win/languages/cs-CZ.rc @@ -13,7 +13,7 @@ LANGUAGE LANG_CZECH, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Akce" BEGIN @@ -34,7 +34,7 @@ BEGIN MENUITEM "&Schovat stavový řádek", IDM_VID_HIDE_STATUS_BAR MENUITEM "Schovat panel &nástrojů", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS MENUITEM "&Měnitelná velikost okna", IDM_VID_RESIZE MENUITEM "&Pamatovat velikost a pozici", IDM_VID_REMEMBER MENUITEM SEPARATOR @@ -128,7 +128,7 @@ BEGIN END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -278,6 +278,7 @@ END #define STR_ENABLED_LOCAL "Zapnuta (místní čas)" #define STR_ENABLED_UTC "Zapnuta (UTC)" #define STR_DYNAREC "Dynamický překladač" +#define STR_SOFTFLOAT "Softfloat FPU" #define STR_VIDEO "Grafika:" #define STR_VIDEO_2 "Grafika 2:" @@ -367,7 +368,6 @@ END #define STR_CHECKBPB "Kontrola BPB" #define STR_CDROM_DRIVES "Mechaniky CD-ROM:" #define STR_CD_SPEED "Rychlost:" -#define STR_EARLY "Časná mechanika" #define STR_MO_DRIVES "Magnetooptické mechaniky:" #define STR_ZIP_DRIVES "Mechaniky ZIP:" @@ -392,7 +392,7 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN 2048 "86Box" IDS_2049 "Chyba" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Počítač ""%hs"" není dostupný, jelikož chybí obraz jeho paměti ROM ve složce ""roms/machines"". Konfigurace se přepne na jiný dostupný počítač." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Video adaptér ""%hs"" není dostupný, jelikož chybí obraz jeho paměti ROM ve složce ""roms/video"". Konfigurace se přepne na jiný dostupný adaptér." IDS_2065 "Počítač" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Stiskněte F8+F12 nebo prostřední tlačítko pro uvolnění myši" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nastala chyba při inicializaci knihovny FluidSynth." IDS_2081 "Sběrnice" IDS_2082 "Soubor" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disketová mechanika %i (%s): %ls" IDS_2110 "Všechny obrazy (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Rozšířené sektorové obrazy (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Základní sektorové obrazy (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Obrazy magnetického toku (*.FDI)\0*.FDI\0Obrazy povrchu (*.86F;*.MFM)\0*.86F;*.MFM\0Všechny soubory (*.*)\0*.*\0" - IDS_2111 "Nastala chyba při inicializaci knihovny FreeType" IDS_2112 "Nastala chyba při inicializaci knihovny SDL, je potřeba SDL2.dll" IDS_2113 "Opravdu chcete resetovat emulovaný počítač?" IDS_2114 "Opravdu chcete ukončit 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Ujistěte se, že je nainstalován " LIB_NAME_PCAP " a používáte síťové připojení s ním kompatibilní." IDS_2131 "Neplatná konfigurace" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " je potřeba pro emulaci ESC/P tiskáren." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " je potřeba pro automatický převod PostScript dokumentů do PDF.\n\nJakékoliv dokumenty vytisknuté přes obecnou PostScriptovou tiskárnu budou uloženy jako PostScript (.ps) soubory." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " je potřeba pro MIDI výstup přes knihovnu FluidSynth." IDS_2135 "Vstup do režimu celé obrazovky" IDS_2136 "Nezobrazovat dále tuto zprávu" IDS_2137 "Neukončovat" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Resetovat" IDS_2160 "Vypnout skrze rozhraní ACPI" IDS_2161 "Nastavení" - IDS_2162 "Časná mechanika" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Pevný disk (%s)" IDS_4097 "%01i:%01i" diff --git a/src/win/languages/de-DE.rc b/src/win/languages/de-DE.rc index 79872535a..5e6f38221 100644 --- a/src/win/languages/de-DE.rc +++ b/src/win/languages/de-DE.rc @@ -13,7 +13,7 @@ LANGUAGE LANG_GERMAN, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Aktionen" BEGIN @@ -128,7 +128,7 @@ BEGIN END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -278,6 +278,7 @@ END #define STR_ENABLED_LOCAL "Aktiviert (Lokale Uhrzeit)" #define STR_ENABLED_UTC "Aktiviert (UTC)" #define STR_DYNAREC "Dynamischer Recompiler" +#define STR_SOFTFLOAT "Softfloat FPU" #define STR_VIDEO "Videokarte:" #define STR_VIDEO_2 "Videokarte 2:" @@ -367,7 +368,6 @@ END #define STR_CHECKBPB "BPB überprüfen" #define STR_CDROM_DRIVES "CD-ROM-Laufwerke:" #define STR_CD_SPEED "Geschwindigkeit:" -#define STR_EARLY "Früheres Laufwerk" #define STR_MO_DRIVES "MO-Laufwerke:" #define STR_ZIP_DRIVES "ZIP-Laufwerke:" @@ -392,7 +392,7 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN 2048 "86Box" IDS_2049 "Fehler" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Das System ""%hs"" ist aufgrund von fehlenden ROMs im Verzeichnis roms/machines nicht verfügbar. Es wird auf ein verfügbares System gewechselt." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Die Videokarte ""%hs"" ist aufgrund von fehlenden ROMs im Verzeichnis roms/video nicht verfügbar. Es wird auf eine verfügbare Videokarte gewechselt." IDS_2065 "System" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Bitte F8+F12 oder die mittlere Maustaste zur Mausfreigabe drücken" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynth konnte nicht initialisiert werden" IDS_2081 "Bus" IDS_2082 "Datei" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Diskette %i (%s): %ls" IDS_2110 "Alle Images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Fortgeschrittene Sektorimages (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basissektorimages (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Fluximages (*.FDI)\0*.FDI\0Oberflächenimages (*.86F;*.MFM)\0*.86F;*.MFM\0Alle Dateien (*.*)\0*.*\0" - IDS_2111 "FreeType konnte nicht initialisiert werden" IDS_2112 "SDL konnte nicht initialisiert werden, die Datei SDL2.dll wird benötigt" IDS_2113 "Sind Sie sich sicher, dass Sie einen Hard-Reset für das emulierte System durchführen wollen?" IDS_2114 "Sind Sie sich sicher, dass Sie 86Box beenden wollen?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Bitte stellen Sie sicher, dass " LIB_NAME_PCAP " installiert ist und sie eine " LIB_NAME_PCAP "-kompatible Netzwerkverbindung nutzen." IDS_2131 "Ungültige Konfiguration" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " wird für die ESC/P-Druckeremulation benötigt." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " wird zur automatischen Konversion von PostScript-Dateien in das PDF-Format benötigt.\n\nSämtliche an den generischen PostScript-Drucker gesendete Dateien werden als PostScript (.ps)-Dateien gesichert." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " wird für die FluidSynth-MIDI-Ausgabe benötigt." IDS_2135 "Vollbildmodus wird aktiviert" IDS_2136 "Diese Nachricht nicht mehr anzeigen" IDS_2137 "Nicht beenden" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Hard-Reset" IDS_2160 "ACPI-basiertes Herunterfahren" IDS_2161 "Optionen" - IDS_2162 "Früheres Laufwerk" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Festplatte (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Systemstandard)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // German (de-DE) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/dialogs.rc b/src/win/languages/dialogs.rc index 1facfb10d..1daf46b4c 100644 --- a/src/win/languages/dialogs.rc +++ b/src/win/languages/dialogs.rc @@ -3,6 +3,8 @@ #define CFG_BTN_WIDTH 46 #define CFG_BTN_HEIGHT 14 #define CFG_PANE_LTEXT_PRI_WIDTH 85 +#define CFG_PANE_LTEXT_PRI_WIDTH_2 170 +#define CFG_PANE_LTEXT_PRI_WIDTH_3 255 #define CFG_PANE_LTEXT_HEIGHT 10 #define CFG_COMBO_BTN_WIDTH 212 #define CFG_COMBO_NOBTN_WIDTH CFG_COMBO_BTN_WIDTH + CFG_BTN_WIDTH + 8 @@ -232,20 +234,25 @@ BEGIN CFG_HMARGIN, 120, 120, CFG_CHECKBOX_HEIGHT #endif + CONTROL STR_SOFTFLOAT, IDC_CHECK_SOFTFLOAT, + "Button", BS_AUTOCHECKBOX | WS_TABSTOP, + CFG_HMARGIN, 135, 120, CFG_CHECKBOX_HEIGHT + + GROUPBOX STR_TIME_SYNC, IDC_TIME_SYNC, - CFG_HMARGIN, 135, 110, 56 + CFG_HMARGIN, 150, 110, 56 CONTROL STR_DISABLED, IDC_RADIO_TS_DISABLED, "Button", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, - 14, 147, CFG_CHECKBOX_PRI_WIDTH, CFG_CHECKBOX_HEIGHT + 14, 162, CFG_CHECKBOX_PRI_WIDTH, CFG_CHECKBOX_HEIGHT CONTROL STR_ENABLED_LOCAL, IDC_RADIO_TS_LOCAL, "Button", BS_AUTORADIOBUTTON | WS_TABSTOP, - 14, 161, CFG_CHECKBOX_PRI_WIDTH, CFG_CHECKBOX_HEIGHT + 14, 176, CFG_CHECKBOX_PRI_WIDTH, CFG_CHECKBOX_HEIGHT CONTROL STR_ENABLED_UTC, IDC_RADIO_TS_UTC, "Button", BS_AUTORADIOBUTTON | WS_TABSTOP, - 14, 175, CFG_CHECKBOX_PRI_WIDTH, CFG_CHECKBOX_HEIGHT + 14, 190, CFG_CHECKBOX_PRI_WIDTH, CFG_CHECKBOX_HEIGHT END DLG_CFG_VIDEO DIALOG DISCARDABLE CFG_PANE_LEFT, CFG_PANE_TOP, CFG_PANE_WIDTH, CFG_PANE_HEIGHT @@ -397,23 +404,67 @@ FONT FONT_SIZE, FONT_NAME BEGIN LTEXT STR_NET_TYPE, IDT_NET_TYPE, CFG_HMARGIN, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT - COMBOBOX IDC_COMBO_NET1_TYPE, - CFG_COMBO_BOX_LEFT, 7, CFG_COMBO_NOBTN_WIDTH, CFG_COMBO_HEIGHT, - CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT STR_PCAP, IDT_PCAP, - CFG_HMARGIN, 28, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT - COMBOBOX IDC_COMBO_PCAP1, - CFG_COMBO_BOX_LEFT, 26, CFG_COMBO_NOBTN_WIDTH, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH - 10, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT + LTEXT STR_NET, IDT_NET, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT + + COMBOBOX IDC_COMBO_NET1_TYPE, + CFG_HMARGIN, 28, 48, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + COMBOBOX IDC_COMBO_PCAP1, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH - 10, 28, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT STR_NET, IDT_NET, - CFG_HMARGIN, 47, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT COMBOBOX IDC_COMBO_NET1, - CFG_COMBO_BOX_LEFT, 45, CFG_COMBO_BTN_WIDTH, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 28, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET1, - CFG_COMBO_BTN_LEFT, 44, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 27, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + + COMBOBOX IDC_COMBO_NET2_TYPE, + CFG_HMARGIN, 49, 48, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + COMBOBOX IDC_COMBO_PCAP2, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH - 10, 49, 110, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + COMBOBOX IDC_COMBO_NET2, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 49, 110, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET2, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 48, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + + COMBOBOX IDC_COMBO_NET3_TYPE, + CFG_HMARGIN, 70, 48, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + COMBOBOX IDC_COMBO_PCAP3, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH - 10, 70, 110, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + COMBOBOX IDC_COMBO_NET3, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 70, 110, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET3, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 69, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + + COMBOBOX IDC_COMBO_NET4_TYPE, + CFG_HMARGIN, 91, 48, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + COMBOBOX IDC_COMBO_PCAP4, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH - 10, 91, 110, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + COMBOBOX IDC_COMBO_NET4, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 91, 110, CFG_COMBO_HEIGHT, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET4, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 90, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + END DLG_CFG_PORTS DIALOG DISCARDABLE CFG_PANE_LEFT, CFG_PANE_TOP, CFG_PANE_WIDTH, CFG_PANE_HEIGHT @@ -614,22 +665,28 @@ BEGIN LTEXT STR_BUS,IDT_BUS, CFG_HMARGIN, 188, 24, CFG_PANE_LTEXT_HEIGHT COMBOBOX IDC_COMBO_HD_BUS, - 33, 186, 130, 12,CBS_DROPDOWNLIST | + 33, 186, 40, 12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT STR_CHANNEL, IDT_CHANNEL, - 181, 188, 38, CFG_PANE_LTEXT_HEIGHT + 91, 188, 38, CFG_PANE_LTEXT_HEIGHT COMBOBOX IDC_COMBO_HD_CHANNEL, - 221, 186, 140, 12, + 131, 186, 40, 12, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_HD_CHANNEL_IDE, - 221, 186, 140, 12, + 131, 186, 40, 12, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT STR_ID, IDT_ID, - 181, 188, 38, CFG_PANE_LTEXT_HEIGHT + 91, 188, 38, CFG_PANE_LTEXT_HEIGHT COMBOBOX IDC_COMBO_HD_ID, - 221, 186, 140, 12, + 131, 186, 70, 12, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + + LTEXT STR_SPEED, IDT_SPEED, + 201, 188, 38, CFG_PANE_LTEXT_HEIGHT + COMBOBOX IDC_COMBO_HD_SPEED, + 241, 186, 70, 12, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_NEW, IDC_BUTTON_HDD_ADD_NEW, @@ -785,9 +842,12 @@ BEGIN 33, 205, 140, 12, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - CONTROL STR_EARLY, IDC_CHECKEARLY, - "Button", BS_AUTOCHECKBOX | WS_TABSTOP, - 186, 206, 84, CFG_CHECKBOX_HEIGHT + LTEXT STR_TYPE, IDT_CD_TYPE, + 181, 207, 34, CFG_PANE_LTEXT_HEIGHT + COMBOBOX IDC_COMBO_CD_TYPE, + 221, 205, 140, 12, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + END DLG_CFG_OTHER_REMOVABLE_DEVICES DIALOG DISCARDABLE CFG_PANE_LEFT, CFG_PANE_TOP, CFG_PANE_WIDTH, CFG_PANE_HEIGHT @@ -974,6 +1034,7 @@ END #undef STR_ENABLED_LOCAL #undef STR_ENABLED_UTC #undef STR_DYNAREC +#undef STR_SOFTFLOAT #undef STR_VIDEO #undef STR_VIDEO_2 @@ -1003,6 +1064,10 @@ END #undef STR_NET_TYPE #undef STR_PCAP #undef STR_NET +#undef STR_NET1 +#undef STR_NET2 +#undef STR_NET3 +#undef STR_NET4 #undef STR_COM1 #undef STR_COM2 diff --git a/src/win/languages/en-GB.rc b/src/win/languages/en-GB.rc index d673f1a2c..9f6f178a6 100644 --- a/src/win/languages/en-GB.rc +++ b/src/win/languages/en-GB.rc @@ -13,7 +13,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Action" BEGIN @@ -40,12 +40,12 @@ BEGIN MENUITEM SEPARATOR POPUP "Re&nderer" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR @@ -53,16 +53,16 @@ BEGIN MENUITEM "F&orce 4:3 display ratio", IDM_VID_FORCE43 POPUP "&Window scale factor" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Filter method" BEGIN @@ -109,7 +109,7 @@ BEGIN MENUITEM SEPARATOR MENUITEM "Take s&creenshot\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Preferences...", IDM_PREFERENCES + MENUITEM "&Preferences...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Enable &Discord integration", IDM_DISCORD #endif @@ -128,7 +128,7 @@ BEGIN END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -278,6 +278,7 @@ END #define STR_ENABLED_LOCAL "Enabled (local time)" #define STR_ENABLED_UTC "Enabled (UTC)" #define STR_DYNAREC "Dynamic Recompiler" +#define STR_SOFTFLOAT "Softfloat FPU" #define STR_VIDEO "Video:" #define STR_VIDEO_2 "Video 2:" @@ -296,42 +297,42 @@ END #define STR_SOUND2 "Sound card 2:" #define STR_SOUND3 "Sound card 3:" #define STR_SOUND4 "Sound card 4:" -#define STR_MIDI_OUT "MIDI Out Device:" -#define STR_MIDI_IN "MIDI In Device:" +#define STR_MIDI_OUT "MIDI Out Device:" +#define STR_MIDI_IN "MIDI In Device:" #define STR_MPU401 "Standalone MPU-401" -#define STR_FLOAT "Use FLOAT32 sound" -#define STR_FM_DRIVER "FM synth driver" -#define STR_FM_DRV_NUKED "Nuked (more accurate)" -#define STR_FM_DRV_YMFM "YMFM (faster)" +#define STR_FLOAT "Use FLOAT32 sound" +#define STR_FM_DRIVER "FM synth driver" +#define STR_FM_DRV_NUKED "Nuked (more accurate)" +#define STR_FM_DRV_YMFM "YMFM (faster)" -#define STR_NET_TYPE "Network type:" -#define STR_PCAP "PCap device:" -#define STR_NET "Network adapter:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Network type:" +#define STR_PCAP "PCap device:" +#define STR_NET "Network adapter:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "COM1 Device:" -#define STR_COM2 "COM2 Device:" -#define STR_COM3 "COM3 Device:" -#define STR_COM4 "COM4 Device:" -#define STR_LPT1 "LPT1 Device:" -#define STR_LPT2 "LPT2 Device:" -#define STR_LPT3 "LPT3 Device:" -#define STR_LPT4 "LPT4 Device:" -#define STR_SERIAL1 "Serial port 1" -#define STR_SERIAL2 "Serial port 2" -#define STR_SERIAL3 "Serial port 3" -#define STR_SERIAL4 "Serial port 4" -#define STR_PARALLEL1 "Parallel port 1" -#define STR_PARALLEL2 "Parallel port 2" -#define STR_PARALLEL3 "Parallel port 3" -#define STR_PARALLEL4 "Parallel port 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1 Device:" +#define STR_COM2 "COM2 Device:" +#define STR_COM3 "COM3 Device:" +#define STR_COM4 "COM4 Device:" +#define STR_LPT1 "LPT1 Device:" +#define STR_LPT2 "LPT2 Device:" +#define STR_LPT3 "LPT3 Device:" +#define STR_LPT4 "LPT4 Device:" +#define STR_SERIAL1 "Serial port 1" +#define STR_SERIAL2 "Serial port 2" +#define STR_SERIAL3 "Serial port 3" +#define STR_SERIAL4 "Serial port 4" +#define STR_PARALLEL1 "Parallel port 1" +#define STR_PARALLEL2 "Parallel port 2" +#define STR_PARALLEL3 "Parallel port 3" +#define STR_PARALLEL4 "Parallel port 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" #define STR_HDC "HD Controller:" #define STR_FDC "FD Controller:" @@ -367,7 +368,6 @@ END #define STR_CHECKBPB "Check BPB" #define STR_CDROM_DRIVES "CD-ROM drives:" #define STR_CD_SPEED "Speed:" -#define STR_EARLY "Earlier drive" #define STR_MO_DRIVES "MO drives:" #define STR_ZIP_DRIVES "ZIP drives:" @@ -392,7 +392,7 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN 2048 "86Box" IDS_2049 "Error" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Machine ""%hs"" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Video card ""%hs"" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." IDS_2065 "Machine" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Press F8+F12 or middle button to release mouse" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Unable to initialize FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "All images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Advanced sector images (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basic sector images (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Surface images (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Unable to initialize FreeType" IDS_2112 "Unable to initialize SDL, SDL2.dll is required" IDS_2113 "Are you sure you want to hard reset the emulated machine?" IDS_2114 "Are you sure you want to exit 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Make sure " LIB_NAME_PCAP " is installed and that you are on a " LIB_NAME_PCAP "-compatible network connection." IDS_2131 "Invalid configuration" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " is required for ESC/P printer emulation." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " is required for FluidSynth MIDI output." IDS_2135 "Entering fullscreen mode" IDS_2136 "Don't show this message again" IDS_2137 "Don't exit" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Hard reset" IDS_2160 "ACPI shutdown" IDS_2161 "Settings" - IDS_2162 "Earlier drive" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Hard disk (%s)" IDS_4097 "%01i:%01i" diff --git a/src/win/languages/en-US.rc b/src/win/languages/en-US.rc index 047a64c94..b1163f8f3 100644 --- a/src/win/languages/en-US.rc +++ b/src/win/languages/en-US.rc @@ -13,78 +13,78 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Action" BEGIN MENUITEM "&Keyboard requires capture", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Right CTRL is left ALT", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Right CTRL is left ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Hard Reset...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Hard Reset...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pause", IDM_ACTION_PAUSE + MENUITEM "&Pause", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "E&xit...", IDM_ACTION_EXIT + MENUITEM "E&xit...", IDM_ACTION_EXIT END POPUP "&View" BEGIN - MENUITEM "&Hide status bar", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Hide status bar", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Resizeable window", IDM_VID_RESIZE + MENUITEM "&Resizeable window", IDM_VID_RESIZE MENUITEM "R&emember size && position", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "Re&nderer" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Specify dimensions...", IDM_VID_SPECIFY_DIM + MENUITEM "Specify dimensions...", IDM_VID_SPECIFY_DIM MENUITEM "F&orce 4:3 display ratio", IDM_VID_FORCE43 POPUP "&Window scale factor" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Filter method" BEGIN MENUITEM "&Nearest", IDM_VID_FILTER_NEAREST - MENUITEM "&Linear", IDM_VID_FILTER_LINEAR + MENUITEM "&Linear", IDM_VID_FILTER_LINEAR END - MENUITEM "Hi&DPI scaling", IDM_VID_HIDPI + MENUITEM "Hi&DPI scaling", IDM_VID_HIDPI MENUITEM SEPARATOR MENUITEM "&Fullscreen\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Fullscreen &stretch mode" BEGIN - MENUITEM "&Full screen stretch", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Full screen stretch", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Square pixels (Keep ratio)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Integer scale", IDM_VID_FS_INT + MENUITEM "&Integer scale", IDM_VID_FS_INT END POPUP "E&GA/(S)VGA settings" BEGIN MENUITEM "&Inverted VGA monitor", IDM_VID_INVERT POPUP "VGA screen &type" BEGIN - MENUITEM "RGB &Color", IDM_VID_GRAY_RGB + MENUITEM "RGB &Color", IDM_VID_GRAY_RGB MENUITEM "&RGB Grayscale", IDM_VID_GRAY_MONO MENUITEM "&Amber monitor", IDM_VID_GRAY_AMBER MENUITEM "&Green monitor", IDM_VID_GRAY_GREEN @@ -93,42 +93,42 @@ BEGIN POPUP "Grayscale &conversion type" BEGIN MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Average", IDM_VID_GRAYCT_AVE + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Average", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA overscan", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA overscan", IDM_VID_OVERSCAN MENUITEM "Change contrast for &monochrome display", IDM_VID_CGACON END MENUITEM "&Media", IDM_MEDIA POPUP "&Tools" BEGIN - MENUITEM "&Settings...", IDM_CONFIG - MENUITEM "&Update status bar icons", IDM_UPDATE_ICONS + MENUITEM "&Settings...", IDM_CONFIG + MENUITEM "&Update status bar icons", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Take s&creenshot\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Take s&creenshot\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Preferences...", IDM_PREFERENCES + MENUITEM "&Preferences...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Enable &Discord integration", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "Sound &gain...", IDM_SND_GAIN + MENUITEM "Sound &gain...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Begin trace\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "End trace\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Begin trace\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "End trace\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Help" BEGIN MENUITEM "&Documentation...", IDM_DOCS - MENUITEM "&About 86Box...", IDM_ABOUT + MENUITEM "&About 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&New image...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&New image...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Existing image...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "&Existing image...", IDM_CASSETTE_IMAGE_EXISTING MENUITEM "Existing image (&Write-protected)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Record", IDM_CASSETTE_RECORD - MENUITEM "&Play", IDM_CASSETTE_PLAY - MENUITEM "&Rewind to the beginning", IDM_CASSETTE_REWIND - MENUITEM "&Fast forward to the end", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Record", IDM_CASSETTE_RECORD + MENUITEM "&Play", IDM_CASSETTE_PLAY + MENUITEM "&Rewind to the beginning", IDM_CASSETTE_REWIND + MENUITEM "&Fast forward to the end", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "E&ject", IDM_CASSETTE_EJECT + MENUITEM "E&ject", IDM_CASSETTE_EJECT END END @@ -157,7 +157,7 @@ BEGIN BEGIN MENUITEM "&Image...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "E&ject", IDM_CARTRIDGE_EJECT + MENUITEM "E&ject", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&New image...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&New image...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Existing image...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "&Existing image...", IDM_FLOPPY_IMAGE_EXISTING MENUITEM "Existing image (&Write-protected)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xport to 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&xport to 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "E&ject", IDM_FLOPPY_EJECT + MENUITEM "E&ject", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Mute", IDM_CDROM_MUTE + MENUITEM "&Mute", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "E&mpty", IDM_CDROM_EMPTY + MENUITEM "E&mpty", IDM_CDROM_EMPTY MENUITEM "&Reload previous image", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Image...", IDM_CDROM_IMAGE - MENUITEM "&Folder...", IDM_CDROM_DIR + MENUITEM "&Image...", IDM_CDROM_IMAGE + MENUITEM "&Folder...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&New image...", IDM_ZIP_IMAGE_NEW + MENUITEM "&New image...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Existing image...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "&Existing image...", IDM_ZIP_IMAGE_EXISTING MENUITEM "Existing image (&Write-protected)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&ject", IDM_ZIP_EJECT - MENUITEM "&Reload previous image", IDM_ZIP_RELOAD + MENUITEM "E&ject", IDM_ZIP_EJECT + MENUITEM "&Reload previous image", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&New image...", IDM_MO_IMAGE_NEW + MENUITEM "&New image...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Existing image...", IDM_MO_IMAGE_EXISTING + MENUITEM "&Existing image...", IDM_MO_IMAGE_EXISTING MENUITEM "Existing image (&Write-protected)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&ject", IDM_MO_EJECT - MENUITEM "&Reload previous image", IDM_MO_RELOAD + MENUITEM "E&ject", IDM_MO_EJECT + MENUITEM "&Reload previous image", IDM_MO_RELOAD END END @@ -223,15 +223,15 @@ BEGIN POPUP "Target &framerate" BEGIN MENUITEM "&Sync with video", IDM_VID_GL_FPS_BLITTER - MENUITEM "&25 fps", IDM_VID_GL_FPS_25 - MENUITEM "&30 fps", IDM_VID_GL_FPS_30 - MENUITEM "&50 fps", IDM_VID_GL_FPS_50 - MENUITEM "&60 fps", IDM_VID_GL_FPS_60 - MENUITEM "&75 fps", IDM_VID_GL_FPS_75 + MENUITEM "&25 fps", IDM_VID_GL_FPS_25 + MENUITEM "&30 fps", IDM_VID_GL_FPS_30 + MENUITEM "&50 fps", IDM_VID_GL_FPS_50 + MENUITEM "&60 fps", IDM_VID_GL_FPS_60 + MENUITEM "&75 fps", IDM_VID_GL_FPS_75 END - MENUITEM "&VSync", IDM_VID_GL_VSYNC + MENUITEM "&VSync", IDM_VID_GL_VSYNC MENUITEM "&Select shader...", IDM_VID_GL_SHADER - MENUITEM "&Remove shader", IDM_VID_GL_NOSHADER + MENUITEM "&Remove shader", IDM_VID_GL_NOSHADER END @@ -278,6 +278,7 @@ END #define STR_ENABLED_LOCAL "Enabled (local time)" #define STR_ENABLED_UTC "Enabled (UTC)" #define STR_DYNAREC "Dynamic Recompiler" +#define STR_SOFTFLOAT "Softfloat FPU" #define STR_VIDEO "Video:" #define STR_VIDEO_2 "Video 2:" @@ -296,42 +297,42 @@ END #define STR_SOUND2 "Sound card 2:" #define STR_SOUND3 "Sound card 3:" #define STR_SOUND4 "Sound card 4:" -#define STR_MIDI_OUT "MIDI Out Device:" -#define STR_MIDI_IN "MIDI In Device:" +#define STR_MIDI_OUT "MIDI Out Device:" +#define STR_MIDI_IN "MIDI In Device:" #define STR_MPU401 "Standalone MPU-401" -#define STR_FLOAT "Use FLOAT32 sound" -#define STR_FM_DRIVER "FM synth driver" -#define STR_FM_DRV_NUKED "Nuked (more accurate)" -#define STR_FM_DRV_YMFM "YMFM (faster)" +#define STR_FLOAT "Use FLOAT32 sound" +#define STR_FM_DRIVER "FM synth driver" +#define STR_FM_DRV_NUKED "Nuked (more accurate)" +#define STR_FM_DRV_YMFM "YMFM (faster)" -#define STR_NET_TYPE "Network type:" -#define STR_PCAP "PCap device:" -#define STR_NET "Network adapter:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Network type:" +#define STR_PCAP "PCap device:" +#define STR_NET "Network adapter:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "COM1 Device:" -#define STR_COM2 "COM2 Device:" -#define STR_COM3 "COM3 Device:" -#define STR_COM4 "COM4 Device:" -#define STR_LPT1 "LPT1 Device:" -#define STR_LPT2 "LPT2 Device:" -#define STR_LPT3 "LPT3 Device:" -#define STR_LPT4 "LPT4 Device:" -#define STR_SERIAL1 "Serial port 1" -#define STR_SERIAL2 "Serial port 2" -#define STR_SERIAL3 "Serial port 3" -#define STR_SERIAL4 "Serial port 4" -#define STR_PARALLEL1 "Parallel port 1" -#define STR_PARALLEL2 "Parallel port 2" -#define STR_PARALLEL3 "Parallel port 3" -#define STR_PARALLEL4 "Parallel port 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1 Device:" +#define STR_COM2 "COM2 Device:" +#define STR_COM3 "COM3 Device:" +#define STR_COM4 "COM4 Device:" +#define STR_LPT1 "LPT1 Device:" +#define STR_LPT2 "LPT2 Device:" +#define STR_LPT3 "LPT3 Device:" +#define STR_LPT4 "LPT4 Device:" +#define STR_SERIAL1 "Serial port 1" +#define STR_SERIAL2 "Serial port 2" +#define STR_SERIAL3 "Serial port 3" +#define STR_SERIAL4 "Serial port 4" +#define STR_PARALLEL1 "Parallel port 1" +#define STR_PARALLEL2 "Parallel port 2" +#define STR_PARALLEL3 "Parallel port 3" +#define STR_PARALLEL4 "Parallel port 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" #define STR_HDC "HD Controller:" #define STR_FDC "FD Controller:" @@ -367,7 +368,6 @@ END #define STR_CHECKBPB "Check BPB" #define STR_CDROM_DRIVES "CD-ROM drives:" #define STR_CD_SPEED "Speed:" -#define STR_EARLY "Earlier drive" #define STR_MO_DRIVES "MO drives:" #define STR_ZIP_DRIVES "ZIP drives:" @@ -392,7 +392,7 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN 2048 "86Box" IDS_2049 "Error" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Machine ""%hs"" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Video card ""%hs"" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." IDS_2065 "Machine" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Press F8+F12 or middle button to release mouse" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Unable to initialize FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "All images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Advanced sector images (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basic sector images (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Surface images (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Unable to initialize FreeType" IDS_2112 "Unable to initialize SDL, SDL2.dll is required" IDS_2113 "Are you sure you want to hard reset the emulated machine?" IDS_2114 "Are you sure you want to exit 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Make sure " LIB_NAME_PCAP " is installed and that you are on a " LIB_NAME_PCAP "-compatible network connection." IDS_2131 "Invalid configuration" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " is required for ESC/P printer emulation." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " is required for FluidSynth MIDI output." IDS_2135 "Entering fullscreen mode" IDS_2136 "Don't show this message again" IDS_2137 "Don't exit" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Hard reset" IDS_2160 "ACPI shutdown" IDS_2161 "Settings" - IDS_2162 "Earlier drive" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Hard disk (%s)" IDS_4097 "%01i:%01i" diff --git a/src/win/languages/es-ES.rc b/src/win/languages/es-ES.rc index 548c1fdcb..49fea1fae 100644 --- a/src/win/languages/es-ES.rc +++ b/src/win/languages/es-ES.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_SPANISH, SUBLANG_SPANISH // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Acción" BEGIN - MENUITEM "&Teclado requiere captura", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "CTRL &derecho es ALT izquierdo", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Teclado requiere captura", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "CTRL &derecho es ALT izquierdo", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Hard Reset...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Hard Reset...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pausa", IDM_ACTION_PAUSE + MENUITEM "&Pausa", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Salir...", IDM_ACTION_EXIT + MENUITEM "&Salir...", IDM_ACTION_EXIT END POPUP "&Vista" BEGIN - MENUITEM "&Ocultar barra de estado", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Ocultar barra de estado", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Ventana redimensionable", IDM_VID_RESIZE - MENUITEM "&Recordar tamaño y posición", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Ventana redimensionable", IDM_VID_RESIZE + MENUITEM "&Recordar tamaño y posición", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "Re&nderizador" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "E&specificar dimensiones...", IDM_VID_SPECIFY_DIM - MENUITEM "F&orzar ratio 4:3", IDM_VID_FORCE43 + MENUITEM "E&specificar dimensiones...", IDM_VID_SPECIFY_DIM + MENUITEM "F&orzar ratio 4:3", IDM_VID_FORCE43 POPUP "&Factor de escalado de ventana" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "&Método de filtrado" BEGIN - MENUITEM "&Más cercano", IDM_VID_FILTER_NEAREST - MENUITEM "&Lineal", IDM_VID_FILTER_LINEAR + MENUITEM "&Más cercano", IDM_VID_FILTER_NEAREST + MENUITEM "&Lineal", IDM_VID_FILTER_LINEAR END - MENUITEM "&Escalado alta densidad", IDM_VID_HIDPI + MENUITEM "&Escalado alta densidad", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Pantalla completa\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Pantalla completa\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Escalado pantalla completa" BEGIN - MENUITEM "&Estirar", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Estirar", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Píxeles cuadrados (Mant. aspecto)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Escalado valor entero", IDM_VID_FS_INT + MENUITEM "&Escalado valor entero", IDM_VID_FS_INT END POPUP "&Ajustes EGA/(S)VGA" BEGIN - MENUITEM "&Monitor VGA invertido", IDM_VID_INVERT + MENUITEM "&Monitor VGA invertido", IDM_VID_INVERT POPUP "&Tipo de pantalla VGA" BEGIN - MENUITEM "RGB &Color", IDM_VID_GRAY_RGB - MENUITEM "RGB &Grises", IDM_VID_GRAY_MONO - MENUITEM "Monitor &Ámbar", IDM_VID_GRAY_AMBER - MENUITEM "Monitor &Verde", IDM_VID_GRAY_GREEN - MENUITEM "Monitor &Blanco", IDM_VID_GRAY_WHITE + MENUITEM "RGB &Color", IDM_VID_GRAY_RGB + MENUITEM "RGB &Grises", IDM_VID_GRAY_MONO + MENUITEM "Monitor &Ámbar", IDM_VID_GRAY_AMBER + MENUITEM "Monitor &Verde", IDM_VID_GRAY_GREEN + MENUITEM "Monitor &Blanco", IDM_VID_GRAY_WHITE END POPUP "&Conversión a grises" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Media", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Media", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "&Overscan CGA/PCjr/Tandy/EGA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "&Overscan CGA/PCjr/Tandy/EGA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "Cambiar contraste para pantalla &monocroma", IDM_VID_CGACON END - MENUITEM "&Medios", IDM_MEDIA + MENUITEM "&Medios", IDM_MEDIA POPUP "&Herramientas" BEGIN - MENUITEM "&Ajustes...", IDM_CONFIG - MENUITEM "&Actualizar iconos en barra de estado", IDM_UPDATE_ICONS + MENUITEM "&Ajustes...", IDM_CONFIG + MENUITEM "&Actualizar iconos en barra de estado", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Tomar c&aptura\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Tomar c&aptura\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Preferencias...", IDM_PREFERENCES + MENUITEM "&Preferencias...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Habilitar integración con &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Ganancia de sonido...", IDM_SND_GAIN + MENUITEM "&Ganancia de sonido...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Comenzar traza\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Terminar traza\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Comenzar traza\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Terminar traza\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Ayuda" BEGIN - MENUITEM "&Documentación...", IDM_DOCS - MENUITEM "&Acerca de 86Box...", IDM_ABOUT + MENUITEM "&Documentación...", IDM_DOCS + MENUITEM "&Acerca de 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nueva imagen...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nueva imagen...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagen &Existente...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Imagen Existente (&Sólo-lectura)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "Imagen &Existente...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Imagen Existente (&Sólo-lectura)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Grabar", IDM_CASSETTE_RECORD - MENUITEM "&Reproducir", IDM_CASSETTE_PLAY - MENUITEM "&Rebobinar al inicio", IDM_CASSETTE_REWIND - MENUITEM "&Avance rápido al final", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Grabar", IDM_CASSETTE_RECORD + MENUITEM "&Reproducir", IDM_CASSETTE_PLAY + MENUITEM "&Rebobinar al inicio", IDM_CASSETTE_REWIND + MENUITEM "&Avance rápido al final", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "E&xtraer", IDM_CASSETTE_EJECT + MENUITEM "E&xtraer", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Imagen...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Imagen...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "E&xtraer", IDM_CARTRIDGE_EJECT + MENUITEM "E&xtraer", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nueva imagen...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nueva imagen...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagen &existente...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Imagen existente (&sólo-lectura)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "Imagen &existente...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Imagen existente (&sólo-lectura)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xportar a 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&xportar a 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "E&xtraer", IDM_FLOPPY_EJECT + MENUITEM "E&xtraer", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Silenciar", IDM_CDROM_MUTE + MENUITEM "&Silenciar", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "E&xtraer disco", IDM_CDROM_EMPTY - MENUITEM "&Recargar imagen previa", IDM_CDROM_RELOAD + MENUITEM "E&xtraer disco", IDM_CDROM_EMPTY + MENUITEM "&Recargar imagen previa", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Imagen...", IDM_CDROM_IMAGE - MENUITEM "&Carpeta...", IDM_CDROM_DIR + MENUITEM "&Imagen...", IDM_CDROM_IMAGE + MENUITEM "&Carpeta...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nueva imagen...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nueva imagen...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagen &existente...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Imagen existente (&sólo-lectura)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "Imagen &existente...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Imagen existente (&sólo-lectura)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xtraer", IDM_ZIP_EJECT - MENUITEM "&Recargar imagen previa", IDM_ZIP_RELOAD + MENUITEM "E&xtraer", IDM_ZIP_EJECT + MENUITEM "&Recargar imagen previa", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nueva imagen...", IDM_MO_IMAGE_NEW + MENUITEM "&Nueva imagen...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagen &existente...", IDM_MO_IMAGE_EXISTING - MENUITEM "Imagen existente (&sólo-lectura)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "Imagen &existente...", IDM_MO_IMAGE_EXISTING + MENUITEM "Imagen existente (&sólo-lectura)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xtraer", IDM_MO_EJECT - MENUITEM "&Recargar imagen previa", IDM_MO_RELOAD + MENUITEM "E&xtraer", IDM_MO_EJECT + MENUITEM "&Recargar imagen previa", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Preferencias" -#define STR_SND_GAIN "Ganancia de Sonido" -#define STR_NEW_FLOPPY "Nueva Imagen" +#define STR_PREFERENCES "Preferencias" +#define STR_SND_GAIN "Ganancia de Sonido" +#define STR_NEW_FLOPPY "Nueva Imagen" #define STR_CONFIG "Ajustes" -#define STR_SPECIFY_DIM "Especificar Dimensiones de la Ventana Principal" +#define STR_SPECIFY_DIM "Especificar Dimensiones de la Ventana Principal" #define STR_OK "Aceptar" #define STR_CANCEL "Cancelar" #define STR_GLOBAL "Salvar estos ajustes como por &defecto globalmente" -#define STR_DEFAULT "&Por defecto" -#define STR_LANGUAGE "Idioma:" -#define STR_ICONSET "Juego de iconos:" +#define STR_DEFAULT "&Por defecto" +#define STR_LANGUAGE "Idioma:" +#define STR_ICONSET "Juego de iconos:" -#define STR_GAIN "Ganancia" +#define STR_GAIN "Ganancia" -#define STR_FILE_NAME "Nombre de archivo:" -#define STR_DISK_SIZE "Tamaño de disco:" -#define STR_RPM_MODE "Modo RPM:" -#define STR_PROGRESS "Progreso:" +#define STR_FILE_NAME "Nombre de archivo:" +#define STR_DISK_SIZE "Tamaño de disco:" +#define STR_RPM_MODE "Modo RPM:" +#define STR_PROGRESS "Progreso:" -#define STR_WIDTH "Ancho:" +#define STR_WIDTH "Ancho:" #define STR_HEIGHT "Alto:" -#define STR_LOCK_TO_SIZE "Bloquear a este tamaño" +#define STR_LOCK_TO_SIZE "Bloquear a este tamaño" -#define STR_MACHINE_TYPE "Tipo de máquina:" -#define STR_MACHINE "Máquina:" -#define STR_CONFIGURE "Configurar" -#define STR_CPU_TYPE "Tipo de CPU:" -#define STR_CPU_SPEED "Velocidad:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "Estados en espera:" +#define STR_MACHINE_TYPE "Tipo de máquina:" +#define STR_MACHINE "Máquina:" +#define STR_CONFIGURE "Configurar" +#define STR_CPU_TYPE "Tipo de CPU:" +#define STR_CPU_SPEED "Velocidad:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "Estados en espera:" #define STR_MB "MB" #define STR_MEMORY "Memoria:" -#define STR_TIME_SYNC "Sincronización horaria" -#define STR_DISABLED "Deshabilitado" -#define STR_ENABLED_LOCAL "Habilitado (hora local)" -#define STR_ENABLED_UTC "Habilitado (UTC)" -#define STR_DYNAREC "Recompilador Dinámico" +#define STR_TIME_SYNC "Sincronización horaria" +#define STR_DISABLED "Deshabilitado" +#define STR_ENABLED_LOCAL "Habilitado (hora local)" +#define STR_ENABLED_UTC "Habilitado (UTC)" +#define STR_DYNAREC "Recompilador Dinámico" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Vídeo:" -#define STR_VIDEO_2 "Vídeo 2:" +#define STR_VIDEO "Vídeo:" +#define STR_VIDEO_2 "Vídeo 2:" #define STR_VOODOO "Voodoo Graphics" -#define STR_IBM8514 "IBM 8514/a Graphics" -#define STR_XGA "XGA Graphics" +#define STR_IBM8514 "IBM 8514/a Graphics" +#define STR_XGA "XGA Graphics" -#define STR_MOUSE "Ratón:" -#define STR_JOYSTICK "Mando:" -#define STR_JOY1 "Mando 1..." -#define STR_JOY2 "Mando 2..." -#define STR_JOY3 "Mando 3..." -#define STR_JOY4 "Mando 4..." +#define STR_MOUSE "Ratón:" +#define STR_JOYSTICK "Mando:" +#define STR_JOY1 "Mando 1..." +#define STR_JOY2 "Mando 2..." +#define STR_JOY3 "Mando 3..." +#define STR_JOY4 "Mando 4..." #define STR_SOUND1 "Tarjeta de sonido 1:" #define STR_SOUND2 "Tarjeta de sonido 2:" #define STR_SOUND3 "Tarjeta de sonido 3:" #define STR_SOUND4 "Tarjeta de sonido 4:" -#define STR_MIDI_OUT "Dispositivo MIDI de salida:" -#define STR_MIDI_IN "Dispositivo MIDI de entrada:" +#define STR_MIDI_OUT "Dispositivo MIDI de salida:" +#define STR_MIDI_IN "Dispositivo MIDI de entrada:" #define STR_MPU401 "MPU-401 independiente" -#define STR_FLOAT "Usar sonido FLOAT32" -#define STR_FM_DRIVER "Controlador de sintet. FM" -#define STR_FM_DRV_NUKED "Nuked (más preciso)" -#define STR_FM_DRV_YMFM "YMFM (más rápido)" +#define STR_FLOAT "Usar sonido FLOAT32" +#define STR_FM_DRIVER "Controlador de sintet. FM" +#define STR_FM_DRV_NUKED "Nuked (más preciso)" +#define STR_FM_DRV_YMFM "YMFM (más rápido)" -#define STR_NET_TYPE "Tipo de red:" -#define STR_PCAP "Dispositivo PCap:" -#define STR_NET "Adaptador de red:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Tipo de red:" +#define STR_PCAP "Dispositivo PCap:" +#define STR_NET "Adaptador de red:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Dispositivo COM1:" -#define STR_COM2 "Dispositivo COM2:" -#define STR_COM3 "Dispositivo COM3:" -#define STR_COM4 "Dispositivo COM4:" -#define STR_LPT1 "Dispositivo LPT1:" -#define STR_LPT2 "Dispositivo LPT2:" -#define STR_LPT3 "Dispositivo LPT3:" -#define STR_LPT4 "Dispositivo LPT4:" -#define STR_SERIAL1 "Puerto serie 1" -#define STR_SERIAL2 "Puerto serie 2" -#define STR_SERIAL3 "Puerto serie 3" -#define STR_SERIAL4 "Puerto serie 4" -#define STR_PARALLEL1 "Puerto paralelo 1" -#define STR_PARALLEL2 "Puerto paralelo 2" -#define STR_PARALLEL3 "Puerto paralelo 3" -#define STR_PARALLEL4 "Puerto paralelo 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Dispositivo COM1:" +#define STR_COM2 "Dispositivo COM2:" +#define STR_COM3 "Dispositivo COM3:" +#define STR_COM4 "Dispositivo COM4:" +#define STR_LPT1 "Dispositivo LPT1:" +#define STR_LPT2 "Dispositivo LPT2:" +#define STR_LPT3 "Dispositivo LPT3:" +#define STR_LPT4 "Dispositivo LPT4:" +#define STR_SERIAL1 "Puerto serie 1" +#define STR_SERIAL2 "Puerto serie 2" +#define STR_SERIAL3 "Puerto serie 3" +#define STR_SERIAL4 "Puerto serie 4" +#define STR_PARALLEL1 "Puerto paralelo 1" +#define STR_PARALLEL2 "Puerto paralelo 2" +#define STR_PARALLEL3 "Puerto paralelo 3" +#define STR_PARALLEL4 "Puerto paralelo 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Controladora HD:" -#define STR_FDC "Controladora FD:" -#define STR_IDE_TER "Tercera controladora IDE" -#define STR_IDE_QUA "Cuarta controladora IDE" -#define STR_SCSI "SCSI" +#define STR_HDC "Controladora HD:" +#define STR_FDC "Controladora FD:" +#define STR_IDE_TER "Tercera controladora IDE" +#define STR_IDE_QUA "Cuarta controladora IDE" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Controladora 1:" #define STR_SCSI_2 "Controladora 2:" #define STR_SCSI_3 "Controladora 3:" #define STR_SCSI_4 "Controladora 4:" -#define STR_CASSETTE "Cassette" +#define STR_CASSETTE "Cassette" -#define STR_HDD "Discos duros:" -#define STR_NEW "&Nuevo..." -#define STR_EXISTING "&Existente..." +#define STR_HDD "Discos duros:" +#define STR_NEW "&Nuevo..." +#define STR_EXISTING "&Existente..." #define STR_REMOVE "E&liminar" -#define STR_BUS "Bus:" -#define STR_CHANNEL "Canal:" +#define STR_BUS "Bus:" +#define STR_CHANNEL "Canal:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "E&specificar..." -#define STR_SECTORS "Sectores:" -#define STR_HEADS "Cabezas:" -#define STR_CYLS "Cilindros:" -#define STR_SIZE_MB "Tamaño (MB):" -#define STR_TYPE "Tipo:" -#define STR_IMG_FORMAT "Formato de imagen:" -#define STR_BLOCK_SIZE "Tamaño de bloque:" +#define STR_SPECIFY "E&specificar..." +#define STR_SECTORS "Sectores:" +#define STR_HEADS "Cabezas:" +#define STR_CYLS "Cilindros:" +#define STR_SIZE_MB "Tamaño (MB):" +#define STR_TYPE "Tipo:" +#define STR_IMG_FORMAT "Formato de imagen:" +#define STR_BLOCK_SIZE "Tamaño de bloque:" -#define STR_FLOPPY_DRIVES "Unidades de disquete:" -#define STR_TURBO "Temporizaciones Turbo" -#define STR_CHECKBPB "Chequear BPB" -#define STR_CDROM_DRIVES "Unidades de CD-ROM:" -#define STR_CD_SPEED "Velocidad:" -#define STR_EARLY "Unidad anterior" +#define STR_FLOPPY_DRIVES "Unidades de disquete:" +#define STR_TURBO "Temporizaciones Turbo" +#define STR_CHECKBPB "Chequear BPB" +#define STR_CDROM_DRIVES "Unidades de CD-ROM:" +#define STR_CD_SPEED "Velocidad:" -#define STR_MO_DRIVES "Unidades MO:" -#define STR_ZIP_DRIVES "Unidades ZIP:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Unidades MO:" +#define STR_ZIP_DRIVES "Unidades ZIP:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC:" #define STR_ISAMEM "Expansión de Memoria ISA" -#define STR_ISAMEM_1 "Tarjeta 1:" -#define STR_ISAMEM_2 "Tarjeta 2:" -#define STR_ISAMEM_3 "Tarjeta 3:" -#define STR_ISAMEM_4 "Tarjeta 4:" +#define STR_ISAMEM_1 "Tarjeta 1:" +#define STR_ISAMEM_2 "Tarjeta 2:" +#define STR_ISAMEM_3 "Tarjeta 3:" +#define STR_ISAMEM_4 "Tarjeta 4:" #define STR_BUGGER "Dispositivo ISABugger" -#define STR_POSTCARD "Tarjeta POST" +#define STR_POSTCARD "Tarjeta POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Error" IDS_2050 "Error fatal" IDS_2051 " - PAUSED" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "La máquina ""%hs"" no está disponible debido a ROMs faltantes en el directorio roms/machines. Cambiando a una máquina disponible." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "La tarjeta de vídeo ""%hs"" no está disponible debido a ROMs faltantes en el directorio roms/machines. Cambiando a una tarjeta de vídeo disponible." IDS_2065 "Máquina" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Pulsa F8+F12 o el botón central para liberar el ratón" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Incapaz de inicializar FluidSynth" IDS_2081 "Bus" IDS_2082 "Archivo" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disquete %i (%s): %ls" IDS_2110 "Todas las Imágenes (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Advanced sector images (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basic sector images (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Surface images (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Incapaz de inicializar FreeType" IDS_2112 "Incapaz de inicializar SDL, se requiere SDL2.dll" IDS_2113 "¿Seguro que quieres resetear la máquina emulada?" IDS_2114 "¿Seguro que quieres cerrar 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Asegúrate de que " LIB_NAME_PCAP " está instalado y de que estás en una conexión de red compatible con " LIB_NAME_PCAP "." IDS_2131 "Configuración inválida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " es necesaria para emulación de impresión ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " es necesaria para la conversión automática de archivos PostScript a PDF.\n\nCualquier documento enviado a la impresora genérica postScript se guardará como archivo PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " es necesario para salida MIDI FluidSynth." IDS_2135 "Entrando en modo pantalla completa" IDS_2136 "No mostrar más este mensaje" IDS_2137 "No salir" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Hard reset" IDS_2160 "ACPI shutdown" IDS_2161 "Settings" - IDS_2162 "Unidad anterior" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Disco duro (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Por defecto del sistema)" END -#define IDS_LANG_ESES IDS_7168 +#define IDS_LANG_ESES IDS_7168 // Spanish (Spain) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/fi-FI.rc b/src/win/languages/fi-FI.rc index edcf7d53e..1c5cda78b 100644 --- a/src/win/languages/fi-FI.rc +++ b/src/win/languages/fi-FI.rc @@ -17,114 +17,114 @@ MainMenu MENU DISCARDABLE BEGIN POPUP "&Toiminto" BEGIN - MENUITEM "&Vaadi näppäimistön kaappaus", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Oikea CTRL on vasen ALT", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Vaadi näppäimistön kaappaus", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Oikea CTRL on vasen ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Uudelleenkäynnistys (kylmä)...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Uudelleenkäynnistys (kylmä)...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Tauko", IDM_ACTION_PAUSE + MENUITEM "&Tauko", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Poistu...", IDM_ACTION_EXIT + MENUITEM "&Poistu...", IDM_ACTION_EXIT END POPUP "&Näytä" BEGIN - MENUITEM "&Piilota tilapalkki", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Piilota &työkalupalkki", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Piilota tilapalkki", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Piilota &työkalupalkki", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Salli koon muuttaminen", IDM_VID_RESIZE - MENUITEM "&Muista koko ja sijainti", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Salli koon muuttaminen", IDM_VID_RESIZE + MENUITEM "&Muista koko ja sijainti", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Renderöijä" BEGIN - MENUITEM "&SDL (ohjelmistopohjainen)", IDM_VID_SDL_SW - MENUITEM "SDL (&laitteistokiihdytetty)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (ohjelmistopohjainen)", IDM_VID_SDL_SW + MENUITEM "SDL (&laitteistokiihdytetty)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "&Määritä koko...", IDM_VID_SPECIFY_DIM - MENUITEM "Pakota 4:3-näyttösuhde", IDM_VID_FORCE43 + MENUITEM "&Määritä koko...", IDM_VID_SPECIFY_DIM + MENUITEM "Pakota 4:3-näyttösuhde", IDM_VID_FORCE43 POPUP "&Ikkunan kokokerroin" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "&Suodatusmetodi" BEGIN - MENUITEM "&Lähin naapuri", IDM_VID_FILTER_NEAREST - MENUITEM "Li&neaarinen interpolaatio", IDM_VID_FILTER_LINEAR + MENUITEM "&Lähin naapuri", IDM_VID_FILTER_NEAREST + MENUITEM "Li&neaarinen interpolaatio", IDM_VID_FILTER_LINEAR END - MENUITEM "&Suuri DPI-skaalaus", IDM_VID_HIDPI + MENUITEM "&Suuri DPI-skaalaus", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Koko näytön tila\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Koko näytön tila\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Koko näytön &skaalaustila" BEGIN - MENUITEM "&Venytä koko näyttöön", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 - MENUITEM "&Tasasivuiset kuvapisteet (säilytä kuvasuhde)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Kokonaislukuskaalaus", IDM_VID_FS_INT + MENUITEM "&Venytä koko näyttöön", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Tasasivuiset kuvapisteet (säilytä kuvasuhde)", IDM_VID_FS_KEEPRATIO + MENUITEM "&Kokonaislukuskaalaus", IDM_VID_FS_INT END POPUP "&EGA/(S)VGA-asetukset" BEGIN - MENUITEM "&VGA-näyttö käänteisillä väreillä", IDM_VID_INVERT + MENUITEM "&VGA-näyttö käänteisillä väreillä", IDM_VID_INVERT POPUP "VGA-näytön &tyyppi" BEGIN - MENUITEM "RGB, &värit", IDM_VID_GRAY_RGB - MENUITEM "&RGB, harmaasävy", IDM_VID_GRAY_MONO - MENUITEM "&Meripihkanvärinen", IDM_VID_GRAY_AMBER - MENUITEM "V&ihreä", IDM_VID_GRAY_GREEN - MENUITEM "V&alkoinen", IDM_VID_GRAY_WHITE + MENUITEM "RGB, &värit", IDM_VID_GRAY_RGB + MENUITEM "&RGB, harmaasävy", IDM_VID_GRAY_MONO + MENUITEM "&Meripihkanvärinen", IDM_VID_GRAY_AMBER + MENUITEM "V&ihreä", IDM_VID_GRAY_GREEN + MENUITEM "V&alkoinen", IDM_VID_GRAY_WHITE END POPUP "&Harmaasävymuunnoksen tyyppi" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Keskiarvo", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Keskiarvo", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA &yliskannaus", IDM_VID_OVERSCAN - MENUITEM "&Muuta harmaavärinäytön kontrastia", IDM_VID_CGACON + MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA &yliskannaus", IDM_VID_OVERSCAN + MENUITEM "&Muuta harmaavärinäytön kontrastia", IDM_VID_CGACON END - MENUITEM "&Media", IDM_MEDIA + MENUITEM "&Media", IDM_MEDIA POPUP "Työ&kalut" BEGIN - MENUITEM "&Kokoonpano...", IDM_CONFIG - MENUITEM "&Päivitä tilapalkin kuvakkeita", IDM_UPDATE_ICONS + MENUITEM "&Kokoonpano...", IDM_CONFIG + MENUITEM "&Päivitä tilapalkin kuvakkeita", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Ota &kuvakaappaus\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Ota &kuvakaappaus\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Sovellusasetukset...", IDM_PREFERENCES + MENUITEM "&Sovellusasetukset...", IDM_PREFERENCES #ifdef DISCORD - MENUITEM "Käytä &Discord-integraatiota", IDM_DISCORD + MENUITEM "Käytä &Discord-integraatiota", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Äänitasot...", IDM_SND_GAIN + MENUITEM "&Äänitasot...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Aloita jäljitys\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Lopeta jäljitys\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Aloita jäljitys\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Lopeta jäljitys\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Ohje" BEGIN - MENUITEM "&Ohjekirja...", IDM_DOCS - MENUITEM "&Tietoja 86Boxista...", IDM_ABOUT + MENUITEM "&Ohjekirja...", IDM_DOCS + MENUITEM "&Tietoja 86Boxista...", IDM_ABOUT END END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Uusi kasettikuva...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Uusi kasettikuva...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Olemassaoleva kasettikuva...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Olemassaoleva kasettikuva (&kirjoitussuojattu)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Olemassaoleva kasettikuva...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Olemassaoleva kasettikuva (&kirjoitussuojattu)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Nauhoita", IDM_CASSETTE_RECORD - MENUITEM "&Toista", IDM_CASSETTE_PLAY - MENUITEM "Kelaa &alkuun", IDM_CASSETTE_REWIND - MENUITEM "Kelaa &loppuun", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Nauhoita", IDM_CASSETTE_RECORD + MENUITEM "&Toista", IDM_CASSETTE_PLAY + MENUITEM "Kelaa &alkuun", IDM_CASSETTE_REWIND + MENUITEM "Kelaa &loppuun", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "&Poista kasettipesästä", IDM_CASSETTE_EJECT + MENUITEM "&Poista kasettipesästä", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&ROM-moduulikuva...", IDM_CARTRIDGE_IMAGE + MENUITEM "&ROM-moduulikuva...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "&Irrota", IDM_CARTRIDGE_EJECT + MENUITEM "&Irrota", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Uusi levykekuva...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Uusi levykekuva...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Olemassaoleva levykekuva...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Olemassaoleva levykekuva (&kirjoitussuojattu)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Olemassaoleva levykekuva...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Olemassaoleva levykekuva (&kirjoitussuojattu)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Vie 86F-tiedostoon...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "&Vie 86F-tiedostoon...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "&Poista asemasta", IDM_FLOPPY_EJECT + MENUITEM "&Poista asemasta", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Mykistä", IDM_CDROM_MUTE + MENUITEM "&Mykistä", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&Tyhjä", IDM_CDROM_EMPTY - MENUITEM "&Lataa edellinen levykuva uudelleen", IDM_CDROM_RELOAD + MENUITEM "&Tyhjä", IDM_CDROM_EMPTY + MENUITEM "&Lataa edellinen levykuva uudelleen", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "L&evykuva...", IDM_CDROM_IMAGE - MENUITEM "&Kansio...", IDM_CDROM_DIR + MENUITEM "L&evykuva...", IDM_CDROM_IMAGE + MENUITEM "&Kansio...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Uusi levykuva...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Uusi levykuva...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Olemassaoleva levykuva...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Olemassaoleva levykuva (&kirjoitussuojattu)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Olemassaoleva levykuva...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Olemassaoleva levykuva (&kirjoitussuojattu)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Poista asemasta", IDM_ZIP_EJECT - MENUITEM "&Lataa edellinen levykuva uudelleen", IDM_ZIP_RELOAD + MENUITEM "&Poista asemasta", IDM_ZIP_EJECT + MENUITEM "&Lataa edellinen levykuva uudelleen", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Uusi levykuva...", IDM_MO_IMAGE_NEW + MENUITEM "&Uusi levykuva...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Olemassaoleva levykuva...", IDM_MO_IMAGE_EXISTING - MENUITEM "Olemassaoleva levykuva (&kirjoitussuojattu)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Olemassaoleva levykuva...", IDM_MO_IMAGE_EXISTING + MENUITEM "Olemassaoleva levykuva (&kirjoitussuojattu)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Poista asemasta", IDM_MO_EJECT - MENUITEM "&Lataa edellinen levykuva uudelleen", IDM_MO_RELOAD + MENUITEM "&Poista asemasta", IDM_MO_EJECT + MENUITEM "&Lataa edellinen levykuva uudelleen", IDM_MO_RELOAD END END @@ -222,16 +222,16 @@ VidGLSubMenu MENU DISCARDABLE BEGIN POPUP "&Kuvataajuustavoite" BEGIN - MENUITEM "&Synkronisoi videoon", IDM_VID_GL_FPS_BLITTER - MENUITEM "&25 ruutua/s", IDM_VID_GL_FPS_25 - MENUITEM "&30 ruutua/s", IDM_VID_GL_FPS_30 - MENUITEM "&50 ruutua/s", IDM_VID_GL_FPS_50 - MENUITEM "&60 ruutua/s", IDM_VID_GL_FPS_60 - MENUITEM "&75 ruutua/s", IDM_VID_GL_FPS_75 + MENUITEM "&Synkronisoi videoon", IDM_VID_GL_FPS_BLITTER + MENUITEM "&25 ruutua/s", IDM_VID_GL_FPS_25 + MENUITEM "&30 ruutua/s", IDM_VID_GL_FPS_30 + MENUITEM "&50 ruutua/s", IDM_VID_GL_FPS_50 + MENUITEM "&60 ruutua/s", IDM_VID_GL_FPS_60 + MENUITEM "&75 ruutua/s", IDM_VID_GL_FPS_75 END - MENUITEM "&VSync", IDM_VID_GL_VSYNC - MENUITEM "Valitse varjostin&ohjelma...", IDM_VID_GL_SHADER - MENUITEM "&Poista varjostinohjelma", IDM_VID_GL_NOSHADER + MENUITEM "&VSync", IDM_VID_GL_VSYNC + MENUITEM "Valitse varjostin&ohjelma...", IDM_VID_GL_SHADER + MENUITEM "&Poista varjostinohjelma", IDM_VID_GL_NOSHADER END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Sovellusasetukset" -#define STR_SND_GAIN "Äänen taso" -#define STR_NEW_FLOPPY "Uusi levykuva" -#define STR_CONFIG "Kokoonpano" -#define STR_SPECIFY_DIM "Määritä pääikkunan koko" +#define STR_PREFERENCES "Sovellusasetukset" +#define STR_SND_GAIN "Äänen taso" +#define STR_NEW_FLOPPY "Uusi levykuva" +#define STR_CONFIG "Kokoonpano" +#define STR_SPECIFY_DIM "Määritä pääikkunan koko" -#define STR_OK "OK" -#define STR_CANCEL "Peruuta" -#define STR_GLOBAL "Tallenna nämä asetukset &globaaleiksi oletuksiksi" -#define STR_DEFAULT "&Oletus" -#define STR_LANGUAGE "Kieli:" -#define STR_ICONSET "Kuvakkeet:" +#define STR_OK "OK" +#define STR_CANCEL "Peruuta" +#define STR_GLOBAL "Tallenna nämä asetukset &globaaleiksi oletuksiksi" +#define STR_DEFAULT "&Oletus" +#define STR_LANGUAGE "Kieli:" +#define STR_ICONSET "Kuvakkeet:" -#define STR_GAIN "Taso" +#define STR_GAIN "Taso" -#define STR_FILE_NAME "Tiedostonimi:" -#define STR_DISK_SIZE "Levyn koko:" -#define STR_RPM_MODE "Kierroslukutila:" -#define STR_PROGRESS "Edistyminen:" +#define STR_FILE_NAME "Tiedostonimi:" +#define STR_DISK_SIZE "Levyn koko:" +#define STR_RPM_MODE "Kierroslukutila:" +#define STR_PROGRESS "Edistyminen:" -#define STR_WIDTH "Leveys:" -#define STR_HEIGHT "Korkeus:" -#define STR_LOCK_TO_SIZE "Lukitse tähän kokoon" +#define STR_WIDTH "Leveys:" +#define STR_HEIGHT "Korkeus:" +#define STR_LOCK_TO_SIZE "Lukitse tähän kokoon" -#define STR_MACHINE_TYPE "Tietokoneen tyyppi:" -#define STR_MACHINE "Tietokone:" -#define STR_CONFIGURE "Määritys" -#define STR_CPU_TYPE "Suorittimen tyyppi:" -#define STR_CPU_SPEED "Nopeus:" -#define STR_FPU "Apusuoritin:" -#define STR_WAIT_STATES "Odotustilat:" -#define STR_MB "Mt" -#define STR_MEMORY "Muisti:" -#define STR_TIME_SYNC "Kellon synkronointi" -#define STR_DISABLED "Ei käytössä" -#define STR_ENABLED_LOCAL "Käytössä (paikallinen)" -#define STR_ENABLED_UTC "Käytössä (UTC)" -#define STR_DYNAREC "Dynaaminen uudelleenkääntäjä" +#define STR_MACHINE_TYPE "Tietokoneen tyyppi:" +#define STR_MACHINE "Tietokone:" +#define STR_CONFIGURE "Määritys" +#define STR_CPU_TYPE "Suorittimen tyyppi:" +#define STR_CPU_SPEED "Nopeus:" +#define STR_FPU "Apusuoritin:" +#define STR_WAIT_STATES "Odotustilat:" +#define STR_MB "Mt" +#define STR_MEMORY "Muisti:" +#define STR_TIME_SYNC "Kellon synkronointi" +#define STR_DISABLED "Ei käytössä" +#define STR_ENABLED_LOCAL "Käytössä (paikallinen)" +#define STR_ENABLED_UTC "Käytössä (UTC)" +#define STR_DYNAREC "Dynaaminen uudelleenkääntäjä" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Näytönohjain:" -#define STR_VIDEO_2 "Näytönohjain 2:" -#define STR_VOODOO "Voodoo-grafiikkasuoritin" -#define STR_IBM8514 "IBM 8514/a-grafiikkasuoritin" -#define STR_XGA "XGA-grafiikkasuoritin" +#define STR_VIDEO "Näytönohjain:" +#define STR_VIDEO_2 "Näytönohjain 2:" +#define STR_VOODOO "Voodoo-grafiikkasuoritin" +#define STR_IBM8514 "IBM 8514/a-grafiikkasuoritin" +#define STR_XGA "XGA-grafiikkasuoritin" -#define STR_MOUSE "Hiiri:" -#define STR_JOYSTICK "Peliohjain:" -#define STR_JOY1 "Peliohjain 1..." -#define STR_JOY2 "Peliohjain 2..." -#define STR_JOY3 "Peliohjain 3..." -#define STR_JOY4 "Peliohjain 4..." +#define STR_MOUSE "Hiiri:" +#define STR_JOYSTICK "Peliohjain:" +#define STR_JOY1 "Peliohjain 1..." +#define STR_JOY2 "Peliohjain 2..." +#define STR_JOY3 "Peliohjain 3..." +#define STR_JOY4 "Peliohjain 4..." -#define STR_SOUND1 "Äänikortti 1:" -#define STR_SOUND2 "Äänikortti 2:" -#define STR_SOUND3 "Äänikortti 3:" -#define STR_SOUND4 "Äänikortti 4:" -#define STR_MIDI_OUT "MIDI-ulostulo:" -#define STR_MIDI_IN "MIDI-sisääntulo:" -#define STR_MPU401 "Erillinen MPU-401" -#define STR_FLOAT "Käytä FLOAT32-ääntä" -#define STR_FM_DRIVER "FM-syntetisaattoriohjain" -#define STR_FM_DRV_NUKED "Nuked (tarkempi)" -#define STR_FM_DRV_YMFM "YMFM (nopeampi)" +#define STR_SOUND1 "Äänikortti 1:" +#define STR_SOUND2 "Äänikortti 2:" +#define STR_SOUND3 "Äänikortti 3:" +#define STR_SOUND4 "Äänikortti 4:" +#define STR_MIDI_OUT "MIDI-ulostulo:" +#define STR_MIDI_IN "MIDI-sisääntulo:" +#define STR_MPU401 "Erillinen MPU-401" +#define STR_FLOAT "Käytä FLOAT32-ääntä" +#define STR_FM_DRIVER "FM-syntetisaattoriohjain" +#define STR_FM_DRV_NUKED "Nuked (tarkempi)" +#define STR_FM_DRV_YMFM "YMFM (nopeampi)" -#define STR_NET_TYPE "Verkon tyyppi:" -#define STR_PCAP "PCap-laite:" -#define STR_NET "Verkkokortti:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Verkon tyyppi:" +#define STR_PCAP "PCap-laite:" +#define STR_NET "Verkkokortti:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "COM1-laite:" -#define STR_COM2 "COM2-laite:" -#define STR_COM3 "COM3-laite:" -#define STR_COM4 "COM4-laite:" -#define STR_LPT1 "LPT1-laite:" -#define STR_LPT2 "LPT2-laite:" -#define STR_LPT3 "LPT3-laite:" -#define STR_LPT4 "LPT4-laite:" -#define STR_SERIAL1 "Sarjaportti 1" -#define STR_SERIAL2 "Sarjaportti 2" -#define STR_SERIAL3 "Sarjaportti 3" -#define STR_SERIAL4 "Sarjaportti 4" -#define STR_PARALLEL1 "Rinnakkaisportti 1" -#define STR_PARALLEL2 "Rinnakkaisportti 2" -#define STR_PARALLEL3 "Rinnakkaisportti 3" -#define STR_PARALLEL4 "Rinnakkaisportti 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1-laite:" +#define STR_COM2 "COM2-laite:" +#define STR_COM3 "COM3-laite:" +#define STR_COM4 "COM4-laite:" +#define STR_LPT1 "LPT1-laite:" +#define STR_LPT2 "LPT2-laite:" +#define STR_LPT3 "LPT3-laite:" +#define STR_LPT4 "LPT4-laite:" +#define STR_SERIAL1 "Sarjaportti 1" +#define STR_SERIAL2 "Sarjaportti 2" +#define STR_SERIAL3 "Sarjaportti 3" +#define STR_SERIAL4 "Sarjaportti 4" +#define STR_PARALLEL1 "Rinnakkaisportti 1" +#define STR_PARALLEL2 "Rinnakkaisportti 2" +#define STR_PARALLEL3 "Rinnakkaisportti 3" +#define STR_PARALLEL4 "Rinnakkaisportti 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Kiintolevyohjain:" -#define STR_FDC "Levykeohjain:" -#define STR_IDE_TER "Kolmas IDE-ohjain" -#define STR_IDE_QUA "Neljäs IDE-ohjain" -#define STR_SCSI "SCSI" -#define STR_SCSI_1 "Ohjain 1:" -#define STR_SCSI_2 "Ohjain 2:" -#define STR_SCSI_3 "Ohjain 3:" -#define STR_SCSI_4 "Ohjain 4:" -#define STR_CASSETTE "Kasettiasema" +#define STR_HDC "Kiintolevyohjain:" +#define STR_FDC "Levykeohjain:" +#define STR_IDE_TER "Kolmas IDE-ohjain" +#define STR_IDE_QUA "Neljäs IDE-ohjain" +#define STR_SCSI "SCSI" +#define STR_SCSI_1 "Ohjain 1:" +#define STR_SCSI_2 "Ohjain 2:" +#define STR_SCSI_3 "Ohjain 3:" +#define STR_SCSI_4 "Ohjain 4:" +#define STR_CASSETTE "Kasettiasema" -#define STR_HDD "Kiintolevyt:" -#define STR_NEW "&Uusi..." -#define STR_EXISTING "&Olemassaoleva..." -#define STR_REMOVE "&Poista" -#define STR_BUS "Väylä:" -#define STR_CHANNEL "Kanava:" -#define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_HDD "Kiintolevyt:" +#define STR_NEW "&Uusi..." +#define STR_EXISTING "&Olemassaoleva..." +#define STR_REMOVE "&Poista" +#define STR_BUS "Väylä:" +#define STR_CHANNEL "Kanava:" +#define STR_ID "ID:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Määritä..." -#define STR_SECTORS "Sektorit:" -#define STR_HEADS "Lukupäät:" -#define STR_CYLS "Sylinterit:" -#define STR_SIZE_MB "Koko (Mt):" -#define STR_TYPE "Tyyppi:" -#define STR_IMG_FORMAT "Tiedostomuoto:" -#define STR_BLOCK_SIZE "Lohkon koko:" +#define STR_SPECIFY "&Määritä..." +#define STR_SECTORS "Sektorit:" +#define STR_HEADS "Lukupäät:" +#define STR_CYLS "Sylinterit:" +#define STR_SIZE_MB "Koko (Mt):" +#define STR_TYPE "Tyyppi:" +#define STR_IMG_FORMAT "Tiedostomuoto:" +#define STR_BLOCK_SIZE "Lohkon koko:" -#define STR_FLOPPY_DRIVES "Levykeasemat:" -#define STR_TURBO "Turbo-ajoitukset" -#define STR_CHECKBPB "Tarkista BPB" -#define STR_CDROM_DRIVES "CD-ROM-asemat:" -#define STR_CD_SPEED "Nopeus:" -#define STR_EARLY "Aiemmat asemat" +#define STR_FLOPPY_DRIVES "Levykeasemat:" +#define STR_TURBO "Turbo-ajoitukset" +#define STR_CHECKBPB "Tarkista BPB" +#define STR_CDROM_DRIVES "CD-ROM-asemat:" +#define STR_CD_SPEED "Nopeus:" -#define STR_MO_DRIVES "Magneettisoptiset asemat (MO):" -#define STR_ZIP_DRIVES "ZIP-asemat:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Magneettisoptiset asemat (MO):" +#define STR_ZIP_DRIVES "ZIP-asemat:" +#define STR_250 "ZIP 250" -#define STR_ISARTC "ISA-RTC (kello):" -#define STR_ISAMEM "ISA-muistilaajennus" -#define STR_ISAMEM_1 "Kortti 1:" -#define STR_ISAMEM_2 "Kortti 2:" -#define STR_ISAMEM_3 "Kortti 3:" -#define STR_ISAMEM_4 "Kortti 4:" -#define STR_BUGGER "ISABugger-laite" -#define STR_POSTCARD "POST-kortti" +#define STR_ISARTC "ISA-RTC (kello):" +#define STR_ISAMEM "ISA-muistilaajennus" +#define STR_ISAMEM_1 "Kortti 1:" +#define STR_ISAMEM_2 "Kortti 2:" +#define STR_ISAMEM_3 "Kortti 3:" +#define STR_ISAMEM_4 "Kortti 4:" +#define STR_BUGGER "ISABugger-laite" +#define STR_POSTCARD "POST-kortti" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -394,7 +394,7 @@ END STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Virhe" IDS_2050 "Vakava virhe" IDS_2051 " - TAUKO" @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynthin alustus epäonnistui" IDS_2081 "Väylä" IDS_2082 "Tiedosto" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u Mt (CHS: %i, %i, %i)" IDS_2109 "Levyke %i (%s): %ls" IDS_2110 "Kaikki levykuvat (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Kehittyneet sektorilevykuvat (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Perussektorilevykuvat (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux-levykuvat (*.FDI)\0*.FDI\0Pintalevykuvat (*.86F;*.MFM)\0*.86F;*.MFM\0Kaikki tiedostot (*.*)\0*.*\0" - IDS_2111 "FreeType:n alustus epäonnistui" IDS_2112 "SDL:n alustus epäonnistui. Tarvitaan SDL2.dll" IDS_2113 "Haluatko varmasti käynnistää emuloidun tietokoneen uudelleen?" IDS_2114 "Haluatko varmasti sulkea 86Boxin?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Varmista, että " LIB_NAME_PCAP " on asennettu ja että verkkoyhteytesi on " LIB_NAME_PCAP "-yhteensopiva." IDS_2131 "Virheelliset määritykset" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " vaaditaan ESC/P-tulostimen emuloimiseksi." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " vaaditaan PostScript-tiedostojen automaattiseen muuntamiseen PDF-tiedostoiksi.\n\nKaikki geneeriselle PostScript-tulostimelle lähetetyt asiakirjat tallennetaan PostScript (.ps) -tiedostoina." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " vaaditaan FluidSynth MIDI-ulostuloa varten." IDS_2135 "Siirrytään koko näytön tilaan" IDS_2136 "Älä näytä tätä viestiä uudelleen" IDS_2137 "Älä poistu" @@ -537,11 +523,13 @@ BEGIN IDS_2159 "Kylmä uudelleenkäynnistys" IDS_2160 "ACPI-sammutus" IDS_2161 "Asetukset" - IDS_2162 "Aiemmat asemat" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END STRINGTABLE DISCARDABLE @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Järjestelmän oletus)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/fr-FR.rc b/src/win/languages/fr-FR.rc index 15ab41645..1d4643eeb 100644 --- a/src/win/languages/fr-FR.rc +++ b/src/win/languages/fr-FR.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_FRENCH, SUBLANG_FRENCH // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Action" BEGIN - MENUITEM "&Capturer le clavier", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "CTRL &Droite devient ALT Gauche", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Capturer le clavier", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "CTRL &Droite devient ALT Gauche", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Hard Reset...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Hard Reset...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pause", IDM_ACTION_PAUSE + MENUITEM "&Pause", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Quitter...", IDM_ACTION_EXIT + MENUITEM "&Quitter...", IDM_ACTION_EXIT END POPUP "&Vue" BEGIN - MENUITEM "&Masquer la barre de status", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Masquer la barre de status", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "Fenètre &Retaillable", IDM_VID_RESIZE - MENUITEM "S&auvegarder taille && position", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "Fenètre &Retaillable", IDM_VID_RESIZE + MENUITEM "S&auvegarder taille && position", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "Moteur de &rendu vidéo" BEGIN - MENUITEM "&SDL (Logiciel)", IDM_VID_SDL_SW - MENUITEM "SDL (&Materiel)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Logiciel)", IDM_VID_SDL_SW + MENUITEM "SDL (&Materiel)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Specifier dimensions...", IDM_VID_SPECIFY_DIM - MENUITEM "F&orcer 4:3", IDM_VID_FORCE43 + MENUITEM "Specifier dimensions...", IDM_VID_SPECIFY_DIM + MENUITEM "F&orcer 4:3", IDM_VID_FORCE43 POPUP "&Echelle facteur" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Methode Filtre" BEGIN - MENUITEM "&Plus proche", IDM_VID_FILTER_NEAREST - MENUITEM "&Lineaire", IDM_VID_FILTER_LINEAR + MENUITEM "&Plus proche", IDM_VID_FILTER_NEAREST + MENUITEM "&Lineaire", IDM_VID_FILTER_LINEAR END - MENUITEM "Mise à l'échelle Hi&DPI", IDM_VID_HIDPI + MENUITEM "Mise à l'échelle Hi&DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Plein Ecran\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Plein Ecran\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Mode &Elargi plein écran" BEGIN - MENUITEM "&Plein écran étiré", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Plein écran étiré", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "pixels &Carrés(Keep ratio)", IDM_VID_FS_KEEPRATIO - MENUITEM "Echelle &Entière", IDM_VID_FS_INT + MENUITEM "Echelle &Entière", IDM_VID_FS_INT END POPUP "Réglages E&GA/(S)VGA" BEGIN - MENUITEM "Moniteur VGA &Inversé", IDM_VID_INVERT + MENUITEM "Moniteur VGA &Inversé", IDM_VID_INVERT POPUP "&Type Ecran VGA" BEGIN - MENUITEM "RGB &Couleur", IDM_VID_GRAY_RGB - MENUITEM "&RGB Ton de Gris", IDM_VID_GRAY_MONO - MENUITEM "Moniteur &Ambre", IDM_VID_GRAY_AMBER - MENUITEM "Moniteur &Vert", IDM_VID_GRAY_GREEN - MENUITEM "Moniteur &Blanc", IDM_VID_GRAY_WHITE + MENUITEM "RGB &Couleur", IDM_VID_GRAY_RGB + MENUITEM "&RGB Ton de Gris", IDM_VID_GRAY_MONO + MENUITEM "Moniteur &Ambre", IDM_VID_GRAY_AMBER + MENUITEM "Moniteur &Vert", IDM_VID_GRAY_GREEN + MENUITEM "Moniteur &Blanc", IDM_VID_GRAY_WHITE END POPUP "Grayscale &conversion type" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Moyenne", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Moyenne", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA overscan", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA overscan", IDM_VID_OVERSCAN MENUITEM "Modifier contraste affichage &monochrome", IDM_VID_CGACON END - MENUITEM "&Media", IDM_MEDIA + MENUITEM "&Media", IDM_MEDIA POPUP "Ou&tils" BEGIN - MENUITEM "&Réglages...", IDM_CONFIG - MENUITEM "Mettre à jour la barre de stat&us", IDM_UPDATE_ICONS + MENUITEM "&Réglages...", IDM_CONFIG + MENUITEM "Mettre à jour la barre de stat&us", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Copie &Ecran\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Copie &Ecran\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Préférences...", IDM_PREFERENCES + MENUITEM "&Préférences...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Activer intégration &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Gain Son...", IDM_SND_GAIN + MENUITEM "&Gain Son...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Démarrer traces\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Finir traces\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Démarrer traces\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Finir traces\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Aide" BEGIN - MENUITEM "&Documentation...", IDM_DOCS - MENUITEM "&A Propos de 86Box...", IDM_ABOUT + MENUITEM "&Documentation...", IDM_DOCS + MENUITEM "&A Propos de 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nouvelle image...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nouvelle image...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Image &Existante...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Image Existante(&Lecture seule)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "Image &Existante...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Image Existante(&Lecture seule)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "En®istrer", IDM_CASSETTE_RECORD - MENUITEM "&Jouer", IDM_CASSETTE_PLAY - MENUITEM "&Revenir au debut", IDM_CASSETTE_REWIND - MENUITEM "Aller à la &Fin", IDM_CASSETTE_FAST_FORWARD + MENUITEM "En®istrer", IDM_CASSETTE_RECORD + MENUITEM "&Jouer", IDM_CASSETTE_PLAY + MENUITEM "&Revenir au debut", IDM_CASSETTE_REWIND + MENUITEM "Aller à la &Fin", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "E&jecter", IDM_CASSETTE_EJECT + MENUITEM "E&jecter", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Image...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Image...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "E&jecter", IDM_CARTRIDGE_EJECT + MENUITEM "E&jecter", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nouvelle image...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nouvelle image...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Image &Existante...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Image Existante(&Lecture seule)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "Image &Existante...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Image Existante(&Lecture seule)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xport vers 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&xport vers 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "E&jecter", IDM_FLOPPY_EJECT + MENUITEM "E&jecter", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Couper", IDM_CDROM_MUTE + MENUITEM "&Couper", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "E&jecter", IDM_CDROM_EMPTY - MENUITEM "&Recharger image précedente", IDM_CDROM_RELOAD + MENUITEM "E&jecter", IDM_CDROM_EMPTY + MENUITEM "&Recharger image précedente", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Image...", IDM_CDROM_IMAGE - MENUITEM "&Dossier...", IDM_CDROM_DIR + MENUITEM "&Image...", IDM_CDROM_IMAGE + MENUITEM "&Dossier...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nouvelle image...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nouvelle image...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Image &Existante...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Image Existante (&Lecture Seule)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "Image &Existante...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Image Existante (&Lecture Seule)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&jecter", IDM_ZIP_EJECT - MENUITEM "&Recharger image précédente", IDM_ZIP_RELOAD + MENUITEM "E&jecter", IDM_ZIP_EJECT + MENUITEM "&Recharger image précédente", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nouvelle image...", IDM_MO_IMAGE_NEW + MENUITEM "&Nouvelle image...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Image &Existante...", IDM_MO_IMAGE_EXISTING - MENUITEM "Image Existante (&Lecture Seule)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "Image &Existante...", IDM_MO_IMAGE_EXISTING + MENUITEM "Image Existante (&Lecture Seule)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&jecter", IDM_MO_EJECT - MENUITEM "&Recharger image précédente", IDM_MO_RELOAD + MENUITEM "E&jecter", IDM_MO_EJECT + MENUITEM "&Recharger image précédente", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Préférences" -#define STR_SND_GAIN "Gain son" -#define STR_NEW_FLOPPY "Nouvelle image" +#define STR_PREFERENCES "Préférences" +#define STR_SND_GAIN "Gain son" +#define STR_NEW_FLOPPY "Nouvelle image" #define STR_CONFIG "Réglages" -#define STR_SPECIFY_DIM "Spécifier le détournement de la fenêtre principale" +#define STR_SPECIFY_DIM "Spécifier le détournement de la fenêtre principale" #define STR_OK "OK" #define STR_CANCEL "Annuler" #define STR_GLOBAL "Sauvegarder ces paramètres comme valeurs par défaut &globales" -#define STR_DEFAULT "&Défaut" -#define STR_LANGUAGE "Langue:" -#define STR_ICONSET "Ensemble d'icônes:" +#define STR_DEFAULT "&Défaut" +#define STR_LANGUAGE "Langue:" +#define STR_ICONSET "Ensemble d'icônes:" -#define STR_GAIN "Gain" +#define STR_GAIN "Gain" -#define STR_FILE_NAME "Nom fichier:" -#define STR_DISK_SIZE "Taille disque:" -#define STR_RPM_MODE "Mode RPM:" -#define STR_PROGRESS "Progrès:" +#define STR_FILE_NAME "Nom fichier:" +#define STR_DISK_SIZE "Taille disque:" +#define STR_RPM_MODE "Mode RPM:" +#define STR_PROGRESS "Progrès:" -#define STR_WIDTH "Largeur:" +#define STR_WIDTH "Largeur:" #define STR_HEIGHT "Hauteur:" -#define STR_LOCK_TO_SIZE "Verrouiller à cette taille" +#define STR_LOCK_TO_SIZE "Verrouiller à cette taille" -#define STR_MACHINE_TYPE "Type de machine:" -#define STR_MACHINE "Machine:" -#define STR_CONFIGURE "Configurer" -#define STR_CPU_TYPE "Type du processeur:" -#define STR_CPU_SPEED "Vitesse:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "États d'attente:" +#define STR_MACHINE_TYPE "Type de machine:" +#define STR_MACHINE "Machine:" +#define STR_CONFIGURE "Configurer" +#define STR_CPU_TYPE "Type du processeur:" +#define STR_CPU_SPEED "Vitesse:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "États d'attente:" #define STR_MB "Mo" #define STR_MEMORY "Mémoire:" -#define STR_TIME_SYNC "Synchronisation du temps" -#define STR_DISABLED "Désactivé" -#define STR_ENABLED_LOCAL "Activé (heure locale)" -#define STR_ENABLED_UTC "Activé (UTC)" -#define STR_DYNAREC "Recompilateur dynamique" +#define STR_TIME_SYNC "Synchronisation du temps" +#define STR_DISABLED "Désactivé" +#define STR_ENABLED_LOCAL "Activé (heure locale)" +#define STR_ENABLED_UTC "Activé (UTC)" +#define STR_DYNAREC "Recompilateur dynamique" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Vidéo:" -#define STR_VIDEO_2 "Vidéo 2:" +#define STR_VIDEO "Vidéo:" +#define STR_VIDEO_2 "Vidéo 2:" #define STR_VOODOO "Graphique Voodoo" -#define STR_IBM8514 "Graphique IBM 8514/a" -#define STR_XGA "Graphique XGA" +#define STR_IBM8514 "Graphique IBM 8514/a" +#define STR_XGA "Graphique XGA" -#define STR_MOUSE "Souris:" -#define STR_JOYSTICK "Manette de commande:" -#define STR_JOY1 "Manette 1..." -#define STR_JOY2 "Manette 2..." -#define STR_JOY3 "Manette 3..." -#define STR_JOY4 "Manette 4..." +#define STR_MOUSE "Souris:" +#define STR_JOYSTICK "Manette de commande:" +#define STR_JOY1 "Manette 1..." +#define STR_JOY2 "Manette 2..." +#define STR_JOY3 "Manette 3..." +#define STR_JOY4 "Manette 4..." #define STR_SOUND1 "Carte son 1:" #define STR_SOUND2 "Carte son 2:" #define STR_SOUND3 "Carte son 3:" #define STR_SOUND4 "Carte son 4:" -#define STR_MIDI_OUT "Sortie MIDI:" -#define STR_MIDI_IN "Entrée MIDI:" +#define STR_MIDI_OUT "Sortie MIDI:" +#define STR_MIDI_IN "Entrée MIDI:" #define STR_MPU401 "MPU-401 autonome" -#define STR_FLOAT "Utiliser le son FLOAT32" -#define STR_FM_DRIVER "Pilote de synthétiseur FM" -#define STR_FM_DRV_NUKED "Nuked (plus précis)" -#define STR_FM_DRV_YMFM "YMFM (plus rapide)" +#define STR_FLOAT "Utiliser le son FLOAT32" +#define STR_FM_DRIVER "Pilote de synthétiseur FM" +#define STR_FM_DRV_NUKED "Nuked (plus précis)" +#define STR_FM_DRV_YMFM "YMFM (plus rapide)" -#define STR_NET_TYPE "Type de réseau:" -#define STR_PCAP "Dispositif PCap:" -#define STR_NET "Adaptateur de réseau:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Type de réseau:" +#define STR_PCAP "Dispositif PCap:" +#define STR_NET "Adaptateur de réseau:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Dispositif COM1:" -#define STR_COM2 "Dispositif COM2:" -#define STR_COM3 "Dispositif COM3:" -#define STR_COM4 "Dispositif COM4:" -#define STR_LPT1 "Dispositif LPT1:" -#define STR_LPT2 "Dispositif LPT2:" -#define STR_LPT3 "Dispositif LPT3:" -#define STR_LPT4 "Dispositif LPT4:" -#define STR_SERIAL1 "Port série 1" -#define STR_SERIAL2 "Port série 2" -#define STR_SERIAL3 "Port série 3" -#define STR_SERIAL4 "Port série 4" -#define STR_PARALLEL1 "Port parallèle 1" -#define STR_PARALLEL2 "Port parallèle 2" -#define STR_PARALLEL3 "Port parallèle 3" -#define STR_PARALLEL4 "Port parallèle 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Dispositif COM1:" +#define STR_COM2 "Dispositif COM2:" +#define STR_COM3 "Dispositif COM3:" +#define STR_COM4 "Dispositif COM4:" +#define STR_LPT1 "Dispositif LPT1:" +#define STR_LPT2 "Dispositif LPT2:" +#define STR_LPT3 "Dispositif LPT3:" +#define STR_LPT4 "Dispositif LPT4:" +#define STR_SERIAL1 "Port série 1" +#define STR_SERIAL2 "Port série 2" +#define STR_SERIAL3 "Port série 3" +#define STR_SERIAL4 "Port série 4" +#define STR_PARALLEL1 "Port parallèle 1" +#define STR_PARALLEL2 "Port parallèle 2" +#define STR_PARALLEL3 "Port parallèle 3" +#define STR_PARALLEL4 "Port parallèle 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Contrôleur HD:" -#define STR_FDC "Contrôleur FD:" -#define STR_IDE_TER "Contrôleur IDE tertiaire" -#define STR_IDE_QUA "Contrôleur IDE quaternair" -#define STR_SCSI "SCSI" +#define STR_HDC "Contrôleur HD:" +#define STR_FDC "Contrôleur FD:" +#define STR_IDE_TER "Contrôleur IDE tertiaire" +#define STR_IDE_QUA "Contrôleur IDE quaternair" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Contrôleur 1:" #define STR_SCSI_2 "Contrôleur 2:" #define STR_SCSI_3 "Contrôleur 3:" #define STR_SCSI_4 "Contrôleur 4:" -#define STR_CASSETTE "Cassette" +#define STR_CASSETTE "Cassette" -#define STR_HDD "Disques durs:" -#define STR_NEW "&Nouveau..." -#define STR_EXISTING "&Existant..." +#define STR_HDD "Disques durs:" +#define STR_NEW "&Nouveau..." +#define STR_EXISTING "&Existant..." #define STR_REMOVE "&Supprimer" -#define STR_BUS "Bus:" -#define STR_CHANNEL "Canal:" +#define STR_BUS "Bus:" +#define STR_CHANNEL "Canal:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Spécifier..." -#define STR_SECTORS "Secteurs:" -#define STR_HEADS "Têtes:" -#define STR_CYLS "Cylindres:" -#define STR_SIZE_MB "Taille (Mo):" -#define STR_TYPE "Type:" -#define STR_IMG_FORMAT "Format Image:" -#define STR_BLOCK_SIZE "Taille du bloc:" +#define STR_SPECIFY "&Spécifier..." +#define STR_SECTORS "Secteurs:" +#define STR_HEADS "Têtes:" +#define STR_CYLS "Cylindres:" +#define STR_SIZE_MB "Taille (Mo):" +#define STR_TYPE "Type:" +#define STR_IMG_FORMAT "Format Image:" +#define STR_BLOCK_SIZE "Taille du bloc:" -#define STR_FLOPPY_DRIVES "Lecteurs de disquettes:" -#define STR_TURBO "Turbo" -#define STR_CHECKBPB "Vérifier BPB" -#define STR_CDROM_DRIVES "Lecterus CD-ROM:" -#define STR_CD_SPEED "Vitesse:" -#define STR_EARLY "Lecteur plus tôt" +#define STR_FLOPPY_DRIVES "Lecteurs de disquettes:" +#define STR_TURBO "Turbo" +#define STR_CHECKBPB "Vérifier BPB" +#define STR_CDROM_DRIVES "Lecterus CD-ROM:" +#define STR_CD_SPEED "Vitesse:" -#define STR_MO_DRIVES "Lecteurs magnéto-optiques:" -#define STR_ZIP_DRIVES "Lecteurs ZIP:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Lecteurs magnéto-optiques:" +#define STR_ZIP_DRIVES "Lecteurs ZIP:" +#define STR_250 "ZIP 250" #define STR_ISARTC "Horloge temps réel ISA:" #define STR_ISAMEM "Expansion de la mémoire ISA" -#define STR_ISAMEM_1 "Carte 1:" -#define STR_ISAMEM_2 "Carte 2:" -#define STR_ISAMEM_3 "Carte 3:" -#define STR_ISAMEM_4 "Carte 4:" +#define STR_ISAMEM_1 "Carte 1:" +#define STR_ISAMEM_2 "Carte 2:" +#define STR_ISAMEM_3 "Carte 3:" +#define STR_ISAMEM_4 "Carte 4:" #define STR_BUGGER "Dispositif ISABugger" -#define STR_POSTCARD "Carte POST" +#define STR_POSTCARD "Carte POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Erreur" IDS_2050 "Erreur fatale" IDS_2051 " - PAUSED" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "La machine ""%hs"" n'est pas disponible en raison de l'absence de ROMs dans le répertoire roms/machines. Basculer vers une machine disponible." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "La carte vidéo ""%hs"" n'est pas disponible en raison de l'absence de ROMs dans le répertoire roms/video. Basculer vers une carte vidéo disponible." IDS_2065 "Machine" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Appuyer sur F8+F12 ou le bouton central pour libérer la souris" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Impossible d'initialiser FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u Mo (CTS: %i, %i, %i)" IDS_2109 "Disquette %i (%s): %ls" IDS_2110 "Toutes les images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Images du secteur avancés (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Images du secteur basiques (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Images du flux (*.FDI)\0*.FDI\0Images de surface (*.86F;*.MFM)\0*.86F;*.MFM\0Tous les fichiers (*.*)\0*.*\0" - IDS_2111 "Impossible d'initialiser FreeType" IDS_2112 "Impossible d'initialiser SDL, SDL2.dll est nécessaire" IDS_2113 "Etes-vous sûr de vouloir réinitialiser la machine émulée ?" IDS_2114 "Etes-vous sûr de vouloir quitter 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Assurez-vous que " LIB_NAME_PCAP " est installé et que vou utilisez une connexion réseau compatible avec " LIB_NAME_PCAP "." IDS_2131 "Configuration non valide" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " est nécessaire pour l'émulation de l'imprimante ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " est nécessair pour la conversion automatique des fichiers PostScript dans PDF.\n\nTous les documents envoyés à l'imprimante générique PostScript seront sauvés comme des fichiers PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " est nécessaire pour la sortie MIDI FluidSynth." IDS_2135 "Entrer en mode plein écran" IDS_2136 "Ne pas montrer ce message à nouveau" IDS_2137 "Ne pas sortir" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Hard reset" IDS_2160 "ACPI shutdown" IDS_2161 "Settings" - IDS_2162 "Lecteur plus tôt" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Disque dur (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Défaut du système)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // French (F.R.) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/hr-HR.rc b/src/win/languages/hr-HR.rc index 487894acd..5225ff969 100644 --- a/src/win/languages/hr-HR.rc +++ b/src/win/languages/hr-HR.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_CROATIAN, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Radnje" BEGIN - MENUITEM "&Tipkovnica zahtijeva hvatanje miša", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Desni CTRL je lijevi ALT", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Tipkovnica zahtijeva hvatanje miša", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Desni CTRL je lijevi ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Ponovno pokretanje...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Ponovno pokretanje...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pauza", IDM_ACTION_PAUSE + MENUITEM "&Pauza", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "Iz&laz...", IDM_ACTION_EXIT + MENUITEM "Iz&laz...", IDM_ACTION_EXIT END POPUP "&Pogled" BEGIN - MENUITEM "&Sakrij statusni redak", IDM_VID_HIDE_STATUS_BAR - MENUITEM "&Sakrij alatni redak", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Sakrij statusni redak", IDM_VID_HIDE_STATUS_BAR + MENUITEM "&Sakrij alatni redak", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Prozor s promjenjivim veličinama", IDM_VID_RESIZE - MENUITEM "&Zapamtite veličinu i položaj", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Prozor s promjenjivim veličinama", IDM_VID_RESIZE + MENUITEM "&Zapamtite veličinu i položaj", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Renderer" BEGIN - MENUITEM "&SDL (Softver)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardver)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 jezgra)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Softver)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardver)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 jezgra)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Odrediti veličinu...", IDM_VID_SPECIFY_DIM - MENUITEM "&4:3 omjer prikaza", IDM_VID_FORCE43 + MENUITEM "Odrediti veličinu...", IDM_VID_SPECIFY_DIM + MENUITEM "&4:3 omjer prikaza", IDM_VID_FORCE43 POPUP "&Faktor skaliranja prozora" BEGIN - MENUITEM "&0,5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1,&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0,5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1,&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Metoda filtriranja" BEGIN - MENUITEM "&Najbliža", IDM_VID_FILTER_NEAREST - MENUITEM "&Linearna", IDM_VID_FILTER_LINEAR + MENUITEM "&Najbliža", IDM_VID_FILTER_NEAREST + MENUITEM "&Linearna", IDM_VID_FILTER_LINEAR END - MENUITEM "&HiDPI skaliranje", IDM_VID_HIDPI + MENUITEM "&HiDPI skaliranje", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Cijelozaslonski način\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Cijelozaslonski način\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "&Način cijelozaslonskog rastezanja" BEGIN - MENUITEM "&Razvuci na cijeli zaslona", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Razvuci na cijeli zaslona", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Kvadratni pikseli (zadrži omjer)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Cijelobrojno skaliranje", IDM_VID_FS_INT + MENUITEM "&Cijelobrojno skaliranje", IDM_VID_FS_INT END POPUP "E&GA/(S)VGA postavke" BEGIN - MENUITEM "&Obrni boje zaslona VGA", IDM_VID_INVERT + MENUITEM "&Obrni boje zaslona VGA", IDM_VID_INVERT POPUP "&Tip zaslona VGA" BEGIN - MENUITEM "RGB u &boji", IDM_VID_GRAY_RGB - MENUITEM "&RGB u nijansama sive boje", IDM_VID_GRAY_MONO - MENUITEM "&Jantarni zaslon", IDM_VID_GRAY_AMBER - MENUITEM "&Zeleni zaslon", IDM_VID_GRAY_GREEN - MENUITEM "&Bijeli zaslon", IDM_VID_GRAY_WHITE + MENUITEM "RGB u &boji", IDM_VID_GRAY_RGB + MENUITEM "&RGB u nijansama sive boje", IDM_VID_GRAY_MONO + MENUITEM "&Jantarni zaslon", IDM_VID_GRAY_AMBER + MENUITEM "&Zeleni zaslon", IDM_VID_GRAY_GREEN + MENUITEM "&Bijeli zaslon", IDM_VID_GRAY_WHITE END POPUP "&Vrsta konverzije nijansa sive boje" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Prosjek", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Prosjek", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "&Višak slike CGA/PCjr/Tandy/EGA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "&Višak slike CGA/PCjr/Tandy/EGA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "&Promjeni kontrast za crno-bijeli zaslon", IDM_VID_CGACON END - MENUITEM "&Mediji", IDM_MEDIA + MENUITEM "&Mediji", IDM_MEDIA POPUP "&Alati" BEGIN - MENUITEM "&Opcije...", IDM_CONFIG - MENUITEM "&Ažuriraj ikone statusnog redka", IDM_UPDATE_ICONS + MENUITEM "&Opcije...", IDM_CONFIG + MENUITEM "&Ažuriraj ikone statusnog redka", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Napravi &snimku zaslona\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Napravi &snimku zaslona\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Postavke...", IDM_PREFERENCES + MENUITEM "&Postavke...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Omogući integraciju sa programom &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Pojačanje zvuka...", IDM_SND_GAIN + MENUITEM "&Pojačanje zvuka...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Z&apočni praćenje\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "&Svrši praćenje\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Z&apočni praćenje\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "&Svrši praćenje\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Pomoć" BEGIN - MENUITEM "&Dokumentacija...", IDM_DOCS - MENUITEM "&O programu 86Box...", IDM_ABOUT + MENUITEM "&Dokumentacija...", IDM_DOCS + MENUITEM "&O programu 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Postojeća slika...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Postojeća slika...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Snimi", IDM_CASSETTE_RECORD - MENUITEM "&Pokreni", IDM_CASSETTE_PLAY - MENUITEM "P&remotaj na početak", IDM_CASSETTE_REWIND - MENUITEM "&Preskoči do kraja", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Snimi", IDM_CASSETTE_RECORD + MENUITEM "&Pokreni", IDM_CASSETTE_PLAY + MENUITEM "P&remotaj na početak", IDM_CASSETTE_REWIND + MENUITEM "&Preskoči do kraja", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "&Izbaci", IDM_CASSETTE_EJECT + MENUITEM "&Izbaci", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Slika...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Slika...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "&Izbaci", IDM_CARTRIDGE_EJECT + MENUITEM "&Izbaci", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Postojeća slika...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Postojeća slika...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Izvozi u 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "&Izvozi u 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "&Izbaci", IDM_FLOPPY_EJECT + MENUITEM "&Izbaci", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Isključi zvuk", IDM_CDROM_MUTE + MENUITEM "&Isključi zvuk", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&Prazno", IDM_CDROM_EMPTY - MENUITEM "&Ponovo učitaj prethodnu sliku", IDM_CDROM_RELOAD + MENUITEM "&Prazno", IDM_CDROM_EMPTY + MENUITEM "&Ponovo učitaj prethodnu sliku", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Slika...", IDM_CDROM_IMAGE - MENUITEM "&Mapa...", IDM_CDROM_DIR + MENUITEM "&Slika...", IDM_CDROM_IMAGE + MENUITEM "&Mapa...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Postojeća slika...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Postojeća slika...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Izbaci", IDM_ZIP_EJECT - MENUITEM "&Ponovo učitaj prethodnu sliku", IDM_ZIP_RELOAD + MENUITEM "&Izbaci", IDM_ZIP_EJECT + MENUITEM "&Ponovo učitaj prethodnu sliku", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_MO_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Postojeća slika...", IDM_MO_IMAGE_EXISTING - MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Postojeća slika...", IDM_MO_IMAGE_EXISTING + MENUITEM "Postojeća slika (&zaštićena od pisanja)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Izbaci", IDM_MO_EJECT - MENUITEM "&Ponovo učitaj prethodnu sliku", IDM_MO_RELOAD + MENUITEM "&Izbaci", IDM_MO_EJECT + MENUITEM "&Ponovo učitaj prethodnu sliku", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Postavke" -#define STR_SND_GAIN "Pojačavanje zvuka" -#define STR_NEW_FLOPPY "Nova slika" +#define STR_PREFERENCES "Postavke" +#define STR_SND_GAIN "Pojačavanje zvuka" +#define STR_NEW_FLOPPY "Nova slika" #define STR_CONFIG "Opcije" -#define STR_SPECIFY_DIM "Odredite glavne dimenzije prozora" +#define STR_SPECIFY_DIM "Odredite glavne dimenzije prozora" #define STR_OK "U redu" #define STR_CANCEL "Otkaži" #define STR_GLOBAL "Spremite ove postavke kao &globalne zadane postavke" -#define STR_DEFAULT "Zadano" -#define STR_LANGUAGE "Jezik:" -#define STR_ICONSET "Paket ikona:" +#define STR_DEFAULT "Zadano" +#define STR_LANGUAGE "Jezik:" +#define STR_ICONSET "Paket ikona:" -#define STR_GAIN "Pojačavanje" +#define STR_GAIN "Pojačavanje" -#define STR_FILE_NAME "Ime datoteke:" -#define STR_DISK_SIZE "Veličina diska:" -#define STR_RPM_MODE "Način broja okretaja:" -#define STR_PROGRESS "Napredak:" +#define STR_FILE_NAME "Ime datoteke:" +#define STR_DISK_SIZE "Veličina diska:" +#define STR_RPM_MODE "Način broja okretaja:" +#define STR_PROGRESS "Napredak:" -#define STR_WIDTH "Širina:" +#define STR_WIDTH "Širina:" #define STR_HEIGHT "Visina:" -#define STR_LOCK_TO_SIZE "Zaključajte na ovu veličinu" +#define STR_LOCK_TO_SIZE "Zaključajte na ovu veličinu" -#define STR_MACHINE_TYPE "Tip sistema:" -#define STR_MACHINE "Sistem:" -#define STR_CONFIGURE "Namjesti" -#define STR_CPU_TYPE "Tip procesora:" -#define STR_CPU_SPEED "Brzina:" -#define STR_FPU "FPU uređaj:" -#define STR_WAIT_STATES "Stanja čekanja:" +#define STR_MACHINE_TYPE "Tip sistema:" +#define STR_MACHINE "Sistem:" +#define STR_CONFIGURE "Namjesti" +#define STR_CPU_TYPE "Tip procesora:" +#define STR_CPU_SPEED "Brzina:" +#define STR_FPU "FPU uređaj:" +#define STR_WAIT_STATES "Stanja čekanja:" #define STR_MB "MB" #define STR_MEMORY "Memorija:" -#define STR_TIME_SYNC "Sinkronizacija vremena" -#define STR_DISABLED "Isključeno" -#define STR_ENABLED_LOCAL "Uključeno (lokalno vrijeme)" -#define STR_ENABLED_UTC "Uključeno (UTC)" -#define STR_DYNAREC "Dinamički rekompilator" +#define STR_TIME_SYNC "Sinkronizacija vremena" +#define STR_DISABLED "Isključeno" +#define STR_ENABLED_LOCAL "Uključeno (lokalno vrijeme)" +#define STR_ENABLED_UTC "Uključeno (UTC)" +#define STR_DYNAREC "Dinamički rekompilator" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Video:" -#define STR_VIDEO_2 "Video 2:" +#define STR_VIDEO "Video:" +#define STR_VIDEO_2 "Video 2:" #define STR_VOODOO "Voodoo grafika" -#define STR_IBM8514 "IBM 8514/a grafika" -#define STR_XGA "XGA grafika" +#define STR_IBM8514 "IBM 8514/a grafika" +#define STR_XGA "XGA grafika" -#define STR_MOUSE "Miš:" -#define STR_JOYSTICK "Palica za igru:" -#define STR_JOY1 "Palica za igru 1..." -#define STR_JOY2 "Palica za igru 2..." -#define STR_JOY3 "Palica za igru 3..." -#define STR_JOY4 "Palica za igru 4..." +#define STR_MOUSE "Miš:" +#define STR_JOYSTICK "Palica za igru:" +#define STR_JOY1 "Palica za igru 1..." +#define STR_JOY2 "Palica za igru 2..." +#define STR_JOY3 "Palica za igru 3..." +#define STR_JOY4 "Palica za igru 4..." #define STR_SOUND1 "Zvučna kartica 1:" #define STR_SOUND2 "Zvučna kartica 2:" #define STR_SOUND3 "Zvučna kartica 3:" #define STR_SOUND4 "Zvučna kartica 4:" -#define STR_MIDI_OUT "Izlazni uređaj MIDI:" -#define STR_MIDI_IN "Ulazni uređaj MIDI:" +#define STR_MIDI_OUT "Izlazni uređaj MIDI:" +#define STR_MIDI_IN "Ulazni uređaj MIDI:" #define STR_MPU401 "Samostalni MPU-401" -#define STR_FLOAT "Koristi FLOAT32 za zvuk" -#define STR_FM_DRIVER "Drajver za FM sintisajzer" -#define STR_FM_DRV_NUKED "Nuked (precizniji)" -#define STR_FM_DRV_YMFM "YMFM (brži)" +#define STR_FLOAT "Koristi FLOAT32 za zvuk" +#define STR_FM_DRIVER "Drajver za FM sintisajzer" +#define STR_FM_DRV_NUKED "Nuked (precizniji)" +#define STR_FM_DRV_YMFM "YMFM (brži)" -#define STR_NET_TYPE "Tip mreže:" -#define STR_PCAP "Uređaj PCap:" -#define STR_NET "Mrežna kartica:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Tip mreže:" +#define STR_PCAP "Uređaj PCap:" +#define STR_NET "Mrežna kartica:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Uređaj COM1:" -#define STR_COM2 "Uređaj COM2:" -#define STR_COM3 "Uređaj COM3:" -#define STR_COM4 "Uređaj COM4:" -#define STR_LPT1 "Uređaj LPT1:" -#define STR_LPT2 "Uređaj LPT2:" -#define STR_LPT3 "Uređaj LPT3:" -#define STR_LPT4 "Uređaj LPT4:" -#define STR_SERIAL1 "Serijska vrata 1" -#define STR_SERIAL2 "Serijska vrata 2" -#define STR_SERIAL3 "Serijska vrata 3" -#define STR_SERIAL4 "Serijska vrata 4" -#define STR_PARALLEL1 "Paralelna vrata 1" -#define STR_PARALLEL2 "Paralelna vrata 2" -#define STR_PARALLEL3 "Paralelna vrata 3" -#define STR_PARALLEL4 "Paralelna vrata 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Uređaj COM1:" +#define STR_COM2 "Uređaj COM2:" +#define STR_COM3 "Uređaj COM3:" +#define STR_COM4 "Uređaj COM4:" +#define STR_LPT1 "Uređaj LPT1:" +#define STR_LPT2 "Uređaj LPT2:" +#define STR_LPT3 "Uređaj LPT3:" +#define STR_LPT4 "Uređaj LPT4:" +#define STR_SERIAL1 "Serijska vrata 1" +#define STR_SERIAL2 "Serijska vrata 2" +#define STR_SERIAL3 "Serijska vrata 3" +#define STR_SERIAL4 "Serijska vrata 4" +#define STR_PARALLEL1 "Paralelna vrata 1" +#define STR_PARALLEL2 "Paralelna vrata 2" +#define STR_PARALLEL3 "Paralelna vrata 3" +#define STR_PARALLEL4 "Paralelna vrata 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Kontroler tvrdog diska:" -#define STR_FDC "Kontroler diskete:" -#define STR_IDE_TER "Tercijarni IDE kontroler" -#define STR_IDE_QUA "Kvaternarni IDE kontroler" -#define STR_SCSI "SCSI" +#define STR_HDC "Kontroler tvrdog diska:" +#define STR_FDC "Kontroler diskete:" +#define STR_IDE_TER "Tercijarni IDE kontroler" +#define STR_IDE_QUA "Kvaternarni IDE kontroler" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Kontroler 1:" #define STR_SCSI_2 "Kontroler 2:" #define STR_SCSI_3 "Kontroler 3:" #define STR_SCSI_4 "Kontroler 4:" -#define STR_CASSETTE "Audio kaseta" +#define STR_CASSETTE "Audio kaseta" -#define STR_HDD "Tvrdi diskovi:" -#define STR_NEW "&Novi..." -#define STR_EXISTING "&Postojeći..." +#define STR_HDD "Tvrdi diskovi:" +#define STR_NEW "&Novi..." +#define STR_EXISTING "&Postojeći..." #define STR_REMOVE "&Ukloni" -#define STR_BUS "Sabirnica:" -#define STR_CHANNEL "Kanal:" +#define STR_BUS "Sabirnica:" +#define STR_CHANNEL "Kanal:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Odredi..." -#define STR_SECTORS "Sektori:" -#define STR_HEADS "Glave:" -#define STR_CYLS "Cilindri:" -#define STR_SIZE_MB "Veličina (MB):" -#define STR_TYPE "Tip:" -#define STR_IMG_FORMAT "Format slike:" -#define STR_BLOCK_SIZE "Veličina slike:" +#define STR_SPECIFY "&Odredi..." +#define STR_SECTORS "Sektori:" +#define STR_HEADS "Glave:" +#define STR_CYLS "Cilindri:" +#define STR_SIZE_MB "Veličina (MB):" +#define STR_TYPE "Tip:" +#define STR_IMG_FORMAT "Format slike:" +#define STR_BLOCK_SIZE "Veličina slike:" -#define STR_FLOPPY_DRIVES "Disketni pogoni:" -#define STR_TURBO "Turbo vrijemena" -#define STR_CHECKBPB "Provjeraj BPB" -#define STR_CDROM_DRIVES "CD-ROM pogoni:" -#define STR_CD_SPEED "Brzina:" -#define STR_EARLY "Raniji pogon" +#define STR_FLOPPY_DRIVES "Disketni pogoni:" +#define STR_TURBO "Turbo vrijemena" +#define STR_CHECKBPB "Provjeraj BPB" +#define STR_CDROM_DRIVES "CD-ROM pogoni:" +#define STR_CD_SPEED "Brzina:" -#define STR_MO_DRIVES "MO pogoni:" -#define STR_ZIP_DRIVES "ZIP pogoni:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "MO pogoni:" +#define STR_ZIP_DRIVES "ZIP pogoni:" +#define STR_250 "ZIP 250" #define STR_ISARTC "Sat stvarnog vremena (RTC):" #define STR_ISAMEM "Proširenje memorije ISA" -#define STR_ISAMEM_1 "Kartica 1:" -#define STR_ISAMEM_2 "Kartica 2:" -#define STR_ISAMEM_3 "Kartica 3:" -#define STR_ISAMEM_4 "Kartica 4:" +#define STR_ISAMEM_1 "Kartica 1:" +#define STR_ISAMEM_2 "Kartica 2:" +#define STR_ISAMEM_3 "Kartica 3:" +#define STR_ISAMEM_4 "Kartica 4:" #define STR_BUGGER "Uređaj ISABugger" -#define STR_POSTCARD "Kartica POST" +#define STR_POSTCARD "Kartica POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Greška" IDS_2050 "Fatalna greška" IDS_2051 " - PAUSED" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Sistem ""%hs"" nije dostupan jer ne postoje potrebni ROM-ovi u mapu roms/machines. Prebacivanje na dostupno računalo." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Video kartica ""%hs"" nije dostupna jer ne postoje potrebni ROM-ovi u mapu roms/video. Prebacivanje na dostupnu video karticu." IDS_2065 "Sistem" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Pritisnite F8+F12 ili srednji gumb miša za otpuštanje miša" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nije moguće inicijalizirati FluidSynth" IDS_2081 "Bus" IDS_2082 "Datoteka" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disketa %i (%s): %ls" IDS_2110 "Sve slike (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Napredne sektorske slike (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Osnovne sektorske slike (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux slike (*.FDI)\0*.FDI\0Površinske slike (*.86F;*.MFM)\0*.86F;*.MFM\0Sve datoteke (*.*)\0*.*\0" - IDS_2111 "Nije moguće inicijalizirati FreeType" IDS_2112 "Nije moguće inicijalizirati SDL, SDL2.dll je potrebno" IDS_2113 "Jeste li sigurni da želite hard resetirati emulirani sistem?" IDS_2114 "Jeste li sigurni da želite zatvoriti 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Provjerite je li " LIB_NAME_PCAP " instaliran i jeste li na mreži, kompadibilnoj s " LIB_NAME_PCAP "." IDS_2131 "Nevažeća konfiguracija" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " je potrebno za emuliranje ESC/P pisača." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " je potrebno za automatsku konverziju PostScript datoteke u PDF datoteke.\n\nSvi dokumenti poslani na generički PostScript pisač bit će spremljeni kao PostScript (.ps) datoteke." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " je potrebno za FluidSynth MIDI izlaz." IDS_2135 "Ulazim u cijelozaslonski način" IDS_2136 "Ne pokazi više ovu poruku" IDS_2137 "Ne izlazi" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Ponovno pokretanje" IDS_2160 "ACPI bazirano gašenje" IDS_2161 "Postavke" - IDS_2162 "Raniji pogon" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Tvrdi disk (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Zadana postavka operativnog sustava)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Croatian (hr-HR) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/hu-HU.rc b/src/win/languages/hu-HU.rc index ce380dfb4..aa7e06eff 100644 --- a/src/win/languages/hu-HU.rc +++ b/src/win/languages/hu-HU.rc @@ -18,122 +18,122 @@ LANGUAGE LANG_HUNGARIAN, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Művelet" BEGIN - MENUITEM "A &billentyűzet elfogást igényel", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "A &jobb oldali CTRL a bal ALT", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "A &billentyűzet elfogást igényel", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "A &jobb oldali CTRL a bal ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "Hardveres &újraindítás...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "Hardveres &újraindítás...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Szüneteltetés", IDM_ACTION_PAUSE + MENUITEM "&Szüneteltetés", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Kilépés...", IDM_ACTION_EXIT + MENUITEM "&Kilépés...", IDM_ACTION_EXIT END POPUP "&Nézet" BEGIN - MENUITEM "Állapotsor &elrejtése", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "Állapotsor &elrejtése", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Átméretezhető ablak", IDM_VID_RESIZE - MENUITEM "Méret és pozíció &megjegyzése", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Átméretezhető ablak", IDM_VID_RESIZE + MENUITEM "Méret és pozíció &megjegyzése", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Megjelenítő" BEGIN - MENUITEM "&SDL (Szoftveres)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardveres)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Szoftveres)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardveres)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Méretek kézi megadása...", IDM_VID_SPECIFY_DIM - MENUITEM "&Rögzített 4:3 képarány", IDM_VID_FORCE43 + MENUITEM "Méretek kézi megadása...", IDM_VID_SPECIFY_DIM + MENUITEM "&Rögzített 4:3 képarány", IDM_VID_FORCE43 POPUP "&Ablak méretezési tényező" BEGIN - MENUITEM "&0,5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1,&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0,5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1,&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Szűrési mód" BEGIN - MENUITEM "&Szomszédos", IDM_VID_FILTER_NEAREST - MENUITEM "&Lineáris", IDM_VID_FILTER_LINEAR + MENUITEM "&Szomszédos", IDM_VID_FILTER_NEAREST + MENUITEM "&Lineáris", IDM_VID_FILTER_LINEAR END - MENUITEM "Hi&DPI méretezés", IDM_VID_HIDPI + MENUITEM "Hi&DPI méretezés", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Teljes képernyő\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Teljes képernyő\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Teljes képernyős &méretezés" BEGIN - MENUITEM "&Nyújtás a teljes képernyőre", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Nyújtás a teljes képernyőre", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Négyzetes képpontok (aránytartás)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Egész tényezős nagyítás", IDM_VID_FS_INT + MENUITEM "&Egész tényezős nagyítás", IDM_VID_FS_INT END POPUP "E&GA/(S)VGA beállítások" BEGIN - MENUITEM "&Invertált VGA kijelző", IDM_VID_INVERT + MENUITEM "&Invertált VGA kijelző", IDM_VID_INVERT POPUP "VGA képernyő &típusa" BEGIN - MENUITEM "RGB &színes", IDM_VID_GRAY_RGB - MENUITEM "&RGB szürkeárnyalatos", IDM_VID_GRAY_MONO - MENUITEM "&Gyömbér kijelző", IDM_VID_GRAY_AMBER - MENUITEM "&Zöld kijelző", IDM_VID_GRAY_GREEN - MENUITEM "&Fehér kijelző", IDM_VID_GRAY_WHITE + MENUITEM "RGB &színes", IDM_VID_GRAY_RGB + MENUITEM "&RGB szürkeárnyalatos", IDM_VID_GRAY_MONO + MENUITEM "&Gyömbér kijelző", IDM_VID_GRAY_AMBER + MENUITEM "&Zöld kijelző", IDM_VID_GRAY_GREEN + MENUITEM "&Fehér kijelző", IDM_VID_GRAY_WHITE END POPUP "Szürkéskála &konzerziós eljárás" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Átlag szerint", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Átlag szerint", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA túlpásztázás", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA túlpásztázás", IDM_VID_OVERSCAN MENUITEM "Kontraszt illesztése &monokróm kijelzőhöz", IDM_VID_CGACON END - MENUITEM "&Média", IDM_MEDIA + MENUITEM "&Média", IDM_MEDIA POPUP "&Eszközök" BEGIN - MENUITEM "&Konfigurálás...", IDM_CONFIG - MENUITEM "Állapotsori ikonok &frissítése", IDM_UPDATE_ICONS + MENUITEM "&Konfigurálás...", IDM_CONFIG + MENUITEM "Állapotsori ikonok &frissítése", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "&Képernyőkép készítése\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "&Képernyőkép készítése\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Beállítások...", IDM_PREFERENCES + MENUITEM "&Beállítások...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "&Discord integráció engedélyezése", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Hangerőszabályzó...", IDM_SND_GAIN + MENUITEM "&Hangerőszabályzó...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Nyomkövetés megkezdése\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Nyomkövetés befejezése\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Nyomkövetés megkezdése\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Nyomkövetés befejezése\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Súgó" BEGIN - MENUITEM "&Dokumentáció...", IDM_DOCS - MENUITEM "A 86Box &névjegye...", IDM_ABOUT + MENUITEM "&Dokumentáció...", IDM_DOCS + MENUITEM "A 86Box &névjegye...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -142,17 +142,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Új képfájl létrehozása...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Új képfájl létrehozása...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Meglévő képfájl &megnyitása...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "Meglévő képfájl &megnyitása...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Felvétel", IDM_CASSETTE_RECORD - MENUITEM "&Lejátszás", IDM_CASSETTE_PLAY - MENUITEM "&Visszatekerés az elejére", IDM_CASSETTE_REWIND - MENUITEM "&Előretekerés a végére", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Felvétel", IDM_CASSETTE_RECORD + MENUITEM "&Lejátszás", IDM_CASSETTE_PLAY + MENUITEM "&Visszatekerés az elejére", IDM_CASSETTE_REWIND + MENUITEM "&Előretekerés a végére", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "&Kiadás", IDM_CASSETTE_EJECT + MENUITEM "&Kiadás", IDM_CASSETTE_EJECT END END @@ -160,9 +160,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "Kép&fájl...", IDM_CARTRIDGE_IMAGE + MENUITEM "Kép&fájl...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "&Kiadás", IDM_CARTRIDGE_EJECT + MENUITEM "&Kiadás", IDM_CARTRIDGE_EJECT END END @@ -170,14 +170,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Új képfájl létrehozása...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Új képfájl létrehozása...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Meglévő képfájl &megnyitása...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "Meglévő képfájl &megnyitása...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xportálás 86F formátumba...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&xportálás 86F formátumba...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "&Kiadás", IDM_FLOPPY_EJECT + MENUITEM "&Kiadás", IDM_FLOPPY_EJECT END END @@ -185,13 +185,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Némítás", IDM_CDROM_MUTE + MENUITEM "&Némítás", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&Kiadás", IDM_CDROM_EMPTY - MENUITEM "Előző képfájl &újratöltése", IDM_CDROM_RELOAD + MENUITEM "&Kiadás", IDM_CDROM_EMPTY + MENUITEM "Előző képfájl &újratöltése", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Meglévő képfájl &megnyitása...", IDM_CDROM_IMAGE - MENUITEM "&Mappa...", IDM_CDROM_DIR + MENUITEM "&Meglévő képfájl &megnyitása...", IDM_CDROM_IMAGE + MENUITEM "&Mappa...", IDM_CDROM_DIR END END @@ -199,13 +199,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Új képfájl létrehozása...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Új képfájl létrehozása...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Meglévő képfájl &megnyitása...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Meglévő képfájl &megnyitása...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "Kiadás", IDM_ZIP_EJECT - MENUITEM "Előző képfájl &újratöltése", IDM_ZIP_RELOAD + MENUITEM "Kiadás", IDM_ZIP_EJECT + MENUITEM "Előző képfájl &újratöltése", IDM_ZIP_RELOAD END END @@ -213,13 +213,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Új képfájl létrehozása...", IDM_MO_IMAGE_NEW + MENUITEM "&Új képfájl létrehozása...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Meglévő képfájl &megnyitása...", IDM_MO_IMAGE_EXISTING - MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Meglévő képfájl &megnyitása...", IDM_MO_IMAGE_EXISTING + MENUITEM "Meglévő képfájl megnyitása (&írásvédett)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "Kiadás", IDM_MO_EJECT - MENUITEM "Előző képfájl &újratöltése", IDM_MO_RELOAD + MENUITEM "Kiadás", IDM_MO_EJECT + MENUITEM "Előző képfájl &újratöltése", IDM_MO_RELOAD END END @@ -245,150 +245,150 @@ END // Dialog // -#define STR_PREFERENCES "Beállítások" -#define STR_SND_GAIN "Hangerőszabályzó" -#define STR_NEW_FLOPPY "Új képfájl létrehozása" +#define STR_PREFERENCES "Beállítások" +#define STR_SND_GAIN "Hangerőszabályzó" +#define STR_NEW_FLOPPY "Új képfájl létrehozása" #define STR_CONFIG "Konfigurálás" -#define STR_SPECIFY_DIM "Főablak méreteinek megadása" +#define STR_SPECIFY_DIM "Főablak méreteinek megadása" #define STR_OK "OK" #define STR_CANCEL "Mégse" #define STR_GLOBAL "Beállítások mentése &globális alapértékként" -#define STR_DEFAULT "&Alapértelmezett" -#define STR_LANGUAGE "Nyelv:" -#define STR_ICONSET "Ikonkészlet:" +#define STR_DEFAULT "&Alapértelmezett" +#define STR_LANGUAGE "Nyelv:" +#define STR_ICONSET "Ikonkészlet:" -#define STR_GAIN "Hangerő" +#define STR_GAIN "Hangerő" -#define STR_FILE_NAME "Fájlnév:" -#define STR_DISK_SIZE "Méret:" -#define STR_RPM_MODE "RPM-mód:" -#define STR_PROGRESS "Folyamat:" +#define STR_FILE_NAME "Fájlnév:" +#define STR_DISK_SIZE "Méret:" +#define STR_RPM_MODE "RPM-mód:" +#define STR_PROGRESS "Folyamat:" -#define STR_WIDTH "Szélesség:" +#define STR_WIDTH "Szélesség:" #define STR_HEIGHT "Magasság:" -#define STR_LOCK_TO_SIZE "Rögzítés a megadott méretre" +#define STR_LOCK_TO_SIZE "Rögzítés a megadott méretre" -#define STR_MACHINE_TYPE "Géptípus:" -#define STR_MACHINE "Számítógép:" -#define STR_CONFIGURE "Beállítások..." -#define STR_CPU_TYPE "Processzor:" -#define STR_CPU_SPEED "Seb.:" -#define STR_FPU "FPU-egység:" -#define STR_WAIT_STATES "Várak. ciklusok:" +#define STR_MACHINE_TYPE "Géptípus:" +#define STR_MACHINE "Számítógép:" +#define STR_CONFIGURE "Beállítások..." +#define STR_CPU_TYPE "Processzor:" +#define STR_CPU_SPEED "Seb.:" +#define STR_FPU "FPU-egység:" +#define STR_WAIT_STATES "Várak. ciklusok:" #define STR_MB "MB" #define STR_MEMORY "Memória:" -#define STR_TIME_SYNC "Idő szinkronizáció" -#define STR_DISABLED "Letiltva" -#define STR_ENABLED_LOCAL "Engedélyezve (helyi idő)" -#define STR_ENABLED_UTC "Engedélyezve (UTC)" -#define STR_DYNAREC "Dinamikus újrafordítás" +#define STR_TIME_SYNC "Idő szinkronizáció" +#define STR_DISABLED "Letiltva" +#define STR_ENABLED_LOCAL "Engedélyezve (helyi idő)" +#define STR_ENABLED_UTC "Engedélyezve (UTC)" +#define STR_DYNAREC "Dinamikus újrafordítás" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Videokártya:" -#define STR_VIDEO_2 "Videokártya 2:" +#define STR_VIDEO "Videokártya:" +#define STR_VIDEO_2 "Videokártya 2:" #define STR_VOODOO "Voodoo-gyorsítókártya" -#define STR_IBM8514 "IBM 8514/a-gyorsítókártya" -#define STR_XGA "XGA-gyorsítókártya" +#define STR_IBM8514 "IBM 8514/a-gyorsítókártya" +#define STR_XGA "XGA-gyorsítókártya" -#define STR_MOUSE "Egér:" -#define STR_JOYSTICK "Játékvezérlő:" -#define STR_JOY1 "Játékvez. 1..." -#define STR_JOY2 "Játékvez. 2..." -#define STR_JOY3 "Játékvez. 3..." -#define STR_JOY4 "Játékvez. 4..." +#define STR_MOUSE "Egér:" +#define STR_JOYSTICK "Játékvezérlő:" +#define STR_JOY1 "Játékvez. 1..." +#define STR_JOY2 "Játékvez. 2..." +#define STR_JOY3 "Játékvez. 3..." +#define STR_JOY4 "Játékvez. 4..." #define STR_SOUND1 "Hangkártya 1:" #define STR_SOUND2 "Hangkártya 2:" #define STR_SOUND3 "Hangkártya 3:" #define STR_SOUND4 "Hangkártya 4:" -#define STR_MIDI_OUT "MIDI-kimenet:" -#define STR_MIDI_IN "MIDI-bemenet:" +#define STR_MIDI_OUT "MIDI-kimenet:" +#define STR_MIDI_IN "MIDI-bemenet:" #define STR_MPU401 "Különálló MPU-401" -#define STR_FLOAT "FLOAT32 használata" -#define STR_FM_DRIVER "FM szintetizátor meghajtó" -#define STR_FM_DRV_NUKED "Nuked (pontosabb)" -#define STR_FM_DRV_YMFM "YMFM (gyorsabb)" +#define STR_FLOAT "FLOAT32 használata" +#define STR_FM_DRIVER "FM szintetizátor meghajtó" +#define STR_FM_DRV_NUKED "Nuked (pontosabb)" +#define STR_FM_DRV_YMFM "YMFM (gyorsabb)" -#define STR_NET_TYPE "Hálózati típusa:" -#define STR_PCAP "PCap eszköz:" -#define STR_NET "Hálózati kártya:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Hálózati típusa:" +#define STR_PCAP "PCap eszköz:" +#define STR_NET "Hálózati kártya:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "COM1 eszköz:" -#define STR_COM2 "COM2 eszköz:" -#define STR_COM3 "COM3 eszköz:" -#define STR_COM4 "COM4 eszköz:" -#define STR_LPT1 "LPT1 eszköz:" -#define STR_LPT2 "LPT2 eszköz:" -#define STR_LPT3 "LPT3 eszköz:" -#define STR_LPT4 "LPT4 eszköz:" -#define STR_SERIAL1 "Soros port 1" -#define STR_SERIAL2 "Soros port 2" -#define STR_SERIAL3 "Soros port 3" -#define STR_SERIAL4 "Soros port 4" -#define STR_PARALLEL1 "Párhuzamos port 1" -#define STR_PARALLEL2 "Párhuzamos port 2" -#define STR_PARALLEL3 "Párhuzamos port 3" -#define STR_PARALLEL4 "Párhuzamos port 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1 eszköz:" +#define STR_COM2 "COM2 eszköz:" +#define STR_COM3 "COM3 eszköz:" +#define STR_COM4 "COM4 eszköz:" +#define STR_LPT1 "LPT1 eszköz:" +#define STR_LPT2 "LPT2 eszköz:" +#define STR_LPT3 "LPT3 eszköz:" +#define STR_LPT4 "LPT4 eszköz:" +#define STR_SERIAL1 "Soros port 1" +#define STR_SERIAL2 "Soros port 2" +#define STR_SERIAL3 "Soros port 3" +#define STR_SERIAL4 "Soros port 4" +#define STR_PARALLEL1 "Párhuzamos port 1" +#define STR_PARALLEL2 "Párhuzamos port 2" +#define STR_PARALLEL3 "Párhuzamos port 3" +#define STR_PARALLEL4 "Párhuzamos port 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Merevl.-vezérlő:" -#define STR_FDC "Floppy-vezérlő:" -#define STR_IDE_TER "Harmadlagos IDE-vezérlő" -#define STR_IDE_QUA "Negyedleges IDE-vezérlő" -#define STR_SCSI "SCSI" +#define STR_HDC "Merevl.-vezérlő:" +#define STR_FDC "Floppy-vezérlő:" +#define STR_IDE_TER "Harmadlagos IDE-vezérlő" +#define STR_IDE_QUA "Negyedleges IDE-vezérlő" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Gazdaadapt. 1:" #define STR_SCSI_2 "Gazdaadapt. 2:" #define STR_SCSI_3 "Gazdaadapt. 3:" #define STR_SCSI_4 "Gazdaadapt. 4:" -#define STR_CASSETTE "Magnókazetta" +#define STR_CASSETTE "Magnókazetta" -#define STR_HDD "Merevlemezek:" -#define STR_NEW "&Új..." -#define STR_EXISTING "&Megnyitás..." +#define STR_HDD "Merevlemezek:" +#define STR_NEW "&Új..." +#define STR_EXISTING "&Megnyitás..." #define STR_REMOVE "&Eltávolítás" -#define STR_BUS "Busz:" -#define STR_CHANNEL "Csatorna:" +#define STR_BUS "Busz:" +#define STR_CHANNEL "Csatorna:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Kiválasztás..." -#define STR_SECTORS "Szektor:" -#define STR_HEADS "Fej:" -#define STR_CYLS "Cilinder:" -#define STR_SIZE_MB "Méret (MB):" -#define STR_TYPE "Típus:" -#define STR_IMG_FORMAT "Formátum:" -#define STR_BLOCK_SIZE "Blokkméret:" +#define STR_SPECIFY "&Kiválasztás..." +#define STR_SECTORS "Szektor:" +#define STR_HEADS "Fej:" +#define STR_CYLS "Cilinder:" +#define STR_SIZE_MB "Méret (MB):" +#define STR_TYPE "Típus:" +#define STR_IMG_FORMAT "Formátum:" +#define STR_BLOCK_SIZE "Blokkméret:" -#define STR_FLOPPY_DRIVES "Floppy-meghajtók:" -#define STR_TURBO "Turbó időzítés" -#define STR_CHECKBPB "BPB ellenőrzés" -#define STR_CDROM_DRIVES "CD-ROM meghajtók:" -#define STR_CD_SPEED "Seb.:" -#define STR_EARLY "Korábbi meghajtó" +#define STR_FLOPPY_DRIVES "Floppy-meghajtók:" +#define STR_TURBO "Turbó időzítés" +#define STR_CHECKBPB "BPB ellenőrzés" +#define STR_CDROM_DRIVES "CD-ROM meghajtók:" +#define STR_CD_SPEED "Seb.:" -#define STR_MO_DRIVES "MO-meghajtók:" -#define STR_ZIP_DRIVES "ZIP-meghajtók:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "MO-meghajtók:" +#define STR_ZIP_DRIVES "ZIP-meghajtók:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC (óra):" #define STR_ISAMEM "ISA memóriabővítők" -#define STR_ISAMEM_1 "Kártya 1:" -#define STR_ISAMEM_2 "Kártya 2:" -#define STR_ISAMEM_3 "Kártya 3:" -#define STR_ISAMEM_4 "Kártya 4:" +#define STR_ISAMEM_1 "Kártya 1:" +#define STR_ISAMEM_2 "Kártya 2:" +#define STR_ISAMEM_3 "Kártya 3:" +#define STR_ISAMEM_4 "Kártya 4:" #define STR_BUGGER "ISABugger eszköz" -#define STR_POSTCARD "POST kártya" +#define STR_POSTCARD "POST kártya" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -397,9 +397,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Hiba" IDS_2050 "Végzetes hiba" IDS_2051 " - PAUSED" @@ -417,7 +417,7 @@ BEGIN IDS_2063 "A számítógép ""%hs"" nem elérhető a ""roms/machines"" mappából hiányzó ROM-képek miatt. Ehelyett egy másik gép kerül futtatásra." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "A videokártya ""%hs"" nem elérhető a ""roms/video"" mappából hiányzó ROM-képek miatt. Ehelyett egy másik kártya kerül futtatásra." IDS_2065 "Számítógép" @@ -437,9 +437,8 @@ BEGIN IDS_2079 "Nyomja meg az F8+F12-t vagy a középső gombot az egér elengédéséhez" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nem sikerült a FluidSynth inicializálása" IDS_2081 "Busz" IDS_2082 "Fájl" IDS_2083 "C" @@ -470,7 +469,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "Minden képfájl (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Továbbfejlesztett szektor képek (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Alapvető szektor képek (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux képekfájlok (*.FDI)\0*.FDI\0Felületi képfájlok (*.86F;*.MFM)\0*.86F;*.MFM\0Minden fájl (*.*)\0*.*\0" - IDS_2111 "A FreeType inicializálása nem lehetséges" IDS_2112 "Az SDL inicializálása nem lehetséges, az SDL2.dll fájl szükséges" IDS_2113 "Biztosan szeretné újraindítani az emulált gépet?" IDS_2114 "Biztos benne, hogy ki szeretne lépni a 86Box-ból?" @@ -497,23 +495,11 @@ BEGIN IDS_2130 "Győződjön meg hogy a(z) " LIB_NAME_PCAP " telepítve van és jelenleg a " LIB_NAME_PCAP "-kompatibilis kapcsolatot használja." IDS_2131 "Érvénytelen konfiguráció" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " szükséges az ESC/P nyomtató emulációhoz." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " szükséges a PostScript fájlok PDF formátumba való automatikus konvertálásához.\n\nAz általános PostScript nyomtatóra küldött dokumentumok PostScript (.ps) fájlként kerülnek mentésre." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " szükséges a FluidSynth MIDI kimenethez." IDS_2135 "Teljes képernyős módra váltás" IDS_2136 "Ne jelenítse meg újra ezt az üzenetet " IDS_2137 "Ne lépjen ki" @@ -541,14 +527,16 @@ BEGIN IDS_2159 "Hard reset" IDS_2160 "ACPI shutdown" IDS_2161 "Settings" - IDS_2162 "Korábbi meghajtó" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Merevlemez (%s)" IDS_4097 "%01i:%01i" @@ -647,7 +635,7 @@ BEGIN IDS_7168 "(A rendszer nyelve)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Hungarian resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/it-IT.rc b/src/win/languages/it-IT.rc index ce2d23262..f546fc1d4 100644 --- a/src/win/languages/it-IT.rc +++ b/src/win/languages/it-IT.rc @@ -14,122 +14,122 @@ LANGUAGE LANG_ITALIAN, SUBLANG_ITALIAN // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Azione" BEGIN - MENUITEM "&Tastiera richiede la cattura", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&CTRL destro è ALT sinistro", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Tastiera richiede la cattura", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&CTRL destro è ALT sinistro", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Riavvia...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Riavvia...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pausa", IDM_ACTION_PAUSE + MENUITEM "&Pausa", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "E&sci...", IDM_ACTION_EXIT + MENUITEM "E&sci...", IDM_ACTION_EXIT END POPUP "&Visualizza" BEGIN - MENUITEM "&Nascondi barra di stato", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Nascondi barra di stato", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Finestra ridimensionabile", IDM_VID_RESIZE - MENUITEM "R&icorda dimensioni e posizione", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Finestra ridimensionabile", IDM_VID_RESIZE + MENUITEM "R&icorda dimensioni e posizione", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "Re&nderer" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Specifica dimensioni...", IDM_VID_SPECIFY_DIM - MENUITEM "F&orza display 4:3", IDM_VID_FORCE43 + MENUITEM "Specifica dimensioni...", IDM_VID_SPECIFY_DIM + MENUITEM "F&orza display 4:3", IDM_VID_FORCE43 POPUP "&Fattore scalare della finestra" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Metodo filtro" BEGIN - MENUITEM "&Dal più vicino", IDM_VID_FILTER_NEAREST - MENUITEM "&Lineare", IDM_VID_FILTER_LINEAR + MENUITEM "&Dal più vicino", IDM_VID_FILTER_NEAREST + MENUITEM "&Lineare", IDM_VID_FILTER_LINEAR END - MENUITEM "Scala Hi&DPI", IDM_VID_HIDPI + MENUITEM "Scala Hi&DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Schermo intero\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Schermo intero\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Modalità adattamento &schermo intero" BEGIN - MENUITEM "&Adatta a schermo intero", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Adatta a schermo intero", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Pixel quadrati (mantiene l'aspetto)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Scala intera", IDM_VID_FS_INT + MENUITEM "&Scala intera", IDM_VID_FS_INT END POPUP "Impostazioni E&GA/(S)VGA" BEGIN - MENUITEM "&Invertire monitor VGA", IDM_VID_INVERT + MENUITEM "&Invertire monitor VGA", IDM_VID_INVERT POPUP "Schermi VGA &" BEGIN - MENUITEM "RGB &Color", IDM_VID_GRAY_RGB - MENUITEM "&RGB Monocroma", IDM_VID_GRAY_MONO - MENUITEM "&Monitor ambra", IDM_VID_GRAY_AMBER - MENUITEM "&Monitor verde", IDM_VID_GRAY_GREEN - MENUITEM "&Monitor bianco", IDM_VID_GRAY_WHITE + MENUITEM "RGB &Color", IDM_VID_GRAY_RGB + MENUITEM "&RGB Monocroma", IDM_VID_GRAY_MONO + MENUITEM "&Monitor ambra", IDM_VID_GRAY_AMBER + MENUITEM "&Monitor verde", IDM_VID_GRAY_GREEN + MENUITEM "&Monitor bianco", IDM_VID_GRAY_WHITE END POPUP "Conversione &scala grigia" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&AMedia", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&AMedia", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "Sovrascansione CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "Sovrascansione CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "Cambia il contrasto per &display monocromatici", IDM_VID_CGACON END - MENUITEM "&Dispositivi", IDM_MEDIA + MENUITEM "&Dispositivi", IDM_MEDIA POPUP "&Strumenti" BEGIN - MENUITEM "&Impostazioni...", IDM_CONFIG - MENUITEM "&Aggiorna icone della barra di stato", IDM_UPDATE_ICONS + MENUITEM "&Impostazioni...", IDM_CONFIG + MENUITEM "&Aggiorna icone della barra di stato", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Cattura schermata\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Cattura schermata\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Preferenze...", IDM_PREFERENCES + MENUITEM "&Preferenze...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Abilita &integrazione Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "Guadagno &suono...", IDM_SND_GAIN + MENUITEM "Guadagno &suono...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Inizia traccia\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Ferma traccia\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Inizia traccia\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Ferma traccia\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&?" BEGIN - MENUITEM "&Documentazione...", IDM_DOCS - MENUITEM "&Informazioni su 86Box...", IDM_ABOUT + MENUITEM "&Documentazione...", IDM_DOCS + MENUITEM "&Informazioni su 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -138,17 +138,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nuova immagine...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nuova immagine...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Immagine esistente...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Immagine esistente...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Registra", IDM_CASSETTE_RECORD - MENUITEM "R&iproduci", IDM_CASSETTE_PLAY - MENUITEM "Ri&avvolgi all'inizio", IDM_CASSETTE_REWIND - MENUITEM "A&vanti veloce alla fine", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Registra", IDM_CASSETTE_RECORD + MENUITEM "R&iproduci", IDM_CASSETTE_PLAY + MENUITEM "Ri&avvolgi all'inizio", IDM_CASSETTE_REWIND + MENUITEM "A&vanti veloce alla fine", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "&Espelli", IDM_CASSETTE_EJECT + MENUITEM "&Espelli", IDM_CASSETTE_EJECT END END @@ -156,9 +156,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Immagine...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Immagine...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "&Espelli", IDM_CARTRIDGE_EJECT + MENUITEM "&Espelli", IDM_CARTRIDGE_EJECT END END @@ -166,14 +166,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nuova immagine...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nuova immagine...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Immagine esistente...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Immagine esistente...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&sporta in 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&sporta in 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "&Espelli", IDM_FLOPPY_EJECT + MENUITEM "&Espelli", IDM_FLOPPY_EJECT END END @@ -181,13 +181,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Muto", IDM_CDROM_MUTE + MENUITEM "&Muto", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&Espelli", IDM_CDROM_EMPTY - MENUITEM "&Ricarica l'immagine precedente", IDM_CDROM_RELOAD + MENUITEM "&Espelli", IDM_CDROM_EMPTY + MENUITEM "&Ricarica l'immagine precedente", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Immagine...", IDM_CDROM_IMAGE - MENUITEM "&Cartella...", IDM_CDROM_DIR + MENUITEM "&Immagine...", IDM_CDROM_IMAGE + MENUITEM "&Cartella...", IDM_CDROM_DIR END END @@ -195,13 +195,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nuova immagine...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nuova immagine...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Immagine esistente...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Immagine esistente...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Espelli", IDM_ZIP_EJECT - MENUITEM "&Ricarica l'immagine precedente", IDM_ZIP_RELOAD + MENUITEM "&Espelli", IDM_ZIP_EJECT + MENUITEM "&Ricarica l'immagine precedente", IDM_ZIP_RELOAD END END @@ -209,13 +209,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nuova immagine...", IDM_MO_IMAGE_NEW + MENUITEM "&Nuova immagine...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Immagine esistente...", IDM_MO_IMAGE_EXISTING - MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Immagine esistente...", IDM_MO_IMAGE_EXISTING + MENUITEM "Immagine esistente (&protezione contro scrittura)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Espelli", IDM_MO_EJECT - MENUITEM "&Ricarica l'immagine precedente", IDM_MO_RELOAD + MENUITEM "&Espelli", IDM_MO_EJECT + MENUITEM "&Ricarica l'immagine precedente", IDM_MO_RELOAD END END @@ -241,150 +241,150 @@ END // Dialog // -#define STR_PREFERENCES "Preferenze" -#define STR_SND_GAIN "Guadagno del suono" -#define STR_NEW_FLOPPY "Nuova immagine" +#define STR_PREFERENCES "Preferenze" +#define STR_SND_GAIN "Guadagno del suono" +#define STR_NEW_FLOPPY "Nuova immagine" #define STR_CONFIG "Impostazioni" -#define STR_SPECIFY_DIM "Specifica dimensioni della finestra principale" +#define STR_SPECIFY_DIM "Specifica dimensioni della finestra principale" #define STR_OK "OK" #define STR_CANCEL "Annulla" #define STR_GLOBAL "Salva queste impostazioni come &predefinite globali" -#define STR_DEFAULT "&Predefinito" -#define STR_LANGUAGE "Lingua:" -#define STR_ICONSET "Pacchetto di icone:" +#define STR_DEFAULT "&Predefinito" +#define STR_LANGUAGE "Lingua:" +#define STR_ICONSET "Pacchetto di icone:" -#define STR_GAIN "Guadagno" +#define STR_GAIN "Guadagno" -#define STR_FILE_NAME "Nome file:" -#define STR_DISK_SIZE "Dimensioni disco:" -#define STR_RPM_MODE "Modalità RPM:" -#define STR_PROGRESS "Progresso:" +#define STR_FILE_NAME "Nome file:" +#define STR_DISK_SIZE "Dimensioni disco:" +#define STR_RPM_MODE "Modalità RPM:" +#define STR_PROGRESS "Progresso:" -#define STR_WIDTH "Larghezza:" +#define STR_WIDTH "Larghezza:" #define STR_HEIGHT "Altezza:" -#define STR_LOCK_TO_SIZE "Blocca in queste dimensioni" +#define STR_LOCK_TO_SIZE "Blocca in queste dimensioni" -#define STR_MACHINE_TYPE "Tipo di piastra madre:" -#define STR_MACHINE "Piastra madre:" -#define STR_CONFIGURE "Configura" -#define STR_CPU_TYPE "Tipo del CPU:" -#define STR_CPU_SPEED "Veloc.:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "Stati di attesa:" +#define STR_MACHINE_TYPE "Tipo di piastra madre:" +#define STR_MACHINE "Piastra madre:" +#define STR_CONFIGURE "Configura" +#define STR_CPU_TYPE "Tipo del CPU:" +#define STR_CPU_SPEED "Veloc.:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "Stati di attesa:" #define STR_MB "MB" #define STR_MEMORY "Memoria:" -#define STR_TIME_SYNC "Sincronizzazione dell'ora" -#define STR_DISABLED "Disabilitata" -#define STR_ENABLED_LOCAL "Abilitata (ora locale)" -#define STR_ENABLED_UTC "Abilitata (UTC)" -#define STR_DYNAREC "Ricompilatore dinamico" +#define STR_TIME_SYNC "Sincronizzazione dell'ora" +#define STR_DISABLED "Disabilitata" +#define STR_ENABLED_LOCAL "Abilitata (ora locale)" +#define STR_ENABLED_UTC "Abilitata (UTC)" +#define STR_DYNAREC "Ricompilatore dinamico" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Video:" -#define STR_VIDEO_2 "Video 2:" +#define STR_VIDEO "Video:" +#define STR_VIDEO_2 "Video 2:" #define STR_VOODOO "Grafica Voodoo" -#define STR_IBM8514 "Grafica IBM 8514/a" -#define STR_XGA "Grafica XGA" +#define STR_IBM8514 "Grafica IBM 8514/a" +#define STR_XGA "Grafica XGA" -#define STR_MOUSE "Mouse:" -#define STR_JOYSTICK "Joystick:" -#define STR_JOY1 "Joystick 1..." -#define STR_JOY2 "Joystick 2..." -#define STR_JOY3 "Joystick 3..." -#define STR_JOY4 "Joystick 4..." +#define STR_MOUSE "Mouse:" +#define STR_JOYSTICK "Joystick:" +#define STR_JOY1 "Joystick 1..." +#define STR_JOY2 "Joystick 2..." +#define STR_JOY3 "Joystick 3..." +#define STR_JOY4 "Joystick 4..." #define STR_SOUND1 "Scheda audio 1:" #define STR_SOUND2 "Scheda audio 2:" #define STR_SOUND3 "Scheda audio 3:" #define STR_SOUND4 "Scheda audio 4:" -#define STR_MIDI_OUT "Uscita MIDI:" -#define STR_MIDI_IN "Entrata MIDI:" +#define STR_MIDI_OUT "Uscita MIDI:" +#define STR_MIDI_IN "Entrata MIDI:" #define STR_MPU401 "MPU-401 autonomo" -#define STR_FLOAT "Usa suono FLOAT32" -#define STR_FM_DRIVER "Driver sint. FM" -#define STR_FM_DRV_NUKED "Nuked (più accurato)" -#define STR_FM_DRV_YMFM "YMFM (più veloce)" +#define STR_FLOAT "Usa suono FLOAT32" +#define STR_FM_DRIVER "Driver sint. FM" +#define STR_FM_DRV_NUKED "Nuked (più accurato)" +#define STR_FM_DRV_YMFM "YMFM (più veloce)" -#define STR_NET_TYPE "Tipo di rete:" -#define STR_PCAP "Dispositivo PCap:" -#define STR_NET "Scheda di rete:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Tipo di rete:" +#define STR_PCAP "Dispositivo PCap:" +#define STR_NET "Scheda di rete:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Dispositivo COM1:" -#define STR_COM2 "Dispositivo COM2:" -#define STR_COM3 "Dispositivo COM3:" -#define STR_COM4 "Dispositivo COM4:" -#define STR_LPT1 "Dispositivo LPT1:" -#define STR_LPT2 "Dispositivo LPT2:" -#define STR_LPT3 "Dispositivo LPT3:" -#define STR_LPT4 "Dispositivo LPT4:" -#define STR_SERIAL1 "Porta seriale 1" -#define STR_SERIAL2 "Porta seriale 2" -#define STR_SERIAL3 "Porta seriale 3" -#define STR_SERIAL4 "Porta seriale 4" -#define STR_PARALLEL1 "Porta parallela 1" -#define STR_PARALLEL2 "Porta parallela 2" -#define STR_PARALLEL3 "Porta parallela 3" -#define STR_PARALLEL4 "Porta parallela 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Dispositivo COM1:" +#define STR_COM2 "Dispositivo COM2:" +#define STR_COM3 "Dispositivo COM3:" +#define STR_COM4 "Dispositivo COM4:" +#define STR_LPT1 "Dispositivo LPT1:" +#define STR_LPT2 "Dispositivo LPT2:" +#define STR_LPT3 "Dispositivo LPT3:" +#define STR_LPT4 "Dispositivo LPT4:" +#define STR_SERIAL1 "Porta seriale 1" +#define STR_SERIAL2 "Porta seriale 2" +#define STR_SERIAL3 "Porta seriale 3" +#define STR_SERIAL4 "Porta seriale 4" +#define STR_PARALLEL1 "Porta parallela 1" +#define STR_PARALLEL2 "Porta parallela 2" +#define STR_PARALLEL3 "Porta parallela 3" +#define STR_PARALLEL4 "Porta parallela 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Controller HD:" -#define STR_FDC "Controller FD:" -#define STR_IDE_TER "Controller IDE terziario" -#define STR_IDE_QUA "Controller IDE quaternario" -#define STR_SCSI "SCSI" +#define STR_HDC "Controller HD:" +#define STR_FDC "Controller FD:" +#define STR_IDE_TER "Controller IDE terziario" +#define STR_IDE_QUA "Controller IDE quaternario" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Controller 1:" #define STR_SCSI_2 "Controller 2:" #define STR_SCSI_3 "Controller 3:" #define STR_SCSI_4 "Controller 4:" -#define STR_CASSETTE "Cassetta" +#define STR_CASSETTE "Cassetta" -#define STR_HDD "Hard disk:" -#define STR_NEW "&Nuovo..." -#define STR_EXISTING "&Esistente..." +#define STR_HDD "Hard disk:" +#define STR_NEW "&Nuovo..." +#define STR_EXISTING "&Esistente..." #define STR_REMOVE "&Rimouvi" -#define STR_BUS "Bus:" -#define STR_CHANNEL "Canale:" +#define STR_BUS "Bus:" +#define STR_CHANNEL "Canale:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Specifica..." -#define STR_SECTORS "Settori:" -#define STR_HEADS "Testine:" -#define STR_CYLS "Cilindri:" -#define STR_SIZE_MB "Dimensioni (MB):" -#define STR_TYPE "Tipo:" -#define STR_IMG_FORMAT "Formato immagine:" -#define STR_BLOCK_SIZE "Dimensioni blocco:" +#define STR_SPECIFY "&Specifica..." +#define STR_SECTORS "Settori:" +#define STR_HEADS "Testine:" +#define STR_CYLS "Cilindri:" +#define STR_SIZE_MB "Dimensioni (MB):" +#define STR_TYPE "Tipo:" +#define STR_IMG_FORMAT "Formato immagine:" +#define STR_BLOCK_SIZE "Dimensioni blocco:" -#define STR_FLOPPY_DRIVES "Unità floppy:" -#define STR_TURBO "Turbo" -#define STR_CHECKBPB "Verifica BPB" -#define STR_CDROM_DRIVES "Unità CD-ROM:" -#define STR_CD_SPEED "Veloc.:" -#define STR_EARLY "Unità anteriore" +#define STR_FLOPPY_DRIVES "Unità floppy:" +#define STR_TURBO "Turbo" +#define STR_CHECKBPB "Verifica BPB" +#define STR_CDROM_DRIVES "Unità CD-ROM:" +#define STR_CD_SPEED "Veloc.:" -#define STR_MO_DRIVES "Unità magneto-ottiche:" -#define STR_ZIP_DRIVES "Unità ZIP:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Unità magneto-ottiche:" +#define STR_ZIP_DRIVES "Unità ZIP:" +#define STR_250 "ZIP 250" #define STR_ISARTC "RTC ISA:" #define STR_ISAMEM "Espansione memoria ISA" -#define STR_ISAMEM_1 "Scheda 1:" -#define STR_ISAMEM_2 "Scheda 2:" -#define STR_ISAMEM_3 "Scheda 3:" -#define STR_ISAMEM_4 "Scheda 4:" +#define STR_ISAMEM_1 "Scheda 1:" +#define STR_ISAMEM_2 "Scheda 2:" +#define STR_ISAMEM_3 "Scheda 3:" +#define STR_ISAMEM_4 "Scheda 4:" #define STR_BUGGER "Dispositivo ISABugger" -#define STR_POSTCARD "Scheda POST" +#define STR_POSTCARD "Scheda POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -393,9 +393,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Errore" IDS_2050 "Errore fatale" IDS_2051 " - PAUSED" @@ -413,7 +413,7 @@ BEGIN IDS_2063 "La macchina ""%hs"" non è disponibile a causa di immagini ROM mancanti nella directory roms/machines. Cambiando ad una macchina disponibile." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "La scheda video ""%hs"" non è disponibile a causa di immagini ROM mancanti nella directory roms/video. Cambiando ad una scheda video disponibile." IDS_2065 "Piastra madre" @@ -433,9 +433,8 @@ BEGIN IDS_2079 "Premi F8+F12 o pulsante centrale per rilasciare il mouse" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Impossibile inizializzare FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -466,7 +465,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "Tutte le immagini (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Immagini da settori avanzati (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Imagini da settori basilari (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Immagini flusso (*.FDI)\0*.FDI\0Immagini da superficie (*.86F;*.MFM)\0*.86F;*.MFM\0Tutti i file (*.*)\0*.*\0" - IDS_2111 "Impossibile inizializzare FreeType" IDS_2112 "Impossibile inizializzare SDL, SDL2.dll è necessario" IDS_2113 "Sei sicuro di voler riavviare la macchina emulata?" IDS_2114 "Sei sicuro di voler uscire da 86Box?" @@ -494,23 +492,11 @@ BEGIN IDS_2130 "Controlla se " LIB_NAME_PCAP " è installato e che tu sia connesso ad una connessione " LIB_NAME_PCAP " compatibile." IDS_2131 "Configurazione invalida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " è richesto per l'emuazione di stampanti ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " è richiesto per la conversione automatica di file PostScript a file PDF.\n\nQualsiasi documento mandato alla stampante generica PostScript sarà salvato come file PostScript. (.ps)" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " è richiesto per l'output FluidSynth MIDI." IDS_2135 "Entrando nella modalità schermo intero" IDS_2136 "Non mostrare più questo messaggio" IDS_2137 "Non uscire" @@ -538,14 +524,16 @@ BEGIN IDS_2159 "Hard reset" IDS_2160 "ACPI shutdown" IDS_2161 "Settings" - IDS_2162 "Unità anteriore" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Hard disk (%s)" IDS_4097 "%01i:%01i" @@ -644,7 +632,7 @@ BEGIN IDS_7168 "(Predefinito del sistema)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Italian (IT-it) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/ja-JP.rc b/src/win/languages/ja-JP.rc index 16a54a822..fb5106134 100644 --- a/src/win/languages/ja-JP.rc +++ b/src/win/languages/ja-JP.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "動作(&A)" BEGIN - MENUITEM "キーボードはキャプチャが必要(&K)", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "右CTRLを左ALTへ(&R)", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "キーボードはキャプチャが必要(&K)", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "右CTRLを左ALTへ(&R)", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "ハードリセット(&H)...", IDM_ACTION_HRESET - MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "ハードリセット(&H)...", IDM_ACTION_HRESET + MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "一時停止(&P)", IDM_ACTION_PAUSE + MENUITEM "一時停止(&P)", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "終了(&X)...", IDM_ACTION_EXIT + MENUITEM "終了(&X)...", IDM_ACTION_EXIT END POPUP "表示(&V)" BEGIN - MENUITEM "ステータスバーを隠す(&H)", IDM_VID_HIDE_STATUS_BAR - MENUITEM "ツールバーを隠す(&T)", IDM_VID_HIDE_TOOLBAR + MENUITEM "ステータスバーを隠す(&H)", IDM_VID_HIDE_STATUS_BAR + MENUITEM "ツールバーを隠す(&T)", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "ウィンドウのサイズをリサイズ可能(&R)", IDM_VID_RESIZE - MENUITEM "ウィンドウのサイズと位置を記憶(&E)", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "ウィンドウのサイズをリサイズ可能(&R)", IDM_VID_RESIZE + MENUITEM "ウィンドウのサイズと位置を記憶(&E)", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "レンダラー(&N)" BEGIN - MENUITEM "SDL (ソフトウェア)(&S)", IDM_VID_SDL_SW - MENUITEM "SDL (ハードウェア)(&H)", IDM_VID_SDL_HW - MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL - MENUITEM "OpenGL (3.0コア)(&G)", IDM_VID_OPENGL_CORE + MENUITEM "SDL (ソフトウェア)(&S)", IDM_VID_SDL_SW + MENUITEM "SDL (ハードウェア)(&H)", IDM_VID_SDL_HW + MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL + MENUITEM "OpenGL (3.0コア)(&G)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "VNC(&V)", IDM_VID_VNC + MENUITEM "VNC(&V)", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "ウィンドウのサイズを指定...", IDM_VID_SPECIFY_DIM - MENUITEM "4:3アスペクト比を固定(&O)", IDM_VID_FORCE43 + MENUITEM "ウィンドウのサイズを指定...", IDM_VID_SPECIFY_DIM + MENUITEM "4:3アスペクト比を固定(&O)", IDM_VID_FORCE43 POPUP "ウィンドウの表示倍率(&W)" BEGIN - MENUITEM "0.5x(&0)", IDM_VID_SCALE_1X - MENUITEM "1x(&1)", IDM_VID_SCALE_2X - MENUITEM "1.5x(&5)", IDM_VID_SCALE_3X - MENUITEM "2x(&2)", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "0.5x(&0)", IDM_VID_SCALE_1X + MENUITEM "1x(&1)", IDM_VID_SCALE_2X + MENUITEM "1.5x(&5)", IDM_VID_SCALE_3X + MENUITEM "2x(&2)", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "フィルター方式" BEGIN - MENUITEM "最近傍補間(&N)", IDM_VID_FILTER_NEAREST - MENUITEM "線形補間(&L)", IDM_VID_FILTER_LINEAR + MENUITEM "最近傍補間(&N)", IDM_VID_FILTER_NEAREST + MENUITEM "線形補間(&L)", IDM_VID_FILTER_LINEAR END - MENUITEM "HiDPIスケーリング(&D)", IDM_VID_HIDPI + MENUITEM "HiDPIスケーリング(&D)", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "フルスクリーン(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "フルスクリーン(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "フルスクリーンのスケール(&S)" BEGIN - MENUITEM "フルスクリーンに拡大(&F)", IDM_VID_FS_FULL - MENUITEM "4:3(&4)", IDM_VID_FS_43 + MENUITEM "フルスクリーンに拡大(&F)", IDM_VID_FS_FULL + MENUITEM "4:3(&4)", IDM_VID_FS_43 MENUITEM "正方形ピクセル(アスペクト比を維持)(&S)", IDM_VID_FS_KEEPRATIO - MENUITEM "整数倍(&I)", IDM_VID_FS_INT + MENUITEM "整数倍(&I)", IDM_VID_FS_INT END POPUP "E&GA/(S)VGAの設定" BEGIN - MENUITEM "色を反転(&I)", IDM_VID_INVERT + MENUITEM "色を反転(&I)", IDM_VID_INVERT POPUP "画面タイプ(&T)" BEGIN - MENUITEM "RGB(カラー)(&C)", IDM_VID_GRAY_RGB - MENUITEM "RGB(グレースケール)(&R)", IDM_VID_GRAY_MONO - MENUITEM "モニター(琥珀色)(&A)", IDM_VID_GRAY_AMBER - MENUITEM "モニター(緑色)(&G)", IDM_VID_GRAY_GREEN - MENUITEM "モニター(白色)(&W)", IDM_VID_GRAY_WHITE + MENUITEM "RGB(カラー)(&C)", IDM_VID_GRAY_RGB + MENUITEM "RGB(グレースケール)(&R)", IDM_VID_GRAY_MONO + MENUITEM "モニター(琥珀色)(&A)", IDM_VID_GRAY_AMBER + MENUITEM "モニター(緑色)(&G)", IDM_VID_GRAY_GREEN + MENUITEM "モニター(白色)(&W)", IDM_VID_GRAY_WHITE END POPUP "グレースケール変換タイプ(&C)" BEGIN - MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 - MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 - MENUITEM "平均(&A)", IDM_VID_GRAYCT_AVE + MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 + MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 + MENUITEM "平均(&A)", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGAオーバースキャン(&G)", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGAオーバースキャン(&G)", IDM_VID_OVERSCAN MENUITEM "単色モニター用コントラストを変更(&M)", IDM_VID_CGACON END - MENUITEM "メディア(&M)", IDM_MEDIA + MENUITEM "メディア(&M)", IDM_MEDIA POPUP "ツール(&T)" BEGIN - MENUITEM "設定(&S)...", IDM_CONFIG - MENUITEM "ステータスバーのアイコンを更新(&U)", IDM_UPDATE_ICONS + MENUITEM "設定(&S)...", IDM_CONFIG + MENUITEM "ステータスバーのアイコンを更新(&U)", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "スクリーンショットを撮る(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "スクリーンショットを撮る(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "環境設定(&P)...", IDM_PREFERENCES + MENUITEM "環境設定(&P)...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Discordとの連携機能(&D)", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "音量を調節(&G)...", IDM_SND_GAIN + MENUITEM "音量を調節(&G)...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "トレース開始\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "トレース終了\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "トレース開始\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "トレース終了\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "ヘルプ(&H)" BEGIN - MENUITEM "ドキュメント(&D)...", IDM_DOCS - MENUITEM "86Boxのバージョン情報(&A)...", IDM_ABOUT + MENUITEM "ドキュメント(&D)...", IDM_DOCS + MENUITEM "86Boxのバージョン情報(&A)...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新規イメージ(&N)...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "新規イメージ(&N)...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "既存のイメージを開く(&E)...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "既存のイメージを開く(&E)...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "録音(&R)", IDM_CASSETTE_RECORD - MENUITEM "再生(&P)", IDM_CASSETTE_PLAY - MENUITEM "冒頭に巻き戻す(&R)", IDM_CASSETTE_REWIND - MENUITEM "最後まで早送り(&F)", IDM_CASSETTE_FAST_FORWARD + MENUITEM "録音(&R)", IDM_CASSETTE_RECORD + MENUITEM "再生(&P)", IDM_CASSETTE_PLAY + MENUITEM "冒頭に巻き戻す(&R)", IDM_CASSETTE_REWIND + MENUITEM "最後まで早送り(&F)", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "取り出す(&J)", IDM_CASSETTE_EJECT + MENUITEM "取り出す(&J)", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "イメージ(&I)...", IDM_CARTRIDGE_IMAGE + MENUITEM "イメージ(&I)...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "取り出す(&J)", IDM_CARTRIDGE_EJECT + MENUITEM "取り出す(&J)", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新規イメージ(&N)...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "新規イメージ(&N)...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "既存のイメージを開く(&E)...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "既存のイメージを開く(&E)...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "86Fイメージにエクスポート(&X)...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "86Fイメージにエクスポート(&X)...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "取り出す(&J)", IDM_FLOPPY_EJECT + MENUITEM "取り出す(&J)", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "ミュート(&M)", IDM_CDROM_MUTE + MENUITEM "ミュート(&M)", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "空(&M)", IDM_CDROM_EMPTY - MENUITEM "前のイメージを再読み込み(&R)", IDM_CDROM_RELOAD + MENUITEM "空(&M)", IDM_CDROM_EMPTY + MENUITEM "前のイメージを再読み込み(&R)", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "イメージ(&I)...", IDM_CDROM_IMAGE - MENUITEM "フォルダ(&F)...", IDM_CDROM_DIR + MENUITEM "イメージ(&I)...", IDM_CDROM_IMAGE + MENUITEM "フォルダ(&F)...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新規イメージ(&N)...", IDM_ZIP_IMAGE_NEW + MENUITEM "新規イメージ(&N)...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "既存のイメージを開く(&E)...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "既存のイメージを開く(&E)...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "取り出す(&J)", IDM_ZIP_EJECT - MENUITEM "前のイメージを再読み込み(&R)", IDM_ZIP_RELOAD + MENUITEM "取り出す(&J)", IDM_ZIP_EJECT + MENUITEM "前のイメージを再読み込み(&R)", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新規イメージ(&N)...", IDM_MO_IMAGE_NEW + MENUITEM "新規イメージ(&N)...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "既存のイメージを開く(&E)...", IDM_MO_IMAGE_EXISTING - MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "既存のイメージを開く(&E)...", IDM_MO_IMAGE_EXISTING + MENUITEM "既存のイメージを開く(書き込み保護)(&W)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "取り出す(&J)", IDM_MO_EJECT - MENUITEM "前のイメージを再読み込み(&R)", IDM_MO_RELOAD + MENUITEM "取り出す(&J)", IDM_MO_EJECT + MENUITEM "前のイメージを再読み込み(&R)", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "環境設定" -#define STR_SND_GAIN "音量ゲイン" -#define STR_NEW_FLOPPY "新規のイメージ" +#define STR_PREFERENCES "環境設定" +#define STR_SND_GAIN "音量ゲイン" +#define STR_NEW_FLOPPY "新規のイメージ" #define STR_CONFIG "設定" -#define STR_SPECIFY_DIM "メインウィンドウのサイズ指定" +#define STR_SPECIFY_DIM "メインウィンドウのサイズ指定" #define STR_OK "OK" #define STR_CANCEL "キャンセル" #define STR_GLOBAL "これらの設定をグローバル既定値として保存する(&G)" -#define STR_DEFAULT "既定値(&D)" -#define STR_LANGUAGE "言語:" -#define STR_ICONSET "アイコンセット:" +#define STR_DEFAULT "既定値(&D)" +#define STR_LANGUAGE "言語:" +#define STR_ICONSET "アイコンセット:" -#define STR_GAIN "ゲイン値" +#define STR_GAIN "ゲイン値" -#define STR_FILE_NAME "ファイル名:" -#define STR_DISK_SIZE "ディスクサイズ:" -#define STR_RPM_MODE "回転数モード:" -#define STR_PROGRESS "進行状況:" +#define STR_FILE_NAME "ファイル名:" +#define STR_DISK_SIZE "ディスクサイズ:" +#define STR_RPM_MODE "回転数モード:" +#define STR_PROGRESS "進行状況:" -#define STR_WIDTH "幅:" +#define STR_WIDTH "幅:" #define STR_HEIGHT "高さ:" -#define STR_LOCK_TO_SIZE "このサイズをロックする" +#define STR_LOCK_TO_SIZE "このサイズをロックする" -#define STR_MACHINE_TYPE "マシンタイプ:" -#define STR_MACHINE "マシン:" -#define STR_CONFIGURE "設定" -#define STR_CPU_TYPE "CPUタイプ:" -#define STR_CPU_SPEED "速度:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "待機状態:" +#define STR_MACHINE_TYPE "マシンタイプ:" +#define STR_MACHINE "マシン:" +#define STR_CONFIGURE "設定" +#define STR_CPU_TYPE "CPUタイプ:" +#define STR_CPU_SPEED "速度:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "待機状態:" #define STR_MB "MB" #define STR_MEMORY "メモリ:" -#define STR_TIME_SYNC "時刻同期機能" -#define STR_DISABLED "無効にする" -#define STR_ENABLED_LOCAL "有効にする (現地時間)" -#define STR_ENABLED_UTC "有効にする (UTC)" -#define STR_DYNAREC "動的リコンパイラ" +#define STR_TIME_SYNC "時刻同期機能" +#define STR_DISABLED "無効にする" +#define STR_ENABLED_LOCAL "有効にする (現地時間)" +#define STR_ENABLED_UTC "有効にする (UTC)" +#define STR_DYNAREC "動的リコンパイラ" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "ビデオカード:" -#define STR_VIDEO_2 "ビデオカード 2:" +#define STR_VIDEO "ビデオカード:" +#define STR_VIDEO_2 "ビデオカード 2:" #define STR_VOODOO "Voodooグラフィック" -#define STR_IBM8514 "IBM 8514/aグラフィック" -#define STR_XGA "XGAグラフィック" +#define STR_IBM8514 "IBM 8514/aグラフィック" +#define STR_XGA "XGAグラフィック" -#define STR_MOUSE "マウス:" -#define STR_JOYSTICK "ジョイスティック:" -#define STR_JOY1 "ジョイスティック1..." -#define STR_JOY2 "ジョイスティック2..." -#define STR_JOY3 "ジョイスティック3..." -#define STR_JOY4 "ジョイスティック4..." +#define STR_MOUSE "マウス:" +#define STR_JOYSTICK "ジョイスティック:" +#define STR_JOY1 "ジョイスティック1..." +#define STR_JOY2 "ジョイスティック2..." +#define STR_JOY3 "ジョイスティック3..." +#define STR_JOY4 "ジョイスティック4..." #define STR_SOUND1 "サウンドカード 1:" #define STR_SOUND2 "サウンドカード 2:" #define STR_SOUND3 "サウンドカード 3:" #define STR_SOUND4 "サウンドカード 4:" -#define STR_MIDI_OUT "MIDI出力デバイス:" -#define STR_MIDI_IN "MIDI入力デバイス:" +#define STR_MIDI_OUT "MIDI出力デバイス:" +#define STR_MIDI_IN "MIDI入力デバイス:" #define STR_MPU401 "独立型MPU-401" -#define STR_FLOAT "FLOAT32サウンドを使用する" -#define STR_FM_DRIVER "FMシンセドライバー" -#define STR_FM_DRV_NUKED "Nuked (高精度化)" -#define STR_FM_DRV_YMFM "YMFM (より速く)" +#define STR_FLOAT "FLOAT32サウンドを使用する" +#define STR_FM_DRIVER "FMシンセドライバー" +#define STR_FM_DRV_NUKED "Nuked (高精度化)" +#define STR_FM_DRV_YMFM "YMFM (より速く)" -#define STR_NET_TYPE "ネットワークタイプ:" -#define STR_PCAP "PCapデバイス:" -#define STR_NET "ネットワークアダプター:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "ネットワークタイプ:" +#define STR_PCAP "PCapデバイス:" +#define STR_NET "ネットワークアダプター:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "COM1デバイス:" -#define STR_COM2 "COM2デバイス:" -#define STR_COM3 "COM3デバイス:" -#define STR_COM4 "COM4デバイス:" -#define STR_LPT1 "LPT1デバイス:" -#define STR_LPT2 "LPT2デバイス:" -#define STR_LPT3 "LPT3デバイス:" -#define STR_LPT4 "LPT4デバイス:" -#define STR_SERIAL1 "シリアルポート1" -#define STR_SERIAL2 "シリアルポート2" -#define STR_SERIAL3 "シリアルポート3" -#define STR_SERIAL4 "シリアルポート4" -#define STR_PARALLEL1 "パラレルポート1" -#define STR_PARALLEL2 "パラレルポート2" -#define STR_PARALLEL3 "パラレルポート3" -#define STR_PARALLEL4 "パラレルポート4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1デバイス:" +#define STR_COM2 "COM2デバイス:" +#define STR_COM3 "COM3デバイス:" +#define STR_COM4 "COM4デバイス:" +#define STR_LPT1 "LPT1デバイス:" +#define STR_LPT2 "LPT2デバイス:" +#define STR_LPT3 "LPT3デバイス:" +#define STR_LPT4 "LPT4デバイス:" +#define STR_SERIAL1 "シリアルポート1" +#define STR_SERIAL2 "シリアルポート2" +#define STR_SERIAL3 "シリアルポート3" +#define STR_SERIAL4 "シリアルポート4" +#define STR_PARALLEL1 "パラレルポート1" +#define STR_PARALLEL2 "パラレルポート2" +#define STR_PARALLEL3 "パラレルポート3" +#define STR_PARALLEL4 "パラレルポート4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "HDコントローラー:" -#define STR_FDC "FDコントローラー:" -#define STR_IDE_TER "第三のIDEコントローラー" -#define STR_IDE_QUA "第四のIDEコントローラー" -#define STR_SCSI "SCSI" +#define STR_HDC "HDコントローラー:" +#define STR_FDC "FDコントローラー:" +#define STR_IDE_TER "第三のIDEコントローラー" +#define STR_IDE_QUA "第四のIDEコントローラー" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "コントローラー1:" #define STR_SCSI_2 "コントローラー2:" #define STR_SCSI_3 "コントローラー3:" #define STR_SCSI_4 "コントローラー4:" -#define STR_CASSETTE "カセット" +#define STR_CASSETTE "カセット" -#define STR_HDD "ハードディスク:" -#define STR_NEW "新規(&N)..." -#define STR_EXISTING "既定(&E)..." +#define STR_HDD "ハードディスク:" +#define STR_NEW "新規(&N)..." +#define STR_EXISTING "既定(&E)..." #define STR_REMOVE "除去(&R)" -#define STR_BUS "バス:" -#define STR_CHANNEL "チャンネル:" +#define STR_BUS "バス:" +#define STR_CHANNEL "チャンネル:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "参照(&S)..." -#define STR_SECTORS "セクター:" -#define STR_HEADS "ヘッド:" -#define STR_CYLS "シリンダー:" -#define STR_SIZE_MB "サイズ(MB):" -#define STR_TYPE "タイプ:" -#define STR_IMG_FORMAT "イメージ形式:" -#define STR_BLOCK_SIZE "ブロックサイズ:" +#define STR_SPECIFY "参照(&S)..." +#define STR_SECTORS "セクター:" +#define STR_HEADS "ヘッド:" +#define STR_CYLS "シリンダー:" +#define STR_SIZE_MB "サイズ(MB):" +#define STR_TYPE "タイプ:" +#define STR_IMG_FORMAT "イメージ形式:" +#define STR_BLOCK_SIZE "ブロックサイズ:" -#define STR_FLOPPY_DRIVES "フロッピードライブ:" -#define STR_TURBO "高速タイミング" -#define STR_CHECKBPB "BPBをチェック" -#define STR_CDROM_DRIVES "CD-ROMドライブ:" -#define STR_CD_SPEED "速度:" -#define STR_EARLY "アーリードライブ" +#define STR_FLOPPY_DRIVES "フロッピードライブ:" +#define STR_TURBO "高速タイミング" +#define STR_CHECKBPB "BPBをチェック" +#define STR_CDROM_DRIVES "CD-ROMドライブ:" +#define STR_CD_SPEED "速度:" -#define STR_MO_DRIVES "光磁気ドライブ:" -#define STR_ZIP_DRIVES "ZIPドライブ:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "光磁気ドライブ:" +#define STR_ZIP_DRIVES "ZIPドライブ:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTCカード:" #define STR_ISAMEM "ISAメモリー拡張カード" -#define STR_ISAMEM_1 "カード1:" -#define STR_ISAMEM_2 "カード2:" -#define STR_ISAMEM_3 "カード3:" -#define STR_ISAMEM_4 "カード4:" +#define STR_ISAMEM_1 "カード1:" +#define STR_ISAMEM_2 "カード2:" +#define STR_ISAMEM_3 "カード3:" +#define STR_ISAMEM_4 "カード4:" #define STR_BUGGER "ISABuggerデバイス" -#define STR_POSTCARD "POSTカード" +#define STR_POSTCARD "POSTカード" -#define FONT_SIZE 9 -#define FONT_NAME "Meiryo UI" +#define FONT_SIZE 9 +#define FONT_NAME "Meiryo UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "エラー" IDS_2050 "致命的なエラー" IDS_2051 " - 一時停止" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "roms/machinesディレクトリにROMがないため、マシン「%hs」は使用できません。使用可能なマシンに切り替えます。" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "roms/videoディレクトリにROMがないため、ビデオカード「%hs」は使用できません。使用可能なビデオカードに切り替えます。" IDS_2065 "マシン" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "F8+F12キーまたは中ボタンでマウスを解放します" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynthが初期化できません" IDS_2081 "バス" IDS_2082 "ファイル" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "フロッピー %i (%s): %ls" IDS_2110 "すべてのイメージ (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0アドバンスドセクターイメージ (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0基本セクターイメージ (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0フラックスイメージ (*.FDI)\0*.FDI\0表面イメージ (*.86F;*.MFM)\0*.86F;*.MFM\0すべてのファイル (*.*)\0*.*\0" - IDS_2111 "FreeTypeが初期化できません" IDS_2112 "SDLが初期化できません。SDL2.dllが必要です" IDS_2113 "使用中のマシンをハードリセットしますか?" IDS_2114 "86Boxを終了しますか?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 LIB_NAME_PCAP "がインストールされてるか、" LIB_NAME_PCAP "に対応したネットワークに接続されてるか確認してください。" IDS_2131 "不正な設定です" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/Pプリンタのエミュレーションには" LIB_NAME_FREETYPE "が必要です。" -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 "PostScriptファイルをPDFに自動変換するには" LIB_NAME_GS "が必要です。\n\n汎用PostScriptプリンターに送信されたドキュメントは、PostScript(.ps)ファイルとして保存されます。" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynthのMIDI出力には" LIB_NAME_FLUIDSYNTH "が必要です。" IDS_2135 "フルスクリーンに切り替えています" IDS_2136 "今後、このメッセージを表示しない" IDS_2137 "終了しない" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "ハードリセット" IDS_2160 "ACPIシャットダウン" IDS_2161 "設定" - IDS_2162 "アーリードライブ" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "ハードディスク (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(システム既定値)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Japanese resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/ko-KR.rc b/src/win/languages/ko-KR.rc index 2ca9db02e..4fd952c38 100644 --- a/src/win/languages/ko-KR.rc +++ b/src/win/languages/ko-KR.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_KOREAN, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "동작(&A)" BEGIN - MENUITEM "키보드는 캡쳐가 필요함(&K)", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "우측CTRL로 좌측ALT 입력(&R)", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "키보드는 캡쳐가 필요함(&K)", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "우측 CTRL로 좌측 ALT 입력(&R)", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "재시작(&H)...", IDM_ACTION_HRESET - MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "재시작(&H)...", IDM_ACTION_HRESET + MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "일시정지(&P)", IDM_ACTION_PAUSE + MENUITEM "일시정지(&P)", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "끝내기(&X)...", IDM_ACTION_EXIT + MENUITEM "끝내기(&X)...", IDM_ACTION_EXIT END POPUP "표시(&V)" BEGIN - MENUITEM "상태 바 숨기기(&H)", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "상태 바 숨기기(&H)", IDM_VID_HIDE_STATUS_BAR + MENUITEM "툴바 숨기기", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "창 크기 조절 가능하게 하기(&R)", IDM_VID_RESIZE - MENUITEM "창 크기와 위치를 기억하기(&E)", IDM_VID_REMEMBER + MENUITEM "기본 모니터가 아닌 모니터 표시", IDM_VID_MONITORS + MENUITEM "창 크기 조절 가능하게 하기(&R)", IDM_VID_RESIZE + MENUITEM "창 크기와 위치를 기억하기(&E)", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "렌더러(&N)" BEGIN - MENUITEM "SDL (소프트웨어)(&S)", IDM_VID_SDL_SW - MENUITEM "SDL (하드웨어)(&H)", IDM_VID_SDL_HW - MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL - MENUITEM "OpenGL (3.0 코어)(&G)", IDM_VID_OPENGL_CORE + MENUITEM "SDL (소프트웨어)(&S)", IDM_VID_SDL_SW + MENUITEM "SDL (하드웨어)(&H)", IDM_VID_SDL_HW + MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL + MENUITEM "OpenGL (3.0 코어)(&G)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "VNC(&V)", IDM_VID_VNC + MENUITEM "VNC(&V)", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "창 크기 지정하기...", IDM_VID_SPECIFY_DIM - MENUITEM "화면 비율을 4:3으로 맞추기(&O)", IDM_VID_FORCE43 + MENUITEM "창 크기 지정하기...", IDM_VID_SPECIFY_DIM + MENUITEM "화면 비율을 4:3으로 맞추기(&O)", IDM_VID_FORCE43 POPUP "창 표시 배율(&W)" BEGIN - MENUITEM "0.5배(&0)", IDM_VID_SCALE_1X - MENUITEM "1배(&1)", IDM_VID_SCALE_2X - MENUITEM "1.5배(&5)", IDM_VID_SCALE_3X - MENUITEM "2배(&2)", IDM_VID_SCALE_4X - MENUITEM "&3배", IDM_VID_SCALE_5X - MENUITEM "&4배", IDM_VID_SCALE_6X - MENUITEM "&5배", IDM_VID_SCALE_7X - MENUITEM "&6배", IDM_VID_SCALE_8X - MENUITEM "&7배", IDM_VID_SCALE_9X - MENUITEM "&8배", IDM_VID_SCALE_10X + MENUITEM "0.5배(&0)", IDM_VID_SCALE_1X + MENUITEM "1배(&1)", IDM_VID_SCALE_2X + MENUITEM "1.5배(&5)", IDM_VID_SCALE_3X + MENUITEM "2배(&2)", IDM_VID_SCALE_4X + MENUITEM "&3배", IDM_VID_SCALE_5X + MENUITEM "&4배", IDM_VID_SCALE_6X + MENUITEM "&5배", IDM_VID_SCALE_7X + MENUITEM "&6배", IDM_VID_SCALE_8X + MENUITEM "&7배", IDM_VID_SCALE_9X + MENUITEM "&8배", IDM_VID_SCALE_10X END POPUP "필터 형식" BEGIN - MENUITEM "최근방 이웃 보간법(&N)", IDM_VID_FILTER_NEAREST - MENUITEM "선형 보간법(&L)", IDM_VID_FILTER_LINEAR + MENUITEM "최근방 이웃 보간법(&N)", IDM_VID_FILTER_NEAREST + MENUITEM "선형 보간법(&L)", IDM_VID_FILTER_LINEAR END - MENUITEM "HiDPI 스케일링(&D)", IDM_VID_HIDPI + MENUITEM "HiDPI 스케일링(&D)", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "전체 화면(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "전체 화면(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "전체 화면 비율(&S)" BEGIN - MENUITEM "전체 화면으로 확대(&F)", IDM_VID_FS_FULL - MENUITEM "4:3(&4)", IDM_VID_FS_43 + MENUITEM "전체 화면으로 확대(&F)", IDM_VID_FS_FULL + MENUITEM "4:3(&4)", IDM_VID_FS_43 MENUITEM "정사각형 픽셀 (비율 유지)(&S)", IDM_VID_FS_KEEPRATIO - MENUITEM "정수배 확대(&I)", IDM_VID_FS_INT + MENUITEM "정수배 확대(&I)", IDM_VID_FS_INT END POPUP "E&GA/(S)VGA 설정" BEGIN - MENUITEM "색상 반전된 VGA 모니터(&I)", IDM_VID_INVERT + MENUITEM "색상 반전된 VGA 모니터(&I)", IDM_VID_INVERT POPUP "VGA 화면 종류(&T)" BEGIN - MENUITEM "RGB 천연색(&C)", IDM_VID_GRAY_RGB - MENUITEM "RGB 회색조(&R)", IDM_VID_GRAY_MONO - MENUITEM "주황색 모니터(&A)", IDM_VID_GRAY_AMBER - MENUITEM "녹색 모니터(&G)", IDM_VID_GRAY_GREEN - MENUITEM "흰색 모니터(&W)", IDM_VID_GRAY_WHITE + MENUITEM "RGB 천연색(&C)", IDM_VID_GRAY_RGB + MENUITEM "RGB 회색조(&R)", IDM_VID_GRAY_MONO + MENUITEM "주황색 모니터(&A)", IDM_VID_GRAY_AMBER + MENUITEM "녹색 모니터(&G)", IDM_VID_GRAY_GREEN + MENUITEM "흰색 모니터(&W)", IDM_VID_GRAY_WHITE END POPUP "회색조 표현방식(&C)" BEGIN - MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 - MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 - MENUITEM "평균값(&A)", IDM_VID_GRAYCT_AVE + MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 + MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 + MENUITEM "평균값(&A)", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGA 오버스캔(&G)", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGA 오버스캔(&G)", IDM_VID_OVERSCAN MENUITEM "흑백 표시를 위한 밝기 조정(&M)", IDM_VID_CGACON END - MENUITEM "미디어(&M)", IDM_MEDIA + MENUITEM "미디어(&M)", IDM_MEDIA POPUP "도구(&T)" BEGIN - MENUITEM "설정(&S)...", IDM_CONFIG - MENUITEM "상태 바 아이콘 갱신하기(&U)", IDM_UPDATE_ICONS + MENUITEM "설정(&S)...", IDM_CONFIG + MENUITEM "상태 바 아이콘 갱신하기(&U)", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "스크린샷 찍기(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "스크린샷 찍기(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "환경설정(&P)...", IDM_PREFERENCES + MENUITEM "환경설정(&P)...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "디스코드 연동 활성화하기(&D)", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "음량 증폭(&G)...", IDM_SND_GAIN + MENUITEM "음량 증폭(&G)...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "추적 시작하기\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "추적 끝내기\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "추적 시작하기\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "추적 끝내기\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "도움말(&H)" BEGIN - MENUITEM "문서(&D)...", IDM_DOCS - MENUITEM "86Box에 대해(&A)...", IDM_ABOUT + MENUITEM "문서(&D)...", IDM_DOCS + MENUITEM "86Box에 대해(&A)...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "새 이미지(&N)...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "새 이미지(&N)...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "이미지 불러오기(&E)...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "이미지 불러오기(&E)...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "녹음하기(&R)", IDM_CASSETTE_RECORD - MENUITEM "재생하기(&P)", IDM_CASSETTE_PLAY - MENUITEM "맨앞으로 되감기(&R)", IDM_CASSETTE_REWIND - MENUITEM "맨끝으로 빨리감기(&F)", IDM_CASSETTE_FAST_FORWARD + MENUITEM "녹음하기(&R)", IDM_CASSETTE_RECORD + MENUITEM "재생하기(&P)", IDM_CASSETTE_PLAY + MENUITEM "맨앞으로 되감기(&R)", IDM_CASSETTE_REWIND + MENUITEM "맨끝으로 빨리감기(&F)", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "꺼내기(&J)", IDM_CASSETTE_EJECT + MENUITEM "꺼내기(&J)", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "이미지(&I)...", IDM_CARTRIDGE_IMAGE + MENUITEM "이미지(&I)...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "꺼내기(&J)", IDM_CARTRIDGE_EJECT + MENUITEM "꺼내기(&J)", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "새 이미지(&N)...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "새 이미지(&N)...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "이미지 불러오기(&E)...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "이미지 불러오기(&E)...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "86F로 보내기(&X)...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "86F로 보내기(&X)...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "꺼내기(&J)", IDM_FLOPPY_EJECT + MENUITEM "꺼내기(&J)", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "음소거(&M)", IDM_CDROM_MUTE + MENUITEM "음소거(&M)", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "비었음(&M)", IDM_CDROM_EMPTY - MENUITEM "이전 이미지 다시 불러오기(&R)", IDM_CDROM_RELOAD + MENUITEM "비었음(&M)", IDM_CDROM_EMPTY + MENUITEM "이전 이미지 다시 불러오기(&R)", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "이미지(&I)...", IDM_CDROM_IMAGE - MENUITEM "폴더(&F)...", IDM_CDROM_DIR + MENUITEM "이미지(&I)...", IDM_CDROM_IMAGE + MENUITEM "폴더(&F)...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "새 이미지(&N)...", IDM_ZIP_IMAGE_NEW + MENUITEM "새 이미지(&N)...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "이미지 불러오기(&E)...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "이미지 불러오기(&E)...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "꺼내기(&J)", IDM_ZIP_EJECT - MENUITEM "이전 이미지 다시 불러오기(&R)", IDM_ZIP_RELOAD + MENUITEM "꺼내기(&J)", IDM_ZIP_EJECT + MENUITEM "이전 이미지 다시 불러오기(&R)", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "새 이미지(&N)...", IDM_MO_IMAGE_NEW + MENUITEM "새 이미지(&N)...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "이미지 불러오기(&E)...", IDM_MO_IMAGE_EXISTING - MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "이미지 불러오기(&E)...", IDM_MO_IMAGE_EXISTING + MENUITEM "이미지 불러오기 (쓰기방지)(&W)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "꺼내기(&J)", IDM_MO_EJECT - MENUITEM "이전 이미지 다시 불러오기(&R)", IDM_MO_RELOAD + MENUITEM "꺼내기(&J)", IDM_MO_EJECT + MENUITEM "이전 이미지 다시 불러오기(&R)", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "환경설정" -#define STR_SND_GAIN "음량 증폭" -#define STR_NEW_FLOPPY "새 이미지" +#define STR_PREFERENCES "환경설정" +#define STR_SND_GAIN "음량 증폭" +#define STR_NEW_FLOPPY "새 이미지" #define STR_CONFIG "설정" -#define STR_SPECIFY_DIM "창 크기 지정" +#define STR_SPECIFY_DIM "창 크기 지정" #define STR_OK "확인" #define STR_CANCEL "취소" #define STR_GLOBAL "이 설정들을 전역 기본값으로 저장하기(&G)" -#define STR_DEFAULT "기본값(&D)" -#define STR_LANGUAGE "언어:" -#define STR_ICONSET "아이콘셋:" +#define STR_DEFAULT "기본값(&D)" +#define STR_LANGUAGE "언어:" +#define STR_ICONSET "아이콘셋:" -#define STR_GAIN "증가값" +#define STR_GAIN "증가값" -#define STR_FILE_NAME "파일명:" -#define STR_DISK_SIZE "디스크 용량:" -#define STR_RPM_MODE "RPM 모드:" -#define STR_PROGRESS "진행:" +#define STR_FILE_NAME "파일명:" +#define STR_DISK_SIZE "디스크 용량:" +#define STR_RPM_MODE "RPM 모드:" +#define STR_PROGRESS "진행:" -#define STR_WIDTH "가로:" +#define STR_WIDTH "가로:" #define STR_HEIGHT "세로:" -#define STR_LOCK_TO_SIZE "크기 고정" +#define STR_LOCK_TO_SIZE "크기 고정" -#define STR_MACHINE_TYPE "머신 종류:" -#define STR_MACHINE "기종:" -#define STR_CONFIGURE "설정" -#define STR_CPU_TYPE "CPU 종류:" -#define STR_CPU_SPEED "속도:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "대기 상태:" +#define STR_MACHINE_TYPE "머신 종류:" +#define STR_MACHINE "기종:" +#define STR_CONFIGURE "설정" +#define STR_CPU_TYPE "CPU 종류:" +#define STR_CPU_SPEED "속도:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "대기 상태:" #define STR_MB "MB" #define STR_MEMORY "메모리:" -#define STR_TIME_SYNC "시간 동기화" -#define STR_DISABLED "사용하지 않음" -#define STR_ENABLED_LOCAL "사용 (현지 시간)" -#define STR_ENABLED_UTC "사용 (UTC)" -#define STR_DYNAREC "동적 재컴파일" +#define STR_TIME_SYNC "시간 동기화" +#define STR_DISABLED "사용하지 않음" +#define STR_ENABLED_LOCAL "사용 (현지 시간)" +#define STR_ENABLED_UTC "사용 (UTC)" +#define STR_DYNAREC "동적 재컴파일" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "비디오 카드:" -#define STR_VIDEO_2 "비디오 카드 2:" +#define STR_VIDEO "비디오 카드:" +#define STR_VIDEO_2 "비디오 카드 2:" #define STR_VOODOO "Voodoo 그래픽" -#define STR_IBM8514 "IBM 8514/a 그래픽" -#define STR_XGA "XGA 그래픽" +#define STR_IBM8514 "IBM 8514/a 그래픽" +#define STR_XGA "XGA 그래픽" -#define STR_MOUSE "마우스:" -#define STR_JOYSTICK "조이스틱:" -#define STR_JOY1 "조이스틱 1..." -#define STR_JOY2 "조이스틱 2..." -#define STR_JOY3 "조이스틱 3..." -#define STR_JOY4 "조이스틱 4..." +#define STR_MOUSE "마우스:" +#define STR_JOYSTICK "조이스틱:" +#define STR_JOY1 "조이스틱 1..." +#define STR_JOY2 "조이스틱 2..." +#define STR_JOY3 "조이스틱 3..." +#define STR_JOY4 "조이스틱 4..." #define STR_SOUND1 "사운드 카드 1:" #define STR_SOUND2 "사운드 카드 2:" #define STR_SOUND3 "사운드 카드 3:" #define STR_SOUND4 "사운드 카드 4:" -#define STR_MIDI_OUT "MIDI 출력 장치:" -#define STR_MIDI_IN "MIDI 입력 장치:" +#define STR_MIDI_OUT "MIDI 출력 장치:" +#define STR_MIDI_IN "MIDI 입력 장치:" #define STR_MPU401 "MPU-401 단독 사용" -#define STR_FLOAT "FLOAT32 사운드 사용" -#define STR_FM_DRIVER "FM 신디사이저 드라이버" -#define STR_FM_DRV_NUKED "Nuked (더 정확한)" -#define STR_FM_DRV_YMFM "YMFM (더 빠르게)" +#define STR_FLOAT "FLOAT32 사운드 사용" +#define STR_FM_DRIVER "FM 신디사이저 드라이버" +#define STR_FM_DRV_NUKED "Nuked (더 정확한)" +#define STR_FM_DRV_YMFM "YMFM (더 빠르게)" -#define STR_NET_TYPE "네트워크 종류:" -#define STR_PCAP "PCap 장치:" -#define STR_NET "네트워크 어댑터:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "네트워크 종류:" +#define STR_PCAP "PCap 장치:" +#define STR_NET "네트워크 어댑터:" +#define STR_NET1 "네트워크 카드 1:" +#define STR_NET2 "네트워크 카드 2:" +#define STR_NET3 "네트워크 카드 3:" +#define STR_NET4 "네트워크 카드 4:" -#define STR_COM1 "COM1 장치:" -#define STR_COM2 "COM2 장치:" -#define STR_COM3 "COM3 장치:" -#define STR_COM4 "COM4 장치:" -#define STR_LPT1 "LPT1 장치:" -#define STR_LPT2 "LPT2 장치:" -#define STR_LPT3 "LPT3 장치:" -#define STR_LPT4 "LPT4 장치:" -#define STR_SERIAL1 "직렬 포트 1" -#define STR_SERIAL2 "직렬 포트 2" -#define STR_SERIAL3 "직렬 포트 3" -#define STR_SERIAL4 "직렬 포트 4" -#define STR_PARALLEL1 "병렬 포트 1" -#define STR_PARALLEL2 "병렬 포트 2" -#define STR_PARALLEL3 "병렬 포트 3" -#define STR_PARALLEL4 "병렬 포트 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1 장치:" +#define STR_COM2 "COM2 장치:" +#define STR_COM3 "COM3 장치:" +#define STR_COM4 "COM4 장치:" +#define STR_LPT1 "LPT1 장치:" +#define STR_LPT2 "LPT2 장치:" +#define STR_LPT3 "LPT3 장치:" +#define STR_LPT4 "LPT4 장치:" +#define STR_SERIAL1 "직렬 포트 1" +#define STR_SERIAL2 "직렬 포트 2" +#define STR_SERIAL3 "직렬 포트 3" +#define STR_SERIAL4 "직렬 포트 4" +#define STR_PARALLEL1 "병렬 포트 1" +#define STR_PARALLEL2 "병렬 포트 2" +#define STR_PARALLEL3 "병렬 포트 3" +#define STR_PARALLEL4 "병렬 포트 4" +#define STR_SERIAL_PASS1 "직렬 포트 패스쓰루 1" +#define STR_SERIAL_PASS2 "직렬 포트 패스쓰루 2" +#define STR_SERIAL_PASS3 "직렬 포트 패스쓰루 3" +#define STR_SERIAL_PASS4 "직렬 포트 패스쓰루 4" -#define STR_HDC "HD 컨트롤러:" -#define STR_FDC "FD 컨트롤러:" -#define STR_IDE_TER "제3의 IDE 컨트롤러" -#define STR_IDE_QUA "제4의 IDE 컨트롤러" -#define STR_SCSI "SCSI" +#define STR_HDC "HD 컨트롤러:" +#define STR_FDC "FD 컨트롤러:" +#define STR_IDE_TER "제3의 IDE 컨트롤러" +#define STR_IDE_QUA "제4의 IDE 컨트롤러" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "컨트롤러 1:" #define STR_SCSI_2 "컨트롤러 2:" #define STR_SCSI_3 "컨트롤러 3:" #define STR_SCSI_4 "컨트롤러 4:" -#define STR_CASSETTE "카세트 테이프" +#define STR_CASSETTE "카세트 테이프" -#define STR_HDD "하드 디스크:" -#define STR_NEW "새로 만들기(&N)..." -#define STR_EXISTING "불러오기(&E)..." +#define STR_HDD "하드 디스크:" +#define STR_NEW "새로 만들기(&N)..." +#define STR_EXISTING "불러오기(&E)..." #define STR_REMOVE "목록에서 제거(&R)" -#define STR_BUS "버스:" -#define STR_CHANNEL "채널:" +#define STR_BUS "버스:" +#define STR_CHANNEL "채널:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "열기(&S)..." -#define STR_SECTORS "섹터:" -#define STR_HEADS "헤드:" -#define STR_CYLS "실린더:" -#define STR_SIZE_MB "용량(MB):" -#define STR_TYPE "형식:" -#define STR_IMG_FORMAT "이미지 포맷:" -#define STR_BLOCK_SIZE "블록 크기:" +#define STR_SPECIFY "열기(&S)..." +#define STR_SECTORS "섹터:" +#define STR_HEADS "헤드:" +#define STR_CYLS "실린더:" +#define STR_SIZE_MB "용량(MB):" +#define STR_TYPE "형식:" +#define STR_IMG_FORMAT "이미지 포맷:" +#define STR_BLOCK_SIZE "블록 크기:" -#define STR_FLOPPY_DRIVES "플로피 드라이브:" -#define STR_TURBO "고속 동작" -#define STR_CHECKBPB "BPB 확인" -#define STR_CDROM_DRIVES "CD-ROM 드라이브:" -#define STR_CD_SPEED "속도:" -#define STR_EARLY "이전 드라이브" +#define STR_FLOPPY_DRIVES "플로피 드라이브:" +#define STR_TURBO "고속 동작" +#define STR_CHECKBPB "BPB 확인" +#define STR_CDROM_DRIVES "CD-ROM 드라이브:" +#define STR_CD_SPEED "속도:" -#define STR_MO_DRIVES "광자기 드라이브:" -#define STR_ZIP_DRIVES "ZIP 드라이브:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "광자기 드라이브:" +#define STR_ZIP_DRIVES "ZIP 드라이브:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC 카드:" #define STR_ISAMEM "ISA 메모리 확장 카드" -#define STR_ISAMEM_1 "카드 1:" -#define STR_ISAMEM_2 "카드 2:" -#define STR_ISAMEM_3 "카드 3:" -#define STR_ISAMEM_4 "카드 4:" +#define STR_ISAMEM_1 "카드 1:" +#define STR_ISAMEM_2 "카드 2:" +#define STR_ISAMEM_3 "카드 3:" +#define STR_ISAMEM_4 "카드 4:" #define STR_BUGGER "ISABugger 장치" -#define STR_POSTCARD "POST 카드" +#define STR_POSTCARD "POST 카드" -#define FONT_SIZE 9 -#define FONT_NAME "Malgun Gothic" +#define FONT_SIZE 9 +#define FONT_NAME "Malgun Gothic" #include "dialogs.rc" @@ -392,12 +392,12 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "오류" IDS_2050 "치명적인 오류" - IDS_2051 " - PAUSED" + IDS_2051 " - 일시중지" IDS_2052 "Ctrl+Alt+PgDn 키를 누르면 창 모드로 전환합니다." IDS_2053 "속도" IDS_2054 "ZIP %03i %i (%s): %ls" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "roms/machines 디렉토리에 필요한 롬파일이 없어 기종 ""%hs""을(를) 사용할 수 없습니다. 사용 가능한 기종으로 변경합니다." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "roms/video 디렉토리에 필요한 롬파일이 없어 비디오 카드 ""%hs""을(를) 사용할 수 없습니다. 사용 가능한 기종으로 변경합니다." IDS_2065 "기종" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "F12+F8키 또는 가운데 버튼을 클릭하면 마우스를 해제합니다" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynth를 초기화할 수 없습니다" IDS_2081 "버스" IDS_2082 "파일" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "플로피 %i (%s): %ls" IDS_2110 "모든 이미지 (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0어드밴스드 섹터 이미지 (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0기본 섹터 이미지 (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0플럭스 이미지 (*.FDI)\0*.FDI\0표면 이미지 (*.86F;*.MFM)\0*.86F;*.MFM\0모든 파일 (*.*)\0*.*\0" - IDS_2111 "FreeType을 초기화할 수 없습니다" IDS_2112 "SDL을 초기화할 수 없습니다. SDL2.dll이 필요합니다" IDS_2113 "실행중인 머신을 재시작하시겠습니까?" IDS_2114 "86Box를 끝내시겠습니까?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 LIB_NAME_PCAP "이 설치되었는지 " LIB_NAME_PCAP "에 대응하는 네트워크에 접속되어 있는지 확인해 주세요." IDS_2131 "올바르지 않은 설정입니다" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/P 프린터 에뮬레이션에 " LIB_NAME_FREETYPE "이(가) 필요합니다." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS "은(는) PostScript 파일을 PDF로 자동변환하는 데에 필요합니다.\n\n표준 PostScript 프린터로 보내신 임의의 문서는 PostScript (.ps) 파일로 저장됩니다." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynth의 MIDI 출력에 " LIB_NAME_FLUIDSYNTH "이(가) 필요합니다." IDS_2135 "전체 화면으로 전환" IDS_2136 "이 메시지 그만 보기" IDS_2137 "끝내지 않기" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "재시작" IDS_2160 "ACPI 종료" IDS_2161 "설정" - IDS_2162 "이전 드라이브" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" - IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2166 "두번째 비디오카드 ""%hs""는 roms/video 디렉토리에서 ROM이 누락되어 사용할 수 없습니다. 두번째 비디오 카드를 비활성화 합니다." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "하드 디스크 (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(시스템 기본값)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Korean resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/pl-PL.rc b/src/win/languages/pl-PL.rc index e1e7979de..442a225ed 100644 --- a/src/win/languages/pl-PL.rc +++ b/src/win/languages/pl-PL.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_POLISH, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Akcje" BEGIN - MENUITEM "&Klawaitura wymaga przechwytu myszy", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Prawy CTRL to lewy Alt", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Klawaitura wymaga przechwytu myszy", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Prawy CTRL to lewy Alt", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Twardy reset...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Twardy reset...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pauza", IDM_ACTION_PAUSE + MENUITEM "&Pauza", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "W&yjdź...", IDM_ACTION_EXIT + MENUITEM "W&yjdź...", IDM_ACTION_EXIT END POPUP "&Widok" BEGIN - MENUITEM "&Ukryj pasek statusu", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Ukryj &pasek narzędzi", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Ukryj pasek statusu", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Ukryj &pasek narzędzi", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Okno o zmiennym rozmiarze", IDM_VID_RESIZE - MENUITEM "P&amiętaj rozmiar &i pozycję", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Okno o zmiennym rozmiarze", IDM_VID_RESIZE + MENUITEM "P&amiętaj rozmiar &i pozycję", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "Re&nderer" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Określ rozmiary...", IDM_VID_SPECIFY_DIM - MENUITEM "&Wymuś proporcje wyświetlania 4:3", IDM_VID_FORCE43 + MENUITEM "Określ rozmiary...", IDM_VID_SPECIFY_DIM + MENUITEM "&Wymuś proporcje wyświetlania 4:3", IDM_VID_FORCE43 POPUP "&Czynnik skalowania okna" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Metoda filtrowania" BEGIN - MENUITEM "&Nearest", IDM_VID_FILTER_NEAREST - MENUITEM "&Linear", IDM_VID_FILTER_LINEAR + MENUITEM "&Nearest", IDM_VID_FILTER_NEAREST + MENUITEM "&Linear", IDM_VID_FILTER_LINEAR END - MENUITEM "Skalowanie Hi&DPI", IDM_VID_HIDPI + MENUITEM "Skalowanie Hi&DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Pełny ekran\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Pełny ekran\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Fullscreen &stretch mode" BEGIN - MENUITEM "&Tryb rozciągania na pełnym ekranie", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Tryb rozciągania na pełnym ekranie", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Kwadratowe piksele (Zachowaj proporcje)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Skalowanie całkowite", IDM_VID_FS_INT + MENUITEM "&Skalowanie całkowite", IDM_VID_FS_INT END POPUP "Ustawienia E&GA/(S)VGA" BEGIN - MENUITEM "&Odwrócony monitor VGA", IDM_VID_INVERT + MENUITEM "&Odwrócony monitor VGA", IDM_VID_INVERT POPUP "Rodzaj ekranu &VGA" BEGIN - MENUITEM "RGB - &Kolorowy", IDM_VID_GRAY_RGB - MENUITEM "&RGB - Skala szarości", IDM_VID_GRAY_MONO - MENUITEM "&Bursztynowy monitor", IDM_VID_GRAY_AMBER - MENUITEM "&Zielony monitor", IDM_VID_GRAY_GREEN - MENUITEM "&Biały monitor", IDM_VID_GRAY_WHITE + MENUITEM "RGB - &Kolorowy", IDM_VID_GRAY_RGB + MENUITEM "&RGB - Skala szarości", IDM_VID_GRAY_MONO + MENUITEM "&Bursztynowy monitor", IDM_VID_GRAY_AMBER + MENUITEM "&Zielony monitor", IDM_VID_GRAY_GREEN + MENUITEM "&Biały monitor", IDM_VID_GRAY_WHITE END POPUP "Typ konwersji &w skali szarości" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Średni", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Średni", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "Overscan dla CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "Overscan dla CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "Zmień kontrast dla &monochromatycznego ekranu", IDM_VID_CGACON END - MENUITEM "&Nośnik", IDM_MEDIA + MENUITEM "&Nośnik", IDM_MEDIA POPUP "&Narzędzia" BEGIN - MENUITEM "&Ustawienia...", IDM_CONFIG - MENUITEM "&Aktualizuj ikony na pasku statusu", IDM_UPDATE_ICONS + MENUITEM "&Ustawienia...", IDM_CONFIG + MENUITEM "&Aktualizuj ikony na pasku statusu", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Zrób &zrzut ekranu\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Zrób &zrzut ekranu\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Preferencje...", IDM_PREFERENCES + MENUITEM "&Preferencje...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Włącz integrację z &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "Wzmocnienie &dźwięku...", IDM_SND_GAIN + MENUITEM "Wzmocnienie &dźwięku...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Rozpocznij śledzenie\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Zakończ śledzenie\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Rozpocznij śledzenie\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Zakończ śledzenie\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Pomoc" BEGIN - MENUITEM "&Dokumentacja...", IDM_DOCS - MENUITEM "&O 86Box...", IDM_ABOUT + MENUITEM "&Dokumentacja...", IDM_DOCS + MENUITEM "&O 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nowy obraz...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nowy obraz...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Istniejący obraz...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Istniejący obraz...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Nagraj", IDM_CASSETTE_RECORD - MENUITEM "&Odtwórz", IDM_CASSETTE_PLAY - MENUITEM "&Przewiń do początku", IDM_CASSETTE_REWIND - MENUITEM "&Przewiń do końca", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Nagraj", IDM_CASSETTE_RECORD + MENUITEM "&Odtwórz", IDM_CASSETTE_PLAY + MENUITEM "&Przewiń do początku", IDM_CASSETTE_REWIND + MENUITEM "&Przewiń do końca", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "W&yjmij", IDM_CASSETTE_EJECT + MENUITEM "W&yjmij", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Obraz...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Obraz...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "W&yjmij", IDM_CARTRIDGE_EJECT + MENUITEM "W&yjmij", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nowy obraz...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nowy obraz...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Istniejący obraz...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Istniejący obraz...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&ksportuj do 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&ksportuj do 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "W&yjmij", IDM_FLOPPY_EJECT + MENUITEM "W&yjmij", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Ścisz", IDM_CDROM_MUTE + MENUITEM "&Ścisz", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "P&usty", IDM_CDROM_EMPTY - MENUITEM "&Przeładuj poprzedni obraz", IDM_CDROM_RELOAD + MENUITEM "P&usty", IDM_CDROM_EMPTY + MENUITEM "&Przeładuj poprzedni obraz", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Obraz...", IDM_CDROM_IMAGE - MENUITEM "&Teczka...", IDM_CDROM_DIR + MENUITEM "&Obraz...", IDM_CDROM_IMAGE + MENUITEM "&Teczka...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nowy obraz...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nowy obraz...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Istniejący obraz...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Istniejący obraz...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "W&yjmij", IDM_ZIP_EJECT - MENUITEM "&Przeładuj poprzedni obraz", IDM_ZIP_RELOAD + MENUITEM "W&yjmij", IDM_ZIP_EJECT + MENUITEM "&Przeładuj poprzedni obraz", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nowy obraz...", IDM_MO_IMAGE_NEW + MENUITEM "&Nowy obraz...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Istniejący obraz...", IDM_MO_IMAGE_EXISTING - MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Istniejący obraz...", IDM_MO_IMAGE_EXISTING + MENUITEM "Istniejący obraz (&Chroniony przed zapisem)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "W&yjmij", IDM_MO_EJECT - MENUITEM "&Przeładuj poprzedni obraz", IDM_MO_RELOAD + MENUITEM "W&yjmij", IDM_MO_EJECT + MENUITEM "&Przeładuj poprzedni obraz", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Preferencje" -#define STR_SND_GAIN "Wzmocnienie dźwięku" -#define STR_NEW_FLOPPY "Nowy obraz" +#define STR_PREFERENCES "Preferencje" +#define STR_SND_GAIN "Wzmocnienie dźwięku" +#define STR_NEW_FLOPPY "Nowy obraz" #define STR_CONFIG "Ustawienia" -#define STR_SPECIFY_DIM "Określ rozmiary okna" +#define STR_SPECIFY_DIM "Określ rozmiary okna" #define STR_OK "OK" #define STR_CANCEL "Anuluj" #define STR_GLOBAL "Zapisz ustawienia jako &globalne ustawienia domyślne" -#define STR_DEFAULT "&Domyślny" -#define STR_LANGUAGE "Język:" -#define STR_ICONSET "Zestaw ikon:" +#define STR_DEFAULT "&Domyślny" +#define STR_LANGUAGE "Język:" +#define STR_ICONSET "Zestaw ikon:" -#define STR_GAIN "Wzmacniacz" +#define STR_GAIN "Wzmacniacz" -#define STR_FILE_NAME "Nazwa pliku:" -#define STR_DISK_SIZE "Rozmiar dysku:" -#define STR_RPM_MODE "Tryb RPM:" -#define STR_PROGRESS "Postęp:" +#define STR_FILE_NAME "Nazwa pliku:" +#define STR_DISK_SIZE "Rozmiar dysku:" +#define STR_RPM_MODE "Tryb RPM:" +#define STR_PROGRESS "Postęp:" -#define STR_WIDTH "Szerokość:" +#define STR_WIDTH "Szerokość:" #define STR_HEIGHT "Wysokość:" -#define STR_LOCK_TO_SIZE "Stały rozmiar" +#define STR_LOCK_TO_SIZE "Stały rozmiar" -#define STR_MACHINE_TYPE "Rodzaj maszyny:" -#define STR_MACHINE "Maszyna:" -#define STR_CONFIGURE "Konfiguruj" -#define STR_CPU_TYPE "Rodzaj procesora:" -#define STR_CPU_SPEED "Szybkość:" -#define STR_FPU "Jednostka FPU:" -#define STR_WAIT_STATES "Stany oczekiwania:" +#define STR_MACHINE_TYPE "Rodzaj maszyny:" +#define STR_MACHINE "Maszyna:" +#define STR_CONFIGURE "Konfiguruj" +#define STR_CPU_TYPE "Rodzaj procesora:" +#define STR_CPU_SPEED "Szybkość:" +#define STR_FPU "Jednostka FPU:" +#define STR_WAIT_STATES "Stany oczekiwania:" #define STR_MB "MB" #define STR_MEMORY "Pamięć:" -#define STR_TIME_SYNC "Synchronizacja czasu" -#define STR_DISABLED "Wyłączona" -#define STR_ENABLED_LOCAL "Włączona (czas lokalny)" -#define STR_ENABLED_UTC "Włączona (UTC)" -#define STR_DYNAREC "Dynamiczny rekompilator" +#define STR_TIME_SYNC "Synchronizacja czasu" +#define STR_DISABLED "Wyłączona" +#define STR_ENABLED_LOCAL "Włączona (czas lokalny)" +#define STR_ENABLED_UTC "Włączona (UTC)" +#define STR_DYNAREC "Dynamiczny rekompilator" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Wideo:" -#define STR_VIDEO_2 "Wideo 2:" +#define STR_VIDEO "Wideo:" +#define STR_VIDEO_2 "Wideo 2:" #define STR_VOODOO "Grafika Voodoo" -#define STR_IBM8514 "Grafika IBM 8514/a" -#define STR_XGA "Grafika XGA" +#define STR_IBM8514 "Grafika IBM 8514/a" +#define STR_XGA "Grafika XGA" -#define STR_MOUSE "Mysz:" -#define STR_JOYSTICK "Joystick:" -#define STR_JOY1 "Joystick 1..." -#define STR_JOY2 "Joystick 2..." -#define STR_JOY3 "Joystick 3..." -#define STR_JOY4 "Joystick 4..." +#define STR_MOUSE "Mysz:" +#define STR_JOYSTICK "Joystick:" +#define STR_JOY1 "Joystick 1..." +#define STR_JOY2 "Joystick 2..." +#define STR_JOY3 "Joystick 3..." +#define STR_JOY4 "Joystick 4..." #define STR_SOUND1 "Karta dźwiękowa 1:" #define STR_SOUND2 "Karta dźwiękowa 2:" #define STR_SOUND3 "Karta dźwiękowa 3:" #define STR_SOUND4 "Karta dźwiękowa 4:" -#define STR_MIDI_OUT "Urządzenie wyjściowe MIDI:" -#define STR_MIDI_IN "Urządzenie wejściowe MIDI:" +#define STR_MIDI_OUT "Urządzenie wyjściowe MIDI:" +#define STR_MIDI_IN "Urządzenie wejściowe MIDI:" #define STR_MPU401 "Samodzielne urządzenie MPU-401" -#define STR_FLOAT "Użyj dźwięku FLOAT32" -#define STR_FM_DRIVER "Sterownik syntezy FM" -#define STR_FM_DRV_NUKED "Nuked (dokładniejszy)" -#define STR_FM_DRV_YMFM "YMFM (szybszy)" +#define STR_FLOAT "Użyj dźwięku FLOAT32" +#define STR_FM_DRIVER "Sterownik syntezy FM" +#define STR_FM_DRV_NUKED "Nuked (dokładniejszy)" +#define STR_FM_DRV_YMFM "YMFM (szybszy)" -#define STR_NET_TYPE "Rodzaj sieci:" -#define STR_PCAP "Urządzenie PCap:" -#define STR_NET "Karta sieciowa:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Rodzaj sieci:" +#define STR_PCAP "Urządzenie PCap:" +#define STR_NET "Karta sieciowa:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Urządzenie COM1:" -#define STR_COM2 "Urządzenie COM2:" -#define STR_COM3 "Urządzenie COM3:" -#define STR_COM4 "Urządzenie COM4:" -#define STR_LPT1 "Urządzenie LPT1:" -#define STR_LPT2 "Urządzenie LPT2:" -#define STR_LPT3 "Urządzenie LPT3:" -#define STR_LPT4 "Urządzenie LPT4:" -#define STR_SERIAL1 "Port szeregowy 1" -#define STR_SERIAL2 "Port szeregowy 2" -#define STR_SERIAL3 "Port szeregowy 3" -#define STR_SERIAL4 "Port Szeregowy 4" -#define STR_PARALLEL1 "Port równoległy 1" -#define STR_PARALLEL2 "Port równoległy 2" -#define STR_PARALLEL3 "Port równoległy 3" -#define STR_PARALLEL4 "Port równoległy 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Urządzenie COM1:" +#define STR_COM2 "Urządzenie COM2:" +#define STR_COM3 "Urządzenie COM3:" +#define STR_COM4 "Urządzenie COM4:" +#define STR_LPT1 "Urządzenie LPT1:" +#define STR_LPT2 "Urządzenie LPT2:" +#define STR_LPT3 "Urządzenie LPT3:" +#define STR_LPT4 "Urządzenie LPT4:" +#define STR_SERIAL1 "Port szeregowy 1" +#define STR_SERIAL2 "Port szeregowy 2" +#define STR_SERIAL3 "Port szeregowy 3" +#define STR_SERIAL4 "Port Szeregowy 4" +#define STR_PARALLEL1 "Port równoległy 1" +#define STR_PARALLEL2 "Port równoległy 2" +#define STR_PARALLEL3 "Port równoległy 3" +#define STR_PARALLEL4 "Port równoległy 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Kontroler dysku twardego:" -#define STR_FDC "Kontroler dyskietek:" -#define STR_IDE_TER "Trzeciorzędowy kontroler IDE" -#define STR_IDE_QUA "Czwartorzędowy kontroler IDE" -#define STR_SCSI "SCSI" +#define STR_HDC "Kontroler dysku twardego:" +#define STR_FDC "Kontroler dyskietek:" +#define STR_IDE_TER "Trzeciorzędowy kontroler IDE" +#define STR_IDE_QUA "Czwartorzędowy kontroler IDE" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Kontroler 1:" #define STR_SCSI_2 "Kontroler 2:" #define STR_SCSI_3 "Kontroler 3:" #define STR_SCSI_4 "Kontroler 4:" #define STR_CASSETTE "Kaseta" -#define STR_HDD "Dyski twarde:" -#define STR_NEW "&Nowy..." -#define STR_EXISTING "&Istniejący..." +#define STR_HDD "Dyski twarde:" +#define STR_NEW "&Nowy..." +#define STR_EXISTING "&Istniejący..." #define STR_REMOVE "&Usuń" -#define STR_BUS "Magistrala:" -#define STR_CHANNEL "Kanał:" +#define STR_BUS "Magistrala:" +#define STR_CHANNEL "Kanał:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Określ..." -#define STR_SECTORS "Sektory:" -#define STR_HEADS "Głowice:" -#define STR_CYLS "Cylindry:" -#define STR_SIZE_MB "Rozmiar (MB):" -#define STR_TYPE "Rodzaj:" -#define STR_IMG_FORMAT "Format obrazu:" -#define STR_BLOCK_SIZE "Rozmiar bloku:" +#define STR_SPECIFY "&Określ..." +#define STR_SECTORS "Sektory:" +#define STR_HEADS "Głowice:" +#define STR_CYLS "Cylindry:" +#define STR_SIZE_MB "Rozmiar (MB):" +#define STR_TYPE "Rodzaj:" +#define STR_IMG_FORMAT "Format obrazu:" +#define STR_BLOCK_SIZE "Rozmiar bloku:" -#define STR_FLOPPY_DRIVES "Napędy dyskietek:" -#define STR_TURBO "Rozrządy Turbo" -#define STR_CHECKBPB "Sprawdzaj BPB" -#define STR_CDROM_DRIVES "Napędy CD-ROM:" -#define STR_CD_SPEED "Szybkość:" -#define STR_EARLY "Wcześniejszy napęd" +#define STR_FLOPPY_DRIVES "Napędy dyskietek:" +#define STR_TURBO "Rozrządy Turbo" +#define STR_CHECKBPB "Sprawdzaj BPB" +#define STR_CDROM_DRIVES "Napędy CD-ROM:" +#define STR_CD_SPEED "Szybkość:" -#define STR_MO_DRIVES "Napędy MO:" -#define STR_ZIP_DRIVES "Napędy ZIP:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Napędy MO:" +#define STR_ZIP_DRIVES "Napędy ZIP:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC:" #define STR_ISAMEM "Rozszerzenie pamięci ISA" -#define STR_ISAMEM_1 "Karta 1:" -#define STR_ISAMEM_2 "Karta 2:" -#define STR_ISAMEM_3 "Karta 3:" -#define STR_ISAMEM_4 "Karta 4:" +#define STR_ISAMEM_1 "Karta 1:" +#define STR_ISAMEM_2 "Karta 2:" +#define STR_ISAMEM_3 "Karta 3:" +#define STR_ISAMEM_4 "Karta 4:" #define STR_BUGGER "Urządzenie ISABugger" -#define STR_POSTCARD "Karta POST" +#define STR_POSTCARD "Karta POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Błąd" IDS_2050 "Fatalny błąd" IDS_2051 " - PAUSED" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Maszyna ""%hs"" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/machines. Przełączanie na dostępną maszynę." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Karta wideo ""%hs"" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Przełączanie na dostępną kartę wideo." IDS_2065 "Maszyna" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Naciśnij klawisze F8+F12 lub środkowy przycisk w celu uwolnienia myszy" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nie można zainicjować FluidSynth" IDS_2081 "Magistrala" IDS_2082 "Plik" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Dyskietka %i (%s): %ls" IDS_2110 "Wszystkie obrazy (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Zaawansowane obrazy sektorów (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Podstawowe obrazy sektorów (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Obrazy powierzchniowe (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Nie można zainicjować FreeType" IDS_2112 "Nie można zainicjować SDL, wymagany SDL2.dll" IDS_2113 "Jesteś pewien że chcesz wykonać twardy reset emulowanej maszyny?" IDS_2114 "Jesteś pewien że chcesz zakończyć 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Sprawdź, czy " LIB_NAME_PCAP " jest zainstalowany i czy posiadasz połączenie sieciowe kompatybilne z " LIB_NAME_PCAP "." IDS_2131 "Nieprawidłowa konfiguracja" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " jest wymagany do emulacji drukarki ESC-P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " jest wymagany do automatycznej konwersji plików PostScript do PDF.\n\nDokumenty wysłane do ogólnej drukarki PostScript zostaną zapisane jako pliki PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " jest wymagany dla wyjścia FluidSynth MIDI." IDS_2135 "Przechodzenie do trybu pełnoekranowego" IDS_2136 "Nie pokazuj więcej tego komunikatu" IDS_2137 "Nie kończ" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Twardy reset" IDS_2160 "Wyłączenie ACPI" IDS_2161 "Ustawienia" - IDS_2162 "Wcześniejszy napęd" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Dysk twardy (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Domyślne ustawienie systemowe)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Polish (pl-PL) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/pt-BR.rc b/src/win/languages/pt-BR.rc index 657e2956c..db85ed021 100644 --- a/src/win/languages/pt-BR.rc +++ b/src/win/languages/pt-BR.rc @@ -16,122 +16,122 @@ LANGUAGE LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Ação" BEGIN - MENUITEM "&Teclado requer captura", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "CTRL &direito é o ALT esquerdo", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Teclado requer captura", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "CTRL &direito é o ALT esquerdo", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Reinicialização completa...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Reinicialização completa...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pausar", IDM_ACTION_PAUSE + MENUITEM "&Pausar", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Sair...", IDM_ACTION_EXIT + MENUITEM "&Sair...", IDM_ACTION_EXIT END POPUP "&Exibir" BEGIN - MENUITEM "&Ocultar barra de status", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Ocultar &barra de ferramenta", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Ocultar barra de status", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Ocultar &barra de ferramenta", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Mostrar monitores não-primários", IDM_VID_MONITORS - MENUITEM "&Janela redimensionável", IDM_VID_RESIZE - MENUITEM "&Lembrar tamanho e posição", IDM_VID_REMEMBER + MENUITEM "&Mostrar monitores não-primários", IDM_VID_MONITORS + MENUITEM "&Janela redimensionável", IDM_VID_RESIZE + MENUITEM "&Lembrar tamanho e posição", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Renderizador" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (Núcleo 3.0)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (Núcleo 3.0)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Especificar as dimensões...", IDM_VID_SPECIFY_DIM - MENUITEM "F&orçar proporção de tela em 4:3", IDM_VID_FORCE43 + MENUITEM "Especificar as dimensões...", IDM_VID_SPECIFY_DIM + MENUITEM "F&orçar proporção de tela em 4:3", IDM_VID_FORCE43 POPUP "&Fator de redimensionamento da janela" BEGIN - MENUITEM "&0,5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1,&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0,5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1,&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Método de filtragem" BEGIN - MENUITEM "&Mais próximo", IDM_VID_FILTER_NEAREST - MENUITEM "&Linear", IDM_VID_FILTER_LINEAR + MENUITEM "&Mais próximo", IDM_VID_FILTER_NEAREST + MENUITEM "&Linear", IDM_VID_FILTER_LINEAR END - MENUITEM "Escala Hi&DPI", IDM_VID_HIDPI + MENUITEM "Escala Hi&DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Tela cheia\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Tela cheia\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Modo de &redimensionamento da tela cheia" BEGIN - MENUITEM "&Tela cheia esticada", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Tela cheia esticada", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "Pixel&s quadrados (manter proporção)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Redimensionamento com valores inteiros", IDM_VID_FS_INT + MENUITEM "&Redimensionamento com valores inteiros", IDM_VID_FS_INT END POPUP "Configurações E&GA/(S)VGA" BEGIN - MENUITEM "Monitor VGA &invertido", IDM_VID_INVERT + MENUITEM "Monitor VGA &invertido", IDM_VID_INVERT POPUP "&Tipo de tela VGA" BEGIN - MENUITEM "&Cores RGB", IDM_VID_GRAY_RGB - MENUITEM "Tons de cinza &RGB", IDM_VID_GRAY_MONO - MENUITEM "Monitor &âmbar", IDM_VID_GRAY_AMBER - MENUITEM "Monitor &verde", IDM_VID_GRAY_GREEN - MENUITEM "Monitor &branco", IDM_VID_GRAY_WHITE + MENUITEM "&Cores RGB", IDM_VID_GRAY_RGB + MENUITEM "Tons de cinza &RGB", IDM_VID_GRAY_MONO + MENUITEM "Monitor &âmbar", IDM_VID_GRAY_AMBER + MENUITEM "Monitor &verde", IDM_VID_GRAY_GREEN + MENUITEM "Monitor &branco", IDM_VID_GRAY_WHITE END POPUP "Tipo de &conversão de tons de cinza" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Média", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Média", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "Overscan do CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "Overscan do CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "Alterar contraste para exibição &monocromática", IDM_VID_CGACON END - MENUITEM "&Mídia", IDM_MEDIA + MENUITEM "&Mídia", IDM_MEDIA POPUP "&Ferramentas" BEGIN - MENUITEM "&Configurações...", IDM_CONFIG - MENUITEM "&Atualizar ícones da barra de status", IDM_UPDATE_ICONS + MENUITEM "&Configurações...", IDM_CONFIG + MENUITEM "&Atualizar ícones da barra de status", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Capturar &tela\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Capturar &tela\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Preferências...", IDM_PREFERENCES + MENUITEM "&Preferências...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Ativar integração com o &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Ganho de som...", IDM_SND_GAIN + MENUITEM "&Ganho de som...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Inicio do rastreamento\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Fim do rastreamento\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Inicio do rastreamento\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Fim do rastreamento\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Ajuda" BEGIN - MENUITEM "&Documentação...", IDM_DOCS - MENUITEM "&Sobre o 86Box...", IDM_ABOUT + MENUITEM "&Documentação...", IDM_DOCS + MENUITEM "&Sobre o 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -140,17 +140,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Imagem existente...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Imagem existente...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Gravar", IDM_CASSETTE_RECORD - MENUITEM "&Reproduzir", IDM_CASSETTE_PLAY - MENUITEM "&Rebobinar até o começo", IDM_CASSETTE_REWIND - MENUITEM "&Avançar até o fim", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Gravar", IDM_CASSETTE_RECORD + MENUITEM "&Reproduzir", IDM_CASSETTE_PLAY + MENUITEM "&Rebobinar até o começo", IDM_CASSETTE_REWIND + MENUITEM "&Avançar até o fim", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_CASSETTE_EJECT + MENUITEM "E&jetar", IDM_CASSETTE_EJECT END END @@ -158,9 +158,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Imagem...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Imagem...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_CARTRIDGE_EJECT + MENUITEM "E&jetar", IDM_CARTRIDGE_EJECT END END @@ -168,14 +168,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Imagem existente...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Imagem existente...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xportar para 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&xportar para 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_FLOPPY_EJECT + MENUITEM "E&jetar", IDM_FLOPPY_EJECT END END @@ -183,13 +183,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Sem som", IDM_CDROM_MUTE + MENUITEM "&Sem som", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&Vazio", IDM_CDROM_EMPTY - MENUITEM "&Recarregar imagem anterior", IDM_CDROM_RELOAD + MENUITEM "&Vazio", IDM_CDROM_EMPTY + MENUITEM "&Recarregar imagem anterior", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Imagem...", IDM_CDROM_IMAGE - MENUITEM "&Pasta...", IDM_CDROM_DIR + MENUITEM "&Imagem...", IDM_CDROM_IMAGE + MENUITEM "&Pasta...", IDM_CDROM_DIR END END @@ -197,13 +197,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Imagem existente...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Imagem existente...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_ZIP_EJECT - MENUITEM "&Recarregar imagem anterior", IDM_ZIP_RELOAD + MENUITEM "E&jetar", IDM_ZIP_EJECT + MENUITEM "&Recarregar imagem anterior", IDM_ZIP_RELOAD END END @@ -211,13 +211,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_MO_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Imagem existente...", IDM_MO_IMAGE_EXISTING - MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Imagem existente...", IDM_MO_IMAGE_EXISTING + MENUITEM "Imagem existente (&protegida contra escrita)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_MO_EJECT - MENUITEM "&Recarregar imagem anterior", IDM_MO_RELOAD + MENUITEM "E&jetar", IDM_MO_EJECT + MENUITEM "&Recarregar imagem anterior", IDM_MO_RELOAD END END @@ -243,150 +243,150 @@ END // Dialog // -#define STR_PREFERENCES "Preferências" -#define STR_SND_GAIN "Ganho de som" -#define STR_NEW_FLOPPY "Nova imagem de disquete" +#define STR_PREFERENCES "Preferências" +#define STR_SND_GAIN "Ganho de som" +#define STR_NEW_FLOPPY "Nova imagem de disquete" #define STR_CONFIG "Configurações" -#define STR_SPECIFY_DIM "Especifique as dimensões da janela principal" +#define STR_SPECIFY_DIM "Especifique as dimensões da janela principal" #define STR_OK "OK" #define STR_CANCEL "Cancelar" #define STR_GLOBAL "Usar estas configurações como &padrões globais" -#define STR_DEFAULT "&Padrão" -#define STR_LANGUAGE "Idioma:" -#define STR_ICONSET "Pacote de ícones:" +#define STR_DEFAULT "&Padrão" +#define STR_LANGUAGE "Idioma:" +#define STR_ICONSET "Pacote de ícones:" -#define STR_GAIN "Ganho" +#define STR_GAIN "Ganho" -#define STR_FILE_NAME "Nome:" -#define STR_DISK_SIZE "Tamanho:" -#define STR_RPM_MODE "Modo RPM:" -#define STR_PROGRESS "Progresso:" +#define STR_FILE_NAME "Nome:" +#define STR_DISK_SIZE "Tamanho:" +#define STR_RPM_MODE "Modo RPM:" +#define STR_PROGRESS "Progresso:" -#define STR_WIDTH "Largura:" +#define STR_WIDTH "Largura:" #define STR_HEIGHT "Altura:" -#define STR_LOCK_TO_SIZE "Travar nesse tamanho" +#define STR_LOCK_TO_SIZE "Travar nesse tamanho" -#define STR_MACHINE_TYPE "Tipo de máquina:" -#define STR_MACHINE "Máquina:" -#define STR_CONFIGURE "Configurar" -#define STR_CPU_TYPE "Tipo de CPU:" -#define STR_CPU_SPEED "Veloc.:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "Estados de espera:" +#define STR_MACHINE_TYPE "Tipo de máquina:" +#define STR_MACHINE "Máquina:" +#define STR_CONFIGURE "Configurar" +#define STR_CPU_TYPE "Tipo de CPU:" +#define STR_CPU_SPEED "Veloc.:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "Estados de espera:" #define STR_MB "MB" #define STR_MEMORY "Memória:" -#define STR_TIME_SYNC "Sincronização da hora" -#define STR_DISABLED "Desativar" -#define STR_ENABLED_LOCAL "Ativar (hora local)" -#define STR_ENABLED_UTC "Ativar (UTC)" -#define STR_DYNAREC "Recompilador dinâmico" +#define STR_TIME_SYNC "Sincronização da hora" +#define STR_DISABLED "Desativar" +#define STR_ENABLED_LOCAL "Ativar (hora local)" +#define STR_ENABLED_UTC "Ativar (UTC)" +#define STR_DYNAREC "Recompilador dinâmico" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Vídeo:" -#define STR_VIDEO_2 "Vídeo 2:" +#define STR_VIDEO "Vídeo:" +#define STR_VIDEO_2 "Vídeo 2:" #define STR_VOODOO "3DFX Voodoo" -#define STR_IBM8514 "Gráficos IBM 8514/a" -#define STR_XGA "Gráficos XGA" +#define STR_IBM8514 "Gráficos IBM 8514/a" +#define STR_XGA "Gráficos XGA" -#define STR_MOUSE "Mouse:" -#define STR_JOYSTICK "Joystick:" -#define STR_JOY1 "Joystick 1..." -#define STR_JOY2 "Joystick 2..." -#define STR_JOY3 "Joystick 3..." -#define STR_JOY4 "Joystick 4..." +#define STR_MOUSE "Mouse:" +#define STR_JOYSTICK "Joystick:" +#define STR_JOY1 "Joystick 1..." +#define STR_JOY2 "Joystick 2..." +#define STR_JOY3 "Joystick 3..." +#define STR_JOY4 "Joystick 4..." #define STR_SOUND1 "Placa de som 1:" #define STR_SOUND2 "Placa de som 2:" #define STR_SOUND3 "Placa de som 3:" #define STR_SOUND4 "Placa de som 4:" -#define STR_MIDI_OUT "Disp. saída MIDI:" -#define STR_MIDI_IN "Disp. entrada MIDI:" +#define STR_MIDI_OUT "Disp. saída MIDI:" +#define STR_MIDI_IN "Disp. entrada MIDI:" #define STR_MPU401 "MPU-401 autônomo" -#define STR_FLOAT "Usar som FLOAT32" -#define STR_FM_DRIVER "Controlador de sint. FM" -#define STR_FM_DRV_NUKED "Nuked (mais preciso)" -#define STR_FM_DRV_YMFM "YMFM (mais rápido)" +#define STR_FLOAT "Usar som FLOAT32" +#define STR_FM_DRIVER "Controlador de sint. FM" +#define STR_FM_DRV_NUKED "Nuked (mais preciso)" +#define STR_FM_DRV_YMFM "YMFM (mais rápido)" -#define STR_NET_TYPE "Tipo de rede:" -#define STR_PCAP "Dispositivo PCap:" -#define STR_NET "Adaptador de rede:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Tipo de rede:" +#define STR_PCAP "Dispositivo PCap:" +#define STR_NET "Adaptador de rede:" +#define STR_NET1 "Placa de rede 1:" +#define STR_NET2 "Placa de rede 2:" +#define STR_NET3 "Placa de rede 3:" +#define STR_NET4 "Placa de rede 4:" -#define STR_COM1 "Dispositivo COM1:" -#define STR_COM2 "Dispositivo COM2:" -#define STR_COM3 "Dispositivo COM3:" -#define STR_COM4 "Dispositivo COM4:" -#define STR_LPT1 "Dispositivo LPT1:" -#define STR_LPT2 "Dispositivo LPT2:" -#define STR_LPT3 "Dispositivo LPT3:" -#define STR_LPT4 "Dispositivo LPT4:" -#define STR_SERIAL1 "Porta serial 1" -#define STR_SERIAL2 "Porta serial 2" -#define STR_SERIAL3 "Porta serial 3" -#define STR_SERIAL4 "Porta serial 4" -#define STR_PARALLEL1 "Porta paralela 1" -#define STR_PARALLEL2 "Porta paralela 2" -#define STR_PARALLEL3 "Porta paralela 3" -#define STR_PARALLEL4 "Porta paralela 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Dispositivo COM1:" +#define STR_COM2 "Dispositivo COM2:" +#define STR_COM3 "Dispositivo COM3:" +#define STR_COM4 "Dispositivo COM4:" +#define STR_LPT1 "Dispositivo LPT1:" +#define STR_LPT2 "Dispositivo LPT2:" +#define STR_LPT3 "Dispositivo LPT3:" +#define STR_LPT4 "Dispositivo LPT4:" +#define STR_SERIAL1 "Porta serial 1" +#define STR_SERIAL2 "Porta serial 2" +#define STR_SERIAL3 "Porta serial 3" +#define STR_SERIAL4 "Porta serial 4" +#define STR_PARALLEL1 "Porta paralela 1" +#define STR_PARALLEL2 "Porta paralela 2" +#define STR_PARALLEL3 "Porta paralela 3" +#define STR_PARALLEL4 "Porta paralela 4" +#define STR_SERIAL_PASS1 "Encaminhamento de porta serial 1" +#define STR_SERIAL_PASS2 "Encaminhamento de porta serial 2" +#define STR_SERIAL_PASS3 "Encaminhamento de porta serial 3" +#define STR_SERIAL_PASS4 "Encaminhamento de porta serial 4" -#define STR_HDC "Controlador HD:" -#define STR_FDC "Controlador FD:" -#define STR_IDE_TER "Controlador IDE terciário" -#define STR_IDE_QUA "Controlador IDE quaternário" -#define STR_SCSI "SCSI" +#define STR_HDC "Controlador HD:" +#define STR_FDC "Controlador FD:" +#define STR_IDE_TER "Controlador IDE terciário" +#define STR_IDE_QUA "Controlador IDE quaternário" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Controlador 1:" #define STR_SCSI_2 "Controlador 2:" #define STR_SCSI_3 "Controlador 3:" #define STR_SCSI_4 "Controlador 4:" -#define STR_CASSETTE "Cassete" +#define STR_CASSETTE "Cassete" -#define STR_HDD "Discos rígidos:" -#define STR_NEW "&Novo..." -#define STR_EXISTING "&Existente..." +#define STR_HDD "Discos rígidos:" +#define STR_NEW "&Novo..." +#define STR_EXISTING "&Existente..." #define STR_REMOVE "&Remover" -#define STR_BUS "Bar.:" -#define STR_CHANNEL "Canal:" +#define STR_BUS "Bar.:" +#define STR_CHANNEL "Canal:" #define STR_ID "ID:" -#define STR_SPEED "Velocidade:" +#define STR_SPEED "Velocidade:" -#define STR_SPECIFY "&Especificar..." -#define STR_SECTORS "Setores:" -#define STR_HEADS "Cabeças:" -#define STR_CYLS "Cilindros:" -#define STR_SIZE_MB "Tamanho (MB):" -#define STR_TYPE "Tipo:" -#define STR_IMG_FORMAT "Formato:" -#define STR_BLOCK_SIZE "Blocos:" +#define STR_SPECIFY "&Especificar..." +#define STR_SECTORS "Setores:" +#define STR_HEADS "Cabeças:" +#define STR_CYLS "Cilindros:" +#define STR_SIZE_MB "Tamanho (MB):" +#define STR_TYPE "Tipo:" +#define STR_IMG_FORMAT "Formato:" +#define STR_BLOCK_SIZE "Blocos:" -#define STR_FLOPPY_DRIVES "Unidades de disquete:" -#define STR_TURBO "Turbo" -#define STR_CHECKBPB "Verificar BPB" -#define STR_CDROM_DRIVES "Unidades de CD-ROM:" -#define STR_CD_SPEED "Veloc.:" -#define STR_EARLY "Unidade anterior" +#define STR_FLOPPY_DRIVES "Unidades de disquete:" +#define STR_TURBO "Turbo" +#define STR_CHECKBPB "Verificar BPB" +#define STR_CDROM_DRIVES "Unidades de CD-ROM:" +#define STR_CD_SPEED "Veloc.:" -#define STR_MO_DRIVES "Unidades magneto-ópticas:" -#define STR_ZIP_DRIVES "Unidades ZIP:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Unidades magneto-ópticas:" +#define STR_ZIP_DRIVES "Unidades ZIP:" +#define STR_250 "ZIP 250" #define STR_ISARTC "RTC ISA:" #define STR_ISAMEM "Expansão de memória ISA" -#define STR_ISAMEM_1 "Placa 1:" -#define STR_ISAMEM_2 "Placa 2:" -#define STR_ISAMEM_3 "Placa 3:" -#define STR_ISAMEM_4 "Placa 4:" +#define STR_ISAMEM_1 "Placa 1:" +#define STR_ISAMEM_2 "Placa 2:" +#define STR_ISAMEM_3 "Placa 3:" +#define STR_ISAMEM_4 "Placa 4:" #define STR_BUGGER "Dispositivo ISABugger" -#define STR_POSTCARD "Placa de diagnóstico" +#define STR_POSTCARD "Placa de diagnóstico" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -395,9 +395,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Erro" IDS_2050 "Erro fatal" IDS_2051 " - PAUSADO" @@ -415,7 +415,7 @@ BEGIN IDS_2063 "A máquina ""%hs"" não está disponível devido à falta de ROMs no diretório roms/machines. Mudando para uma máquina disponível." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "A placa de vídeo ""%hs"" não está disponível devido à falta de ROMs no diretório roms/video. Mudando para uma placa de vídeo disponível." IDS_2065 "Máquina" @@ -435,9 +435,8 @@ BEGIN IDS_2079 "Aperte F8+F12 ou botão do meio para liberar o mouse" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Não foi possível inicializar o FluidSynth" IDS_2081 "Barramento" IDS_2082 "Arquivo" IDS_2083 "CI" @@ -468,7 +467,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disquete %i (%s): %ls" IDS_2110 "Todas as imagens (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Imagens de setor avançado (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Imagens de setor básico (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Imagens de fluxo (*.FDI)\0*.FDI\0Imagens de superfície (*.86F;*.MFM)\0*.86F;*.MFM\0Todos os arquivos (*.*)\0*.*\0" - IDS_2111 "Não foi possível inicializar o FreeType" IDS_2112 "Não é possível inicializar o SDL, é necessário o SDL2.dll" IDS_2113 "Tem certeza de que deseja reiniciar completamente a máquina emulada?" IDS_2114 "Tem certeza de que deseja sair do 86Box?" @@ -496,23 +494,11 @@ BEGIN IDS_2130 "Certifique-se de que " LIB_NAME_PCAP " esteja instalado e que você tenha uma conexão de rede compatível com " LIB_NAME_PCAP "." IDS_2131 "Configuração inválida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " é necessário para emulação de impressora ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " é necessário para a conversão automática de arquivos PostScript para PDF.\n\nQualquer documento enviado para a impressora genérica PostScript será salvo como arquivos PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " é necessário para a saída MIDI FluidSynth." IDS_2135 "Entrando no modo de tela cheia" IDS_2136 "Não exibir esta mensagem novamente" IDS_2137 "Não sair" @@ -540,14 +526,16 @@ BEGIN IDS_2159 "Reinicialização completa" IDS_2160 "Desligamento por ACPI" IDS_2161 "Configurações" - IDS_2162 "Unidade anterior" - IDS_2163 "No Dynarec" - IDS_2164 "Old Dynarec" - IDS_2165 "New Dynarec" - IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2162 "Tipo" + IDS_2163 "Sem recompilador dinâmico" + IDS_2164 "Recompilador dinâmico antigo" + IDS_2165 "Novo recompilador dinâmico" + IDS_2166 "A placa de vídeo #2 ""%hs"" não está disponível devido à ausência de ROMs no diretório roms/video. Desabilitando a segunda placa de vídeo." + IDS_2167 "Falha ao inicializar o driver de rede" + IDS_2168 "A configuração de rede será alterada para o driver nulo" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Disco rígido (%s)" IDS_4097 "%01i:%01i" @@ -646,7 +634,7 @@ BEGIN IDS_7168 "(Padrão do sistema)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Portuguese (pt-BR) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/pt-PT.rc b/src/win/languages/pt-PT.rc index ffdd5f655..00f5af336 100644 --- a/src/win/languages/pt-PT.rc +++ b/src/win/languages/pt-PT.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_PORTUGUESE, SUBLANG_PORTUGUESE // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Ação" BEGIN - MENUITEM "&Teclado requere captura", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Teclado requere captura", IDM_ACTION_KBD_REQ_CAPTURE MENUITEM "&CTRL direito é ALT esquerdo",IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR MENUITEM "&Reinicialização completa...",IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Pausa", IDM_ACTION_PAUSE + MENUITEM "&Pausa", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Sair...", IDM_ACTION_EXIT + MENUITEM "&Sair...", IDM_ACTION_EXIT END POPUP "&Ver" BEGIN - MENUITEM "&Ocultar barra de estado", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Ocultar barra de estado", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Janela redimensionável", IDM_VID_RESIZE - MENUITEM "&Lembrar tamanho e posição", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Janela redimensionável", IDM_VID_RESIZE + MENUITEM "&Lembrar tamanho e posição", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Renderizador" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (Núcleo 3.0)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (Núcleo 3.0)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "&Especificar dimensões...", IDM_VID_SPECIFY_DIM - MENUITEM "&Forçar rácio de visualização 4:3", IDM_VID_FORCE43 + MENUITEM "&Especificar dimensões...", IDM_VID_SPECIFY_DIM + MENUITEM "&Forçar rácio de visualização 4:3", IDM_VID_FORCE43 POPUP "F&actor de escala de janela" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Método de filtragem" BEGIN - MENUITEM "&Mais próximo", IDM_VID_FILTER_NEAREST - MENUITEM "&Linear", IDM_VID_FILTER_LINEAR + MENUITEM "&Mais próximo", IDM_VID_FILTER_NEAREST + MENUITEM "&Linear", IDM_VID_FILTER_LINEAR END - MENUITEM "Escala Hi&DPI", IDM_VID_HIDPI + MENUITEM "Escala Hi&DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "E&crã cheio\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "E&crã cheio\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Modo &de estiramento em ecrã cheio" BEGIN - MENUITEM "&Estiramento em ecrã cheio", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Estiramento em ecrã cheio", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "Pixels &quadrados (Manter rácio)", IDM_VID_FS_KEEPRATIO - MENUITEM "Escala &inteira", IDM_VID_FS_INT + MENUITEM "Escala &inteira", IDM_VID_FS_INT END POPUP "Definições E&GA/(S)VGA" BEGIN - MENUITEM "Monitor VGA &invertido", IDM_VID_INVERT + MENUITEM "Monitor VGA &invertido", IDM_VID_INVERT POPUP "&Tipo de ecrã VGA" BEGIN - MENUITEM "&Cores RGB", IDM_VID_GRAY_RGB - MENUITEM "&RGB em escala de cinzentos", IDM_VID_GRAY_MONO - MENUITEM "Monitor âmb&ar", IDM_VID_GRAY_AMBER - MENUITEM "Monitor &verde", IDM_VID_GRAY_GREEN - MENUITEM "Monitor &branco", IDM_VID_GRAY_WHITE + MENUITEM "&Cores RGB", IDM_VID_GRAY_RGB + MENUITEM "&RGB em escala de cinzentos", IDM_VID_GRAY_MONO + MENUITEM "Monitor âmb&ar", IDM_VID_GRAY_AMBER + MENUITEM "Monitor &verde", IDM_VID_GRAY_GREEN + MENUITEM "Monitor &branco", IDM_VID_GRAY_WHITE END POPUP "Tipo de &conversão para escala de cinzentos" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Media", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Media", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "Overscan de CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "Overscan de CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "Mudar &contraste para ecrã monocromático", IDM_VID_CGACON END - MENUITEM "&Media", IDM_MEDIA + MENUITEM "&Media", IDM_MEDIA POPUP "&Ferramentas" BEGIN - MENUITEM "&Definições...", IDM_CONFIG - MENUITEM "&Atualizar ícones da barra de estado", IDM_UPDATE_ICONS + MENUITEM "&Definições...", IDM_CONFIG + MENUITEM "&Atualizar ícones da barra de estado", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Gravar imagem de ecrã\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Gravar imagem de ecrã\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Preferências...", IDM_PREFERENCES + MENUITEM "&Preferências...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Ativar integração com &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Ganho de som...", IDM_SND_GAIN + MENUITEM "&Ganho de som...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Iniciar o rastreio\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Terminar o rastreio\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Iniciar o rastreio\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Terminar o rastreio\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Ajuda" BEGIN - MENUITEM "&Documentação...", IDM_DOCS - MENUITEM "&Acerca do 86Box...", IDM_ABOUT + MENUITEM "&Documentação...", IDM_DOCS + MENUITEM "&Acerca do 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagem &existente...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "Imagem &existente...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Gravar", IDM_CASSETTE_RECORD - MENUITEM "&Reproduzir", IDM_CASSETTE_PLAY - MENUITEM "Re&bobinar para o início", IDM_CASSETTE_REWIND - MENUITEM "&Avanço rápido para o fim", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Gravar", IDM_CASSETTE_RECORD + MENUITEM "&Reproduzir", IDM_CASSETTE_PLAY + MENUITEM "Re&bobinar para o início", IDM_CASSETTE_REWIND + MENUITEM "&Avanço rápido para o fim", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_CASSETTE_EJECT + MENUITEM "E&jetar", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Imagem...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Imagem...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_CARTRIDGE_EJECT + MENUITEM "E&jetar", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagem &existente...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "Imagem &existente...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&xportar para 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "E&xportar para 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_FLOPPY_EJECT + MENUITEM "E&jetar", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Mute", IDM_CDROM_MUTE + MENUITEM "&Mute", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&CDROM vazio", IDM_CDROM_EMPTY - MENUITEM "&Recarregar imagem anterior", IDM_CDROM_RELOAD + MENUITEM "&CDROM vazio", IDM_CDROM_EMPTY + MENUITEM "&Recarregar imagem anterior", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Imagem...", IDM_CDROM_IMAGE - MENUITEM "&Pasta...", IDM_CDROM_DIR + MENUITEM "&Imagem...", IDM_CDROM_IMAGE + MENUITEM "&Pasta...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagem &existente...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "Imagem &existente...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_ZIP_EJECT - MENUITEM "&Recarregar imagem anterior", IDM_ZIP_RELOAD + MENUITEM "E&jetar", IDM_ZIP_EJECT + MENUITEM "&Recarregar imagem anterior", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova imagem...", IDM_MO_IMAGE_NEW + MENUITEM "&Nova imagem...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "Imagem &existente...", IDM_MO_IMAGE_EXISTING - MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "Imagem &existente...", IDM_MO_IMAGE_EXISTING + MENUITEM "Imagem existente (&Proteção contra escrita)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "E&jetar", IDM_MO_EJECT - MENUITEM "&Recarregar imagem anterior", IDM_MO_RELOAD + MENUITEM "E&jetar", IDM_MO_EJECT + MENUITEM "&Recarregar imagem anterior", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Preferências" -#define STR_SND_GAIN "Ganho de som" -#define STR_NEW_FLOPPY "Nova imagem" +#define STR_PREFERENCES "Preferências" +#define STR_SND_GAIN "Ganho de som" +#define STR_NEW_FLOPPY "Nova imagem" #define STR_CONFIG "Definições" -#define STR_SPECIFY_DIM "Especificar dimensões da janela principal" +#define STR_SPECIFY_DIM "Especificar dimensões da janela principal" #define STR_OK "OK" #define STR_CANCEL "Cancelar" #define STR_GLOBAL "Guardar estas definições como padrões &globais" -#define STR_DEFAULT "&Padrão" -#define STR_LANGUAGE "Idioma:" -#define STR_ICONSET "Pacote de ícones:" +#define STR_DEFAULT "&Padrão" +#define STR_LANGUAGE "Idioma:" +#define STR_ICONSET "Pacote de ícones:" -#define STR_GAIN "Ganho" +#define STR_GAIN "Ganho" -#define STR_FILE_NAME "Nome:" -#define STR_DISK_SIZE "Tamanho:" -#define STR_RPM_MODE "Modo RPM:" -#define STR_PROGRESS "Progresso:" +#define STR_FILE_NAME "Nome:" +#define STR_DISK_SIZE "Tamanho:" +#define STR_RPM_MODE "Modo RPM:" +#define STR_PROGRESS "Progresso:" -#define STR_WIDTH "Largura:" +#define STR_WIDTH "Largura:" #define STR_HEIGHT "Altura:" -#define STR_LOCK_TO_SIZE "Fixar neste tamanho" +#define STR_LOCK_TO_SIZE "Fixar neste tamanho" -#define STR_MACHINE_TYPE "Tipo de máquina:" -#define STR_MACHINE "Máquina:" -#define STR_CONFIGURE "Configurar" -#define STR_CPU_TYPE "Tipo do CPU:" -#define STR_CPU_SPEED "Velocidade:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "Estados de espera:" +#define STR_MACHINE_TYPE "Tipo de máquina:" +#define STR_MACHINE "Máquina:" +#define STR_CONFIGURE "Configurar" +#define STR_CPU_TYPE "Tipo do CPU:" +#define STR_CPU_SPEED "Velocidade:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "Estados de espera:" #define STR_MB "MB" #define STR_MEMORY "Memória:" -#define STR_TIME_SYNC "Sincronização da hora" -#define STR_DISABLED "Desativada" -#define STR_ENABLED_LOCAL "Ativada (hora local)" -#define STR_ENABLED_UTC "Ativada (UTC)" -#define STR_DYNAREC "Recompilador dinâmico" +#define STR_TIME_SYNC "Sincronização da hora" +#define STR_DISABLED "Desativada" +#define STR_ENABLED_LOCAL "Ativada (hora local)" +#define STR_ENABLED_UTC "Ativada (UTC)" +#define STR_DYNAREC "Recompilador dinâmico" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Vídeo:" -#define STR_VIDEO_2 "Vídeo 2:" +#define STR_VIDEO "Vídeo:" +#define STR_VIDEO_2 "Vídeo 2:" #define STR_VOODOO "Gráficos Voodoo" -#define STR_IBM8514 "Gráficos IBM 8514/a" -#define STR_XGA "Gráficos XGA" +#define STR_IBM8514 "Gráficos IBM 8514/a" +#define STR_XGA "Gráficos XGA" -#define STR_MOUSE "Rato:" -#define STR_JOYSTICK "Joystick:" -#define STR_JOY1 "Joystick 1..." -#define STR_JOY2 "Joystick 2..." -#define STR_JOY3 "Joystick 3..." -#define STR_JOY4 "Joystick 4..." +#define STR_MOUSE "Rato:" +#define STR_JOYSTICK "Joystick:" +#define STR_JOY1 "Joystick 1..." +#define STR_JOY2 "Joystick 2..." +#define STR_JOY3 "Joystick 3..." +#define STR_JOY4 "Joystick 4..." #define STR_SOUND1 "Placa de som 1:" #define STR_SOUND2 "Placa de som 2:" #define STR_SOUND3 "Placa de som 3:" #define STR_SOUND4 "Placa de som 4:" -#define STR_MIDI_OUT "Disp. saída MIDI:" -#define STR_MIDI_IN "Disp. entrada MIDI:" +#define STR_MIDI_OUT "Disp. saída MIDI:" +#define STR_MIDI_IN "Disp. entrada MIDI:" #define STR_MPU401 "MPU-401 autónomo" -#define STR_FLOAT "Utilizar som FLOAT32" -#define STR_FM_DRIVER "Controlador de sint. FM" -#define STR_FM_DRV_NUKED "Nuked (mais exacto)" -#define STR_FM_DRV_YMFM "YMFM (mais rápido)" +#define STR_FLOAT "Utilizar som FLOAT32" +#define STR_FM_DRIVER "Controlador de sint. FM" +#define STR_FM_DRV_NUKED "Nuked (mais exacto)" +#define STR_FM_DRV_YMFM "YMFM (mais rápido)" -#define STR_NET_TYPE "Tipo de rede:" -#define STR_PCAP "Dispositivo PCap:" -#define STR_NET "Placa de rede:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Tipo de rede:" +#define STR_PCAP "Dispositivo PCap:" +#define STR_NET "Placa de rede:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Dispositivo COM1:" -#define STR_COM2 "Dispositivo COM2:" -#define STR_COM3 "Dispositivo COM3:" -#define STR_COM4 "Dispositivo COM4:" -#define STR_LPT1 "Dispositivo LPT1:" -#define STR_LPT2 "Dispositivo LPT2:" -#define STR_LPT3 "Dispositivo LPT3:" -#define STR_LPT4 "Dispositivo LPT4:" -#define STR_SERIAL1 "Porta de série 1" -#define STR_SERIAL2 "Porta de série 2" -#define STR_SERIAL3 "Porta de série 3" -#define STR_SERIAL4 "Porta de série 4" -#define STR_PARALLEL1 "Porta paralela 1" -#define STR_PARALLEL2 "Porta paralela 2" -#define STR_PARALLEL3 "Porta paralela 3" -#define STR_PARALLEL4 "Porta paralela 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Dispositivo COM1:" +#define STR_COM2 "Dispositivo COM2:" +#define STR_COM3 "Dispositivo COM3:" +#define STR_COM4 "Dispositivo COM4:" +#define STR_LPT1 "Dispositivo LPT1:" +#define STR_LPT2 "Dispositivo LPT2:" +#define STR_LPT3 "Dispositivo LPT3:" +#define STR_LPT4 "Dispositivo LPT4:" +#define STR_SERIAL1 "Porta de série 1" +#define STR_SERIAL2 "Porta de série 2" +#define STR_SERIAL3 "Porta de série 3" +#define STR_SERIAL4 "Porta de série 4" +#define STR_PARALLEL1 "Porta paralela 1" +#define STR_PARALLEL2 "Porta paralela 2" +#define STR_PARALLEL3 "Porta paralela 3" +#define STR_PARALLEL4 "Porta paralela 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Controlador HD:" -#define STR_FDC "Controlador FD:" -#define STR_IDE_TER "Controlador IDE terciário" -#define STR_IDE_QUA "Controlador IDE quaternário" -#define STR_SCSI "SCSI" +#define STR_HDC "Controlador HD:" +#define STR_FDC "Controlador FD:" +#define STR_IDE_TER "Controlador IDE terciário" +#define STR_IDE_QUA "Controlador IDE quaternário" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Controlador 1:" #define STR_SCSI_2 "Controlador 2:" #define STR_SCSI_3 "Controlador 3:" #define STR_SCSI_4 "Controlador 4:" -#define STR_CASSETTE "Cassete" +#define STR_CASSETTE "Cassete" -#define STR_HDD "Discos rígidos:" -#define STR_NEW "&Novo..." -#define STR_EXISTING "&Existente..." +#define STR_HDD "Discos rígidos:" +#define STR_NEW "&Novo..." +#define STR_EXISTING "&Existente..." #define STR_REMOVE "&Remover" -#define STR_BUS "Barram.:" -#define STR_CHANNEL "Canal:" +#define STR_BUS "Barram.:" +#define STR_CHANNEL "Canal:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Especificar..." -#define STR_SECTORS "Sectores:" -#define STR_HEADS "Cabeças:" -#define STR_CYLS "Cilindros:" -#define STR_SIZE_MB "Tamanho (MB):" -#define STR_TYPE "Tipo:" -#define STR_IMG_FORMAT "Formato de imagem:" -#define STR_BLOCK_SIZE "Tamanho de bloco:" +#define STR_SPECIFY "&Especificar..." +#define STR_SECTORS "Sectores:" +#define STR_HEADS "Cabeças:" +#define STR_CYLS "Cilindros:" +#define STR_SIZE_MB "Tamanho (MB):" +#define STR_TYPE "Tipo:" +#define STR_IMG_FORMAT "Formato de imagem:" +#define STR_BLOCK_SIZE "Tamanho de bloco:" -#define STR_FLOPPY_DRIVES "Unidades de disquete:" -#define STR_TURBO "Velocidade turbo" -#define STR_CHECKBPB "Verificar BPB" -#define STR_CDROM_DRIVES "Unidades CD-ROM:" -#define STR_CD_SPEED "Velocidade:" -#define STR_EARLY "Unidade anterior" +#define STR_FLOPPY_DRIVES "Unidades de disquete:" +#define STR_TURBO "Velocidade turbo" +#define STR_CHECKBPB "Verificar BPB" +#define STR_CDROM_DRIVES "Unidades CD-ROM:" +#define STR_CD_SPEED "Velocidade:" -#define STR_MO_DRIVES "Unidades magneto-ópticas:" -#define STR_ZIP_DRIVES "Unidades ZIP:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Unidades magneto-ópticas:" +#define STR_ZIP_DRIVES "Unidades ZIP:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC:" #define STR_ISAMEM "Expansão de memória ISA" -#define STR_ISAMEM_1 "Placa 1:" -#define STR_ISAMEM_2 "Placa 2:" -#define STR_ISAMEM_3 "Placa 3:" -#define STR_ISAMEM_4 "Placa 4:" +#define STR_ISAMEM_1 "Placa 1:" +#define STR_ISAMEM_2 "Placa 2:" +#define STR_ISAMEM_3 "Placa 3:" +#define STR_ISAMEM_4 "Placa 4:" #define STR_BUGGER "Dispositivo ISABugger" -#define STR_POSTCARD "Placa POST" +#define STR_POSTCARD "Placa POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Erro" IDS_2050 "Erro fatal" IDS_2051 " - PAUSED" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "A máquina ""%hs"" não está disponível devido à falta de ROMs na pasta roms/machines. A mudar para uma máquina disponível." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "A placa vídeo ""%hs"" não está disponível devido à falta de ROMs na pasta roms/video. A mudar para uma placa vídeo disponível." IDS_2065 "Máquina" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Pressione F8+F12 ou tecla média para soltar o rato" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Não foi possível inicializar o FluidSynth" IDS_2081 "Barramento" IDS_2082 "Ficheiro" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CCS: %i, %i, %i)" IDS_2109 "Disquete %i (%s): %ls" IDS_2110 "Todas as imagens (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Imagens avançadas de sector (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Imagens básicas de sector (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Imagens de fluxo (*.FDI)\0*.FDI\0Imagens de superfície (*.86F;*.MFM)\0*.86F;*.MFM\0Todos os ficheiros (*.*)\0*.*\0" - IDS_2111 "Não foi possível inicializar o FreeType" IDS_2112 "Não foi possível inicializar o SDL. O ficheiro SDL2.dll é necessário!" IDS_2113 "Tem a certeza de que quer um reinício completo da máquina emulada?" IDS_2114 "Tem a certeza de que quer sair do 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Certifique-se de que a biblioteca " LIB_NAME_PCAP " está instalada e de que está a utilizar uma ligação de rede compatível com a biblioteca " LIB_NAME_PCAP "." IDS_2131 "Configuração inválida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " é requerida para a emulação de impressora ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " é requerido para a conversão automática de ficheiros PostScript para ficheiros PDF.\n\nQualquer documento enviado para a impressora PostScript genérica será gravado como um ficheiro PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " é necessário para a saída MIDI FluidSynth MIDI." IDS_2135 "A entrar no modo de ecrã cheio" IDS_2136 "Não mostrar mais esta mensagem" IDS_2137 "Não sair" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Reinicialização completa" IDS_2160 "Encerramento ACPI" IDS_2161 "Definições" - IDS_2162 "Unidade anterior" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Disco rígido (%s)" IDS_4097 "%01i:%01i" diff --git a/src/win/languages/ru-RU.rc b/src/win/languages/ru-RU.rc index f66923b57..458b0e874 100644 --- a/src/win/languages/ru-RU.rc +++ b/src/win/languages/ru-RU.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Действие" BEGIN - MENUITEM "&Клавиатура требует захвата", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Правый CTRL - это левый ALT", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Клавиатура требует захвата", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Правый CTRL - это левый ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Холодная перезагрузка...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Холодная перезагрузка...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Пауза", IDM_ACTION_PAUSE + MENUITEM "&Пауза", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Выход...", IDM_ACTION_EXIT + MENUITEM "&Выход...", IDM_ACTION_EXIT END POPUP "&Вид" BEGIN - MENUITEM "&Скрыть строку состояния", IDM_VID_HIDE_STATUS_BAR - MENUITEM "С&крыть панель инструментов", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Скрыть строку состояния", IDM_VID_HIDE_STATUS_BAR + MENUITEM "С&крыть панель инструментов", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Изменяемый размер окна", IDM_VID_RESIZE - MENUITEM "&Запомнить размер и положение", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Изменяемый размер окна", IDM_VID_RESIZE + MENUITEM "&Запомнить размер и положение", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Рендеринг" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "&Указать размеры...", IDM_VID_SPECIFY_DIM - MENUITEM "У&становить соотношение сторон 4:3", IDM_VID_FORCE43 + MENUITEM "&Указать размеры...", IDM_VID_SPECIFY_DIM + MENUITEM "У&становить соотношение сторон 4:3", IDM_VID_FORCE43 POPUP "&Масштаб окна" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Метод фильтрации" BEGIN - MENUITEM "&Ближайший", IDM_VID_FILTER_NEAREST - MENUITEM "&Линейный", IDM_VID_FILTER_LINEAR + MENUITEM "&Ближайший", IDM_VID_FILTER_NEAREST + MENUITEM "&Линейный", IDM_VID_FILTER_LINEAR END - MENUITEM "Масштабирование Hi&DPI", IDM_VID_HIDPI + MENUITEM "Масштабирование Hi&DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Полноэкранный режим\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Полноэкранный режим\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "&Растягивание в полноэкранном режиме" BEGIN - MENUITEM "&На весь экран", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&На весь экран", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Квадратные пиксели (сохранить соотношение)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Целочисленное масштабирование", IDM_VID_FS_INT + MENUITEM "&Целочисленное масштабирование", IDM_VID_FS_INT END POPUP "Настройки E&GA/(S)VGA" BEGIN - MENUITEM "&Инвертировать цвета VGA", IDM_VID_INVERT + MENUITEM "&Инвертировать цвета VGA", IDM_VID_INVERT POPUP "&Тип экрана VGA" BEGIN - MENUITEM "RGB &цветной", IDM_VID_GRAY_RGB - MENUITEM "&RGB монохромный", IDM_VID_GRAY_MONO - MENUITEM "&Янтарный оттенок", IDM_VID_GRAY_AMBER - MENUITEM "&Зелёный оттенок", IDM_VID_GRAY_GREEN - MENUITEM "&Белый оттенок", IDM_VID_GRAY_WHITE + MENUITEM "RGB &цветной", IDM_VID_GRAY_RGB + MENUITEM "&RGB монохромный", IDM_VID_GRAY_MONO + MENUITEM "&Янтарный оттенок", IDM_VID_GRAY_AMBER + MENUITEM "&Зелёный оттенок", IDM_VID_GRAY_GREEN + MENUITEM "&Белый оттенок", IDM_VID_GRAY_WHITE END POPUP "Тип монохромного &конвертирования" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Усреднённый", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Усреднённый", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "Вылеты развёртки CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "Вылеты развёртки CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "Изменить контрастность &монохромного дисплея", IDM_VID_CGACON END - MENUITEM "&Носители", IDM_MEDIA + MENUITEM "&Носители", IDM_MEDIA POPUP "&Инструменты" BEGIN - MENUITEM "&Настройки машины...", IDM_CONFIG - MENUITEM "&Обновление значков строки состояния", IDM_UPDATE_ICONS + MENUITEM "&Настройки машины...", IDM_CONFIG + MENUITEM "&Обновление значков строки состояния", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Сделать с&криншот\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Сделать с&криншот\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Параметры...", IDM_PREFERENCES + MENUITEM "&Параметры...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Включить интеграцию &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Усиление звука...", IDM_SND_GAIN + MENUITEM "&Усиление звука...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Начать трассировку\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Завершить трассировку\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Начать трассировку\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Завершить трассировку\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Помощь" BEGIN - MENUITEM "&Документация...", IDM_DOCS - MENUITEM "&О программе 86Box...", IDM_ABOUT + MENUITEM "&Документация...", IDM_DOCS + MENUITEM "&О программе 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новый образ...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Новый образ...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Выбрать образ...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Выбрать образ (&Защита от записи)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Выбрать образ...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Выбрать образ (&Защита от записи)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Запись", IDM_CASSETTE_RECORD - MENUITEM "&Воспроизведение", IDM_CASSETTE_PLAY - MENUITEM "&Перемотка на начало", IDM_CASSETTE_REWIND - MENUITEM "&Перемотка в конец", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Запись", IDM_CASSETTE_RECORD + MENUITEM "&Воспроизведение", IDM_CASSETTE_PLAY + MENUITEM "&Перемотка на начало", IDM_CASSETTE_REWIND + MENUITEM "&Перемотка в конец", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "И&звлечь", IDM_CASSETTE_EJECT + MENUITEM "И&звлечь", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Образ...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Образ...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "И&звлечь", IDM_CARTRIDGE_EJECT + MENUITEM "И&звлечь", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новый образ...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Новый образ...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Выбрать образ...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Выбрать образ (&Защита от записи)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Выбрать образ...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Выбрать образ (&Защита от записи)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "Э&кспорт в 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "Э&кспорт в 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "И&звлечь", IDM_FLOPPY_EJECT + MENUITEM "И&звлечь", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "О&тключить звук", IDM_CDROM_MUTE + MENUITEM "О&тключить звук", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "П&устой", IDM_CDROM_EMPTY - MENUITEM "&Снова загрузить предыдущий образ", IDM_CDROM_RELOAD + MENUITEM "П&устой", IDM_CDROM_EMPTY + MENUITEM "&Снова загрузить предыдущий образ", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Образ...", IDM_CDROM_IMAGE - MENUITEM "&Папка...", IDM_CDROM_DIR + MENUITEM "&Образ...", IDM_CDROM_IMAGE + MENUITEM "&Папка...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новый образ...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Новый образ...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Выбрать образ...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Выбрать образ (&Защита от записи)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Выбрать образ...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Выбрать образ (&Защита от записи)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "И&звлечь", IDM_ZIP_EJECT - MENUITEM "&Снова загрузить предыдущий образ", IDM_ZIP_RELOAD + MENUITEM "И&звлечь", IDM_ZIP_EJECT + MENUITEM "&Снова загрузить предыдущий образ", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новый образ...", IDM_MO_IMAGE_NEW + MENUITEM "&Новый образ...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Выбрать образ...", IDM_MO_IMAGE_EXISTING - MENUITEM "Выбрать образ (&Защита от записи)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Выбрать образ...", IDM_MO_IMAGE_EXISTING + MENUITEM "Выбрать образ (&Защита от записи)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "И&звлечь", IDM_MO_EJECT - MENUITEM "&Снова загрузить предыдущий образ", IDM_MO_RELOAD + MENUITEM "И&звлечь", IDM_MO_EJECT + MENUITEM "&Снова загрузить предыдущий образ", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Параметры" -#define STR_SND_GAIN "Усиление звука" -#define STR_NEW_FLOPPY "Новый образ" +#define STR_PREFERENCES "Параметры" +#define STR_SND_GAIN "Усиление звука" +#define STR_NEW_FLOPPY "Новый образ" #define STR_CONFIG "Настройки" -#define STR_SPECIFY_DIM "Указать размеры главного окна" +#define STR_SPECIFY_DIM "Указать размеры главного окна" #define STR_OK "OK" #define STR_CANCEL "Отмена" #define STR_GLOBAL "Сохранить эти параметры как &глобальные по умолчанию" -#define STR_DEFAULT "&По умолчанию" -#define STR_LANGUAGE "Язык:" -#define STR_ICONSET "Набор иконок:" +#define STR_DEFAULT "&По умолчанию" +#define STR_LANGUAGE "Язык:" +#define STR_ICONSET "Набор иконок:" -#define STR_GAIN "Усиление" +#define STR_GAIN "Усиление" -#define STR_FILE_NAME "Имя файла:" -#define STR_DISK_SIZE "Размер диска:" -#define STR_RPM_MODE "RPM режим:" -#define STR_PROGRESS "Прогресс:" +#define STR_FILE_NAME "Имя файла:" +#define STR_DISK_SIZE "Размер диска:" +#define STR_RPM_MODE "RPM режим:" +#define STR_PROGRESS "Прогресс:" -#define STR_WIDTH "Ширина:" +#define STR_WIDTH "Ширина:" #define STR_HEIGHT "Высота:" -#define STR_LOCK_TO_SIZE "Зафиксировать размер" +#define STR_LOCK_TO_SIZE "Зафиксировать размер" -#define STR_MACHINE_TYPE "Тип машины:" -#define STR_MACHINE "Системная плата:" -#define STR_CONFIGURE "Настройка" -#define STR_CPU_TYPE "Тип ЦП:" -#define STR_CPU_SPEED "Скорость:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "Циклы ожидания:" +#define STR_MACHINE_TYPE "Тип машины:" +#define STR_MACHINE "Системная плата:" +#define STR_CONFIGURE "Настройка" +#define STR_CPU_TYPE "Тип ЦП:" +#define STR_CPU_SPEED "Скорость:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "Циклы ожидания:" #define STR_MB "МБ" #define STR_MEMORY "Память:" -#define STR_TIME_SYNC "Синхронизация времени" -#define STR_DISABLED "Отключить" -#define STR_ENABLED_LOCAL "Включить (местное)" -#define STR_ENABLED_UTC "Включить (UTC)" -#define STR_DYNAREC "Динамический рекомпилятор" +#define STR_TIME_SYNC "Синхронизация времени" +#define STR_DISABLED "Отключить" +#define STR_ENABLED_LOCAL "Включить (местное)" +#define STR_ENABLED_UTC "Включить (UTC)" +#define STR_DYNAREC "Динамический рекомпилятор" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Видеокарта:" -#define STR_VIDEO_2 "Видеокарта 2:" +#define STR_VIDEO "Видеокарта:" +#define STR_VIDEO_2 "Видеокарта 2:" #define STR_VOODOO "Ускоритель Voodoo" -#define STR_IBM8514 "Ускоритель IBM 8514/a" -#define STR_XGA "Ускоритель XGA" +#define STR_IBM8514 "Ускоритель IBM 8514/a" +#define STR_XGA "Ускоритель XGA" -#define STR_MOUSE "Мышь:" -#define STR_JOYSTICK "Джойстик:" -#define STR_JOY1 "Джойстик 1..." -#define STR_JOY2 "Джойстик 2..." -#define STR_JOY3 "Джойстик 3..." -#define STR_JOY4 "Джойстик 4..." +#define STR_MOUSE "Мышь:" +#define STR_JOYSTICK "Джойстик:" +#define STR_JOY1 "Джойстик 1..." +#define STR_JOY2 "Джойстик 2..." +#define STR_JOY3 "Джойстик 3..." +#define STR_JOY4 "Джойстик 4..." #define STR_SOUND1 "Звуковая карта 1:" #define STR_SOUND2 "Звуковая карта 2:" #define STR_SOUND3 "Звуковая карта 3:" #define STR_SOUND4 "Звуковая карта 4:" -#define STR_MIDI_OUT "MIDI Out устр-во:" -#define STR_MIDI_IN "MIDI In устр-во:" +#define STR_MIDI_OUT "MIDI Out устр-во:" +#define STR_MIDI_IN "MIDI In устр-во:" #define STR_MPU401 "Отдельный MPU-401" -#define STR_FLOAT "FLOAT32 звук" -#define STR_FM_DRIVER "Драйвер FM-синтезатора" -#define STR_FM_DRV_NUKED "Nuked (более точный)" -#define STR_FM_DRV_YMFM "YMFM (быстрей)" +#define STR_FLOAT "FLOAT32 звук" +#define STR_FM_DRIVER "Драйвер FM-синтезатора" +#define STR_FM_DRV_NUKED "Nuked (более точный)" +#define STR_FM_DRV_YMFM "YMFM (быстрей)" -#define STR_NET_TYPE "Тип сети:" -#define STR_PCAP "Устройство PCap:" -#define STR_NET "Сетевая карта:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Тип сети:" +#define STR_PCAP "Устройство PCap:" +#define STR_NET "Сетевая карта:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Устройство COM1:" -#define STR_COM2 "Устройство COM2:" -#define STR_COM3 "Устройство COM3:" -#define STR_COM4 "Устройство COM4:" -#define STR_LPT1 "Устройство LPT1:" -#define STR_LPT2 "Устройство LPT2:" -#define STR_LPT3 "Устройство LPT3:" -#define STR_LPT4 "Устройство LPT4:" -#define STR_SERIAL1 "Последов. порт COM1" -#define STR_SERIAL2 "Последов. порт COM2" -#define STR_SERIAL3 "Последов. порт COM3" -#define STR_SERIAL4 "Последов. порт COM4" -#define STR_PARALLEL1 "Параллельный порт LPT1" -#define STR_PARALLEL2 "Параллельный порт LPT2" -#define STR_PARALLEL3 "Параллельный порт LPT3" -#define STR_PARALLEL4 "Параллельный порт LPT4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Устройство COM1:" +#define STR_COM2 "Устройство COM2:" +#define STR_COM3 "Устройство COM3:" +#define STR_COM4 "Устройство COM4:" +#define STR_LPT1 "Устройство LPT1:" +#define STR_LPT2 "Устройство LPT2:" +#define STR_LPT3 "Устройство LPT3:" +#define STR_LPT4 "Устройство LPT4:" +#define STR_SERIAL1 "Последов. порт COM1" +#define STR_SERIAL2 "Последов. порт COM2" +#define STR_SERIAL3 "Последов. порт COM3" +#define STR_SERIAL4 "Последов. порт COM4" +#define STR_PARALLEL1 "Параллельный порт LPT1" +#define STR_PARALLEL2 "Параллельный порт LPT2" +#define STR_PARALLEL3 "Параллельный порт LPT3" +#define STR_PARALLEL4 "Параллельный порт LPT4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Контроллер HD:" -#define STR_FDC "Контроллер FD:" -#define STR_IDE_TER "Третичный IDE контроллер" -#define STR_IDE_QUA "Четвертичный IDE контроллер" -#define STR_SCSI "SCSI" +#define STR_HDC "Контроллер HD:" +#define STR_FDC "Контроллер FD:" +#define STR_IDE_TER "Третичный IDE контроллер" +#define STR_IDE_QUA "Четвертичный IDE контроллер" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Контроллер 1:" #define STR_SCSI_2 "Контроллер 2:" #define STR_SCSI_3 "Контроллер 3:" #define STR_SCSI_4 "Контроллер 4:" -#define STR_CASSETTE "Кассета" +#define STR_CASSETTE "Кассета" -#define STR_HDD "Жёсткие диски:" -#define STR_NEW "&Создать..." -#define STR_EXISTING "&Выбрать..." +#define STR_HDD "Жёсткие диски:" +#define STR_NEW "&Создать..." +#define STR_EXISTING "&Выбрать..." #define STR_REMOVE "&Убрать" -#define STR_BUS "Шина:" -#define STR_CHANNEL "Канал:" +#define STR_BUS "Шина:" +#define STR_CHANNEL "Канал:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Указать..." -#define STR_SECTORS "Сектора:" -#define STR_HEADS "Головки:" -#define STR_CYLS "Цилиндры:" -#define STR_SIZE_MB "Размер (МБ):" -#define STR_TYPE "Тип:" -#define STR_IMG_FORMAT "Тип образа:" -#define STR_BLOCK_SIZE "Размер блока:" +#define STR_SPECIFY "&Указать..." +#define STR_SECTORS "Сектора:" +#define STR_HEADS "Головки:" +#define STR_CYLS "Цилиндры:" +#define STR_SIZE_MB "Размер (МБ):" +#define STR_TYPE "Тип:" +#define STR_IMG_FORMAT "Тип образа:" +#define STR_BLOCK_SIZE "Размер блока:" -#define STR_FLOPPY_DRIVES "Гибкие диски:" -#define STR_TURBO "Турбо тайминги" -#define STR_CHECKBPB "Проверять BPB" -#define STR_CDROM_DRIVES "Дисководы CD-ROM:" -#define STR_CD_SPEED "Скорость:" -#define STR_EARLY "Предыдущий дисковод" +#define STR_FLOPPY_DRIVES "Гибкие диски:" +#define STR_TURBO "Турбо тайминги" +#define STR_CHECKBPB "Проверять BPB" +#define STR_CDROM_DRIVES "Дисководы CD-ROM:" +#define STR_CD_SPEED "Скорость:" -#define STR_MO_DRIVES "Магнитооптические дисководы:" -#define STR_ZIP_DRIVES "ZIP дисководы:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Магнитооптические дисководы:" +#define STR_ZIP_DRIVES "ZIP дисководы:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC:" #define STR_ISAMEM "Карта расширения памяти (ISA)" -#define STR_ISAMEM_1 "Карта 1:" -#define STR_ISAMEM_2 "Карта 2:" -#define STR_ISAMEM_3 "Карта 3:" -#define STR_ISAMEM_4 "Карта 4:" +#define STR_ISAMEM_1 "Карта 1:" +#define STR_ISAMEM_2 "Карта 2:" +#define STR_ISAMEM_3 "Карта 3:" +#define STR_ISAMEM_4 "Карта 4:" #define STR_BUGGER "Устройство ISABugger" -#define STR_POSTCARD "Карта POST" +#define STR_POSTCARD "Карта POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Ошибка" IDS_2050 "Неустранимая ошибка" IDS_2051 " - ПАУЗА" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Системная плата ""%hs"" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/machines. Переключение на доступную системную плату." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Видеокарта ""%hs"" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/video. Переключение на доступную видеокарту." IDS_2065 "Компьютер" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Нажмите F8+F12 или среднюю кнопку мыши чтобы освободить курсор" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Невозможно инициализировать FluidSynth" IDS_2081 "Шина" IDS_2082 "Файл" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u МБ (CHS: %i, %i, %i)" IDS_2109 "Дисковод %i (%s): %ls" IDS_2110 "Все образы (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Расширенные образы секторов (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Основные образы секторов (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Образы Flux (*.FDI)\0*.FDI\0Образы Surface (*.86F;*.MFM)\0*.86F;*.MFM\0Все файлы (*.*)\0*.*\0" - IDS_2111 "Невозможно инициализировать FreeType" IDS_2112 "Невозможно инициализировать SDL, требуется SDL2.dll" IDS_2113 "Вы уверены, что хотите выполнить холодную перезагрузку эмулируемой машины?" IDS_2114 "Вы уверены, что хотите выйти из 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Убедитесь, что " LIB_NAME_PCAP " установлен и ваше сетевое соединение, совместимо с " LIB_NAME_PCAP "." IDS_2131 "Недопустимая конфигурация" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "Для эмуляции принтера ESC/P требуется " LIB_NAME_FREETYPE "." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " требуется для автоматического преобразования файлов PostScript в PDF.\n\nВсе документы, отправленные на общий принтер PostScript, будут сохранены в виде файлов PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "Для FluidSynth MIDI-вывода требуется " LIB_NAME_FLUIDSYNTH "." IDS_2135 "Вход в полноэкранный режим" IDS_2136 "Больше не показывать это сообщение" IDS_2137 "Не выходить" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Холодная перезагрузка" IDS_2160 "Сигнал завершения ACPI" IDS_2161 "Настройки машины" - IDS_2162 "Предыдущий дисковод" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Жёсткий диск (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Системный)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Russian resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/sl-SI.rc b/src/win/languages/sl-SI.rc index 671d8191b..f9d2fb82a 100644 --- a/src/win/languages/sl-SI.rc +++ b/src/win/languages/sl-SI.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_SLOVENIAN, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Dejanja" BEGIN - MENUITEM "&Tipkovnica potrebuje zajem", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Desni CTRL je levi ALT", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Tipkovnica potrebuje zajem", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Desni CTRL je levi ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Ponovni zagon...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Ponovni zagon...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Premor", IDM_ACTION_PAUSE + MENUITEM "&Premor", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "Iz&hod...", IDM_ACTION_EXIT + MENUITEM "Iz&hod...", IDM_ACTION_EXIT END POPUP "&Pogled" BEGIN - MENUITEM "&Skrij statusno vrstico", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Skrij statusno vrstico", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "S&premenljiva velikost okna", IDM_VID_RESIZE - MENUITEM "&Zapomni si velikost in položaj", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "S&premenljiva velikost okna", IDM_VID_RESIZE + MENUITEM "&Zapomni si velikost in položaj", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Upodabljanje" BEGIN - MENUITEM "&SDL (programsko)", IDM_VID_SDL_SW - MENUITEM "SDL (s&trojno)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (Jedro 3.0)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (programsko)", IDM_VID_SDL_SW + MENUITEM "SDL (s&trojno)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (Jedro 3.0)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "&Določi velikost...", IDM_VID_SPECIFY_DIM - MENUITEM "&Vsili 4:3 razmerje zaslona", IDM_VID_FORCE43 + MENUITEM "&Določi velikost...", IDM_VID_SPECIFY_DIM + MENUITEM "&Vsili 4:3 razmerje zaslona", IDM_VID_FORCE43 POPUP "&Faktor velikosti okna" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "&Metoda filtriranja" BEGIN - MENUITEM "&Najbližja", IDM_VID_FILTER_NEAREST - MENUITEM "&Linearna", IDM_VID_FILTER_LINEAR + MENUITEM "&Najbližja", IDM_VID_FILTER_NEAREST + MENUITEM "&Linearna", IDM_VID_FILTER_LINEAR END - MENUITEM "&Raztezanje za visok DPI", IDM_VID_HIDPI + MENUITEM "&Raztezanje za visok DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Celozaslonski način\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Celozaslonski način\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "&Način celozaslonskega raztezanja" BEGIN - MENUITEM "&Raztegni na celoten zaslon", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Raztegni na celoten zaslon", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Kvadratni piksli (ohrani razmerje)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Celoštevilsko raztezanje", IDM_VID_FS_INT + MENUITEM "&Celoštevilsko raztezanje", IDM_VID_FS_INT END POPUP "Nastavitve E&GA/(S)VGA" BEGIN - MENUITEM "&Obrni barve zaslona VGA", IDM_VID_INVERT + MENUITEM "&Obrni barve zaslona VGA", IDM_VID_INVERT POPUP "&Vrsta zaslona VGA" BEGIN - MENUITEM "&Barvni RGB", IDM_VID_GRAY_RGB - MENUITEM "&Sivinski RGB", IDM_VID_GRAY_MONO - MENUITEM "&Rumeni zaslon", IDM_VID_GRAY_AMBER - MENUITEM "&Zeleni zaslon", IDM_VID_GRAY_GREEN - MENUITEM "B&eli zaslon", IDM_VID_GRAY_WHITE + MENUITEM "&Barvni RGB", IDM_VID_GRAY_RGB + MENUITEM "&Sivinski RGB", IDM_VID_GRAY_MONO + MENUITEM "&Rumeni zaslon", IDM_VID_GRAY_AMBER + MENUITEM "&Zeleni zaslon", IDM_VID_GRAY_GREEN + MENUITEM "B&eli zaslon", IDM_VID_GRAY_WHITE END POPUP "V&rsta pretvorbe sivin" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Povprečje", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Povprečje", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "&Presežek slike CGA/PCjr/Tandy/EGA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "&Presežek slike CGA/PCjr/Tandy/EGA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "&Spremeni contrast za črno-beli zaslon", IDM_VID_CGACON END - MENUITEM "&Mediji", IDM_MEDIA + MENUITEM "&Mediji", IDM_MEDIA POPUP "&Orodja" BEGIN - MENUITEM "&Nastavitve...", IDM_CONFIG - MENUITEM "&Posodabljaj ikone statusne vrstice", IDM_UPDATE_ICONS + MENUITEM "&Nastavitve...", IDM_CONFIG + MENUITEM "&Posodabljaj ikone statusne vrstice", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "&Zajemi posnetek zaslona\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "&Zajemi posnetek zaslona\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Možnosti...", IDM_PREFERENCES + MENUITEM "&Možnosti...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Omogoči integracijo s programom &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Ojačanje zvoka...", IDM_SND_GAIN + MENUITEM "&Ojačanje zvoka...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Z&ačni sledenje\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "&Končaj sledenje\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Z&ačni sledenje\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "&Končaj sledenje\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Pomoč" BEGIN - MENUITEM "&Dokumentacija...", IDM_DOCS - MENUITEM "&O programu 86Box...", IDM_ABOUT + MENUITEM "&Dokumentacija...", IDM_DOCS + MENUITEM "&O programu 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Obstoječa slika...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Obstoječa slika (&samo za branje)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Obstoječa slika...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Obstoječa slika (&samo za branje)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "Snemaj", IDM_CASSETTE_RECORD - MENUITEM "Predvajaj", IDM_CASSETTE_PLAY - MENUITEM "Previj na začetek", IDM_CASSETTE_REWIND - MENUITEM "Preskoči na konec", IDM_CASSETTE_FAST_FORWARD + MENUITEM "Snemaj", IDM_CASSETTE_RECORD + MENUITEM "Predvajaj", IDM_CASSETTE_PLAY + MENUITEM "Previj na začetek", IDM_CASSETTE_REWIND + MENUITEM "Preskoči na konec", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "Izvrzi", IDM_CASSETTE_EJECT + MENUITEM "Izvrzi", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "Slika...", IDM_CARTRIDGE_IMAGE + MENUITEM "Slika...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "Izvrzi", IDM_CARTRIDGE_EJECT + MENUITEM "Izvrzi", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Obstoječa slika...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Obstoječa slika (&samo za branje)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Obstoječa slika...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Obstoječa slika (&samo za branje)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Izvozi v 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "&Izvozi v 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "I&zvrzi", IDM_FLOPPY_EJECT + MENUITEM "I&zvrzi", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Utišaj", IDM_CDROM_MUTE + MENUITEM "&Utišaj", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&Prazen", IDM_CDROM_EMPTY - MENUITEM "&Naloži zadnjo sliko", IDM_CDROM_RELOAD + MENUITEM "&Prazen", IDM_CDROM_EMPTY + MENUITEM "&Naloži zadnjo sliko", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Slika...", IDM_CDROM_IMAGE - MENUITEM "&Mapa...", IDM_CDROM_DIR + MENUITEM "&Slika...", IDM_CDROM_IMAGE + MENUITEM "&Mapa...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Obstoječa slika...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Obstoječa slika (&samo za branje)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Obstoječa slika...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Obstoječa slika (&samo za branje)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "I&zvrzi", IDM_ZIP_EJECT - MENUITEM "&Naloži zadnjo sliko", IDM_ZIP_RELOAD + MENUITEM "I&zvrzi", IDM_ZIP_EJECT + MENUITEM "&Naloži zadnjo sliko", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Nova slika...", IDM_MO_IMAGE_NEW + MENUITEM "&Nova slika...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Obstoječa slika...", IDM_MO_IMAGE_EXISTING - MENUITEM "Obstoječa slika (&samo za branje)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Obstoječa slika...", IDM_MO_IMAGE_EXISTING + MENUITEM "Obstoječa slika (&samo za branje)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "I&zvrzi", IDM_MO_EJECT - MENUITEM "&Naloži zadnjo sliko", IDM_MO_RELOAD + MENUITEM "I&zvrzi", IDM_MO_EJECT + MENUITEM "&Naloži zadnjo sliko", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Možnosti" -#define STR_SND_GAIN "Ojačanje zvoka" -#define STR_NEW_FLOPPY "Nova slika" +#define STR_PREFERENCES "Možnosti" +#define STR_SND_GAIN "Ojačanje zvoka" +#define STR_NEW_FLOPPY "Nova slika" #define STR_CONFIG "Nastavitve" -#define STR_SPECIFY_DIM "Določi velikost glavnega okna" +#define STR_SPECIFY_DIM "Določi velikost glavnega okna" #define STR_OK "V redu" #define STR_CANCEL "Prekliči" #define STR_GLOBAL "Shrani te nastavitve kot globalne privzete" -#define STR_DEFAULT "Privzeto" -#define STR_LANGUAGE "Jezik:" -#define STR_ICONSET "Komplet ikon:" +#define STR_DEFAULT "Privzeto" +#define STR_LANGUAGE "Jezik:" +#define STR_ICONSET "Komplet ikon:" -#define STR_GAIN "Ojačanje" +#define STR_GAIN "Ojačanje" -#define STR_FILE_NAME "Ime datoteke:" -#define STR_DISK_SIZE "Velikost diska:" -#define STR_RPM_MODE "Način števila obratov:" -#define STR_PROGRESS "Napredek:" +#define STR_FILE_NAME "Ime datoteke:" +#define STR_DISK_SIZE "Velikost diska:" +#define STR_RPM_MODE "Način števila obratov:" +#define STR_PROGRESS "Napredek:" -#define STR_WIDTH "Širina:" +#define STR_WIDTH "Širina:" #define STR_HEIGHT "Višina:" -#define STR_LOCK_TO_SIZE "Zakleni na to velikost" +#define STR_LOCK_TO_SIZE "Zakleni na to velikost" -#define STR_MACHINE_TYPE "Vrsta sistema:" -#define STR_MACHINE "Sistem:" -#define STR_CONFIGURE "Nastavi" -#define STR_CPU_TYPE "Vrsta procesorja:" -#define STR_CPU_SPEED "Hitrost:" -#define STR_FPU "Procesor plavajoče vejice:" -#define STR_WAIT_STATES "Čakalna stanja:" +#define STR_MACHINE_TYPE "Vrsta sistema:" +#define STR_MACHINE "Sistem:" +#define STR_CONFIGURE "Nastavi" +#define STR_CPU_TYPE "Vrsta procesorja:" +#define STR_CPU_SPEED "Hitrost:" +#define STR_FPU "Procesor plavajoče vejice:" +#define STR_WAIT_STATES "Čakalna stanja:" #define STR_MB "MB" #define STR_MEMORY "Spomin:" -#define STR_TIME_SYNC "Sinhronizacija časa" -#define STR_DISABLED "Onemogočeno" -#define STR_ENABLED_LOCAL "Omogočeno (lokalni čas)" -#define STR_ENABLED_UTC "Omogočeno (UTC)" -#define STR_DYNAREC "Dinamični prevajalnik" +#define STR_TIME_SYNC "Sinhronizacija časa" +#define STR_DISABLED "Onemogočeno" +#define STR_ENABLED_LOCAL "Omogočeno (lokalni čas)" +#define STR_ENABLED_UTC "Omogočeno (UTC)" +#define STR_DYNAREC "Dinamični prevajalnik" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Video:" -#define STR_VIDEO_2 "Video 2:" +#define STR_VIDEO "Video:" +#define STR_VIDEO_2 "Video 2:" #define STR_VOODOO "Voodoo grafika" -#define STR_IBM8514 "IBM 8514/a grafika" -#define STR_XGA "XGA grafika" +#define STR_IBM8514 "IBM 8514/a grafika" +#define STR_XGA "XGA grafika" -#define STR_MOUSE "Miška:" -#define STR_JOYSTICK "Igralna palica:" -#define STR_JOY1 "Igralna palica 1..." -#define STR_JOY2 "Igralna palica 2..." -#define STR_JOY3 "Igralna palica 3..." -#define STR_JOY4 "Igralna palica 4..." +#define STR_MOUSE "Miška:" +#define STR_JOYSTICK "Igralna palica:" +#define STR_JOY1 "Igralna palica 1..." +#define STR_JOY2 "Igralna palica 2..." +#define STR_JOY3 "Igralna palica 3..." +#define STR_JOY4 "Igralna palica 4..." #define STR_SOUND1 "Zvočna kartica 1:" #define STR_SOUND2 "Zvočna kartica 2:" #define STR_SOUND3 "Zvočna kartica 3:" #define STR_SOUND4 "Zvočna kartica 4:" -#define STR_MIDI_OUT "Izhodna naprava MIDI:" -#define STR_MIDI_IN "Vhodna naprava MIDI:" +#define STR_MIDI_OUT "Izhodna naprava MIDI:" +#define STR_MIDI_IN "Vhodna naprava MIDI:" #define STR_MPU401 "Samostojen MPU-401" -#define STR_FLOAT "Uporabi FLOAT32 za zvok" -#define STR_FM_DRIVER "Gonilnik sintetizacije FM" -#define STR_FM_DRV_NUKED "Nuked (točnejši)" -#define STR_FM_DRV_YMFM "YMFM (hitrejši)" +#define STR_FLOAT "Uporabi FLOAT32 za zvok" +#define STR_FM_DRIVER "Gonilnik sintetizacije FM" +#define STR_FM_DRV_NUKED "Nuked (točnejši)" +#define STR_FM_DRV_YMFM "YMFM (hitrejši)" -#define STR_NET_TYPE "Vrsta omrežja:" -#define STR_PCAP "Naprava PCap:" -#define STR_NET "Omrežna kartica:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Vrsta omrežja:" +#define STR_PCAP "Naprava PCap:" +#define STR_NET "Omrežna kartica:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "Naprava COM1:" -#define STR_COM2 "Naprava COM2:" -#define STR_COM3 "Naprava COM3:" -#define STR_COM4 "Naprava COM4:" -#define STR_LPT1 "Naprava LPT1:" -#define STR_LPT2 "Naprava LPT2:" -#define STR_LPT3 "Naprava LPT3:" -#define STR_LPT4 "Naprava LPT4:" -#define STR_SERIAL1 "Serijska vrata 1" -#define STR_SERIAL2 "Serijska vrata 2" -#define STR_SERIAL3 "Serijska vrata 3" -#define STR_SERIAL4 "Serijska vrata 4" -#define STR_PARALLEL1 "Paralelna vrata 1" -#define STR_PARALLEL2 "Paralelna vrata 2" -#define STR_PARALLEL3 "Paralelna vrata 3" -#define STR_PARALLEL4 "Paralelna vrata 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Naprava COM1:" +#define STR_COM2 "Naprava COM2:" +#define STR_COM3 "Naprava COM3:" +#define STR_COM4 "Naprava COM4:" +#define STR_LPT1 "Naprava LPT1:" +#define STR_LPT2 "Naprava LPT2:" +#define STR_LPT3 "Naprava LPT3:" +#define STR_LPT4 "Naprava LPT4:" +#define STR_SERIAL1 "Serijska vrata 1" +#define STR_SERIAL2 "Serijska vrata 2" +#define STR_SERIAL3 "Serijska vrata 3" +#define STR_SERIAL4 "Serijska vrata 4" +#define STR_PARALLEL1 "Paralelna vrata 1" +#define STR_PARALLEL2 "Paralelna vrata 2" +#define STR_PARALLEL3 "Paralelna vrata 3" +#define STR_PARALLEL4 "Paralelna vrata 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Krmilnik trdega diska:" -#define STR_FDC "Krmilnik disketnika:" -#define STR_IDE_TER "Terciarni krmilnik IDE" -#define STR_IDE_QUA "Kvartarni krmilnik IDE" -#define STR_SCSI "SCSI" +#define STR_HDC "Krmilnik trdega diska:" +#define STR_FDC "Krmilnik disketnika:" +#define STR_IDE_TER "Terciarni krmilnik IDE" +#define STR_IDE_QUA "Kvartarni krmilnik IDE" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Krmilnik 1:" #define STR_SCSI_2 "Krmilnik 2:" #define STR_SCSI_3 "Krmilnik 3:" #define STR_SCSI_4 "Krmilnik 4:" -#define STR_CASSETTE "Kasetnik" +#define STR_CASSETTE "Kasetnik" -#define STR_HDD "Trdi diski:" -#define STR_NEW "Nov..." -#define STR_EXISTING "Obstoječ..." +#define STR_HDD "Trdi diski:" +#define STR_NEW "Nov..." +#define STR_EXISTING "Obstoječ..." #define STR_REMOVE "Odstrani" -#define STR_BUS "Vodilo:" -#define STR_CHANNEL "Kanal:" +#define STR_BUS "Vodilo:" +#define STR_CHANNEL "Kanal:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "Določi..." -#define STR_SECTORS "Sektorji:" -#define STR_HEADS "Glave:" -#define STR_CYLS "Cilindri:" -#define STR_SIZE_MB "Velikost (MB):" -#define STR_TYPE "Vrsta:" -#define STR_IMG_FORMAT "Format slike:" -#define STR_BLOCK_SIZE "Velikost bloka:" +#define STR_SPECIFY "Določi..." +#define STR_SECTORS "Sektorji:" +#define STR_HEADS "Glave:" +#define STR_CYLS "Cilindri:" +#define STR_SIZE_MB "Velikost (MB):" +#define STR_TYPE "Vrsta:" +#define STR_IMG_FORMAT "Format slike:" +#define STR_BLOCK_SIZE "Velikost bloka:" -#define STR_FLOPPY_DRIVES "Disketni pogoni:" -#define STR_TURBO "Turbo časovniki" -#define STR_CHECKBPB "Preverjaj BPB" -#define STR_CDROM_DRIVES "Pogoni CD-ROM:" -#define STR_CD_SPEED "Hitrost:" -#define STR_EARLY "Zgodnejši pogon" +#define STR_FLOPPY_DRIVES "Disketni pogoni:" +#define STR_TURBO "Turbo časovniki" +#define STR_CHECKBPB "Preverjaj BPB" +#define STR_CDROM_DRIVES "Pogoni CD-ROM:" +#define STR_CD_SPEED "Hitrost:" -#define STR_MO_DRIVES "Magnetno-optični pogoni:" -#define STR_ZIP_DRIVES "Pogoni ZIP:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Magnetno-optični pogoni:" +#define STR_ZIP_DRIVES "Pogoni ZIP:" +#define STR_250 "ZIP 250" #define STR_ISARTC "Ura v realnem času ISA:" #define STR_ISAMEM "Razširitev spomina ISA" -#define STR_ISAMEM_1 "Kartica 1:" -#define STR_ISAMEM_2 "Kartica 2:" -#define STR_ISAMEM_3 "Kartica 3:" -#define STR_ISAMEM_4 "Kartica 4:" +#define STR_ISAMEM_1 "Kartica 1:" +#define STR_ISAMEM_2 "Kartica 2:" +#define STR_ISAMEM_3 "Kartica 3:" +#define STR_ISAMEM_4 "Kartica 4:" #define STR_BUGGER "Naprava ISABugger" -#define STR_POSTCARD "Kartica POST" +#define STR_POSTCARD "Kartica POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Napaka" IDS_2050 "Kritična napaka" IDS_2051 " - PAUSED" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "Sistem ""%hs"" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/machines. Preklapljam na drug sistem, ki je na voljo." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Grafična kartica ""%hs"" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/video. Preklapljam na drugo grafično kartico, ki je na voljo.." IDS_2065 "Sistem" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Pritisnite F8+F12 ali srednji gumb za izpust miške" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Ne morem inicializirati FluidSynth" IDS_2081 "Vodilo" IDS_2082 "Datoteka" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disketa %i (%s): %ls" IDS_2110 "Vse slike (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Napredne sektorske slike (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Osnovne sektorske slike (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Tokovne slike (*.FDI)\0*.FDI\0Površinske slike (*.86F;*.MFM)\0*.86F;*.MFM\0Vse datoteke (*.*)\0*.*\0" - IDS_2111 "Ne morem inicializirati FreeType" IDS_2112 "Ne morem inicializirati SDL, potrebna je knjižica SDL2.dll" IDS_2113 "Ste prepričani, da želite ponovno zagnati emulirani sistem?" IDS_2114 "Ste prepričani, da želite zapreti 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Prepičajte se, da je nameščen " LIB_NAME_PCAP " in da ste na omrežni povezavi, združljivi z " LIB_NAME_PCAP IDS_2131 "Neveljavna konfiguracija" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " je potreben za emuliranje ESC/P tiskalnika." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " je potreben za samodejno pretvorbo PostScript datotek v PDF.\n\nVsi dokumenti, poslani generičnemu PostScript tiskalniku bodo shranjeni kot PostScript (.ps) datoteke." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " je potreben za FluidSynth MIDI izhod." IDS_2135 "Preklapljam v celozaslonski način" IDS_2136 "Ne pokaži več tega sporočila" IDS_2137 "Prekliči izhod" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Ponovni zagon" IDS_2160 "Zaustavitev ACPI" IDS_2161 "Nastavitve" - IDS_2162 "Zgodnejši pogon" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Trdi disk (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Sistemsko privzeto)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Slovenian resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/tr-TR.rc b/src/win/languages/tr-TR.rc index 17f701d24..cb45eab74 100644 --- a/src/win/languages/tr-TR.rc +++ b/src/win/languages/tr-TR.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_TURKISH, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Komutlar" BEGIN - MENUITEM "&Klavye sadece fare yakalandığında çalışsın", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Sağ CTRL tuşunu sol ALT tuşu olarak ayarla", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Klavye sadece fare yakalandığında çalışsın", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Sağ CTRL tuşunu sol ALT tuşu olarak ayarla", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Makineyi yeniden başlat...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Makineyi yeniden başlat...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Duraklat", IDM_ACTION_PAUSE + MENUITEM "&Duraklat", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "Emülatörden &çık...", IDM_ACTION_EXIT + MENUITEM "Emülatörden &çık...", IDM_ACTION_EXIT END POPUP "&Görüntüleme" BEGIN - MENUITEM "&Durum çubuğunu gizle", IDM_VID_HIDE_STATUS_BAR - MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Durum çubuğunu gizle", IDM_VID_HIDE_STATUS_BAR + MENUITEM "Hide &toolbar", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Yeniden boyutlandırılabilir pencere", IDM_VID_RESIZE - MENUITEM "&Pencere boyut ve pozisyonunu hatırla", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Yeniden boyutlandırılabilir pencere", IDM_VID_RESIZE + MENUITEM "&Pencere boyut ve pozisyonunu hatırla", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&İşleyici" BEGIN - MENUITEM "&SDL (Yazılım)", IDM_VID_SDL_SW - MENUITEM "SDL (&Donanım)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Yazılım)", IDM_VID_SDL_SW + MENUITEM "SDL (&Donanım)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0 Core)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "Pencere &boyutunu belirle...", IDM_VID_SPECIFY_DIM - MENUITEM "&4:3 görüntüleme oranına zorla", IDM_VID_FORCE43 + MENUITEM "Pencere &boyutunu belirle...", IDM_VID_SPECIFY_DIM + MENUITEM "&4:3 görüntüleme oranına zorla", IDM_VID_FORCE43 POPUP "Pencere &ölçek çarpanı" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "&Filtre metodu" BEGIN - MENUITEM "&Nearest (En yakın)", IDM_VID_FILTER_NEAREST - MENUITEM "&Linear (Doğrusal)", IDM_VID_FILTER_LINEAR + MENUITEM "&Nearest (En yakın)", IDM_VID_FILTER_NEAREST + MENUITEM "&Linear (Doğrusal)", IDM_VID_FILTER_LINEAR END - MENUITEM "Hi&DPI ölçeklemesi", IDM_VID_HIDPI + MENUITEM "Hi&DPI ölçeklemesi", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Tam ekran\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Tam ekran\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "Tam ekran &germe modu" BEGIN - MENUITEM "&Tam ekrana ger", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&Tam ekrana ger", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Kare piksel (ölçeği koru)", IDM_VID_FS_KEEPRATIO - MENUITEM "Tam &sayı ölçeklemesi", IDM_VID_FS_INT + MENUITEM "Tam &sayı ölçeklemesi", IDM_VID_FS_INT END POPUP "EGA/&(S)VGA ayarları" BEGIN - MENUITEM "Ters &renk VGA monitör", IDM_VID_INVERT + MENUITEM "Ters &renk VGA monitör", IDM_VID_INVERT POPUP "VGA ekran &tipi" BEGIN - MENUITEM "RGB (&renkli)", IDM_VID_GRAY_RGB - MENUITEM "RGB (&gri tonlama)", IDM_VID_GRAY_MONO - MENUITEM "&Kehribar rengi monitör", IDM_VID_GRAY_AMBER - MENUITEM "&Yeşil renk monitör", IDM_VID_GRAY_GREEN - MENUITEM "&Beyaz renk monitör", IDM_VID_GRAY_WHITE + MENUITEM "RGB (&renkli)", IDM_VID_GRAY_RGB + MENUITEM "RGB (&gri tonlama)", IDM_VID_GRAY_MONO + MENUITEM "&Kehribar rengi monitör", IDM_VID_GRAY_AMBER + MENUITEM "&Yeşil renk monitör", IDM_VID_GRAY_GREEN + MENUITEM "&Beyaz renk monitör", IDM_VID_GRAY_WHITE END POPUP "&Gri tonlama dönüştürme tipi" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Ortalama", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Ortalama", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA aşırı taraması", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/E&GA/(S)VGA aşırı taraması", IDM_VID_OVERSCAN MENUITEM "Gri to&nlamalı görüntü için kontrastı değiştir", IDM_VID_CGACON END - MENUITEM "&Medya", IDM_MEDIA + MENUITEM "&Medya", IDM_MEDIA POPUP "&Araçlar" BEGIN - MENUITEM "&Ayarlar...", IDM_CONFIG - MENUITEM "Durum &çubuğu ikonlarını güncelle", IDM_UPDATE_ICONS + MENUITEM "&Ayarlar...", IDM_CONFIG + MENUITEM "Durum &çubuğu ikonlarını güncelle", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "&Ekran görüntüsü al\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "&Ekran görüntüsü al\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Tercihler...", IDM_PREFERENCES + MENUITEM "&Tercihler...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "&Discord entegrasyonunu etkinleştir", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Ses yükseltici...", IDM_SND_GAIN + MENUITEM "&Ses yükseltici...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Begin trace\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "End trace\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Begin trace\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "End trace\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Yardım" BEGIN - MENUITEM "&Dökümanlar...", IDM_DOCS - MENUITEM "&86Box Hakkında...", IDM_ABOUT + MENUITEM "&Dökümanlar...", IDM_DOCS + MENUITEM "&86Box Hakkında...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Yeni imaj oluştur...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Yeni imaj oluştur...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&İmaj seç...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&İmaj seç...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Kaydet", IDM_CASSETTE_RECORD - MENUITEM "&Oynat", IDM_CASSETTE_PLAY - MENUITEM "&Başlangıca geri sar", IDM_CASSETTE_REWIND - MENUITEM "Sona doğru &ileri sar", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Kaydet", IDM_CASSETTE_RECORD + MENUITEM "&Oynat", IDM_CASSETTE_PLAY + MENUITEM "&Başlangıca geri sar", IDM_CASSETTE_REWIND + MENUITEM "Sona doğru &ileri sar", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "&Çıkar", IDM_CASSETTE_EJECT + MENUITEM "&Çıkar", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&İmaj...", IDM_CARTRIDGE_IMAGE + MENUITEM "&İmaj...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "&Çıkar", IDM_CARTRIDGE_EJECT + MENUITEM "&Çıkar", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Yeni imaj oluştur...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Yeni imaj oluştur...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&İmaj seç...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&İmaj seç...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&86F dosyası olarak aktar...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "&86F dosyası olarak aktar...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "&Çıkar", IDM_FLOPPY_EJECT + MENUITEM "&Çıkar", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Sesi kapat", IDM_CDROM_MUTE + MENUITEM "&Sesi kapat", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "İmajı &çıkar", IDM_CDROM_EMPTY - MENUITEM "&Önceki imajı seç", IDM_CDROM_RELOAD + MENUITEM "İmajı &çıkar", IDM_CDROM_EMPTY + MENUITEM "&Önceki imajı seç", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&İmaj seç...", IDM_CDROM_IMAGE - MENUITEM "&Klasör...", IDM_CDROM_DIR + MENUITEM "&İmaj seç...", IDM_CDROM_IMAGE + MENUITEM "&Klasör...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Yeni imaj...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Yeni imaj...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&İmaj seç...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&İmaj seç...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Çıkar", IDM_ZIP_EJECT - MENUITEM "&Önceki imajı seç", IDM_ZIP_RELOAD + MENUITEM "&Çıkar", IDM_ZIP_EJECT + MENUITEM "&Önceki imajı seç", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Yeni imaj...", IDM_MO_IMAGE_NEW + MENUITEM "&Yeni imaj...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&İmaj seç...", IDM_MO_IMAGE_EXISTING - MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&İmaj seç...", IDM_MO_IMAGE_EXISTING + MENUITEM "İmaj &seç (Yazma-korumalı)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Çıkar", IDM_MO_EJECT - MENUITEM "&Önceki imajı seç", IDM_MO_RELOAD + MENUITEM "&Çıkar", IDM_MO_EJECT + MENUITEM "&Önceki imajı seç", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Tercihler" -#define STR_SND_GAIN "Ses Artırma" -#define STR_NEW_FLOPPY "Yeni İmaj" +#define STR_PREFERENCES "Tercihler" +#define STR_SND_GAIN "Ses Artırma" +#define STR_NEW_FLOPPY "Yeni İmaj" #define STR_CONFIG "Ayarlar" -#define STR_SPECIFY_DIM "Ana Pencere Boyutunu Belirle" +#define STR_SPECIFY_DIM "Ana Pencere Boyutunu Belirle" #define STR_OK "Tamam" #define STR_CANCEL "İptal et" #define STR_GLOBAL "Bu ayarları &varsayılan olarak kaydet" -#define STR_DEFAULT "&Varsayılan" -#define STR_LANGUAGE "Dil:" -#define STR_ICONSET "Simge seti:" +#define STR_DEFAULT "&Varsayılan" +#define STR_LANGUAGE "Dil:" +#define STR_ICONSET "Simge seti:" -#define STR_GAIN "Artırma" +#define STR_GAIN "Artırma" -#define STR_FILE_NAME "Dosya adı:" -#define STR_DISK_SIZE "Disk boyutu:" -#define STR_RPM_MODE "RPM modu:" -#define STR_PROGRESS "İşlem:" +#define STR_FILE_NAME "Dosya adı:" +#define STR_DISK_SIZE "Disk boyutu:" +#define STR_RPM_MODE "RPM modu:" +#define STR_PROGRESS "İşlem:" -#define STR_WIDTH "Genişlik:" +#define STR_WIDTH "Genişlik:" #define STR_HEIGHT "Yükseklik:" -#define STR_LOCK_TO_SIZE "Bu boyuta kilitle" +#define STR_LOCK_TO_SIZE "Bu boyuta kilitle" -#define STR_MACHINE_TYPE "Makine türü:" -#define STR_MACHINE "Makine:" -#define STR_CONFIGURE "Ayarla" -#define STR_CPU_TYPE "CPU türü:" -#define STR_CPU_SPEED "Hız:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "Bekleme süreleri:" +#define STR_MACHINE_TYPE "Makine türü:" +#define STR_MACHINE "Makine:" +#define STR_CONFIGURE "Ayarla" +#define STR_CPU_TYPE "CPU türü:" +#define STR_CPU_SPEED "Hız:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "Bekleme süreleri:" #define STR_MB "MB" #define STR_MEMORY "Bellek:" -#define STR_TIME_SYNC "Zaman senkronizasyonu" -#define STR_DISABLED "Devre dışı" -#define STR_ENABLED_LOCAL "Etkin (yerel zaman)" -#define STR_ENABLED_UTC "Etkin (UTC)" -#define STR_DYNAREC "Dinamik Derleyici" +#define STR_TIME_SYNC "Zaman senkronizasyonu" +#define STR_DISABLED "Devre dışı" +#define STR_ENABLED_LOCAL "Etkin (yerel zaman)" +#define STR_ENABLED_UTC "Etkin (UTC)" +#define STR_DYNAREC "Dinamik Derleyici" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Ekran kartı:" -#define STR_VIDEO_2 "Ekran kartı 2:" +#define STR_VIDEO "Ekran kartı:" +#define STR_VIDEO_2 "Ekran kartı 2:" #define STR_VOODOO "Voodoo Grafikleri" -#define STR_IBM8514 "IBM 8514/a Grafikleri" -#define STR_XGA "XGA Grafikleri" +#define STR_IBM8514 "IBM 8514/a Grafikleri" +#define STR_XGA "XGA Grafikleri" -#define STR_MOUSE "Fare:" -#define STR_JOYSTICK "Oyun kolu:" -#define STR_JOY1 "Oyun kolu 1..." -#define STR_JOY2 "Oyun kolu 2..." -#define STR_JOY3 "Oyun kolu 3..." -#define STR_JOY4 "Oyun kolu 4..." +#define STR_MOUSE "Fare:" +#define STR_JOYSTICK "Oyun kolu:" +#define STR_JOY1 "Oyun kolu 1..." +#define STR_JOY2 "Oyun kolu 2..." +#define STR_JOY3 "Oyun kolu 3..." +#define STR_JOY4 "Oyun kolu 4..." #define STR_SOUND1 "Ses kartı 1:" #define STR_SOUND2 "Ses kartı 2:" #define STR_SOUND3 "Ses kartı 3:" #define STR_SOUND4 "Ses kartı 4:" -#define STR_MIDI_OUT "MIDI Çıkış Cihazı:" -#define STR_MIDI_IN "MIDI Giriş Cihazı:" +#define STR_MIDI_OUT "MIDI Çıkış Cihazı:" +#define STR_MIDI_IN "MIDI Giriş Cihazı:" #define STR_MPU401 "Bağımsız MPU-401" -#define STR_FLOAT "FLOAT32 ses kullan" -#define STR_FM_DRIVER "FM sentez sürücüsü" -#define STR_FM_DRV_NUKED "Nuked (daha doğru)" -#define STR_FM_DRV_YMFM "YMFM (daha hızlı)" +#define STR_FLOAT "FLOAT32 ses kullan" +#define STR_FM_DRIVER "FM sentez sürücüsü" +#define STR_FM_DRV_NUKED "Nuked (daha doğru)" +#define STR_FM_DRV_YMFM "YMFM (daha hızlı)" -#define STR_NET_TYPE "Ağ tipi:" -#define STR_PCAP "PCap cihazı:" -#define STR_NET "Ağ cihazı:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Ağ tipi:" +#define STR_PCAP "PCap cihazı:" +#define STR_NET "Ağ cihazı:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "COM1 Cihazı:" -#define STR_COM2 "COM2 Cihazı:" -#define STR_COM3 "COM3 Cihazı:" -#define STR_COM4 "COM4 Cihazı:" -#define STR_LPT1 "LPT1 Cihazı:" -#define STR_LPT2 "LPT2 Cihazı:" -#define STR_LPT3 "LPT3 Cihazı:" -#define STR_LPT4 "LPT4 Cihazı:" -#define STR_SERIAL1 "Seri port 1" -#define STR_SERIAL2 "Seri port 2" -#define STR_SERIAL3 "Seri port 3" -#define STR_SERIAL4 "Seri port 4" -#define STR_PARALLEL1 "Paralel port 1" -#define STR_PARALLEL2 "Paralel port 2" -#define STR_PARALLEL3 "Paralel port 3" -#define STR_PARALLEL4 "Paralel port 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1 Cihazı:" +#define STR_COM2 "COM2 Cihazı:" +#define STR_COM3 "COM3 Cihazı:" +#define STR_COM4 "COM4 Cihazı:" +#define STR_LPT1 "LPT1 Cihazı:" +#define STR_LPT2 "LPT2 Cihazı:" +#define STR_LPT3 "LPT3 Cihazı:" +#define STR_LPT4 "LPT4 Cihazı:" +#define STR_SERIAL1 "Seri port 1" +#define STR_SERIAL2 "Seri port 2" +#define STR_SERIAL3 "Seri port 3" +#define STR_SERIAL4 "Seri port 4" +#define STR_PARALLEL1 "Paralel port 1" +#define STR_PARALLEL2 "Paralel port 2" +#define STR_PARALLEL3 "Paralel port 3" +#define STR_PARALLEL4 "Paralel port 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "HD Kontrolcüsü:" -#define STR_FDC "FD Kontrolcüsü:" -#define STR_IDE_TER "Üçlü IDE Kontrolcüsü" -#define STR_IDE_QUA "Dörtlü IDE Kontrolcüsü" -#define STR_SCSI "SCSI" +#define STR_HDC "HD Kontrolcüsü:" +#define STR_FDC "FD Kontrolcüsü:" +#define STR_IDE_TER "Üçlü IDE Kontrolcüsü" +#define STR_IDE_QUA "Dörtlü IDE Kontrolcüsü" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Kontrolcü 1:" #define STR_SCSI_2 "Kontrolcü 2:" #define STR_SCSI_3 "Kontrolcü 3:" #define STR_SCSI_4 "Kontrolcü 4:" -#define STR_CASSETTE "Kaset" +#define STR_CASSETTE "Kaset" -#define STR_HDD "Hard diskler:" -#define STR_NEW "&Yeni..." -#define STR_EXISTING "&Var olan..." +#define STR_HDD "Hard diskler:" +#define STR_NEW "&Yeni..." +#define STR_EXISTING "&Var olan..." #define STR_REMOVE "&Kaldır" -#define STR_BUS "Veri yolu:" -#define STR_CHANNEL "Kanal:" +#define STR_BUS "Veri yolu:" +#define STR_CHANNEL "Kanal:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Belirle..." -#define STR_SECTORS "Sektörler:" -#define STR_HEADS "Veri Kafaları:" -#define STR_CYLS "Silindirler:" -#define STR_SIZE_MB "Boyut (MB):" -#define STR_TYPE "Tip:" -#define STR_IMG_FORMAT "İmaj Düzeni:" -#define STR_BLOCK_SIZE "Blok Boyutu:" +#define STR_SPECIFY "&Belirle..." +#define STR_SECTORS "Sektörler:" +#define STR_HEADS "Veri Kafaları:" +#define STR_CYLS "Silindirler:" +#define STR_SIZE_MB "Boyut (MB):" +#define STR_TYPE "Tip:" +#define STR_IMG_FORMAT "İmaj Düzeni:" +#define STR_BLOCK_SIZE "Blok Boyutu:" -#define STR_FLOPPY_DRIVES "Disket sürücüleri:" -#define STR_TURBO "Turbo zamanlamaları" -#define STR_CHECKBPB "BPB'yi denetle" -#define STR_CDROM_DRIVES "CD-ROM sürücüleri:" -#define STR_CD_SPEED "Hız:" -#define STR_EARLY "Daha erken sürüş" +#define STR_FLOPPY_DRIVES "Disket sürücüleri:" +#define STR_TURBO "Turbo zamanlamaları" +#define STR_CHECKBPB "BPB'yi denetle" +#define STR_CDROM_DRIVES "CD-ROM sürücüleri:" +#define STR_CD_SPEED "Hız:" -#define STR_MO_DRIVES "MO sürücüleri:" -#define STR_ZIP_DRIVES "ZIP sürücüleri:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "MO sürücüleri:" +#define STR_ZIP_DRIVES "ZIP sürücüleri:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC:" #define STR_ISAMEM "ISA Bellek Artırma" -#define STR_ISAMEM_1 "Kart 1:" -#define STR_ISAMEM_2 "Kart 2:" -#define STR_ISAMEM_3 "Kart 3:" -#define STR_ISAMEM_4 "Kart 4:" +#define STR_ISAMEM_1 "Kart 1:" +#define STR_ISAMEM_2 "Kart 2:" +#define STR_ISAMEM_3 "Kart 3:" +#define STR_ISAMEM_4 "Kart 4:" #define STR_BUGGER "ISABugger cihazı" -#define STR_POSTCARD "POST kartı" +#define STR_POSTCARD "POST kartı" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Hata" IDS_2050 "Kritik hata" IDS_2051 " - PAUSED" @@ -412,7 +412,7 @@ BEGIN IDS_2063 """%hs"" makinesi roms/machines klasöründe mevcut olmayan ROM imajı yüzünden mevcut değil. Mevcut olan bir makineye geçiş yapılıyor." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 """%hs"" ekran kartı roms/video klasöründe mevcut olmayan ROM imajı yüzünden mevcut değil. Mevcut olan bir ekran kartına geçiş yapılıyor." IDS_2065 "Makine" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Farenin bırakılması için F8+F12 veya farenin orta tuşuna basın" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynth başlatılamadı" IDS_2081 "Veri yolu" IDS_2082 "Dosya" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disket %i (%s): %ls" IDS_2110 "Tüm imajlar (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Gelişmiş sektör imajları (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basit sektör imajları (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Yüzey imajları (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "FreeType başlatılamadı" IDS_2112 "SDL başlatılamadı, SDL2.dll gerekmektedir" IDS_2113 "Emüle edilen makineyi yeniden başlatmak istediğinizden emin misiniz?" IDS_2114 "86Box'tan çıkmak istediğinize emin misiniz?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "" LIB_NAME_PCAP " kurulu olduğundan ve " LIB_NAME_PCAP "-uyumlu bir internet ağında bulunduğunuzdan emin olun." IDS_2131 "Geçersiz konfigürasyon" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " ESC/P yazıcı emülasyonu için gereklidir." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " PostScript dosyalarının otomatik olarak PDF dosyalarına çevirilmesi için gereklidir.\n\nGenel PostScript yazıcısına gönderilen tüm dökümanlar PostScript (.ps) dosyaları olarak kaydedilecektir." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " FluidSynth MIDI çıkışı için gereklidir." IDS_2135 "Tam ekran moduna geçiliyor" IDS_2136 "Bu mesajı bir daha gösterme" IDS_2137 "Çıkış yapma" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "Makineyi yeniden başlat" IDS_2160 "ACPI kapatma" IDS_2161 "Ayarlar" - IDS_2162 "Daha erken sürüş" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Hard disk (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(Sistem Varsayılanı)" END -#define IDS_LANG_TRTR IDS_7168 +#define IDS_LANG_TRTR IDS_7168 // Turkish (TR) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/uk-UA.rc b/src/win/languages/uk-UA.rc index f22edf48e..e282e467b 100644 --- a/src/win/languages/uk-UA.rc +++ b/src/win/languages/uk-UA.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_UKRAINIAN, SUBLANG_DEFAULT // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Дія" BEGIN - MENUITEM "&Клавіатура потребує захвату", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "&Правий CTRL - це лівий ALT", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "&Клавіатура потребує захвату", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "&Правий CTRL - це лівий ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "&Холодне перезавантаження...", IDM_ACTION_HRESET - MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "&Холодне перезавантаження...", IDM_ACTION_HRESET + MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "&Пауза", IDM_ACTION_PAUSE + MENUITEM "&Пауза", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "&Вихід...", IDM_ACTION_EXIT + MENUITEM "&Вихід...", IDM_ACTION_EXIT END POPUP "&Вигляд" BEGIN - MENUITEM "&Приховати рядок стану", IDM_VID_HIDE_STATUS_BAR - MENUITEM "&Приховати панель інструментів", IDM_VID_HIDE_TOOLBAR + MENUITEM "&Приховати рядок стану", IDM_VID_HIDE_STATUS_BAR + MENUITEM "&Приховати панель інструментів", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS - MENUITEM "&Змінний розмір вікна", IDM_VID_RESIZE - MENUITEM "&Запам'ятати розмір і становище", IDM_VID_REMEMBER + MENUITEM "&Show non-primary monitors", IDM_VID_MONITORS + MENUITEM "&Змінний розмір вікна", IDM_VID_RESIZE + MENUITEM "&Запам'ятати розмір і становище", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "&Рендеринг" BEGIN - MENUITEM "&SDL (Software)", IDM_VID_SDL_SW - MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW - MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL - MENUITEM "Open&GL (3.0)", IDM_VID_OPENGL_CORE + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "SDL (&Hardware)", IDM_VID_SDL_HW + MENUITEM "SDL (&OpenGL)", IDM_VID_SDL_OPENGL + MENUITEM "Open&GL (3.0)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "&VNC", IDM_VID_VNC + MENUITEM "&VNC", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "&Вказати розміри...", IDM_VID_SPECIFY_DIM - MENUITEM "&Встановити відношення сторін 4:3", IDM_VID_FORCE43 + MENUITEM "&Вказати розміри...", IDM_VID_SPECIFY_DIM + MENUITEM "&Встановити відношення сторін 4:3", IDM_VID_FORCE43 POPUP "&Масштаб вікна" BEGIN - MENUITEM "&0.5x", IDM_VID_SCALE_1X - MENUITEM "&1x", IDM_VID_SCALE_2X - MENUITEM "1.&5x", IDM_VID_SCALE_3X - MENUITEM "&2x", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "&0.5x", IDM_VID_SCALE_1X + MENUITEM "&1x", IDM_VID_SCALE_2X + MENUITEM "1.&5x", IDM_VID_SCALE_3X + MENUITEM "&2x", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "Метод фільтрації" BEGIN - MENUITEM "&Найближчий", IDM_VID_FILTER_NEAREST - MENUITEM "&Лінійний", IDM_VID_FILTER_LINEAR + MENUITEM "&Найближчий", IDM_VID_FILTER_NEAREST + MENUITEM "&Лінійний", IDM_VID_FILTER_LINEAR END - MENUITEM "Масштабування Hi&DPI", IDM_VID_HIDPI + MENUITEM "Масштабування Hi&DPI", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "&Повноекранний режим\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "&Повноекранний режим\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "&Розстягування у повноекранному режимі" BEGIN - MENUITEM "&На весь екран", IDM_VID_FS_FULL - MENUITEM "&4:3", IDM_VID_FS_43 + MENUITEM "&На весь екран", IDM_VID_FS_FULL + MENUITEM "&4:3", IDM_VID_FS_43 MENUITEM "&Квадратні пікселі (зберегти відношення)", IDM_VID_FS_KEEPRATIO - MENUITEM "&Цілісночисленне масштабування", IDM_VID_FS_INT + MENUITEM "&Цілісночисленне масштабування", IDM_VID_FS_INT END POPUP "Налаштування E&GA/(S)VGA" BEGIN - MENUITEM "&Інвертувати кольори VGA", IDM_VID_INVERT + MENUITEM "&Інвертувати кольори VGA", IDM_VID_INVERT POPUP "&Тип екрана VGA" BEGIN - MENUITEM "RGB &кольоровий", IDM_VID_GRAY_RGB - MENUITEM "&RGB монохромний", IDM_VID_GRAY_MONO - MENUITEM "&Бурштиновий відтінок", IDM_VID_GRAY_AMBER - MENUITEM "&Зелений відтінок", IDM_VID_GRAY_GREEN - MENUITEM "&Білий відтінок", IDM_VID_GRAY_WHITE + MENUITEM "RGB &кольоровий", IDM_VID_GRAY_RGB + MENUITEM "&RGB монохромний", IDM_VID_GRAY_MONO + MENUITEM "&Бурштиновий відтінок", IDM_VID_GRAY_AMBER + MENUITEM "&Зелений відтінок", IDM_VID_GRAY_GREEN + MENUITEM "&Білий відтінок", IDM_VID_GRAY_WHITE END POPUP "Тип монохромного &конвертування" BEGIN - MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 - MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 - MENUITEM "&Усереднений", IDM_VID_GRAYCT_AVE + MENUITEM "BT&601 (NTSC/PAL)", IDM_VID_GRAYCT_601 + MENUITEM "BT&709 (HDTV)", IDM_VID_GRAYCT_709 + MENUITEM "&Усереднений", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "Вильоти розгортки CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN + MENUITEM "Вильоти розгортки CGA/PCjr/Tandy/E&GA/(S)VGA", IDM_VID_OVERSCAN MENUITEM "Змінити контрастність &монохромного дисплея", IDM_VID_CGACON END - MENUITEM "&Носії", IDM_MEDIA + MENUITEM "&Носії", IDM_MEDIA POPUP "&Інструменти" BEGIN - MENUITEM "&Налаштування машини...", IDM_CONFIG - MENUITEM "&Обновлення значків рядка стану", IDM_UPDATE_ICONS + MENUITEM "&Налаштування машини...", IDM_CONFIG + MENUITEM "&Обновлення значків рядка стану", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "Зробити &знімок\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "Зробити &знімок\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "&Параметри...", IDM_PREFERENCES + MENUITEM "&Параметри...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "Увімкнути інтеграцію &Discord", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "&Посилення звуку...", IDM_SND_GAIN + MENUITEM "&Посилення звуку...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "Почати трасування\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "Завершити трасування\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "Почати трасування\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "Завершити трасування\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "&Допомога" BEGIN - MENUITEM "&Документація...", IDM_DOCS - MENUITEM "&Про програму 86Box...", IDM_ABOUT + MENUITEM "&Документація...", IDM_DOCS + MENUITEM "&Про програму 86Box...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новий образ...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "&Новий образ...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Вибрати образ...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "Вибрати образ (&Захист від запису)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "&Вибрати образ...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "Вибрати образ (&Захист від запису)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Запис", IDM_CASSETTE_RECORD - MENUITEM "&Відтворення", IDM_CASSETTE_PLAY - MENUITEM "&Перемотування на початок", IDM_CASSETTE_REWIND - MENUITEM "&Перемотування у кінець", IDM_CASSETTE_FAST_FORWARD + MENUITEM "&Запис", IDM_CASSETTE_RECORD + MENUITEM "&Відтворення", IDM_CASSETTE_PLAY + MENUITEM "&Перемотування на початок", IDM_CASSETTE_REWIND + MENUITEM "&Перемотування у кінець", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "&Вилучити", IDM_CASSETTE_EJECT + MENUITEM "&Вилучити", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Образ...", IDM_CARTRIDGE_IMAGE + MENUITEM "&Образ...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "&Вилучити", IDM_CARTRIDGE_EJECT + MENUITEM "&Вилучити", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новий образ...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "&Новий образ...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Вибрати образ...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "Вибрати образ (&Захист від запису)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "&Вибрати образ...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "Вибрати образ (&Захист від запису)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Експорт в 86F...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "&Експорт в 86F...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "&Вилучити", IDM_FLOPPY_EJECT + MENUITEM "&Вилучити", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Відключити звук", IDM_CDROM_MUTE + MENUITEM "&Відключити звук", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "&Пустий", IDM_CDROM_EMPTY - MENUITEM "&Знову завантажити попередній образ", IDM_CDROM_RELOAD + MENUITEM "&Пустий", IDM_CDROM_EMPTY + MENUITEM "&Знову завантажити попередній образ", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "&Образ...", IDM_CDROM_IMAGE - MENUITEM "&Тека...", IDM_CDROM_DIR + MENUITEM "&Образ...", IDM_CDROM_IMAGE + MENUITEM "&Тека...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новий образ...", IDM_ZIP_IMAGE_NEW + MENUITEM "&Новий образ...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Вибрати образ...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "Вибрати образ (&Захист від запису)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "&Вибрати образ...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "Вибрати образ (&Захист від запису)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Вилучити", IDM_ZIP_EJECT - MENUITEM "&Знову завантажити попередній образ", IDM_ZIP_RELOAD + MENUITEM "&Вилучити", IDM_ZIP_EJECT + MENUITEM "&Знову завантажити попередній образ", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "&Новий образ...", IDM_MO_IMAGE_NEW + MENUITEM "&Новий образ...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "&Вибрати образ...", IDM_MO_IMAGE_EXISTING - MENUITEM "Вибрати образ (&Захист від запису)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "&Вибрати образ...", IDM_MO_IMAGE_EXISTING + MENUITEM "Вибрати образ (&Захист від запису)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "&Вилучити", IDM_MO_EJECT - MENUITEM "&Знову завантажити попередній образ", IDM_MO_RELOAD + MENUITEM "&Вилучити", IDM_MO_EJECT + MENUITEM "&Знову завантажити попередній образ", IDM_MO_RELOAD END END @@ -240,150 +240,150 @@ END // Dialog // -#define STR_PREFERENCES "Параметри" -#define STR_SND_GAIN "Посилення звуку" -#define STR_NEW_FLOPPY "Новий образ" +#define STR_PREFERENCES "Параметри" +#define STR_SND_GAIN "Посилення звуку" +#define STR_NEW_FLOPPY "Новий образ" #define STR_CONFIG "Налаштування" -#define STR_SPECIFY_DIM "Вказати розміри головного вікна" +#define STR_SPECIFY_DIM "Вказати розміри головного вікна" #define STR_OK "OK" #define STR_CANCEL "Відміна" #define STR_GLOBAL "Зберегти ці параметри як &глобальні за замовчуванням" -#define STR_DEFAULT "&За замовчуванням" -#define STR_LANGUAGE "Язык:" -#define STR_ICONSET "Набір іконок:" +#define STR_DEFAULT "&За замовчуванням" +#define STR_LANGUAGE "Мова:" +#define STR_ICONSET "Набір іконок:" -#define STR_GAIN "Посилення" +#define STR_GAIN "Посилення" -#define STR_FILE_NAME "Ім'я файлу:" -#define STR_DISK_SIZE "Розмір диска:" -#define STR_RPM_MODE "RPM режим:" -#define STR_PROGRESS "Прогрес:" +#define STR_FILE_NAME "Ім'я файлу:" +#define STR_DISK_SIZE "Розмір диска:" +#define STR_RPM_MODE "RPM режим:" +#define STR_PROGRESS "Прогрес:" -#define STR_WIDTH "Ширина:" +#define STR_WIDTH "Ширина:" #define STR_HEIGHT "Висота:" -#define STR_LOCK_TO_SIZE "Зафіксувати розмір" +#define STR_LOCK_TO_SIZE "Зафіксувати розмір" -#define STR_MACHINE_TYPE "Тип машини:" -#define STR_MACHINE "Системна плата:" -#define STR_CONFIGURE "Налаштування" -#define STR_CPU_TYPE "Тип ЦП:" -#define STR_CPU_SPEED "Швидкість:" -#define STR_FPU "FPU:" -#define STR_WAIT_STATES "Цикли очікування:" +#define STR_MACHINE_TYPE "Тип машини:" +#define STR_MACHINE "Системна плата:" +#define STR_CONFIGURE "Налаштування" +#define STR_CPU_TYPE "Тип ЦП:" +#define STR_CPU_SPEED "Швидкість:" +#define STR_FPU "FPU:" +#define STR_WAIT_STATES "Цикли очікування:" #define STR_MB "МБ" #define STR_MEMORY "Пам'ять:" -#define STR_TIME_SYNC "Синхронізація часу" -#define STR_DISABLED "Відключити" -#define STR_ENABLED_LOCAL "Увімкнути (місцеве)" -#define STR_ENABLED_UTC "Увімкнути (UTC)" -#define STR_DYNAREC "Динамічний рекомпілятор" +#define STR_TIME_SYNC "Синхронізація часу" +#define STR_DISABLED "Відключити" +#define STR_ENABLED_LOCAL "Увімкнути (місцеве)" +#define STR_ENABLED_UTC "Увімкнути (UTC)" +#define STR_DYNAREC "Динамічний рекомпілятор" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "Відеокарта:" -#define STR_VIDEO_2 "Відеокарта 2:" +#define STR_VIDEO "Відеокарта:" +#define STR_VIDEO_2 "Відеокарта 2:" #define STR_VOODOO "Прискорювач Voodoo" -#define STR_IBM8514 "Прискорювач IBM 8514/a" -#define STR_XGA "Прискорювач XGA" +#define STR_IBM8514 "Прискорювач IBM 8514/a" +#define STR_XGA "Прискорювач XGA" -#define STR_MOUSE "Миша:" -#define STR_JOYSTICK "Джойстик:" -#define STR_JOY1 "Джойстик 1..." -#define STR_JOY2 "Джойстик 2..." -#define STR_JOY3 "Джойстик 3..." -#define STR_JOY4 "Джойстик 4..." +#define STR_MOUSE "Миша:" +#define STR_JOYSTICK "Джойстик:" +#define STR_JOY1 "Джойстик 1..." +#define STR_JOY2 "Джойстик 2..." +#define STR_JOY3 "Джойстик 3..." +#define STR_JOY4 "Джойстик 4..." #define STR_SOUND1 "Звукова карта 1:" #define STR_SOUND2 "Звукова карта 2:" #define STR_SOUND3 "Звукова карта 3:" #define STR_SOUND4 "Звукова карта 4:" -#define STR_MIDI_OUT "MIDI Out при-ій:" -#define STR_MIDI_IN "MIDI In при-ій:" +#define STR_MIDI_OUT "MIDI Out при-ій:" +#define STR_MIDI_IN "MIDI In при-ій:" #define STR_MPU401 "Окремий MPU-401" -#define STR_FLOAT "FLOAT32 звук" -#define STR_FM_DRIVER "Драйвер FM-синтезатора" -#define STR_FM_DRV_NUKED "Nuked (більш точний)" -#define STR_FM_DRV_YMFM "YMFM (швидший)" +#define STR_FLOAT "FLOAT32 звук" +#define STR_FM_DRIVER "Драйвер FM-синтезатора" +#define STR_FM_DRV_NUKED "Nuked (більш точний)" +#define STR_FM_DRV_YMFM "YMFM (швидший)" -#define STR_NET_TYPE "Тип мережі:" -#define STR_PCAP "Пристрій PCap:" -#define STR_NET "Мережева карта:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "Тип мережі:" +#define STR_PCAP "Пристрій PCap:" +#define STR_NET "Мережевий адаптер:" +#define STR_NET1 "Мережева карта 1:" +#define STR_NET2 "Мережева карта 2:" +#define STR_NET3 "Мережева карта 3:" +#define STR_NET4 "Мережева карта 4:" -#define STR_COM1 "Пристрій COM1:" -#define STR_COM2 "Пристрій COM2:" -#define STR_COM3 "Пристрій COM3:" -#define STR_COM4 "Пристрій COM4:" -#define STR_LPT1 "Пристрій LPT1:" -#define STR_LPT2 "Пристрій LPT2:" -#define STR_LPT3 "Пристрій LPT3:" -#define STR_LPT4 "Пристрій LPT4:" -#define STR_SERIAL1 "Послідов. порт COM1" -#define STR_SERIAL2 "Послідов. порт COM2" -#define STR_SERIAL3 "Послідов. порт COM3" -#define STR_SERIAL4 "Послідов. порт COM4" -#define STR_PARALLEL1 "Паралельний порт LPT1" -#define STR_PARALLEL2 "Паралельний порт LPT2" -#define STR_PARALLEL3 "Паралельний порт LPT3" -#define STR_PARALLEL4 "Паралельний порт LPT4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "Пристрій COM1:" +#define STR_COM2 "Пристрій COM2:" +#define STR_COM3 "Пристрій COM3:" +#define STR_COM4 "Пристрій COM4:" +#define STR_LPT1 "Пристрій LPT1:" +#define STR_LPT2 "Пристрій LPT2:" +#define STR_LPT3 "Пристрій LPT3:" +#define STR_LPT4 "Пристрій LPT4:" +#define STR_SERIAL1 "Послідов. порт COM1" +#define STR_SERIAL2 "Послідов. порт COM2" +#define STR_SERIAL3 "Послідов. порт COM3" +#define STR_SERIAL4 "Послідов. порт COM4" +#define STR_PARALLEL1 "Паралельний порт LPT1" +#define STR_PARALLEL2 "Паралельний порт LPT2" +#define STR_PARALLEL3 "Паралельний порт LPT3" +#define STR_PARALLEL4 "Паралельний порт LPT4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "Контролер HD:" -#define STR_FDC "Контролер FD:" -#define STR_IDE_TER "Третинний IDE контролер" -#define STR_IDE_QUA "Четвертинний IDE контролер" -#define STR_SCSI "SCSI" +#define STR_HDC "Контролер HD:" +#define STR_FDC "Контролер FD:" +#define STR_IDE_TER "Третинний IDE контролер" +#define STR_IDE_QUA "Четвертинний IDE контролер" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "Контролер 1:" #define STR_SCSI_2 "Контролер 2:" #define STR_SCSI_3 "Контролер 3:" #define STR_SCSI_4 "Контролер 4:" -#define STR_CASSETTE "Касета" +#define STR_CASSETTE "Касета" -#define STR_HDD "Жорсткі диски:" -#define STR_NEW "&Створити..." -#define STR_EXISTING "&Вибрати..." +#define STR_HDD "Жорсткі диски:" +#define STR_NEW "&Створити..." +#define STR_EXISTING "&Вибрати..." #define STR_REMOVE "&Прибрати" -#define STR_BUS "Шина:" -#define STR_CHANNEL "Канал:" +#define STR_BUS "Шина:" +#define STR_CHANNEL "Канал:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "&Вказати..." -#define STR_SECTORS "Сектора:" -#define STR_HEADS "Головки:" -#define STR_CYLS "Циліндри:" -#define STR_SIZE_MB "Розмір (МБ):" -#define STR_TYPE "Тип:" -#define STR_IMG_FORMAT "Тип образу:" -#define STR_BLOCK_SIZE "Розмір блоку:" +#define STR_SPECIFY "&Вказати..." +#define STR_SECTORS "Сектора:" +#define STR_HEADS "Головки:" +#define STR_CYLS "Циліндри:" +#define STR_SIZE_MB "Розмір (МБ):" +#define STR_TYPE "Тип:" +#define STR_IMG_FORMAT "Тип образу:" +#define STR_BLOCK_SIZE "Розмір блоку:" -#define STR_FLOPPY_DRIVES "Гнучкі диски:" -#define STR_TURBO "Турбо таймінги" -#define STR_CHECKBPB "Перевіряти BPB" -#define STR_CDROM_DRIVES "Дисководи CD-ROM:" -#define STR_CD_SPEED "Швидкість:" -#define STR_EARLY "Більш ранній дисковод" +#define STR_FLOPPY_DRIVES "Гнучкі диски:" +#define STR_TURBO "Турбо таймінги" +#define STR_CHECKBPB "Перевіряти BPB" +#define STR_CDROM_DRIVES "Дисководи CD-ROM:" +#define STR_CD_SPEED "Швидкість:" -#define STR_MO_DRIVES "Магнітооптичні дисководи:" -#define STR_ZIP_DRIVES "ZIP дисководи:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "Магнітооптичні дисководи:" +#define STR_ZIP_DRIVES "ZIP дисководи:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA RTC:" #define STR_ISAMEM "Карта розширення пам'яті (ISA)" -#define STR_ISAMEM_1 "Карта 1:" -#define STR_ISAMEM_2 "Карта 2:" -#define STR_ISAMEM_3 "Карта 3:" -#define STR_ISAMEM_4 "Карта 4:" +#define STR_ISAMEM_1 "Карта 1:" +#define STR_ISAMEM_2 "Карта 2:" +#define STR_ISAMEM_3 "Карта 3:" +#define STR_ISAMEM_4 "Карта 4:" #define STR_BUGGER "Пристрій ISABugger" -#define STR_POSTCARD "Карта POST" +#define STR_POSTCARD "Карта POST" -#define FONT_SIZE 9 -#define FONT_NAME "Segoe UI" +#define FONT_SIZE 9 +#define FONT_NAME "Segoe UI" #include "dialogs.rc" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "Помилка" IDS_2050 "Непереробна помилка" IDS_2051 " - PAUSED" @@ -404,15 +404,15 @@ BEGIN IDS_2055 "Образи ZIP (*.IM?;*.ZDI)\0*.IM?;*.ZDI\0" IDS_2056 "86Box не зміг знайти жодного відповідного для використання файлу з ПЗУ.\n\nБудь ласка завантажте набір ПЗУ і витягніть його в каталог ""roms""." IDS_2057 "(порожньо)" - IDS_2058 "Образи ZIP (*.IM?;*.ZDI)\0*.IM?;*.ZDI\0Всі файли (*.*)\0*.*\0" + IDS_2058 "Образи ZIP (*.IM?;*.ZDI)\0*.IM?;*.ZDI\0Усі файли (*.*)\0*.*\0" IDS_2059 "Турбо" IDS_2060 "Увімк" IDS_2061 "Вимк" - IDS_2062 "Всі образи (*.86F;*.DSK;*.FLP;*.IM?;*.*FD?)\0*.86F;*.DSK;*.FLP;*.IM?;*.*FD?\0Прості посекторні образи (*.DSK;*.FLP;*.IM?;*.*FD?)\0*.DSK;*.FLP;*.IM?;*.IMG;*.*FD?\0Образ поверхні (*.86F)\0*.86F\0" + IDS_2062 "Усі образи (*.86F;*.DSK;*.FLP;*.IM?;*.*FD?)\0*.86F;*.DSK;*.FLP;*.IM?;*.*FD?\0Прості посекторні образи (*.DSK;*.FLP;*.IM?;*.*FD?)\0*.DSK;*.FLP;*.IM?;*.IMG;*.*FD?\0Образ поверхні (*.86F)\0*.86F\0" IDS_2063 "Системна плата ""%hs"" недоступна через відсутність файлу її ПЗУ в каталозі roms/machines. Переключення на доступну системну плату." END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "Відеокарта ""%hs"" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Переключення на доступну відеокарту." IDS_2065 "Комп'ютер" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "Натисніть F8+F12 або середню кнопку миші, щоб звільнити курсор" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Неможливо ініціалізувати FluidSynth" IDS_2081 "Шина" IDS_2082 "Файл" IDS_2083 "C" @@ -464,14 +463,13 @@ BEGIN IDS_2107 "%u" IDS_2108 "%u МБ (CHS: %i, %i, %i)" IDS_2109 "Дисковод %i (%s): %ls" - IDS_2110 "Всі образи (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Розширені образи секторів (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Основні образи секторів (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Образи Flux (*.FDI)\0*.FDI\0Образи Surface (*.86F;*.MFM)\0*.86F;*.MFM\0Всі файли (*.*)\0*.*\0" - IDS_2111 "Неможливо ініціалізувати FreeType" + IDS_2110 "Усі образи (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Розширені образи секторів (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Основні образи секторів (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Образи Flux (*.FDI)\0*.FDI\0Образи Surface (*.86F;*.MFM)\0*.86F;*.MFM\0Усі файли (*.*)\0*.*\0" IDS_2112 "Неможливо ініціалізувати SDL, потрібно SDL2.dll" IDS_2113 "Ви впевнені, що хочете виконати холодне перезавантаження емульованої машини?" IDS_2114 "Ви впевнені, що хочете вийти з 86Box?" IDS_2115 "Неможливо ініціалізувати Ghostscript" IDS_2116 "Магнітооптичний %i (%ls): %ls" - IDS_2117 "Образи магнітооптичних дисків (*.IM?;*.MDI)\0*.IM?;*.MDI\0Все файлы (*.*)\0*.*\0" + IDS_2117 "Образи магнітооптичних дисків (*.IM?;*.MDI)\0*.IM?;*.MDI\0Усі файлі (*.*)\0*.*\0" IDS_2118 "Ласкаво просимо в 86Box!" IDS_2119 "Вбудований контролер" IDS_2120 "Вихід" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Переконайтесь, що " LIB_NAME_PCAP " встановлений і ваше мережеве з'єднання, сумісне з " LIB_NAME_PCAP "." IDS_2131 "Неприпустима конфігурація" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "Для емуляції принтера ESC/P потрібно " LIB_NAME_FREETYPE "." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif - IDS_2133 LIB_NAME_GS " потрібно для автоматичного перетворення файлів PostScript в PDF.\n\nВсі документи, відправлені на загальний принтер PostScript, будуть збережені у вигляді файлів PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "Для FluidSynth MIDI-висновку потрібно " LIB_NAME_FLUIDSYNTH "." + IDS_2133 LIB_NAME_GS " потрібно для автоматичного перетворення файлів PostScript в PDF.\n\nсі документи, відправлені на загальний принтер PostScript, будуть збережені у вигляді файлів PostScript (.ps)." IDS_2135 "Вхід у повноекранний режим" IDS_2136 "Більше не показувати це повідомлення" IDS_2137 "Не виходити" @@ -524,124 +510,126 @@ BEGIN IDS_2146 "Ви завантажуєте непідтримувану конфігурацію" IDS_2147 "Вибір типів ЦП для цієї системної плати на даній емульованій машині відключено.\n\nЦе дозволяє вибрати процесор, який в іншому випадку не сумісний з вибраною материнською платою. Однак, ви можете зіткнутися з несумісністю з BIOS материнської плати або іншим ПО.\n\nВключення цього параметра офіційно не підтримується, і всі подані звіти про помилки можуть бути закриті як недійсні." IDS_2148 "Продовжити" - IDS_2149 "Касета: %s" - IDS_2150 "Образи касет (*.PCM;*.RAW;*.WAV;*.CAS)\0*.PCM;*.RAW;*.WAV;*.CAS\0Усі файли (*.*)\0*. *\0" - IDS_2151 "Картридж %i: %ls" - IDS_2152 "Образи картриджів (*.A;*.B;*.JRC)\0*.A;*.B;*.JRC\0Всі файли (*.*)\0*.*\0" - IDS_2153 "Помилка ініціалізації рендерера" - IDS_2154 "Неможливо ініціалізувати рендерер OpenGL (3.0). Будь ласка, використовуйте інший рендерер." - IDS_2155 "Відновити виконання" - IDS_2156 "Призупинити виконання" - IDS_2157 "Натиснути Ctrl+Alt+Del" - IDS_2158 "Натиснути Ctrl+Alt+Esc" - IDS_2159 "Холодне перезавантаження" - IDS_2160 "Сигнал завершення ACPI" - IDS_2161 "Налаштування машини" - IDS_2162 "Більш ранній дисковод" + IDS_2149 "Касета: %s" + IDS_2150 "Образи касет (*.PCM;*.RAW;*.WAV;*.CAS)\0*.PCM;*.RAW;*.WAV;*.CAS\0Усі файли (*.*)\0*. *\0" + IDS_2151 "Картридж %i: %ls" + IDS_2152 "Образи картриджів (*.A;*.B;*.JRC)\0*.A;*.B;*.JRC\0Усі файли (*.*)\0*.*\0" + IDS_2153 "Помилка ініціалізації рендерера" + IDS_2154 "Неможливо ініціалізувати рендерер OpenGL (3.0). Будь ласка, використовуйте інший рендерер." + IDS_2155 "Відновити виконання" + IDS_2156 "Призупинити виконання" + IDS_2157 "Натиснути Ctrl+Alt+Del" + IDS_2158 "Натиснути Ctrl+Alt+Esc" + IDS_2159 "Холодне перезавантаження" + IDS_2160 "Сигнал завершення ACPI" + IDS_2161 "Налаштування машини" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" - IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2166 "Відеокарта #2 ""%hs"" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Відключення другої відеокарти." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END STRINGTABLE DISCARDABLE BEGIN - IDS_4096 "Жорсткий диск (%s)" - IDS_4097 "%01i:%01i" - IDS_4098 "%01i" - IDS_4099 "MFM/RLL або ESDI дисководів CD-ROM ніколи не існувало" - IDS_4100 "Задати вручну..." - IDS_4101 "Задати вручну (large)..." - IDS_4102 "Створити новий жорсткий диск" - IDS_4103 "Вибрати існуючий жорсткий диск" - IDS_4104 "Розмір образів дисків HDI не може перевищувати 4 ГБ." - IDS_4105 "Розмір образів дисків не може перевищувати 127 ГБ." - IDS_4106 "Образи жорстких дисків (*.HD?;*.IM?;*.VHD)\0*.HD?;*.IM?;*.VHD\0Всі файли (*.*)\0*.*\0 " - IDS_4107 "Неможливо прочитати файл" - IDS_4108 "Неможливо записати файл" - IDS_4109 "Образи HDI або HDX з розміром сектора, відмінним від 512, не підтримуються." - IDS_4110 "USB поки не підтримується" - IDS_4111 "Файл образу диска вже існує" - IDS_4112 "Вкажіть правильне ім'я файлу." - IDS_4113 "Образ диску створено" - IDS_4114 "Переконайтеся, що файл є доступним для читання." - IDS_4115 "Переконайтеся, що файл зберігається в каталог, який є доступним для запису." - IDS_4116 "Занадто великий образ диска" - IDS_4117 "Не забудьте розмітити та відформатувати новостворений диск." - IDS_4118 "Вибраний файл буде перезаписано. Ви впевнені, що хочете використовувати його?" - IDS_4119 "Образ диска, що не підтримується" - IDS_4120 "Перезаписати" - IDS_4121 "Не перезаписувати" - IDS_4122 "RAW образ (.img)" - IDS_4123 "Образ HDI (.hdi)" - IDS_4124 "Образ HDX (.hdx)" - IDS_4125 "VHD фіксованого розміру (.vhd)" - IDS_4126 "VHD динамічного розміру (.vhd)" - IDS_4127 "Диференційований образ VHD (.vhd)" - IDS_4128 "Великі блоки (2 МБ)" - IDS_4129 "Маленькі блоки (512 КБ)" - IDS_4130 "Файли VHD (*.VHD)\0*.VHD\0Всі файли (*.*)\0*.*\0" - IDS_4131 "Виберіть батьківський VHD" - IDS_4132 "Це може означати, що батьківський образ був змінений після того, як було створено диференційований образ.\n\nЦе також може статися, якщо файли зображення були переміщені або скопійовані, або через помилку в програмі, що створила цей диск.\n \nВи хочете виправити тимчасові позначки?" - IDS_4133 "Тимчасові мітки батьківського та дочірнього дисків не співпадають" - IDS_4134 "Не вдалося виправити тимчасову позначку VHD." - IDS_4135 "%01i:%02i" + IDS_4096 "Жорсткий диск (%s)" + IDS_4097 "%01i:%01i" + IDS_4098 "%01i" + IDS_4099 "MFM/RLL або ESDI дисководів CD-ROM ніколи не існувало" + IDS_4100 "Задати вручну..." + IDS_4101 "Задати вручну (large)..." + IDS_4102 "Створити новий жорсткий диск" + IDS_4103 "Вибрати існуючий жорсткий диск" + IDS_4104 "Розмір образів дисків HDI не може перевищувати 4 ГБ." + IDS_4105 "Розмір образів дисків не може перевищувати 127 ГБ." + IDS_4106 "Образи жорстких дисків (*.HD?;*.IM?;*.VHD)\0*.HD?;*.IM?;*.VHD\0Усі файли (*.*)\0*.*\0 " + IDS_4107 "Неможливо прочитати файл" + IDS_4108 "Неможливо записати файл" + IDS_4109 "Образи HDI або HDX з розміром сектора, відмінним від 512, не підтримуються." + IDS_4110 "USB поки не підтримується" + IDS_4111 "Файл образу диска вже існує" + IDS_4112 "Вкажіть правильне ім'я файлу." + IDS_4113 "Образ диску створено" + IDS_4114 "Переконайтеся, що файл є доступним для читання." + IDS_4115 "Переконайтеся, що файл зберігається в каталог, який є доступним для запису." + IDS_4116 "Занадто великий образ диска" + IDS_4117 "Не забудьте розмітити та відформатувати новостворений диск." + IDS_4118 "Вибраний файл буде перезаписано. Ви впевнені, що хочете використовувати його?" + IDS_4119 "Образ диска, що не підтримується" + IDS_4120 "Перезаписати" + IDS_4121 "Не перезаписувати" + IDS_4122 "RAW образ (.img)" + IDS_4123 "Образ HDI (.hdi)" + IDS_4124 "Образ HDX (.hdx)" + IDS_4125 "VHD фіксованого розміру (.vhd)" + IDS_4126 "VHD динамічного розміру (.vhd)" + IDS_4127 "Диференційований образ VHD (.vhd)" + IDS_4128 "Великі блоки (2 МБ)" + IDS_4129 "Маленькі блоки (512 КБ)" + IDS_4130 "Файли VHD (*.VHD)\0*.VHD\0Усі файли (*.*)\0*.*\0" + IDS_4131 "Виберіть батьківський VHD" + IDS_4132 "Це може означати, що батьківський образ був змінений після того, як було створено диференційований образ.\n\nЦе також може статися, якщо файли зображення були переміщені або скопійовані, або через помилку в програмі, що створила цей диск.\n \nВи хочете виправити тимчасові позначки?" + IDS_4133 "Тимчасові мітки батьківського та дочірнього дисків не співпадають" + IDS_4134 "Не вдалося виправити тимчасову позначку VHD." + IDS_4135 "%01i:%02i" - IDS_4352 "MFM/RLL" - IDS_4353 "XTA" - IDS_4354 "ESDI" - IDS_4355 "IDE" - IDS_4356 "ATAPI" - IDS_4357 "SCSI" + IDS_4352 "MFM/RLL" + IDS_4353 "XTA" + IDS_4354 "ESDI" + IDS_4355 "IDE" + IDS_4356 "ATAPI" + IDS_4357 "SCSI" - IDS_4608 "MFM/RLL (%01i:%01i)" - IDS_4609 "XTA (%01i:%01i)" - IDS_4610 "ESDI (%01i:%01i)" - IDS_4611 "IDE (%01i:%01i)" - IDS_4612 "ATAPI (%01i:%01i)" - IDS_4613 "SCSI (%01i:%02i)" + IDS_4608 "MFM/RLL (%01i:%01i)" + IDS_4609 "XTA (%01i:%01i)" + IDS_4610 "ESDI (%01i:%01i)" + IDS_4611 "IDE (%01i:%01i)" + IDS_4612 "ATAPI (%01i:%01i)" + IDS_4613 "SCSI (%01i:%02i)" - IDS_5120 "CD-ROM %i (%s): %s" + IDS_5120 "CD-ROM %i (%s): %s" - IDS_5376 "Відключено" - IDS_5381 "ATAPI" - IDS_5382 "SCSI" + IDS_5376 "Відключено" + IDS_5381 "ATAPI" + IDS_5382 "SCSI" - IDS_5632 "Відключено" - IDS_5637 "ATAPI (%01i:%01i)" - IDS_5638 "SCSI (%01i:%02i)" + IDS_5632 "Відключено" + IDS_5637 "ATAPI (%01i:%01i)" + IDS_5638 "SCSI (%01i:%02i)" - IDS_5888 "160 кБ" - IDS_5889 "180 кБ" - IDS_5890 "320 кБ" - IDS_5891 "360 кБ" - IDS_5892 "640 кБ" - IDS_5893 "720 кБ" - IDS_5894 "1.2 МБ" - IDS_5895 "1.25 МБ" - IDS_5896 "1.44 МБ" - IDS_5897 "DMF (кластер 1024)" - IDS_5898 "DMF (кластер 2048)" - IDS_5899 "2.88 МБ" - IDS_5900 "ZIP 100" - IDS_5901 "ZIP 250" - IDS_5902 "3.5"" 128 МБ (ISO 10090)" - IDS_5903 "3.5"" 230 МБ (ISO 13963)" - IDS_5904 "3.5"" 540 МБ (ISO 15498)" - IDS_5905 "3.5"" 640 МБ (ISO 15498)" - IDS_5906 "3.5"" 1.3 ГБ (GigaMO)" - IDS_5907 "3.5"" 2.3 ГБ (GigaMO 2)" - IDS_5908 "5.25"" 600 МБ" - IDS_5909 "5.25"" 650 МБ" - IDS_5910 "5.25"" 1 ГБ" - IDS_5911 "5.25"" 1.3 ГБ" + IDS_5888 "160 кБ" + IDS_5889 "180 кБ" + IDS_5890 "320 кБ" + IDS_5891 "360 кБ" + IDS_5892 "640 кБ" + IDS_5893 "720 кБ" + IDS_5894 "1.2 МБ" + IDS_5895 "1.25 МБ" + IDS_5896 "1.44 МБ" + IDS_5897 "DMF (кластер 1024)" + IDS_5898 "DMF (кластер 2048)" + IDS_5899 "2.88 МБ" + IDS_5900 "ZIP 100" + IDS_5901 "ZIP 250" + IDS_5902 "3.5"" 128 МБ (ISO 10090)" + IDS_5903 "3.5"" 230 МБ (ISO 13963)" + IDS_5904 "3.5"" 540 МБ (ISO 15498)" + IDS_5905 "3.5"" 640 МБ (ISO 15498)" + IDS_5906 "3.5"" 1.3 ГБ (GigaMO)" + IDS_5907 "3.5"" 2.3 ГБ (GigaMO 2)" + IDS_5908 "5.25"" 600 МБ" + IDS_5909 "5.25"" 650 МБ" + IDS_5910 "5.25"" 1 ГБ" + IDS_5911 "5.25"" 1.3 ГБ" - IDS_6144 "Точний RPM" - IDS_6145 "На 1% повільніше точного RPM" - IDS_6146 "На 1.5% повільніше точного RPM" - IDS_6147 "На 2% повільніше точного RPM" + IDS_6144 "Точний RPM" + IDS_6145 "На 1% повільніше точного RPM" + IDS_6146 "На 1.5% повільніше точного RPM" + IDS_6147 "На 2% повільніше точного RPM" - IDS_7168 "(Системний)" + IDS_7168 "(Системний)" END #define IDS_LANG_ENUS IDS_7168 diff --git a/src/win/languages/zh-CN.rc b/src/win/languages/zh-CN.rc index c84da1578..3320af15f 100644 --- a/src/win/languages/zh-CN.rc +++ b/src/win/languages/zh-CN.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "操作(&A)" BEGIN - MENUITEM "键盘需要捕捉(&K)", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "将右 CTRL 键映射为左 ALT 键(&R)", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "键盘需要捕捉(&K)", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "将右 CTRL 键映射为左 ALT 键(&R)", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "硬重置(&H)...", IDM_ACTION_HRESET - MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "硬重置(&H)...", IDM_ACTION_HRESET + MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "暂停(&P)", IDM_ACTION_PAUSE + MENUITEM "暂停(&P)", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "退出(&X)...", IDM_ACTION_EXIT + MENUITEM "退出(&X)...", IDM_ACTION_EXIT END POPUP "查看(&V)" BEGIN - MENUITEM "隐藏状态栏(&H)", IDM_VID_HIDE_STATUS_BAR - MENUITEM "隐藏工具栏(&T)", IDM_VID_HIDE_TOOLBAR + MENUITEM "隐藏状态栏(&H)", IDM_VID_HIDE_STATUS_BAR + MENUITEM "隐藏工具栏(&T)", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "Show non-primary monitors(&S)", IDM_VID_MONITORS - MENUITEM "窗口大小可调(&R)", IDM_VID_RESIZE - MENUITEM "记住窗口大小和位置(&E)", IDM_VID_REMEMBER + MENUITEM "Show non-primary monitors(&S)", IDM_VID_MONITORS + MENUITEM "窗口大小可调(&R)", IDM_VID_RESIZE + MENUITEM "记住窗口大小和位置(&E)", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "渲染器(&N)" BEGIN - MENUITEM "SDL (软件)(&S)", IDM_VID_SDL_SW - MENUITEM "SDL (硬件)(&H)", IDM_VID_SDL_HW - MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL - MENUITEM "OpenGL (3.0 核心)(&G)", IDM_VID_OPENGL_CORE + MENUITEM "SDL (软件)(&S)", IDM_VID_SDL_SW + MENUITEM "SDL (硬件)(&H)", IDM_VID_SDL_HW + MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL + MENUITEM "OpenGL (3.0 核心)(&G)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "VNC(&V)", IDM_VID_VNC + MENUITEM "VNC(&V)", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "指定窗口大小...", IDM_VID_SPECIFY_DIM - MENUITEM "强制 4:3 显示比例(&O)", IDM_VID_FORCE43 + MENUITEM "指定窗口大小...", IDM_VID_SPECIFY_DIM + MENUITEM "强制 4:3 显示比例(&O)", IDM_VID_FORCE43 POPUP "窗口缩放系数(&W)" BEGIN - MENUITEM "0.5x(&0)", IDM_VID_SCALE_1X - MENUITEM "1x(&1)", IDM_VID_SCALE_2X - MENUITEM "1.5x(&5)", IDM_VID_SCALE_3X - MENUITEM "2x(&2)", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "0.5x(&0)", IDM_VID_SCALE_1X + MENUITEM "1x(&1)", IDM_VID_SCALE_2X + MENUITEM "1.5x(&5)", IDM_VID_SCALE_3X + MENUITEM "2x(&2)", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "过滤方式" BEGIN - MENUITEM "邻近(&N)", IDM_VID_FILTER_NEAREST - MENUITEM "线性(&L)", IDM_VID_FILTER_LINEAR + MENUITEM "邻近(&N)", IDM_VID_FILTER_NEAREST + MENUITEM "线性(&L)", IDM_VID_FILTER_LINEAR END - MENUITEM "HiDPI 缩放(&D)", IDM_VID_HIDPI + MENUITEM "HiDPI 缩放(&D)", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "全屏(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "全屏(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "全屏拉伸模式(&S)" BEGIN - MENUITEM "全屏拉伸(&F)", IDM_VID_FS_FULL - MENUITEM "4:3(&4)", IDM_VID_FS_43 + MENUITEM "全屏拉伸(&F)", IDM_VID_FS_FULL + MENUITEM "4:3(&4)", IDM_VID_FS_43 MENUITEM "保持比例(&S)", IDM_VID_FS_KEEPRATIO - MENUITEM "整数比例(&I)", IDM_VID_FS_INT + MENUITEM "整数比例(&I)", IDM_VID_FS_INT END POPUP "EGA/(S)VGA 设置(&G)" BEGIN - MENUITEM "VGA 显示器反色显示(&I)", IDM_VID_INVERT + MENUITEM "VGA 显示器反色显示(&I)", IDM_VID_INVERT POPUP "VGA 屏幕类型(&T)" BEGIN - MENUITEM "RGB 彩色(&C)", IDM_VID_GRAY_RGB - MENUITEM "RGB 灰度(&R)", IDM_VID_GRAY_MONO - MENUITEM "琥珀色单色显示器(&A)", IDM_VID_GRAY_AMBER - MENUITEM "绿色单色显示器(&G)", IDM_VID_GRAY_GREEN - MENUITEM "白色单色显示器(&W)", IDM_VID_GRAY_WHITE + MENUITEM "RGB 彩色(&C)", IDM_VID_GRAY_RGB + MENUITEM "RGB 灰度(&R)", IDM_VID_GRAY_MONO + MENUITEM "琥珀色单色显示器(&A)", IDM_VID_GRAY_AMBER + MENUITEM "绿色单色显示器(&G)", IDM_VID_GRAY_GREEN + MENUITEM "白色单色显示器(&W)", IDM_VID_GRAY_WHITE END POPUP "灰度转换类型(&C)" BEGIN - MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 - MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 - MENUITEM "平均(&A)", IDM_VID_GRAYCT_AVE + MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 + MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 + MENUITEM "平均(&A)", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGA 过扫描(&G)", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGA 过扫描(&G)", IDM_VID_OVERSCAN MENUITEM "更改单色显示对比度(&M)", IDM_VID_CGACON END - MENUITEM "介质(&M)", IDM_MEDIA + MENUITEM "介质(&M)", IDM_MEDIA POPUP "工具(&T)" BEGIN - MENUITEM "设置(&S)...", IDM_CONFIG - MENUITEM "更新状态栏图标(&U)", IDM_UPDATE_ICONS + MENUITEM "设置(&S)...", IDM_CONFIG + MENUITEM "更新状态栏图标(&U)", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "截图(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "截图(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "首选项(&P)...", IDM_PREFERENCES + MENUITEM "首选项(&P)...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "启用 Discord 集成(&D)", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "音量增益(&G)...", IDM_SND_GAIN + MENUITEM "音量增益(&G)...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "开始追踪\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "结束追踪\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "开始追踪\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "结束追踪\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "帮助(&H)" BEGIN - MENUITEM "文档(&D)...", IDM_DOCS - MENUITEM "关于 86Box(&A)...", IDM_ABOUT + MENUITEM "文档(&D)...", IDM_DOCS + MENUITEM "关于 86Box(&A)...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新建镜像(&N)...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "新建镜像(&N)...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "打开已存在的镜像(&E)...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "打开已存在的镜像(&E)...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "录制(&R)", IDM_CASSETTE_RECORD - MENUITEM "播放(&P)", IDM_CASSETTE_PLAY - MENUITEM "倒带至起点(&R)", IDM_CASSETTE_REWIND - MENUITEM "快进至终点(&F)", IDM_CASSETTE_FAST_FORWARD + MENUITEM "录制(&R)", IDM_CASSETTE_RECORD + MENUITEM "播放(&P)", IDM_CASSETTE_PLAY + MENUITEM "倒带至起点(&R)", IDM_CASSETTE_REWIND + MENUITEM "快进至终点(&F)", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "弹出(&J)", IDM_CASSETTE_EJECT + MENUITEM "弹出(&J)", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "镜像(&I)...", IDM_CARTRIDGE_IMAGE + MENUITEM "镜像(&I)...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "弹出(&J)", IDM_CARTRIDGE_EJECT + MENUITEM "弹出(&J)", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新建镜像(&N)...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "新建镜像(&N)...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "打开已存在的镜像(&E)...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "打开已存在的镜像(&E)...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "导出为 86F 格式(&x)...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "导出为 86F 格式(&x)...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "弹出(&J)", IDM_FLOPPY_EJECT + MENUITEM "弹出(&J)", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "静音(&M)", IDM_CDROM_MUTE + MENUITEM "静音(&M)", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "空置驱动器(&M)", IDM_CDROM_EMPTY - MENUITEM "载入上一个镜像(&R)", IDM_CDROM_RELOAD + MENUITEM "空置驱动器(&M)", IDM_CDROM_EMPTY + MENUITEM "载入上一个镜像(&R)", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "镜像(&I)...", IDM_CDROM_IMAGE - MENUITEM "文件夹(&F)...", IDM_CDROM_DIR + MENUITEM "镜像(&I)...", IDM_CDROM_IMAGE + MENUITEM "文件夹(&F)...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新建镜像(&N)...", IDM_ZIP_IMAGE_NEW + MENUITEM "新建镜像(&N)...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "打开已存在的镜像(&E)...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "打开已存在的镜像(&E)...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "弹出(&J)", IDM_ZIP_EJECT - MENUITEM "载入上一个镜像(&R)", IDM_ZIP_RELOAD + MENUITEM "弹出(&J)", IDM_ZIP_EJECT + MENUITEM "载入上一个镜像(&R)", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新建镜像(&N)...", IDM_MO_IMAGE_NEW + MENUITEM "新建镜像(&N)...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "打开已存在的镜像(&E)...", IDM_MO_IMAGE_EXISTING - MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "打开已存在的镜像(&E)...", IDM_MO_IMAGE_EXISTING + MENUITEM "打开已存在的镜像并写保护(&W)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "弹出(&J)", IDM_MO_EJECT - MENUITEM "载入上一个镜像(&R)", IDM_MO_RELOAD + MENUITEM "弹出(&J)", IDM_MO_EJECT + MENUITEM "载入上一个镜像(&R)", IDM_MO_RELOAD END END @@ -240,147 +240,147 @@ END // Dialog // -#define STR_PREFERENCES "首选项" -#define STR_SND_GAIN "音量增益" -#define STR_NEW_FLOPPY "新建镜像" +#define STR_PREFERENCES "首选项" +#define STR_SND_GAIN "音量增益" +#define STR_NEW_FLOPPY "新建镜像" #define STR_CONFIG "设置" -#define STR_SPECIFY_DIM "指定主窗口大小" +#define STR_SPECIFY_DIM "指定主窗口大小" #define STR_OK "确定" #define STR_CANCEL "取消" #define STR_GLOBAL "将以上设置存储为全局默认值(&G)" -#define STR_DEFAULT "默认(&D)" -#define STR_LANGUAGE "语言:" -#define STR_ICONSET "图标集:" +#define STR_DEFAULT "默认(&D)" +#define STR_LANGUAGE "语言:" +#define STR_ICONSET "图标集:" -#define STR_GAIN "增益" +#define STR_GAIN "增益" -#define STR_FILE_NAME "文件名:" -#define STR_DISK_SIZE "磁盘大小:" -#define STR_RPM_MODE "转速 (RPM) 模式:" -#define STR_PROGRESS "进度:" +#define STR_FILE_NAME "文件名:" +#define STR_DISK_SIZE "磁盘大小:" +#define STR_RPM_MODE "转速 (RPM) 模式:" +#define STR_PROGRESS "进度:" -#define STR_WIDTH "宽度:" +#define STR_WIDTH "宽度:" #define STR_HEIGHT "高度:" -#define STR_LOCK_TO_SIZE "锁定此大小" +#define STR_LOCK_TO_SIZE "锁定此大小" -#define STR_MACHINE_TYPE "机器类型:" -#define STR_MACHINE "机型:" -#define STR_CONFIGURE "配置" -#define STR_CPU_TYPE "CPU 类型:" -#define STR_CPU_SPEED "速度:" -#define STR_FPU "浮点处理器 (FPU):" -#define STR_WAIT_STATES "等待状态 (WS):" +#define STR_MACHINE_TYPE "机器类型:" +#define STR_MACHINE "机型:" +#define STR_CONFIGURE "配置" +#define STR_CPU_TYPE "CPU 类型:" +#define STR_CPU_SPEED "速度:" +#define STR_FPU "浮点处理器 (FPU):" +#define STR_WAIT_STATES "等待状态 (WS):" #define STR_MB "MB" #define STR_MEMORY "内存:" -#define STR_TIME_SYNC "时间同步" -#define STR_DISABLED "禁用" -#define STR_ENABLED_LOCAL "启用 (本地时间)" -#define STR_ENABLED_UTC "启用 (UTC)" -#define STR_DYNAREC "动态重编译器" +#define STR_TIME_SYNC "时间同步" +#define STR_DISABLED "禁用" +#define STR_ENABLED_LOCAL "启用 (本地时间)" +#define STR_ENABLED_UTC "启用 (UTC)" +#define STR_DYNAREC "动态重编译器" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "显卡:" -#define STR_VIDEO_2 "显卡 2:" +#define STR_VIDEO "显卡:" +#define STR_VIDEO_2 "显卡 2:" #define STR_VOODOO "Voodoo Graphics" -#define STR_IBM8514 "IBM 8514/a Graphics" -#define STR_XGA "XGA Graphics" +#define STR_IBM8514 "IBM 8514/a Graphics" +#define STR_XGA "XGA Graphics" -#define STR_MOUSE "鼠标:" -#define STR_JOYSTICK "操纵杆:" -#define STR_JOY1 "操纵杆 1..." -#define STR_JOY2 "操纵杆 2..." -#define STR_JOY3 "操纵杆 3..." -#define STR_JOY4 "操纵杆 4..." +#define STR_MOUSE "鼠标:" +#define STR_JOYSTICK "操纵杆:" +#define STR_JOY1 "操纵杆 1..." +#define STR_JOY2 "操纵杆 2..." +#define STR_JOY3 "操纵杆 3..." +#define STR_JOY4 "操纵杆 4..." #define STR_SOUND1 "声卡 1:" #define STR_SOUND2 "声卡 2:" #define STR_SOUND3 "声卡 3:" #define STR_SOUND4 "声卡 4:" -#define STR_MIDI_OUT "MIDI 输出设备:" -#define STR_MIDI_IN "MIDI 输入设备:" +#define STR_MIDI_OUT "MIDI 输出设备:" +#define STR_MIDI_IN "MIDI 输入设备:" #define STR_MPU401 "独立 MPU-401" -#define STR_FLOAT "使用单精度浮点 (FLOAT32)" -#define STR_FM_DRIVER "调频合成器驱动器" -#define STR_FM_DRV_NUKED "Nuked (更准确)" -#define STR_FM_DRV_YMFM "YMFM (更快)" +#define STR_FLOAT "使用单精度浮点 (FLOAT32)" +#define STR_FM_DRIVER "调频合成器驱动器" +#define STR_FM_DRV_NUKED "Nuked (更准确)" +#define STR_FM_DRV_YMFM "YMFM (更快)" -#define STR_NET_TYPE "网络类型:" -#define STR_PCAP "PCap 设备:" -#define STR_NET "网络适配器:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "网络类型:" +#define STR_PCAP "PCap 设备:" +#define STR_NET "网络适配器:" +#define STR_NET1 "Network card 1:" +#define STR_NET2 "Network card 2:" +#define STR_NET3 "Network card 3:" +#define STR_NET4 "Network card 4:" -#define STR_COM1 "COM1 设备:" -#define STR_COM2 "COM2 设备:" -#define STR_COM3 "COM3 设备:" -#define STR_COM4 "COM4 设备:" -#define STR_LPT1 "LPT1 设备:" -#define STR_LPT2 "LPT2 设备:" -#define STR_LPT3 "LPT3 设备:" -#define STR_LPT4 "LPT4 设备:" -#define STR_SERIAL1 "串口 1" -#define STR_SERIAL2 "串口 2" -#define STR_SERIAL3 "串口 3" -#define STR_SERIAL4 "串口 4" -#define STR_PARALLEL1 "并口 1" -#define STR_PARALLEL2 "并口 2" -#define STR_PARALLEL3 "并口 3" -#define STR_PARALLEL4 "并口 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1 设备:" +#define STR_COM2 "COM2 设备:" +#define STR_COM3 "COM3 设备:" +#define STR_COM4 "COM4 设备:" +#define STR_LPT1 "LPT1 设备:" +#define STR_LPT2 "LPT2 设备:" +#define STR_LPT3 "LPT3 设备:" +#define STR_LPT4 "LPT4 设备:" +#define STR_SERIAL1 "串口 1" +#define STR_SERIAL2 "串口 2" +#define STR_SERIAL3 "串口 3" +#define STR_SERIAL4 "串口 4" +#define STR_PARALLEL1 "并口 1" +#define STR_PARALLEL2 "并口 2" +#define STR_PARALLEL3 "并口 3" +#define STR_PARALLEL4 "并口 4" +#define STR_SERIAL_PASS1 "Serial port passthrough 1" +#define STR_SERIAL_PASS2 "Serial port passthrough 2" +#define STR_SERIAL_PASS3 "Serial port passthrough 3" +#define STR_SERIAL_PASS4 "Serial port passthrough 4" -#define STR_HDC "硬盘控制器:" -#define STR_FDC "软盘控制器:" -#define STR_IDE_TER "第三 IDE 控制器" -#define STR_IDE_QUA "第四 IDE 控制器" -#define STR_SCSI "SCSI" +#define STR_HDC "硬盘控制器:" +#define STR_FDC "软盘控制器:" +#define STR_IDE_TER "第三 IDE 控制器" +#define STR_IDE_QUA "第四 IDE 控制器" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "控制器 1:" #define STR_SCSI_2 "控制器 2:" #define STR_SCSI_3 "控制器 3:" #define STR_SCSI_4 "控制器 4:" -#define STR_CASSETTE "磁带" +#define STR_CASSETTE "磁带" -#define STR_HDD "硬盘:" -#define STR_NEW "新建(&N)..." -#define STR_EXISTING "已有镜像(&E)..." +#define STR_HDD "硬盘:" +#define STR_NEW "新建(&N)..." +#define STR_EXISTING "已有镜像(&E)..." #define STR_REMOVE "移除(&R)" -#define STR_BUS "总线:" -#define STR_CHANNEL "通道:" +#define STR_BUS "总线:" +#define STR_CHANNEL "通道:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "指定(&S)..." -#define STR_SECTORS "扇区(S):" -#define STR_HEADS "磁头(H):" -#define STR_CYLS "柱面(C):" -#define STR_SIZE_MB "大小 (MB):" -#define STR_TYPE "类型:" -#define STR_IMG_FORMAT "镜像格式:" -#define STR_BLOCK_SIZE "块大小:" +#define STR_SPECIFY "指定(&S)..." +#define STR_SECTORS "扇区(S):" +#define STR_HEADS "磁头(H):" +#define STR_CYLS "柱面(C):" +#define STR_SIZE_MB "大小 (MB):" +#define STR_TYPE "类型:" +#define STR_IMG_FORMAT "镜像格式:" +#define STR_BLOCK_SIZE "块大小:" -#define STR_FLOPPY_DRIVES "软盘驱动器:" -#define STR_TURBO "加速时序" -#define STR_CHECKBPB "检查 BPB" -#define STR_CDROM_DRIVES "光盘驱动器:" -#define STR_CD_SPEED "速度:" -#define STR_EARLY "早先的驱动器" +#define STR_FLOPPY_DRIVES "软盘驱动器:" +#define STR_TURBO "加速时序" +#define STR_CHECKBPB "检查 BPB" +#define STR_CDROM_DRIVES "光盘驱动器:" +#define STR_CD_SPEED "速度:" -#define STR_MO_DRIVES "磁光盘驱动器:" -#define STR_ZIP_DRIVES "ZIP 驱动器:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "磁光盘驱动器:" +#define STR_ZIP_DRIVES "ZIP 驱动器:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA 实时时钟:" #define STR_ISAMEM "ISA 内存扩充" -#define STR_ISAMEM_1 "扩展卡 1:" -#define STR_ISAMEM_2 "扩展卡 2:" -#define STR_ISAMEM_3 "扩展卡 3:" -#define STR_ISAMEM_4 "扩展卡 4:" +#define STR_ISAMEM_1 "扩展卡 1:" +#define STR_ISAMEM_2 "扩展卡 2:" +#define STR_ISAMEM_3 "扩展卡 3:" +#define STR_ISAMEM_4 "扩展卡 4:" #define STR_BUGGER "ISABugger 设备" -#define STR_POSTCARD "自检 (POST) 卡" +#define STR_POSTCARD "自检 (POST) 卡" #define FONT_SIZE 9 #define FONT_NAME "Microsoft YaHei" @@ -392,9 +392,9 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "错误" IDS_2050 "致命错误" IDS_2051 " - 已暂停" @@ -412,7 +412,7 @@ BEGIN IDS_2063 "由于 roms/machines 文件夹中缺少合适的 ROM,机型 ""%hs"" 不可用。将切换到其他可用机型。" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "由于 roms/video 文件夹中缺少合适的 ROM,显卡 ""%hs"" 不可用。将切换到其他可用显卡。" IDS_2065 "机型" @@ -432,9 +432,8 @@ BEGIN IDS_2079 "按下 F8+F12 或鼠标中键释放鼠标" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "无法初始化 FluidSynth" IDS_2081 "总线" IDS_2082 "文件" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "软盘 %i (%s): %ls" IDS_2110 "所有镜像 (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0高级扇区镜像 (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0基本扇区镜像 (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux 镜像 (*.FDI)\0*.FDI\0表面镜像 (*.86F;*.MFM)\0*.86F;*.MFM\0所有文件 (*.*)\0*.*\0" - IDS_2111 "无法初始化 FreeType" IDS_2112 "无法初始化 SDL,需要 SDL2.dll" IDS_2113 "确定要硬重置模拟器吗?" IDS_2114 "确定要退出 86Box 吗?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "请确认 " LIB_NAME_PCAP " 已安装且使用兼容 " LIB_NAME_PCAP " 的网络连接。" IDS_2131 "无效配置" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/P 打印机模拟需要" LIB_NAME_FREETYPE -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " 是将 PostScript 文件转换为 PDF 所需要的库。\n\n使用通用 PostScript 打印机打印的文档将被保存为 PostScript (.ps) 文件。" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynth MIDI 输出需要" LIB_NAME_FLUIDSYNTH IDS_2135 "正在进入全屏模式" IDS_2136 "不要再显示此消息" IDS_2137 "不退出" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "硬重置" IDS_2160 "ACPI 关机" IDS_2161 "设置" - IDS_2162 "早先的驱动器" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "硬盘 (%s)" IDS_4097 "%01i:%01i" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(系统默认)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Simplified Chinese resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/languages/zh-TW.rc b/src/win/languages/zh-TW.rc index 5325f0815..4c73ffb6d 100644 --- a/src/win/languages/zh-TW.rc +++ b/src/win/languages/zh-TW.rc @@ -13,122 +13,122 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL // Menu // -MainMenu MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "動作(&A)" BEGIN - MENUITEM "鍵盤需要捕捉(&K)", IDM_ACTION_KBD_REQ_CAPTURE - MENUITEM "將右 CTRL 鍵映射為左 ALT 鍵(&R)", IDM_ACTION_RCTRL_IS_LALT + MENUITEM "鍵盤需要捕捉(&K)", IDM_ACTION_KBD_REQ_CAPTURE + MENUITEM "將右 CTRL 鍵映射為左 ALT 鍵(&R)", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR - MENUITEM "硬重設(&H)...", IDM_ACTION_HRESET - MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD + MENUITEM "硬重設(&H)...", IDM_ACTION_HRESET + MENUITEM "Ctrl+Alt+Del(&C)\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+Esc(&E)", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR - MENUITEM "暫停(&P)", IDM_ACTION_PAUSE + MENUITEM "暫停(&P)", IDM_ACTION_PAUSE MENUITEM SEPARATOR - MENUITEM "退出(&X)...", IDM_ACTION_EXIT + MENUITEM "退出(&X)...", IDM_ACTION_EXIT END POPUP "檢視(&V)" BEGIN - MENUITEM "隱藏狀態列(&H)", IDM_VID_HIDE_STATUS_BAR - MENUITEM "隱藏工具列(&T)", IDM_VID_HIDE_TOOLBAR + MENUITEM "隱藏狀態列(&H)", IDM_VID_HIDE_STATUS_BAR + MENUITEM "隱藏工具列(&T)", IDM_VID_HIDE_TOOLBAR MENUITEM SEPARATOR - MENUITEM "Show non-primary monitors(&S)", IDM_VID_MONITORS - MENUITEM "視窗大小可調(&R)", IDM_VID_RESIZE - MENUITEM "記住視窗大小和位置(&E)", IDM_VID_REMEMBER + MENUITEM "Show non-primary monitors(&S)", IDM_VID_MONITORS + MENUITEM "視窗大小可調(&R)", IDM_VID_RESIZE + MENUITEM "記住視窗大小和位置(&E)", IDM_VID_REMEMBER MENUITEM SEPARATOR POPUP "渲染器(&N)" BEGIN - MENUITEM "SDL (軟體)(&S)", IDM_VID_SDL_SW - MENUITEM "SDL (硬體)(&H)", IDM_VID_SDL_HW - MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL - MENUITEM "OpenGL (3.0 核心)(&G)", IDM_VID_OPENGL_CORE + MENUITEM "SDL (軟體)(&S)", IDM_VID_SDL_SW + MENUITEM "SDL (硬體)(&H)", IDM_VID_SDL_HW + MENUITEM "SDL (OpenGL)(&O)", IDM_VID_SDL_OPENGL + MENUITEM "OpenGL (3.0 核心)(&G)", IDM_VID_OPENGL_CORE #ifdef USE_VNC - MENUITEM "VNC(&V)", IDM_VID_VNC + MENUITEM "VNC(&V)", IDM_VID_VNC #endif END MENUITEM SEPARATOR - MENUITEM "指定視窗大小...", IDM_VID_SPECIFY_DIM - MENUITEM "強制 4:3 顯示比例(&O)", IDM_VID_FORCE43 + MENUITEM "指定視窗大小...", IDM_VID_SPECIFY_DIM + MENUITEM "強制 4:3 顯示比例(&O)", IDM_VID_FORCE43 POPUP "視窗縮放係數(&W)" BEGIN - MENUITEM "0.5x(&0)", IDM_VID_SCALE_1X - MENUITEM "1x(&1)", IDM_VID_SCALE_2X - MENUITEM "1.5x(&5)", IDM_VID_SCALE_3X - MENUITEM "2x(&2)", IDM_VID_SCALE_4X - MENUITEM "&3x", IDM_VID_SCALE_5X - MENUITEM "&4x", IDM_VID_SCALE_6X - MENUITEM "&5x", IDM_VID_SCALE_7X - MENUITEM "&6x", IDM_VID_SCALE_8X - MENUITEM "&7x", IDM_VID_SCALE_9X - MENUITEM "&8x", IDM_VID_SCALE_10X + MENUITEM "0.5x(&0)", IDM_VID_SCALE_1X + MENUITEM "1x(&1)", IDM_VID_SCALE_2X + MENUITEM "1.5x(&5)", IDM_VID_SCALE_3X + MENUITEM "2x(&2)", IDM_VID_SCALE_4X + MENUITEM "&3x", IDM_VID_SCALE_5X + MENUITEM "&4x", IDM_VID_SCALE_6X + MENUITEM "&5x", IDM_VID_SCALE_7X + MENUITEM "&6x", IDM_VID_SCALE_8X + MENUITEM "&7x", IDM_VID_SCALE_9X + MENUITEM "&8x", IDM_VID_SCALE_10X END POPUP "過濾方式" BEGIN - MENUITEM "鄰近(&N)", IDM_VID_FILTER_NEAREST - MENUITEM "線性(&L)", IDM_VID_FILTER_LINEAR + MENUITEM "鄰近(&N)", IDM_VID_FILTER_NEAREST + MENUITEM "線性(&L)", IDM_VID_FILTER_LINEAR END - MENUITEM "HiDPI 縮放(&D)", IDM_VID_HIDPI + MENUITEM "HiDPI 縮放(&D)", IDM_VID_HIDPI MENUITEM SEPARATOR - MENUITEM "全螢幕(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN + MENUITEM "全螢幕(&F)\tCtrl+Alt+PgUp", IDM_VID_FULLSCREEN POPUP "全螢幕拉伸模式(&S)" BEGIN - MENUITEM "全螢幕拉伸(&F)", IDM_VID_FS_FULL - MENUITEM "4:3(&4)", IDM_VID_FS_43 + MENUITEM "全螢幕拉伸(&F)", IDM_VID_FS_FULL + MENUITEM "4:3(&4)", IDM_VID_FS_43 MENUITEM "保持比例(&S)", IDM_VID_FS_KEEPRATIO - MENUITEM "整數比例(&I)", IDM_VID_FS_INT + MENUITEM "整數比例(&I)", IDM_VID_FS_INT END POPUP "EGA/(S)VGA 設定(&G)" BEGIN - MENUITEM "VGA 顯示器反色顯示(&I)", IDM_VID_INVERT + MENUITEM "VGA 顯示器反色顯示(&I)", IDM_VID_INVERT POPUP "VGA 螢幕類型(&T)" BEGIN - MENUITEM "RGB 彩色(&C)", IDM_VID_GRAY_RGB - MENUITEM "RGB 灰度(&R)", IDM_VID_GRAY_MONO - MENUITEM "琥珀色單色顯示器(&A)", IDM_VID_GRAY_AMBER - MENUITEM "綠色單色顯示器(&G)", IDM_VID_GRAY_GREEN - MENUITEM "白色單色顯示器(&W)", IDM_VID_GRAY_WHITE + MENUITEM "RGB 彩色(&C)", IDM_VID_GRAY_RGB + MENUITEM "RGB 灰度(&R)", IDM_VID_GRAY_MONO + MENUITEM "琥珀色單色顯示器(&A)", IDM_VID_GRAY_AMBER + MENUITEM "綠色單色顯示器(&G)", IDM_VID_GRAY_GREEN + MENUITEM "白色單色顯示器(&W)", IDM_VID_GRAY_WHITE END POPUP "灰度轉換類型(&C)" BEGIN - MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 - MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 - MENUITEM "平均(&A)", IDM_VID_GRAYCT_AVE + MENUITEM "BT601 (NTSC/PAL)(&6)", IDM_VID_GRAYCT_601 + MENUITEM "BT709 (HDTV)(&7)", IDM_VID_GRAYCT_709 + MENUITEM "平均(&A)", IDM_VID_GRAYCT_AVE END END MENUITEM SEPARATOR - MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGA 過掃描(&G)", IDM_VID_OVERSCAN + MENUITEM "CGA/PCjr/Tandy/EGA/(S)VGA 過掃描(&G)", IDM_VID_OVERSCAN MENUITEM "變更單色顯示對比度(&M)", IDM_VID_CGACON END - MENUITEM "介質(&M)", IDM_MEDIA + MENUITEM "介質(&M)", IDM_MEDIA POPUP "工具(&T)" BEGIN - MENUITEM "設定(&S)...", IDM_CONFIG - MENUITEM "更新狀態列圖示(&U)", IDM_UPDATE_ICONS + MENUITEM "設定(&S)...", IDM_CONFIG + MENUITEM "更新狀態列圖示(&U)", IDM_UPDATE_ICONS MENUITEM SEPARATOR - MENUITEM "擷圖(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT + MENUITEM "擷圖(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "首選項(&P)...", IDM_PREFERENCES + MENUITEM "偏好設定(&P)...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "啟用 Discord 整合(&D)", IDM_DISCORD #endif MENUITEM SEPARATOR - MENUITEM "音量增益(&G)...", IDM_SND_GAIN + MENUITEM "音量增益(&G)...", IDM_SND_GAIN #ifdef MTR_ENABLED MENUITEM SEPARATOR - MENUITEM "開始追踪\tCtrl+T", IDM_ACTION_BEGIN_TRACE - MENUITEM "結束追踪\tCtrl+T", IDM_ACTION_END_TRACE + MENUITEM "開始追踪\tCtrl+T", IDM_ACTION_BEGIN_TRACE + MENUITEM "結束追踪\tCtrl+T", IDM_ACTION_END_TRACE #endif END POPUP "說明(&H)" BEGIN - MENUITEM "文件(&D)...", IDM_DOCS - MENUITEM "關於 86Box(&A)...", IDM_ABOUT + MENUITEM "文件(&D)...", IDM_DOCS + MENUITEM "關於 86Box(&A)...", IDM_ABOUT END END -StatusBarMenu MENU DISCARDABLE +StatusBarMenu MENU DISCARDABLE BEGIN MENUITEM SEPARATOR END @@ -137,17 +137,17 @@ CassetteSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新增鏡像(&N)...", IDM_CASSETTE_IMAGE_NEW + MENUITEM "新增映像(&N)...", IDM_CASSETTE_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "開啟已存在的鏡像(&E)...", IDM_CASSETTE_IMAGE_EXISTING - MENUITEM "開啟已存在的鏡像並寫保護(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP + MENUITEM "開啟已存在的映像(&E)...", IDM_CASSETTE_IMAGE_EXISTING + MENUITEM "開啟已存在的映像並寫保護(&W)...", IDM_CASSETTE_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "錄製(&R)", IDM_CASSETTE_RECORD - MENUITEM "播放(&P)", IDM_CASSETTE_PLAY - MENUITEM "倒帶至起點(&R)", IDM_CASSETTE_REWIND - MENUITEM "快進至終點(&F)", IDM_CASSETTE_FAST_FORWARD + MENUITEM "錄製(&R)", IDM_CASSETTE_RECORD + MENUITEM "播放(&P)", IDM_CASSETTE_PLAY + MENUITEM "倒帶至起點(&R)", IDM_CASSETTE_REWIND + MENUITEM "快進至終點(&F)", IDM_CASSETTE_FAST_FORWARD MENUITEM SEPARATOR - MENUITEM "彈出(&J)", IDM_CASSETTE_EJECT + MENUITEM "退出(&J)", IDM_CASSETTE_EJECT END END @@ -155,9 +155,9 @@ CartridgeSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "鏡像(&I)...", IDM_CARTRIDGE_IMAGE + MENUITEM "映像(&I)...", IDM_CARTRIDGE_IMAGE MENUITEM SEPARATOR - MENUITEM "彈出(&J)", IDM_CARTRIDGE_EJECT + MENUITEM "退出(&J)", IDM_CARTRIDGE_EJECT END END @@ -165,14 +165,14 @@ FloppySubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新增鏡像(&N)...", IDM_FLOPPY_IMAGE_NEW + MENUITEM "新增映像(&N)...", IDM_FLOPPY_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "開啟已存在的鏡像(&E)...", IDM_FLOPPY_IMAGE_EXISTING - MENUITEM "開啟已存在的鏡像並寫保護(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP + MENUITEM "開啟已存在的映像(&E)...", IDM_FLOPPY_IMAGE_EXISTING + MENUITEM "開啟已存在的映像並寫保護(&W)...", IDM_FLOPPY_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "匯出為 86F 格式(&x)...", IDM_FLOPPY_EXPORT_TO_86F + MENUITEM "匯出為 86F 格式(&x)...", IDM_FLOPPY_EXPORT_TO_86F MENUITEM SEPARATOR - MENUITEM "彈出(&J)", IDM_FLOPPY_EJECT + MENUITEM "退出(&J)", IDM_FLOPPY_EJECT END END @@ -180,13 +180,13 @@ CdromSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "靜音(&M)", IDM_CDROM_MUTE + MENUITEM "靜音(&M)", IDM_CDROM_MUTE MENUITEM SEPARATOR - MENUITEM "空置光碟機(&M)", IDM_CDROM_EMPTY - MENUITEM "載入上一個鏡像(&R)", IDM_CDROM_RELOAD + MENUITEM "空置光碟機(&M)", IDM_CDROM_EMPTY + MENUITEM "載入上一個映像(&R)", IDM_CDROM_RELOAD MENUITEM SEPARATOR - MENUITEM "鏡像(&I)...", IDM_CDROM_IMAGE - MENUITEM "資料夾(&F)...", IDM_CDROM_DIR + MENUITEM "映像(&I)...", IDM_CDROM_IMAGE + MENUITEM "資料夾(&F)...", IDM_CDROM_DIR END END @@ -194,13 +194,13 @@ ZIPSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新增鏡像(&N)...", IDM_ZIP_IMAGE_NEW + MENUITEM "新增映像(&N)...", IDM_ZIP_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "開啟已存在的鏡像(&E)...", IDM_ZIP_IMAGE_EXISTING - MENUITEM "開啟已存在的鏡像並寫保護(&W)...", IDM_ZIP_IMAGE_EXISTING_WP + MENUITEM "開啟已存在的映像(&E)...", IDM_ZIP_IMAGE_EXISTING + MENUITEM "開啟已存在的映像並寫保護(&W)...", IDM_ZIP_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "彈出(&J)", IDM_ZIP_EJECT - MENUITEM "載入上一個鏡像(&R)", IDM_ZIP_RELOAD + MENUITEM "退出(&J)", IDM_ZIP_EJECT + MENUITEM "載入上一個映像(&R)", IDM_ZIP_RELOAD END END @@ -208,13 +208,13 @@ MOSubmenu MENU DISCARDABLE BEGIN POPUP "" BEGIN - MENUITEM "新增鏡像(&N)...", IDM_MO_IMAGE_NEW + MENUITEM "新增映像(&N)...", IDM_MO_IMAGE_NEW MENUITEM SEPARATOR - MENUITEM "開啟已存在的鏡像(&E)...", IDM_MO_IMAGE_EXISTING - MENUITEM "開啟已存在的鏡像並寫保護(&W)...", IDM_MO_IMAGE_EXISTING_WP + MENUITEM "開啟已存在的映像(&E)...", IDM_MO_IMAGE_EXISTING + MENUITEM "開啟已存在的映像並寫保護(&W)...", IDM_MO_IMAGE_EXISTING_WP MENUITEM SEPARATOR - MENUITEM "鏡像(&J)", IDM_MO_EJECT - MENUITEM "載入上一個鏡像(&R)", IDM_MO_RELOAD + MENUITEM "退出(&J)", IDM_MO_EJECT + MENUITEM "載入上一個映像(&R)", IDM_MO_RELOAD END END @@ -230,7 +230,7 @@ BEGIN MENUITEM "75 fps(&7)", IDM_VID_GL_FPS_75 END MENUITEM "垂直同步(&V)", IDM_VID_GL_VSYNC - MENUITEM "選擇著色器(&S)...", IDM_VID_GL_SHADER + MENUITEM "選取著色器(&S)...", IDM_VID_GL_SHADER MENUITEM "移除著色器(&R)", IDM_VID_GL_NOSHADER END @@ -240,147 +240,147 @@ END // Dialog // -#define STR_PREFERENCES "首選項" -#define STR_SND_GAIN "音量增益" -#define STR_NEW_FLOPPY "新增鏡像" +#define STR_PREFERENCES "偏好設定" +#define STR_SND_GAIN "音量增益" +#define STR_NEW_FLOPPY "新增映像" #define STR_CONFIG "設定" -#define STR_SPECIFY_DIM "指定主視窗大小" +#define STR_SPECIFY_DIM "指定主視窗大小" #define STR_OK "確定" #define STR_CANCEL "取消" #define STR_GLOBAL "將以上設定存儲為全局預設值(&G)" -#define STR_DEFAULT "預設(&D)" -#define STR_LANGUAGE "語言:" -#define STR_ICONSET "圖示集:" +#define STR_DEFAULT "預設(&D)" +#define STR_LANGUAGE "語言:" +#define STR_ICONSET "圖示集:" -#define STR_GAIN "增益" +#define STR_GAIN "增益" -#define STR_FILE_NAME "檔案名:" -#define STR_DISK_SIZE "磁碟大小:" -#define STR_RPM_MODE "轉速 (RPM) 模式:" -#define STR_PROGRESS "進度:" +#define STR_FILE_NAME "檔案名:" +#define STR_DISK_SIZE "磁碟大小:" +#define STR_RPM_MODE "轉速 (RPM) 模式:" +#define STR_PROGRESS "進度:" -#define STR_WIDTH "寬度:" +#define STR_WIDTH "寬度:" #define STR_HEIGHT "高度:" -#define STR_LOCK_TO_SIZE "鎖定此大小" +#define STR_LOCK_TO_SIZE "鎖定此大小" -#define STR_MACHINE_TYPE "機器類型:" -#define STR_MACHINE "機型:" -#define STR_CONFIGURE "配置" -#define STR_CPU_TYPE "CPU 類型:" -#define STR_CPU_SPEED "速度:" -#define STR_FPU "浮點處理器 (FPU):" -#define STR_WAIT_STATES "等待狀態 (WS):" +#define STR_MACHINE_TYPE "機器類型:" +#define STR_MACHINE "機型:" +#define STR_CONFIGURE "設定" +#define STR_CPU_TYPE "CPU 類型:" +#define STR_CPU_SPEED "速度:" +#define STR_FPU "浮點處理器 (FPU):" +#define STR_WAIT_STATES "等待狀態 (WS):" #define STR_MB "MB" #define STR_MEMORY "記憶體:" -#define STR_TIME_SYNC "時間同步" -#define STR_DISABLED "禁用" -#define STR_ENABLED_LOCAL "啟用 (本地時間)" -#define STR_ENABLED_UTC "啟用 (UTC)" -#define STR_DYNAREC "動態重編譯器" +#define STR_TIME_SYNC "時間同步" +#define STR_DISABLED "禁用" +#define STR_ENABLED_LOCAL "啟用 (本地時間)" +#define STR_ENABLED_UTC "啟用 (UTC)" +#define STR_DYNAREC "動態重編譯器" +#define STR_SOFTFLOAT "Softfloat FPU" -#define STR_VIDEO "顯示卡:" -#define STR_VIDEO_2 "顯示卡 2:" +#define STR_VIDEO "顯示卡:" +#define STR_VIDEO_2 "顯示卡 2:" #define STR_VOODOO "Voodoo Graphics" -#define STR_IBM8514 "IBM 8514/a Graphics" -#define STR_XGA "XGA Graphics" +#define STR_IBM8514 "IBM 8514/a Graphics" +#define STR_XGA "XGA Graphics" -#define STR_MOUSE "滑鼠:" -#define STR_JOYSTICK "搖桿:" -#define STR_JOY1 "搖桿 1..." -#define STR_JOY2 "搖桿 2..." -#define STR_JOY3 "搖桿 3..." -#define STR_JOY4 "搖桿 4..." +#define STR_MOUSE "滑鼠:" +#define STR_JOYSTICK "搖桿:" +#define STR_JOY1 "搖桿 1..." +#define STR_JOY2 "搖桿 2..." +#define STR_JOY3 "搖桿 3..." +#define STR_JOY4 "搖桿 4..." -#define STR_SOUND1 "音訊卡 1:" -#define STR_SOUND2 "音訊卡 2:" -#define STR_SOUND3 "音訊卡 3:" -#define STR_SOUND4 "音訊卡 4:" -#define STR_MIDI_OUT "MIDI 輸出裝置:" -#define STR_MIDI_IN "MIDI 輸入裝置:" +#define STR_SOUND1 "音效卡 1:" +#define STR_SOUND2 "音效卡 2:" +#define STR_SOUND3 "音效卡 3:" +#define STR_SOUND4 "音效卡 4:" +#define STR_MIDI_OUT "MIDI 輸出裝置:" +#define STR_MIDI_IN "MIDI 輸入裝置:" #define STR_MPU401 "獨立 MPU-401" -#define STR_FLOAT "使用單精度浮點 (FLOAT32)" -#define STR_FM_DRIVER "調頻合成器驅動器" -#define STR_FM_DRV_NUKED "Nuked (更準確)" -#define STR_FM_DRV_YMFM "YMFM (更快)" +#define STR_FLOAT "使用單精度浮點 (FLOAT32)" +#define STR_FM_DRIVER "調頻合成器驅動器" +#define STR_FM_DRV_NUKED "Nuked (更準確)" +#define STR_FM_DRV_YMFM "YMFM (更快)" -#define STR_NET_TYPE "網路類型:" -#define STR_PCAP "PCap 裝置:" -#define STR_NET "網路配接器:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET_TYPE "網路類型:" +#define STR_PCAP "PCap 裝置:" +#define STR_NET "網路配接器:" +#define STR_NET1 "網路卡 1:" +#define STR_NET2 "網路卡 2:" +#define STR_NET3 "網路卡 3:" +#define STR_NET4 "網路卡 4:" -#define STR_COM1 "COM1 裝置:" -#define STR_COM2 "COM2 裝置:" -#define STR_COM3 "COM3 裝置:" -#define STR_COM4 "COM4 裝置:" -#define STR_LPT1 "LPT1 裝置:" -#define STR_LPT2 "LPT2 裝置:" -#define STR_LPT3 "LPT3 裝置:" -#define STR_LPT4 "LPT4 裝置:" -#define STR_SERIAL1 "序列埠 1" -#define STR_SERIAL2 "序列埠 2" -#define STR_SERIAL3 "序列埠 3" -#define STR_SERIAL4 "序列埠 4" -#define STR_PARALLEL1 "並列埠 1" -#define STR_PARALLEL2 "並列埠 2" -#define STR_PARALLEL3 "並列埠 3" -#define STR_PARALLEL4 "並列埠 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_COM1 "COM1 裝置:" +#define STR_COM2 "COM2 裝置:" +#define STR_COM3 "COM3 裝置:" +#define STR_COM4 "COM4 裝置:" +#define STR_LPT1 "LPT1 裝置:" +#define STR_LPT2 "LPT2 裝置:" +#define STR_LPT3 "LPT3 裝置:" +#define STR_LPT4 "LPT4 裝置:" +#define STR_SERIAL1 "序列埠 1" +#define STR_SERIAL2 "序列埠 2" +#define STR_SERIAL3 "序列埠 3" +#define STR_SERIAL4 "序列埠 4" +#define STR_PARALLEL1 "並列埠 1" +#define STR_PARALLEL2 "並列埠 2" +#define STR_PARALLEL3 "並列埠 3" +#define STR_PARALLEL4 "並列埠 4" +#define STR_SERIAL_PASS1 "序列埠直通 1" +#define STR_SERIAL_PASS2 "序列埠直通 2" +#define STR_SERIAL_PASS3 "序列埠直通 3" +#define STR_SERIAL_PASS4 "序列埠直通 4" -#define STR_HDC "硬碟控制器:" -#define STR_FDC "軟碟控制器:" -#define STR_IDE_TER "第三 IDE 控制器" -#define STR_IDE_QUA "第四 IDE 控制器" -#define STR_SCSI "SCSI" +#define STR_HDC "硬碟控制器:" +#define STR_FDC "軟碟控制器:" +#define STR_IDE_TER "第三 IDE 控制器" +#define STR_IDE_QUA "第四 IDE 控制器" +#define STR_SCSI "SCSI" #define STR_SCSI_1 "控制器 1:" #define STR_SCSI_2 "控制器 2:" #define STR_SCSI_3 "控制器 3:" #define STR_SCSI_4 "控制器 4:" -#define STR_CASSETTE "磁帶" +#define STR_CASSETTE "磁帶" -#define STR_HDD "硬碟:" -#define STR_NEW "新增(&N)..." -#define STR_EXISTING "已有鏡像(&E)..." +#define STR_HDD "硬碟:" +#define STR_NEW "新增(&N)..." +#define STR_EXISTING "已有映像(&E)..." #define STR_REMOVE "移除(&R)" -#define STR_BUS "匯流排:" -#define STR_CHANNEL "通道:" +#define STR_BUS "匯流排:" +#define STR_CHANNEL "通道:" #define STR_ID "ID:" -#define STR_SPEED "Speed:" +#define STR_SPEED "Speed:" -#define STR_SPECIFY "指定(&S)..." -#define STR_SECTORS "磁區(S):" -#define STR_HEADS "磁頭(H):" -#define STR_CYLS "柱面(C):" -#define STR_SIZE_MB "大小 (MB):" -#define STR_TYPE "類型:" -#define STR_IMG_FORMAT "鏡像格式:" -#define STR_BLOCK_SIZE "塊大小:" +#define STR_SPECIFY "指定(&S)..." +#define STR_SECTORS "磁區(S):" +#define STR_HEADS "磁頭(H):" +#define STR_CYLS "磁柱(C):" +#define STR_SIZE_MB "大小 (MB):" +#define STR_TYPE "類型:" +#define STR_IMG_FORMAT "映像格式:" +#define STR_BLOCK_SIZE "區塊大小:" -#define STR_FLOPPY_DRIVES "軟碟機:" -#define STR_TURBO "加速時序" -#define STR_CHECKBPB "檢查 BPB" -#define STR_CDROM_DRIVES "光碟機:" -#define STR_CD_SPEED "速度:" -#define STR_EARLY "早先的光碟機" +#define STR_FLOPPY_DRIVES "軟碟機:" +#define STR_TURBO "加速時序" +#define STR_CHECKBPB "檢查 BPB" +#define STR_CDROM_DRIVES "光碟機:" +#define STR_CD_SPEED "速度:" -#define STR_MO_DRIVES "磁光碟機:" -#define STR_ZIP_DRIVES "ZIP 磁碟機:" -#define STR_250 "ZIP 250" +#define STR_MO_DRIVES "磁光碟機:" +#define STR_ZIP_DRIVES "ZIP 磁碟機:" +#define STR_250 "ZIP 250" #define STR_ISARTC "ISA 實時時鐘:" #define STR_ISAMEM "ISA 記憶體擴充" -#define STR_ISAMEM_1 "擴充卡 1:" -#define STR_ISAMEM_2 "擴充卡 2:" -#define STR_ISAMEM_3 "擴充卡 3:" -#define STR_ISAMEM_4 "擴充卡 4:" +#define STR_ISAMEM_1 "擴充卡 1:" +#define STR_ISAMEM_2 "擴充卡 2:" +#define STR_ISAMEM_3 "擴充卡 3:" +#define STR_ISAMEM_4 "擴充卡 4:" #define STR_BUGGER "ISABugger 裝置" -#define STR_POSTCARD "自檢 (POST) 卡" +#define STR_POSTCARD "自檢 (POST) 卡" #define FONT_SIZE 9 #define FONT_NAME "Microsoft JhengHei" @@ -392,27 +392,27 @@ END // String Table // -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - 2048 "86Box" + 2048 "86Box" IDS_2049 "錯誤" IDS_2050 "致命錯誤" IDS_2051 " - 已暫停" IDS_2052 "按下 Ctrl+Alt+PgDn 返回到視窗模式。" IDS_2053 "速度" IDS_2054 "ZIP %03i %i (%s): %ls" - IDS_2055 "ZIP 鏡像 (*.IM?;*.ZDI)\0*.IM?;*.ZDI\0" - IDS_2056 "86Box 找不到任何可用的 ROM 鏡像。\n\n請下載ROM 包並將其解壓到 ""roms"" 資料夾。" + IDS_2055 "ZIP 映像 (*.IM?;*.ZDI)\0*.IM?;*.ZDI\0" + IDS_2056 "86Box 找不到任何可用的 ROM 映像。\n\n請下載 ROM 套件並將其解壓到 ""roms"" 資料夾。" IDS_2057 "(空)" - IDS_2058 "ZIP 鏡像 (*.IM?;*.ZDI)\0*.IM?;*.ZDI\0所有檔案 (*.*)\0*.*\0" + IDS_2058 "ZIP 映像 (*.IM?;*.ZDI)\0*.IM?;*.ZDI\0所有檔案 (*.*)\0*.*\0" IDS_2059 "加速" IDS_2060 "開" IDS_2061 "關" - IDS_2062 "所有鏡像 (*.86F;*.DSK;*.FLP;*.IM?;*.*FD?)\0*.86F;*.DSK;*.FLP;*.IM?;*.*FD?\0基本磁區鏡像 (*.DSK;*.FLP;*.IM?;*.*FD?)\0*.DSK;*.FLP;*.IM?;*.IMG;*.*FD?\0表面鏡像 (*.86F)\0*.86F\0" + IDS_2062 "所有映像 (*.86F;*.DSK;*.FLP;*.IM?;*.*FD?)\0*.86F;*.DSK;*.FLP;*.IM?;*.*FD?\0基本磁區映像 (*.DSK;*.FLP;*.IM?;*.*FD?)\0*.DSK;*.FLP;*.IM?;*.IMG;*.*FD?\0表面映像 (*.86F)\0*.86F\0" IDS_2063 "由於 roms/machines 資料夾中缺少合適的 ROM,機型 ""%hs"" 不可用。將切換到其他可用機型。" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_2064 "由於 roms/video 資料夾中缺少合適的 ROM,顯示卡 ""%hs"" 不可用。將切換到其他可用顯示卡。" IDS_2065 "機型" @@ -426,15 +426,14 @@ BEGIN IDS_2073 "軟碟/光碟機" IDS_2074 "其他可移除裝置" IDS_2075 "其他周邊裝置" - IDS_2076 "表面鏡像 (*.86F)\0*.86F\0" + IDS_2076 "表面映像 (*.86F)\0*.86F\0" IDS_2077 "點擊視窗捕捉滑鼠" IDS_2078 "按下 F8+F12 釋放滑鼠" IDS_2079 "按下 F8+F12 或滑鼠中鍵釋放滑鼠" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "無法初始化 FluidSynth" IDS_2081 "匯流排" IDS_2082 "檔案" IDS_2083 "C" @@ -464,21 +463,20 @@ BEGIN IDS_2107 "%u" IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "軟碟 %i (%s): %ls" - IDS_2110 "所有鏡像 (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0進階磁區鏡像 (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0基本磁區鏡像 (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux 鏡像 (*.FDI)\0*.FDI\0表面鏡像 (*.86F;*.MFM)\0*.86F;*.MFM\0所有檔案 (*.*)\0*.*\0" - IDS_2111 "無法初始化 FreeType" + IDS_2110 "所有映像 (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0進階磁區映像 (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0基本磁區映像 (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux 映像 (*.FDI)\0*.FDI\0表面映像 (*.86F;*.MFM)\0*.86F;*.MFM\0所有檔案 (*.*)\0*.*\0" IDS_2112 "無法初始化 SDL,需要 SDL2.dll" IDS_2113 "確定要硬重設模擬器嗎?" IDS_2114 "確定要退出 86Box 嗎?" IDS_2115 "無法初始化 Ghostscript" IDS_2116 "磁光碟 %i (%ls): %ls" - IDS_2117 "磁光碟鏡像 (*.IM?;*.MDI)\0*.IM?;*.MDI\0所有檔案 (*.*)\0*.*\0" + IDS_2117 "磁光碟映像 (*.IM?;*.MDI)\0*.IM?;*.MDI\0所有檔案 (*.*)\0*.*\0" IDS_2118 "歡迎使用 86Box!" IDS_2119 "內部控制器" IDS_2120 "退出" IDS_2121 "找不到 ROM" - IDS_2122 "要保存設定嗎?" + IDS_2122 "要儲存設定嗎?" IDS_2123 "此操作將硬重設模擬器。" - IDS_2124 "保存" + IDS_2124 "儲存" IDS_2125 "關於 86Box" IDS_2126 "86Box v" EMU_VERSION @@ -491,43 +489,31 @@ BEGIN #define LIB_NAME_PCAP "libpcap" #endif IDS_2130 "請確認 " LIB_NAME_PCAP " 已安裝且使用相容 " LIB_NAME_PCAP " 的網路連線。" - IDS_2131 "無效配置" -#ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/P 印表機模擬需要" LIB_NAME_FREETYPE + IDS_2131 "無效設定" #ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif - IDS_2133 LIB_NAME_GS " 是將 PostScript 檔案轉換為 PDF 所需要的庫。\n\n使用通用 PostScript 印表機列印的文件將被保存為 PostScript (.ps) 檔案。" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynth MIDI 輸出需要" LIB_NAME_FLUIDSYNTH + IDS_2133 LIB_NAME_GS " 是將 PostScript 檔案轉換為 PDF 所需要的庫。\n\n使用通用 PostScript 印表機列印的文件將被儲存為 PostScript (.ps) 檔案。" IDS_2135 "正在進入全螢幕模式" IDS_2136 "不要再顯示此消息" IDS_2137 "不退出" IDS_2138 "重設" IDS_2139 "不重設" - IDS_2140 "磁光碟鏡像 (*.IM?;*.MDI)\0*.IM?;*.MDI\0所有檔案 (*.*)\0*.*\0" - IDS_2141 "光碟鏡像 (*.ISO;*.CUE)\0*.ISO;*.CUE\0所有檔案 (*.*)\0*.*\0" - IDS_2142 "%hs 裝置配置" + IDS_2140 "磁光碟映像 (*.IM?;*.MDI)\0*.IM?;*.MDI\0所有檔案 (*.*)\0*.*\0" + IDS_2141 "光碟映像 (*.ISO;*.CUE)\0*.ISO;*.CUE\0所有檔案 (*.*)\0*.*\0" + IDS_2142 "%hs 裝置設定" IDS_2143 "顯示器處在睡眠狀態" IDS_2144 "OpenGL 著色器 (*.GLSL)\0*.GLSL\0所有檔案 (*.*)\0*.*\0" IDS_2145 "OpenGL 選項" - IDS_2146 "正在載入一個不受支援的配置" + IDS_2146 "正在載入一個不受支援的設定" IDS_2147 "此模擬電腦禁用了基於選定電腦的 CPU 類型過濾。\n\n能夠選中與所選機器本不相容的 CPU,但是可能會遇到與機器 BIOS 或其他軟體不相容的問題。\n\n啟用此設定不受官方支援,並且提交的任何錯誤報告可能會視為無效而關閉。" IDS_2148 "繼續" IDS_2149 "磁帶: %s" - IDS_2150 "磁帶鏡像 (*.PCM;*.RAW;*.WAV;*.CAS)\0*.PCM;*.RAW;*.WAV;*.CAS\0所有檔案 (*.*)\0*.*\0" + IDS_2150 "磁帶映像 (*.PCM;*.RAW;*.WAV;*.CAS)\0*.PCM;*.RAW;*.WAV;*.CAS\0所有檔案 (*.*)\0*.*\0" IDS_2151 "卡帶 %i: %ls" - IDS_2152 "卡帶鏡像 (*.A;*.B;*.JRC)\0*.A;*.B;*.JRC\0所有檔案 (*.*)\0*.*\0" + IDS_2152 "卡帶映像 (*.A;*.B;*.JRC)\0*.A;*.B;*.JRC\0所有檔案 (*.*)\0*.*\0" IDS_2153 "初始化渲染器時出錯" IDS_2154 "無法初始化 OpenGL (3.0 核心) 渲染器。請使用其他渲染器。" IDS_2155 "恢復執行" @@ -537,14 +523,16 @@ BEGIN IDS_2159 "硬重設" IDS_2160 "ACPI 關機" IDS_2161 "設定" - IDS_2162 "早先的光碟機" + IDS_2162 "Type" IDS_2163 "No Dynarec" IDS_2164 "Old Dynarec" IDS_2165 "New Dynarec" IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." + IDS_2167 "Failed to initialize network driver" + IDS_2168 "The network configuration will be switched to the null driver" END -STRINGTABLE DISCARDABLE +STRINGTABLE DISCARDABLE BEGIN IDS_4096 "硬碟 (%s)" IDS_4097 "%01i:%01i" @@ -552,37 +540,37 @@ BEGIN IDS_4099 "不存在 MFM/RLL 或 ESDI CD-ROM 光碟機" IDS_4100 "自訂..." IDS_4101 "自訂 (大容量)..." - IDS_4102 "添加新硬碟" - IDS_4103 "添加已存在的硬碟" - IDS_4104 "HDI 磁碟鏡像不能超過 4 GB。" - IDS_4105 "磁碟鏡像不能超過 127 GB。" - IDS_4106 "硬碟鏡像 (*.HD?;*.IM?;*.VHD)\0*.HD?;*.IM?;*.VHD\0所有檔案 (*.*)\0*.*\0" + IDS_4102 "增加新硬碟" + IDS_4103 "增加已存在的硬碟" + IDS_4104 "HDI 磁碟映像不能超過 4 GB。" + IDS_4105 "磁碟映像不能超過 127 GB。" + IDS_4106 "硬碟映像 (*.HD?;*.IM?;*.VHD)\0*.HD?;*.IM?;*.VHD\0所有檔案 (*.*)\0*.*\0" IDS_4107 "無法讀取檔案" IDS_4108 "無法寫入檔案" - IDS_4109 "不支援非 512 位元組磁區大小的 HDI 或 HDX 鏡像。" + IDS_4109 "不支援非 512 位元組磁區大小的 HDI 或 HDX 映像。" IDS_4110 "尚未支援 USB" - IDS_4111 "磁碟鏡像檔案已存在" + IDS_4111 "磁碟映像檔案已存在" IDS_4112 "請指定有效的檔案名。" - IDS_4113 "已創建磁碟鏡像" + IDS_4113 "已創建磁碟映像" IDS_4114 "請確定此檔案已存在並可讀取。" - IDS_4115 "請確定此檔案保存在可寫目錄中。" - IDS_4116 "磁碟鏡像太大" - IDS_4117 "請記得為新創建的鏡像分區並格式化。" + IDS_4115 "請確定此檔案儲存在可寫目錄中。" + IDS_4116 "磁碟映像太大" + IDS_4117 "請記得為新創建的映像分區並格式化。" IDS_4118 "選定的檔案將被覆蓋。確定繼續使用此檔案嗎?" - IDS_4119 "不支援的磁碟鏡像" + IDS_4119 "不支援的磁碟映像" IDS_4120 "覆蓋" IDS_4121 "不覆蓋" - IDS_4122 "原始鏡像 (.img)" - IDS_4123 "HDI 鏡像 (.hdi)" - IDS_4124 "HDX 鏡像 (.hdx)" + IDS_4122 "原始映像 (.img)" + IDS_4123 "HDI 映像 (.hdi)" + IDS_4124 "HDX 映像 (.hdx)" IDS_4125 "固定大小 VHD (.vhd)" IDS_4126 "動態大小 VHD (.vhd)" IDS_4127 "差分 VHD (.vhd)" - IDS_4128 "大塊 (2 MB)" - IDS_4129 "小塊 (512 KB)" + IDS_4128 "大區塊 (2 MB)" + IDS_4129 "小區塊 (512 KB)" IDS_4130 "VHD 檔案 (*.VHD)\0*.VHD\0所有檔案 (*.*)\0*.*\0" - IDS_4131 "選擇父 VHD 檔案" - IDS_4132 "父映像可能在創建差異鏡像後被修改。\n\n如果鏡像檔案被移動或複製,或創建此磁碟的程式中存在錯誤,也可能發生這種情況。\n\n是否需要修復時間戳?" + IDS_4131 "選取父 VHD 檔案" + IDS_4132 "父映像可能在創建差異映像後被修改。\n\n如果映像檔案被移動或複製,或創建此磁碟的程式中存在錯誤,也可能發生這種情況。\n\n是否需要修復時間戳?" IDS_4133 "父碟與子碟的時間戳不匹配" IDS_4134 "無法修復 VHD 時間戳。" IDS_4135 "%01i:%02i" @@ -625,16 +613,16 @@ BEGIN IDS_5899 "2.88 MB" IDS_5900 "ZIP 100" IDS_5901 "ZIP 250" - IDS_5902 "3.5 英寸 128 MB (ISO 10090)" - IDS_5903 "3.5 英寸 230 MB (ISO 13963)" - IDS_5904 "3.5 英寸 540 MB (ISO 15498)" - IDS_5905 "3.5 英寸 640 MB (ISO 15498)" - IDS_5906 "3.5 英寸 1.3 GB (GigaMO)" - IDS_5907 "3.5 英寸 2.3 GB (GigaMO 2)" - IDS_5908 "5.25 英寸 600 MB" - IDS_5909 "5.25 英寸 650 MB" - IDS_5910 "5.25 英寸 1 GB" - IDS_5911 "5.25 英寸 1.3 GB" + IDS_5902 "3.5 英吋 128 MB (ISO 10090)" + IDS_5903 "3.5 英吋 230 MB (ISO 13963)" + IDS_5904 "3.5 英吋 540 MB (ISO 15498)" + IDS_5905 "3.5 英吋 640 MB (ISO 15498)" + IDS_5906 "3.5 英吋 1.3 GB (GigaMO)" + IDS_5907 "3.5 英吋 2.3 GB (GigaMO 2)" + IDS_5908 "5.25 英吋 600 MB" + IDS_5909 "5.25 英吋 650 MB" + IDS_5910 "5.25 英吋 1 GB" + IDS_5911 "5.25 英吋 1.3 GB" IDS_6144 "標準轉速 (RPM)" IDS_6145 "低於標準轉速的 1%" @@ -643,7 +631,7 @@ BEGIN IDS_7168 "(系統預設)" END -#define IDS_LANG_ENUS IDS_7168 +#define IDS_LANG_ENUS IDS_7168 // Traditional Chinese resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win/win.c b/src/win/win.c index 7c06d3710..f166d559d 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -18,6 +18,7 @@ * Copyright 2016-2019 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2021 Laci bá' + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define NTDDI_VERSION 0x06010000 @@ -625,7 +626,7 @@ plat_tempfile(char *bufp, char *prefix, char *suffix) else strcpy(bufp, ""); - GetSystemTime(&SystemTime); + GetLocalTime(&SystemTime); sprintf(&bufp[strlen(bufp)], "%d%02d%02d-%02d%02d%02d-%03d%s", SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, diff --git a/src/win/win_about.c b/src/win/win_about.c index 82b327d2e..7ba55f73e 100644 --- a/src/win/win_about.c +++ b/src/win/win_about.c @@ -15,6 +15,7 @@ * * Copyright 2016-2018 Miran Grca. * Copyright 2017-2018 Fred N. van Kempen. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP diff --git a/src/win/win_cdrom.c b/src/win/win_cdrom.c index bfd62383a..27e4e0a49 100644 --- a/src/win/win_cdrom.c +++ b/src/win/win_cdrom.c @@ -16,6 +16,7 @@ * * Copyright 2016-2018 Miran Grca. * Copyright 2017-2018 Fred N. van Kempen. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP diff --git a/src/win/win_devconf.c b/src/win/win_devconf.c index 6573e8400..0f233cb3a 100644 --- a/src/win/win_devconf.c +++ b/src/win/win_devconf.c @@ -15,6 +15,7 @@ * * Copyright 2008-2018 Sarah Walker. * Copyright 2016-2018 Miran Grca. + * Copyright 2021-2023 Jasmine Iwanek. */ #include #include @@ -47,18 +48,26 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND h; - int val_int, id, c, d; - int p, q; + int val_int; + int id; + int c; + int d; + int p; + int q; #ifdef USE_RTMIDI int num; #endif - int changed, cid; + int changed; + int cid; const device_config_t *config; const device_config_selection_t *selection; const device_config_bios_t *bios; - char s[512], file_filter[512]; - char *str, *val_str; - wchar_t ws[512], *wstr; + char s[512]; + char file_filter[512]; + char *str; + char *val_str; + wchar_t ws[512]; + wchar_t *wstr; LPTSTR lptsTemp; config = config_device.dev->config; diff --git a/src/win/win_dialog.c b/src/win/win_dialog.c index 14f3119b6..b58ef88d0 100644 --- a/src/win/win_dialog.c +++ b/src/win/win_dialog.c @@ -15,6 +15,7 @@ * * Copyright 2016-2019 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #include @@ -56,12 +57,13 @@ ui_msgbox_ex(int flags, void *header, void *message, void *btn1, void *btn2, voi { WCHAR temp[512]; TASKDIALOGCONFIG tdconfig = { 0 }; - TASKDIALOG_BUTTON tdbuttons[3], - tdb_yes = { IDYES, STRING_OR_RESOURCE(btn1) }, - tdb_no = { IDNO, STRING_OR_RESOURCE(btn2) }, - tdb_cancel = { IDCANCEL, STRING_OR_RESOURCE(btn3) }, - tdb_exit = { IDCLOSE, MAKEINTRESOURCE(IDS_2120) }; - int ret = 0, checked = 0; + TASKDIALOG_BUTTON tdbuttons[3]; + TASKDIALOG_BUTTON tdb_yes = { IDYES, STRING_OR_RESOURCE(btn1) }; + TASKDIALOG_BUTTON tdb_no = { IDNO, STRING_OR_RESOURCE(btn2) }; + TASKDIALOG_BUTTON tdb_cancel = { IDCANCEL, STRING_OR_RESOURCE(btn3) }; + TASKDIALOG_BUTTON tdb_exit = { IDCLOSE, MAKEINTRESOURCE(IDS_2120) }; + int ret = 0; + int checked = 0; /* Configure the default OK button. */ tdconfig.cButtons = 0; @@ -150,7 +152,7 @@ ui_msgbox_ex(int flags, void *header, void *message, void *btn1, void *btn2, voi if (checked) ret += 10; - return (ret); + return ret; } int @@ -201,16 +203,17 @@ file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, WCHAR *title, int save) c16stombs(openfilestring, wopenfilestring, sizeof(openfilestring)); filterindex = ofn.nFilterIndex; - return (0); + return 0; } - return (1); + return 1; } int file_dlg(HWND hwnd, WCHAR *f, char *fn, char *title, int save) { - WCHAR ufn[512], title_buf[512]; + WCHAR ufn[512]; + WCHAR title_buf[512]; if (fn) mbstoc16s(ufn, fn, strlen(fn) + 1); @@ -223,7 +226,9 @@ file_dlg(HWND hwnd, WCHAR *f, char *fn, char *title, int save) int file_dlg_mb(HWND hwnd, char *f, char *fn, char *title, int save) { - WCHAR uf[512], ufn[512], title_buf[512]; + WCHAR uf[512]; + WCHAR ufn[512]; + WCHAR title_buf[512]; mbstoc16s(uf, f, strlen(f) + 1); mbstoc16s(ufn, fn, strlen(fn) + 1); diff --git a/src/win/win_dynld.c b/src/win/win_dynld.c index 88fb632bc..24690f2ba 100644 --- a/src/win/win_dynld.c +++ b/src/win/win_dynld.c @@ -13,6 +13,7 @@ * Authors: Fred N. van Kempen, * * Copyright 2017-2018 Fred N. van Kempen + * Copyright 2021-2023 Jasmine Iwanek. */ #include #include @@ -47,7 +48,6 @@ void * dynld_module(const char *name, dllimp_t *table) { HMODULE h; - dllimp_t *imp; void *func; /* See if we can load the desired module. */ @@ -57,7 +57,7 @@ dynld_module(const char *name, dllimp_t *table) } /* Now load the desired function pointers. */ - for (imp = table; imp->name != NULL; imp++) { + for (dllimp_t *imp = table; imp->name != NULL; imp++) { func = GetProcAddress(h, imp->name); if (func == NULL) { dynld_log("DynLd(\"%s\"): function '%s' not found! (%08X)\n", diff --git a/src/win/win_icon.c b/src/win/win_icon.c index 64acc44b0..f3426b8b5 100644 --- a/src/win/win_icon.c +++ b/src/win/win_icon.c @@ -13,6 +13,7 @@ * Authors: Laci bá' * * Copyright 2021 Laci bá'. + * Copyright 2021-2023 Jasmine Iwanek. */ #include @@ -35,9 +36,7 @@ char icon_set[256] = ""; /* name of the iconset to be used */ void win_clear_icon_set(void) { - int i; - - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) if (hIcon[i] != 0) { DestroyIcon(hIcon[i]); hIcon[i] = 0; @@ -47,9 +46,10 @@ win_clear_icon_set(void) void win_system_icon_set(void) { - int i, x = win_get_system_metrics(SM_CXSMICON, dpi), y = win_get_system_metrics(SM_CYSMICON, dpi); + int x = win_get_system_metrics(SM_CXSMICON, dpi); + int y = win_get_system_metrics(SM_CYSMICON, dpi); - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) hIcon[i] = LoadImage(hinstance, MAKEINTRESOURCE(i), IMAGE_ICON, x, y, LR_DEFAULTCOLOR); } @@ -136,16 +136,18 @@ win_load_icon_set(void) return; } - char path_root[2048] = { 0 }, temp[2048] = { 0 }; - wchar_t wtemp[2048] = { 0 }; + char path_root[2048] = { 0 }; + char temp[2048] = { 0 }; + wchar_t wtemp[2048] = { 0 }; win_get_icons_path(path_root); strcat(path_root, icon_set); path_slash(path_root); - int i, count = sizeof(icon_files) / sizeof(_ICON_DATA), - x = win_get_system_metrics(SM_CXSMICON, dpi), y = win_get_system_metrics(SM_CYSMICON, dpi); - for (i = 0; i < count; i++) { + int count = sizeof(icon_files) / sizeof(_ICON_DATA); + int x = win_get_system_metrics(SM_CXSMICON, dpi); + int y = win_get_system_metrics(SM_CYSMICON, dpi); + for (int i = 0; i < count; i++) { path_append_filename(temp, path_root, icon_files[i].filename); mbstoc16s(wtemp, temp, strlen(temp) + 1); diff --git a/src/win/win_joystick.cpp b/src/win/win_joystick.cpp index 42ab8bd69..5658b14d5 100644 --- a/src/win/win_joystick.cpp +++ b/src/win/win_joystick.cpp @@ -15,6 +15,7 @@ * * Copyright 2008-2019 Sarah Walker. * Copyright 2016-2019 Miran Grca. + * Copyright 2021-2023 Jasmine Iwanek. */ #define DIRECTINPUT_VERSION 0x0800 #include @@ -242,7 +243,8 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process(void) { - int c, d; + int c; + int d; if (!joystick_type) return; @@ -288,8 +290,10 @@ joystick_process(void) joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]]; for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - int x, y; - double angle, magnitude; + int x; + int y; + double angle; + double magnitude; x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]); y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]); @@ -316,4 +320,5 @@ joystick_process(void) void win_joystick_handle(PRAWINPUT raw) { + // Nothing to be done here, atleast currently } diff --git a/src/win/win_joystick_rawinput.c b/src/win/win_joystick_rawinput.c index 2976a54b9..6f2a1e4c0 100644 --- a/src/win/win_joystick_rawinput.c +++ b/src/win/win_joystick_rawinput.c @@ -17,6 +17,7 @@ * Copyright 2008-2018 Sarah Walker. * Copyright 2016-2018 Miran Grca. * Copyright 2020 GH Cao. + * Copyright 2021-2023 Jasmine Iwanek. */ #include #include @@ -98,6 +99,8 @@ joystick_add_button(raw_joystick_t *rawjoy, plat_joystick_t *joy, USAGE usage) void joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS prop) { + LONG center; + if (joy->nr_axes >= 8) return; @@ -141,7 +144,10 @@ joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS } rawjoy->axis[joy->nr_axes].min = prop->LogicalMin; - joy->nr_axes++; + center = (rawjoy->axis[joy->nr_axes].max - rawjoy->axis[joy->nr_axes].min + 1) / 2; + + if (center != 0x00) + joy->nr_axes++; } void @@ -443,12 +449,12 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process(void) { - int c, d; + int d; if (joystick_type == 7) return; - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { + for (int c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { if (joystick_state[c].plat_joystick_nr) { int joystick_nr = joystick_state[c].plat_joystick_nr - 1; @@ -458,8 +464,10 @@ joystick_process(void) joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]]; for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - int x, y; - double angle, magnitude; + int x; + int y; + double angle; + double magnitude; x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]); y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]); diff --git a/src/win/win_joystick_xinput.c b/src/win/win_joystick_xinput.c index 2f98e5241..a1c380668 100644 --- a/src/win/win_joystick_xinput.c +++ b/src/win/win_joystick_xinput.c @@ -17,6 +17,7 @@ * Copyright 2008-2018 Sarah Walker. * Copyright 2016-2018 Miran Grca. * Copyright 2019 GH Cao. + * Copyright 2021-2023 Jasmine Iwanek. */ #include #define _USE_MATH_DEFINES @@ -79,15 +80,13 @@ XINPUT_STATE controllers[XINPUT_MAX_JOYSTICKS]; void joystick_init() { - int c; - atexit(joystick_close); joysticks_present = 0; memset(controllers, 0, sizeof(XINPUT_STATE) * XINPUT_MAX_JOYSTICKS); - for (c = 0; c < XINPUT_MAX_JOYSTICKS; c++) { + for (uint8_t c = 0; c < XINPUT_MAX_JOYSTICKS; c++) { int value = XInputGetState(c, &controllers[c]); if (value != ERROR_SUCCESS) continue; @@ -171,7 +170,8 @@ joystick_poll(void) plat_joystick_state[c].b[10] = (controllers[c].Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? 128 : 0; plat_joystick_state[c].b[11] = (controllers[c].Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? 128 : 0; - int dpad_x = 0, dpad_y = 0; + int dpad_x = 0; + int dpad_y = 0; if (controllers[c].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) dpad_y -= 32767; if (controllers[c].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) @@ -217,14 +217,14 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process(void) { - int c, d; + int d; if (!joystick_type) return; joystick_poll(); - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { + for (int c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { if (joystick_state[c].plat_joystick_nr) { int joystick_nr = joystick_state[c].plat_joystick_nr - 1; @@ -234,8 +234,10 @@ joystick_process(void) joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]]; for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - int x, y; - double angle, magnitude; + int x; + int y; + double angle; + double magnitude; x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]); y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]); @@ -262,4 +264,5 @@ joystick_process(void) void win_joystick_handle(PRAWINPUT raw) { + // Nothing to be done here, atleast currently } diff --git a/src/win/win_jsconf.c b/src/win/win_jsconf.c index fe1967082..0e4f581dd 100644 --- a/src/win/win_jsconf.c +++ b/src/win/win_jsconf.c @@ -27,7 +27,8 @@ rebuild_axis_button_selections(HWND hdlg) int id = IDC_CONFIG_BASE + 2; HWND h; int joystick; - int c, d; + int c; + int d; char s[269]; h = GetDlgItem(hdlg, IDC_CONFIG_BASE); diff --git a/src/win/win_keyboard.c b/src/win/win_keyboard.c index 6b7e00b57..72f8561f0 100644 --- a/src/win/win_keyboard.c +++ b/src/win/win_keyboard.c @@ -13,6 +13,7 @@ * Authors: Miran Grca, * * Copyright 2016-2018 Miran Grca. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define _WIN32_WINNT 0x0501 @@ -107,7 +108,9 @@ void keyboard_handle(PRAWINPUT raw) { USHORT scancode; - static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0; + static int recv_lalt = 0; + static int recv_ralt = 0; + static int recv_tab = 0; RAWKEYBOARD rawKB = raw->data.keyboard; scancode = rawKB.MakeCode; @@ -133,7 +136,7 @@ keyboard_handle(PRAWINPUT raw) We use scan code 0xFFFF to mean a mapping that has a prefix other than E0 and that is not E1 1D, which is, for our purposes, invalid. */ - if ((scancode == 0x00F) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && !mouse_capture) { + if ((scancode == 0x00f) && !(rawKB.Flags & RI_KEY_BREAK) && (recv_lalt || recv_ralt) && (!kbd_req_capture || mouse_capture)) { /* We received a TAB while ALT was pressed, while the mouse is not captured, suppress the TAB and send an ALT key up. */ if (recv_lalt) { @@ -152,14 +155,14 @@ keyboard_handle(PRAWINPUT raw) keyboard_input(0, 0x138); recv_ralt = 0; } - } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && !mouse_capture) { + } else if (((scancode == 0x038) || (scancode == 0x138)) && !(rawKB.Flags & RI_KEY_BREAK) && recv_tab && (!kbd_req_capture || mouse_capture)) { /* We received an ALT while TAB was pressed, while the mouse is not captured, suppress the ALT and send a TAB key up. */ - keyboard_input(0, 0x00F); + keyboard_input(0, 0x00f); recv_tab = 0; } else { switch (scancode) { - case 0x00F: + case 0x00f: recv_tab = !(rawKB.Flags & RI_KEY_BREAK); break; case 0x038: @@ -172,7 +175,7 @@ keyboard_handle(PRAWINPUT raw) /* Translate right CTRL to left ALT if the user has so chosen. */ - if ((scancode == 0x11D) && rctrl_is_lalt) + if ((scancode == 0x11d) && rctrl_is_lalt) scancode = 0x038; /* Normal scan code pass through, pass it through as is if diff --git a/src/win/win_media_menu.c b/src/win/win_media_menu.c index 8d8de6f53..9e5603442 100644 --- a/src/win/win_media_menu.c +++ b/src/win/win_media_menu.c @@ -35,7 +35,8 @@ #define ZIP_FIRST CDROM_FIRST + CDROM_NUM #define MO_FIRST ZIP_FIRST + ZIP_NUM -static HMENU media_menu, stbar_menu; +static HMENU media_menu; +static HMENU stbar_menu; static HMENU menus[1 + 2 + FDD_NUM + CDROM_NUM + ZIP_NUM + MO_NUM]; static char index_map[255]; @@ -75,7 +76,8 @@ media_menu_load_resource(wchar_t *lpName) static void media_menu_set_name_cassette(void) { - wchar_t name[512], fn[512]; + wchar_t name[512]; + wchar_t fn[512]; MENUITEMINFO mii = { 0 }; if (strlen(cassette_fname) == 0) @@ -95,7 +97,8 @@ media_menu_set_name_cassette(void) static void media_menu_set_name_cartridge(int drive) { - wchar_t name[512], fn[512]; + wchar_t name[512]; + wchar_t fn[512]; MENUITEMINFO mii = { 0 }; if (strlen(cart_fns[drive]) == 0) { @@ -117,7 +120,9 @@ media_menu_set_name_cartridge(int drive) static void media_menu_set_name_floppy(int drive) { - wchar_t name[512], temp[512], fn[512]; + wchar_t name[512]; + wchar_t temp[512]; + wchar_t fn[512]; MENUITEMINFO mii = { 0 }; mbstoc16s(temp, fdd_getname(fdd_get_type(drive)), @@ -141,7 +146,9 @@ media_menu_set_name_floppy(int drive) static void media_menu_set_name_cdrom(int drive) { - wchar_t name[512], *temp, fn[512]; + wchar_t name[512]; + wchar_t *temp; + wchar_t fn[512]; MENUITEMINFO mii = { 0 }; int bus = cdrom[drive].bus_type; @@ -171,7 +178,9 @@ media_menu_set_name_cdrom(int drive) static void media_menu_set_name_zip(int drive) { - wchar_t name[512], *temp, fn[512]; + wchar_t name[512]; + wchar_t *temp; + wchar_t fn[512]; MENUITEMINFO mii = { 0 }; int bus = zip_drives[drive].bus_type; @@ -200,7 +209,9 @@ media_menu_set_name_zip(int drive) static void media_menu_set_name_mo(int drive) { - wchar_t name[512], *temp, fn[512]; + wchar_t name[512]; + wchar_t *temp; + wchar_t fn[512]; MENUITEMINFO mii = { 0 }; int bus = mo_drives[drive].bus_type; @@ -529,7 +540,13 @@ media_menu_init(void) int media_menu_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - int id = 0, ret = 0, wp = 0; + int id = 0; + int ret = 0; + int wp = 0; + +#ifdef __clang__ + BROWSEINFO bi; +#endif id = LOWORD(wParam) & 0x00ff; @@ -638,10 +655,15 @@ media_menu_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_CDROM_DIR: +#ifndef __clang__ BROWSEINFO bi = { .hwndOwner = hwnd, .ulFlags = BIF_EDITBOX }; +#else + bi.hwndOwner = hwnd; + bi.ulFlags = BIF_EDITBOX; +#endif OleInitialize(NULL); int old_dopause = dopause; plat_pause(1); diff --git a/src/win/win_mouse.c b/src/win/win_mouse.c index 1a914aa9b..3e31f12de 100644 --- a/src/win/win_mouse.c +++ b/src/win/win_mouse.c @@ -17,6 +17,7 @@ * Copyright 2008-2017 Sarah Walker. * Copyright 2016-2017 Miran Grca. * Copyright 2019 GH Cao. + * Copyright 2021-2023 Jasmine Iwanek. */ #include #include @@ -28,8 +29,9 @@ #include <86box/win.h> int mouse_capture; -double mouse_sensitivity = 1.0; /* Unused. */ -double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */ +double mouse_sensitivity = 1.0; /* Unused. */ +double mouse_x_error = 0.0; /* Unused. */ +double mouse_y_error = 0.0; /* Unused. */ typedef struct { int buttons; @@ -63,7 +65,8 @@ void win_mouse_handle(PRAWINPUT raw) { RAWMOUSE state = raw->data.mouse; - static int x, y; + static int x; + static int y; /* read mouse buttons and wheel */ if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index 6e3f765f0..266660826 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -13,6 +13,7 @@ * Authors: Miran Grca, * * Copyright 2016-2019 Miran Grca. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -49,7 +50,8 @@ create_86f(char *file_name, disk_size_t disk_size, uint8_t rpm_mode) uint32_t index_hole_pos = 0; uint32_t tarray[512]; uint32_t array_size; - uint32_t track_base, track_size; + uint32_t track_base; + uint32_t track_size; int i; uint32_t shift = 0; @@ -262,7 +264,6 @@ create_zip_sector_image(char *file_name, disk_size_t disk_size, uint8_t is_zdi, uint32_t zero_bytes = 0; uint16_t base = 0x1000; uint32_t pbar_max = 0; - uint32_t i; MSG msg; f = plat_fopen(file_name, "wb"); @@ -466,7 +467,7 @@ create_zip_sector_image(char *file_name, disk_size_t disk_size, uint8_t is_zdi, Data = 0x38200 */ } - for (i = 0; i < pbar_max; i++) { + for (uint32_t i = 0; i < pbar_max; i++) { fwrite(&empty[i << 11], 1, 2048, f); SendMessage(h, PBM_SETPOS, (WPARAM) i + 2, (LPARAM) 0); @@ -489,13 +490,16 @@ create_mo_sector_image(char *file_name, int8_t disk_size, uint8_t is_mdi, HWND h HWND h; FILE *f; const mo_type_t *dp = &mo_types[disk_size]; - uint8_t *empty, *empty2 = NULL; - uint32_t total_size = 0, total_size2; + uint8_t *empty; + uint8_t *empty2 = NULL; + uint32_t total_size = 0; + uint32_t total_size2; uint32_t total_sectors = 0; uint32_t sector_bytes = 0; uint16_t base = 0x1000; - uint32_t pbar_max = 0, blocks_num; - uint32_t i, j; + uint32_t pbar_max = 0; + uint32_t blocks_num; + uint32_t j; MSG msg; f = plat_fopen(file_name, "wb"); @@ -574,7 +578,7 @@ create_mo_sector_image(char *file_name, int8_t disk_size, uint8_t is_mdi, HWND h memset(empty, 0x00, total_size2); } - for (i = 0; i < blocks_num; i++) { + for (uint32_t i = 0; i < blocks_num; i++) { fwrite(empty, 1, 1048576, f); SendMessage(h, PBM_SETPOS, (WPARAM) i + j, (LPARAM) 0); @@ -605,7 +609,8 @@ create_mo_sector_image(char *file_name, int8_t disk_size, uint8_t is_mdi, HWND h return 1; } -static int fdd_id, sb_part; +static int fdd_id; +static int sb_part; static int file_type = 0; /* 0 = IMG, 1 = Japanese FDI, 2 = 86F */ static char fd_file_name[1024]; @@ -624,7 +629,7 @@ new_floppy_msgbox_header(HWND hwnd, int flags, void *header, void *message) hwndMain = h; - return (i); + return i; } static int @@ -640,7 +645,7 @@ new_floppy_msgbox_ex(HWND hwnd, int flags, void *header, void *message, void *bt hwndMain = h; - return (i); + return i; } #if defined(__amd64__) || defined(__aarch64__) @@ -652,12 +657,16 @@ NewFloppyDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND h; int i = 0; - int wcs_len, ext_offs; + int wcs_len; + int ext_offs; wchar_t *ext; - uint8_t disk_size, rpm_mode; + uint8_t disk_size; + uint8_t rpm_mode; int ret; FILE *f; - int zip_types, mo_types, floppy_types; + int zip_types; + int mo_types; + int floppy_types; wchar_t *twcs; switch (message) { @@ -770,19 +779,19 @@ NewFloppyDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) ext_offs = wcs_len - 4; ext = &(wopenfilestring[ext_offs]); if (is_zip) { - if (((wcs_len >= 4) && !wcsicmp(ext, L".ZDI"))) + if ((wcs_len >= 4) && !wcsicmp(ext, L".ZDI")) file_type = 1; else file_type = 0; } else if (is_mo) { - if (((wcs_len >= 4) && !wcsicmp(ext, L".MDI"))) + if ((wcs_len >= 4) && !wcsicmp(ext, L".MDI")) file_type = 1; else file_type = 0; } else { - if (((wcs_len >= 4) && !wcsicmp(ext, L".FDI"))) + if ((wcs_len >= 4) && !wcsicmp(ext, L".FDI")) file_type = 1; - else if ((((wcs_len >= 4) && !wcsicmp(ext, L".86F")) || (filterindex == 3))) + else if (((wcs_len >= 4) && !wcsicmp(ext, L".86F")) || (filterindex == 3)) file_type = 2; else file_type = 0; @@ -815,7 +824,7 @@ NewFloppyDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) break; } - return (FALSE); + return FALSE; } void diff --git a/src/win/win_opendir.c b/src/win/win_opendir.c index a3537a546..051ed20bb 100644 --- a/src/win/win_opendir.c +++ b/src/win/win_opendir.c @@ -16,6 +16,7 @@ * * Copyright 1998-2007 MicroWalt Corporation * Copyright 2017 Fred N. van Kempen + * Copyright 2021-2023 Jasmine Iwanek. */ #include #include @@ -72,7 +73,7 @@ opendir(const char *name) } /* All OK. */ - return (p); + return p; } /* Close an open directory. */ @@ -80,7 +81,7 @@ int closedir(DIR *p) { if (p == NULL) - return (0); + return 0; _findclose(p->handle); @@ -88,7 +89,7 @@ closedir(DIR *p) free(p->dta); free(p); - return (0); + return 0; } /* diff --git a/src/win/win_opengl.c b/src/win/win_opengl.c index 1de065855..1f866d273 100644 --- a/src/win/win_opengl.c +++ b/src/win/win_opengl.c @@ -494,8 +494,12 @@ opengl_main(void *param) } /* Keep track of certain parameters, only changed in this thread to avoid race conditions */ - int fullscreen = resize_info.fullscreen, video_width = INIT_WIDTH, video_height = INIT_HEIGHT, - output_width = resize_info.width, output_height = resize_info.height, frametime = options.frametime; + int fullscreen = resize_info.fullscreen; + int video_width = INIT_WIDTH; + int video_height = INIT_HEIGHT; + int output_width = resize_info.width; + int output_height = resize_info.height; + int frametime = options.frametime; SDL_SysWMinfo wmi = { 0 }; SDL_VERSION(&wmi.version); @@ -703,7 +707,11 @@ opengl_main(void *param) } if (fullscreen) { - int width, height, pad_x = 0, pad_y = 0, px_size = 1; + int width; + int height; + int pad_x = 0; + int pad_y = 0; + int px_size = 1; float ratio = 0; const float ratio43 = 4.f / 3.f; @@ -821,14 +829,12 @@ opengl_main(void *param) static void opengl_blit(int x, int y, int w, int h, int monitor_index) { - int row; - if ((x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (thread == NULL) || atomic_flag_test_and_set(&blit_info[write_pos].in_use) || monitor_index >= 1) { video_blit_complete_monitor(monitor_index); return; } - for (row = 0; row < h; ++row) + for (int row = 0; row < h; ++row) video_copy(&(((uint8_t *) blit_info[write_pos].buffer)[row * ROW_LENGTH * sizeof(uint32_t)]), &(buffer32->line[y + row][x]), w * sizeof(uint32_t)); if (monitors[0].mon_screenshots) diff --git a/src/win/win_preferences.c b/src/win/win_preferences.c index 17cfd693c..d095dcd31 100644 --- a/src/win/win_preferences.c +++ b/src/win/win_preferences.c @@ -13,6 +13,7 @@ * Authors: Laci bá' * * Copyright 2021 Laci bá' + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -38,7 +39,8 @@ static LCID temp_language; static char temp_icon_set[256] = { 0 }; -int enum_helper, c; +int enum_helper; +int c; HWND hwndPreferences; @@ -112,7 +114,8 @@ preferences_fill_iconsets(HWND hdlg) if (hFind != INVALID_HANDLE_VALUE) { do { if (wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..") && (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - wchar_t temp[512] = { 0 }, dispname[512] = { 0 }; + wchar_t temp[512] = { 0 }; + wchar_t dispname[512] = { 0 }; mbstoc16s(temp, icon_path_root, strlen(icon_path_root) + 1); wcscat(temp, data.cFileName); wcscat(temp, L"\\iconinfo.txt"); @@ -166,8 +169,7 @@ preferences_settings_changed(void) static int preferences_indexof(HWND combo, LPARAM itemdata) { - int i; - for (i = 0; i < SendMessage(combo, CB_GETCOUNT, 0, 0); i++) + for (int i = 0; i < SendMessage(combo, CB_GETCOUNT, 0, 0); i++) if (SendMessage(combo, CB_GETITEMDATA, i, 0) == itemdata) return i; @@ -265,10 +267,9 @@ PreferencesDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_DESTROY: { - int i; LRESULT temp; HWND combo = GetDlgItem(hdlg, IDC_COMBO_ICON); - for (i = 0; i < SendMessage(combo, CB_GETCOUNT, 0, 0); i++) { + for (int i = 0; i < SendMessage(combo, CB_GETCOUNT, 0, 0); i++) { temp = SendMessage(combo, CB_GETITEMDATA, i, 0); if (temp) { free((void *) temp); @@ -279,7 +280,7 @@ PreferencesDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) break; } - return (FALSE); + return FALSE; } void diff --git a/src/win/win_sdl.c b/src/win/win_sdl.c index 5c133524a..cae5f8147 100644 --- a/src/win/win_sdl.c +++ b/src/win/win_sdl.c @@ -10,7 +10,7 @@ * * NOTE: Given all the problems reported with FULLSCREEN use of SDL, * we will not use that, but, instead, use a new window which - * coverrs the entire desktop. + * covers the entire desktop. * * * @@ -81,10 +81,16 @@ static SDL_Window *sdl_win = NULL; static SDL_Renderer *sdl_render = NULL; static SDL_Texture *sdl_tex = NULL; static HWND sdl_parent_hwnd = NULL; -static int sdl_w, sdl_h; -static int sdl_fs, sdl_flags = -1; -static int cur_w, cur_h; -static int cur_wx = 0, cur_wy = 0, cur_ww = 0, cur_wh = 0; +static int sdl_w; +static int sdl_h; +static int sdl_fs; +static int sdl_flags = -1; +static int cur_w; +static int cur_h; +static int cur_wx = 0; +static int cur_wy = 0; +static int cur_ww = 0; +static int cur_wh = 0; static volatile int sdl_enabled = 0; static SDL_mutex *sdl_mutex = NULL; @@ -164,7 +170,16 @@ sdl_integer_scale(double *d, double *g) static void sdl_stretch(int *w, int *h, int *x, int *y) { - double hw, gw, hh, gh, dx, dy, dw, dh, gsr, hsr; + double hw; + double gw; + double hh; + double gh; + double dx; + double dy; + double dw; + double dh; + double gsr; + double hsr; hw = (double) sdl_w; hh = (double) sdl_h; @@ -265,8 +280,8 @@ sdl_blit_ex(int x, int y, int w, int h, int monitor_index) { SDL_Rect r_src; void *pixeldata; - int pitch, ret; - int row; + int pitch; + int ret; if (!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) { video_blit_complete(); @@ -277,7 +292,7 @@ sdl_blit_ex(int x, int y, int w, int h, int monitor_index) SDL_LockTexture(sdl_tex, 0, &pixeldata, &pitch); - for (row = 0; row < h; ++row) + for (int row = 0; row < h; ++row) video_copy(&(((uint8_t *) pixeldata)[row * 2048 * sizeof(uint32_t)]), &(buffer32->line[y + row][x]), w * sizeof(uint32_t)); if (monitors[0].mon_screenshots) @@ -363,10 +378,9 @@ static int old_capture = 0; static void sdl_select_best_hw_driver(void) { - int i; SDL_RendererInfo renderInfo; - for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) { + for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i) { SDL_GetRenderDriverInfo(i, &renderInfo); if (renderInfo.flags & SDL_RENDERER_ACCELERATED) { SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name); @@ -401,7 +415,10 @@ sdl_reinit_texture(void) void sdl_set_fs(int fs) { - int w = 0, h = 0, x = 0, y = 0; + int w = 0; + int h = 0; + int x = 0; + int y = 0; RECT rect; SDL_LockMutex(sdl_mutex); @@ -468,7 +485,7 @@ sdl_init_common(int flags) /* Initialize the SDL system. */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { sdl_log("SDL: initialization failed (%s)\n", SDL_GetError()); - return (0); + return 0; } if (flags & RENDERER_HARDWARE) { @@ -507,7 +524,7 @@ sdl_init_common(int flags) sdl_enabled = 1; sdl_mutex = SDL_CreateMutex(); - return (1); + return 1; } int @@ -531,13 +548,16 @@ sdl_initho(HWND h) int sdl_pause(void) { - return (0); + return 0; } void sdl_resize(int x, int y) { - int ww = 0, wh = 0, wx = 0, wy = 0; + int ww = 0; + int wh = 0; + int wx = 0; + int wy = 0; if (video_fullscreen & 2) return; diff --git a/src/win/win_serial_passthrough.c b/src/win/win_serial_passthrough.c index 1e190956d..cfe920aa7 100644 --- a/src/win/win_serial_passthrough.c +++ b/src/win/win_serial_passthrough.c @@ -13,7 +13,7 @@ * Jasmine Iwanek * * Copyright 2021 Andreas J. Reichel - * Copyright 2021-2022 Jasmine Iwanek + * Copyright 2021-2023 Jasmine Iwanek */ #define _XOPEN_SOURCE 500 @@ -111,9 +111,9 @@ plat_serpt_set_params(void *p) } else { serialattr.fParity = 1; if (dev->serial->lcr & 0x20) { - serialattr.Parity = (MARKPARITY) + !!(dev->serial->lcr & 0x10); + serialattr.Parity = MARKPARITY + !!(dev->serial->lcr & 0x10); } else { - serialattr.Parity = (ODDPARITY) + !!(dev->serial->lcr & 0x10); + serialattr.Parity = ODDPARITY + !!(dev->serial->lcr & 0x10); } } @@ -166,8 +166,9 @@ static int open_pseudo_terminal(serial_passthrough_t *dev) { char ascii_pipe_name[1024] = { 0 }; - strncpy(ascii_pipe_name, dev->named_pipe, 1023); - dev->master_fd = (intptr_t) CreateNamedPipeA(ascii_pipe_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 32, 65536, 65536, NMPWAIT_USE_DEFAULT_WAIT, NULL); + strncpy(ascii_pipe_name, dev->named_pipe, sizeof(ascii_pipe_name)); + ascii_pipe_name[1023] = '\0'; + dev->master_fd = (intptr_t) CreateNamedPipeA(ascii_pipe_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 65536, 65536, NMPWAIT_USE_DEFAULT_WAIT, NULL); if (dev->master_fd == (intptr_t) INVALID_HANDLE_VALUE) { wchar_t errorMsg[1024] = { 0 }; wchar_t finalMsg[1024] = { 0 }; @@ -194,7 +195,7 @@ open_host_serial_port(serial_passthrough_t *dev) DCB *serialattr = calloc(1, sizeof(DCB)); if (!serialattr) return 0; - dev->master_fd = (intptr_t) CreateFileA(dev->host_serial_path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); + dev->master_fd = (intptr_t) CreateFileA(dev->host_serial_path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL); if (dev->master_fd == (intptr_t) INVALID_HANDLE_VALUE) { free(serialattr); return 0; diff --git a/src/win/win_settings.c b/src/win/win_settings.c index b6166c76c..9ded351b9 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -12,11 +12,12 @@ * * Authors: Miran Grca, * David Hrdlička, + * Jasmine Iwanek, * * Copyright 2016-2019 Miran Grca. * Copyright 2018-2019 David Hrdlička. * Copyright 2021 Laci bá' - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -73,7 +74,6 @@ #include <86box/win.h> #include <86box/serial_passthrough.h> #include "../disk/minivhd/minivhd.h" -#include "../disk/minivhd/minivhd_util.h" /* Icon, Bus, File, C, H, S, Size, Speed */ #define C_COLUMNS_HARD_DISKS 7 @@ -86,36 +86,54 @@ static int first_cat = 0; /* Machine category */ -static int temp_machine_type, temp_machine, temp_cpu, temp_wait_states, temp_fpu, temp_sync; +static int temp_machine_type; +static int temp_machine; +static int temp_cpu; +static int temp_wait_states; +static int temp_fpu; +static int temp_sync; static cpu_family_t *temp_cpu_f; static uint32_t temp_mem_size; #ifdef USE_DYNAREC static int temp_dynarec; #endif +static int temp_fpu_softfloat; /* Video category */ -static int temp_gfxcard[2], temp_ibm8514, temp_voodoo, temp_xga; +static int temp_gfxcard[2]; +static int temp_ibm8514; +static int temp_voodoo; +static int temp_xga; /* Input devices category */ -static int temp_mouse, temp_joystick; +static int temp_mouse; +static int temp_joystick; /* Sound category */ static int temp_sound_card[SOUND_CARD_MAX]; -static int temp_midi_output_device, temp_midi_input_device, temp_mpu401; -static int temp_float, temp_fm_driver; +static int temp_midi_output_device; +static int temp_midi_input_device; +static int temp_mpu401; +static int temp_float; +static int temp_fm_driver; /* Network category */ -static int temp_net_type[NET_CARD_MAX]; -static int temp_net_card[NET_CARD_MAX]; -static char temp_pcap_dev[NET_CARD_MAX][128]; +static int temp_net_type[NET_CARD_MAX]; +static uint16_t temp_net_card[NET_CARD_MAX]; +static char temp_pcap_dev[NET_CARD_MAX][128]; /* Ports category */ -static int temp_lpt_devices[PARALLEL_MAX]; -static int temp_serial[SERIAL_MAX], temp_lpt[PARALLEL_MAX]; -static int temp_serial_passthrough_enabled[SERIAL_MAX]; +static int temp_lpt_devices[PARALLEL_MAX]; +static uint8_t temp_serial[SERIAL_MAX]; +static uint8_t temp_lpt[PARALLEL_MAX]; +static int temp_serial_passthrough_enabled[SERIAL_MAX]; /* Other peripherals category */ -static int temp_fdc_card, temp_hdc, temp_ide_ter, temp_ide_qua, temp_cassette; +static int temp_fdc_card; +static int temp_hdc; +static int temp_ide_ter; +static int temp_ide_qua; +static int temp_cassette; static int temp_scsi_card[SCSI_BUS_MAX]; static int temp_bugger; static int temp_postcard; @@ -137,27 +155,48 @@ static cdrom_t temp_cdrom[CDROM_NUM]; static zip_drive_t temp_zip_drives[ZIP_NUM]; static mo_drive_t temp_mo_drives[MO_NUM]; -static HWND hwndParentDialog, hwndChildDialog; +static HWND hwndParentDialog; +static HWND hwndChildDialog; static uint32_t displayed_category = 0; extern int is486; -static int listtomachinetype[256], listtomachine[256]; -static int listtocpufamily[256], listtocpu[256]; -static int settings_list_to_device[2][256], settings_list_to_fdc[20]; -static int settings_list_to_midi[20], settings_list_to_midi_in[20]; +static int listtomachinetype[256]; +static int listtomachine[256]; +static int listtocpufamily[256]; +static int listtocpu[256]; +static int settings_list_to_device[2][256]; +static int settings_list_to_fdc[20]; +static int settings_list_to_midi[20]; +static int settings_list_to_midi_in[20]; static int settings_list_to_hdc[20]; -static int max_spt = 63, max_hpc = 255, max_tracks = 266305; -static uint64_t mfm_tracking, esdi_tracking, xta_tracking, ide_tracking, scsi_tracking[8]; +static int max_spt = 63; +static int max_hpc = 255; +static int max_tracks = 266305; +static uint64_t mfm_tracking; +static uint64_t esdi_tracking; +static uint64_t xta_tracking; +static uint64_t ide_tracking; +static uint64_t scsi_tracking[8]; static uint64_t size; -static int hd_listview_items, hdc_id_to_listview_index[HDD_NUM]; -static int no_update = 0, existing = 0, chs_enabled = 0; -static int lv1_current_sel, lv2_current_sel; -static int hard_disk_added = 0, next_free_id = 0, selection = 127; -static int spt, hpc, tracks, ignore_change = 0; +static int hd_listview_items; +static int hdc_id_to_listview_index[HDD_NUM]; +static int no_update = 0; +static int existing = 0; +static int chs_enabled = 0; +static int lv1_current_sel; +static int lv2_current_sel; +static int hard_disk_added = 0; +static int next_free_id = 0; +static int selection = 127; +static int spt; +static int hpc; +static int tracks; +static int ignore_change = 0; -static hard_disk_t new_hdd, *hdd_ptr; +static hard_disk_t new_hdd; +static hard_disk_t *hdd_ptr; static wchar_t hd_file_name[512]; static WCHAR device_name[512]; @@ -289,7 +328,7 @@ settings_msgbox_header(int flags, void *header, void *message) hwndMain = h; - return (i); + return i; } static int @@ -305,7 +344,7 @@ settings_msgbox_ex(int flags, void *header, void *message, void *btn1, void *btn hwndMain = h; - return (i); + return i; } /* This does the initial read of global variables into the temporary ones. */ @@ -324,6 +363,7 @@ win_settings_init(void) #ifdef USE_DYNAREC temp_dynarec = cpu_use_dynarec; #endif + temp_fpu_softfloat = fpu_softfloat; temp_fpu = fpu_type; temp_sync = time_sync; @@ -442,7 +482,7 @@ win_settings_init(void) static int win_settings_changed(void) { - int i = 0, j = 0; + int i = 0; /* Machine category */ i = i || (machine != temp_machine); @@ -453,6 +493,7 @@ win_settings_changed(void) #ifdef USE_DYNAREC i = i || (temp_dynarec != cpu_use_dynarec); #endif + i = i || (temp_fpu_softfloat != fpu_softfloat); i = i || (temp_fpu != fpu_type); i = i || (temp_sync != time_sync); @@ -468,7 +509,7 @@ win_settings_changed(void) i = i || (joystick_type != temp_joystick); /* Sound category */ - for (j = 0; j < SOUND_CARD_MAX; j++) + for (uint8_t j = 0; j < SOUND_CARD_MAX; j++) i = i || (sound_card_current[j] != temp_sound_card[j]); i = i || (midi_output_device_current != temp_midi_output_device); i = i || (midi_input_device_current != temp_midi_input_device); @@ -477,24 +518,24 @@ win_settings_changed(void) i = i || (fm_driver != temp_fm_driver); /* Network category */ - for (j = 0; j < NET_CARD_MAX; j++) { + for (uint8_t j = 0; j < NET_CARD_MAX; j++) { i = i || (net_cards_conf[j].net_type != temp_net_type[j]); i = i || strcmp(temp_pcap_dev[j], net_cards_conf[j].host_dev_name); i = i || (net_cards_conf[j].device_num != temp_net_card[j]); } /* Ports category */ - for (j = 0; j < PARALLEL_MAX; j++) { + for (uint8_t j = 0; j < PARALLEL_MAX; j++) { i = i || (temp_lpt_devices[j] != lpt_ports[j].device); i = i || (temp_lpt[j] != lpt_ports[j].enabled); } - for (j = 0; j < SERIAL_MAX; j++) { + for (uint8_t j = 0; j < SERIAL_MAX; j++) { i = i || (temp_serial[j] != com_ports[j].enabled); i = i || (temp_serial_passthrough_enabled[i] != serial_passthrough_enabled[i]); } /* Storage devices category */ - for (j = 0; j < SCSI_BUS_MAX; j++) + for (uint8_t j = 0; j < SCSI_BUS_MAX; j++) i = i || (temp_scsi_card[j] != scsi_card_current[j]); i = i || (fdc_type != temp_fdc_card); i = i || (hdc_current != temp_hdc); @@ -506,7 +547,7 @@ win_settings_changed(void) i = i || memcmp(hdd, temp_hdd, HDD_NUM * sizeof(hard_disk_t)); /* Floppy drives category */ - for (j = 0; j < FDD_NUM; j++) { + for (uint8_t j = 0; j < FDD_NUM; j++) { i = i || (temp_fdd_types[j] != fdd_get_type(j)); i = i || (temp_fdd_turbo[j] != fdd_get_turbo(j)); i = i || (temp_fdd_check_bpb[j] != fdd_get_check_bpb(j)); @@ -523,7 +564,7 @@ win_settings_changed(void) i = i || (temp_isartc != isartc_type); /* ISA memory boards. */ - for (j = 0; j < ISAMEM_MAX; j++) + for (uint8_t j = 0; j < ISAMEM_MAX; j++) i = i || (temp_isamem[j] != isamem_type[j]); i = i || !!temp_deviceconfig; @@ -535,8 +576,6 @@ win_settings_changed(void) static void win_settings_save(void) { - int i = 0; - pc_reset_hard_close(); /* Machine category */ @@ -548,6 +587,7 @@ win_settings_save(void) #ifdef USE_DYNAREC cpu_use_dynarec = temp_dynarec; #endif + fpu_softfloat = temp_fpu_softfloat; fpu_type = temp_fpu; time_sync = temp_sync; @@ -563,7 +603,7 @@ win_settings_save(void) joystick_type = temp_joystick; /* Sound category */ - for (i = 0; i < SOUND_CARD_MAX; i++) + for (uint8_t i = 0; i < SOUND_CARD_MAX; i++) sound_card_current[i] = temp_sound_card[i]; midi_output_device_current = temp_midi_output_device; midi_input_device_current = temp_midi_input_device; @@ -572,7 +612,7 @@ win_settings_save(void) fm_driver = temp_fm_driver; /* Network category */ - for (i = 0; i < NET_CARD_MAX; i++) { + for (uint8_t i = 0; i < NET_CARD_MAX; i++) { net_cards_conf[i].net_type = temp_net_type[i]; memset(net_cards_conf[i].host_dev_name, '\0', sizeof(net_cards_conf[i].host_dev_name)); strcpy(net_cards_conf[i].host_dev_name, temp_pcap_dev[i]); @@ -580,17 +620,17 @@ win_settings_save(void) } /* Ports category */ - for (i = 0; i < PARALLEL_MAX; i++) { + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { lpt_ports[i].device = temp_lpt_devices[i]; lpt_ports[i].enabled = temp_lpt[i]; } - for (i = 0; i < SERIAL_MAX; i++) { + for (uint8_t i = 0; i < SERIAL_MAX; i++) { com_ports[i].enabled = temp_serial[i]; serial_passthrough_enabled[i] = temp_serial_passthrough_enabled[i]; } /* Storage devices category */ - for (i = 0; i < SCSI_BUS_MAX; i++) + for (uint8_t i = 0; i < SCSI_BUS_MAX; i++) scsi_card_current[i] = temp_scsi_card[i]; hdc_current = temp_hdc; fdc_type = temp_fdc_card; @@ -600,11 +640,11 @@ win_settings_save(void) /* Hard disks category */ memcpy(hdd, temp_hdd, HDD_NUM * sizeof(hard_disk_t)); - for (i = 0; i < HDD_NUM; i++) + for (uint8_t i = 0; i < HDD_NUM; i++) hdd[i].priv = NULL; /* Floppy drives category */ - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { fdd_set_type(i, temp_fdd_types[i]); fdd_set_turbo(i, temp_fdd_turbo[i]); fdd_set_check_bpb(i, temp_fdd_check_bpb[i]); @@ -612,7 +652,7 @@ win_settings_save(void) /* Removable devices category */ memcpy(cdrom, temp_cdrom, CDROM_NUM * sizeof(cdrom_t)); - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { cdrom[i].is_dir = 0; cdrom[i].priv = NULL; cdrom[i].ops = NULL; @@ -623,12 +663,12 @@ win_settings_save(void) cdrom[i].get_channel = NULL; } memcpy(zip_drives, temp_zip_drives, ZIP_NUM * sizeof(zip_drive_t)); - for (i = 0; i < ZIP_NUM; i++) { + for (uint8_t i = 0; i < ZIP_NUM; i++) { zip_drives[i].f = NULL; zip_drives[i].priv = NULL; } memcpy(mo_drives, temp_mo_drives, MO_NUM * sizeof(mo_drive_t)); - for (i = 0; i < MO_NUM; i++) { + for (uint8_t i = 0; i < MO_NUM; i++) { mo_drives[i].f = NULL; mo_drives[i].priv = NULL; } @@ -639,7 +679,7 @@ win_settings_save(void) isartc_type = temp_isartc; /* ISA memory boards. */ - for (i = 0; i < ISAMEM_MAX; i++) + for (uint8_t i = 0; i < ISAMEM_MAX; i++) isamem_type[i] = temp_isamem[i]; /* Mark configuration as changed. */ @@ -651,7 +691,8 @@ win_settings_save(void) static void win_settings_machine_recalc_fpu(HWND hdlg) { - int c, type; + int c; + int type; LPTSTR lptsTemp; const char *stransi; @@ -673,6 +714,9 @@ win_settings_machine_recalc_fpu(HWND hdlg) c++; } + settings_set_check(hdlg, IDC_CHECK_SOFTFLOAT, (machine_has_flags(temp_machine, MACHINE_SOFTFLOAT_ONLY) ? TRUE : temp_fpu_softfloat)); + settings_enable_window(hdlg, IDC_CHECK_SOFTFLOAT, (machine_has_flags(temp_machine, MACHINE_SOFTFLOAT_ONLY) ? FALSE : TRUE)); + settings_enable_window(hdlg, IDC_COMBO_FPU, c > 1); temp_fpu = fpu_get_type_from_index(temp_cpu_f, temp_cpu, settings_get_cur_sel(hdlg, IDC_COMBO_FPU)); @@ -712,7 +756,11 @@ win_settings_machine_recalc_cpu(HWND hdlg) static void win_settings_machine_recalc_cpu_m(HWND hdlg) { - int c, i, first_eligible = -1, current_eligible = 0, last_eligible = 0; + int c; + int i; + int first_eligible = -1; + int current_eligible = 0; + int last_eligible = 0; LPTSTR lptsTemp; char *stransi; @@ -755,7 +803,9 @@ static void win_settings_machine_recalc_machine(HWND hdlg) { HWND h; - int c, i, current_eligible; + int c; + int i; + int current_eligible; LPTSTR lptsTemp; char *stransi; UDACCEL accel; @@ -862,8 +912,10 @@ static BOOL CALLBACK #endif win_settings_machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - HWND h, h2; - int c, d; + HWND h; + HWND h2; + int c; + int d; int old_machine_type; LPTSTR lptsTemp; char *stransi; @@ -916,6 +968,8 @@ win_settings_machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) settings_set_check(hdlg, IDC_CHECK_DYNAREC, 0); #endif + settings_set_check(hdlg, IDC_CHECK_SOFTFLOAT, 0); + h = GetDlgItem(hdlg, IDC_MEMSPIN); h2 = GetDlgItem(hdlg, IDC_MEMTEXT); SendMessage(h, UDM_SETBUDDY, (WPARAM) h2, 0); @@ -1009,6 +1063,8 @@ win_settings_machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) temp_dynarec = settings_get_check(hdlg, IDC_CHECK_DYNAREC); #endif + temp_fpu_softfloat = settings_get_check(hdlg, IDC_CHECK_SOFTFLOAT); + if (settings_get_check(hdlg, IDC_RADIO_TS_DISABLED)) temp_sync = TIME_SYNC_DISABLED; @@ -1070,7 +1126,8 @@ static BOOL CALLBACK #endif win_settings_video_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int c = 0, d = 0; + int c = 0; + int d = 0; int e; switch (message) { @@ -1279,7 +1336,7 @@ mouse_valid(int num, int m) const device_t *dev; if ((num == MOUSE_TYPE_INTERNAL) && !machine_has_flags(m, MACHINE_MOUSE)) - return (0); + return 0; dev = mouse_get_device(num); return (device_is_valid(dev, m)); @@ -1294,7 +1351,8 @@ win_settings_input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { wchar_t str[128]; char *joy_name; - int c, d; + int c; + int d; switch (message) { case WM_INITDIALOG: @@ -1383,7 +1441,8 @@ mpu401_present(void) int mpu401_standalone_allow(void) { - char *md, *mdin; + char *md; + char *mdin; if (!machine_has_bus(temp_machine, MACHINE_BUS_ISA) && !machine_has_bus(temp_machine, MACHINE_BUS_MCA)) return 0; @@ -1406,7 +1465,8 @@ static BOOL CALLBACK #endif win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - uint16_t c, d; + uint16_t c; + uint16_t d; LPTSTR lptsTemp; const device_t *sound_dev[SOUND_CARD_MAX]; @@ -1741,7 +1801,8 @@ static BOOL CALLBACK #endif win_settings_ports_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int c, i; + int c; + int i; char *s; LPTSTR lptsTemp; @@ -1818,11 +1879,14 @@ static BOOL CALLBACK #endif win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int c, d; - int e, is_at; + int c; + int d; + int e; + int is_at; LPTSTR lptsTemp; char *stransi; - const device_t *scsi_dev, *fdc_dev; + const device_t *scsi_dev; + const device_t *fdc_dev; const device_t *hdc_dev; switch (message) { @@ -1939,9 +2003,10 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) settings_enable_window(hdlg, IDC_BUTTON_IDE_TER, is_at && temp_ide_ter); settings_enable_window(hdlg, IDC_CHECK_IDE_QUA, is_at); settings_enable_window(hdlg, IDC_BUTTON_IDE_QUA, is_at && temp_ide_qua); + settings_enable_window(hdlg, IDC_CHECK_CASSETTE, machine_has_bus(temp_machine, MACHINE_BUS_CASSETTE)); settings_set_check(hdlg, IDC_CHECK_IDE_TER, temp_ide_ter); settings_set_check(hdlg, IDC_CHECK_IDE_QUA, temp_ide_qua); - settings_set_check(hdlg, IDC_CHECK_CASSETTE, temp_cassette); + settings_set_check(hdlg, IDC_CHECK_CASSETTE, (temp_cassette && machine_has_bus(temp_machine, MACHINE_BUS_CASSETTE))); free(stransi); free(lptsTemp); @@ -2022,16 +2087,12 @@ network_recalc_combos(HWND hdlg) { ignore_change = 1; -#if 0 for (uint8_t i = 0; i < NET_CARD_MAX; i++) { -#endif - settings_enable_window(hdlg, IDC_COMBO_PCAP1, temp_net_type[0] == NET_TYPE_PCAP); - settings_enable_window(hdlg, IDC_COMBO_NET1, - (temp_net_type[0] == NET_TYPE_SLIRP) || ((temp_net_type[0] == NET_TYPE_PCAP) && (network_dev_to_id(temp_pcap_dev[0]) > 0))); - settings_enable_window(hdlg, IDC_CONFIGURE_NET1, network_card_has_config(temp_net_card[0]) && ((temp_net_type[0] == NET_TYPE_SLIRP) || ((temp_net_type[0] == NET_TYPE_PCAP) && (network_dev_to_id(temp_pcap_dev[0]) > 0)))); -#if 0 + settings_enable_window(hdlg, IDC_COMBO_PCAP1 + i, temp_net_type[i] == NET_TYPE_PCAP); + settings_enable_window(hdlg, IDC_COMBO_NET1 + i, + (temp_net_type[i] == NET_TYPE_SLIRP) || ((temp_net_type[i] == NET_TYPE_PCAP) && (network_dev_to_id(temp_pcap_dev[i]) > 0))); + settings_enable_window(hdlg, IDC_CONFIGURE_NET1 + i, network_card_has_config(temp_net_card[i]) && ((temp_net_type[i] == NET_TYPE_SLIRP) || ((temp_net_type[i] == NET_TYPE_PCAP) && (network_dev_to_id(temp_pcap_dev[i]) > 0)))); } -#endif ignore_change = 0; } @@ -2043,80 +2104,88 @@ static BOOL CALLBACK #endif win_settings_network_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int c, d; + int c; + int d; LPTSTR lptsTemp; switch (message) { case WM_INITDIALOG: lptsTemp = (LPTSTR) malloc(512 * sizeof(WCHAR)); -#if 0 for (uint8_t i = 0; i < NET_CARD_MAX; i++) { -#endif - settings_add_string(hdlg, IDC_COMBO_NET1_TYPE, (LPARAM) L"None"); - settings_add_string(hdlg, IDC_COMBO_NET1_TYPE, (LPARAM) L"SLiRP"); - settings_add_string(hdlg, IDC_COMBO_NET1_TYPE, (LPARAM) L"PCap"); - settings_set_cur_sel(hdlg, IDC_COMBO_NET1_TYPE, temp_net_type[0]); - settings_enable_window(hdlg, IDC_COMBO_PCAP1, temp_net_type[0] == NET_TYPE_PCAP); + settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"Null Driver"); + settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"SLiRP"); + settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"PCap"); + settings_set_cur_sel(hdlg, IDC_COMBO_NET1_TYPE + i, temp_net_type[i]); + settings_enable_window(hdlg, IDC_COMBO_PCAP1 + i, temp_net_type[i] == NET_TYPE_PCAP); - for (c = 0; c < network_ndev; c++) { - mbstowcs(lptsTemp, network_devs[c].description, strlen(network_devs[c].description) + 1); - settings_add_string(hdlg, IDC_COMBO_PCAP1, (LPARAM) lptsTemp); - } - settings_set_cur_sel(hdlg, IDC_COMBO_PCAP1, network_dev_to_id(temp_pcap_dev[0])); + for (c = 0; c < network_ndev; c++) { + mbstowcs(lptsTemp, network_devs[c].description, strlen(network_devs[c].description) + 1); + settings_add_string(hdlg, IDC_COMBO_PCAP1 + i, (LPARAM) lptsTemp); + } + settings_set_cur_sel(hdlg, IDC_COMBO_PCAP1 + i, network_dev_to_id(temp_pcap_dev[i])); - /* NIC config */ - c = d = 0; - settings_reset_content(hdlg, IDC_COMBO_NET1); - while (1) { - generate_device_name(network_card_getdevice(c), network_card_get_internal_name(c), 1); + /* NIC config */ + c = d = 0; + settings_reset_content(hdlg, IDC_COMBO_NET1 + i); + while (1) { + generate_device_name(network_card_getdevice(c), network_card_get_internal_name(c), 1); - if (device_name[0] == L'\0') - break; + if (device_name[0] == L'\0') + break; - if (network_card_available(c) && device_is_valid(network_card_getdevice(c), temp_machine)) { - if (c == 0) - settings_add_string(hdlg, IDC_COMBO_NET1, win_get_string(IDS_2104)); - else - settings_add_string(hdlg, IDC_COMBO_NET1, (LPARAM) device_name); - settings_list_to_device[0][d] = c; - if ((c == 0) || (c == temp_net_card[0])) - settings_set_cur_sel(hdlg, IDC_COMBO_NET1, d); - d++; + if (network_card_available(c) && device_is_valid(network_card_getdevice(c), temp_machine)) { + if (c == 0) + settings_add_string(hdlg, IDC_COMBO_NET1 + i, win_get_string(IDS_2104)); + else + settings_add_string(hdlg, IDC_COMBO_NET1 + i, (LPARAM) device_name); + settings_list_to_device[0][d] = c; + if ((c == 0) || (c == temp_net_card[i])) + settings_set_cur_sel(hdlg, IDC_COMBO_NET1 + i, d); + d++; + } + + c++; } - c++; + settings_enable_window(hdlg, IDC_COMBO_NET1 + i, d); + network_recalc_combos(hdlg); } - - settings_enable_window(hdlg, IDC_COMBO_NET1, d); - network_recalc_combos(hdlg); free(lptsTemp); -#if 0 - } -#endif return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_COMBO_NET1_TYPE: -#if 0 - case IDC_COMBO_NET2_TYPE: - case IDC_COMBO_NET3_TYPE: - case IDC_COMBO_NET4_TYPE: -#endif if (ignore_change) return FALSE; temp_net_type[0] = settings_get_cur_sel(hdlg, IDC_COMBO_NET1_TYPE); network_recalc_combos(hdlg); break; + case IDC_COMBO_NET2_TYPE: + if (ignore_change) + return FALSE; + + temp_net_type[1] = settings_get_cur_sel(hdlg, IDC_COMBO_NET2_TYPE); + network_recalc_combos(hdlg); + break; + case IDC_COMBO_NET3_TYPE: + if (ignore_change) + return FALSE; + + temp_net_type[2] = settings_get_cur_sel(hdlg, IDC_COMBO_NET3_TYPE); + network_recalc_combos(hdlg); + break; + case IDC_COMBO_NET4_TYPE: + if (ignore_change) + return FALSE; + + temp_net_type[3] = settings_get_cur_sel(hdlg, IDC_COMBO_NET4_TYPE); + network_recalc_combos(hdlg); + break; case IDC_COMBO_PCAP1: -#if 0 - case IDC_COMBO_PCAP2: - case IDC_COMBO_PCAP3: - case IDC_COMBO_PCAP4: -#endif if (ignore_change) return FALSE; @@ -2124,46 +2193,98 @@ win_settings_network_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) strcpy(temp_pcap_dev[0], network_devs[settings_get_cur_sel(hdlg, IDC_COMBO_PCAP1)].device); network_recalc_combos(hdlg); break; + case IDC_COMBO_PCAP2: + if (ignore_change) + return FALSE; + + memset(temp_pcap_dev[1], '\0', sizeof(temp_pcap_dev[1])); + strcpy(temp_pcap_dev[1], network_devs[settings_get_cur_sel(hdlg, IDC_COMBO_PCAP2)].device); + network_recalc_combos(hdlg); + break; + case IDC_COMBO_PCAP3: + if (ignore_change) + return FALSE; + + memset(temp_pcap_dev[2], '\0', sizeof(temp_pcap_dev[2])); + strcpy(temp_pcap_dev[2], network_devs[settings_get_cur_sel(hdlg, IDC_COMBO_PCAP3)].device); + network_recalc_combos(hdlg); + break; + case IDC_COMBO_PCAP4: + if (ignore_change) + return FALSE; + + memset(temp_pcap_dev[3], '\0', sizeof(temp_pcap_dev[3])); + strcpy(temp_pcap_dev[3], network_devs[settings_get_cur_sel(hdlg, IDC_COMBO_PCAP4)].device); + network_recalc_combos(hdlg); + break; case IDC_COMBO_NET1: -#if 0 - case IDC_COMBO_NET2: - case IDC_COMBO_NET3: - case IDC_COMBO_NET4: -#endif if (ignore_change) return FALSE; temp_net_card[0] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET1)]; network_recalc_combos(hdlg); break; + case IDC_COMBO_NET2: + if (ignore_change) + return FALSE; + + temp_net_card[1] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET2)]; + network_recalc_combos(hdlg); + break; + case IDC_COMBO_NET3: + if (ignore_change) + return FALSE; + + temp_net_card[2] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET3)]; + network_recalc_combos(hdlg); + break; + case IDC_COMBO_NET4: + if (ignore_change) + return FALSE; + + temp_net_card[3] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET4)]; + network_recalc_combos(hdlg); + break; case IDC_CONFIGURE_NET1: -#if 0 - case IDC_CONFIGURE_NET2: - case IDC_CONFIGURE_NET3: - case IDC_CONFIGURE_NET4: -#endif if (ignore_change) return FALSE; temp_net_card[0] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET1)]; temp_deviceconfig |= deviceconfig_open(hdlg, (void *) network_card_getdevice(temp_net_card[0])); break; + case IDC_CONFIGURE_NET2: + if (ignore_change) + return FALSE; + + temp_net_card[1] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET2)]; + temp_deviceconfig |= deviceconfig_open(hdlg, (void *) network_card_getdevice(temp_net_card[1])); + break; + case IDC_CONFIGURE_NET3: + if (ignore_change) + return FALSE; + + temp_net_card[2] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET3)]; + temp_deviceconfig |= deviceconfig_open(hdlg, (void *) network_card_getdevice(temp_net_card[2])); + break; + case IDC_CONFIGURE_NET4: + if (ignore_change) + return FALSE; + + temp_net_card[3] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET4)]; + temp_deviceconfig |= deviceconfig_open(hdlg, (void *) network_card_getdevice(temp_net_card[3])); + break; } return FALSE; case WM_SAVESETTINGS: -#if 0 for (uint8_t i = 0; i < NET_CARD_MAX; i++) { -#endif - temp_net_type[0] = settings_get_cur_sel(hdlg, IDC_COMBO_NET1_TYPE); - memset(temp_pcap_dev[0], '\0', sizeof(temp_pcap_dev[0])); - strcpy(temp_pcap_dev[0], network_devs[settings_get_cur_sel(hdlg, IDC_COMBO_PCAP1)].device); - temp_net_card[0] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET1)]; -#if 0 + temp_net_type[i] = settings_get_cur_sel(hdlg, IDC_COMBO_NET1_TYPE + i); + memset(temp_pcap_dev[i], '\0', sizeof(temp_pcap_dev[i])); + strcpy(temp_pcap_dev[i], network_devs[settings_get_cur_sel(hdlg, IDC_COMBO_PCAP1 + i)].device); + temp_net_card[i] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_NET1 + i)]; } -#endif default: return FALSE; } @@ -2175,12 +2296,11 @@ static void normalize_hd_list(void) { hard_disk_t ihdd[HDD_NUM]; - int i, j; + int j = 0; - j = 0; memset(ihdd, 0x00, HDD_NUM * sizeof(hard_disk_t)); - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if (temp_hdd[i].bus != HDD_BUS_DISABLED) { memcpy(&(ihdd[j]), &(temp_hdd[i]), sizeof(hard_disk_t)); j++; @@ -2194,13 +2314,13 @@ static int get_selected_hard_disk(HWND hdlg) { int hard_disk = -1; - int i, j = 0; + int j = 0; HWND h; if (hd_listview_items == 0) return 0; - for (i = 0; i < hd_listview_items; i++) { + for (int i = 0; i < hd_listview_items; i++) { h = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); j = ListView_GetItemState(h, i, LVIS_SELECTED); if (j) @@ -2242,9 +2362,7 @@ add_locations(HWND hdlg) static uint8_t next_free_binary_channel(uint64_t *tracking) { - int64_t i; - - for (i = 0; i < 2; i++) { + for (int64_t i = 0; i < 2; i++) { if (!(*tracking & (0xffLL << (i << 3LL)))) return i; } @@ -2255,9 +2373,7 @@ next_free_binary_channel(uint64_t *tracking) static uint8_t next_free_ide_channel(void) { - int64_t i; - - for (i = 0; i < (IDE_BUS_MAX * IDE_CHAN_MAX); i++) { + for (int64_t i = 0; i < (IDE_BUS_MAX * IDE_CHAN_MAX); i++) { if (!(ide_tracking & (0xffLL << (i << 3LL)))) return i; } @@ -2268,9 +2384,7 @@ next_free_ide_channel(void) static void next_free_scsi_id(uint8_t *id) { - int64_t i; - - for (i = 0; i < (SCSI_BUS_MAX * SCSI_ID_MAX); i++) { + for (int64_t i = 0; i < (SCSI_BUS_MAX * SCSI_ID_MAX); i++) { if (!(scsi_tracking[i >> 3] & (0xffLL << ((i & 0x07) << 3LL)))) { *id = i; return; @@ -2283,9 +2397,9 @@ next_free_scsi_id(uint8_t *id) static void recalc_location_controls(HWND hdlg, int is_add_dlg, int assign_id) { - int i = 0, bus = 0; + int bus = 0; - for (i = IDT_CHANNEL; i <= IDT_ID; i++) + for (uint16_t i = IDT_CHANNEL; i <= IDT_ID; i++) settings_show_window(hdlg, i, FALSE); settings_show_window(hdlg, IDC_COMBO_HD_CHANNEL, FALSE); settings_show_window(hdlg, IDC_COMBO_HD_ID, FALSE); @@ -2372,10 +2486,14 @@ bus_full(uint64_t *tracking, int count) static void recalc_next_free_id(HWND hdlg) { - int i, enable_add = 0; - int c_mfm = 0, c_esdi = 0; - int c_xta = 0, c_ide = 0; - int c_atapi = 0, c_scsi = 0; + int i; + int enable_add = 0; + int c_mfm = 0; + int c_esdi = 0; + int c_xta = 0; + int c_ide = 0; + int c_atapi = 0; + int c_scsi = 0; next_free_id = -1; @@ -2486,8 +2604,9 @@ static BOOL win_settings_hard_disks_recalc_list(HWND hdlg) { LVITEM lvI; - int i, j = 0; - WCHAR szText[256], usr_path_w[1024]; + int j = 0; + WCHAR szText[256]; + WCHAR usr_path_w[1024]; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); mbstoc16s(usr_path_w, usr_path, sizeof_w(usr_path_w)); @@ -2500,7 +2619,7 @@ win_settings_hard_disks_recalc_list(HWND hdlg) lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvI.stateMask = lvI.iSubItem = lvI.state = 0; - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if (temp_hdd[i].bus > 0) { hdc_id_to_listview_index[i] = j; lvI.iSubItem = 0; @@ -2606,21 +2725,21 @@ static void win_settings_hard_disks_resize_columns(HWND hdlg) { /* Bus, File, Cylinders, Heads, Sectors, Size */ - int iCol, width[C_COLUMNS_HARD_DISKS] = { - C_COLUMNS_HARD_DISKS_BUS, - C_COLUMNS_HARD_DISKS_FILE, - C_COLUMNS_HARD_DISKS_CYLS, - C_COLUMNS_HARD_DISKS_HEADS, - C_COLUMNS_HARD_DISKS_SECT, - C_COLUMNS_HARD_DISKS_SIZE, - C_COLUMNS_HARD_DISKS_SPEED - }; + int width[C_COLUMNS_HARD_DISKS] = { + C_COLUMNS_HARD_DISKS_BUS, + C_COLUMNS_HARD_DISKS_FILE, + C_COLUMNS_HARD_DISKS_CYLS, + C_COLUMNS_HARD_DISKS_HEADS, + C_COLUMNS_HARD_DISKS_SECT, + C_COLUMNS_HARD_DISKS_SIZE, + C_COLUMNS_HARD_DISKS_SPEED + }; int total = 0; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); RECT r; GetWindowRect(hwndList, &r); - for (iCol = 0; iCol < (C_COLUMNS_HARD_DISKS - 1); iCol++) { + for (int iCol = 0; iCol < (C_COLUMNS_HARD_DISKS - 1); iCol++) { width[iCol] = MulDiv(width[iCol], dpi, 96); total += width[iCol]; ListView_SetColumnWidth(hwndList, iCol, MulDiv(width[iCol], dpi, 96)); @@ -2633,12 +2752,11 @@ static BOOL win_settings_hard_disks_init_columns(HWND hdlg) { LVCOLUMN lvc; - int iCol; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_HARD_DISKS); lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - for (iCol = 0; iCol < C_COLUMNS_HARD_DISKS; iCol++) { + for (int iCol = 0; iCol < C_COLUMNS_HARD_DISKS; iCol++) { lvc.iSubItem = iCol; lvc.pszText = plat_get_string(IDS_BUS + iCol); @@ -2722,14 +2840,13 @@ get_edit_box_text_contents(HWND hdlg, int id, WCHAR *text_buffer, int buffer_siz static int hdconf_initialize_hdt_combo(HWND hdlg) { - int i = 0; uint64_t temp_size = 0; uint32_t size_mb = 0; WCHAR szText[256]; selection = 127; - for (i = 0; i < 127; i++) { + for (uint8_t i = 0; i < 127; i++) { temp_size = ((uint64_t) hdd_table[i][0]) * hdd_table[i][1] * hdd_table[i][2]; size_mb = (uint32_t) (temp_size >> 11LL); wsprintf(szText, plat_get_string(IDS_2108), size_mb, hdd_table[i][0], hdd_table[i][1], hdd_table[i][2]); @@ -2746,10 +2863,8 @@ hdconf_initialize_hdt_combo(HWND hdlg) static void recalc_selection(HWND hdlg) { - int i = 0; - selection = 127; - for (i = 0; i < 127; i++) { + for (uint8_t i = 0; i < 127; i++) { if ((tracks == (int) hdd_table[i][0]) && (hpc == (int) hdd_table[i][1]) && (spt == (int) hdd_table[i][2])) selection = i; } @@ -2918,9 +3033,12 @@ win_settings_hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM { HWND h; FILE *f; - uint32_t temp, i = 0, sector_size = 512; - uint32_t zero = 0, base = 0x1000; - uint64_t signature = 0xD778A82044445459ll; + uint32_t temp; + uint32_t i = 0; + uint32_t sector_size = 512; + uint32_t zero = 0; + uint32_t base = 0x1000; + uint64_t signature = 0xD778A82044445459LL; uint64_t r = 0; char *big_buf; char hd_file_name_multibyte[1200]; @@ -2929,7 +3047,8 @@ win_settings_hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM uint8_t channel = 0; uint8_t id = 0; wchar_t *twcs; - int img_format, block_size; + int img_format; + int block_size; WCHAR text_buf[256]; RECT rect; POINT point; @@ -3072,7 +3191,7 @@ win_settings_hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM sector_size = 512; if (!(existing & 1) && (wcslen(hd_file_name) > 0)) { - if (size > 0x1FFFFFFE00ll) { + if (size > 0x1FFFFFFE00LL) { settings_msgbox_header(MBX_ERROR, (wchar_t *) IDS_4116, (wchar_t *) IDS_4105); return TRUE; } @@ -3085,7 +3204,7 @@ win_settings_hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM } if (img_format == IMG_FMT_HDI) { /* HDI file */ - if (size >= 0x100000000ll) { + if (size >= 0x100000000LL) { fclose(f); settings_msgbox_header(MBX_ERROR, (wchar_t *) IDS_4116, (wchar_t *) IDS_4104); return TRUE; @@ -3690,9 +3809,7 @@ hard_disk_untrack(uint8_t id) static void hard_disk_track_all(void) { - int i; - - for (i = 0; i < HDD_NUM; i++) + for (uint8_t i = 0; i < HDD_NUM; i++) hard_disk_track(i); } @@ -3703,7 +3820,9 @@ static BOOL CALLBACK #endif win_settings_hard_disks_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int old_sel = 0, b = 0, assign = 0; + int old_sel = 0; + int b = 0; + int assign = 0; const uint8_t hd_icons[2] = { 80, 0 }; switch (message) { @@ -3850,15 +3969,15 @@ static BOOL win_settings_floppy_drives_recalc_list(HWND hdlg) { LVITEM lvI; - int i = 0; - char s[256], *t; + char s[256]; + char *t; WCHAR szText[256]; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvI.stateMask = lvI.state = 0; - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { lvI.iSubItem = 0; if (temp_fdd_types[i] > 0) { t = fdd_getname(temp_fdd_types[i]); @@ -3897,14 +4016,14 @@ static BOOL win_settings_cdrom_drives_recalc_list(HWND hdlg) { LVITEM lvI; - int i = 0, fsid = 0; + int fsid = 0; WCHAR szText[256]; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvI.stateMask = lvI.iSubItem = lvI.state = 0; - for (i = 0; i < CDROM_NUM; i++) { + for (uint8_t i = 0; i < CDROM_NUM; i++) { fsid = combo_id_to_format_string_id(temp_cdrom[i].bus_type); lvI.iSubItem = 0; @@ -3944,6 +4063,7 @@ win_settings_cdrom_drives_recalc_list(HWND hdlg) if (ListView_SetItem(hwndList, &lvI) == -1) return FALSE; +/* lvI.iSubItem = 2; lvI.pszText = plat_get_string(temp_cdrom[i].early ? IDS_2060 : IDS_2061); lvI.iItem = i; @@ -3951,6 +4071,7 @@ win_settings_cdrom_drives_recalc_list(HWND hdlg) if (ListView_SetItem(hwndList, &lvI) == -1) return FALSE; +*/ } return TRUE; @@ -3960,7 +4081,7 @@ static BOOL win_settings_mo_drives_recalc_list(HWND hdlg) { LVITEM lvI; - int i = 0, fsid = 0; + int fsid = 0; WCHAR szText[256]; char szType[30]; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_MO_DRIVES); @@ -3968,7 +4089,7 @@ win_settings_mo_drives_recalc_list(HWND hdlg) lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvI.stateMask = lvI.iSubItem = lvI.state = 0; - for (i = 0; i < MO_NUM; i++) { + for (uint8_t i = 0; i < MO_NUM; i++) { fsid = combo_id_to_format_string_id(temp_mo_drives[i].bus_type); lvI.iSubItem = 0; @@ -4023,14 +4144,14 @@ static BOOL win_settings_zip_drives_recalc_list(HWND hdlg) { LVITEM lvI; - int i = 0, fsid = 0; + int fsid = 0; WCHAR szText[256]; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_ZIP_DRIVES); lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvI.stateMask = lvI.iSubItem = lvI.state = 0; - for (i = 0; i < ZIP_NUM; i++) { + for (uint8_t i = 0; i < ZIP_NUM; i++) { fsid = combo_id_to_format_string_id(temp_zip_drives[i].bus_type); lvI.iSubItem = 0; @@ -4076,17 +4197,17 @@ win_settings_zip_drives_recalc_list(HWND hdlg) static void win_settings_floppy_drives_resize_columns(HWND hdlg) { - int iCol, width[C_COLUMNS_FLOPPY_DRIVES] = { - C_COLUMNS_FLOPPY_DRIVES_TYPE, - C_COLUMNS_FLOPPY_DRIVES_TURBO, - C_COLUMNS_FLOPPY_DRIVES_BPB - }; + int width[C_COLUMNS_FLOPPY_DRIVES] = { + C_COLUMNS_FLOPPY_DRIVES_TYPE, + C_COLUMNS_FLOPPY_DRIVES_TURBO, + C_COLUMNS_FLOPPY_DRIVES_BPB + }; int total = 0; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); RECT r; GetWindowRect(hwndList, &r); - for (iCol = 0; iCol < C_COLUMNS_FLOPPY_DRIVES; iCol++) { + for (uint8_t iCol = 0; iCol < C_COLUMNS_FLOPPY_DRIVES; iCol++) { width[iCol] = MulDiv(width[iCol], dpi, 96); total += width[iCol]; ListView_SetColumnWidth(hwndList, iCol, MulDiv(width[iCol], dpi, 96)); @@ -4144,17 +4265,17 @@ win_settings_floppy_drives_init_columns(HWND hdlg) static void win_settings_cdrom_drives_resize_columns(HWND hdlg) { - int iCol, width[C_COLUMNS_CDROM_DRIVES] = { - C_COLUMNS_CDROM_DRIVES_BUS, - C_COLUMNS_CDROM_DRIVES_SPEED, - C_COLUMNS_CDROM_DRIVES_EARLIER - }; + int width[C_COLUMNS_CDROM_DRIVES] = { + C_COLUMNS_CDROM_DRIVES_BUS, + C_COLUMNS_CDROM_DRIVES_SPEED, + C_COLUMNS_CDROM_DRIVES_EARLIER + }; int total = 0; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); RECT r; GetWindowRect(hwndList, &r); - for (iCol = 0; iCol < C_COLUMNS_CDROM_DRIVES; iCol++) { + for (uint8_t iCol = 0; iCol < C_COLUMNS_CDROM_DRIVES; iCol++) { width[iCol] = MulDiv(width[iCol], dpi, 96); total += width[iCol]; ListView_SetColumnWidth(hwndList, iCol, MulDiv(width[iCol], dpi, 96)); @@ -4191,7 +4312,7 @@ win_settings_cdrom_drives_init_columns(HWND hdlg) if (ListView_InsertColumn(hwndList, 1, &lvc) == -1) return FALSE; - /* Earlier drive */ + /* Type */ lvc.iSubItem = 2; lvc.pszText = plat_get_string(IDS_2162); @@ -4313,10 +4434,10 @@ static int get_selected_drive(HWND hdlg, int id, int max) { int drive = -1; - int i, j = 0; + int j = 0; HWND h; - for (i = 0; i < max; i++) { + for (int i = 0; i < max; i++) { h = GetDlgItem(hdlg, id); j = ListView_GetItemState(h, i, LVIS_SELECTED); if (j) @@ -4330,7 +4451,8 @@ static void win_settings_floppy_drives_update_item(HWND hdlg, int i) { LVITEM lvI; - char s[256], *t; + char s[256]; + char *t; WCHAR szText[256]; HWND hwndList = GetDlgItem(hdlg, IDC_LIST_FLOPPY_DRIVES); @@ -4419,6 +4541,7 @@ win_settings_cdrom_drives_update_item(HWND hdlg, int i) if (ListView_SetItem(hwndList, &lvI) == -1) return; +/* lvI.iSubItem = 2; lvI.pszText = plat_get_string(temp_cdrom[i].early ? IDS_2060 : IDS_2061); lvI.iItem = i; @@ -4426,6 +4549,7 @@ win_settings_cdrom_drives_update_item(HWND hdlg, int i) if (ListView_SetItem(hwndList, &lvI) == -1) return; +*/ } static void @@ -4568,20 +4692,20 @@ cdrom_add_locations(HWND hdlg) static void cdrom_recalc_location_controls(HWND hdlg, int assign_id) { - int i = 0; int bus = temp_cdrom[lv2_current_sel].bus_type; - for (i = IDT_CD_ID; i <= IDT_CD_CHANNEL; i++) + for (uint16_t i = IDT_CD_ID; i <= IDT_CD_CHANNEL; i++) settings_show_window(hdlg, i, FALSE); settings_show_window(hdlg, IDC_COMBO_CD_ID, FALSE); settings_show_window(hdlg, IDC_COMBO_CD_CHANNEL_IDE, FALSE); settings_show_window(hdlg, IDC_COMBO_CD_SPEED, bus != CDROM_BUS_DISABLED); settings_show_window(hdlg, IDT_CD_SPEED, bus != CDROM_BUS_DISABLED); +/* settings_show_window(hdlg, IDC_CHECKEARLY, bus != CDROM_BUS_DISABLED); - +*/ if (bus != CDROM_BUS_DISABLED) { settings_set_cur_sel(hdlg, IDC_COMBO_CD_SPEED, temp_cdrom[lv2_current_sel].speed - 1); - settings_set_check(hdlg, IDC_CHECKEARLY, temp_cdrom[lv2_current_sel].early); +// settings_set_check(hdlg, IDC_CHECKEARLY, temp_cdrom[lv2_current_sel].early); } switch (bus) { @@ -4650,10 +4774,9 @@ mo_add_locations(HWND hdlg) static void mo_recalc_location_controls(HWND hdlg, int assign_id) { - int i = 0; int bus = temp_mo_drives[lv1_current_sel].bus_type; - for (i = IDT_MO_ID; i <= (IDT_MO_CHANNEL); i++) + for (int i = IDT_MO_ID; i <= IDT_MO_CHANNEL; i++) settings_show_window(hdlg, i, FALSE); settings_show_window(hdlg, IDC_COMBO_MO_ID, FALSE); settings_show_window(hdlg, IDC_COMBO_MO_CHANNEL_IDE, FALSE); @@ -4714,11 +4837,9 @@ zip_add_locations(HWND hdlg) static void zip_recalc_location_controls(HWND hdlg, int assign_id) { - int i = 0; - int bus = temp_zip_drives[lv2_current_sel].bus_type; - for (i = IDT_ZIP_ID; i <= (IDT_ZIP_LUN); i++) + for (int i = IDT_ZIP_ID; i <= IDT_ZIP_LUN; i++) settings_show_window(hdlg, i, FALSE); settings_show_window(hdlg, IDC_COMBO_ZIP_ID, FALSE); settings_show_window(hdlg, IDC_COMBO_ZIP_CHANNEL_IDE, FALSE); @@ -4810,7 +4931,9 @@ static BOOL CALLBACK #endif win_settings_floppy_and_cdrom_drives_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int i = 0, old_sel = 0, b = 0, assign = 0; + int old_sel = 0; + int b = 0; + int assign = 0; uint32_t b2 = 0; WCHAR szText[256]; const uint8_t fd_icons[15] = { 248, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 0 }; @@ -4825,7 +4948,7 @@ win_settings_floppy_and_cdrom_drives_proc(HWND hdlg, UINT message, WPARAM wParam image_list_init(hdlg, IDC_LIST_FLOPPY_DRIVES, (const uint8_t *) fd_icons); win_settings_floppy_drives_recalc_list(hdlg); settings_listview_select(hdlg, IDC_LIST_FLOPPY_DRIVES, 0); - for (i = 0; i < 14; i++) { + for (uint8_t i = 0; i < 14; i++) { if (i == 0) settings_add_string(hdlg, IDC_COMBO_FD_TYPE, win_get_string(IDS_5376)); else { @@ -4972,10 +5095,12 @@ win_settings_floppy_and_cdrom_drives_proc(HWND hdlg, UINT message, WPARAM wParam win_settings_cdrom_drives_update_item(hdlg, lv2_current_sel); break; +/* case IDC_CHECKEARLY: temp_cdrom[lv2_current_sel].early = settings_get_check(hdlg, IDC_CHECKEARLY); win_settings_cdrom_drives_update_item(hdlg, lv2_current_sel); break; +*/ } ignore_change = 0; @@ -4999,7 +5124,9 @@ static BOOL CALLBACK #endif win_settings_other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int old_sel = 0, b = 0, assign = 0; + int old_sel = 0; + int b = 0; + int assign = 0; uint32_t b2 = 0; const uint8_t mo_icons[3] = { 251, 56, 0 }; const uint8_t zip_icons[3] = { 250, 48, 0 }; @@ -5226,7 +5353,8 @@ static BOOL CALLBACK #endif win_settings_peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - int c, d; + int c; + int d; int e; LPTSTR lptsTemp; char *stransi; @@ -5289,7 +5417,7 @@ win_settings_peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPa } settings_enable_window(hdlg, IDC_CHECK_BUGGER, machine_has_bus(temp_machine, MACHINE_BUS_ISA)); - settings_set_check(hdlg, IDC_CHECK_BUGGER, temp_bugger); + settings_set_check(hdlg, IDC_CHECK_BUGGER, (temp_bugger && machine_has_bus(temp_machine, MACHINE_BUS_ISA))); settings_set_check(hdlg, IDC_CHECK_POSTCARD, temp_postcard); free(stransi); @@ -5400,12 +5528,11 @@ static BOOL win_settings_main_insert_categories(HWND hwndList) { LVITEM lvI; - int i = 0; lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvI.stateMask = lvI.iSubItem = lvI.state = 0; - for (i = 0; i < 11; i++) { + for (uint8_t i = 0; i < 11; i++) { lvI.pszText = plat_get_string(IDS_2065 + i); lvI.iItem = i; lvI.iImage = i; @@ -5491,7 +5618,8 @@ static BOOL CALLBACK win_settings_main_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND h = NULL; - int category, i = 0, j = 0; + int category; + int j = 0; const uint8_t cat_icons[12] = { 240, 241, 242, 243, 96, 244, 252, 80, 246, 247, 245, 0 }; hwndParentDialog = hdlg; @@ -5511,7 +5639,7 @@ win_settings_main_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_NOTIFY: if ((((LPNMHDR) lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR) lParam)->idFrom == IDC_SETTINGSCATLIST)) { category = -1; - for (i = 0; i < 11; i++) { + for (uint8_t i = 0; i < 11; i++) { h = GetDlgItem(hdlg, IDC_SETTINGSCATLIST); j = ListView_GetItemState(h, i, LVIS_SELECTED); if (j) diff --git a/src/win/win_snd_gain.c b/src/win/win_snd_gain.c index 358942e39..641a83a5c 100644 --- a/src/win/win_snd_gain.c +++ b/src/win/win_snd_gain.c @@ -13,6 +13,7 @@ * Authors: Miran Grca, * * Copyright 2016-2018 Miran Grca. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -79,7 +80,7 @@ SoundGainDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) break; } - return (FALSE); + return FALSE; } void diff --git a/src/win/win_specify_dim.c b/src/win/win_specify_dim.c index 30698fac6..48e7801a5 100644 --- a/src/win/win_specify_dim.c +++ b/src/win/win_specify_dim.c @@ -13,6 +13,7 @@ * Authors: Miran Grca, * * Copyright 2016-2018 Miran Grca. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -39,12 +40,16 @@ static BOOL CALLBACK #endif SpecifyDimensionsDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - HWND h, h2; + HWND h; + HWND h2; HMENU hmenu; - UDACCEL accel, accel2; + UDACCEL accel; + UDACCEL accel2; RECT r; - uint32_t temp_x = 0, temp_y = 0; - int dpi = 96, lock; + uint32_t temp_x = 0; + uint32_t temp_y = 0; + int dpi = 96; + int lock; LPTSTR lptsTemp; char *stransi; diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index 5586f9d15..73f2d7231 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -15,6 +15,7 @@ * * Copyright 2016-2019 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -56,7 +57,8 @@ #include <86box/win.h> HWND hwndSBAR; -int update_icons = 1, reset_occurred = 1; +int update_icons = 1; +int reset_occurred = 1; static LONG_PTR OriginalProcedure; static WCHAR **sbTips; @@ -103,7 +105,7 @@ fdd_type_to_icon(int type) break; } - return (ret); + return ret; } /* FIXME: should be hdd_count() in hdd.c */ @@ -111,14 +113,13 @@ static int hdd_count(int bus) { int c = 0; - int i; - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if (hdd[i].bus == bus) c++; } - return (c); + return c; } void @@ -147,7 +148,7 @@ ui_sb_update_icon(int tag, int active) if (!update_icons || !sb_ready) return; - if (((tag & 0xf0) >= SB_TEXT)) + if ((tag & 0xf0) >= SB_TEXT) return; found = sb_map[tag]; @@ -453,15 +454,13 @@ ui_sb_update_tip(int meaning) static void StatusBarDestroyTips(void) { - int i; - if (sb_parts == 0) return; if (!sbTips) return; - for (i = 0; i < sb_parts; i++) { + for (int i = 0; i < sb_parts; i++) { if (sbTips[i]) { free(sbTips[i]); sbTips[i] = NULL; @@ -494,11 +493,20 @@ ui_sb_set_ready(int ready) void ui_sb_update_panes(void) { - int i, id; - int cart_int, mfm_int, xta_int, esdi_int, ide_int, scsi_int; + int i; + int id; + int cart_int; + int mfm_int; + int xta_int; + int esdi_int; + int ide_int; + int scsi_int; int edge = 0; - int c_mfm, c_esdi, c_xta; - int c_ide, c_scsi; + int c_mfm; + int c_esdi; + int c_xta; + int c_ide; + int c_scsi; int do_net; char *hdc_name; @@ -879,7 +887,7 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_COMMAND: media_menu_proc(hwnd, message, wParam, lParam); - return (0); + return 0; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: @@ -924,7 +932,7 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) hwnd, message, wParam, lParam)); } - return (0); + return 0; } /* API: Create and set up the Status Bar window. */ @@ -932,7 +940,8 @@ void StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst) { RECT rectDialog; - int dw, dh; + int dw; + int dh; /* Get current DPI and calculate icon sizes */ dpi = win_get_dpi(hwndParent); diff --git a/src/win/win_thread.c b/src/win/win_thread.c index c110779f2..faacca74f 100644 --- a/src/win/win_thread.c +++ b/src/win/win_thread.c @@ -15,6 +15,7 @@ * * Copyright 2008-2018 Sarah Walker. * Copyright 2017-2018 Fred N. van Kempen. + * Copyright 2021-2023 Jasmine Iwanek. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -46,7 +47,7 @@ int thread_test_mutex(thread_t *arg) { if (arg == NULL) - return (0); + return 0; return (WaitForSingleObject(arg, 0) == WAIT_OBJECT_0) ? 1 : 0; } @@ -55,12 +56,12 @@ int thread_wait(thread_t *arg) { if (arg == NULL) - return (0); + return 0; if (WaitForSingleObject(arg, INFINITE)) - return (1); + return 1; - return (0); + return 0; } event_t * @@ -101,18 +102,18 @@ thread_wait_event(event_t *arg, int timeout) win_event_t *ev = (win_event_t *) arg; if (arg == NULL) - return (0); + return 0; if (ev->handle == NULL) - return (0); + return 0; if (timeout == -1) timeout = INFINITE; if (WaitForSingleObject(ev->handle, timeout)) - return (1); + return 1; - return (0); + return 0; } void @@ -142,7 +143,7 @@ int thread_wait_mutex(mutex_t *mutex) { if (mutex == NULL) - return (0); + return 0; LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION) mutex; @@ -155,7 +156,7 @@ int thread_release_mutex(mutex_t *mutex) { if (mutex == NULL) - return (0); + return 0; LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION) mutex; diff --git a/src/win/win_toolbar.c b/src/win/win_toolbar.c index 6b1edefb2..5c8621eea 100644 --- a/src/win/win_toolbar.c +++ b/src/win/win_toolbar.c @@ -204,5 +204,5 @@ ui_window_title(wchar_t *s) s = wTitle; } - return (s); + return s; } diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 4c19f5a7f..deb2eb6ec 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -13,11 +13,13 @@ * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, + * Jasmine Iwanek, * * Copyright 2008-2020 Sarah Walker. * Copyright 2016-2020 Miran Grca. * Copyright 2017-2020 Fred N. van Kempen. * Copyright 2019-2020 GH Cao. + * Copyright 2021-2023 Jasmine Iwanek. */ #include #define UNICODE @@ -55,18 +57,20 @@ #define TIMER_1SEC 1 /* ID of the one-second timer */ /* Platform Public data, specific. */ -HWND hwndMain = NULL, /* application main window */ - hwndRender = NULL, /* machine render window */ - hwndRender2 = NULL; /* machine second screen render window */ +HWND hwndMain = NULL; /* application main window */ +HWND hwndRender = NULL; /* machine render window */ +HWND hwndRender2 = NULL; /* machine second screen render window */ HMENU menuMain; /* application main menu */ RECT oldclip; /* mouse rect */ int sbar_height = 23; /* statusbar height */ int tbar_height = 23; /* toolbar height */ int minimized = 0; -int infocus = 1, button_down = 0; +int infocus = 1; +int button_down = 0; int rctrl_is_lalt = 0; int user_resize = 0; -int fixed_size_x = 0, fixed_size_y = 0; +int fixed_size_x = 0; +int fixed_size_y = 0; int kbd_req_capture = 0; int hide_status_bar = 0; int hide_tool_bar = 0; @@ -77,9 +81,10 @@ extern WCHAR wopenfilestring[512]; /* Local data. */ static int manager_wm = 0; -static int save_window_pos = 0, pause_state = 0; -static int padded_frame = 0; -static int vis = -1; +static int save_window_pos = 0; +static int pause_state = 0; +static int padded_frame = 0; +static int vis = -1; /* Per Monitor DPI Aware v2 APIs, Windows 10 v1703+ */ void *user32_handle = NULL; @@ -268,33 +273,33 @@ ResetAllMenus(void) #ifdef USE_VNC CheckMenuItem(menuMain, IDM_VID_VNC, MF_UNCHECKED); #endif - CheckMenuItem(menuMain, IDM_VID_FS_FULL + 0, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_FS_FULL + 1, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_FS_FULL + 2, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_FS_FULL + 3, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_FS_FULL + 4, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_FULL, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_43, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_KEEPRATIO, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_INT, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SPECIFY_DIM, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_REMEMBER, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 0, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 1, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 2, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 3, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 4, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 5, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 6, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 7, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 8, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_SCALE_1X + 9, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_1X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_2X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_3X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_4X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_5X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_6X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_7X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_8X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_9X, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_10X, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_HIDPI, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_CGACON, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAYCT_601 + 0, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAYCT_601 + 1, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAYCT_601 + 2, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAY_RGB + 0, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAY_RGB + 1, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAY_RGB + 2, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAY_RGB + 3, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_GRAY_RGB + 4, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAYCT_601, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAYCT_709, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAYCT_AVE, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_RGB, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_MONO, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_AMBER, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_GREEN, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_WHITE, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_ACTION_RCTRL_IS_LALT, rctrl_is_lalt ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(menuMain, IDM_ACTION_KBD_REQ_CAPTURE, kbd_req_capture ? MF_CHECKED : MF_UNCHECKED); @@ -347,6 +352,12 @@ ResetAllMenus(void) EnableMenuItem(menuMain, IDM_VID_SCALE_2X, MF_GRAYED); EnableMenuItem(menuMain, IDM_VID_SCALE_3X, MF_GRAYED); EnableMenuItem(menuMain, IDM_VID_SCALE_4X, MF_GRAYED); + EnableMenuItem(menuMain, IDM_VID_SCALE_5X, MF_GRAYED); + EnableMenuItem(menuMain, IDM_VID_SCALE_6X, MF_GRAYED); + EnableMenuItem(menuMain, IDM_VID_SCALE_7X, MF_GRAYED); + EnableMenuItem(menuMain, IDM_VID_SCALE_8X, MF_GRAYED); + EnableMenuItem(menuMain, IDM_VID_SCALE_9X, MF_GRAYED); + EnableMenuItem(menuMain, IDM_VID_SCALE_10X, MF_GRAYED); } } @@ -463,12 +474,14 @@ input_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; default: - return (1); - /* return(CallWindowProc((WNDPROC)input_orig_proc, - hwnd, message, wParam, lParam)); */ + return 1; +#if 0 + return(CallWindowProc((WNDPROC)input_orig_proc, + hwnd, message, wParam, lParam)); +#endif } - return (0); + return 0; } static LRESULT CALLBACK @@ -476,12 +489,14 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HMENU hmenu; - int i; - RECT rect, *rect_p; + int i; + RECT rect; + RECT *rect_p; WINDOWPOS *pos; - int temp_x, temp_y; + int temp_x; + int temp_y; if (input_proc(hwnd, message, wParam, lParam) == 0) return (0); @@ -654,6 +669,12 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) EnableMenuItem(hmenu, IDM_VID_SCALE_2X, vid_resize ? MF_GRAYED : MF_ENABLED); EnableMenuItem(hmenu, IDM_VID_SCALE_3X, vid_resize ? MF_GRAYED : MF_ENABLED); EnableMenuItem(hmenu, IDM_VID_SCALE_4X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_5X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_6X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_7X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_8X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_9X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_10X, vid_resize ? MF_GRAYED : MF_ENABLED); scrnsz_x = unscaled_size_x; scrnsz_y = unscaled_size_y; @@ -750,6 +771,12 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_VID_SCALE_2X: case IDM_VID_SCALE_3X: case IDM_VID_SCALE_4X: + case IDM_VID_SCALE_5X: + case IDM_VID_SCALE_6X: + case IDM_VID_SCALE_7X: + case IDM_VID_SCALE_8X: + case IDM_VID_SCALE_9X: + case IDM_VID_SCALE_10X: CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED); scale = LOWORD(wParam) - IDM_VID_SCALE_1X; CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_CHECKED); @@ -1136,14 +1163,14 @@ SubWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) return (DefWindowProc(hwnd, message, wParam, lParam)); } - return (0); + return 0; } static LRESULT CALLBACK SDLMainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if (input_proc(hwnd, message, wParam, lParam) == 0) - return (0); + return 0; return (DefWindowProc(hwnd, message, wParam, lParam)); } @@ -1183,6 +1210,8 @@ ui_init(int nCmdShow) {IDCANCEL, MAKEINTRESOURCE(IDS_2120)} }; uint32_t helper_lang; + static int fs_on_signal = 0; + static int fs_off_signal = 0; /* Load DPI related Windows 10 APIs */ user32_handle = dynld_module("user32.dll", user32_imports); @@ -1461,9 +1490,20 @@ ui_init(int nCmdShow) plat_mouse_capture(0); } - if (video_fullscreen && keyboard_isfsexit()) { + if (!fs_off_signal && video_fullscreen && keyboard_isfsexit()) { /* Signal "exit fullscreen mode". */ + fs_off_signal = 1; + } else if (fs_off_signal && video_fullscreen && keyboard_isfsexit_up()) { plat_setfullscreen(0); + fs_off_signal = 0; + } + + if (!fs_on_signal && !video_fullscreen && keyboard_isfsenter()) { + /* Signal "enter fullscreen mode". */ + fs_on_signal = 1; + } else if (fs_on_signal && !video_fullscreen && keyboard_isfsenter_up()) { + plat_setfullscreen(1); + fs_on_signal = 0; } #ifdef DISCORD @@ -1538,7 +1578,7 @@ plat_pause(int p) /* Update the actual menu. */ CheckMenuItem(menuMain, IDM_ACTION_PAUSE, - (dopause) ? MF_CHECKED : MF_UNCHECKED); + dopause ? MF_CHECKED : MF_UNCHECKED); #ifdef DISCORD /* Update Discord status */ @@ -1602,14 +1642,17 @@ plat_mouse_capture(int on) void ui_init_monitor(int monitor_index) { + // Nothing done here yet } void ui_deinit_monitor(int monitor_index) { + // Nothing done here yet } void ui_hard_reset_completed(void) { + // Nothing done here yet } diff --git a/vcpkg.json b/vcpkg.json index 890aeed46..f9cf6783c 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,7 +8,8 @@ "freetype", "libpng", "sdl2", - "rtmidi" + "rtmidi", + "libslirp" ], "features": { "qt-ui": { @@ -46,12 +47,6 @@ "libmt32emu" ] }, - "slirp": { - "description": "Slirp network support", - "dependencies": [ - "libslirp" - ] - }, "openal": { "description": "OpenAL sound backend", "dependencies": [